/**
- * Get string description for tunnel state.
+ * Get string description for tunnel state. Reentrant.
*
* @param s Tunnel state.
*
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;
* @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));
msg->peer2 = *id2;
neighbor = GMP_get_short (peer_id);
GMP_queue_add (neighbor, msg,
- GNUNET_MESSAGE_TYPE_MESH_ENCRYPTED,
+ GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN,
sizeof (struct GNUNET_MESH_ConnectionBroken),
NULL, GNUNET_SYSERR, /* connection, fwd */
NULL, NULL); /* continuation */
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);
}
}
LOG (GNUNET_ERROR_TYPE_DEBUG, " storing at %u\n", i - offset);
path->peers[i - offset] = shortid;
- if (path->peers[i] == myid)
- *own_pos = i;
+ if (path->peers[i - offset] == myid)
+ *own_pos = i - offset;
}
path->length -= offset;
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;
orig_peer = GMP_get (&id[0]);
/* Is it a connection to us? */
- if (c->own_pos == size - 1)
+ if (c->own_pos == path->length - 1)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, " It's for us!\n");
GMP_add_path_to_origin (orig_peer, path_duplicate (path), GNUNET_YES);
/**
- * 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 *out_msg;
+ struct MeshPeer *neighbor;
+ struct MeshPeer *endpoint;
+
+ neighbor = get_hop (c, !fwd);
+ endpoint = GMP_get_short (c->path->peers[c->path->length - 1]);
path_invalidate (c->path);
- if (0 < c->pending_messages)
- c->destroy = GNUNET_YES;
- else
- GMC_destroy (c);
+ GMP_notify_broken_link (endpoint, &msg->peer1, &msg->peer2);
+ c->state = MESH_CONNECTION_DESTROYED;
+ while (NULL != (out_msg = GMP_connection_pop (neighbor, c)))
+ {
+ GNUNET_assert (NULL ==
+ GMT_send_prebuilt_message (out_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);
}
+/**
+ * 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.
*
{
struct MeshFlowControl *fc;
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " checking sendability of %s traffic on %s\n",
+ GM_f2s (fwd), GMC_2s (c));
if (NULL == c)
{
GNUNET_break (0);
return GNUNET_YES;
}
fc = fwd ? &c->fwd_fc : &c->bck_fc;
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " last ack recv: %u, last pid sent: %u\n",
+ fc->last_ack_recv, fc->last_pid_sent);
if (GM_is_pid_bigger (fc->last_ack_recv, fc->last_pid_sent))
return GNUNET_YES;
return GNUNET_NO;
{
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));
}