/**
* ID of the connection.
*/
- struct GNUNET_HashCode id;
+ struct GNUNET_MeshHash id;
/**
* State of the connection.
/**
- * Get string description for tunnel state.
+ * Resets the connection timeout task, some other message has done the
+ * task's job.
+ * - For the first peer on the direction this means to send
+ * a keepalive or a path confirmation message (either create or ACK).
+ * - For all other peers, this means to destroy the connection,
+ * due to lack of activity.
+ * Starts the timeout if no timeout was running (connection just created).
+ *
+ * @param c Connection whose timeout to reset.
+ * @param fwd Is this forward?
+ */
+static void
+connection_reset_timeout (struct MeshConnection *c, int fwd);
+
+
+/**
+ * Get string description for tunnel state. Reentrant.
*
* @param s Tunnel state.
*
* @param cid Connection ID.
*/
static struct MeshConnection *
-connection_get (const struct GNUNET_HashCode *cid)
+connection_get (const struct GNUNET_MeshHash *cid)
{
- return GNUNET_CONTAINER_multihashmap_get (connections, cid);
+ return GNUNET_CONTAINER_multihashmap_get (connections, GM_h2hc (cid));
}
enum MeshConnectionState state)
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %s state was %s\n",
- GMC_2s (c), GMC_state2s (c->state));
+ "Connection %s state %s -> %s\n",
+ GMC_2s (c), GMC_state2s (c->state), GMC_state2s (state));
if (MESH_CONNECTION_DESTROYED == c->state)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, "state not changing anymore\n");
return;
}
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Connection %s state is now %s\n",
- GMC_2s (c), GMC_state2s (state));
c->state = state;
if (MESH_CONNECTION_READY == state)
c->create_retry = 1;
fc->last_pid_sent);
}
GMC_send_ack (c, fwd, GNUNET_NO);
+ connection_reset_timeout (c, fwd);
break;
case GNUNET_MESSAGE_TYPE_MESH_POLL:
* @param peer Peer to notify (neighbor who sent the connection).
*/
static void
-send_broken2 (struct GNUNET_HashCode *connection_id,
+send_broken2 (struct GNUNET_MeshHash *connection_id,
const struct GNUNET_PeerIdentity *id1,
const struct GNUNET_PeerIdentity *id2,
GNUNET_PEER_Id peer_id)
struct GNUNET_MESH_ConnectionBroken *msg;
struct MeshPeer *neighbor;
- LOG (GNUNET_ERROR_TYPE_INFO,
- "Send BROKEN on unknown connection %s\n", GNUNET_h2s (connection_id));
+ LOG (GNUNET_ERROR_TYPE_INFO, "=> BROKEN on unknown connection %s\n",
+ GNUNET_h2s (GM_h2hc (connection_id)));
msg = GNUNET_new (struct GNUNET_MESH_ConnectionBroken);
msg->header.size = htons (sizeof (struct GNUNET_MESH_ConnectionBroken));
LOG (GNUNET_ERROR_TYPE_INFO,
"keepalive %s for connection %s\n",
GM_f2s (fwd), GMC_2s (c));
+ GNUNET_STATISTICS_update (stats, "# keepalives sent", 1, GNUNET_NO);
GNUNET_assert (NULL != c->t);
msg.size = htons (sizeof (msg));
/* Schedule the task */
*task_id = GNUNET_SCHEDULER_add_delayed (delay, keepalive_task, c);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "next keepalive in %s\n",
+ GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
}
static void
connection_reset_timeout (struct MeshConnection *c, int fwd)
{
- GNUNET_SCHEDULER_TaskIdentifier *ti;
- GNUNET_SCHEDULER_Task f;
-
- ti = fwd ? &c->fwd_maintenance_task : &c->bck_maintenance_task;
-
LOG (GNUNET_ERROR_TYPE_DEBUG, "Connection %s reset timeout\n", GM_f2s (fwd));
- if (GNUNET_SCHEDULER_NO_TASK != *ti)
- GNUNET_SCHEDULER_cancel (*ti);
-
if (GMC_is_origin (c, fwd)) /* Startpoint */
{
- f = fwd ? &connection_fwd_keepalive : &connection_bck_keepalive;
- *ti = GNUNET_SCHEDULER_add_delayed (refresh_connection_time, f, c);
+ schedule_next_keepalive (c, fwd);
}
else /* Relay, endpoint. */
{
struct GNUNET_TIME_Relative delay;
+ GNUNET_SCHEDULER_TaskIdentifier *ti;
+ GNUNET_SCHEDULER_Task f;
+ ti = fwd ? &c->fwd_maintenance_task : &c->bck_maintenance_task;
+
+ if (GNUNET_SCHEDULER_NO_TASK != *ti)
+ GNUNET_SCHEDULER_cancel (*ti);
delay = GNUNET_TIME_relative_multiply (refresh_connection_time, 4);
f = fwd ? &connection_fwd_timeout : &connection_bck_timeout;
*ti = GNUNET_SCHEDULER_add_delayed (delay, f, c);
if (path->peers[j] == shortid)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, " already exists at pos %u\n", j);
- offset += i - j;
- LOG (GNUNET_ERROR_TYPE_DEBUG, " offset now\n", offset);
+ offset = i - j;
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " offset now %u\n", offset);
GNUNET_PEER_change_rc (shortid, -1);
}
}
static void
log_message (const struct GNUNET_MessageHeader *message,
const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HashCode *hash)
+ const struct GNUNET_MeshHash *hash)
{
LOG (GNUNET_ERROR_TYPE_INFO, "<- %s on connection %s from %s\n",
- GM_m2s (ntohs (message->type)), GNUNET_h2s (hash), GNUNET_i2s (peer));
+ GM_m2s (ntohs (message->type)), GNUNET_h2s (GM_h2hc (hash)),
+ GNUNET_i2s (peer));
}
/******************************************************************************/
{
struct GNUNET_MESH_ConnectionCreate *msg;
struct GNUNET_PeerIdentity *id;
- struct GNUNET_HashCode *cid;
+ struct GNUNET_MeshHash *cid;
struct MeshPeerPath *path;
struct MeshPeer *dest_peer;
struct MeshPeer *orig_peer;
/**
- * Core handler for notifications of broken paths
+ * Core handler for notifications of broken connections.
*
* @param cls Closure (unused).
* @param id Peer identity of sending neighbor.
c = connection_get (&msg->cid);
if (NULL == c)
{
- GNUNET_break_op (0);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " duplicate CONNECTION_BROKEN\n");
return GNUNET_OK;
}
fwd = is_fwd (c, id);
if (GMC_is_terminal (c, fwd))
{
+ struct GNUNET_MessageHeader *msg;
+ struct MeshPeer *peer;
+
+ peer = get_hop (c, !fwd);
path_invalidate (c->path);
- if (0 < c->pending_messages)
- c->destroy = GNUNET_YES;
- else
- GMC_destroy (c);
+ c->state = MESH_CONNECTION_DESTROYED;
+ while (NULL != (msg = GMP_connection_pop (peer, c)))
+ {
+ GNUNET_assert (NULL ==
+ GMT_send_prebuilt_message (msg, c->t, NULL, GNUNET_YES,
+ NULL, NULL));
+ }
+
+ GMC_destroy (c);
}
else
{
if (NULL == c)
{
GNUNET_STATISTICS_update (stats, "# unknown connection", 1, GNUNET_NO);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING enc on unknown connection %s\n",
- GNUNET_h2s (&msg->cid));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "enc on unknown connection %s\n",
+ GNUNET_h2s (GM_h2hc (&msg->cid)));
return GNUNET_OK;
}
{
GNUNET_STATISTICS_update (stats, "# unknown connection", 1, GNUNET_NO);
LOG (GNUNET_ERROR_TYPE_DEBUG, "kx on unknown connection %s\n",
- GNUNET_h2s (&msg->cid));
+ GNUNET_h2s (GM_h2hc (&msg->cid)));
return GNUNET_OK;
}
LOG (GNUNET_ERROR_TYPE_DEBUG, " on connection %s\n", GMC_2s (c));
GNUNET_NO);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"WARNING POLL message on unknown connection %s!\n",
- GNUNET_h2s (&msg->cid));
+ GNUNET_h2s (GM_h2hc (&msg->cid)));
return GNUNET_OK;
}
return;
}
create_connection_time = GNUNET_TIME_UNIT_SECONDS;
- connections = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_YES);
+ connections = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO);
}
struct MeshConnection *
-GMC_new (const struct GNUNET_HashCode *cid,
+GMC_new (const struct GNUNET_MeshHash *cid,
struct MeshTunnel3 *t,
struct MeshPeerPath *p,
unsigned int own_pos)
c->id = *cid;
GNUNET_assert (GNUNET_OK ==
GNUNET_CONTAINER_multihashmap_put (connections,
- &c->id, c,
+ GMC_get_h (c), c,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
fc_init (&c->fwd_fc);
fc_init (&c->bck_fc);
}
GNUNET_break (GNUNET_YES ==
- GNUNET_CONTAINER_multihashmap_remove (connections, &c->id, c));
+ GNUNET_CONTAINER_multihashmap_remove (connections,
+ GMC_get_h (c), c));
GNUNET_STATISTICS_update (stats, "# connections", -1, GNUNET_NO);
GNUNET_free (c);
*
* @return ID of the connection.
*/
-const struct GNUNET_HashCode *
+const struct GNUNET_MeshHash *
GMC_get_id (const struct MeshConnection *c)
{
return &c->id;
}
+/**
+ * Get the connection ID.
+ *
+ * @param c Connection to get the ID from.
+ *
+ * @return ID of the connection.
+ */
+const struct GNUNET_HashCode *
+GMC_get_h (const struct MeshConnection *c)
+{
+ return GM_h2hc (&c->id);
+}
+
+
/**
* Get the connection path.
*
bmsg->cid = c->id;
break;
+ case GNUNET_MESSAGE_TYPE_MESH_KEEPALIVE:
+ GNUNET_break (0);
+ /* falltrough */
case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE:
case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK:
- case GNUNET_MESSAGE_TYPE_MESH_KEEPALIVE:
break;
default:
{
static char buf[128];
- sprintf (buf, "%s (->%s)", GNUNET_h2s (&c->id), GMT_2s (c->t));
+ sprintf (buf, "%s (->%s)", GNUNET_h2s (GM_h2hc (GMC_get_id(c))), GMT_2s (c->t));
return buf;
}
- return GNUNET_h2s (&c->id);
+ return GNUNET_h2s (GM_h2hc (&c->id));
}