From: Bart Polot Date: Thu, 10 Oct 2013 15:35:30 +0000 (+0000) Subject: - fix connection.c X-Git-Tag: initial-import-from-subversion-38251~6615 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=82fc48725fb6b1c508f1ea6b499c3722b62aef25;p=oweals%2Fgnunet.git - fix connection.c --- diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index 06ca072e9..2a0cfbc17 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c @@ -1023,8 +1023,8 @@ GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer, connection_change_state (c, MESH_CONNECTION_SENT); /* Remember peers */ - dest_peer = peer_get (&id[size - 1]); - orig_peer = peer_get (&id[0]); + dest_peer = GMP_get (&id[size - 1]); + orig_peer = GMP_get (&id[0]); /* Is it a connection to us? */ if (c->own_pos == size - 1) @@ -1032,12 +1032,8 @@ GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer, LOG (GNUNET_ERROR_TYPE_DEBUG, " It's for us!\n"); GMP_add_path_to_origin (orig_peer, path, GNUNET_YES); - if (NULL == orig_peer->tunnel) - { - orig_peer->tunnel = GMT_new (); - orig_peer->tunnel->peer = orig_peer; - } - GMT_add_connection (orig_peer->tunnel, c); + GMP_add_tunnel (orig_peer); + GMP_add_connection (orig_peer, c); if (MESH_TUNNEL3_NEW == GMT_get_state (c->t)) GMT_change_state (c->t, MESH_TUNNEL3_WAITING); diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c index 42717b8eb..21ddf6592 100644 --- a/src/mesh/gnunet-service-mesh_peer.c +++ b/src/mesh/gnunet-service-mesh_peer.c @@ -139,7 +139,7 @@ struct MeshPeer /** * Tunnel to this peer, if any. */ - struct MeshTunnel2 *tunnel; + struct MeshTunnel3 *tunnel; /** * Connections that go through this peer, indexed by tid; @@ -252,7 +252,7 @@ core_connect (void *cls, const struct GNUNET_PeerIdentity *peer) LOG ("Peer connected\n"); LOG (" %s\n", GNUNET_i2s (&my_full_id)); - pi = peer_get (peer); + pi = GMP_get (peer); if (myid == pi->id) { LOG (" (self)\n"); @@ -461,7 +461,7 @@ static size_t send_core_connection_ack (struct MeshConnection *c, size_t size, void *buf) { struct GNUNET_MESH_ConnectionACK *msg = buf; - struct MeshTunnel2 *t = c->t; + struct MeshTunnel3 *t = c->t; LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending CONNECTION ACK...\n"); GNUNET_assert (NULL != t); @@ -501,7 +501,7 @@ shutdown_tunnel (void *cls, void *value) { struct MeshPeer *p = value; - struct MeshTunnel2 *t = p->tunnel; + struct MeshTunnel3 *t = p->tunnel; if (NULL != t) GMT_destroy (t); @@ -646,52 +646,6 @@ peer_delete_oldest (void) } -/** - * Retrieve the MeshPeer stucture associated with the peer, create one - * and insert it in the appropriate structures if the peer is not known yet. - * - * @param peer Full identity of the peer. - * - * @return Existing or newly created peer info. - */ -static struct MeshPeer * -peer_get (const struct GNUNET_PeerIdentity *peer_id) -{ - struct MeshPeer *peer; - - peer = GNUNET_CONTAINER_multipeermap_get (peers, peer_id); - if (NULL == peer) - { - peer = GNUNET_new (struct MeshPeer); - if (GNUNET_CONTAINER_multipeermap_size (peers) > max_peers) - { - peer_delete_oldest (); - } - GNUNET_CONTAINER_multipeermap_put (peers, peer_id, peer, - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); - peer->id = GNUNET_PEER_intern (peer_id); - } - peer->last_contact = GNUNET_TIME_absolute_get(); - - return peer; -} - - -/** - * Retrieve the MeshPeer stucture associated with the peer, create one - * and insert it in the appropriate structures if the peer is not known yet. - * - * @param peer Short identity of the peer. - * - * @return Existing or newly created peer info. - */ -static struct MeshPeer * -peer_get_short (const GNUNET_PEER_Id peer) -{ - return peer_get (GNUNET_PEER_resolve2 (peer)); -} - - /** * Get a cost of a path for a peer considering existing tunnel connections. * @@ -818,7 +772,7 @@ queue_send (void *cls, size_t size, void *buf) struct MeshConnection *c; struct GNUNET_MessageHeader *msg; struct MeshPeerQueue *queue; - struct MeshTunnel2 *t; + struct MeshTunnel3 *t; struct MeshChannel *ch; const struct GNUNET_PeerIdentity *dst_id; size_t data_size; @@ -1434,6 +1388,50 @@ GMP_shutdown (void) GNUNET_PEER_change_rc (myid, -1); } +/** + * Retrieve the MeshPeer stucture associated with the peer, create one + * and insert it in the appropriate structures if the peer is not known yet. + * + * @param peer Full identity of the peer. + * + * @return Existing or newly created peer structure. + */ +struct MeshPeer * +GMP_get (const struct GNUNET_PeerIdentity *peer_id) +{ + struct MeshPeer *peer; + + peer = GNUNET_CONTAINER_multipeermap_get (peers, peer_id); + if (NULL == peer) + { + peer = GNUNET_new (struct MeshPeer); + if (GNUNET_CONTAINER_multipeermap_size (peers) > max_peers) + { + peer_delete_oldest (); + } + GNUNET_CONTAINER_multipeermap_put (peers, peer_id, peer, + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); + peer->id = GNUNET_PEER_intern (peer_id); + } + peer->last_contact = GNUNET_TIME_absolute_get(); + + return peer; +} + + +/** + * Retrieve the MeshPeer stucture associated with the peer, create one + * and insert it in the appropriate structures if the peer is not known yet. + * + * @param peer Short identity of the peer. + * + * @return Existing or newly created peer structure. + */ +struct MeshPeer * +GMP_get_short (const GNUNET_PEER_Id peer) +{ + return GMP_get (GNUNET_PEER_resolve2 (peer)); +} /** * Try to establish a new connection to this peer in the given tunnel. @@ -1445,7 +1443,7 @@ GMP_shutdown (void) void GMP_connect (struct MeshPeer *peer) { - struct MeshTunnel2 *t; + struct MeshTunnel3 *t; struct MeshPeerPath *p; struct MeshConnection *c; int rerun_search; @@ -1520,7 +1518,7 @@ GMP_connect (struct MeshPeer *peer) * @param t Tunnel. */ void -GMP_set_tunnel (struct MeshPeer *peer, struct MeshTunnel2 *t) +GMP_set_tunnel (struct MeshPeer *peer, struct MeshTunnel3 *t) { peer->tunnel = t; } @@ -1552,6 +1550,22 @@ GMP_is_neighbor (const struct MeshPeer *peer) } +/** + * Create and initialize a new tunnel towards a peer, in case it has none. + * + * Does not generate any traffic, just creates the local data structures. + * + * @param peer Peer towards which to create the tunnel. + */ +void +GMP_add_tunnel (struct MeshPeer *peer) +{ + if (NULL != peer->tunnel) + return; + peer->tunnel = GMT_new (peer); +} + + /** * Add a connection to a neighboring peer. * @@ -1707,7 +1721,7 @@ GMP_add_path_to_all (struct MeshPeerPath *p, int confirmed) struct MeshPeer *aux; struct MeshPeerPath *copy; - aux = peer_get_short (p->peers[i]); + aux = GMP_get_short (p->peers[i]); copy = path_duplicate (p); copy->length = i + 1; GMP_add_path (aux, copy, p->length < 3 ? GNUNET_NO : confirmed); diff --git a/src/mesh/gnunet-service-mesh_peer.h b/src/mesh/gnunet-service-mesh_peer.h index 1918a7842..4cd108b30 100644 --- a/src/mesh/gnunet-service-mesh_peer.h +++ b/src/mesh/gnunet-service-mesh_peer.h @@ -77,6 +77,30 @@ GMP_init (const struct GNUNET_CONFIGURATION_Handle *c); void GMP_shutdown (void); + +/** + * Retrieve the MeshPeer stucture associated with the peer, create one + * and insert it in the appropriate structures if the peer is not known yet. + * + * @param peer Full identity of the peer. + * + * @return Existing or newly created peer structure. + */ +struct MeshPeer * +GMP_get (const struct GNUNET_PeerIdentity *peer_id); + + +/** + * Retrieve the MeshPeer stucture associated with the peer, create one + * and insert it in the appropriate structures if the peer is not known yet. + * + * @param peer Short identity of the peer. + * + * @return Existing or newly created peer structure. + */ +struct MeshPeer * +GMP_get_short (const GNUNET_PEER_Id peer); + /** * @brief Queue and pass message to core when possible. * @@ -128,6 +152,15 @@ GMP_set_tunnel (struct MeshPeer *peer, struct MeshTunnel3 *t); int GMP_is_neighbor (const struct MeshPeer *peer); +/** + * Create and initialize a new tunnel towards a peer, in case it has none. + * + * Does not generate any traffic, just creates the local data structures. + * + * @param peer Peer towards which to create the tunnel. + */ +void +GMP_add_tunnel (struct MeshPeer *peer); /** * Add a connection to a neighboring peer. @@ -142,7 +175,7 @@ GMP_is_neighbor (const struct MeshPeer *peer); * @return GNUNET_OK on success. */ int -GMP_add_connection (struct MeshPeer *peer, struct MeshConnection *c); +GMP_add_connection (struct MeshPeer *peer, const struct MeshConnection *c); /** * Add the path to the peer and update the path used to reach it in case this diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c index bd57956ad..286eca618 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.c +++ b/src/mesh/gnunet-service-mesh_tunnel.c @@ -573,14 +573,17 @@ GMT_shutdown (void) /** * Create a tunnel. + * + * @param destination Peer this tunnel is towards. */ struct MeshTunnel3 * -GMT_new (void) +GMT_new (struct MeshPeer *destination) { struct MeshTunnel3 *t; t = GNUNET_new (struct MeshTunnel3); t->next_chid = 0; + t->peer = destination; // if (GNUNET_OK != // GNUNET_CONTAINER_multihashmap_put (tunnels, tid, t, // GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) diff --git a/src/mesh/gnunet-service-mesh_tunnel.h b/src/mesh/gnunet-service-mesh_tunnel.h index 6ec94ed53..f966fb2fe 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.h +++ b/src/mesh/gnunet-service-mesh_tunnel.h @@ -101,6 +101,14 @@ GMT_init (const struct GNUNET_CONFIGURATION_Handle *c, void GMT_shutdown (void); +/** + * Create a tunnel. + * + * @param destination Peer this tunnel is towards. + */ +struct MeshTunnel3 * +GMT_new (struct MeshPeer *destination); + /** * Tunnel is empty: destroy it. *