diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-04-01 15:51:38 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-04-01 15:51:38 +0000 |
commit | d816ced9a78620f055abc3c556736ee2887f1603 (patch) | |
tree | a398d5764fb40495f4724cf13c30dcad530180a2 /src/dv/gnunet-service-dv.c | |
parent | 36bfd342bf5703f0f482e0ea0c6adf0682f3d014 (diff) | |
download | gnunet-d816ced9a78620f055abc3c556736ee2887f1603.tar.gz gnunet-d816ced9a78620f055abc3c556736ee2887f1603.zip |
dv changes, closer to a working state
Diffstat (limited to 'src/dv/gnunet-service-dv.c')
-rw-r--r-- | src/dv/gnunet-service-dv.c | 232 |
1 files changed, 208 insertions, 24 deletions
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c index ebf8e82fe..ce996dda3 100644 --- a/src/dv/gnunet-service-dv.c +++ b/src/dv/gnunet-service-dv.c | |||
@@ -37,6 +37,9 @@ | |||
37 | #include "gnunet_core_service.h" | 37 | #include "gnunet_core_service.h" |
38 | #include "gnunet_signal_lib.h" | 38 | #include "gnunet_signal_lib.h" |
39 | #include "gnunet_util_lib.h" | 39 | #include "gnunet_util_lib.h" |
40 | #include "gnunet_hello_lib.h" | ||
41 | #include "gnunet_peerinfo_service.h" | ||
42 | #include "gnunet_crypto_lib.h" | ||
40 | #include "dv.h" | 43 | #include "dv.h" |
41 | 44 | ||
42 | /** | 45 | /** |
@@ -217,6 +220,11 @@ struct DirectNeighbor | |||
217 | struct GNUNET_PeerIdentity identity; | 220 | struct GNUNET_PeerIdentity identity; |
218 | 221 | ||
219 | /** | 222 | /** |
223 | * PublicKey of neighbor. | ||
224 | */ | ||
225 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; | ||
226 | |||
227 | /** | ||
220 | * Head of DLL of nodes that this direct neighbor referred to us. | 228 | * Head of DLL of nodes that this direct neighbor referred to us. |
221 | */ | 229 | */ |
222 | struct DistantNeighbor *referee_head; | 230 | struct DistantNeighbor *referee_head; |
@@ -277,6 +285,11 @@ struct DistantNeighbor | |||
277 | struct GNUNET_PeerIdentity identity; | 285 | struct GNUNET_PeerIdentity identity; |
278 | 286 | ||
279 | /** | 287 | /** |
288 | * PublicKey of neighbor. | ||
289 | */ | ||
290 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; | ||
291 | |||
292 | /** | ||
280 | * Last time we received routing information from this peer | 293 | * Last time we received routing information from this peer |
281 | */ | 294 | */ |
282 | struct GNUNET_TIME_Absolute last_activity; | 295 | struct GNUNET_TIME_Absolute last_activity; |
@@ -302,8 +315,45 @@ struct DistantNeighbor | |||
302 | * from DV? | 315 | * from DV? |
303 | */ | 316 | */ |
304 | int hidden; | 317 | int hidden; |
318 | |||
305 | }; | 319 | }; |
306 | 320 | ||
321 | struct PeerIteratorContext | ||
322 | { | ||
323 | /** | ||
324 | * The actual context, to be freed later. | ||
325 | */ | ||
326 | struct GNUNET_PEERINFO_IteratorContext *ic; | ||
327 | |||
328 | /** | ||
329 | * The neighbor about which we are concerned. | ||
330 | */ | ||
331 | struct DirectNeighbor *neighbor; | ||
332 | |||
333 | }; | ||
334 | |||
335 | /** | ||
336 | * Context used for creating hello messages when | ||
337 | * gossips are received. | ||
338 | */ | ||
339 | struct HelloContext | ||
340 | { | ||
341 | /** | ||
342 | * Identity of distant neighbor. | ||
343 | */ | ||
344 | struct GNUNET_PeerIdentity *distant_peer; | ||
345 | |||
346 | /** | ||
347 | * Identity of direct neighbor, via which we send this message. | ||
348 | */ | ||
349 | const struct GNUNET_PeerIdentity *direct_peer; | ||
350 | |||
351 | /** | ||
352 | * How many addresses do we need to add (always starts at 1, then set to 0) | ||
353 | */ | ||
354 | int addresses_to_add; | ||
355 | |||
356 | }; | ||
307 | 357 | ||
308 | /** | 358 | /** |
309 | * Global construct | 359 | * Global construct |
@@ -387,7 +437,7 @@ find_destination (void *cls, | |||
387 | * @return number of bytes written to buf | 437 | * @return number of bytes written to buf |
388 | */ | 438 | */ |
389 | size_t transmit_to_plugin (void *cls, | 439 | size_t transmit_to_plugin (void *cls, |
390 | size_t size, void *buf) | 440 | size_t size, void *buf) |
391 | { | 441 | { |
392 | struct GNUNET_DV_MessageReceived *msg = cls; | 442 | struct GNUNET_DV_MessageReceived *msg = cls; |
393 | int msize; | 443 | int msize; |
@@ -395,17 +445,25 @@ size_t transmit_to_plugin (void *cls, | |||
395 | if (buf == NULL) | 445 | if (buf == NULL) |
396 | return 0; | 446 | return 0; |
397 | 447 | ||
448 | #if DEBUG_DV | ||
449 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
450 | "%s: Transmit to plugin sending message of type %d!\n", "dv", ntohs(msg->header.type)); | ||
451 | #endif | ||
452 | |||
398 | msize = ntohs(msg->header.size); | 453 | msize = ntohs(msg->header.size); |
399 | GNUNET_assert(size >= msize); | 454 | GNUNET_assert(size >= msize); |
400 | 455 | ||
401 | |||
402 | memcpy(buf, msg, msize); | 456 | memcpy(buf, msg, msize); |
403 | GNUNET_free(msg); | 457 | /* FIXME: this causes crash? GNUNET_free(msg);*/ |
404 | return msize; | 458 | return msize; |
405 | } | 459 | } |
406 | 460 | ||
407 | 461 | ||
408 | void send_to_plugin(const struct GNUNET_PeerIdentity * sender, const struct GNUNET_MessageHeader *message, size_t message_size, struct DistantNeighbor *distant_neighbor) | 462 | void send_to_plugin(const struct GNUNET_PeerIdentity * sender, |
463 | const struct GNUNET_MessageHeader *message, | ||
464 | size_t message_size, | ||
465 | struct GNUNET_PeerIdentity *distant_neighbor, | ||
466 | size_t cost) | ||
409 | { | 467 | { |
410 | struct GNUNET_DV_MessageReceived *received_msg; | 468 | struct GNUNET_DV_MessageReceived *received_msg; |
411 | int size; | 469 | int size; |
@@ -415,19 +473,21 @@ void send_to_plugin(const struct GNUNET_PeerIdentity * sender, const struct GNUN | |||
415 | received_msg->header.size = htons(size); | 473 | received_msg->header.size = htons(size); |
416 | received_msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE); | 474 | received_msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE); |
417 | received_msg->sender_address_len = sizeof(struct GNUNET_PeerIdentity); | 475 | received_msg->sender_address_len = sizeof(struct GNUNET_PeerIdentity); |
418 | received_msg->distance = htonl(distant_neighbor->cost); | 476 | received_msg->distance = htonl(cost); |
419 | received_msg->msg_len = htons(message_size); | 477 | received_msg->msg_len = htons(message_size); |
420 | /* Set the sender in this message to be the original sender! */ | 478 | /* Set the sender in this message to be the original sender! */ |
421 | memcpy(&received_msg->sender, &distant_neighbor->identity, sizeof(struct GNUNET_PeerIdentity)); | 479 | memcpy(&received_msg->sender, &distant_neighbor, sizeof(struct GNUNET_PeerIdentity)); |
422 | /* Copy the intermediate sender to the end of the message, this is how the transport identifies this peer */ | 480 | /* Copy the intermediate sender to the end of the message, this is how the transport identifies this peer */ |
423 | memcpy(&received_msg[1], sender, sizeof(struct GNUNET_PeerIdentity)); | 481 | memcpy(&received_msg[1], sender, sizeof(struct GNUNET_PeerIdentity)); |
424 | /* Copy the actual message after the sender */ | 482 | /* Copy the actual message after the sender */ |
425 | memcpy(&received_msg[1 + sizeof(struct GNUNET_PeerIdentity)], message, message_size); | 483 | memcpy(&received_msg[1 + sizeof(struct GNUNET_PeerIdentity)], message, message_size); |
426 | 484 | ||
427 | /* FIXME: Send to the client please */ | 485 | if (client_handle != NULL) |
428 | GNUNET_SERVER_notify_transmit_ready (client_handle, | 486 | { |
429 | size, client_transmit_timeout, | 487 | GNUNET_SERVER_notify_transmit_ready (client_handle, |
430 | &transmit_to_plugin, &received_msg); | 488 | size, client_transmit_timeout, |
489 | &transmit_to_plugin, received_msg); | ||
490 | } | ||
431 | 491 | ||
432 | } | 492 | } |
433 | 493 | ||
@@ -612,7 +672,7 @@ static int handle_dv_data_message (void *cls, | |||
612 | if ( (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP) && | 672 | if ( (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP) && |
613 | (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_DATA) ) | 673 | (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_DATA) ) |
614 | { | 674 | { |
615 | send_to_plugin(peer, packed_message, ntohs(packed_message->size), pos); | 675 | send_to_plugin(peer, packed_message, ntohs(packed_message->size), &pos->identity, pos->cost); |
616 | } | 676 | } |
617 | 677 | ||
618 | return GNUNET_OK; | 678 | return GNUNET_OK; |
@@ -730,6 +790,8 @@ neighbor_send_task (void *cls, | |||
730 | message->header.type = htons (GNUNET_MESSAGE_TYPE_DV_GOSSIP); | 790 | message->header.type = htons (GNUNET_MESSAGE_TYPE_DV_GOSSIP); |
731 | message->cost = htonl (about->cost); | 791 | message->cost = htonl (about->cost); |
732 | message->neighbor_id = htonl (about->our_id); | 792 | message->neighbor_id = htonl (about->our_id); |
793 | |||
794 | memcpy (&message->pkey, &about->pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | ||
733 | memcpy (&message->neighbor, | 795 | memcpy (&message->neighbor, |
734 | &about->identity, sizeof (struct GNUNET_PeerIdentity)); | 796 | &about->identity, sizeof (struct GNUNET_PeerIdentity)); |
735 | 797 | ||
@@ -753,6 +815,32 @@ neighbor_send_task (void *cls, | |||
753 | 815 | ||
754 | 816 | ||
755 | /** | 817 | /** |
818 | * Handle START-message. This is the first message sent to us | ||
819 | * by the client (can only be one!). | ||
820 | * | ||
821 | * @param cls closure (always NULL) | ||
822 | * @param client identification of the client | ||
823 | * @param message the actual message | ||
824 | */ | ||
825 | static void | ||
826 | handle_start (void *cls, | ||
827 | struct GNUNET_SERVER_Client *client, | ||
828 | const struct GNUNET_MessageHeader *message) | ||
829 | { | ||
830 | |||
831 | #if DEBUG_DV | ||
832 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
833 | "Received `%s' request from client\n", "START"); | ||
834 | #endif | ||
835 | |||
836 | GNUNET_assert(client_handle == NULL); | ||
837 | client_handle = client; | ||
838 | |||
839 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
840 | } | ||
841 | |||
842 | |||
843 | /** | ||
756 | * Service server's handler for message send requests (which come | 844 | * Service server's handler for message send requests (which come |
757 | * bubbling up to us through the DV plugin). | 845 | * bubbling up to us through the DV plugin). |
758 | * | 846 | * |
@@ -812,6 +900,7 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = { | |||
812 | 900 | ||
813 | static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { | 901 | static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { |
814 | {&send_dv_message, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND, 0}, | 902 | {&send_dv_message, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND, 0}, |
903 | {&handle_start, NULL, GNUNET_MESSAGE_TYPE_DV_START, 0}, | ||
815 | {NULL, NULL, 0, 0} | 904 | {NULL, NULL, 0, 0} |
816 | }; | 905 | }; |
817 | 906 | ||
@@ -915,12 +1004,13 @@ distant_neighbor_free (struct DistantNeighbor *referee) | |||
915 | * needs to be updated. | 1004 | * needs to be updated. |
916 | * | 1005 | * |
917 | * @param peer identity of the peer whose info is being added/updated | 1006 | * @param peer identity of the peer whose info is being added/updated |
1007 | * @param pkey public key of the peer whose info is being added/updated | ||
918 | * @param referrer_peer_id id to use when sending to 'peer' | 1008 | * @param referrer_peer_id id to use when sending to 'peer' |
919 | * @param referrer if this is a gossiped peer, who did we hear it from? | 1009 | * @param referrer if this is a gossiped peer, who did we hear it from? |
920 | * @param cost the cost of communicating with this peer via 'referrer' | 1010 | * @param cost the cost of communicating with this peer via 'referrer' |
921 | */ | 1011 | */ |
922 | static void | 1012 | static void |
923 | addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer, | 1013 | addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer, struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey, |
924 | unsigned int referrer_peer_id, | 1014 | unsigned int referrer_peer_id, |
925 | struct DirectNeighbor *referrer, unsigned int cost) | 1015 | struct DirectNeighbor *referrer, unsigned int cost) |
926 | { | 1016 | { |
@@ -984,6 +1074,8 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer, | |||
984 | neighbor, cost); | 1074 | neighbor, cost); |
985 | neighbor->referrer = referrer; | 1075 | neighbor->referrer = referrer; |
986 | memcpy (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity)); | 1076 | memcpy (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity)); |
1077 | if (pkey != NULL) /* pkey will be null on direct neighbor addition */ | ||
1078 | memcpy (&neighbor->pkey, pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | ||
987 | neighbor->last_activity = now; | 1079 | neighbor->last_activity = now; |
988 | neighbor->cost = cost; | 1080 | neighbor->cost = cost; |
989 | neighbor->referrer_id = referrer_peer_id; | 1081 | neighbor->referrer_id = referrer_peer_id; |
@@ -1026,6 +1118,42 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer, | |||
1026 | */ | 1118 | */ |
1027 | } | 1119 | } |
1028 | 1120 | ||
1121 | |||
1122 | static size_t | ||
1123 | generate_hello_address (void *cls, size_t max, void *buf) | ||
1124 | { | ||
1125 | struct HelloContext *hello_context = cls; | ||
1126 | char *addr_buffer; | ||
1127 | size_t offset; | ||
1128 | size_t size; | ||
1129 | size_t ret; | ||
1130 | |||
1131 | if (hello_context->addresses_to_add == 0) | ||
1132 | return 0; | ||
1133 | |||
1134 | /* Hello "address" will be concatenation of distant peer and direct peer identities */ | ||
1135 | size = 2 * sizeof(struct GNUNET_PeerIdentity); | ||
1136 | fprintf(stdout, "size is %lu, max is %lu\n", size, max); | ||
1137 | GNUNET_assert(max >= size); | ||
1138 | |||
1139 | addr_buffer = GNUNET_malloc(size); | ||
1140 | offset = 0; | ||
1141 | /* Copy the distant peer identity to buffer */ | ||
1142 | memcpy(addr_buffer, hello_context->distant_peer, sizeof(struct GNUNET_PeerIdentity)); | ||
1143 | offset += sizeof(struct GNUNET_PeerIdentity); | ||
1144 | /* Copy the direct peer identity to buffer */ | ||
1145 | memcpy(&addr_buffer[offset], hello_context->direct_peer, sizeof(struct GNUNET_PeerIdentity)); | ||
1146 | ret = GNUNET_HELLO_add_address ("dv", | ||
1147 | GNUNET_TIME_relative_to_absolute | ||
1148 | (GNUNET_TIME_UNIT_HOURS), addr_buffer, size, | ||
1149 | buf, max); | ||
1150 | |||
1151 | hello_context->addresses_to_add--; | ||
1152 | |||
1153 | return ret; | ||
1154 | } | ||
1155 | |||
1156 | |||
1029 | /** | 1157 | /** |
1030 | * Core handler for dv gossip messages. These will be used | 1158 | * Core handler for dv gossip messages. These will be used |
1031 | * by us to create a HELLO message for the newly peer containing | 1159 | * by us to create a HELLO message for the newly peer containing |
@@ -1045,13 +1173,20 @@ static int handle_dv_gossip_message (void *cls, | |||
1045 | struct GNUNET_TIME_Relative latency, | 1173 | struct GNUNET_TIME_Relative latency, |
1046 | uint32_t distance) | 1174 | uint32_t distance) |
1047 | { | 1175 | { |
1048 | #if DEBUG_DV | 1176 | struct HelloContext *hello_context; |
1049 | char * encPeerAbout; | 1177 | struct GNUNET_HELLO_Message *hello_msg; |
1050 | char * encPeerFrom; | ||
1051 | #endif | ||
1052 | struct DirectNeighbor *referrer; | 1178 | struct DirectNeighbor *referrer; |
1053 | p2p_dv_MESSAGE_NeighborInfo *enc_message = (p2p_dv_MESSAGE_NeighborInfo *)message; | 1179 | p2p_dv_MESSAGE_NeighborInfo *enc_message = (p2p_dv_MESSAGE_NeighborInfo *)message; |
1180 | |||
1181 | if (ntohs (message->size) < sizeof (p2p_dv_MESSAGE_NeighborInfo)) | ||
1182 | { | ||
1183 | return GNUNET_SYSERR; /* invalid message */ | ||
1184 | } | ||
1185 | |||
1054 | #if DEBUG_DV | 1186 | #if DEBUG_DV |
1187 | char * encPeerAbout; | ||
1188 | char * encPeerFrom; | ||
1189 | |||
1055 | encPeerAbout = GNUNET_strdup(GNUNET_i2s(&enc_message->neighbor)); | 1190 | encPeerAbout = GNUNET_strdup(GNUNET_i2s(&enc_message->neighbor)); |
1056 | encPeerFrom = GNUNET_strdup(GNUNET_i2s(peer)); | 1191 | encPeerFrom = GNUNET_strdup(GNUNET_i2s(peer)); |
1057 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1192 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1060,23 +1195,58 @@ static int handle_dv_gossip_message (void *cls, | |||
1060 | GNUNET_free(encPeerFrom); | 1195 | GNUNET_free(encPeerFrom); |
1061 | #endif | 1196 | #endif |
1062 | 1197 | ||
1063 | if (ntohs (message->size) < sizeof (p2p_dv_MESSAGE_NeighborInfo)) | ||
1064 | { | ||
1065 | return GNUNET_SYSERR; /* invalid message */ | ||
1066 | } | ||
1067 | |||
1068 | referrer = GNUNET_CONTAINER_multihashmap_get (ctx.direct_neighbors, | 1198 | referrer = GNUNET_CONTAINER_multihashmap_get (ctx.direct_neighbors, |
1069 | &peer->hashPubKey); | 1199 | &peer->hashPubKey); |
1070 | if (referrer == NULL) | 1200 | if (referrer == NULL) |
1071 | return GNUNET_OK; | 1201 | return GNUNET_OK; |
1072 | 1202 | ||
1073 | addUpdateNeighbor (&enc_message->neighbor, | 1203 | addUpdateNeighbor (&enc_message->neighbor, &enc_message->pkey, |
1074 | ntohl (enc_message->neighbor_id), | 1204 | ntohl (enc_message->neighbor_id), |
1075 | referrer, ntohl (enc_message->cost) + 1); | 1205 | referrer, ntohl (enc_message->cost) + 1); |
1076 | 1206 | ||
1207 | hello_context = GNUNET_malloc(sizeof(struct HelloContext)); | ||
1208 | hello_context->direct_peer = peer; | ||
1209 | hello_context->distant_peer = &enc_message->neighbor; | ||
1210 | hello_context->addresses_to_add = 1; | ||
1211 | hello_msg = GNUNET_HELLO_create(&enc_message->pkey, &generate_hello_address, hello_context); | ||
1212 | |||
1213 | #if DEBUG_DV | ||
1214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1215 | "%s: Sending %s message to plugin!\n", "dv", "HELLO"); | ||
1216 | #endif | ||
1217 | |||
1218 | send_to_plugin(&enc_message->neighbor, GNUNET_HELLO_get_header(hello_msg), GNUNET_HELLO_size(hello_msg), hello_context->distant_peer, ntohl(enc_message->cost) + 1); | ||
1077 | return GNUNET_OK; | 1219 | return GNUNET_OK; |
1078 | } | 1220 | } |
1079 | 1221 | ||
1222 | static void | ||
1223 | process_peerinfo (void *cls, | ||
1224 | const struct GNUNET_PeerIdentity *peer, | ||
1225 | const struct GNUNET_HELLO_Message *hello, uint32_t trust) | ||
1226 | { | ||
1227 | struct PeerIteratorContext *peerinfo_iterator = cls; | ||
1228 | struct DirectNeighbor *neighbor = peerinfo_iterator->neighbor; | ||
1229 | |||
1230 | #if DEBUG_DV | ||
1231 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1232 | "%s: process_peerinfo called!\n", "dv"); | ||
1233 | #endif | ||
1234 | |||
1235 | if ((peer == NULL))/* && (neighbor->pkey == NULL))*/ | ||
1236 | { | ||
1237 | /* FIXME: Remove peer! */ | ||
1238 | return; | ||
1239 | } | ||
1240 | |||
1241 | if (memcmp(&neighbor->identity, peer, sizeof(struct GNUNET_PeerIdentity) != 0)) | ||
1242 | return; | ||
1243 | |||
1244 | if ((hello != NULL) && (GNUNET_HELLO_get_key (hello, &neighbor->pkey) == GNUNET_OK)) | ||
1245 | { | ||
1246 | neighbor->send_context->task = GNUNET_SCHEDULER_add_now(sched, &neighbor_send_task, neighbor->send_context); | ||
1247 | } | ||
1248 | } | ||
1249 | |||
1080 | /** | 1250 | /** |
1081 | * Method called whenever a peer connects. | 1251 | * Method called whenever a peer connects. |
1082 | * | 1252 | * |
@@ -1091,6 +1261,7 @@ void handle_core_connect (void *cls, | |||
1091 | uint32_t distance) | 1261 | uint32_t distance) |
1092 | { | 1262 | { |
1093 | struct DirectNeighbor *neighbor; | 1263 | struct DirectNeighbor *neighbor; |
1264 | struct PeerIteratorContext *peerinfo_iterator; | ||
1094 | #if DEBUG_DV | 1265 | #if DEBUG_DV |
1095 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1266 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1096 | "%s: Receives core connect message for peer %s distance %d!\n", "dv", GNUNET_i2s(peer), distance); | 1267 | "%s: Receives core connect message for peer %s distance %d!\n", "dv", GNUNET_i2s(peer), distance); |
@@ -1098,16 +1269,29 @@ void handle_core_connect (void *cls, | |||
1098 | 1269 | ||
1099 | if ((distance == 0) && (GNUNET_CONTAINER_multihashmap_get(ctx.direct_neighbors, &peer->hashPubKey) == NULL)) | 1270 | if ((distance == 0) && (GNUNET_CONTAINER_multihashmap_get(ctx.direct_neighbors, &peer->hashPubKey) == NULL)) |
1100 | { | 1271 | { |
1272 | peerinfo_iterator = GNUNET_malloc(sizeof(struct PeerIteratorContext)); | ||
1101 | neighbor = GNUNET_malloc (sizeof (struct DirectNeighbor)); | 1273 | neighbor = GNUNET_malloc (sizeof (struct DirectNeighbor)); |
1102 | neighbor->send_context = GNUNET_malloc(sizeof(struct NeighborSendContext)); | 1274 | neighbor->send_context = GNUNET_malloc(sizeof(struct NeighborSendContext)); |
1103 | neighbor->send_context->toNeighbor = neighbor; | 1275 | neighbor->send_context->toNeighbor = neighbor; |
1104 | neighbor->send_context->timeout = default_dv_delay; /* FIXME: base this on total gossip tasks, or bandwidth */ | 1276 | neighbor->send_context->timeout = default_dv_delay; /* FIXME: base this on total gossip tasks, or bandwidth */ |
1105 | memcpy (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity)); | 1277 | memcpy (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity)); |
1278 | /*memcpy (&neighbor->pkey, ,sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));*/ | ||
1106 | GNUNET_CONTAINER_multihashmap_put (ctx.direct_neighbors, | 1279 | GNUNET_CONTAINER_multihashmap_put (ctx.direct_neighbors, |
1107 | &peer->hashPubKey, | 1280 | &peer->hashPubKey, |
1108 | neighbor, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 1281 | neighbor, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
1109 | addUpdateNeighbor (peer, 0, neighbor, 0); | 1282 | addUpdateNeighbor (peer, NULL, 0, neighbor, 0); |
1110 | neighbor->send_context->task = GNUNET_SCHEDULER_add_now(sched, &neighbor_send_task, neighbor->send_context); | 1283 | peerinfo_iterator->neighbor = neighbor; |
1284 | peerinfo_iterator->ic = GNUNET_PEERINFO_iterate (cfg, | ||
1285 | sched, | ||
1286 | peer, | ||
1287 | 0, | ||
1288 | GNUNET_TIME_relative_multiply | ||
1289 | (GNUNET_TIME_UNIT_SECONDS, 15), | ||
1290 | &process_peerinfo, peerinfo_iterator); | ||
1291 | /* Only add once we get the publicKey of this guy | ||
1292 | * | ||
1293 | * neighbor->send_context->task = GNUNET_SCHEDULER_add_now(sched, &neighbor_send_task, neighbor->send_context); | ||
1294 | */ | ||
1111 | } | 1295 | } |
1112 | else | 1296 | else |
1113 | { | 1297 | { |