aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh_connection.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesh/gnunet-service-mesh_connection.c')
-rw-r--r--src/mesh/gnunet-service-mesh_connection.c62
1 files changed, 38 insertions, 24 deletions
diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c
index 7c3cb08bb..edcb79953 100644
--- a/src/mesh/gnunet-service-mesh_connection.c
+++ b/src/mesh/gnunet-service-mesh_connection.c
@@ -32,6 +32,7 @@
32#include "gnunet-service-mesh_connection.h" 32#include "gnunet-service-mesh_connection.h"
33#include "gnunet-service-mesh_peer.h" 33#include "gnunet-service-mesh_peer.h"
34#include "gnunet-service-mesh_tunnel.h" 34#include "gnunet-service-mesh_tunnel.h"
35#include "gnunet-service-mesh_channel.h"
35#include "mesh_protocol_enc.h" 36#include "mesh_protocol_enc.h"
36#include "mesh_path.h" 37#include "mesh_path.h"
37 38
@@ -1048,7 +1049,7 @@ GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
1048 LOG (GNUNET_ERROR_TYPE_DEBUG, " ... adding %s\n", 1049 LOG (GNUNET_ERROR_TYPE_DEBUG, " ... adding %s\n",
1049 GNUNET_i2s (&id[i])); 1050 GNUNET_i2s (&id[i]));
1050 path->peers[i] = GNUNET_PEER_intern (&id[i]); 1051 path->peers[i] = GNUNET_PEER_intern (&id[i]);
1051 if (path->peers[i] == myid) 1052 if (path->peers[i] == my_short_id)
1052 own_pos = i; 1053 own_pos = i;
1053 } 1054 }
1054 if (own_pos == 0 && path->peers[own_pos] != myid) 1055 if (own_pos == 0 && path->peers[own_pos] != myid)
@@ -1056,7 +1057,7 @@ GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
1056 /* create path: self not found in path through self */ 1057 /* create path: self not found in path through self */
1057 GNUNET_break_op (0); 1058 GNUNET_break_op (0);
1058 path_destroy (path); 1059 path_destroy (path);
1059 connection_destroy (c); 1060 GMC_destroy (c);
1060 return GNUNET_OK; 1061 return GNUNET_OK;
1061 } 1062 }
1062 LOG (GNUNET_ERROR_TYPE_DEBUG, " Own position: %u\n", own_pos); 1063 LOG (GNUNET_ERROR_TYPE_DEBUG, " Own position: %u\n", own_pos);
@@ -1086,9 +1087,9 @@ GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
1086 orig_peer->tunnel = tunnel_new (); 1087 orig_peer->tunnel = tunnel_new ();
1087 orig_peer->tunnel->peer = orig_peer; 1088 orig_peer->tunnel->peer = orig_peer;
1088 } 1089 }
1089 tunnel_add_connection (orig_peer->tunnel, c); 1090 GMT_add_connection (orig_peer->tunnel, c);
1090 if (MESH_TUNNEL_NEW == c->t->state) 1091 if (MESH_TUNNEL_NEW == GMT_get_state (c->t))
1091 tunnel_change_state (c->t, MESH_TUNNEL_WAITING); 1092 GMT_change_state (c->t, MESH_TUNNEL_WAITING);
1092 1093
1093 send_connection_ack (c, GNUNET_NO); 1094 send_connection_ack (c, GNUNET_NO);
1094 if (MESH_CONNECTION_SENT == c->state) 1095 if (MESH_CONNECTION_SENT == c->state)
@@ -1199,15 +1200,14 @@ GMC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer,
1199 if (GMC_is_terminal (c, GNUNET_YES)) 1200 if (GMC_is_terminal (c, GNUNET_YES))
1200 { 1201 {
1201 LOG (GNUNET_ERROR_TYPE_DEBUG, " Connection ACK for us!\n"); 1202 LOG (GNUNET_ERROR_TYPE_DEBUG, " Connection ACK for us!\n");
1202 if (MESH_TUNNEL_READY != c->t->state) 1203 GMC_change_state (c, MESH_CONNECTION_READY);
1203 tunnel_change_state (c->t, MESH_TUNNEL_READY); 1204 GMT_change_state (c->t, MESH_TUNNEL_READY);
1204 connection_change_state (c, MESH_CONNECTION_READY); 1205 GMT_send_queued_data (c->t, GNUNET_NO);
1205 tunnel_send_queued_data (c->t, GNUNET_NO);
1206 return GNUNET_OK; 1206 return GNUNET_OK;
1207 } 1207 }
1208 1208
1209 LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n"); 1209 LOG (GNUNET_ERROR_TYPE_DEBUG, " not for us, retransmitting...\n");
1210 send_prebuilt_message_connection (message, c, NULL, fwd); 1210 GMC_send_prebuilt_message (message, c, NULL, fwd);
1211 return GNUNET_OK; 1211 return GNUNET_OK;
1212} 1212}
1213 1213
@@ -1287,16 +1287,16 @@ GMC_handle_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
1287 return GNUNET_OK; 1287 return GNUNET_OK;
1288 } 1288 }
1289 id = GNUNET_PEER_search (peer); 1289 id = GNUNET_PEER_search (peer);
1290 if (id == connection_get_prev_hop (c)->id) 1290 if (id == GMP_get_short_id (connection_get_prev_hop (c)))
1291 fwd = GNUNET_YES; 1291 fwd = GNUNET_YES;
1292 else if (id == connection_get_next_hop (c)->id) 1292 else if (id == GMP_get_short_id (connection_get_next_hop (c)))
1293 fwd = GNUNET_NO; 1293 fwd = GNUNET_NO;
1294 else 1294 else
1295 { 1295 {
1296 GNUNET_break_op (0); 1296 GNUNET_break_op (0);
1297 return GNUNET_OK; 1297 return GNUNET_OK;
1298 } 1298 }
1299 send_prebuilt_message_connection (message, c, NULL, fwd); 1299 GMC_send_prebuilt_message (message, c, NULL, fwd);
1300 c->destroy = GNUNET_YES; 1300 c->destroy = GNUNET_YES;
1301 1301
1302 return GNUNET_OK; 1302 return GNUNET_OK;
@@ -1353,7 +1353,7 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer,
1353 1353
1354 /* Check if origin is as expected */ 1354 /* Check if origin is as expected */
1355 neighbor = connection_get_hop (c, !fwd); 1355 neighbor = connection_get_hop (c, !fwd);
1356 if (peer_get (peer)->id != neighbor->id) 1356 if (GNUNET_PEER_search (peer) != GMP_get_short_id (neighbor))
1357 { 1357 {
1358 GNUNET_break_op (0); 1358 GNUNET_break_op (0);
1359 return GNUNET_OK; 1359 return GNUNET_OK;
@@ -1502,13 +1502,13 @@ GMC_handle_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
1502 1502
1503 /* Is this a forward or backward ACK? */ 1503 /* Is this a forward or backward ACK? */
1504 id = GNUNET_PEER_search (peer); 1504 id = GNUNET_PEER_search (peer);
1505 if (connection_get_next_hop (c)->id == id) 1505 if (GMP_get_short_id (connection_get_next_hop (c)) == id)
1506 { 1506 {
1507 LOG (GNUNET_ERROR_TYPE_DEBUG, " FWD ACK\n"); 1507 LOG (GNUNET_ERROR_TYPE_DEBUG, " FWD ACK\n");
1508 fc = &c->fwd_fc; 1508 fc = &c->fwd_fc;
1509 fwd = GNUNET_YES; 1509 fwd = GNUNET_YES;
1510 } 1510 }
1511 else if (connection_get_prev_hop (c)->id == id) 1511 else if (GMP_get_short_id (connection_get_prev_hop (c)) == id)
1512 { 1512 {
1513 LOG (GNUNET_ERROR_TYPE_DEBUG, " BCK ACK\n"); 1513 LOG (GNUNET_ERROR_TYPE_DEBUG, " BCK ACK\n");
1514 fc = &c->bck_fc; 1514 fc = &c->bck_fc;
@@ -1585,12 +1585,12 @@ GMC_handle_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
1585 * this way of discerining FWD/BCK should not be a problem. 1585 * this way of discerining FWD/BCK should not be a problem.
1586 */ 1586 */
1587 id = GNUNET_PEER_search (peer); 1587 id = GNUNET_PEER_search (peer);
1588 if (connection_get_next_hop (c)->id == id) 1588 if (GMP_get_short_id (connection_get_next_hop (c)) == id)
1589 { 1589 {
1590 LOG (GNUNET_ERROR_TYPE_DEBUG, " FWD ACK\n"); 1590 LOG (GNUNET_ERROR_TYPE_DEBUG, " FWD ACK\n");
1591 fc = &c->fwd_fc; 1591 fc = &c->fwd_fc;
1592 } 1592 }
1593 else if (connection_get_prev_hop (c)->id == id) 1593 else if (GMP_get_short_id (connection_get_prev_hop (c)) == id)
1594 { 1594 {
1595 LOG (GNUNET_ERROR_TYPE_DEBUG, " BCK ACK\n"); 1595 LOG (GNUNET_ERROR_TYPE_DEBUG, " BCK ACK\n");
1596 fc = &c->bck_fc; 1596 fc = &c->bck_fc;
@@ -1625,7 +1625,7 @@ GMC_handle_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
1625 */ 1625 */
1626int 1626int
1627GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer, 1627GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
1628 const struct GNUNET_MessageHeader *message) 1628 const struct GNUNET_MessageHeader *message)
1629{ 1629{
1630 struct GNUNET_MESH_ConnectionKeepAlive *msg; 1630 struct GNUNET_MESH_ConnectionKeepAlive *msg;
1631 struct MeshConnection *c; 1631 struct MeshConnection *c;
@@ -1649,7 +1649,7 @@ GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
1649 1649
1650 /* Check if origin is as expected */ 1650 /* Check if origin is as expected */
1651 neighbor = connection_get_hop (c, fwd); 1651 neighbor = connection_get_hop (c, fwd);
1652 if (peer_get (peer)->id != neighbor->id) 1652 if (GNUNET_PEER_search (peer) != GMP_get_short_id (neighbor))
1653 { 1653 {
1654 GNUNET_break_op (0); 1654 GNUNET_break_op (0);
1655 return GNUNET_OK; 1655 return GNUNET_OK;
@@ -1676,8 +1676,8 @@ GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
1676 * @param ch Channel, if any. 1676 * @param ch Channel, if any.
1677 * @param fwd Is this a fwd ACK? (will go dest->root) 1677 * @param fwd Is this a fwd ACK? (will go dest->root)
1678 */ 1678 */
1679static void 1679void
1680send_ack (struct MeshConnection *c, struct MeshChannel *ch, int fwd) 1680GMC_send_ack (struct MeshConnection *c, struct MeshChannel *ch, int fwd)
1681{ 1681{
1682 unsigned int buffer; 1682 unsigned int buffer;
1683 1683
@@ -1686,8 +1686,10 @@ send_ack (struct MeshConnection *c, struct MeshChannel *ch, int fwd)
1686 fwd ? "FWD" : "BCK", c, ch); 1686 fwd ? "FWD" : "BCK", c, ch);
1687 if (NULL == c || GMC_is_terminal (c, fwd)) 1687 if (NULL == c || GMC_is_terminal (c, fwd))
1688 { 1688 {
1689 struct MeshTunnel3 *t;
1689 LOG (GNUNET_ERROR_TYPE_DEBUG, " getting from all connections\n"); 1690 LOG (GNUNET_ERROR_TYPE_DEBUG, " getting from all connections\n");
1690 buffer = GMT_get_buffer (NULL == c ? ch->t : c->t, fwd); 1691 t = (NULL == c) ? GMCH_get_tunnel (ch) : GMC_get_tunnel (c);
1692 buffer = GMT_get_buffer (t, fwd);
1691 } 1693 }
1692 else 1694 else
1693 { 1695 {
@@ -1721,7 +1723,6 @@ send_ack (struct MeshConnection *c, struct MeshChannel *ch, int fwd)
1721} 1723}
1722 1724
1723 1725
1724
1725/** 1726/**
1726 * Initialize the connections subsystem 1727 * Initialize the connections subsystem
1727 * 1728 *
@@ -1866,6 +1867,19 @@ GMC_get_state (const struct MeshConnection *c)
1866 return c->state; 1867 return c->state;
1867} 1868}
1868 1869
1870/**
1871 * Get the connection tunnel.
1872 *
1873 * @param c Connection to get the tunnel from.
1874 *
1875 * @return tunnel of the connection.
1876 */
1877struct MeshTunnel3 *
1878GMC_get_tunnel (const struct MeshConnection *c)
1879{
1880 return c->t;
1881}
1882
1869 1883
1870/** 1884/**
1871 * Get free buffer space in a connection. 1885 * Get free buffer space in a connection.