diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-06-15 11:28:47 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-06-15 11:28:47 +0000 |
commit | 6fe56d071a601aa102d1a0b833bad71a0ef84883 (patch) | |
tree | 7b62960d7dbcc758dbd9705add25e6c02fde8143 /src/mesh | |
parent | 90dcbc87096e698b5cd210b5067cabd76f32b4c4 (diff) | |
download | gnunet-6fe56d071a601aa102d1a0b833bad71a0ef84883.tar.gz gnunet-6fe56d071a601aa102d1a0b833bad71a0ef84883.zip |
Changed PeerInfo / Path structure
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 231 | ||||
-rw-r--r-- | src/mesh/mesh_protocol.h | 11 |
2 files changed, 116 insertions, 126 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index cb006bc42..f640364b1 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -57,6 +57,34 @@ | |||
57 | /******************************************************************************/ | 57 | /******************************************************************************/ |
58 | 58 | ||
59 | /** | 59 | /** |
60 | * Information regarding a path | ||
61 | */ | ||
62 | struct MeshPath | ||
63 | { | ||
64 | |||
65 | /** | ||
66 | * Linked list | ||
67 | */ | ||
68 | struct MeshPath *next; | ||
69 | |||
70 | /** | ||
71 | * Whether the path is serving traffic in a tunnel or is a backup | ||
72 | */ | ||
73 | int in_use; | ||
74 | |||
75 | /** | ||
76 | * List of all the peers that form the path from origin to target | ||
77 | */ | ||
78 | GNUNET_PEER_Id *peers; | ||
79 | |||
80 | /** | ||
81 | * Number of peers (hops) in the path | ||
82 | */ | ||
83 | unsigned int length; | ||
84 | }; | ||
85 | |||
86 | |||
87 | /** | ||
60 | * All the states a peer participating in a tunnel can be in. | 88 | * All the states a peer participating in a tunnel can be in. |
61 | */ | 89 | */ |
62 | enum MeshPeerState | 90 | enum MeshPeerState |
@@ -82,6 +110,7 @@ enum MeshPeerState | |||
82 | MESH_PEER_RECONNECTING | 110 | MESH_PEER_RECONNECTING |
83 | }; | 111 | }; |
84 | 112 | ||
113 | |||
85 | /** | 114 | /** |
86 | * Struct containing all information regarding a given peer | 115 | * Struct containing all information regarding a given peer |
87 | */ | 116 | */ |
@@ -108,9 +137,9 @@ struct MeshPeerInfo | |||
108 | int n_reconnect_attempts; | 137 | int n_reconnect_attempts; |
109 | 138 | ||
110 | /** | 139 | /** |
111 | * First hop whom to send data to reach this peer in the current active path | 140 | * Paths to reach the peer |
112 | */ | 141 | */ |
113 | GNUNET_PEER_Id first_hop; | 142 | struct MeshPath *path; |
114 | 143 | ||
115 | /** | 144 | /** |
116 | * Handle to stop the DHT search for a path to this peer | 145 | * Handle to stop the DHT search for a path to this peer |
@@ -120,33 +149,6 @@ struct MeshPeerInfo | |||
120 | 149 | ||
121 | 150 | ||
122 | /** | 151 | /** |
123 | * Information regarding a path | ||
124 | */ | ||
125 | struct MeshPath | ||
126 | { | ||
127 | /** | ||
128 | * Double linked list | ||
129 | */ | ||
130 | struct MeshPath *next; | ||
131 | struct MeshPath *prev; | ||
132 | |||
133 | /** | ||
134 | * Whether the path is serving traffic in a tunnel or is a backup | ||
135 | */ | ||
136 | int in_use; | ||
137 | |||
138 | /** | ||
139 | * List of all the peers that form the path from origin to target | ||
140 | */ | ||
141 | GNUNET_PEER_Id *peers; | ||
142 | |||
143 | /** | ||
144 | * Number of peers (hops) in the path | ||
145 | */ | ||
146 | int length; | ||
147 | }; | ||
148 | |||
149 | /** | ||
150 | * Data scheduled to transmit (to local client or remote peer) | 152 | * Data scheduled to transmit (to local client or remote peer) |
151 | */ | 153 | */ |
152 | struct MeshQueue | 154 | struct MeshQueue |
@@ -227,7 +229,7 @@ struct MeshTunnel | |||
227 | struct GNUNET_TIME_Absolute timestamp; | 229 | struct GNUNET_TIME_Absolute timestamp; |
228 | 230 | ||
229 | /** | 231 | /** |
230 | * Peers in the tunnel, for future optimizations | 232 | * Peers in the tunnelindexed by PeerIdentity (MeshPeerInfo) |
231 | */ | 233 | */ |
232 | struct GNUNET_CONTAINER_MultiHashMap* peers; | 234 | struct GNUNET_CONTAINER_MultiHashMap* peers; |
233 | 235 | ||
@@ -241,11 +243,6 @@ struct MeshTunnel | |||
241 | */ | 243 | */ |
242 | unsigned int peers_total; | 244 | unsigned int peers_total; |
243 | 245 | ||
244 | /** | ||
245 | * Paths (used and backup) | ||
246 | */ | ||
247 | struct MeshPath *paths_head; | ||
248 | struct MeshPath *paths_tail; | ||
249 | 246 | ||
250 | /** | 247 | /** |
251 | * Client owner of the tunnel, if any | 248 | * Client owner of the tunnel, if any |
@@ -304,11 +301,16 @@ struct MeshClient | |||
304 | static struct MeshClient *clients; | 301 | static struct MeshClient *clients; |
305 | 302 | ||
306 | /** | 303 | /** |
307 | * Tunnels known, indexed by MESH_TunnelID | 304 | * Tunnels known, indexed by MESH_TunnelID (MeshTunnel) |
308 | */ | 305 | */ |
309 | struct GNUNET_CONTAINER_MultiHashMap *tunnels; | 306 | struct GNUNET_CONTAINER_MultiHashMap *tunnels; |
310 | 307 | ||
311 | /** | 308 | /** |
309 | * Peers known, indexed by PeerIdentity (MeshPeerInfo) | ||
310 | */ | ||
311 | struct GNUNET_CONTAINER_MultiHashMap *peers; | ||
312 | |||
313 | /** | ||
312 | * Handle to communicate with core | 314 | * Handle to communicate with core |
313 | */ | 315 | */ |
314 | static struct GNUNET_CORE_Handle *core_handle; | 316 | static struct GNUNET_CORE_Handle *core_handle; |
@@ -402,7 +404,6 @@ retrieve_tunnel (struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid) | |||
402 | GNUNET_PEER_change_rc(pi, -1); | 404 | GNUNET_PEER_change_rc(pi, -1); |
403 | return retrieve_tunnel_by_pi(pi, tid); | 405 | return retrieve_tunnel_by_pi(pi, tid); |
404 | } | 406 | } |
405 | #endif | ||
406 | 407 | ||
407 | 408 | ||
408 | /** | 409 | /** |
@@ -416,12 +417,11 @@ destroy_path(struct MeshTunnel *t, struct MeshPath *p) | |||
416 | { | 417 | { |
417 | GNUNET_PEER_decrement_rcs(p->peers, p->length); | 418 | GNUNET_PEER_decrement_rcs(p->peers, p->length); |
418 | GNUNET_free(p->peers); | 419 | GNUNET_free(p->peers); |
419 | GNUNET_CONTAINER_DLL_remove(t->paths_head, t->paths_tail, p); | ||
420 | GNUNET_free(p); | 420 | GNUNET_free(p); |
421 | return GNUNET_OK; | 421 | return GNUNET_OK; |
422 | } | 422 | } |
423 | 423 | ||
424 | #if LATER | 424 | |
425 | /** | 425 | /** |
426 | * Destroy the peer_info and free any allocated resources linked to it | 426 | * Destroy the peer_info and free any allocated resources linked to it |
427 | * @param t tunnel the path belongs to | 427 | * @param t tunnel the path belongs to |
@@ -448,15 +448,16 @@ destroy_path(struct MeshTunnel *t, struct MeshPath *p) | |||
448 | static int | 448 | static int |
449 | destroy_tunnel(struct MeshClient *c, struct MeshTunnel *t) | 449 | destroy_tunnel(struct MeshClient *c, struct MeshTunnel *t) |
450 | { | 450 | { |
451 | struct MeshPath *path; | 451 | // struct MeshPath *path; |
452 | GNUNET_HashCode hash; | 452 | GNUNET_HashCode hash; |
453 | int r; | 453 | int r; |
454 | 454 | ||
455 | if (NULL == t) return GNUNET_OK; | 455 | if (NULL == t) return GNUNET_OK; |
456 | 456 | ||
457 | for (path = t->paths_head; path != NULL; path = t->paths_head) { | 457 | // FIXME |
458 | if(GNUNET_OK != destroy_path(t, path)) r = GNUNET_SYSERR; | 458 | // for (path = t->paths_head; path != NULL; path = t->paths_head) { |
459 | } | 459 | // if(GNUNET_OK != destroy_path(t, path)) r = GNUNET_SYSERR; |
460 | // } | ||
460 | 461 | ||
461 | GNUNET_CRYPTO_hash(&t->id, sizeof(struct MESH_TunnelID), &hash); | 462 | GNUNET_CRYPTO_hash(&t->id, sizeof(struct MESH_TunnelID), &hash); |
462 | if(GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove(tunnels, &hash, t)) { | 463 | if(GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove(tunnels, &hash, t)) { |
@@ -478,7 +479,6 @@ destroy_tunnel(struct MeshClient *c, struct MeshTunnel *t) | |||
478 | /******************************************************************************/ | 479 | /******************************************************************************/ |
479 | 480 | ||
480 | /** | 481 | /** |
481 | * FIXME: rewrite | ||
482 | * Function called to notify a client about the socket | 482 | * Function called to notify a client about the socket |
483 | * being ready to queue more data. "buf" will be | 483 | * being ready to queue more data. "buf" will be |
484 | * NULL and "size" zero if the socket was closed for | 484 | * NULL and "size" zero if the socket was closed for |
@@ -492,24 +492,20 @@ destroy_tunnel(struct MeshClient *c, struct MeshTunnel *t) | |||
492 | static size_t | 492 | static size_t |
493 | send_core_create_path_for_peer (void *cls, size_t size, void *buf) | 493 | send_core_create_path_for_peer (void *cls, size_t size, void *buf) |
494 | { | 494 | { |
495 | size_t size_needed; | 495 | struct MeshPeerInfo *peer_info = cls; |
496 | struct MeshPeerInfo *peer_info; | ||
497 | struct GNUNET_MESH_ManipulatePath *msg; | 496 | struct GNUNET_MESH_ManipulatePath *msg; |
498 | struct MeshPath *p; | 497 | struct MeshPath *p; |
499 | struct GNUNET_PeerIdentity peer_id; | ||
500 | struct GNUNET_PeerIdentity *peer_ptr; | 498 | struct GNUNET_PeerIdentity *peer_ptr; |
499 | size_t size_needed; | ||
501 | int i; | 500 | int i; |
502 | 501 | ||
503 | if (0 == size && NULL == buf) { | 502 | if (0 == size && NULL == buf) { |
504 | // TODO retry? cancel? | 503 | // TODO retry? cancel? |
505 | return 0; | 504 | return 0; |
506 | } | 505 | } |
507 | peer_info = (struct MeshPeerInfo *)cls; | 506 | p = peer_info->path; |
508 | peer_info->dhtget = NULL; | ||
509 | // p = peer_info->t->paths_head; | ||
510 | p = NULL; | ||
511 | while (NULL != p) { | 507 | while (NULL != p) { |
512 | if (p->peers[p->length-1] == peer_info->id) { | 508 | if (p->in_use) { |
513 | break; | 509 | break; |
514 | } | 510 | } |
515 | p = p->next; | 511 | p = p->next; |
@@ -524,14 +520,12 @@ send_core_create_path_for_peer (void *cls, size_t size, void *buf) | |||
524 | } | 520 | } |
525 | 521 | ||
526 | msg = (struct GNUNET_MESH_ManipulatePath *) buf; | 522 | msg = (struct GNUNET_MESH_ManipulatePath *) buf; |
527 | msg->header.size = htons(sizeof(struct GNUNET_MESH_ManipulatePath)); | 523 | msg->header.size = htons(size_needed); |
528 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE); | 524 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE); |
529 | msg->speed_min = 0; | ||
530 | 525 | ||
531 | peer_ptr = (struct GNUNET_PeerIdentity *) &msg[1]; | 526 | peer_ptr = (struct GNUNET_PeerIdentity *) &msg[1]; |
532 | for (i = 0; i < p->length; i++) { | 527 | for (i = 0; i < p->length; i++) { |
533 | GNUNET_PEER_resolve(p->peers[i], &peer_id); | 528 | GNUNET_PEER_resolve(p->peers[i], peer_ptr++); |
534 | memcpy(&peer_ptr[i], &peer_id, sizeof(struct GNUNET_PeerIdentity)); | ||
535 | } | 529 | } |
536 | 530 | ||
537 | peer_info->state = MESH_PEER_WAITING; | 531 | peer_info->state = MESH_PEER_WAITING; |
@@ -539,7 +533,7 @@ send_core_create_path_for_peer (void *cls, size_t size, void *buf) | |||
539 | return size_needed; | 533 | return size_needed; |
540 | } | 534 | } |
541 | 535 | ||
542 | 536 | #if LATER | |
543 | /** | 537 | /** |
544 | * Send another peer a notification to destroy a tunnel | 538 | * Send another peer a notification to destroy a tunnel |
545 | * @param cls The tunnel to destroy | 539 | * @param cls The tunnel to destroy |
@@ -563,6 +557,7 @@ send_p2p_tunnel_destroy(void *cls, size_t size, void *buf) | |||
563 | destroy_tunnel(c, t); | 557 | destroy_tunnel(c, t); |
564 | return sizeof(struct GNUNET_MESH_TunnelMessage); | 558 | return sizeof(struct GNUNET_MESH_TunnelMessage); |
565 | } | 559 | } |
560 | #endif | ||
566 | 561 | ||
567 | 562 | ||
568 | /******************************************************************************/ | 563 | /******************************************************************************/ |
@@ -641,6 +636,14 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = { | |||
641 | /**************** MESH LOCAL HANDLER HELPERS ***********************/ | 636 | /**************** MESH LOCAL HANDLER HELPERS ***********************/ |
642 | /******************************************************************************/ | 637 | /******************************************************************************/ |
643 | 638 | ||
639 | /** | ||
640 | * delete_tunnel_entry: iterator for deleting each tunnel that belongs to a | ||
641 | * client when the client disconnects. | ||
642 | * @param cls closure (client that is disconnecting) | ||
643 | * @param key the hash of the local tunnel id (used to access the hashmap) | ||
644 | * @param value the value stored at the key (tunnel to destroy) | ||
645 | * @return GNUNET_OK on success | ||
646 | */ | ||
644 | static int | 647 | static int |
645 | delete_tunnel_entry (void *cls, const GNUNET_HashCode * key, void *value) { | 648 | delete_tunnel_entry (void *cls, const GNUNET_HashCode * key, void *value) { |
646 | int r; | 649 | int r; |
@@ -648,6 +651,7 @@ delete_tunnel_entry (void *cls, const GNUNET_HashCode * key, void *value) { | |||
648 | return r; | 651 | return r; |
649 | } | 652 | } |
650 | 653 | ||
654 | #if LATER | ||
651 | /** | 655 | /** |
652 | * notify_client_connection_failure: notify a client that the connection to the | 656 | * notify_client_connection_failure: notify a client that the connection to the |
653 | * requested remote peer is not possible (for instance, no route found) | 657 | * requested remote peer is not possible (for instance, no route found) |
@@ -683,10 +687,9 @@ notify_client_connection_failure (void *cls, size_t size, void *buf) | |||
683 | 687 | ||
684 | return size_needed; | 688 | return size_needed; |
685 | } | 689 | } |
686 | 690 | #endif | |
687 | 691 | ||
688 | /** | 692 | /** |
689 | * FIXME: rewrite | ||
690 | * Function to process paths received for a new peer addition. The recorded | 693 | * Function to process paths received for a new peer addition. The recorded |
691 | * paths form the initial tunnel, which can be optimized later. | 694 | * paths form the initial tunnel, which can be optimized later. |
692 | * Called on each result obtained for the DHT search. | 695 | * Called on each result obtained for the DHT search. |
@@ -712,28 +715,31 @@ dht_get_response_handler(void *cls, | |||
712 | size_t size, | 715 | size_t size, |
713 | const void *data) | 716 | const void *data) |
714 | { | 717 | { |
715 | struct MeshPeerInfo *peer_info; | 718 | struct MeshPeerInfo *peer_info = cls; |
716 | struct MeshTunnel *t; | ||
717 | struct MeshPath *p; | 719 | struct MeshPath *p; |
720 | struct MeshPath *aux; | ||
721 | struct GNUNET_PeerIdentity pi; | ||
718 | int i; | 722 | int i; |
719 | 723 | ||
720 | peer_info = (struct MeshPeerInfo *)cls; | 724 | if ((NULL == get_path || NULL == put_path) && NULL == peer_info->path) { |
721 | // t = peer_info->t; | 725 | // Find ourselves some alternate initial path to the destination: retry |
722 | t = NULL; // FIXME | 726 | GNUNET_DHT_get_stop(peer_info->dhtget); |
723 | 727 | GNUNET_PEER_resolve(peer_info->id, &pi); | |
724 | if (NULL == get_path || NULL == put_path) { | 728 | peer_info->dhtget = GNUNET_DHT_get_start(dht_handle, |
725 | // TODO: find ourselves some alternate initial path to the destination | 729 | GNUNET_TIME_UNIT_FOREVER_REL, |
726 | GNUNET_SERVER_notify_transmit_ready( | 730 | GNUNET_BLOCK_TYPE_ANY, |
727 | t->client->handle, | 731 | &pi.hashPubKey, |
728 | sizeof(struct GNUNET_MESH_PeerControl), | 732 | 4, /* replication level */ |
729 | GNUNET_TIME_UNIT_FOREVER_REL, | 733 | GNUNET_DHT_RO_RECORD_ROUTE, |
730 | ¬ify_client_connection_failure, | 734 | NULL, /* bloom filter */ |
731 | peer_info | 735 | 0, /* mutator */ |
732 | ); | 736 | NULL, /* xquery */ |
737 | 0, /* xquery bits */ | ||
738 | dht_get_response_handler, | ||
739 | (void *)peer_info); | ||
733 | } | 740 | } |
734 | 741 | ||
735 | p = GNUNET_malloc(sizeof(struct MeshPath)); | 742 | p = GNUNET_malloc(sizeof(struct MeshPath)); |
736 | GNUNET_CONTAINER_DLL_insert(t->paths_head, t->paths_tail, p); | ||
737 | for (i = 0; get_path[i] != NULL; i++); | 743 | for (i = 0; get_path[i] != NULL; i++); |
738 | for (i--; i >= 0; i--) { | 744 | for (i--; i >= 0; i--) { |
739 | p->peers = GNUNET_realloc(p->peers, | 745 | p->peers = GNUNET_realloc(p->peers, |
@@ -748,9 +754,15 @@ dht_get_response_handler(void *cls, | |||
748 | p->peers[p->length] = GNUNET_PEER_intern(put_path[i]); | 754 | p->peers[p->length] = GNUNET_PEER_intern(put_path[i]); |
749 | p->length++; | 755 | p->length++; |
750 | } | 756 | } |
751 | // p->id = 0; // FIXME generate ID or remove field | 757 | if (NULL == peer_info->path) { |
752 | p->in_use = 0; | 758 | p->in_use = 1; |
753 | // peer_info->first_hop = p->peers[1]; // FIXME do this on path completion | 759 | peer_info->path = p; |
760 | } else { | ||
761 | p->in_use = 0; | ||
762 | aux = peer_info->path; | ||
763 | while (NULL != aux->next) aux = aux->next; | ||
764 | aux->next = p; | ||
765 | } | ||
754 | GNUNET_CORE_notify_transmit_ready(core_handle, | 766 | GNUNET_CORE_notify_transmit_ready(core_handle, |
755 | 0, | 767 | 0, |
756 | 0, | 768 | 0, |
@@ -920,6 +932,7 @@ handle_local_tunnel_create (void *cls, | |||
920 | t->id.oid = myid; | 932 | t->id.oid = myid; |
921 | t->local_tid = ntohl(t_msg->tunnel_id); | 933 | t->local_tid = ntohl(t_msg->tunnel_id); |
922 | t->client = c; | 934 | t->client = c; |
935 | t->peers = GNUNET_CONTAINER_multihashmap_create(32); | ||
923 | 936 | ||
924 | GNUNET_CRYPTO_hash(&t->local_tid, sizeof(MESH_TunnelNumber), &hash); | 937 | GNUNET_CRYPTO_hash(&t->local_tid, sizeof(MESH_TunnelNumber), &hash); |
925 | if (GNUNET_OK != | 938 | if (GNUNET_OK != |
@@ -992,15 +1005,7 @@ handle_local_tunnel_destroy (void *cls, | |||
992 | GNUNET_CRYPTO_hash(&t->id, sizeof(struct MESH_TunnelID), &hash); | 1005 | GNUNET_CRYPTO_hash(&t->id, sizeof(struct MESH_TunnelID), &hash); |
993 | GNUNET_CONTAINER_multihashmap_remove(tunnels, &hash, t); | 1006 | GNUNET_CONTAINER_multihashmap_remove(tunnels, &hash, t); |
994 | 1007 | ||
995 | GNUNET_CORE_notify_transmit_ready(core_handle, | 1008 | // notify_tunnel_destroy(t); |
996 | 1, | ||
997 | 1, | ||
998 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
999 | NULL, | ||
1000 | sizeof(struct GNUNET_MESH_TunnelMessage), | ||
1001 | &send_p2p_tunnel_destroy, | ||
1002 | t); | ||
1003 | |||
1004 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 1009 | GNUNET_SERVER_receive_done(client, GNUNET_OK); |
1005 | return; | 1010 | return; |
1006 | } | 1011 | } |
@@ -1023,7 +1028,6 @@ handle_local_connect_add (void *cls, | |||
1023 | struct MeshTunnel *t; | 1028 | struct MeshTunnel *t; |
1024 | MESH_TunnelNumber tid; | 1029 | MESH_TunnelNumber tid; |
1025 | struct MeshPeerInfo *peer_info; | 1030 | struct MeshPeerInfo *peer_info; |
1026 | GNUNET_HashCode key; | ||
1027 | 1031 | ||
1028 | 1032 | ||
1029 | /* Sanity check for client registration */ | 1033 | /* Sanity check for client registration */ |
@@ -1035,7 +1039,9 @@ handle_local_connect_add (void *cls, | |||
1035 | 1039 | ||
1036 | peer_msg = (struct GNUNET_MESH_PeerControl *)message; | 1040 | peer_msg = (struct GNUNET_MESH_PeerControl *)message; |
1037 | /* Sanity check for message size */ | 1041 | /* Sanity check for message size */ |
1038 | if (sizeof(struct GNUNET_MESH_PeerControl) != ntohs(peer_msg->header.size)) { | 1042 | if (sizeof(struct GNUNET_MESH_PeerControl) |
1043 | != ntohs(peer_msg->header.size)) | ||
1044 | { | ||
1039 | GNUNET_break(0); | 1045 | GNUNET_break(0); |
1040 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 1046 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); |
1041 | return; | 1047 | return; |
@@ -1058,19 +1064,27 @@ handle_local_connect_add (void *cls, | |||
1058 | } | 1064 | } |
1059 | 1065 | ||
1060 | /* Ok, add peer to tunnel */ | 1066 | /* Ok, add peer to tunnel */ |
1061 | peer_info = (struct MeshPeerInfo *) GNUNET_malloc(sizeof(struct MeshPeerInfo)); | 1067 | peer_info = GNUNET_CONTAINER_multihashmap_get(peers, |
1062 | peer_info->id = GNUNET_PEER_intern(&peer_msg->peer); | 1068 | &peer_msg->peer.hashPubKey); |
1063 | peer_info->state = MESH_PEER_SEARCHING; | 1069 | if (NULL == peer_info) { |
1070 | peer_info = (struct MeshPeerInfo *) | ||
1071 | GNUNET_malloc(sizeof(struct MeshPeerInfo)); | ||
1072 | GNUNET_CONTAINER_multihashmap_put(peers, | ||
1073 | &peer_msg->peer.hashPubKey, | ||
1074 | peer_info, | ||
1075 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
1076 | peer_info->id = GNUNET_PEER_intern(&peer_msg->peer); | ||
1077 | peer_info->state = MESH_PEER_SEARCHING; | ||
1078 | } | ||
1079 | |||
1064 | t->peers_total++; | 1080 | t->peers_total++; |
1065 | /* FIXME insert */ | 1081 | /* FIXME insert */ |
1066 | /* Start DHT search */ | 1082 | /* Start DHT search if needed */ |
1067 | GNUNET_CRYPTO_hash (&peer_msg->peer, | 1083 | if(MESH_PEER_READY != peer_info->state && NULL == peer_info->dhtget) { |
1068 | sizeof(struct GNUNET_PeerIdentity), | 1084 | peer_info->dhtget = GNUNET_DHT_get_start(dht_handle, |
1069 | &key); | ||
1070 | peer_info->dhtget = GNUNET_DHT_get_start(dht_handle, | ||
1071 | GNUNET_TIME_UNIT_FOREVER_REL, | 1085 | GNUNET_TIME_UNIT_FOREVER_REL, |
1072 | GNUNET_BLOCK_TYPE_ANY, | 1086 | GNUNET_BLOCK_TYPE_ANY, |
1073 | &key, | 1087 | &peer_msg->peer.hashPubKey, |
1074 | 4, /* replication level */ | 1088 | 4, /* replication level */ |
1075 | GNUNET_DHT_RO_RECORD_ROUTE, | 1089 | GNUNET_DHT_RO_RECORD_ROUTE, |
1076 | NULL, /* bloom filter */ | 1090 | NULL, /* bloom filter */ |
@@ -1079,6 +1093,7 @@ handle_local_connect_add (void *cls, | |||
1079 | 0, /* xquery bits */ | 1093 | 0, /* xquery bits */ |
1080 | dht_get_response_handler, | 1094 | dht_get_response_handler, |
1081 | (void *)peer_info); | 1095 | (void *)peer_info); |
1096 | } | ||
1082 | 1097 | ||
1083 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 1098 | GNUNET_SERVER_receive_done(client, GNUNET_OK); |
1084 | return; | 1099 | return; |
@@ -1100,8 +1115,6 @@ handle_local_connect_del (void *cls, | |||
1100 | struct GNUNET_MESH_PeerControl *peer_msg; | 1115 | struct GNUNET_MESH_PeerControl *peer_msg; |
1101 | struct MeshClient *c; | 1116 | struct MeshClient *c; |
1102 | struct MeshTunnel *t; | 1117 | struct MeshTunnel *t; |
1103 | struct MeshPath *p; | ||
1104 | struct MeshPath *aux_path; | ||
1105 | MESH_TunnelNumber tid; | 1118 | MESH_TunnelNumber tid; |
1106 | GNUNET_PEER_Id peer_id; | 1119 | GNUNET_PEER_Id peer_id; |
1107 | 1120 | ||
@@ -1138,20 +1151,7 @@ handle_local_connect_del (void *cls, | |||
1138 | /* Ok, delete peer from tunnel */ | 1151 | /* Ok, delete peer from tunnel */ |
1139 | peer_id = GNUNET_PEER_intern(&peer_msg->peer); | 1152 | peer_id = GNUNET_PEER_intern(&peer_msg->peer); |
1140 | 1153 | ||
1141 | /* Delete paths */ | 1154 | /* FIXME Delete paths */ |
1142 | p = t->paths_head; | ||
1143 | while (p != NULL) { | ||
1144 | if (p->peers[p->length-1] == peer_id) { /* one path per destination */ | ||
1145 | GNUNET_CONTAINER_DLL_remove(t->paths_head, t->paths_tail, p); | ||
1146 | GNUNET_PEER_decrement_rcs(p->peers, p->length); | ||
1147 | aux_path = p; | ||
1148 | p = p->next; | ||
1149 | GNUNET_free(aux_path); | ||
1150 | } else { | ||
1151 | p = p->next; | ||
1152 | } | ||
1153 | } | ||
1154 | |||
1155 | /* FIXME Delete peer info */ | 1155 | /* FIXME Delete peer info */ |
1156 | 1156 | ||
1157 | GNUNET_PEER_change_rc(peer_id, -1); | 1157 | GNUNET_PEER_change_rc(peer_id, -1); |
@@ -1479,7 +1479,8 @@ run (void *cls, | |||
1479 | } | 1479 | } |
1480 | next_tid = 0; | 1480 | next_tid = 0; |
1481 | 1481 | ||
1482 | tunnels = GNUNET_CONTAINER_multihashmap_create(64); | 1482 | tunnels = GNUNET_CONTAINER_multihashmap_create(32); |
1483 | peers = GNUNET_CONTAINER_multihashmap_create(32); | ||
1483 | 1484 | ||
1484 | /* Scheduled the task to clean up when shutdown is called */ | 1485 | /* Scheduled the task to clean up when shutdown is called */ |
1485 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 1486 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
diff --git a/src/mesh/mesh_protocol.h b/src/mesh/mesh_protocol.h index 01a44b58b..dcffdac96 100644 --- a/src/mesh/mesh_protocol.h +++ b/src/mesh/mesh_protocol.h | |||
@@ -58,17 +58,6 @@ struct GNUNET_MESH_ManipulatePath | |||
58 | uint32_t tid GNUNET_PACKED; | 58 | uint32_t tid GNUNET_PACKED; |
59 | 59 | ||
60 | /** | 60 | /** |
61 | * Information about speed requirements. If the tunnel cannot sustain the | ||
62 | * minimum bandwidth, packets are to be dropped. | ||
63 | */ | ||
64 | uint32_t speed_min GNUNET_PACKED; | ||
65 | |||
66 | /** | ||
67 | * 64-bit alignment. | ||
68 | */ | ||
69 | uint32_t reserved GNUNET_PACKED; | ||
70 | |||
71 | /** | ||
72 | * path_length structs defining the *whole* path from the origin [0] to the | 61 | * path_length structs defining the *whole* path from the origin [0] to the |
73 | * final destination [path_length-1]. | 62 | * final destination [path_length-1]. |
74 | */ | 63 | */ |