diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-06-17 13:26:19 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-06-17 13:26:19 +0000 |
commit | 89c9cb7c978a7a79776d940cadf13740c315b632 (patch) | |
tree | 87958650c5ff2ade1e06d310d383f96b9fff5ec4 /src/mesh/gnunet-service-mesh.c | |
parent | 976473839da8f1978ea31015339858927d0bdbd2 (diff) | |
download | gnunet-89c9cb7c978a7a79776d940cadf13740c315b632.tar.gz gnunet-89c9cb7c978a7a79776d940cadf13740c315b632.zip |
WiP (adding paths)
Diffstat (limited to 'src/mesh/gnunet-service-mesh.c')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 125 |
1 files changed, 89 insertions, 36 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index eb2382ae1..241bb00fe 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -71,6 +71,7 @@ struct MeshPath | |||
71 | * Linked list | 71 | * Linked list |
72 | */ | 72 | */ |
73 | struct MeshPath *next; | 73 | struct MeshPath *next; |
74 | struct MeshPath *prev; | ||
74 | 75 | ||
75 | /** | 76 | /** |
76 | * Whether the path is serving traffic in a tunnel or is a backup | 77 | * Whether the path is serving traffic in a tunnel or is a backup |
@@ -145,6 +146,7 @@ struct MeshPeerInfo | |||
145 | * Paths to reach the peer | 146 | * Paths to reach the peer |
146 | */ | 147 | */ |
147 | struct MeshPath *path; | 148 | struct MeshPath *path; |
149 | struct MeshPath *path_tail; | ||
148 | 150 | ||
149 | /** | 151 | /** |
150 | * Handle to stop the DHT search for a path to this peer | 152 | * Handle to stop the DHT search for a path to this peer |
@@ -305,7 +307,7 @@ struct MeshClient | |||
305 | * All the clients | 307 | * All the clients |
306 | */ | 308 | */ |
307 | static struct MeshClient *clients; | 309 | static struct MeshClient *clients; |
308 | static struct MeshClient *clients_t; | 310 | static struct MeshClient *clients_tail; |
309 | 311 | ||
310 | /** | 312 | /** |
311 | * Tunnels known, indexed by MESH_TunnelID (MeshTunnel) | 313 | * Tunnels known, indexed by MESH_TunnelID (MeshTunnel) |
@@ -342,6 +344,66 @@ static MESH_TunnelNumber next_tid; | |||
342 | /******************************************************************************/ | 344 | /******************************************************************************/ |
343 | 345 | ||
344 | /** | 346 | /** |
347 | * Retrieve the MeshPeerInfo stucture associated with the peer, create one | ||
348 | * and inster it in the appropiate structures if the peer is not known yet. | ||
349 | * @param peer Identity of the peer | ||
350 | * @return Existing or newly created peer info | ||
351 | */ | ||
352 | static struct MeshPeerInfo * | ||
353 | retireve_peer_info (const struct GNUNET_PeerIdentity *peer) | ||
354 | { | ||
355 | struct MeshPeerInfo * peer_info; | ||
356 | |||
357 | peer_info = GNUNET_CONTAINER_multihashmap_get(peers, | ||
358 | &peer->hashPubKey); | ||
359 | if (NULL == peer_info) { | ||
360 | peer_info = (struct MeshPeerInfo *) | ||
361 | GNUNET_malloc(sizeof(struct MeshPeerInfo)); | ||
362 | GNUNET_CONTAINER_multihashmap_put(peers, | ||
363 | &peer->hashPubKey, | ||
364 | peer_info, | ||
365 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
366 | peer_info->id = GNUNET_PEER_intern(peer); | ||
367 | peer_info->state = MESH_PEER_SEARCHING; | ||
368 | } | ||
369 | |||
370 | return peer_info; | ||
371 | } | ||
372 | |||
373 | /** | ||
374 | * find the first peer whom to send a packet to go down this path | ||
375 | * @param path The path to use | ||
376 | * @return short id of the next peer, myid in case of local delivery, | ||
377 | * or 0 in case of error | ||
378 | */ | ||
379 | static GNUNET_PEER_Id | ||
380 | retrieve_first_hop (struct MeshPath *path) | ||
381 | { | ||
382 | unsigned int i; | ||
383 | |||
384 | if (NULL == path) return 0; | ||
385 | if (path->in_use == 0) return 0; | ||
386 | |||
387 | for (i = 0; i < path->length; i++) { | ||
388 | if (path->peers[i] == myid) { | ||
389 | if (i < path->length - 1) { | ||
390 | return path->peers[i+1]; | ||
391 | } else { | ||
392 | return myid; | ||
393 | } | ||
394 | } | ||
395 | } | ||
396 | return 0; | ||
397 | } | ||
398 | |||
399 | static void | ||
400 | add_path_to_peer(struct MeshPeerInfo *peer_info, struct MeshPath *path) | ||
401 | { | ||
402 | return; | ||
403 | } | ||
404 | |||
405 | |||
406 | /** | ||
345 | * Check if client has registered with the service and has not disconnected | 407 | * Check if client has registered with the service and has not disconnected |
346 | * @param client the client to check | 408 | * @param client the client to check |
347 | * @return non-NULL if client exists in the global DLL | 409 | * @return non-NULL if client exists in the global DLL |
@@ -509,11 +571,11 @@ send_core_create_path_for_peer (void *cls, size_t size, void *buf) | |||
509 | 571 | ||
510 | if (0 == size && NULL == buf) { | 572 | if (0 == size && NULL == buf) { |
511 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Retransmitting create path\n"); | 573 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Retransmitting create path\n"); |
512 | GNUNET_PEER_resolve(peer_info->path->peers[1], &id); | 574 | GNUNET_PEER_resolve(retrieve_first_hop(peer_info->path), &id); |
513 | GNUNET_CORE_notify_transmit_ready(core_handle, | 575 | GNUNET_CORE_notify_transmit_ready(core_handle, |
514 | 0, | 576 | 0, |
515 | 0, | 577 | 0, |
516 | GNUNET_TIME_UNIT_SECONDS, | 578 | GNUNET_TIME_UNIT_FOREVER_REL, |
517 | &id, | 579 | &id, |
518 | sizeof(struct GNUNET_MESH_ManipulatePath) | 580 | sizeof(struct GNUNET_MESH_ManipulatePath) |
519 | + (peer_info->path->length | 581 | + (peer_info->path->length |
@@ -736,7 +798,6 @@ dht_get_response_handler(void *cls, | |||
736 | { | 798 | { |
737 | struct MeshPeerInfo *peer_info = cls; | 799 | struct MeshPeerInfo *peer_info = cls; |
738 | struct MeshPath *p; | 800 | struct MeshPath *p; |
739 | struct MeshPath *aux; | ||
740 | struct GNUNET_PeerIdentity pi; | 801 | struct GNUNET_PeerIdentity pi; |
741 | int i; | 802 | int i; |
742 | 803 | ||
@@ -773,15 +834,7 @@ dht_get_response_handler(void *cls, | |||
773 | p->peers[p->length] = GNUNET_PEER_intern(put_path[i]); | 834 | p->peers[p->length] = GNUNET_PEER_intern(put_path[i]); |
774 | p->length++; | 835 | p->length++; |
775 | } | 836 | } |
776 | if (NULL == peer_info->path) { | 837 | add_path_to_peer(peer_info, p); |
777 | p->in_use = 1; | ||
778 | peer_info->path = p; | ||
779 | } else { | ||
780 | p->in_use = 0; | ||
781 | aux = peer_info->path; | ||
782 | while (NULL != aux->next) aux = aux->next; | ||
783 | aux->next = p; | ||
784 | } | ||
785 | GNUNET_CORE_notify_transmit_ready(core_handle, | 838 | GNUNET_CORE_notify_transmit_ready(core_handle, |
786 | 0, | 839 | 0, |
787 | 0, | 840 | 0, |
@@ -827,7 +880,7 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
827 | GNUNET_CONTAINER_multihashmap_destroy(c->tunnels); | 880 | GNUNET_CONTAINER_multihashmap_destroy(c->tunnels); |
828 | if(0 != c->app_counter) GNUNET_free (c->apps); | 881 | if(0 != c->app_counter) GNUNET_free (c->apps); |
829 | if(0 != c->type_counter) GNUNET_free (c->types); | 882 | if(0 != c->type_counter) GNUNET_free (c->types); |
830 | GNUNET_CONTAINER_DLL_remove(clients, clients_t, c); | 883 | GNUNET_CONTAINER_DLL_remove(clients, clients_tail, c); |
831 | next = c->next; | 884 | next = c->next; |
832 | GNUNET_free (c); | 885 | GNUNET_free (c); |
833 | c = next; | 886 | c = next; |
@@ -895,7 +948,7 @@ handle_local_new_client (void *cls, | |||
895 | c->type_counter, | 948 | c->type_counter, |
896 | c->app_counter); | 949 | c->app_counter); |
897 | 950 | ||
898 | GNUNET_CONTAINER_DLL_insert(clients, clients_t, c); | 951 | GNUNET_CONTAINER_DLL_insert(clients, clients_tail, c); |
899 | c->tunnels = GNUNET_CONTAINER_multihashmap_create(32); | 952 | c->tunnels = GNUNET_CONTAINER_multihashmap_create(32); |
900 | 953 | ||
901 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 954 | GNUNET_SERVER_receive_done(client, GNUNET_OK); |
@@ -1086,22 +1139,9 @@ handle_local_connect_add (void *cls, | |||
1086 | return; | 1139 | return; |
1087 | } | 1140 | } |
1088 | 1141 | ||
1089 | /* Ok, add peer to tunnel */ | ||
1090 | peer_info = GNUNET_CONTAINER_multihashmap_get(peers, | ||
1091 | &peer_msg->peer.hashPubKey); | ||
1092 | if (NULL == peer_info) { | ||
1093 | peer_info = (struct MeshPeerInfo *) | ||
1094 | GNUNET_malloc(sizeof(struct MeshPeerInfo)); | ||
1095 | GNUNET_CONTAINER_multihashmap_put(peers, | ||
1096 | &peer_msg->peer.hashPubKey, | ||
1097 | peer_info, | ||
1098 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
1099 | peer_info->id = GNUNET_PEER_intern(&peer_msg->peer); | ||
1100 | peer_info->state = MESH_PEER_SEARCHING; | ||
1101 | } | ||
1102 | |||
1103 | t->peers_total++; | 1142 | t->peers_total++; |
1104 | /* FIXME insert */ | 1143 | peer_info = retireve_peer_info(&peer_msg->peer); |
1144 | |||
1105 | /* Start DHT search if needed */ | 1145 | /* Start DHT search if needed */ |
1106 | if(MESH_PEER_READY != peer_info->state && NULL == peer_info->dhtget) { | 1146 | if(MESH_PEER_READY != peer_info->state && NULL == peer_info->dhtget) { |
1107 | peer_info->dhtget = GNUNET_DHT_get_start(dht_handle, | 1147 | peer_info->dhtget = GNUNET_DHT_get_start(dht_handle, |
@@ -1149,7 +1189,9 @@ handle_local_connect_del (void *cls, | |||
1149 | } | 1189 | } |
1150 | peer_msg = (struct GNUNET_MESH_PeerControl *)message; | 1190 | peer_msg = (struct GNUNET_MESH_PeerControl *)message; |
1151 | /* Sanity check for message size */ | 1191 | /* Sanity check for message size */ |
1152 | if (sizeof(struct GNUNET_MESH_PeerControl) != ntohs(peer_msg->header.size)) { | 1192 | if (sizeof(struct GNUNET_MESH_PeerControl) |
1193 | != ntohs(peer_msg->header.size)) | ||
1194 | { | ||
1153 | GNUNET_break(0); | 1195 | GNUNET_break(0); |
1154 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 1196 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); |
1155 | return; | 1197 | return; |
@@ -1324,7 +1366,9 @@ handle_local_network_traffic_bcast (void *cls, | |||
1324 | } | 1366 | } |
1325 | data_msg = (struct GNUNET_MESH_DataBroadcast *)message; | 1367 | data_msg = (struct GNUNET_MESH_DataBroadcast *)message; |
1326 | /* Sanity check for message size */ | 1368 | /* Sanity check for message size */ |
1327 | if (sizeof(struct GNUNET_MESH_PeerControl) != ntohs(data_msg->header.size)) { | 1369 | if (sizeof(struct GNUNET_MESH_PeerControl) |
1370 | != ntohs(data_msg->header.size)) | ||
1371 | { | ||
1328 | GNUNET_break(0); | 1372 | GNUNET_break(0); |
1329 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 1373 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); |
1330 | return; | 1374 | return; |
@@ -1413,14 +1457,23 @@ core_connect (void *cls, | |||
1413 | const struct GNUNET_PeerIdentity *peer, | 1457 | const struct GNUNET_PeerIdentity *peer, |
1414 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 1458 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
1415 | { | 1459 | { |
1416 | GNUNET_PEER_Id pid; | 1460 | // GNUNET_PEER_Id pid; |
1461 | struct MeshPeerInfo *peer_info; | ||
1462 | struct MeshPath *path; | ||
1463 | |||
1417 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1464 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1418 | "Peer connected\n"); | 1465 | "Peer connected\n"); |
1419 | pid = GNUNET_PEER_intern(peer); | 1466 | peer_info = retireve_peer_info(peer); |
1420 | if (myid == pid) { | 1467 | if (myid == peer_info->id) { |
1421 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1468 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1422 | " (self)\n"); | 1469 | " (self)\n"); |
1423 | } | 1470 | } |
1471 | path = GNUNET_malloc(sizeof(struct MeshPath)); | ||
1472 | path->length = 2; | ||
1473 | path->peers = GNUNET_malloc(sizeof(GNUNET_PEER_Id) * 2); | ||
1474 | path->peers[0] = myid; | ||
1475 | path->peers[1] = peer_info->id; | ||
1476 | add_path_to_peer(peer_info, path); | ||
1424 | return; | 1477 | return; |
1425 | } | 1478 | } |
1426 | 1479 | ||
@@ -1572,7 +1625,7 @@ run (void *cls, | |||
1572 | tunnels = GNUNET_CONTAINER_multihashmap_create(32); | 1625 | tunnels = GNUNET_CONTAINER_multihashmap_create(32); |
1573 | peers = GNUNET_CONTAINER_multihashmap_create(32); | 1626 | peers = GNUNET_CONTAINER_multihashmap_create(32); |
1574 | clients = NULL; | 1627 | clients = NULL; |
1575 | clients_t = NULL; | 1628 | clients_tail = NULL; |
1576 | 1629 | ||
1577 | /* Path keepalive */ | 1630 | /* Path keepalive */ |
1578 | GNUNET_SCHEDULER_add_delayed(REFRESH_PATH_TIME, | 1631 | GNUNET_SCHEDULER_add_delayed(REFRESH_PATH_TIME, |