aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-10-10 15:47:14 +0000
committerBart Polot <bart@net.in.tum.de>2013-10-10 15:47:14 +0000
commit0f50b74b830b74d16ba4ceded679dbe8cf206c5c (patch)
tree89437c9e8a5fe1d42b0f213d39eb19fe1b1f0b2f /src/mesh
parentbdce0f5ebf081bb80a36062674fbaac5f45eb7e0 (diff)
downloadgnunet-0f50b74b830b74d16ba4ceded679dbe8cf206c5c.tar.gz
gnunet-0f50b74b830b74d16ba4ceded679dbe8cf206c5c.zip
- expose appropriate functions in API
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh_connection.c58
-rw-r--r--src/mesh/gnunet-service-mesh_connection.h9
-rw-r--r--src/mesh/gnunet-service-mesh_peer.c17
-rw-r--r--src/mesh/gnunet-service-mesh_peer.h12
-rw-r--r--src/mesh/gnunet-service-mesh_tunnel.h13
5 files changed, 71 insertions, 38 deletions
diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c
index 2a0cfbc17..ee19d6706 100644
--- a/src/mesh/gnunet-service-mesh_connection.c
+++ b/src/mesh/gnunet-service-mesh_connection.c
@@ -480,35 +480,6 @@ send_connection_ack (struct MeshConnection *connection, int fwd)
480 480
481 481
482/** 482/**
483 * Sends a CREATE CONNECTION message for a path to a peer.
484 * Changes the connection and tunnel states if necessary.
485 *
486 * @param connection Connection to create.
487 */
488static void
489send_connection_create (struct MeshConnection *connection)
490{
491enum MeshTunnel3State state;
492 size_t size;
493
494 size = sizeof (struct GNUNET_MESH_ConnectionCreate);
495 size += connection->path->length * sizeof (struct GNUNET_PeerIdentity);
496 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection create\n");
497 GMP_queue_add (NULL,
498 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE,
499 size,
500 connection,
501 NULL,
502 GNUNET_YES, &message_sent, (void *) size);
503 state = GMT_get_state (connection->t);
504 if (MESH_TUNNEL3_SEARCHING == state || MESH_TUNNEL3_NEW == state)
505 GMT_change_state (connection->t, MESH_TUNNEL3_WAITING);
506 if (MESH_CONNECTION_NEW == connection->state)
507 connection_change_state (connection, MESH_CONNECTION_SENT);
508}
509
510
511/**
512 * Send keepalive packets for a connection. 483 * Send keepalive packets for a connection.
513 * 484 *
514 * @param c Connection to keep alive.. 485 * @param c Connection to keep alive..
@@ -2037,6 +2008,35 @@ GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
2037 2008
2038 2009
2039/** 2010/**
2011 * Sends a CREATE CONNECTION message for a path to a peer.
2012 * Changes the connection and tunnel states if necessary.
2013 *
2014 * @param connection Connection to create.
2015 */
2016void
2017GMC_send_create (struct MeshConnection *connection)
2018{
2019enum MeshTunnel3State state;
2020 size_t size;
2021
2022 size = sizeof (struct GNUNET_MESH_ConnectionCreate);
2023 size += connection->path->length * sizeof (struct GNUNET_PeerIdentity);
2024 LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection create\n");
2025 GMP_queue_add (NULL,
2026 GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE,
2027 size,
2028 connection,
2029 NULL,
2030 GNUNET_YES, &message_sent, (void *) size);
2031 state = GMT_get_state (connection->t);
2032 if (MESH_TUNNEL3_SEARCHING == state || MESH_TUNNEL3_NEW == state)
2033 GMT_change_state (connection->t, MESH_TUNNEL3_WAITING);
2034 if (MESH_CONNECTION_NEW == connection->state)
2035 GMC_change_state (connection, MESH_CONNECTION_SENT);
2036}
2037
2038
2039/**
2040 * Send a message to all peers in this connection that the connection 2040 * Send a message to all peers in this connection that the connection
2041 * is no longer valid. 2041 * is no longer valid.
2042 * 2042 *
diff --git a/src/mesh/gnunet-service-mesh_connection.h b/src/mesh/gnunet-service-mesh_connection.h
index 0d70764c2..436ae01c7 100644
--- a/src/mesh/gnunet-service-mesh_connection.h
+++ b/src/mesh/gnunet-service-mesh_connection.h
@@ -397,6 +397,15 @@ GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
397 int fwd); 397 int fwd);
398 398
399/** 399/**
400 * Sends a CREATE CONNECTION message for a path to a peer.
401 * Changes the connection and tunnel states if necessary.
402 *
403 * @param connection Connection to create.
404 */
405void
406GMC_send_create (struct MeshConnection *connection);
407
408/**
400 * Send a message to all peers in this connection that the connection 409 * Send a message to all peers in this connection that the connection
401 * is no longer valid. 410 * is no longer valid.
402 * 411 *
diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c
index a0dede486..72eabab28 100644
--- a/src/mesh/gnunet-service-mesh_peer.c
+++ b/src/mesh/gnunet-service-mesh_peer.c
@@ -732,7 +732,7 @@ peer_get_best_path (const struct MeshPeer *peer)
732 * @param path 732 * @param path
733 */ 733 */
734static void 734static void
735search_handler (void *cls, struct MeshPeerPath *path) 735search_handler (void *cls, const struct MeshPeerPath *path)
736{ 736{
737 struct MeshPeer *peer = cls; 737 struct MeshPeer *peer = cls;
738 unsigned int connection_count; 738 unsigned int connection_count;
@@ -1299,7 +1299,7 @@ GMP_queue_unlock (struct MeshPeer *peer, struct MeshConnection *c)
1299 return; /* Already unlocked */ 1299 return; /* Already unlocked */
1300 } 1300 }
1301 1301
1302 q = connection_get_first_message (c); 1302 q = connection_get_first_message (peer, c);
1303 if (NULL == q) 1303 if (NULL == q)
1304 { 1304 {
1305 LOG (GNUNET_ERROR_TYPE_DEBUG, " queue empty!\n"); 1305 LOG (GNUNET_ERROR_TYPE_DEBUG, " queue empty!\n");
@@ -1433,12 +1433,13 @@ GMP_get_short (const GNUNET_PEER_Id peer)
1433 return GMP_get (GNUNET_PEER_resolve2 (peer)); 1433 return GMP_get (GNUNET_PEER_resolve2 (peer));
1434} 1434}
1435 1435
1436
1436/** 1437/**
1437 * Try to establish a new connection to this peer in the given tunnel. 1438 * Try to establish a new connection to this peer (in its tunnel).
1438 * If the peer doesn't have any path to it yet, try to get one. 1439 * If the peer doesn't have any path to it yet, try to get one.
1439 * If the peer already has some path, send a CREATE CONNECTION towards it. 1440 * If the peer already has some path, send a CREATE CONNECTION towards it.
1440 * 1441 *
1441 * @param peer PeerInfo of the peer. 1442 * @param peer Peer to connect to.
1442 */ 1443 */
1443void 1444void
1444GMP_connect (struct MeshPeer *peer) 1445GMP_connect (struct MeshPeer *peer)
@@ -1462,7 +1463,7 @@ GMP_connect (struct MeshPeer *peer)
1462 if (NULL != p) 1463 if (NULL != p)
1463 { 1464 {
1464 LOG (GNUNET_ERROR_TYPE_DEBUG, " %u hops\n", p->length); 1465 LOG (GNUNET_ERROR_TYPE_DEBUG, " %u hops\n", p->length);
1465 c = tunnel_use_path (t, p); 1466 c = GMT_use_path (t, p);
1466 if (NULL == c) 1467 if (NULL == c)
1467 { 1468 {
1468 /* This case can happen when the path includes a first hop that is 1469 /* This case can happen when the path includes a first hop that is
@@ -1482,7 +1483,7 @@ GMP_connect (struct MeshPeer *peer)
1482 } 1483 }
1483 else 1484 else
1484 { 1485 {
1485 send_connection_create (c); 1486 GMC_send_create (c);
1486 return; 1487 return;
1487 } 1488 }
1488 } 1489 }
@@ -1505,7 +1506,7 @@ GMP_connect (struct MeshPeer *peer)
1505 LOG (GNUNET_ERROR_TYPE_DEBUG, 1506 LOG (GNUNET_ERROR_TYPE_DEBUG,
1506 " Starting DHT GET for peer %s\n", peer2s (peer)); 1507 " Starting DHT GET for peer %s\n", peer2s (peer));
1507 peer->search_h = GMD_search (id, &search_handler, peer); 1508 peer->search_h = GMD_search (id, &search_handler, peer);
1508 if (MESH_TUNNEL3_NEW == t->state) 1509 if (MESH_TUNNEL3_NEW == GMT_get_state (t))
1509 GMT_change_state (t, MESH_TUNNEL3_SEARCHING); 1510 GMT_change_state (t, MESH_TUNNEL3_SEARCHING);
1510 } 1511 }
1511} 1512}
@@ -1580,7 +1581,7 @@ GMP_add_tunnel (struct MeshPeer *peer)
1580 */ 1581 */
1581int 1582int
1582GMP_add_connection (struct MeshPeer *peer, 1583GMP_add_connection (struct MeshPeer *peer,
1583 const struct MeshConnection *c) 1584 struct MeshConnection *c)
1584{ 1585{
1585 if (NULL == peer->connections) 1586 if (NULL == peer->connections)
1586 { 1587 {
diff --git a/src/mesh/gnunet-service-mesh_peer.h b/src/mesh/gnunet-service-mesh_peer.h
index 84bf4eb2a..4213ab38b 100644
--- a/src/mesh/gnunet-service-mesh_peer.h
+++ b/src/mesh/gnunet-service-mesh_peer.h
@@ -102,6 +102,16 @@ struct MeshPeer *
102GMP_get_short (const GNUNET_PEER_Id peer); 102GMP_get_short (const GNUNET_PEER_Id peer);
103 103
104/** 104/**
105 * Try to establish a new connection to this peer (in its tunnel).
106 * If the peer doesn't have any path to it yet, try to get one.
107 * If the peer already has some path, send a CREATE CONNECTION towards it.
108 *
109 * @param peer Peer to connect to.
110 */
111void
112GMP_connect (struct MeshPeer *peer);
113
114/**
105 * @brief Queue and pass message to core when possible. 115 * @brief Queue and pass message to core when possible.
106 * 116 *
107 * @param cls Closure (@c type dependant). It will be used by queue_send to 117 * @param cls Closure (@c type dependant). It will be used by queue_send to
@@ -175,7 +185,7 @@ GMP_add_tunnel (struct MeshPeer *peer);
175 * @return GNUNET_OK on success. 185 * @return GNUNET_OK on success.
176 */ 186 */
177int 187int
178GMP_add_connection (struct MeshPeer *peer, const struct MeshConnection *c); 188GMP_add_connection (struct MeshPeer *peer, struct MeshConnection *c);
179 189
180/** 190/**
181 * Add the path to the peer and update the path used to reach it in case this 191 * 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.h b/src/mesh/gnunet-service-mesh_tunnel.h
index f966fb2fe..c55e91fe2 100644
--- a/src/mesh/gnunet-service-mesh_tunnel.h
+++ b/src/mesh/gnunet-service-mesh_tunnel.h
@@ -222,6 +222,19 @@ void
222GMT_send_queued_data (struct MeshTunnel3 *t, int fwd); 222GMT_send_queued_data (struct MeshTunnel3 *t, int fwd);
223 223
224/** 224/**
225 * @brief Use the given path for the tunnel.
226 * Update the next and prev hops (and RCs).
227 * (Re)start the path refresh in case the tunnel is locally owned.
228 *
229 * @param t Tunnel to update.
230 * @param p Path to use.
231 *
232 * @return Connection created.
233 */
234struct MeshConnection *
235GMT_use_path (struct MeshTunnel3 *t, struct MeshPeerPath *p);
236
237/**
225 * Count established (ready) connections of a tunnel. 238 * Count established (ready) connections of a tunnel.
226 * 239 *
227 * @param t Tunnel on which to count. 240 * @param t Tunnel on which to count.