aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-06-14 13:32:00 +0000
committerBart Polot <bart@net.in.tum.de>2011-06-14 13:32:00 +0000
commitb8bc30b1a609c041f9fbdf72212e6f15e82d875d (patch)
tree4c05842dc200f54729c6f7a79f0fbc484cdf1d86 /src/mesh
parent34857d410f10a469ba8cb729b296285dc1af5fe8 (diff)
downloadgnunet-b8bc30b1a609c041f9fbdf72212e6f15e82d875d.tar.gz
gnunet-b8bc30b1a609c041f9fbdf72212e6f15e82d875d.zip
WiP
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh.c121
1 files changed, 82 insertions, 39 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index cb88762f4..cb006bc42 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -26,7 +26,9 @@
26 * STRUCTURE: 26 * STRUCTURE:
27 * - DATA STRUCTURES 27 * - DATA STRUCTURES
28 * - GLOBAL VARIABLES 28 * - GLOBAL VARIABLES
29 * - MESH NETWORK HANDLER HELPERS
29 * - MESH NETWORK HANDLES 30 * - MESH NETWORK HANDLES
31 * - MESH LOCAL HANDLER HELPERS
30 * - MESH LOCAL HANDLES 32 * - MESH LOCAL HANDLES
31 * - MAIN FUNCTIONS (main & run) 33 * - MAIN FUNCTIONS (main & run)
32 * 34 *
@@ -117,9 +119,6 @@ struct MeshPeerInfo
117}; 119};
118 120
119 121
120typedef uint32_t MESH_PathID;
121
122
123/** 122/**
124 * Information regarding a path 123 * Information regarding a path
125 */ 124 */
@@ -132,11 +131,6 @@ struct MeshPath
132 struct MeshPath *prev; 131 struct MeshPath *prev;
133 132
134 /** 133 /**
135 * Id of the path, in case it's needed
136 */
137 MESH_PathID id;
138
139 /**
140 * Whether the path is serving traffic in a tunnel or is a backup 134 * Whether the path is serving traffic in a tunnel or is a backup
141 */ 135 */
142 int in_use; 136 int in_use;
@@ -330,7 +324,7 @@ static struct GNUNET_DHT_Handle *dht_handle;
330static GNUNET_PEER_Id myid; 324static GNUNET_PEER_Id myid;
331 325
332/** 326/**
333 * Tunnel ID for the next created tunnel 327 * Tunnel ID for the next created tunnel (global tunnel number)
334 */ 328 */
335static MESH_TunnelNumber next_tid; 329static MESH_TunnelNumber next_tid;
336 330
@@ -356,6 +350,7 @@ retrieve_client (struct GNUNET_SERVER_Client *client)
356 return NULL; 350 return NULL;
357} 351}
358 352
353
359/** 354/**
360 * Search for a tunnel among the tunnels for a client 355 * Search for a tunnel among the tunnels for a client
361 * @param client the client whose tunnels to search in 356 * @param client the client whose tunnels to search in
@@ -371,25 +366,45 @@ retrieve_tunnel_by_local_id (struct MeshClient *c, MESH_TunnelNumber tid)
371 return GNUNET_CONTAINER_multihashmap_get(c->tunnels, &hash); 366 return GNUNET_CONTAINER_multihashmap_get(c->tunnels, &hash);
372} 367}
373 368
374#if LATER
375/** 369/**
376 * Search for a tunnel by global ID 370 * Search for a tunnel by global ID using PEER_ID
371 * @param pi owner of the tunnel
372 * @param tid global tunnel number
373 * @return tunnel handler, NULL if doesn't exist
377 */ 374 */
378static struct MeshTunnel * 375static struct MeshTunnel *
379retrieve_tunnel (struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid) 376retrieve_tunnel_by_pi (GNUNET_PEER_Id pi, MESH_TunnelNumber tid)
380{ 377{
381 struct MESH_TunnelID id; 378 struct MESH_TunnelID id;
382 GNUNET_HashCode hash; 379 GNUNET_HashCode hash;
383 380
384 id.oid = GNUNET_PEER_intern(oid); 381 id.oid = pi;
385 GNUNET_PEER_change_rc(id.oid, -1);
386 id.tid = tid; 382 id.tid = tid;
387 383
388 GNUNET_CRYPTO_hash(&id, sizeof(struct MESH_TunnelID), &hash); 384 GNUNET_CRYPTO_hash(&id, sizeof(struct MESH_TunnelID), &hash);
389 return GNUNET_CONTAINER_multihashmap_get(tunnels, &hash); 385 return GNUNET_CONTAINER_multihashmap_get(tunnels, &hash);
390} 386}
387
388
389#if LATER
390/**
391 * Search for a tunnel by global ID using full PeerIdentities
392 * @param oid owner of the tunnel
393 * @param tid global tunnel number
394 * @return tunnel handler, NULL if doesn't exist
395 */
396static struct MeshTunnel *
397retrieve_tunnel (struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid)
398{
399 GNUNET_PEER_Id pi;
400
401 pi = GNUNET_PEER_intern(oid);
402 GNUNET_PEER_change_rc(pi, -1);
403 return retrieve_tunnel_by_pi(pi, tid);
404}
391#endif 405#endif
392 406
407
393/** 408/**
394 * Destroy the path and free any allocated resources linked to it 409 * Destroy the path and free any allocated resources linked to it
395 * @param t tunnel the path belongs to 410 * @param t tunnel the path belongs to
@@ -413,16 +428,17 @@ destroy_path(struct MeshTunnel *t, struct MeshPath *p)
413 * @param pi the peer_info to destroy 428 * @param pi the peer_info to destroy
414 * @return GNUNET_OK on success 429 * @return GNUNET_OK on success
415 */ 430 */
416static int 431// static int
417destroy_peer_info(struct MeshTunnel *t, struct MeshPeerInfo *pi) 432// destroy_peer_info(struct MeshTunnel *t, struct MeshPeerInfo *pi)
418{ 433// {
419 GNUNET_PEER_change_rc(pi->id, -1); 434// GNUNET_PEER_change_rc(pi->id, -1);
420 /* FIXME delete from list */ 435// /* FIXME delete from list */
421 GNUNET_free(pi); 436// GNUNET_free(pi);
422 return GNUNET_OK; 437// return GNUNET_OK;
423} 438// }
424#endif 439#endif
425 440
441
426/** 442/**
427 * Destroy the tunnel and free any allocated resources linked to it 443 * Destroy the tunnel and free any allocated resources linked to it
428 * @param c client the tunnel belongs to 444 * @param c client the tunnel belongs to
@@ -458,7 +474,7 @@ destroy_tunnel(struct MeshClient *c, struct MeshTunnel *t)
458} 474}
459 475
460/******************************************************************************/ 476/******************************************************************************/
461/******************** MESH NETWORK HANDLERS **************************/ 477/**************** MESH NETWORK HANDLER HELPERS ***********************/
462/******************************************************************************/ 478/******************************************************************************/
463 479
464/** 480/**
@@ -491,6 +507,7 @@ send_core_create_path_for_peer (void *cls, size_t size, void *buf)
491 peer_info = (struct MeshPeerInfo *)cls; 507 peer_info = (struct MeshPeerInfo *)cls;
492 peer_info->dhtget = NULL; 508 peer_info->dhtget = NULL;
493// p = peer_info->t->paths_head; 509// p = peer_info->t->paths_head;
510 p = NULL;
494 while (NULL != p) { 511 while (NULL != p) {
495 if (p->peers[p->length-1] == peer_info->id) { 512 if (p->peers[p->length-1] == peer_info->id) {
496 break; 513 break;
@@ -548,6 +565,11 @@ send_p2p_tunnel_destroy(void *cls, size_t size, void *buf)
548} 565}
549 566
550 567
568/******************************************************************************/
569/******************** MESH NETWORK HANDLERS **************************/
570/******************************************************************************/
571
572
551/** 573/**
552 * Core handler for path creation 574 * Core handler for path creation
553 * struct GNUNET_CORE_MessageHandler 575 * struct GNUNET_CORE_MessageHandler
@@ -616,7 +638,7 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
616 638
617 639
618/******************************************************************************/ 640/******************************************************************************/
619/********************* MESH LOCAL HANDLES **************************/ 641/**************** MESH LOCAL HANDLER HELPERS ***********************/
620/******************************************************************************/ 642/******************************************************************************/
621 643
622static int 644static int
@@ -743,6 +765,11 @@ dht_get_response_handler(void *cls,
743} 765}
744 766
745 767
768/******************************************************************************/
769/********************* MESH LOCAL HANDLES **************************/
770/******************************************************************************/
771
772
746/** 773/**
747 * Handler for client disconnection 774 * Handler for client disconnection
748 * 775 *
@@ -794,19 +821,17 @@ handle_local_new_client (void *cls,
794{ 821{
795 struct GNUNET_MESH_ClientConnect *cc_msg; 822 struct GNUNET_MESH_ClientConnect *cc_msg;
796 struct MeshClient *c; 823 struct MeshClient *c;
797 unsigned int payload_size; 824 unsigned int size;
798 uint16_t types; 825 uint16_t types;
799 uint16_t apps; 826 uint16_t apps;
800 827
801 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 828 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: new client connected\n");
802 "MESH: new client connected\n");
803 /* Check data sanity */ 829 /* Check data sanity */
804 payload_size = ntohs(message->size) 830 size = ntohs(message->size) - sizeof(struct GNUNET_MESH_ClientConnect);
805 - sizeof(struct GNUNET_MESH_ClientConnect);
806 cc_msg = (struct GNUNET_MESH_ClientConnect *) message; 831 cc_msg = (struct GNUNET_MESH_ClientConnect *) message;
807 types = ntohs(cc_msg->types); 832 types = ntohs(cc_msg->types);
808 apps = ntohs(cc_msg->applications); 833 apps = ntohs(cc_msg->applications);
809 if (payload_size != 834 if (size !=
810 types * sizeof(uint16_t) + apps * sizeof(GNUNET_MESH_ApplicationType)) 835 types * sizeof(uint16_t) + apps * sizeof(GNUNET_MESH_ApplicationType))
811 { 836 {
812 GNUNET_break(0); 837 GNUNET_break(0);
@@ -834,9 +859,9 @@ handle_local_new_client (void *cls,
834 c->type_counter, 859 c->type_counter,
835 c->app_counter); 860 c->app_counter);
836 861
837 /* Insert new client in DLL */ 862 c->next = clients;
838 /* FIXME insert client */ 863 clients = c;
839 c->tunnels = GNUNET_CONTAINER_multihashmap_create(100); 864 c->tunnels = GNUNET_CONTAINER_multihashmap_create(32);
840 865
841 GNUNET_SERVER_receive_done(client, GNUNET_OK); 866 GNUNET_SERVER_receive_done(client, GNUNET_OK);
842 867
@@ -887,9 +912,10 @@ handle_local_tunnel_create (void *cls,
887 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); 912 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
888 return; 913 return;
889 } 914 }
890 t = GNUNET_malloc(sizeof(struct MeshTunnel )); 915
891 // FIXME:what if all 2^32 ID are taken? 916 t = GNUNET_malloc(sizeof(struct MeshTunnel));
892 while (NULL != retrieve_tunnel_by_local_id(c, next_tid)) next_tid++; 917 // FIXME: what if all 2^32 ID are taken?
918 while (NULL != retrieve_tunnel_by_pi(myid, next_tid)) next_tid++;
893 t->id.tid = next_tid++; 919 t->id.tid = next_tid++;
894 t->id.oid = myid; 920 t->id.oid = myid;
895 t->local_tid = ntohl(t_msg->tunnel_id); 921 t->local_tid = ntohl(t_msg->tunnel_id);
@@ -905,7 +931,15 @@ handle_local_tunnel_create (void *cls,
905 return; 931 return;
906 } 932 }
907 933
908 /* FIXME insert */ 934 GNUNET_CRYPTO_hash(&t->id, sizeof(struct MESH_TunnelID), &hash);
935 if (GNUNET_OK !=
936 GNUNET_CONTAINER_multihashmap_put(tunnels, &hash, t,
937 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
938 {
939 GNUNET_break(0);
940 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
941 return;
942 }
909 943
910 GNUNET_SERVER_receive_done(client, GNUNET_OK); 944 GNUNET_SERVER_receive_done(client, GNUNET_OK);
911 return; 945 return;
@@ -948,9 +982,16 @@ handle_local_tunnel_destroy (void *cls,
948 982
949 /* Retrieve tunnel */ 983 /* Retrieve tunnel */
950 tid = ntohl(tunnel_msg->tunnel_id); 984 tid = ntohl(tunnel_msg->tunnel_id);
985
986 /* Remove from local id hashmap */
951 GNUNET_CRYPTO_hash(&tid, sizeof(MESH_TunnelNumber), &hash); 987 GNUNET_CRYPTO_hash(&tid, sizeof(MESH_TunnelNumber), &hash);
952 t = GNUNET_CONTAINER_multihashmap_get(c->tunnels, &hash); 988 t = GNUNET_CONTAINER_multihashmap_get(c->tunnels, &hash);
953 GNUNET_CONTAINER_multihashmap_remove_all(c->tunnels, &hash); 989 GNUNET_CONTAINER_multihashmap_remove(c->tunnels, &hash, t);
990
991 /* Remove from global id hashmap */
992 GNUNET_CRYPTO_hash(&t->id, sizeof(struct MESH_TunnelID), &hash);
993 GNUNET_CONTAINER_multihashmap_remove(tunnels, &hash, t);
994
954 GNUNET_CORE_notify_transmit_ready(core_handle, 995 GNUNET_CORE_notify_transmit_ready(core_handle,
955 1, 996 1,
956 1, 997 1,
@@ -1432,12 +1473,14 @@ run (void *cls,
1432 if (core_handle == NULL) { 1473 if (core_handle == NULL) {
1433 GNUNET_break(0); 1474 GNUNET_break(0);
1434 } 1475 }
1435 dht_handle = GNUNET_DHT_connect(c, 100); /* FIXME ht len correct size? */ 1476 dht_handle = GNUNET_DHT_connect(c, 64);
1436 if (dht_handle == NULL) { 1477 if (dht_handle == NULL) {
1437 GNUNET_break(0); 1478 GNUNET_break(0);
1438 } 1479 }
1439 next_tid = 0; 1480 next_tid = 0;
1440 1481
1482 tunnels = GNUNET_CONTAINER_multihashmap_create(64);
1483
1441 /* Scheduled the task to clean up when shutdown is called */ 1484 /* Scheduled the task to clean up when shutdown is called */
1442 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 1485 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
1443 &shutdown_task, NULL); 1486 &shutdown_task, NULL);