[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r30022 - gnunet/src/mesh
From: |
gnunet |
Subject: |
[GNUnet-SVN] r30022 - gnunet/src/mesh |
Date: |
Wed, 9 Oct 2013 03:30:25 +0200 |
Author: bartpolot
Date: 2013-10-09 03:30:25 +0200 (Wed, 09 Oct 2013)
New Revision: 30022
Modified:
gnunet/src/mesh/gnunet-service-mesh_connection.c
gnunet/src/mesh/gnunet-service-mesh_peer.c
gnunet/src/mesh/gnunet-service-mesh_peer.h
gnunet/src/mesh/gnunet-service-mesh_tunnel.c
gnunet/src/mesh/gnunet-service-mesh_tunnel.h
Log:
- sync
Modified: gnunet/src/mesh/gnunet-service-mesh_connection.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_connection.c 2013-10-09 01:08:49 UTC
(rev 30021)
+++ gnunet/src/mesh/gnunet-service-mesh_connection.c 2013-10-09 01:30:25 UTC
(rev 30022)
@@ -31,6 +31,7 @@
#include "gnunet-service-mesh_connection.h"
#include "gnunet-service-mesh_peer.h"
+#include "gnunet-service-mesh_tunnel.h"
#include "mesh_protocol_enc.h"
#include "mesh_path.h"
@@ -314,7 +315,6 @@
}
-
/**
* Initialize a Flow Control structure to the initial state.
*
@@ -726,8 +726,6 @@
}
-
-
/**
* Function called if a connection has been stalled for a while,
* possibly due to a missed ACK. Poll the neighbor about its ACK status.
@@ -951,6 +949,23 @@
}
+/**
+ *
+ */
+static void
+unregister_neighbors (struct MeshConnection *c)
+{
+ struct MeshPeer *peer;
+
+ peer = connection_get_next_hop (c);
+ GMP_remove_connection (peer, c);
+
+ peer = connection_get_prev_hop (c);
+ GMP_remove_connection (peer, c);
+
+}
+
+
/******************************************************************************/
/******************************** API
***********************************/
/******************************************************************************/
@@ -1647,7 +1662,7 @@
return GNUNET_OK;
GNUNET_STATISTICS_update (stats, "# keepalives forwarded", 1, GNUNET_NO);
- send_prebuilt_message_connection (message, c, NULL, fwd);
+ GMC_send_prebuilt_message (message, c, NULL, fwd);
return GNUNET_OK;
}
@@ -1672,17 +1687,17 @@
if (NULL == c || GMC_is_terminal (c, fwd))
{
LOG (GNUNET_ERROR_TYPE_DEBUG, " getting from all connections\n");
- buffer = tunnel_get_buffer (NULL == c ? ch->t : c->t, fwd);
+ buffer = GMT_get_buffer (NULL == c ? ch->t : c->t, fwd);
}
else
{
LOG (GNUNET_ERROR_TYPE_DEBUG, " getting from one connection\n");
- buffer = connection_get_buffer (c, fwd);
+ buffer = GMC_get_buffer (c, fwd);
}
LOG (GNUNET_ERROR_TYPE_DEBUG, " buffer available: %u\n", buffer);
- if ( (NULL != ch && channel_is_origin (ch, fwd)) ||
- (NULL != c && connection_is_origin (c, fwd)) )
+ if ( (NULL != ch && GMCH_is_origin (ch, fwd)) ||
+ (NULL != c && GMC_is_origin (c, fwd)) )
{
LOG (GNUNET_ERROR_TYPE_DEBUG, " sending on channel...\n");
if (0 < buffer)
@@ -1763,7 +1778,6 @@
unsigned int own_pos)
{
struct MeshConnection *c;
- unsigned int own_pos;
c = GNUNET_new (struct MeshConnection);
c->id = *cid;
@@ -1795,7 +1809,7 @@
}
-static void
+void
GMC_destroy (struct MeshConnection *c)
{
struct MeshPeer *peer;
@@ -1803,9 +1817,8 @@
if (NULL == c)
return;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying connection %s[%X]\n",
- peer2s (c->t->peer),
- c->id);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying connection %s\n",
+ GNUNET_h2s (&c->id));
/* Cancel all traffic */
connection_cancel_queues (c, GNUNET_YES);
@@ -1817,17 +1830,12 @@
if (GNUNET_SCHEDULER_NO_TASK != c->bck_maintenance_task)
GNUNET_SCHEDULER_cancel (c->bck_maintenance_task);
- /* Deregister from neighbors */
- peer = connection_get_next_hop (c);
- if (NULL != peer && NULL != peer->connections)
- GNUNET_CONTAINER_multihashmap_remove (peer->connections, &c->id, c);
- peer = connection_get_prev_hop (c);
- if (NULL != peer && NULL != peer->connections)
- GNUNET_CONTAINER_multihashmap_remove (peer->connections, &c->id, c);
+ /* Unregister from neighbors */
+ unregister_neighbors (c);
/* Delete */
GNUNET_STATISTICS_update (stats, "# connections", -1, GNUNET_NO);
- GNUNET_CONTAINER_DLL_remove (c->t->connection_head, c->t->connection_tail,
c);
+ GMT_remove_connection (c->t, c);
GNUNET_free (c);
}
@@ -1909,7 +1917,6 @@
struct MeshPeer *peer,
struct GNUNET_PeerIdentity *my_full_id)
{
- struct MeshConnection *c = value;
struct GNUNET_MESH_ConnectionBroken msg;
int fwd;
@@ -1920,18 +1927,18 @@
{
/* Local shutdown, no one to notify about this. */
GMC_destroy (c);
- return GNUNET_YES;
+ return;
}
msg.header.size = htons (sizeof (struct GNUNET_MESH_ConnectionBroken));
msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN);
msg.cid = c->id;
msg.peer1 = *my_full_id;
- msg.peer2 = *GNUNET_PEER_resolve2 (peer->id);
+ msg.peer2 = *GMP_get_id (peer);
GMC_send_prebuilt_message (&msg.header, c, NULL, fwd);
c->destroy = GNUNET_YES;
- return GNUNET_YES;
+ return;
}
@@ -2084,9 +2091,8 @@
msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY);;
msg.cid = c->id;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- " sending connection destroy for connection %s[%X]\n",
- peer2s (c->t->peer),
- c->id);
+ " sending connection destroy for connection %s\n",
+ GNUNET_h2s (&c->id));
if (GNUNET_NO == GMC_is_terminal (c, GNUNET_YES))
GMC_send_prebuilt_message (&msg.header, c, NULL, GNUNET_YES);
Modified: gnunet/src/mesh/gnunet-service-mesh_peer.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_peer.c 2013-10-09 01:08:49 UTC (rev
30021)
+++ gnunet/src/mesh/gnunet-service-mesh_peer.c 2013-10-09 01:30:25 UTC (rev
30022)
@@ -1541,7 +1541,35 @@
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
}
+
+int
+GMP_remove_connection (struct MeshPeer *peer,
+ const struct MeshConnection *c)
+{
+ if (NULL == peer || NULL == peer->connections)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_CONTAINER_multihashmap_remove (peer->connections,
+ GMC_get_id (c),
+ c);
+}
+
/**
+ * Get the Full ID of a peer.
+ *
+ * @param peer Peer to get from.
+ *
+ * @return Full ID of peer.
+ */
+struct GNUNET_PeerIdentity *
+GMP_get_id (const struct MeshPeer *peer)
+{
+ return GNUNET_PEER_resolve2 (peer->id);
+}
+
+/**
* Get the static string for a peer ID.
*
* @param peer Peer.
Modified: gnunet/src/mesh/gnunet-service-mesh_peer.h
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_peer.h 2013-10-09 01:08:49 UTC (rev
30021)
+++ gnunet/src/mesh/gnunet-service-mesh_peer.h 2013-10-09 01:30:25 UTC (rev
30022)
@@ -40,6 +40,8 @@
#include "platform.h"
#include "gnunet_util_lib.h"
+#include "gnunet-service-mesh_connection.h"
+
/**
* Struct containing all information regarding a given peer
*/
@@ -115,7 +117,20 @@
int
GMP_add_connection (struct MeshPeer *peer, struct MeshConnection *c);
+int
+GMP_remove_connection (struct MeshPeer *peer, struct MeshConnection *c);
+
/**
+ * Get the Full ID of a peer.
+ *
+ * @param peer Peer to get from.
+ *
+ * @return Full ID of peer.
+ */
+struct GNUNET_PeerIdentity *
+GMP_get_id (const struct MeshPeer *peer);
+
+/**
* Get the static string for a peer ID.
*
* @param peer Peer.
Modified: gnunet/src/mesh/gnunet-service-mesh_tunnel.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_tunnel.c 2013-10-09 01:08:49 UTC
(rev 30021)
+++ gnunet/src/mesh/gnunet-service-mesh_tunnel.c 2013-10-09 01:30:25 UTC
(rev 30022)
@@ -290,58 +290,6 @@
/**
- * Get the total buffer space for a tunnel.
- *
- * @param t Tunnel.
- * @param fwd Is this for FWD traffic?
- *
- * @return Buffer space offered by all connections in the tunnel.
- */
-static unsigned int
-tunnel_get_buffer (struct MeshTunnel3 *t, int fwd)
-{
- struct MeshTConnection *iter;
- unsigned int buffer;
-
- iter = t->connection_head;
- buffer = 0;
-
- /* If terminal, return biggest channel buffer */
- if (NULL == iter || GMC_is_terminal (iter->c, fwd))
- {
- struct MeshTChannel *iter_ch;
- unsigned int ch_buf;
-
- if (NULL == t->channel_head)
- return 64;
-
- for (iter_ch = t->channel_head; NULL != iter_ch; iter_ch = iter_ch->next)
- {
- ch_buf = GMCH_get_buffer (iter_ch->ch, fwd);
- if (ch_buf > buffer)
- buffer = ch_buf;
- }
- return buffer;
- }
-
- /* If not terminal, return sum of connection buffers */
- while (NULL != iter)
- {
- if (GMC_get_state (iter->c) != MESH_CONNECTION_READY)
- {
- iter = iter->next;
- continue;
- }
-
- buffer += GMC_get_buffer (iter->c, fwd);
- iter = iter->next;
- }
-
- return buffer;
-}
-
-
-/**
* Send all cached messages that we can, tunnel is online.
*
* @param t Tunnel that holds the messages.
@@ -357,7 +305,7 @@
LOG (GNUNET_ERROR_TYPE_DEBUG,
"tunnel_send_queued_data on tunnel %s\n",
GMP_2s (t->peer));
- room = tunnel_get_buffer (t, fwd);
+ room = GMT_get_buffer (t, fwd);
LOG (GNUNET_ERROR_TYPE_DEBUG, " buffer space: %u\n", room);
for (tq = t->tq_head; NULL != tq && room > 0; tq = next)
{
@@ -741,6 +689,27 @@
/**
+ * Remove a connection from a tunnel.
+ *
+ * @param t Tunnel.
+ * @param c Connection.
+ */
+void
+GMT_remove_connection (struct MeshTunnel3 *t, struct MeshConnection *c)
+{
+ struct MeshTConnection *aux;
+
+ for (aux = t->connection_head; aux != NULL; aux = aux->next)
+ if (aux->c == c)
+ {
+ GNUNET_CONTAINER_DLL_remove (t->connection_head, t->connection_tail,
aux);
+ GNUNET_free (aux);
+ return;
+ }
+}
+
+
+/**
* Tunnel is empty: destroy it.
*
* Notifies all connections about the destruction.
@@ -983,6 +952,57 @@
/**
+ * Get the total buffer space for a tunnel.
+ *
+ * @param t Tunnel.
+ * @param fwd Is this for FWD traffic?
+ *
+ * @return Buffer space offered by all connections in the tunnel.
+ */
+unsigned int
+GMT_get_buffer (struct MeshTunnel3 *t, int fwd)
+{
+ struct MeshTConnection *iter;
+ unsigned int buffer;
+
+ iter = t->connection_head;
+ buffer = 0;
+
+ /* If terminal, return biggest channel buffer */
+ if (NULL == iter || GMC_is_terminal (iter->c, fwd))
+ {
+ struct MeshTChannel *iter_ch;
+ unsigned int ch_buf;
+
+ if (NULL == t->channel_head)
+ return 64;
+
+ for (iter_ch = t->channel_head; NULL != iter_ch; iter_ch = iter_ch->next)
+ {
+ ch_buf = GMCH_get_buffer (iter_ch->ch, fwd);
+ if (ch_buf > buffer)
+ buffer = ch_buf;
+ }
+ return buffer;
+ }
+
+ /* If not terminal, return sum of connection buffers */
+ while (NULL != iter)
+ {
+ if (GMC_get_state (iter->c) != MESH_CONNECTION_READY)
+ {
+ iter = iter->next;
+ continue;
+ }
+
+ buffer += GMC_get_buffer (iter->c, fwd);
+ iter = iter->next;
+ }
+
+ return buffer;
+}
+
+/**
* Sends an already built message on a tunnel, choosing the best connection.
*
* @param message Message to send. Function modifies it.
Modified: gnunet/src/mesh/gnunet-service-mesh_tunnel.h
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_tunnel.h 2013-10-09 01:08:49 UTC
(rev 30021)
+++ gnunet/src/mesh/gnunet-service-mesh_tunnel.h 2013-10-09 01:30:25 UTC
(rev 30022)
@@ -41,8 +41,8 @@
#include "gnunet_util_lib.h"
#include "gnunet-service-mesh_channel.h"
+#include "gnunet-service-mesh_connection.h"
-
/**
* All the states a tunnel can be in.
*/
@@ -142,8 +142,26 @@
void
GMT_change_state (struct MeshTunnel3* t, enum MeshTunnelState state);
+/**
+ * Add a connection to a tunnel.
+ *
+ * @param t Tunnel.
+ * @param c Connection.
+ */
+void
+GMT_add_connection (struct MeshTunnel3 *t, struct MeshConnection *c);
+
/**
+ * Remove a connection from a tunnel.
+ *
+ * @param t Tunnel.
+ * @param c Connection.
+ */
+void
+GMT_remove_connection (struct MeshTunnel3 *t, struct MeshConnection *c);
+
+/**
* Cache a message to be sent once tunnel is online.
*
* @param t Tunnel to hold the message.
@@ -177,6 +195,17 @@
unsigned int
GMT_count_channels (struct MeshTunnel3 *t);
+/**
+ * Get the total buffer space for a tunnel.
+ *
+ * @param t Tunnel.
+ * @param fwd Is this for FWD traffic?
+ *
+ * @return Buffer space offered by all connections in the tunnel.
+ */
+unsigned int
+GMT_get_buffer (struct MeshTunnel3 *t, int fwd);
+
#if 0 /* keep Emacsens' auto-indent happy */
{
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r30022 - gnunet/src/mesh,
gnunet <=