* Find a connection.
*
* @param cid Connection ID.
+ *
+ * @return conntection with the given ID @cid or NULL if not found.
*/
static struct CadetConnection *
connection_get (const struct GNUNET_CADET_Hash *cid)
}
+/**
+ * Mark a connection as "destroyed", to send all pending traffic and freeing
+ * all associated resources, without accepting new status changes on it.
+ *
+ * @param c Connection to mark as destroyed.
+ */
+static void
+mark_destroyed (struct CadetConnection *c)
+{
+ c->destroy = GNUNET_YES;
+ connection_change_state (c, CADET_CONNECTION_DESTROYED);
+}
+
+
/**
* Callback called when a queued ACK message is sent.
*
const struct GNUNET_PeerIdentity *peer_id)
{
struct GNUNET_CADET_ConnectionBroken *msg;
+ struct CadetPeerQueue *q;
struct CadetPeer *neighbor;
GCC_check_connections ();
memset (&msg->peer2, 0, sizeof (msg->peer2));
neighbor = GCP_get (peer_id, GNUNET_NO); /* We MUST know neighbor. */
GNUNET_assert (NULL != neighbor);
- GCP_queue_add (neighbor, msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN,
- UINT16_MAX, 2, sizeof (struct GNUNET_CADET_ConnectionBroken),
- NULL, GNUNET_SYSERR, /* connection, fwd */
- NULL, NULL); /* continuation */
+ q = GCP_queue_add (neighbor, msg, GNUNET_MESSAGE_TYPE_CADET_CONNECTION_BROKEN,
+ UINT16_MAX, 2,
+ sizeof (struct GNUNET_CADET_ConnectionBroken),
+ NULL, GNUNET_SYSERR, /* connection, fwd */
+ NULL, NULL); /* continuation */
+ GNUNET_assert (NULL != q);
GCC_check_connections ();
}
*
* @param c Connection to keep alive.
* @param fwd Direction.
- * @param shutdown Are we shutting down? (Don't send traffic)
- * Non-zero value for true, not necessarily GNUNET_YES.
*/
static void
-connection_keepalive (struct CadetConnection *c, int fwd, int shutdown)
+connection_keepalive (struct CadetConnection *c,
+ int fwd)
{
GCC_check_connections ();
LOG (GNUNET_ERROR_TYPE_DEBUG,
c->fwd_maintenance_task = NULL;
else
c->bck_maintenance_task = NULL;
-
- if (GNUNET_NO != shutdown)
- return;
-
connection_maintain (c, fwd);
GCC_check_connections ();
/* Next execution will be scheduled by message_sent or _maintain*/
* Keep the connection alive in the FWD direction.
*
* @param cls Closure (connection to keepalive).
- * @param tc TaskContext.
*/
static void
-connection_fwd_keepalive (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+connection_fwd_keepalive (void *cls)
{
+ struct CadetConnection *c = cls;
+
GCC_check_connections ();
- connection_keepalive ((struct CadetConnection *) cls,
- GNUNET_YES,
- tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN);
+ connection_keepalive (c,
+ GNUNET_YES);
GCC_check_connections ();
}
* Keep the connection alive in the BCK direction.
*
* @param cls Closure (connection to keepalive).
- * @param tc TaskContext.
*/
static void
-connection_bck_keepalive (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+connection_bck_keepalive (void *cls)
{
+ struct CadetConnection *c = cls;
+
GCC_check_connections ();
- connection_keepalive ((struct CadetConnection *) cls,
- GNUNET_NO,
- tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN);
+ connection_keepalive (c,
+ GNUNET_NO);
GCC_check_connections ();
}
* possibly due to a missed ACK. Poll the neighbor about its ACK status.
*
* @param cls Closure (poll ctx).
- * @param tc TaskContext.
*/
static void
-connection_poll (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+connection_poll (void *cls);
/**
* possibly due to a missed ACK. Poll the neighbor about its ACK status.
*
* @param cls Closure (poll ctx).
- * @param tc TaskContext.
*/
static void
-connection_poll (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+connection_poll (void *cls)
{
struct CadetFlowControl *fc = cls;
struct GNUNET_CADET_Poll msg;
fc->poll_task = NULL;
GCC_check_connections ();
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {
- return;
- }
-
c = fc->c;
fwd = fc == &c->fwd_fc;
LOG (GNUNET_ERROR_TYPE_DEBUG, "Polling connection %s %s\n",
int destroyed;
GCC_check_connections ();
- c->state = CADET_CONNECTION_DESTROYED;
- c->destroy = GNUNET_YES;
+ mark_destroyed (c);
destroyed = GNUNET_NO;
neighbor = get_hop (c, fwd);
}
/* If dest, salvage queued traffic. */
- if (GCC_is_origin (c, !fwd))
+ if (GCC_is_terminal (c, fwd))
{
const struct GNUNET_PeerIdentity *next_hop;
* Destroys connection if called.
*
* @param cls Closure (connection to destroy).
- * @param tc TaskContext.
*/
static void
-connection_fwd_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+connection_fwd_timeout (void *cls)
{
struct CadetConnection *c = cls;
c->fwd_maintenance_task = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GCC_check_connections ();
connection_timeout (c, GNUNET_YES);
GCC_check_connections ();
* Destroys connection if called.
*
* @param cls Closure (connection to destroy).
- * @param tc TaskContext
*/
static void
-connection_bck_timeout (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+connection_bck_timeout (void *cls)
{
struct CadetConnection *c = cls;
c->bck_maintenance_task = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
GCC_check_connections ();
connection_timeout (c, GNUNET_NO);
GCC_check_connections ();
/**
* Iterator to compare each connection's path with the path of a new connection.
*
- * If the connection conincides, the c member of path is set to the connection
+ * If the connection coincides, the c member of path is set to the connection
* and the destroy flag of the connection is set.
*
* @param cls Closure (new path).
GCC_2s (c), c, c->path->length);
if (c != new_conn
- && c->destroy == GNUNET_NO
- && c->state != CADET_CONNECTION_BROKEN
- && c->state != CADET_CONNECTION_DESTROYED
+ && GNUNET_NO == c->destroy
+ && CADET_CONNECTION_BROKEN != c->state
+ && CADET_CONNECTION_DESTROYED != c->state
&& path_equivalent (path, c->path))
{
- new_conn->destroy = GNUNET_YES;
- new_conn->path->c = c;
+ new_conn->destroy = GNUNET_YES; /* Do not mark_destroyed, */
+ new_conn->path->c = c; /* this is only a flag for the Iterator. */
LOG (GNUNET_ERROR_TYPE_DEBUG, " MATCH!\n");
}
}
if (CADET_CONNECTION_READY == c->state)
{
/* The other peer confirmed a live connection with this path,
- * why is it trying to duplicate it. */
+ * why are they trying to duplicate it? */
GNUNET_STATISTICS_update (stats, "# duplicate connections", 1, GNUNET_NO);
return GNUNET_YES;
}
* connection with the same path, and destroy one if so.
*
* @param cls Closure (connection to check).
- * @param tc Task context.
*/
static void
-check_duplicates (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+check_duplicates (void *cls)
{
struct CadetConnection *c = cls;
c->check_duplicates_task = NULL;
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- return;
-
if (GNUNET_YES == does_connection_exist (c))
{
GCT_debug (c->t, GNUNET_ERROR_TYPE_DEBUG);
}
-
/**
* Wait for enough time to let any dead connections time out and check for
* any remaining duplicates.
if (NULL != c->check_duplicates_task)
return;
-
delay = GNUNET_TIME_relative_multiply (refresh_connection_time, 5);
c->check_duplicates_task = GNUNET_SCHEDULER_add_delayed (delay,
&check_duplicates,
}
-
/**
* Add the connection to the list of both neighbors.
*
* @param disconnected Peer that disconnected.
*/
static void
-invalidate_paths (struct CadetConnection *c, struct CadetPeer *disconnected)
+invalidate_paths (struct CadetConnection *c,
+ struct CadetPeer *disconnected)
{
struct CadetPeer *peer;
unsigned int i;
t = c->t;
fwd = is_fwd (c, id);
- c->destroy = GNUNET_YES;
+ mark_destroyed (c);
if (GCC_is_terminal (c, fwd))
{
struct CadetPeer *endpoint;
path_invalidate (c->path);
GCP_notify_broken_link (endpoint, &msg->peer1, &msg->peer2);
- c->state = CADET_CONNECTION_BROKEN;
+ connection_change_state (c, CADET_CONNECTION_BROKEN);
GCT_remove_connection (t, c);
c->t = NULL;
GCC_check_connections ();
return GNUNET_OK;
}
- c->destroy = GNUNET_YES;
- c->state = CADET_CONNECTION_DESTROYED;
+ mark_destroyed (c);
if (NULL != c->t)
{
GCT_remove_connection (c->t, c);
/* Connection will have at least one pending message
* (the one we just scheduled), so delay destruction
* and remove from map so we don't use accidentally. */
- c->destroy = GNUNET_YES;
- c->state = CADET_CONNECTION_DESTROYED;
+ mark_destroyed (c);
GNUNET_assert (GNUNET_NO == c->was_removed);
c->was_removed = GNUNET_YES;
GNUNET_break (GNUNET_YES ==
GNUNET_assert (NULL == GCC_send_prebuilt_message (&msg.header, UINT16_MAX,
0, c, GNUNET_NO,
GNUNET_YES, NULL, NULL));
- c->destroy = GNUNET_YES;
- c->state = CADET_CONNECTION_DESTROYED;
+ mark_destroyed (c);
GCC_check_connections ();
}