[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r28328 - gnunet/src/mesh
From: |
gnunet |
Subject: |
[GNUnet-SVN] r28328 - gnunet/src/mesh |
Date: |
Sat, 27 Jul 2013 09:50:45 +0200 |
Author: bartpolot
Date: 2013-07-27 09:50:45 +0200 (Sat, 27 Jul 2013)
New Revision: 28328
Modified:
gnunet/src/mesh/gnunet-service-mesh-enc.c
gnunet/src/mesh/mesh.conf.in
gnunet/src/mesh/mesh_path.h
gnunet/src/mesh/mesh_protocol_enc.h
Log:
- wip
Modified: gnunet/src/mesh/gnunet-service-mesh-enc.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh-enc.c 2013-07-26 12:56:07 UTC (rev
28327)
+++ gnunet/src/mesh/gnunet-service-mesh-enc.c 2013-07-27 07:50:45 UTC (rev
28328)
@@ -130,6 +130,29 @@
MESH_TUNNEL_RECONNECTING
};
+
+/**
+ * All the states a connection can be in.
+ */
+enum MeshConnectionState
+{
+ /**
+ * Uninitialized status, should never appear in operation.
+ */
+ MESH_CONNECTION_NEW,
+
+ /**
+ * Connection created, waiting for ACK.
+ */
+ MESH_CONNECTION_SENT,
+
+ /**
+ * Connection confirmed, ready to carry traffic..
+ */
+ MESH_CONNECTION_READY,
+};
+
+
/******************************************************************************/
/************************ DATA STRUCTURES
****************************/
/******************************************************************************/
@@ -478,6 +501,11 @@
uint32_t id;
/**
+ * State of the connection
+ */
+ enum MeshConnectionState state;
+
+ /**
* Path being used for the tunnel.
*/
struct MeshPeerPath *path;
@@ -658,7 +686,7 @@
/**
* How often to send path keepalives. Paths timeout after 4 missed.
*/
-static struct GNUNET_TIME_Relative refresh_path_time;
+static struct GNUNET_TIME_Relative refresh_connection_time;
/**
* How often to PUT own ID in the DHT.
@@ -873,7 +901,7 @@
/**
* Change the tunnel state.
*
- * @param t Tunnel whose ttate to change.
+ * @param t Tunnel whose state to change.
* @param state New state.
*/
static void
@@ -1023,38 +1051,31 @@
__mesh_divider______________________________________________________________();
+/**
+ * Get string description for tunnel state.
+ *
+ * @param s Tunnel state.
+ *
+ * @return String representation.
+ */
static const char *
-GNUNET_MESH_DEBUG_S2S (enum MeshTunnelState s)
+GNUNET_MESH_DEBUG_TS2S (enum MeshTunnelState s)
{
static char buf[128];
switch (s)
{
- /**
- * Uninitialized status, should never appear in operation.
- */
- case MESH_TUNNEL_NEW: return "MESH_TUNNEL_NEW";
+ case MESH_TUNNEL_NEW:
+ return "MESH_TUNNEL_NEW";
+ case MESH_TUNNEL_SEARCHING:
+ return "MESH_TUNNEL_SEARCHING";
+ case MESH_TUNNEL_WAITING:
+ return "MESH_TUNNEL_WAITING";
+ case MESH_TUNNEL_READY:
+ return "MESH_TUNNEL_READY";
+ case MESH_TUNNEL_RECONNECTING:
+ return "MESH_TUNNEL_RECONNECTING";
- /**
- * Path to the peer not known yet
- */
- case MESH_TUNNEL_SEARCHING: return "MESH_TUNNEL_SEARCHING";
-
- /**
- * Request sent, not yet answered.
- */
- case MESH_TUNNEL_WAITING: return "MESH_TUNNEL_WAITING";
-
- /**
- * Peer connected and ready to accept data
- */
- case MESH_TUNNEL_READY: return "MESH_TUNNEL_READY";
-
- /**
- * Peer connected previosly but not responding
- */
- case MESH_TUNNEL_RECONNECTING: return "MESH_TUNNEL_RECONNECTING";
-
default:
sprintf (buf, "%u (UNKNOWN STATE)", s);
return buf;
@@ -1062,6 +1083,31 @@
}
+/**
+ * Get string description for tunnel state.
+ *
+ * @param s Tunnel state.
+ *
+ * @return String representation.
+ */
+static const char *
+GNUNET_MESH_DEBUG_CS2S (enum MeshTunnelState s)
+{
+ switch (s)
+ {
+ case MESH_CONNECTION_NEW:
+ return "MESH_CONNECTION_NEW";
+ case MESH_CONNECTION_SENT:
+ return "MESH_CONNECTION_SENT";
+ case MESH_CONNECTION_READY:
+ return "MESH_CONNECTION_READY";
+ default:
+ return "MESH_CONNECTION_STATE_ERROR";
+ }
+}
+
+
+
/******************************************************************************/
/************************ PERIODIC FUNCTIONS
****************************/
/******************************************************************************/
@@ -1664,7 +1710,7 @@
}
}
}
- return path->length + overlap;
+ return (path->length + overlap) * (path->score * -1);
}
@@ -1692,7 +1738,8 @@
if (c->path == p)
break;
if (NULL != p)
- continue;
+ continue; /* If path is in use in a connection, skip it. */
+
if ((cost = peer_get_path_cost (peer, p)) < best_cost)
{
best_cost = cost;
@@ -1725,6 +1772,7 @@
{
c = tunnel_use_path (t, p);
send_connection_create (t, c);
+ connection_change_state (c, MESH_CONNECTION_SENT);
}
}
else if (NULL == peer->dhtget)
@@ -2342,7 +2390,7 @@
/**
* Change the tunnel state.
*
- * @param t Tunnel whose ttate to change.
+ * @param t Tunnel whose state to change.
* @param state New state.
*/
static void
@@ -2351,16 +2399,36 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Tunnel %s[%X] state was %s\n",
GNUNET_i2s (GNUNET_PEER_resolve2 (t->id.oid)), t->id.tid,
- GNUNET_MESH_DEBUG_S2S (t->state));
+ GNUNET_MESH_DEBUG_TS2S (t->state));
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Tunnel %s[%X] state is now %s\n",
GNUNET_i2s (GNUNET_PEER_resolve2 (t->id.oid)), t->id.tid,
- GNUNET_MESH_DEBUG_S2S (state));
+ GNUNET_MESH_DEBUG_TS2S (state));
t->state = state;
}
+/**
+ * Change the tunnel state.
+ *
+ * @param c Connection whose state to change.
+ * @param state New state.
+ */
+static void
+connection_change_state (MeshConnection* c, MeshConnectionState state)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %s[%X] state was %s\n",
+ GNUNET_i2s (GNUNET_PEER_resolve2 (c->t->peer->id)), c->id,
+ GNUNET_MESH_DEBUG_CS2S (c->state));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Connection %s[%X] state is now %s\n",
+ GNUNET_i2s (GNUNET_PEER_resolve2 (c->t->peer->id)), c->id,
+ GNUNET_MESH_DEBUG_CS2S (state));
+ c->state = state;
+}
+
/**
* Add a client to a tunnel, initializing all needed data structures.
*
@@ -2423,7 +2491,7 @@
if (GNUNET_SCHEDULER_NO_TASK != c->fwd_maintenance_task)
GNUNET_SCHEDULER_cancel (c->fwd_maintenance_task);
c->fwd_maintenance_task =
- GNUNET_SCHEDULER_add_delayed (refresh_path_time,
+ GNUNET_SCHEDULER_add_delayed (refresh_connection_time,
&connection_fwd_keepalive, c);
}
return c;
@@ -2988,13 +3056,13 @@
/**
* Send keepalive packets for a tunnel.
*
- * @param t Tunnel to keep alive..
+ * @param c Connection to keep alive..
* @param fwd Is this a FWD keepalive? (owner -> dest).
*/
static void
-tunnel_keepalive (struct MeshTunnel *t, int fwd)
+connection_keepalive (struct MeshConnection *c, int fwd)
{
- struct GNUNET_MESH_TunnelKeepAlive *msg;
+ struct GNUNET_MESH_ConnectionKeepAlive *msg;
size_t size = sizeof (struct GNUNET_MESH_TunnelKeepAlive);
char cbuf[size];
GNUNET_PEER_Id hop;
@@ -3002,11 +3070,11 @@
type = fwd ? GNUNET_MESSAGE_TYPE_MESH_FWD_KEEPALIVE :
GNUNET_MESSAGE_TYPE_MESH_BCK_KEEPALIVE;
- hop = fwd ? t->next_hop : t->prev_hop;
+ hop = fwd ? connection_get_next_hop (c) : connection_get_prev_hop (c);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "sending %s keepalive for tunnel %d\n",
- fwd ? "FWD" : "BCK", t->id.tid);
+ "sending %s keepalive for connection %d\n",
+ fwd ? "FWD" : "BCK", c->id);
msg = (struct GNUNET_MESH_TunnelKeepAlive *) cbuf;
msg->header.size = htons (size);
@@ -3024,7 +3092,7 @@
* @param fwd If GNUNET_YES, send CREATE, otherwise send ACK.
*/
static void
-tunnel_recreate (struct MeshTunnel *t, int fwd)
+connection_recreate (struct MeshTunnel *t, int fwd)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"sending path recreate for tunnel %s[%X]\n",
@@ -3037,29 +3105,31 @@
/**
- * Generic tunnel timer management.
- * Depending on the role of the peer in the tunnel will send the
+ * Generic connection timer management.
+ * Depending on the role of the peer in the connection will send the
* appropriate message (build or keepalive)
*
- * @param t Tunnel to maintain.
+ * @param c Conncetion to maintain.
* @param fwd Is FWD?
*/
static void
-tunnel_maintain (struct MeshTunnel *t, int fwd)
+connection_maintain (struct MeshConnection *c, int fwd)
{
- switch (t->state)
+ if (MESH_TUNNEL_SEARCHING == c->t->state)
{
- case MESH_TUNNEL_NEW:
+ /* TODO DHT GET with RO_BART */
+ return;
+ }
+ switch (c->state)
+ {
+ case MESH_CONNECTION_NEW:
GNUNET_break (0);
- case MESH_TUNNEL_SEARCHING:
- /* TODO DHT GET with RO_BART */
+ case MESH_CONNECTION_SENT:
+ connection_recreate (t, fwd);
break;
- case MESH_TUNNEL_WAITING:
- tunnel_recreate (t, fwd);
+ case MESH_CONNECTION_READY:
+ connection_keepalive (t, fwd);
break;
- case MESH_TUNNEL_READY:
- tunnel_keepalive (t, fwd);
- break;
default:
break;
}
@@ -3067,36 +3137,34 @@
static void
-tunnel_fwd_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+connection_fwd_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
{
- struct MeshTunnel *t = cls;
+ struct MeshConnection *c = cls;
- t->fwd_maintenance_task = GNUNET_SCHEDULER_NO_TASK;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) ||
- NULL == t->owner)
+ c->fwd_maintenance_task = GNUNET_SCHEDULER_NO_TASK;
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
- tunnel_maintain (t, GNUNET_YES);
- t->fwd_maintenance_task = GNUNET_SCHEDULER_add_delayed (refresh_path_time,
-
&tunnel_fwd_keepalive,
- t);
+ connection_keepalive (c, GNUNET_YES);
+ c->fwd_maintenance_task = GNUNET_SCHEDULER_add_delayed
(refresh_connection_time,
+
&connection_fwd_keepalive,
+ c);
}
static void
-tunnel_bck_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+connection_bck_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext
*tc)
{
- struct MeshTunnel *t = cls;
+ struct MeshConnection *c = cls;
- t->bck_maintenance_task = GNUNET_SCHEDULER_NO_TASK;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) ||
- NULL == t->client)
+ c->bck_maintenance_task = GNUNET_SCHEDULER_NO_TASK;
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
- tunnel_keepalive (t, GNUNET_NO);
- t->bck_maintenance_task = GNUNET_SCHEDULER_add_delayed (refresh_path_time,
-
&tunnel_bck_keepalive,
- t);
+ connection_keepalive (c, GNUNET_NO);
+ c->bck_maintenance_task = GNUNET_SCHEDULER_add_delayed
(refresh_connection_time,
+
&connection_bck_keepalive,
+ c);
}
@@ -3399,9 +3467,10 @@
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Client %u is destination.\n",
c->id);
t->client = NULL;
- if (0 != t->next_hop) { /* destroy could come before a path is used */
- GNUNET_PEER_change_rc (t->next_hop, -1);
- t->next_hop = 0;
+ if (0 != t->next_hop) /* destroy could come before a path is used */
+ {
+ GNUNET_PEER_change_rc (t->next_hop, -1);
+ t->next_hop = 0;
}
}
if (c == t->owner)
@@ -3524,13 +3593,13 @@
if (NULL != c)
{
f = fwd ? &tunnel_fwd_keepalive : &tunnel_bck_keepalive;
- *ti = GNUNET_SCHEDULER_add_delayed (refresh_path_time, f, t);
+ *ti = GNUNET_SCHEDULER_add_delayed (refresh_connection_time, f, t);
}
else
{
f = fwd ? &tunnel_fwd_timeout : &tunnel_bck_timeout;
*ti = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
- (refresh_path_time, 4),
+ (refresh_connection_time, 4),
f, t);
}
}
@@ -4910,6 +4979,7 @@
{
struct MeshPeer *peer = cls;
struct MeshPeerPath *p;
+ struct MeshConnection *c;
struct GNUNET_PeerIdentity pi;
int i;
@@ -4921,7 +4991,13 @@
put_path, put_path_length);
path_add_to_peers (p, GNUNET_NO);
path_destroy (p);
-
+
+ /* Count connections */
+ for (c = peer->tunnel->connection_head, i = 0; NULL != c; c = c->next, i++);
+
+ if (3 <= i)
+ return;
+
if (peer->tunnel->state == MESH_TUNNEL_SEARCHING)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ... connect!\n");
@@ -5856,8 +5932,8 @@
}
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_time (c, "MESH", "REFRESH_PATH_TIME",
- &refresh_path_time))
+ GNUNET_CONFIGURATION_get_value_time (c, "MESH",
"REFRESH_CONNECTION_TIME",
+ &refresh_connection_time))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_
Modified: gnunet/src/mesh/mesh.conf.in
===================================================================
--- gnunet/src/mesh/mesh.conf.in 2013-07-26 12:56:07 UTC (rev 28327)
+++ gnunet/src/mesh/mesh.conf.in 2013-07-27 07:50:45 UTC (rev 28328)
@@ -9,7 +9,8 @@
UNIXPATH = /tmp/gnunet-service-mesh.sock
UNIX_MATCH_UID = YES
UNIX_MATCH_GID = YES
-REFRESH_PATH_TIME = 30 min
+REFRESH_CONNECTION_TIME = 5 min
+REFRESH_PATH_TIME = 30 min # deprecated, remove
ID_ANNOUNCE_TIME = 1 h
APP_ANNOUNCE_TIME = 1 h
CONNECT_TIMEOUT = 30 s
Modified: gnunet/src/mesh/mesh_path.h
===================================================================
--- gnunet/src/mesh/mesh_path.h 2013-07-26 12:56:07 UTC (rev 28327)
+++ gnunet/src/mesh/mesh_path.h 2013-07-27 07:50:45 UTC (rev 28328)
@@ -63,6 +63,11 @@
*/
unsigned int length;
+ /**
+ * Path's score, how reliable is the path.
+ */
+ int score;
+
};
/******************************************************************************/
Modified: gnunet/src/mesh/mesh_protocol_enc.h
===================================================================
--- gnunet/src/mesh/mesh_protocol_enc.h 2013-07-26 12:56:07 UTC (rev 28327)
+++ gnunet/src/mesh/mesh_protocol_enc.h 2013-07-27 07:50:45 UTC (rev 28328)
@@ -281,19 +281,19 @@
struct GNUNET_MESH_ConnectionKeepAlive
{
/**
- * Type: GNUNET_MESSAGE_TYPE_MESH_CONNECTION_(FWD|BCK)_KEEPALIVE
+ * Type: GNUNET_MESSAGE_TYPE_MESH_(FWD|BCK)_KEEPALIVE
*/
struct GNUNET_MessageHeader header;
/**
- * TID of the tunnel
+ * ID of the connection
*/
- uint32_t tid GNUNET_PACKED;
+ uint32_t cid GNUNET_PACKED;
/**
- * OID of the tunnel
+ * ID of the tunnel
*/
- struct GNUNET_PeerIdentity oid;
+ struct GNUNET_HashCode tid;
};
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r28328 - gnunet/src/mesh,
gnunet <=