aboutsummaryrefslogtreecommitdiff
path: root/src/dv
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-06-23 12:05:51 +0000
committerNathan S. Evans <evans@in.tum.de>2010-06-23 12:05:51 +0000
commitef1c9e128f922eeb930fa659e37d22256e6886d6 (patch)
tree8d502225d0e12443a96c567c66ffee417783430e /src/dv
parentfd9eec78a3c275401d4b661a49cd90b972c9f58d (diff)
downloadgnunet-ef1c9e128f922eeb930fa659e37d22256e6886d6.tar.gz
gnunet-ef1c9e128f922eeb930fa659e37d22256e6886d6.zip
tokenizer api change, a bit of source cleanup
Diffstat (limited to 'src/dv')
-rw-r--r--src/dv/gnunet-service-dv.c316
1 files changed, 191 insertions, 125 deletions
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c
index f2ba74ade..842b2dee7 100644
--- a/src/dv/gnunet-service-dv.c
+++ b/src/dv/gnunet-service-dv.c
@@ -54,30 +54,6 @@
54#define USE_PEER_ID GNUNET_YES 54#define USE_PEER_ID GNUNET_YES
55 55
56/** 56/**
57 * DV Service Context stuff goes here...
58 */
59
60/**
61 * Handle to the core service api.
62 */
63static struct GNUNET_CORE_Handle *coreAPI;
64
65/**
66 * The identity of our peer.
67 */
68static struct GNUNET_PeerIdentity my_identity;
69
70/**
71 * The configuration for this service.
72 */
73static const struct GNUNET_CONFIGURATION_Handle *cfg;
74
75/**
76 * The scheduler for this service.
77 */
78static struct GNUNET_SCHEDULER_Handle *sched;
79
80/**
81 * How often do we check about sending out more peer information (if 57 * How often do we check about sending out more peer information (if
82 * we are connected to no peers previously). 58 * we are connected to no peers previously).
83 */ 59 */
@@ -137,22 +113,6 @@ static struct GNUNET_SCHEDULER_Handle *sched;
137#define DEFAULT_FISHEYE_DEPTH 4 113#define DEFAULT_FISHEYE_DEPTH 4
138 114
139/** 115/**
140 * The client, the DV plugin connected to us. Hopefully
141 * this client will never change, although if the plugin dies
142 * and returns for some reason it may happen.
143 */
144static struct GNUNET_SERVER_Client * client_handle;
145
146/**
147 * Task to run when we shut down, cleaning up all our trash
148 */
149static GNUNET_SCHEDULER_TaskIdentifier cleanup_task;
150
151static size_t default_dv_priority = 0;
152
153static char *my_short_id;
154
155/**
156 * Linked list of messages to send to clients. 116 * Linked list of messages to send to clients.
157 */ 117 */
158struct PendingMessage 118struct PendingMessage
@@ -199,42 +159,6 @@ struct PendingMessage
199 159
200}; 160};
201 161
202/**
203 * Transmit handle to the plugin.
204 */
205static struct GNUNET_CONNECTION_TransmitHandle * plugin_transmit_handle;
206
207/**
208 * Head of DLL for client messages
209 */
210static struct PendingMessage *plugin_pending_head;
211
212/**
213 * Tail of DLL for client messages
214 */
215static struct PendingMessage *plugin_pending_tail;
216
217/**
218 * Handle to the peerinfo service
219 */
220static struct GNUNET_PEERINFO_Handle *peerinfo_handle;
221
222/**
223 * Transmit handle to core service.
224 */
225static struct GNUNET_CORE_TransmitHandle * core_transmit_handle;
226
227/**
228 * Head of DLL for core messages
229 */
230static struct PendingMessage *core_pending_head;
231
232/**
233 * Tail of DLL for core messages
234 */
235static struct PendingMessage *core_pending_tail;
236
237
238struct FastGossipNeighborList 162struct FastGossipNeighborList
239{ 163{
240 /** 164 /**
@@ -517,6 +441,135 @@ struct DV_SendContext
517 unsigned int uid; 441 unsigned int uid;
518}; 442};
519 443
444struct FindDestinationContext
445{
446 unsigned int tid;
447 struct DistantNeighbor *dest;
448};
449
450struct FindIDContext
451{
452 unsigned int tid;
453 struct GNUNET_PeerIdentity *dest;
454 const struct GNUNET_PeerIdentity *via;
455};
456
457struct DisconnectContext
458{
459 /**
460 * Distant neighbor to get pid from.
461 */
462 struct DistantNeighbor *distant;
463
464 /**
465 * Direct neighbor that disconnected.
466 */
467 struct DirectNeighbor *direct;
468};
469
470struct TokenizedMessageContext
471{
472 /**
473 * Immediate sender of this message
474 */
475 const struct GNUNET_PeerIdentity *peer;
476
477 /**
478 * Distant sender of the message
479 */
480 struct DistantNeighbor *distant;
481
482 /**
483 * Uid for this set of messages
484 */
485 uint32_t uid;
486};
487
488/**
489 * Context for finding the least cost peer to send to.
490 * Transport selection can only go so far.
491 */
492struct FindLeastCostContext
493{
494 struct DistantNeighbor *target;
495 unsigned int least_cost;
496};
497
498/**
499 * Handle to the core service api.
500 */
501static struct GNUNET_CORE_Handle *coreAPI;
502
503/**
504 * Stream tokenizer to handle messages coming in from core.
505 */
506struct GNUNET_SERVER_MessageStreamTokenizer *coreMST;
507
508/**
509 * The identity of our peer.
510 */
511static struct GNUNET_PeerIdentity my_identity;
512
513/**
514 * The configuration for this service.
515 */
516static const struct GNUNET_CONFIGURATION_Handle *cfg;
517
518/**
519 * The scheduler for this service.
520 */
521static struct GNUNET_SCHEDULER_Handle *sched;
522
523/**
524 * The client, the DV plugin connected to us. Hopefully
525 * this client will never change, although if the plugin dies
526 * and returns for some reason it may happen.
527 */
528static struct GNUNET_SERVER_Client * client_handle;
529
530/**
531 * Task to run when we shut down, cleaning up all our trash
532 */
533static GNUNET_SCHEDULER_TaskIdentifier cleanup_task;
534
535static size_t default_dv_priority = 0;
536
537static char *my_short_id;
538
539/**
540 * Transmit handle to the plugin.
541 */
542static struct GNUNET_CONNECTION_TransmitHandle * plugin_transmit_handle;
543
544/**
545 * Head of DLL for client messages
546 */
547static struct PendingMessage *plugin_pending_head;
548
549/**
550 * Tail of DLL for client messages
551 */
552static struct PendingMessage *plugin_pending_tail;
553
554/**
555 * Handle to the peerinfo service
556 */
557static struct GNUNET_PEERINFO_Handle *peerinfo_handle;
558
559/**
560 * Transmit handle to core service.
561 */
562static struct GNUNET_CORE_TransmitHandle * core_transmit_handle;
563
564/**
565 * Head of DLL for core messages
566 */
567static struct PendingMessage *core_pending_head;
568
569/**
570 * Tail of DLL for core messages
571 */
572static struct PendingMessage *core_pending_tail;
520 573
521/** 574/**
522 * Map of PeerIdentifiers to 'struct GNUNET_dv_neighbor*'s for all 575 * Map of PeerIdentifiers to 'struct GNUNET_dv_neighbor*'s for all
@@ -545,37 +598,16 @@ static struct GNUNET_CONTAINER_Heap *neighbor_min_heap;
545 */ 598 */
546static struct GNUNET_CONTAINER_Heap *neighbor_max_heap; 599static struct GNUNET_CONTAINER_Heap *neighbor_max_heap;
547 600
601/**
602 * How far out to keep peers we learn about.
603 */
548static unsigned long long fisheye_depth; 604static unsigned long long fisheye_depth;
549 605
606/**
607 * How many peers to store at most.
608 */
550static unsigned long long max_table_size; 609static unsigned long long max_table_size;
551 610
552
553struct FindDestinationContext
554{
555 unsigned int tid;
556 struct DistantNeighbor *dest;
557};
558
559struct FindIDContext
560{
561 unsigned int tid;
562 struct GNUNET_PeerIdentity *dest;
563 const struct GNUNET_PeerIdentity *via;
564};
565
566struct DisconnectContext
567{
568 /**
569 * Distant neighbor to get pid from.
570 */
571 struct DistantNeighbor *distant;
572
573 /**
574 * Direct neighbor that disconnected.
575 */
576 struct DirectNeighbor *direct;
577};
578
579/** 611/**
580 * We've been given a target ID based on the random numbers that 612 * We've been given a target ID based on the random numbers that
581 * we assigned to our DV-neighborhood. Find the entry for the 613 * we assigned to our DV-neighborhood. Find the entry for the
@@ -893,9 +925,6 @@ send_message_via (const struct GNUNET_PeerIdentity *sender,
893 find_context.dest = send_context->distant_peer; 925 find_context.dest = send_context->distant_peer;
894 find_context.via = recipient; 926 find_context.via = recipient;
895 find_context.tid = 0; 927 find_context.tid = 0;
896 //specific_neighbor = GNUNET_CONTAINER_multihashmap_get(extended_neighbors, &send_context->distant_peer->hashPubKey);
897
898 //GNUNET_CONTAINER_multihashmap_iterate(extended_neighbors, &find_specific_id, &find_context);
899 GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors, &send_context->distant_peer->hashPubKey, 928 GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors, &send_context->distant_peer->hashPubKey,
900 &find_specific_id, &find_context); 929 &find_specific_id, &find_context);
901 930
@@ -970,18 +999,6 @@ send_message_via (const struct GNUNET_PeerIdentity *sender,
970 return GNUNET_YES; 999 return GNUNET_YES;
971} 1000}
972 1001
973
974/**
975 * Context for finding the least cost peer to send to.
976 * Transport selection can only go so far.
977 */
978struct FindLeastCostContext
979{
980 struct DistantNeighbor *target;
981 unsigned int least_cost;
982};
983
984
985/** 1002/**
986 * Given a FindLeastCostContext, and a set 1003 * Given a FindLeastCostContext, and a set
987 * of peers that match the target, return the cheapest. 1004 * of peers that match the target, return the cheapest.
@@ -1175,6 +1192,34 @@ int checkPeerID (void *cls,
1175} 1192}
1176#endif 1193#endif
1177 1194
1195
1196/**
1197 * Handler for messages parsed out by the tokenizer from
1198 * DV DATA received for this peer.
1199 *
1200 * @param cls NULL
1201 * @param client the TokenizedMessageContext which contains message information
1202 * @param message the actual message
1203 */
1204void tokenized_message_handler (void *cls,
1205 void *client,
1206 const struct GNUNET_MessageHeader *message)
1207{
1208 struct TokenizedMessageContext *ctx = client;
1209 GNUNET_break_op (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP);
1210 GNUNET_break_op (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_DATA);
1211 if ( (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP) &&
1212 (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_DATA) )
1213 {
1214#if DEBUG_DV_MESSAGES
1215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1216 "%s: Receives %s message for me, uid %u, total size %d cost %u from %s!\n", my_short_id, "DV DATA", ctx->uid, ntohs(message->size), ctx->distant->cost, GNUNET_i2s(&ctx->distant->identity));
1217#endif
1218 GNUNET_assert(memcmp(ctx->peer, &ctx->distant->identity, sizeof(struct GNUNET_PeerIdentity)) != 0);
1219 send_to_plugin(ctx->peer, message, ntohs(message->size), &ctx->distant->identity, ctx->distant->cost);
1220 }
1221}
1222
1178/** 1223/**
1179 * Core handler for dv data messages. Whatever this message 1224 * Core handler for dv data messages. Whatever this message
1180 * contains all we really have to do is rip it out of its 1225 * contains all we really have to do is rip it out of its
@@ -1202,6 +1247,7 @@ static int handle_dv_data_message (void *cls,
1202 struct GNUNET_PeerIdentity original_sender; 1247 struct GNUNET_PeerIdentity original_sender;
1203 struct GNUNET_PeerIdentity destination; 1248 struct GNUNET_PeerIdentity destination;
1204 struct FindDestinationContext fdc; 1249 struct FindDestinationContext fdc;
1250 struct TokenizedMessageContext tkm_ctx;
1205#if USE_PEER_ID 1251#if USE_PEER_ID
1206 struct CheckPeerContext checkPeerCtx; 1252 struct CheckPeerContext checkPeerCtx;
1207#endif 1253#endif
@@ -1210,8 +1256,9 @@ static int handle_dv_data_message (void *cls,
1210 int ret; 1256 int ret;
1211 size_t packed_message_size; 1257 size_t packed_message_size;
1212 char *cbuf; 1258 char *cbuf;
1259#if NO_MST
1213 size_t offset; 1260 size_t offset;
1214 1261#endif
1215 packed_message_size = ntohs(incoming->header.size) - sizeof(p2p_dv_MESSAGE_Data); 1262 packed_message_size = ntohs(incoming->header.size) - sizeof(p2p_dv_MESSAGE_Data);
1216 1263
1217 1264
@@ -1292,26 +1339,41 @@ static int handle_dv_data_message (void *cls,
1292 { 1339 {
1293 /* 0 == us */ 1340 /* 0 == us */
1294 cbuf = (char *)&incoming[1]; 1341 cbuf = (char *)&incoming[1];
1342
1343 tkm_ctx.peer = peer;
1344 tkm_ctx.distant = pos;
1345 tkm_ctx.uid = ntohl(incoming->uid);
1346 if (GNUNET_OK != GNUNET_SERVER_mst_receive (coreMST,
1347 &tkm_ctx,
1348 cbuf,
1349 packed_message_size,
1350 GNUNET_NO,
1351 GNUNET_NO))
1352 {
1353 GNUNET_break_op(0);
1354 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: %s Received corrupt data, discarding!", my_short_id, "DV SERVICE");
1355 }
1356#if NO_MST
1295 offset = 0; 1357 offset = 0;
1296 while(offset < packed_message_size) 1358 while(offset < packed_message_size)
1297 { 1359 {
1298 packed_message = (struct GNUNET_MessageHeader *)&cbuf[offset]; 1360 packed_message = (struct GNUNET_MessageHeader *)&cbuf[offset];
1299 1361
1300#if DEBUG_DV_MESSAGES
1301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1302 "%s: Receives %s message for me, uid %u, size %d type %d, cost %u from %s!\n", my_short_id, "DV DATA", ntohl(incoming->uid), ntohs(packed_message->size), ntohs(packed_message->type), pos->cost, GNUNET_i2s(&pos->identity));
1303#endif
1304 GNUNET_break_op (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP); 1362 GNUNET_break_op (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP);
1305 GNUNET_break_op (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_DATA); 1363 GNUNET_break_op (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_DATA);
1306 if ( (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP) && 1364 if ( (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP) &&
1307 (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_DATA) ) 1365 (ntohs (packed_message->type) != GNUNET_MESSAGE_TYPE_DV_DATA) )
1308 { 1366 {
1367#if DEBUG_DV_MESSAGES
1368 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1369 "%s: Receives %s message(s) for me, uid %u, total size %d cost %u from %s!\n", my_short_id, "DV DATA", ntohl(incoming->uid), ntohs(packed_message->size), pos->cost, GNUNET_i2s(&pos->identity));
1370#endif
1309 GNUNET_assert(memcmp(peer, &pos->identity, sizeof(struct GNUNET_PeerIdentity)) != 0); 1371 GNUNET_assert(memcmp(peer, &pos->identity, sizeof(struct GNUNET_PeerIdentity)) != 0);
1310 send_to_plugin(peer, packed_message, ntohs(packed_message->size), &pos->identity, pos->cost); 1372 send_to_plugin(peer, packed_message, ntohs(packed_message->size), &pos->identity, pos->cost);
1311 } 1373 }
1312 offset += ntohs(packed_message->size); 1374 offset += ntohs(packed_message->size);
1313 } 1375 }
1314 1376#endif
1315 return GNUNET_OK; 1377 return GNUNET_OK;
1316 } 1378 }
1317 else 1379 else
@@ -1966,7 +2028,7 @@ shutdown_task (void *cls,
1966 2028
1967 GNUNET_CORE_disconnect (coreAPI); 2029 GNUNET_CORE_disconnect (coreAPI);
1968 GNUNET_PEERINFO_disconnect(peerinfo_handle); 2030 GNUNET_PEERINFO_disconnect(peerinfo_handle);
1969 2031 GNUNET_SERVER_mst_destroy(coreMST);
1970 GNUNET_free_non_null(my_short_id); 2032 GNUNET_free_non_null(my_short_id);
1971#if DEBUG_DV 2033#if DEBUG_DV
1972 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "CORE_DISCONNECT completed\n"); 2034 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "CORE_DISCONNECT completed\n");
@@ -2829,6 +2891,10 @@ run (void *cls,
2829 if (coreAPI == NULL) 2891 if (coreAPI == NULL)
2830 return; 2892 return;
2831 2893
2894 coreMST = GNUNET_SERVER_mst_create (GNUNET_SERVER_MAX_MESSAGE_SIZE,
2895 &tokenized_message_handler,
2896 NULL);
2897
2832 peerinfo_handle = GNUNET_PEERINFO_connect(sched, cfg); 2898 peerinfo_handle = GNUNET_PEERINFO_connect(sched, cfg);
2833 2899
2834 if (peerinfo_handle == NULL) 2900 if (peerinfo_handle == NULL)