diff options
Diffstat (limited to 'src/namestore/plugin_rest_namestore.c')
-rw-r--r-- | src/namestore/plugin_rest_namestore.c | 78 |
1 files changed, 61 insertions, 17 deletions
diff --git a/src/namestore/plugin_rest_namestore.c b/src/namestore/plugin_rest_namestore.c index a9b49e19a..7a5a70fca 100644 --- a/src/namestore/plugin_rest_namestore.c +++ b/src/namestore/plugin_rest_namestore.c | |||
@@ -201,6 +201,21 @@ struct RequestHandle | |||
201 | unsigned int rd_count; | 201 | unsigned int rd_count; |
202 | 202 | ||
203 | /** | 203 | /** |
204 | * RecordInfo array | ||
205 | */ | ||
206 | struct GNUNET_NAMESTORE_RecordInfo *ri; | ||
207 | |||
208 | /** | ||
209 | * Size of record info | ||
210 | */ | ||
211 | unsigned int rd_set_count; | ||
212 | |||
213 | /** | ||
214 | * Position of record info | ||
215 | */ | ||
216 | unsigned int rd_set_pos; | ||
217 | |||
218 | /** | ||
204 | * NAMESTORE Operation | 219 | * NAMESTORE Operation |
205 | */ | 220 | */ |
206 | struct GNUNET_NAMESTORE_QueueEntry *ns_qe; | 221 | struct GNUNET_NAMESTORE_QueueEntry *ns_qe; |
@@ -768,7 +783,7 @@ bulk_tx_commit_cb (void *cls, int32_t success, const char *emsg) | |||
768 | * @param emsg the error message (can be NULL) | 783 | * @param emsg the error message (can be NULL) |
769 | */ | 784 | */ |
770 | static void | 785 | static void |
771 | import_finished_cb (void *cls, int32_t success, const char *emsg) | 786 | import_next_cb (void *cls, int32_t success, const char *emsg) |
772 | { | 787 | { |
773 | struct RequestHandle *handle = cls; | 788 | struct RequestHandle *handle = cls; |
774 | 789 | ||
@@ -787,9 +802,32 @@ import_finished_cb (void *cls, int32_t success, const char *emsg) | |||
787 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 802 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
788 | return; | 803 | return; |
789 | } | 804 | } |
790 | handle->ns_qe = GNUNET_NAMESTORE_transaction_commit (handle->nc, | 805 | unsigned int remaining = handle->rd_set_count - handle->rd_set_pos; |
791 | &bulk_tx_commit_cb, | 806 | if (0 == remaining) |
792 | handle); | 807 | { |
808 | handle->ns_qe = GNUNET_NAMESTORE_transaction_commit (handle->nc, | ||
809 | &bulk_tx_commit_cb, | ||
810 | handle); | ||
811 | return; | ||
812 | } | ||
813 | unsigned int sent_rds = 0; | ||
814 | // Find the smallest set of records we can send with our message size | ||
815 | // restriction of 16 bit | ||
816 | handle->ns_qe = GNUNET_NAMESTORE_records_store2 (handle->nc, | ||
817 | handle->zone_pkey, | ||
818 | remaining, | ||
819 | &handle->ri[handle-> | ||
820 | rd_set_pos], | ||
821 | &sent_rds, | ||
822 | &import_next_cb, | ||
823 | handle); | ||
824 | if ((NULL == handle->ns_qe) && (0 == sent_rds)) | ||
825 | { | ||
826 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); | ||
827 | GNUNET_SCHEDULER_add_now (&do_error, handle); | ||
828 | return; | ||
829 | } | ||
830 | handle->rd_set_pos += sent_rds; | ||
793 | } | 831 | } |
794 | 832 | ||
795 | static void | 833 | static void |
@@ -827,11 +865,11 @@ bulk_tx_start (void *cls, int32_t success, const char *emsg) | |||
827 | json_decref (data_js); | 865 | json_decref (data_js); |
828 | return; | 866 | return; |
829 | } | 867 | } |
830 | size_t rd_set_count = json_array_size (data_js); | 868 | handle->rd_set_count = json_array_size (data_js); |
831 | struct GNUNET_NAMESTORE_RecordInfo ri[rd_set_count]; | 869 | handle->ri = GNUNET_malloc (handle->rd_set_count |
870 | * sizeof (struct GNUNET_NAMESTORE_RecordInfo)); | ||
832 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 871 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
833 | "Got record set of size %d\n", rd_set_count); | 872 | "Got record set of size %d\n", handle->rd_set_count); |
834 | const struct GNUNET_GNSRECORD_Data *a_rd[rd_set_count]; | ||
835 | char *albl; | 873 | char *albl; |
836 | size_t index; | 874 | size_t index; |
837 | json_t *value; | 875 | json_t *value; |
@@ -839,7 +877,8 @@ bulk_tx_start (void *cls, int32_t success, const char *emsg) | |||
839 | { | 877 | { |
840 | struct GNUNET_GNSRECORD_Data *rd; | 878 | struct GNUNET_GNSRECORD_Data *rd; |
841 | struct GNUNET_JSON_Specification gnsspec[] = | 879 | struct GNUNET_JSON_Specification gnsspec[] = |
842 | { GNUNET_GNSRECORD_JSON_spec_gnsrecord (&rd, &ri[index].a_rd_count, | 880 | { GNUNET_GNSRECORD_JSON_spec_gnsrecord (&rd, |
881 | &handle->ri[index].a_rd_count, | ||
843 | &albl), | 882 | &albl), |
844 | GNUNET_JSON_spec_end () }; | 883 | GNUNET_JSON_spec_end () }; |
845 | if (GNUNET_OK != GNUNET_JSON_parse (value, gnsspec, NULL, NULL)) | 884 | if (GNUNET_OK != GNUNET_JSON_parse (value, gnsspec, NULL, NULL)) |
@@ -849,30 +888,35 @@ bulk_tx_start (void *cls, int32_t success, const char *emsg) | |||
849 | json_decref (data_js); | 888 | json_decref (data_js); |
850 | return; | 889 | return; |
851 | } | 890 | } |
852 | ri[index].a_rd = rd; | 891 | handle->ri[index].a_rd = rd; |
853 | ri[index].a_label = albl; | 892 | handle->ri[index].a_label = albl; |
854 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 893 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
855 | "Parsed record set for name %s\n", ri[index].a_label); | 894 | "Parsed record set for name %s\n", |
895 | handle->ri[index].a_label); | ||
856 | } | 896 | } |
857 | } | 897 | } |
858 | // json_decref (data_js); | 898 | // json_decref (data_js); |
859 | 899 | ||
900 | unsigned int sent_rds = 0; | ||
901 | // Find the smallest set of records we can send with our message size | ||
902 | // restriction of 16 bit | ||
860 | handle->ns_qe = GNUNET_NAMESTORE_records_store2 (handle->nc, | 903 | handle->ns_qe = GNUNET_NAMESTORE_records_store2 (handle->nc, |
861 | handle->zone_pkey, | 904 | handle->zone_pkey, |
862 | rd_set_count, | 905 | handle->rd_set_count, |
863 | ri, | 906 | handle->ri, |
864 | &import_finished_cb, | 907 | &sent_rds, |
908 | &import_next_cb, | ||
865 | handle); | 909 | handle); |
866 | if (NULL == handle->ns_qe) | 910 | if ((NULL == handle->ns_qe) && (0 == sent_rds)) |
867 | { | 911 | { |
868 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); | 912 | handle->emsg = GNUNET_strdup (GNUNET_REST_NAMESTORE_FAILED); |
869 | GNUNET_SCHEDULER_add_now (&do_error, handle); | 913 | GNUNET_SCHEDULER_add_now (&do_error, handle); |
870 | return; | 914 | return; |
871 | } | 915 | } |
916 | handle->rd_set_pos += sent_rds; | ||
872 | } | 917 | } |
873 | 918 | ||
874 | 919 | ||
875 | |||
876 | /** | 920 | /** |
877 | * Handle namestore POST import | 921 | * Handle namestore POST import |
878 | * | 922 | * |