diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-05-03 21:23:20 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-05-03 21:23:20 +0000 |
commit | 2dd926e8fd80a05d3dffbf05845fffec638a282d (patch) | |
tree | 9f97cb00371d38e61a4f5b0d3d7e9c3d80677e72 /src | |
parent | 4fbd46e8d0553d74ec06e9c6275d17fa73b3714c (diff) | |
download | gnunet-2dd926e8fd80a05d3dffbf05845fffec638a282d.tar.gz gnunet-2dd926e8fd80a05d3dffbf05845fffec638a282d.zip |
WiP
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 70 |
1 files changed, 54 insertions, 16 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 16f75455d..6755e55c7 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -214,6 +214,11 @@ struct GNUNET_MESH_SpeedNotify | |||
214 | enum PeerState | 214 | enum PeerState |
215 | { | 215 | { |
216 | /** | 216 | /** |
217 | * Path to the peer not known yet | ||
218 | */ | ||
219 | MESH_PEER_SEARCHING, | ||
220 | |||
221 | /** | ||
217 | * Request sent, not yet answered. | 222 | * Request sent, not yet answered. |
218 | */ | 223 | */ |
219 | MESH_PEER_WAITING, | 224 | MESH_PEER_WAITING, |
@@ -498,18 +503,18 @@ static GNUNET_PEER_Id myid; | |||
498 | * @return number of bytes written to buf | 503 | * @return number of bytes written to buf |
499 | */ | 504 | */ |
500 | size_t send_core_create_path_for_peer (void *cls, size_t size, void *buf) { | 505 | size_t send_core_create_path_for_peer (void *cls, size_t size, void *buf) { |
501 | size_t size_used; | 506 | size_t size_needed; |
502 | struct PeerInfo *peer_info; | 507 | struct PeerInfo *peer_info; |
503 | struct GNUNET_MESH_ManipulatePath *msg; | 508 | struct GNUNET_MESH_ManipulatePath *msg; |
504 | struct Path *p; | 509 | struct Path *p; |
510 | struct GNUNET_PeerIdentity peer_id; | ||
511 | struct GNUNET_PeerIdentity *peer_ptr; | ||
512 | int i; | ||
505 | 513 | ||
506 | if((0 == size && NULL == buf) || | 514 | if(0 == size && NULL == buf) { |
507 | size < sizeof(struct GNUNET_MESH_ManipulatePath)) | ||
508 | { | ||
509 | // TODO retry? cancel? | 515 | // TODO retry? cancel? |
510 | return 0; | 516 | return 0; |
511 | } | 517 | } |
512 | size_used = 0; | ||
513 | peer_info = (struct PeerInfo *)cls; | 518 | peer_info = (struct PeerInfo *)cls; |
514 | peer_info->dhtget = NULL; | 519 | peer_info->dhtget = NULL; |
515 | p = peer_info->t->paths_head; | 520 | p = peer_info->t->paths_head; |
@@ -524,13 +529,27 @@ size_t send_core_create_path_for_peer (void *cls, size_t size, void *buf) { | |||
524 | } | 529 | } |
525 | } | 530 | } |
526 | 531 | ||
532 | size_needed = sizeof(struct GNUNET_MESH_ManipulatePath) | ||
533 | + p->length * sizeof(struct GNUNET_PeerIdentity); | ||
534 | if(size < size_needed) { | ||
535 | // TODO retry? cancel? | ||
536 | return 0; | ||
537 | } | ||
538 | |||
527 | msg = (struct GNUNET_MESH_ManipulatePath *) buf; | 539 | msg = (struct GNUNET_MESH_ManipulatePath *) buf; |
528 | msg->header.size = htons(sizeof(struct GNUNET_MESH_ManipulatePath)); | 540 | msg->header.size = htons(sizeof(struct GNUNET_MESH_ManipulatePath)); |
529 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE); | 541 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE); |
530 | 542 | msg->speed_min = 0; | |
531 | 543 | ||
544 | peer_ptr = (struct GNUNET_PeerIdentity *) &msg[1]; | ||
545 | for(i = 0; i < p->length; i++) { | ||
546 | GNUNET_PEER_resolve(p->peers[i], &peer_id); | ||
547 | memcpy(&peer_ptr[i], &peer_id, sizeof(struct GNUNET_PeerIdentity)); | ||
548 | } | ||
532 | 549 | ||
533 | return size_used; | 550 | peer_info->state = MESH_PEER_WAITING; |
551 | |||
552 | return size_needed; | ||
534 | } | 553 | } |
535 | 554 | ||
536 | 555 | ||
@@ -623,10 +642,10 @@ client_retrieve (struct GNUNET_SERVER_Client *client) { | |||
623 | } | 642 | } |
624 | 643 | ||
625 | /** | 644 | /** |
626 | * Function called to notify a client about the socket | 645 | * notify_client_connection_failure: notify a client that the connection to the |
627 | * begin ready to queue more data. "buf" will be | 646 | * requested remote peer is not possible (for instance, no route found) |
628 | * NULL and "size" zero if the socket was closed for | 647 | * Function called when the socket is ready to queue more data."buf" will be |
629 | * writing in the meantime. | 648 | * NULL and "size" zero if the socket was closed for writing in the meantime. |
630 | * | 649 | * |
631 | * @param cls closure | 650 | * @param cls closure |
632 | * @param size number of bytes available in buf | 651 | * @param size number of bytes available in buf |
@@ -634,7 +653,26 @@ client_retrieve (struct GNUNET_SERVER_Client *client) { | |||
634 | * @return number of bytes written to buf | 653 | * @return number of bytes written to buf |
635 | */ | 654 | */ |
636 | size_t notify_client_connection_failure (void *cls, size_t size, void *buf) { | 655 | size_t notify_client_connection_failure (void *cls, size_t size, void *buf) { |
637 | return 0; | 656 | int size_needed; |
657 | struct PeerInfo *peer_info; | ||
658 | struct GNUNET_MESH_PeerControl *msg; | ||
659 | struct GNUNET_PeerIdentity id; | ||
660 | |||
661 | if(0 == size && NULL == buf) { | ||
662 | // TODO retry? cancel? | ||
663 | return 0; | ||
664 | } | ||
665 | |||
666 | size_needed = sizeof(struct GNUNET_MESH_PeerControl); | ||
667 | peer_info = (struct PeerInfo *) cls; | ||
668 | msg = (struct GNUNET_MESH_PeerControl *) buf; | ||
669 | msg->header.size = htons(sizeof(struct GNUNET_MESH_PeerControl)); | ||
670 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED); | ||
671 | msg->tunnel_id = htonl(peer_info->t->tid); | ||
672 | GNUNET_PEER_resolve(peer_info->id, &id); | ||
673 | memcpy(&msg->peer, &id, sizeof(struct GNUNET_PeerIdentity)); | ||
674 | |||
675 | return size_needed; | ||
638 | } | 676 | } |
639 | 677 | ||
640 | 678 | ||
@@ -671,7 +709,7 @@ void dht_get_response_handler(void *cls, | |||
671 | t = peer_info->t; | 709 | t = peer_info->t; |
672 | 710 | ||
673 | if(NULL == get_path || NULL == put_path) { | 711 | if(NULL == get_path || NULL == put_path) { |
674 | // TODO: find ourselves some alternate first path to the destination | 712 | // TODO: find ourselves some alternate initial path to the destination |
675 | GNUNET_SERVER_notify_transmit_ready( | 713 | GNUNET_SERVER_notify_transmit_ready( |
676 | t->client->handle, | 714 | t->client->handle, |
677 | sizeof(struct GNUNET_MESH_PeerControl), | 715 | sizeof(struct GNUNET_MESH_PeerControl), |
@@ -680,7 +718,7 @@ void dht_get_response_handler(void *cls, | |||
680 | peer_info | 718 | peer_info |
681 | ); | 719 | ); |
682 | } | 720 | } |
683 | 721 | ||
684 | p = GNUNET_malloc(sizeof(struct Path)); | 722 | p = GNUNET_malloc(sizeof(struct Path)); |
685 | GNUNET_CONTAINER_DLL_insert(t->paths_head, t->paths_tail, p); | 723 | GNUNET_CONTAINER_DLL_insert(t->paths_head, t->paths_tail, p); |
686 | for(i = 0; get_path[i] != NULL; i++) { | 724 | for(i = 0; get_path[i] != NULL; i++) { |
@@ -990,7 +1028,7 @@ handle_local_connect_add (void *cls, | |||
990 | /* Ok, add peer to tunnel */ | 1028 | /* Ok, add peer to tunnel */ |
991 | peer_info = (struct PeerInfo *) GNUNET_malloc(sizeof(struct PeerInfo)); | 1029 | peer_info = (struct PeerInfo *) GNUNET_malloc(sizeof(struct PeerInfo)); |
992 | peer_info->id = GNUNET_PEER_intern(&peer_msg->peer); | 1030 | peer_info->id = GNUNET_PEER_intern(&peer_msg->peer); |
993 | peer_info->state = MESH_PEER_WAITING; | 1031 | peer_info->state = MESH_PEER_SEARCHING; |
994 | peer_info->t = t; | 1032 | peer_info->t = t; |
995 | t->peers_total++; | 1033 | t->peers_total++; |
996 | GNUNET_CONTAINER_DLL_insert(t->peers_head, t->peers_tail, peer_info); | 1034 | GNUNET_CONTAINER_DLL_insert(t->peers_head, t->peers_tail, peer_info); |