diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-06-22 02:21:43 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-06-22 02:21:43 +0000 |
commit | 422b457fbe23cb25e998a021994d8367c58a60b7 (patch) | |
tree | 83d9a7923e635b8642b08d225629f5d04a788aef /src/mesh/gnunet-service-mesh.c | |
parent | e840960d5dad5ac4f3c8b421c30ba4bfe6f10307 (diff) | |
download | gnunet-422b457fbe23cb25e998a021994d8367c58a60b7.tar.gz gnunet-422b457fbe23cb25e998a021994d8367c58a60b7.zip |
WiP (handle of create_path P2P message)
Diffstat (limited to 'src/mesh/gnunet-service-mesh.c')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 114 |
1 files changed, 102 insertions, 12 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index f27291cb6..9cefef7a5 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -458,7 +458,7 @@ retrieve_tunnel_by_pi (GNUNET_PEER_Id pi, MESH_TunnelNumber tid) | |||
458 | } | 458 | } |
459 | 459 | ||
460 | 460 | ||
461 | #if LATER | 461 | |
462 | /** | 462 | /** |
463 | * Search for a tunnel by global ID using full PeerIdentities | 463 | * Search for a tunnel by global ID using full PeerIdentities |
464 | * @param oid owner of the tunnel | 464 | * @param oid owner of the tunnel |
@@ -483,7 +483,7 @@ retrieve_tunnel (struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid) | |||
483 | * @return GNUNET_OK on success | 483 | * @return GNUNET_OK on success |
484 | */ | 484 | */ |
485 | static int | 485 | static int |
486 | destroy_path(struct MeshTunnel *t, struct MeshPath *p) | 486 | destroy_path(struct MeshPath *p) |
487 | { | 487 | { |
488 | GNUNET_PEER_decrement_rcs(p->peers, p->length); | 488 | GNUNET_PEER_decrement_rcs(p->peers, p->length); |
489 | GNUNET_free(p->peers); | 489 | GNUNET_free(p->peers); |
@@ -491,7 +491,7 @@ destroy_path(struct MeshTunnel *t, struct MeshPath *p) | |||
491 | return GNUNET_OK; | 491 | return GNUNET_OK; |
492 | } | 492 | } |
493 | 493 | ||
494 | 494 | #if LATER | |
495 | /** | 495 | /** |
496 | * Destroy the peer_info and free any allocated resources linked to it | 496 | * Destroy the peer_info and free any allocated resources linked to it |
497 | * @param t tunnel the path belongs to | 497 | * @param t tunnel the path belongs to |
@@ -522,14 +522,17 @@ destroy_peer_info(struct MeshPeerInfo *pi) | |||
522 | * @return GNUNET_OK on success | 522 | * @return GNUNET_OK on success |
523 | */ | 523 | */ |
524 | static int | 524 | static int |
525 | destroy_tunnel(struct MeshClient *c, struct MeshTunnel *t) | 525 | destroy_tunnel(struct MeshTunnel *t) |
526 | { | 526 | { |
527 | // struct MeshPath *path; | 527 | // struct MeshPath *path; |
528 | GNUNET_HashCode hash; | 528 | struct MeshClient *c; |
529 | int r; | 529 | GNUNET_HashCode hash; |
530 | int r; | ||
530 | 531 | ||
531 | if (NULL == t) return GNUNET_OK; | 532 | if (NULL == t) return GNUNET_OK; |
532 | 533 | ||
534 | c = t->client; | ||
535 | |||
533 | GNUNET_CRYPTO_hash(&t->id, sizeof(struct MESH_TunnelID), &hash); | 536 | GNUNET_CRYPTO_hash(&t->id, sizeof(struct MESH_TunnelID), &hash); |
534 | if(GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove(tunnels, &hash, t)) { | 537 | if(GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove(tunnels, &hash, t)) { |
535 | r = GNUNET_SYSERR; | 538 | r = GNUNET_SYSERR; |
@@ -667,11 +670,98 @@ handle_mesh_path_create (void *cls, | |||
667 | const struct GNUNET_TRANSPORT_ATS_Information | 670 | const struct GNUNET_TRANSPORT_ATS_Information |
668 | *atsi) | 671 | *atsi) |
669 | { | 672 | { |
670 | /* Extract path */ | 673 | unsigned int own_pos; |
671 | /* Find origin & self */ | 674 | uint16_t size; |
672 | /* Search for origin in local tunnels */ | 675 | uint16_t i; |
673 | /* Create tunnel / add path */ | 676 | MESH_TunnelNumber tid; |
674 | /* Retransmit to next link in chain, if any (core_notify + callback) */ | 677 | struct GNUNET_MESH_ManipulatePath *msg; |
678 | struct GNUNET_PeerIdentity *pi; | ||
679 | GNUNET_HashCode hash; | ||
680 | struct MeshPath *path; | ||
681 | struct MeshPeerInfo *peer_info; | ||
682 | struct MeshTunnel *t; | ||
683 | |||
684 | |||
685 | size = ntohs(message->size); | ||
686 | if (size < sizeof(struct GNUNET_MESH_ManipulatePath)) { | ||
687 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
688 | "received create path message too short\n"); | ||
689 | return GNUNET_OK; | ||
690 | } | ||
691 | |||
692 | size -= sizeof(struct GNUNET_MESH_ManipulatePath); | ||
693 | if (size < 2 * sizeof(struct GNUNET_PeerIdentity)) { | ||
694 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
695 | "create path message lacks enough peers\n"); | ||
696 | return GNUNET_OK; | ||
697 | } | ||
698 | if (size % sizeof(struct GNUNET_PeerIdentity)) { | ||
699 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
700 | "create path message of wrong size\n"); | ||
701 | return GNUNET_OK; | ||
702 | } | ||
703 | msg = (struct GNUNET_MESH_ManipulatePath *) message; | ||
704 | size /= sizeof(struct GNUNET_PeerIdentity); | ||
705 | |||
706 | tid = ntohl(msg->tid); | ||
707 | pi = (struct GNUNET_PeerIdentity *) &msg[1]; | ||
708 | t = retrieve_tunnel(pi, tid); | ||
709 | |||
710 | if (NULL == t) { | ||
711 | t = GNUNET_malloc(sizeof(struct MeshTunnel)); | ||
712 | t->id.oid = GNUNET_PEER_intern(pi); | ||
713 | t->id.tid = tid; | ||
714 | t->local_tid = 0; | ||
715 | t->client = NULL; | ||
716 | t->peers = GNUNET_CONTAINER_multihashmap_create(32); | ||
717 | |||
718 | GNUNET_CRYPTO_hash(&t->id, sizeof(struct MESH_TunnelID), &hash); | ||
719 | if (GNUNET_OK != | ||
720 | GNUNET_CONTAINER_multihashmap_put(tunnels, | ||
721 | &hash, | ||
722 | t, | ||
723 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
724 | { | ||
725 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
726 | "create path: could not store tunnel in hashmap\n"); | ||
727 | return GNUNET_OK; | ||
728 | } | ||
729 | |||
730 | } | ||
731 | peer_info = GNUNET_CONTAINER_multihashmap_get(peers, | ||
732 | &pi[size - 1].hashPubKey); | ||
733 | if (NULL == peer_info) { | ||
734 | peer_info = GNUNET_malloc(sizeof(struct MeshPeerInfo)); | ||
735 | peer_info->id = GNUNET_PEER_intern(&pi[size - 1]); | ||
736 | peer_info->state = MESH_PEER_WAITING; | ||
737 | GNUNET_CONTAINER_multihashmap_put(peers, | ||
738 | &pi[size - 1].hashPubKey, | ||
739 | peer_info, | ||
740 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | ||
741 | } | ||
742 | |||
743 | path = GNUNET_malloc(sizeof(struct MeshPath)); | ||
744 | path->length = size; | ||
745 | path->peers = GNUNET_malloc(size * sizeof(GNUNET_PEER_Id)); | ||
746 | own_pos = 0; | ||
747 | for (i = 0; i < size; i++) { | ||
748 | path->peers[i] = GNUNET_PEER_intern(&pi[i]); | ||
749 | if (path->peers[i] == myid) own_pos = i; | ||
750 | } | ||
751 | if (own_pos == 0) { /* cannot be self, must be 'not found' */ | ||
752 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
753 | "create path: self not found in path through self\n"); | ||
754 | destroy_path(path); | ||
755 | /* FIXME destroy tunnel? leave for timeout? */ | ||
756 | return 0; | ||
757 | } | ||
758 | if (own_pos == size - 1) { /* it is for us! */ | ||
759 | destroy_path(path); /* not needed anymore */ | ||
760 | /* TODO: send ack? new meesage type? */ | ||
761 | } else { | ||
762 | add_path_to_peer(peer_info, path); | ||
763 | /* TODO: Retransmit to next link in chain, if any (core_notify + callback) */ | ||
764 | } | ||
675 | return GNUNET_OK; | 765 | return GNUNET_OK; |
676 | } | 766 | } |
677 | 767 | ||
@@ -730,7 +820,7 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = { | |||
730 | static int | 820 | static int |
731 | delete_tunnel_entry (void *cls, const GNUNET_HashCode * key, void *value) { | 821 | delete_tunnel_entry (void *cls, const GNUNET_HashCode * key, void *value) { |
732 | int r; | 822 | int r; |
733 | r = destroy_tunnel((struct MeshClient *) cls, (struct MeshTunnel *) value); | 823 | r = destroy_tunnel((struct MeshTunnel *) value); |
734 | return r; | 824 | return r; |
735 | } | 825 | } |
736 | 826 | ||