return "MESH_CONNECTION_ACK";
case MESH_CONNECTION_READY:
return "MESH_CONNECTION_READY";
+ case MESH_CONNECTION_DESTROYED:
+ return "MESH_CONNECTION_DESTROYED";
default:
return "MESH_CONNECTION_STATE_ERROR";
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Connection %s state was %s\n",
GMC_2s (c), GMC_state2s (c->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));
* @param size Size of the message.
* @param wait Time spent waiting for core (only the time for THIS message)
*/
-static void
+static void
message_sent (void *cls,
struct MeshConnection *c, uint16_t type,
int fwd, size_t size,
* #GNUNET_NO for BCK.
* #GNUNET_SYSERR for errors.
*/
-static int
+static int
is_fwd (const struct MeshConnection *c,
const struct GNUNET_PeerIdentity *sender)
{
*
* @param c Connection to keep alive..
* @param fwd Is this a FWD keepalive? (owner -> dest).
+ *
+ * FIXME use only one type, register in GMC_send_prebuilt_message()
*/
static void
connection_keepalive (struct MeshConnection *c, int fwd)
/**
* Cancel all transmissions that belong to a certain connection.
- *
+ *
* If the connection is scheduled for destruction and no more messages are left,
* the connection will be destroyed by the continuation call.
*
struct MeshFlowControl *fc;
struct MeshPeer *peer;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ " *** Cancel %s queues for connection %s\n",
+ fwd ? "FWD" : "BCK", GMC_2s (c));
if (NULL == c)
{
GNUNET_break (0);
{
GNUNET_SCHEDULER_cancel (fc->poll_task);
fc->poll_task = GNUNET_SCHEDULER_NO_TASK;
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " *** Cancel POLL in ccq for fc %p\n", fc);
}
peer = get_hop (c, fwd);
GMP_queue_cancel (peer, c);
{
struct MeshFlowControl *fc = cls;
- LOG (GNUNET_ERROR_TYPE_DEBUG, " *** POLL sent, scheduling new one!\n");
+ if (2 == c->destroy)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " *** POLL canceled on shutdown\n");
+ return;
+ }
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ " *** POLL sent for , scheduling new one!\n");
fc->poll_msg = NULL;
fc->poll_time = GNUNET_TIME_STD_BACKOFF (fc->poll_time);
fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time,
&connection_poll, fc);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " task %u\n", fc->poll_task);
+
}
/**
}
else
{
- path = c->path;
+ path = path_duplicate (c->path);
}
if (MESH_CONNECTION_NEW == c->state)
connection_change_state (c, MESH_CONNECTION_SENT);
if (c->own_pos == size - 1)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, " It's for us!\n");
- GMP_add_path_to_origin (orig_peer, path, GNUNET_YES);
+ GMP_add_path_to_origin (orig_peer, path_duplicate (path), GNUNET_YES);
add_to_peer (c, orig_peer);
if (MESH_TUNNEL3_NEW == GMT_get_state (c->t))
/* It's for somebody else! Retransmit. */
LOG (GNUNET_ERROR_TYPE_DEBUG, " Retransmitting.\n");
GMP_add_path (dest_peer, path_duplicate (path), GNUNET_NO);
- GMP_add_path_to_origin (orig_peer, path, GNUNET_NO);
+ GMP_add_path_to_origin (orig_peer, path_duplicate (path), GNUNET_NO);
GMC_send_prebuilt_message (message, c, GNUNET_YES, NULL, NULL);
}
+ path_destroy (path);
return GNUNET_OK;
}
*/
GNUNET_STATISTICS_update (stats, "# control on unknown tunnel",
1, GNUNET_NO);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " connection unknown: already destroyed?\n");
return GNUNET_OK;
}
fwd = is_fwd (c, peer);
}
GMC_send_prebuilt_message (message, c, fwd, NULL, NULL);
c->destroy = GNUNET_YES;
+ c->state = MESH_CONNECTION_DESTROYED;
return GNUNET_OK;
}
if (NULL == c)
{
GNUNET_STATISTICS_update (stats, "# unknown connection", 1, GNUNET_NO);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING connection unknown\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "WARNING connection %s unknown\n",
+ GNUNET_h2s (&msg->cid));
return GNUNET_OK;
}
return;
}
+ if (GNUNET_NO != c->destroy)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " being destroyed, why bother...\n");
+ return;
+ }
+
/* Get available buffer space */
if (GMC_is_terminal (c, fwd))
{
connections = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_YES);
}
+
+/**
+ * Destroy each connection on shutdown.
+ *
+ * @param cls Closure (unused).
+ * @param key Current key code (CID, unused).
+ * @param value Value in the hash map (connection)
+ *
+ * @return #GNUNET_YES, because we should continue to iterate,
+ */
+static int
+shutdown_iterator (void *cls,
+ const struct GNUNET_HashCode *key,
+ void *value)
+{
+ struct MeshConnection *c = value;
+
+ GMC_destroy (c);
+ return GNUNET_YES;
+}
+
+
/**
* Shut down the connections subsystem.
*/
void
GMC_shutdown (void)
{
+ GNUNET_CONTAINER_multihashmap_iterate (connections, &shutdown_iterator, NULL);
GNUNET_CONTAINER_multihashmap_destroy (connections);
connections = NULL;
}
c->destroy = 2;
LOG (GNUNET_ERROR_TYPE_DEBUG, "destroying connection %s\n", GMC_2s (c));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " fc's f: %p, b: %p\n",
+ &c->fwd_fc, &c->bck_fc);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " fc tasks f: %u, b: %u\n",
+ c->fwd_fc.poll_task, c->bck_fc.poll_task);
/* Cancel all traffic */
connection_cancel_queues (c, GNUNET_YES);
connection_cancel_queues (c, GNUNET_NO);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " fc tasks f: %u, b: %u\n",
+ c->fwd_fc.poll_task, c->bck_fc.poll_task);
+
/* Cancel maintainance task (keepalive/timeout) */
if (GNUNET_SCHEDULER_NO_TASK != c->fwd_maintenance_task)
GNUNET_SCHEDULER_cancel (c->fwd_maintenance_task);
if (GNUNET_SCHEDULER_NO_TASK != c->bck_maintenance_task)
GNUNET_SCHEDULER_cancel (c->bck_maintenance_task);
if (GNUNET_SCHEDULER_NO_TASK != c->fwd_fc.poll_task)
+ {
GNUNET_SCHEDULER_cancel (c->fwd_fc.poll_task);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " *** POLL FWD canceled\n");
+ }
if (GNUNET_SCHEDULER_NO_TASK != c->bck_fc.poll_task)
+ {
GNUNET_SCHEDULER_cancel (c->bck_fc.poll_task);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " *** POLL BCK canceled\n");
+ }
if (NULL != c->fwd_fc.poll_msg)
+ {
GMC_cancel (c->fwd_fc.poll_msg);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " *** POLL msg FWD canceled\n");
+ }
if (NULL != c->bck_fc.poll_msg)
+ {
GMC_cancel (c->bck_fc.poll_msg);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " *** POLL msg BCK canceled\n");
+ }
/* Unregister from neighbors */
unregister_neighbors (c);
* (the one we just scheduled), so no point in checking whether to
* destroy immediately. */
c->destroy = GNUNET_YES;
+ c->state = MESH_CONNECTION_DESTROYED;
/**
* Cancel all queues, if no message is left, connection will be destroyed.
if (GNUNET_NO == GMC_is_terminal (c, GNUNET_NO))
GMC_send_prebuilt_message (&msg.header, c, GNUNET_NO, NULL, NULL);
c->destroy = GNUNET_YES;
+ c->state = MESH_CONNECTION_DESTROYED;
}
struct MeshFlowControl *fc;
fc = fwd ? &c->fwd_fc : &c->bck_fc;
- if (GNUNET_SCHEDULER_NO_TASK != fc->poll_task && NULL != fc->poll_msg)
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " *** POLL %s requested\n",
+ fwd ? "FWD" : "BCK");
+ if (GNUNET_SCHEDULER_NO_TASK != fc->poll_task || NULL != fc->poll_msg)
{
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " *** not needed (%u, %p)\n",
+ fc->poll_task, fc->poll_msg);
return;
}
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " *** POLL started on request\n");
fc->poll_task = GNUNET_SCHEDULER_add_delayed (fc->poll_time,
&connection_poll,
fc);
return buf;
}
return GNUNET_h2s (&c->id);
-}
\ No newline at end of file
+}