summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dv/Makefile.am2
-rw-r--r--src/dv/dv.h6
-rw-r--r--src/dv/dv_api.c68
-rw-r--r--src/dv/gnunet-service-dv.c232
-rw-r--r--src/dv/plugin_transport_dv.c8
-rw-r--r--src/dv/test_transport_api_dv_peer1.conf4
6 files changed, 289 insertions, 31 deletions
diff --git a/src/dv/Makefile.am b/src/dv/Makefile.am
index 9b5761f32..0dc4afb08 100644
--- a/src/dv/Makefile.am
+++ b/src/dv/Makefile.am
@@ -33,6 +33,8 @@ gnunet_service_dv_SOURCES = \
33 gnunet-service-dv.c 33 gnunet-service-dv.c
34gnunet_service_dv_LDADD = \ 34gnunet_service_dv_LDADD = \
35 $(top_builddir)/src/dv/libgnunetdv.la \ 35 $(top_builddir)/src/dv/libgnunetdv.la \
36 $(top_builddir)/src/hello/libgnunethello.la \
37 $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \
36 $(top_builddir)/src/util/libgnunetutil.la \ 38 $(top_builddir)/src/util/libgnunetutil.la \
37 $(GN_LIBINTL) 39 $(GN_LIBINTL)
38 40
diff --git a/src/dv/dv.h b/src/dv/dv.h
index d43befd70..38c6f2a60 100644
--- a/src/dv/dv.h
+++ b/src/dv/dv.h
@@ -163,6 +163,7 @@ struct GNUNET_DV_SendMessage
163 */ 163 */
164typedef struct 164typedef struct
165{ 165{
166 /* Message Header */
166 struct GNUNET_MessageHeader header; 167 struct GNUNET_MessageHeader header;
167 168
168 /** 169 /**
@@ -176,6 +177,11 @@ typedef struct
176 struct GNUNET_PeerIdentity neighbor; 177 struct GNUNET_PeerIdentity neighbor;
177 178
178 /** 179 /**
180 * PublicKey of neighbor.
181 */
182 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
183
184 /**
179 * Neighbor ID to use when sending to this peer 185 * Neighbor ID to use when sending to this peer
180 */ 186 */
181 unsigned int neighbor_id GNUNET_PACKED; 187 unsigned int neighbor_id GNUNET_PACKED;
diff --git a/src/dv/dv_api.c b/src/dv/dv_api.c
index 7b1a4f0cf..abfb249e4 100644
--- a/src/dv/dv_api.c
+++ b/src/dv/dv_api.c
@@ -57,6 +57,8 @@ struct PendingMessages
57 57
58}; 58};
59 59
60
61
60/** 62/**
61 * Handle for the service. 63 * Handle for the service.
62 */ 64 */
@@ -110,6 +112,21 @@ struct GNUNET_DV_Handle
110}; 112};
111 113
112 114
115struct StartContext
116{
117
118 /**
119 * Start message
120 */
121 struct GNUNET_MessageHeader *message;
122
123 /**
124 * Handle to service, in case of timeout
125 */
126 struct GNUNET_DV_Handle *handle;
127};
128
129
113/** 130/**
114 * Try to (re)connect to the dv service. 131 * Try to (re)connect to the dv service.
115 * 132 *
@@ -215,7 +232,7 @@ static void process_pending_message(struct GNUNET_DV_Handle *handle)
215 GNUNET_YES, 232 GNUNET_YES,
216 &transmit_pending, handle))) 233 &transmit_pending, handle)))
217 { 234 {
218#if DEBUG_STATISTICS 235#if DEBUG_DV
219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
220 "Failed to transmit request to dv service.\n"); 237 "Failed to transmit request to dv service.\n");
221#endif 238#endif
@@ -259,8 +276,6 @@ static void add_pending(struct GNUNET_DV_Handle *handle, struct GNUNET_DV_SendMe
259} 276}
260 277
261 278
262
263
264void handle_message_receipt (void *cls, 279void handle_message_receipt (void *cls,
265 const struct GNUNET_MessageHeader * msg) 280 const struct GNUNET_MessageHeader * msg)
266{ 281{
@@ -276,6 +291,9 @@ void handle_message_receipt (void *cls,
276 return; /* Connection closed? */ 291 return; /* Connection closed? */
277 } 292 }
278 293
294#if DEBUG_DV
295 fprintf(stdout, "dv api receives message of type %d or raw %d\n", ntohs(msg->type), msg->type);
296#endif
279 GNUNET_assert(ntohs(msg->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE); 297 GNUNET_assert(ntohs(msg->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE);
280 298
281 if (ntohs(msg->size) < sizeof(struct GNUNET_DV_MessageReceived)) 299 if (ntohs(msg->size) < sizeof(struct GNUNET_DV_MessageReceived))
@@ -348,6 +366,34 @@ int GNUNET_DV_send (struct GNUNET_DV_Handle *dv_handle,
348 return GNUNET_OK; 366 return GNUNET_OK;
349} 367}
350 368
369/* Forward declaration */
370void GNUNET_DV_disconnect(struct GNUNET_DV_Handle *handle);
371
372static size_t
373transmit_start (void *cls, size_t size, void *buf)
374{
375 struct StartContext *start_context = cls;
376 struct GNUNET_DV_Handle *handle = start_context->handle;
377 size_t tsize;
378
379 if (buf == NULL)
380 {
381 GNUNET_free(start_context->message);
382 GNUNET_free(start_context);
383 GNUNET_DV_disconnect(handle);
384 return 0;
385 }
386
387 tsize = ntohs(start_context->message->size);
388 if (size >= tsize)
389 {
390 memcpy(buf, start_context->message, tsize);
391 return tsize;
392 }
393
394 return 0;
395}
396
351/** 397/**
352 * Connect to the DV service 398 * Connect to the DV service
353 * 399 *
@@ -365,7 +411,8 @@ GNUNET_DV_connect (struct GNUNET_SCHEDULER_Handle *sched,
365 void *receive_handler_cls) 411 void *receive_handler_cls)
366{ 412{
367 struct GNUNET_DV_Handle *handle; 413 struct GNUNET_DV_Handle *handle;
368 414 struct GNUNET_MessageHeader *start_message;
415 struct StartContext *start_context;
369 handle = GNUNET_malloc(sizeof(struct GNUNET_DV_Handle)); 416 handle = GNUNET_malloc(sizeof(struct GNUNET_DV_Handle));
370 417
371 handle->cfg = cfg; 418 handle->cfg = cfg;
@@ -384,6 +431,19 @@ GNUNET_DV_connect (struct GNUNET_SCHEDULER_Handle *sched,
384 return NULL; 431 return NULL;
385 } 432 }
386 433
434 start_message = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader));
435 start_message->size = htons(sizeof(struct GNUNET_MessageHeader));
436 start_message->type = htons(GNUNET_MESSAGE_TYPE_DV_START);
437
438 start_context = GNUNET_malloc(sizeof(struct StartContext));
439 start_context->handle = handle;
440 start_context->message = start_message;
441 GNUNET_CLIENT_notify_transmit_ready (handle->client,
442 sizeof(struct GNUNET_MessageHeader),
443 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60),
444 GNUNET_YES,
445 &transmit_start, start_context);
446
387 GNUNET_CLIENT_receive (handle->client, 447 GNUNET_CLIENT_receive (handle->client,
388 &handle_message_receipt, 448 &handle_message_receipt,
389 handle, GNUNET_TIME_UNIT_FOREVER_REL); 449 handle, GNUNET_TIME_UNIT_FOREVER_REL);
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
321struct 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 */
339struct 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 */
389size_t transmit_to_plugin (void *cls, 439size_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
408void send_to_plugin(const struct GNUNET_PeerIdentity * sender, const struct GNUNET_MessageHeader *message, size_t message_size, struct DistantNeighbor *distant_neighbor) 462void 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 */
825static void
826handle_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
813static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { 901static 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 */
922static void 1012static void
923addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer, 1013addUpdateNeighbor (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
1122static size_t
1123generate_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
1222static void
1223process_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 {
diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c
index fa35fa5a8..c29b17e8c 100644
--- a/src/dv/plugin_transport_dv.c
+++ b/src/dv/plugin_transport_dv.c
@@ -166,6 +166,9 @@ struct Plugin
166 166
167}; 167};
168 168
169/**
170 * Handler for messages received from the DV service.
171 */
169void handle_dv_message_received (void *cls, 172void handle_dv_message_received (void *cls,
170 struct GNUNET_PeerIdentity *sender, 173 struct GNUNET_PeerIdentity *sender,
171 char *msg, 174 char *msg,
@@ -176,7 +179,10 @@ void handle_dv_message_received (void *cls,
176{ 179{
177 struct Plugin *plugin = cls; 180 struct Plugin *plugin = cls;
178 181
179 /* TODO: Add in demultiplexing if we think we'll be receiving multiple messages at once */ 182 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
183 "plugin_transport_dv",
184 _("Received message from %s of type %d!\n"),
185 "DV SERVICE", ntohs(((struct GNUNET_MessageHeader *)msg)->type));
180 plugin->env->receive(plugin, 186 plugin->env->receive(plugin,
181 sender, 187 sender,
182 (struct GNUNET_MessageHeader *)msg, 188 (struct GNUNET_MessageHeader *)msg,
diff --git a/src/dv/test_transport_api_dv_peer1.conf b/src/dv/test_transport_api_dv_peer1.conf
index 0f7b733ef..9da289fde 100644
--- a/src/dv/test_transport_api_dv_peer1.conf
+++ b/src/dv/test_transport_api_dv_peer1.conf
@@ -97,8 +97,8 @@ ALLOW_SHUTDOWN = YES
97ACCEPT_FROM6 = ::1; 97ACCEPT_FROM6 = ::1;
98ACCEPT_FROM = 127.0.0.1; 98ACCEPT_FROM = 127.0.0.1;
99BINARY = gnunet-service-dv 99BINARY = gnunet-service-dv
100#BINARY = /root/documents/research/gnunet/gnunet-ng/src/dv/.libs/gnunet-service-dv 100BINARY = /home/mrwiggles/documents/research/gnunet/gnunet-ng/src/dv/.libs/gnunet-service-dv
101#PREFIX = xterm -T dvservice -e gdb --args 101PREFIX = xterm -T dvservice -e gdb --args
102CONFIG = $DEFAULTCONFIG 102CONFIG = $DEFAULTCONFIG
103HOME = $SERVICEHOME 103HOME = $SERVICEHOME
104HOSTNAME = localhost 104HOSTNAME = localhost