diff options
Diffstat (limited to 'src/namestore/gnunet-service-namestore.c')
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 132 |
1 files changed, 77 insertions, 55 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index af5f84979..59059d84e 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -614,6 +614,10 @@ handle_create_record_it (void *cls, | |||
614 | rd_count_new, rd_new, | 614 | rd_count_new, rd_new, |
615 | signature_new); | 615 | signature_new); |
616 | GNUNET_break (GNUNET_OK == res); | 616 | GNUNET_break (GNUNET_OK == res); |
617 | if (res == GNUNET_OK) | ||
618 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully put record for `%s' in database \n", crc->name); | ||
619 | else | ||
620 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to put record for `%s' in database \n", crc->name); | ||
617 | res = GNUNET_YES; | 621 | res = GNUNET_YES; |
618 | 622 | ||
619 | end: | 623 | end: |
@@ -1163,40 +1167,68 @@ void zone_iteration_proc (void *cls, | |||
1163 | const struct GNUNET_NAMESTORE_RecordData *rd, | 1167 | const struct GNUNET_NAMESTORE_RecordData *rd, |
1164 | const struct GNUNET_CRYPTO_RsaSignature *signature) | 1168 | const struct GNUNET_CRYPTO_RsaSignature *signature) |
1165 | { | 1169 | { |
1166 | struct ZoneIterationProcResult *zipr = cls; | 1170 | struct GNUNET_NAMESTORE_ZoneIteration *zi = cls; |
1167 | size_t len; | 1171 | struct GNUNET_NAMESTORE_Client *nc = zi->client; |
1168 | if (zone_key != NULL) | 1172 | //size_t len; |
1169 | { | ||
1170 | zipr->zone_key = *zone_key; | ||
1171 | zipr->have_zone_key = GNUNET_YES; | ||
1172 | } | ||
1173 | else | ||
1174 | zipr->have_zone_key = GNUNET_NO; | ||
1175 | |||
1176 | zipr->expire = expire; | ||
1177 | |||
1178 | if (name != NULL) | ||
1179 | { | ||
1180 | memcpy (zipr->name, name, strlen(name) + 1); | ||
1181 | zipr->have_name = GNUNET_YES; | ||
1182 | } | ||
1183 | else | ||
1184 | zipr->have_name = GNUNET_NO; | ||
1185 | 1173 | ||
1186 | if (signature != NULL) | 1174 | if ((zone_key == NULL) && (name == NULL)) |
1187 | { | 1175 | { |
1188 | zipr->signature = *signature; | 1176 | struct ZoneIterationResponseMessage zir_msg; |
1189 | zipr->have_signature = GNUNET_YES; | 1177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more results for zone `%s'\n", GNUNET_h2s(&zi->zone)); |
1178 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending empty `%s' message\n", "ZONE_ITERATION_RESPONSE"); | ||
1179 | zir_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE); | ||
1180 | zir_msg.gns_header.header.size = htons (sizeof (struct ZoneIterationResponseMessage)); | ||
1181 | zir_msg.gns_header.r_id = htonl(zi->request_id); | ||
1182 | zir_msg.expire = GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_zero()); | ||
1183 | zir_msg.name_len = htons (0); | ||
1184 | zir_msg.reserved = htons (0); | ||
1185 | zir_msg.rd_count = htons (0); | ||
1186 | zir_msg.rd_len = htons (0); | ||
1187 | memset (&zir_msg.public_key, '\0', sizeof (zir_msg.public_key)); | ||
1188 | memset (&zir_msg.signature, '\0', sizeof (zir_msg.signature)); | ||
1189 | GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &zir_msg, GNUNET_NO); | ||
1190 | |||
1191 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removing zone iterator\n"); | ||
1192 | GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, zi); | ||
1193 | GNUNET_free (zi); | ||
1194 | return; | ||
1190 | } | 1195 | } |
1191 | else | 1196 | else |
1192 | zipr->have_signature = GNUNET_NO; | ||
1193 | |||
1194 | if ((rd_count > 0) && (rd != NULL)) | ||
1195 | { | 1197 | { |
1196 | len = GNUNET_NAMESTORE_records_get_size(rd_count, rd); | 1198 | struct ZoneIterationResponseMessage *zir_msg; |
1197 | zipr->rd_ser = GNUNET_malloc (len); | 1199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending name `%s' for iterating zone `%s'\n", name, GNUNET_h2s(&zi->zone)); |
1198 | GNUNET_NAMESTORE_records_serialize(rd_count, rd, len, zipr->rd_ser); | 1200 | size_t name_len; |
1199 | zipr->rd_ser_len = len; | 1201 | size_t rd_ser_len; |
1202 | size_t msg_size; | ||
1203 | char *name_tmp; | ||
1204 | char *rd_tmp; | ||
1205 | name_len = strlen (name) +1; | ||
1206 | |||
1207 | rd_ser_len = GNUNET_NAMESTORE_records_get_size(rd_count, rd); | ||
1208 | char rd_ser[rd_ser_len]; | ||
1209 | GNUNET_NAMESTORE_records_serialize(rd_count, rd, rd_ser_len, rd_ser); | ||
1210 | msg_size = sizeof (struct ZoneIterationResponseMessage) + name_len + rd_ser_len; | ||
1211 | zir_msg = GNUNET_malloc(msg_size); | ||
1212 | |||
1213 | name_tmp = (char *) &zir_msg[1]; | ||
1214 | rd_tmp = &name_tmp[name_len]; | ||
1215 | |||
1216 | zir_msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE); | ||
1217 | zir_msg->gns_header.header.size = htons (msg_size); | ||
1218 | zir_msg->gns_header.r_id = htonl(zi->request_id); | ||
1219 | zir_msg->expire = GNUNET_TIME_absolute_hton(expire); | ||
1220 | zir_msg->reserved = htons (0); | ||
1221 | zir_msg->name_len = htons (name_len); | ||
1222 | zir_msg->rd_count = htons (rd_count); | ||
1223 | zir_msg->rd_len = htons (rd_ser_len); | ||
1224 | zir_msg->signature = *signature; | ||
1225 | zir_msg->public_key = *zone_key; | ||
1226 | memcpy (name_tmp, name, name_len); | ||
1227 | memcpy (rd_tmp, rd_ser, rd_ser_len); | ||
1228 | |||
1229 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending empty `%s' message with size %u\n", "ZONE_ITERATION_RESPONSE", msg_size); | ||
1230 | GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) zir_msg, GNUNET_NO); | ||
1231 | GNUNET_free (zir_msg); | ||
1200 | } | 1232 | } |
1201 | } | 1233 | } |
1202 | 1234 | ||
@@ -1209,8 +1241,6 @@ static void handle_iteration_start (void *cls, | |||
1209 | struct ZoneIterationStartMessage * zis_msg = (struct ZoneIterationStartMessage *) message; | 1241 | struct ZoneIterationStartMessage * zis_msg = (struct ZoneIterationStartMessage *) message; |
1210 | struct GNUNET_NAMESTORE_Client *nc; | 1242 | struct GNUNET_NAMESTORE_Client *nc; |
1211 | struct GNUNET_NAMESTORE_ZoneIteration *zi; | 1243 | struct GNUNET_NAMESTORE_ZoneIteration *zi; |
1212 | struct ZoneIterationResponseMessage zir_msg; | ||
1213 | struct ZoneIterationProcResult zipr; | ||
1214 | int res; | 1244 | int res; |
1215 | 1245 | ||
1216 | nc = client_lookup(client); | 1246 | nc = client_lookup(client); |
@@ -1227,33 +1257,24 @@ static void handle_iteration_start (void *cls, | |||
1227 | zi->client = nc; | 1257 | zi->client = nc; |
1228 | zi->zone = zis_msg->zone; | 1258 | zi->zone = zis_msg->zone; |
1229 | 1259 | ||
1230 | GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi); | 1260 | GNUNET_HashCode dummy; |
1231 | 1261 | GNUNET_HashCode *zone_tmp; | |
1232 | res = GSN_database->iterate_records (GSN_database->cls, &zis_msg->zone, NULL, zi->offset , &zone_iteration_proc, &zipr); | 1262 | memset (&dummy, '\0', sizeof (dummy)); |
1233 | switch (res) { | 1263 | if (0 == memcmp (&dummy, &zis_msg->zone, sizeof (dummy))) |
1234 | case GNUNET_OK: | 1264 | { |
1235 | /* GNUNET_OK on success */ | 1265 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to iterate over all zones\n"); |
1236 | 1266 | zone_tmp = NULL; | |
1237 | break; | 1267 | } |
1238 | case GNUNET_SYSERR: | 1268 | else |
1239 | /* GNUNET_SYSERR on error */ | 1269 | { |
1240 | break; | 1270 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to iterate over zone `%s'\n", GNUNET_h2s (&zis_msg->zone)); |
1241 | case GNUNET_NO: | 1271 | zone_tmp = &zis_msg->zone; |
1242 | /* GNUNET_NO if there were no results, */ | ||
1243 | break; | ||
1244 | default: | ||
1245 | break; | ||
1246 | } | 1272 | } |
1247 | 1273 | ||
1274 | GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi); | ||
1248 | 1275 | ||
1249 | 1276 | ||
1250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "ZONE_ITERATION_RESPONSE"); | 1277 | res = GSN_database->iterate_records (GSN_database->cls, zone_tmp , NULL, zi->offset , &zone_iteration_proc, zi); |
1251 | zir_msg.gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE); | ||
1252 | zir_msg.gns_header.header.size = htons (sizeof (struct ZoneIterationResponseMessage)); | ||
1253 | zir_msg.gns_header.r_id = htonl(zi->request_id); | ||
1254 | |||
1255 | GNUNET_SERVER_notification_context_unicast (snc, zi->client->client, (const struct GNUNET_MessageHeader *) &zir_msg, GNUNET_NO); | ||
1256 | |||
1257 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1278 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1258 | } | 1279 | } |
1259 | 1280 | ||
@@ -1327,9 +1348,10 @@ static void handle_iteration_next (void *cls, | |||
1327 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1348 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1328 | return; | 1349 | return; |
1329 | } | 1350 | } |
1330 | |||
1331 | zi->offset++; | 1351 | zi->offset++; |
1352 | |||
1332 | GSN_database->iterate_records (GSN_database->cls, &zi->zone, NULL, zi->offset , &zone_iteration_proc, zi); | 1353 | GSN_database->iterate_records (GSN_database->cls, &zi->zone, NULL, zi->offset , &zone_iteration_proc, zi); |
1354 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
1333 | } | 1355 | } |
1334 | 1356 | ||
1335 | 1357 | ||