diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-09 14:29:34 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-09 14:29:34 +0000 |
commit | 03374cc39814fa4bfb8d96e1165c688c44d8342f (patch) | |
tree | ed772250c49b39d82b9708ec8df0ee3e07e366d1 /src/namestore/namestore_api.c | |
parent | 0c13a1e6fb0baffd83d413f313742a5f2b420297 (diff) | |
download | gnunet-03374cc39814fa4bfb8d96e1165c688c44d8342f.tar.gz gnunet-03374cc39814fa4bfb8d96e1165c688c44d8342f.zip |
make namestore API less brittle/sublte to use
Diffstat (limited to 'src/namestore/namestore_api.c')
-rw-r--r-- | src/namestore/namestore_api.c | 92 |
1 files changed, 75 insertions, 17 deletions
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index b8da654ce..61d8385b6 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -84,6 +84,16 @@ struct GNUNET_NAMESTORE_QueueEntry | |||
84 | void *proc_cls; | 84 | void *proc_cls; |
85 | 85 | ||
86 | /** | 86 | /** |
87 | * Function to call on errors. | ||
88 | */ | ||
89 | GNUNET_SCHEDULER_TaskCallback error_cb; | ||
90 | |||
91 | /** | ||
92 | * Closure for @e error_cb. | ||
93 | */ | ||
94 | void *error_cb_cls; | ||
95 | |||
96 | /** | ||
87 | * Envelope of the message to send to the service, if not yet | 97 | * Envelope of the message to send to the service, if not yet |
88 | * sent. | 98 | * sent. |
89 | */ | 99 | */ |
@@ -119,6 +129,16 @@ struct GNUNET_NAMESTORE_ZoneIterator | |||
119 | struct GNUNET_NAMESTORE_Handle *h; | 129 | struct GNUNET_NAMESTORE_Handle *h; |
120 | 130 | ||
121 | /** | 131 | /** |
132 | * Function to call on completion. | ||
133 | */ | ||
134 | GNUNET_SCHEDULER_TaskCallback finish_cb; | ||
135 | |||
136 | /** | ||
137 | * Closure for @e error_cb. | ||
138 | */ | ||
139 | void *finish_cb_cls; | ||
140 | |||
141 | /** | ||
122 | * The continuation to call with the results | 142 | * The continuation to call with the results |
123 | */ | 143 | */ |
124 | GNUNET_NAMESTORE_RecordMonitor proc; | 144 | GNUNET_NAMESTORE_RecordMonitor proc; |
@@ -129,6 +149,16 @@ struct GNUNET_NAMESTORE_ZoneIterator | |||
129 | void *proc_cls; | 149 | void *proc_cls; |
130 | 150 | ||
131 | /** | 151 | /** |
152 | * Function to call on errors. | ||
153 | */ | ||
154 | GNUNET_SCHEDULER_TaskCallback error_cb; | ||
155 | |||
156 | /** | ||
157 | * Closure for @e error_cb. | ||
158 | */ | ||
159 | void *error_cb_cls; | ||
160 | |||
161 | /** | ||
132 | * Envelope of the message to send to the service, if not yet | 162 | * Envelope of the message to send to the service, if not yet |
133 | * sent. | 163 | * sent. |
134 | */ | 164 | */ |
@@ -543,9 +573,11 @@ handle_record_result (void *cls, | |||
543 | ntohl (msg->gns_header.r_id)); | 573 | ntohl (msg->gns_header.r_id)); |
544 | qe = find_qe (h, | 574 | qe = find_qe (h, |
545 | ntohl (msg->gns_header.r_id)); | 575 | ntohl (msg->gns_header.r_id)); |
546 | if ( (NULL == ze) && (NULL == qe) ) | 576 | if ( (NULL == ze) && |
577 | (NULL == qe) ) | ||
547 | return; /* rid not found */ | 578 | return; /* rid not found */ |
548 | if ( (NULL != ze) && (NULL != qe) ) | 579 | if ( (NULL != ze) && |
580 | (NULL != qe) ) | ||
549 | { | 581 | { |
550 | GNUNET_break (0); /* rid ambigous */ | 582 | GNUNET_break (0); /* rid ambigous */ |
551 | force_reconnect (h); | 583 | force_reconnect (h); |
@@ -564,8 +596,8 @@ handle_record_result (void *cls, | |||
564 | force_reconnect (h); | 596 | force_reconnect (h); |
565 | return; | 597 | return; |
566 | } | 598 | } |
567 | if (NULL != ze->proc) | 599 | if (NULL != ze->finish_cb) |
568 | ze->proc (ze->proc_cls, NULL, NULL, 0, NULL); | 600 | ze->finish_cb (ze->finish_cb_cls); |
569 | free_ze (ze); | 601 | free_ze (ze); |
570 | return; | 602 | return; |
571 | } | 603 | } |
@@ -706,7 +738,8 @@ handle_zone_to_name_response (void *cls, | |||
706 | qe->proc (qe->proc_cls, | 738 | qe->proc (qe->proc_cls, |
707 | &msg->zone, | 739 | &msg->zone, |
708 | name_tmp, | 740 | name_tmp, |
709 | rd_count, rd); | 741 | rd_count, |
742 | rd); | ||
710 | /* return is important here: break would call continuation with error! */ | 743 | /* return is important here: break would call continuation with error! */ |
711 | free_qe (qe); | 744 | free_qe (qe); |
712 | return; | 745 | return; |
@@ -717,8 +750,8 @@ handle_zone_to_name_response (void *cls, | |||
717 | return; | 750 | return; |
718 | } | 751 | } |
719 | /* error case, call continuation with error */ | 752 | /* error case, call continuation with error */ |
720 | if (NULL != qe->proc) | 753 | if (NULL != qe->error_cb) |
721 | qe->proc (qe->proc_cls, NULL, NULL, 0, NULL); | 754 | qe->error_cb (qe->error_cb_cls); |
722 | free_qe (qe); | 755 | free_qe (qe); |
723 | } | 756 | } |
724 | 757 | ||
@@ -826,18 +859,18 @@ force_reconnect (struct GNUNET_NAMESTORE_Handle *h) | |||
826 | h->mq = NULL; | 859 | h->mq = NULL; |
827 | while (NULL != (ze = h->z_head)) | 860 | while (NULL != (ze = h->z_head)) |
828 | { | 861 | { |
829 | /* FIXME: This does not allow clients to distinguish | 862 | if (NULL != ze->error_cb) |
830 | iteration error from successful termination! */ | 863 | ze->error_cb (ze->error_cb_cls); |
831 | if (NULL != ze->proc) | ||
832 | ze->proc (ze->proc_cls, NULL, NULL, 0, NULL); | ||
833 | free_ze (ze); | 864 | free_ze (ze); |
834 | } | 865 | } |
835 | while (NULL != (qe = h->op_head)) | 866 | while (NULL != (qe = h->op_head)) |
836 | { | 867 | { |
837 | /* FIXME: This does not allow clients to distinguish | 868 | if (NULL != qe->error_cb) |
838 | iteration error from successful termination! */ | 869 | qe->error_cb (qe->error_cb_cls); |
839 | if (NULL != qe->proc) | 870 | if (NULL != qe->cont) |
840 | qe->proc (qe->proc_cls, NULL, NULL, 0, NULL); | 871 | qe->cont (qe->cont_cls, |
872 | GNUNET_SYSERR, | ||
873 | "failure in communication with namestore service"); | ||
841 | free_qe (qe); | 874 | free_qe (qe); |
842 | } | 875 | } |
843 | 876 | ||
@@ -1058,6 +1091,8 @@ GNUNET_NAMESTORE_set_nick (struct GNUNET_NAMESTORE_Handle *h, | |||
1058 | * @param h handle to the namestore | 1091 | * @param h handle to the namestore |
1059 | * @param pkey private key of the zone | 1092 | * @param pkey private key of the zone |
1060 | * @param label name that is being mapped (at most 255 characters long) | 1093 | * @param label name that is being mapped (at most 255 characters long) |
1094 | * @param error_cb function to call on error (i.e. disconnect) | ||
1095 | * @param error_cb_cls closure for @a error_cb | ||
1061 | * @param rm function to call with the result (with 0 records if we don't have that label) | 1096 | * @param rm function to call with the result (with 0 records if we don't have that label) |
1062 | * @param rm_cls closure for @a rm | 1097 | * @param rm_cls closure for @a rm |
1063 | * @return handle to abort the request | 1098 | * @return handle to abort the request |
@@ -1066,6 +1101,8 @@ struct GNUNET_NAMESTORE_QueueEntry * | |||
1066 | GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h, | 1101 | GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h, |
1067 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | 1102 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, |
1068 | const char *label, | 1103 | const char *label, |
1104 | GNUNET_SCHEDULER_TaskCallback error_cb, | ||
1105 | void *error_cb_cls, | ||
1069 | GNUNET_NAMESTORE_RecordMonitor rm, | 1106 | GNUNET_NAMESTORE_RecordMonitor rm, |
1070 | void *rm_cls) | 1107 | void *rm_cls) |
1071 | { | 1108 | { |
@@ -1082,6 +1119,8 @@ GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h, | |||
1082 | 1119 | ||
1083 | qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); | 1120 | qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); |
1084 | qe->h = h; | 1121 | qe->h = h; |
1122 | qe->error_cb = error_cb; | ||
1123 | qe->error_cb_cls = error_cb_cls; | ||
1085 | qe->proc = rm; | 1124 | qe->proc = rm; |
1086 | qe->proc_cls = rm_cls; | 1125 | qe->proc_cls = rm_cls; |
1087 | qe->op_id = get_op_id(h); | 1126 | qe->op_id = get_op_id(h); |
@@ -1114,6 +1153,8 @@ GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h, | |||
1114 | * @param h handle to the namestore | 1153 | * @param h handle to the namestore |
1115 | * @param zone public key of the zone to look up in, never NULL | 1154 | * @param zone public key of the zone to look up in, never NULL |
1116 | * @param value_zone public key of the target zone (value), never NULL | 1155 | * @param value_zone public key of the target zone (value), never NULL |
1156 | * @param error_cb function to call on error (i.e. disconnect) | ||
1157 | * @param error_cb_cls closure for @a error_cb | ||
1117 | * @param proc function to call on the matching records, or with | 1158 | * @param proc function to call on the matching records, or with |
1118 | * NULL (rd_count == 0) if there are no matching records | 1159 | * NULL (rd_count == 0) if there are no matching records |
1119 | * @param proc_cls closure for @a proc | 1160 | * @param proc_cls closure for @a proc |
@@ -1124,6 +1165,8 @@ struct GNUNET_NAMESTORE_QueueEntry * | |||
1124 | GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, | 1165 | GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, |
1125 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 1166 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
1126 | const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone, | 1167 | const struct GNUNET_CRYPTO_EcdsaPublicKey *value_zone, |
1168 | GNUNET_SCHEDULER_TaskCallback error_cb, | ||
1169 | void *error_cb_cls, | ||
1127 | GNUNET_NAMESTORE_RecordMonitor proc, | 1170 | GNUNET_NAMESTORE_RecordMonitor proc, |
1128 | void *proc_cls) | 1171 | void *proc_cls) |
1129 | { | 1172 | { |
@@ -1135,6 +1178,8 @@ GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, | |||
1135 | rid = get_op_id(h); | 1178 | rid = get_op_id(h); |
1136 | qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); | 1179 | qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); |
1137 | qe->h = h; | 1180 | qe->h = h; |
1181 | qe->error_cb = error_cb; | ||
1182 | qe->error_cb_cls = error_cb_cls; | ||
1138 | qe->proc = proc; | 1183 | qe->proc = proc; |
1139 | qe->proc_cls = proc_cls; | 1184 | qe->proc_cls = proc_cls; |
1140 | qe->op_id = rid; | 1185 | qe->op_id = rid; |
@@ -1166,26 +1211,39 @@ GNUNET_NAMESTORE_zone_to_name (struct GNUNET_NAMESTORE_Handle *h, | |||
1166 | * | 1211 | * |
1167 | * @param h handle to the namestore | 1212 | * @param h handle to the namestore |
1168 | * @param zone zone to access, NULL for all zones | 1213 | * @param zone zone to access, NULL for all zones |
1214 | * @param error_cb function to call on error (i.e. disconnect) | ||
1215 | * @param error_cb_cls closure for @a error_cb | ||
1169 | * @param proc function to call on each name from the zone; it | 1216 | * @param proc function to call on each name from the zone; it |
1170 | * will be called repeatedly with a value (if available) | 1217 | * will be called repeatedly with a value (if available) |
1171 | * and always once at the end with a name of NULL. | ||
1172 | * @param proc_cls closure for @a proc | 1218 | * @param proc_cls closure for @a proc |
1219 | * @param finish_cb function to call on completion | ||
1220 | * @param finish_cb_cls closure for @a finish_cb | ||
1173 | * @return an iterator handle to use for iteration | 1221 | * @return an iterator handle to use for iteration |
1174 | */ | 1222 | */ |
1175 | struct GNUNET_NAMESTORE_ZoneIterator * | 1223 | struct GNUNET_NAMESTORE_ZoneIterator * |
1176 | GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h, | 1224 | GNUNET_NAMESTORE_zone_iteration_start (struct GNUNET_NAMESTORE_Handle *h, |
1177 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, | 1225 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, |
1226 | GNUNET_SCHEDULER_TaskCallback error_cb, | ||
1227 | void *error_cb_cls, | ||
1178 | GNUNET_NAMESTORE_RecordMonitor proc, | 1228 | GNUNET_NAMESTORE_RecordMonitor proc, |
1179 | void *proc_cls) | 1229 | void *proc_cls, |
1230 | GNUNET_SCHEDULER_TaskCallback finish_cb, | ||
1231 | void *finish_cb_cls) | ||
1180 | { | 1232 | { |
1181 | struct GNUNET_NAMESTORE_ZoneIterator *it; | 1233 | struct GNUNET_NAMESTORE_ZoneIterator *it; |
1182 | struct GNUNET_MQ_Envelope *env; | 1234 | struct GNUNET_MQ_Envelope *env; |
1183 | struct ZoneIterationStartMessage *msg; | 1235 | struct ZoneIterationStartMessage *msg; |
1184 | uint32_t rid; | 1236 | uint32_t rid; |
1185 | 1237 | ||
1238 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1239 | "Sending ZONE_ITERATION_START message\n"); | ||
1186 | rid = get_op_id (h); | 1240 | rid = get_op_id (h); |
1187 | it = GNUNET_new (struct GNUNET_NAMESTORE_ZoneIterator); | 1241 | it = GNUNET_new (struct GNUNET_NAMESTORE_ZoneIterator); |
1188 | it->h = h; | 1242 | it->h = h; |
1243 | it->error_cb = error_cb; | ||
1244 | it->error_cb_cls = error_cb_cls; | ||
1245 | it->finish_cb = finish_cb; | ||
1246 | it->finish_cb_cls = finish_cb_cls; | ||
1189 | it->proc = proc; | 1247 | it->proc = proc; |
1190 | it->proc_cls = proc_cls; | 1248 | it->proc_cls = proc_cls; |
1191 | it->op_id = rid; | 1249 | it->op_id = rid; |