* Time we give plugin to transmit DISCONNECT message before the
* neighbour entry self-destructs.
*/
-#define DISCONNECT_SENT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 100)
+#define DISCONNECT_SENT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500)
/**
* How often must a peer violate bandwidth quotas before we start
*/
GNUNET_SCHEDULER_TaskIdentifier task;
+ /**
+ * Task to disconnect neighbour after we received a DISCONNECT message
+ */
+ GNUNET_SCHEDULER_TaskIdentifier delayed_disconnect_task;
+
/**
* At what time should we sent the next keep-alive message?
*/
* Flag to set if we still need to send a CONNECT_ACK message to the other peer
* (once we have an address to use and the peer has been allowed by our
* blacklist). Initially set to #ACK_UNDEFINED. Set to #ACK_SEND_CONNECT_ACK
- * if we need to send a CONNECT_ACK. Set to #SESSION_ACK if we did
+ * if we need to send a CONNECT_ACK. Set to #ACK_SEND_SESSION_ACK if we did
* send a CONNECT_ACK and should go to 'S_CONNECTED' upon receiving a
* 'SESSION_ACK' (regardless of what our own state machine might say).
*/
/**
- * Context for blacklist checks and the #handle_test_blacklist_cont()
+ * Context for blacklist checks and the #try_connect_bl_check_cont()
* function. Stores information about ongoing blacklist checks.
*/
struct BlackListCheckContext
struct GNUNET_TIME_Absolute timeout)
{
n->timeout = timeout;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Neighbour `%s' changed timeout %s\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Neighbour `%s' changed timeout %s\n",
GNUNET_i2s (&n->id),
GNUNET_STRINGS_absolute_time_to_string (timeout));
neighbour_change_cb (callback_cls,
n->suggest_handle = NULL;
}
+ /* Cancel the disconnect task */
+ if (GNUNET_SCHEDULER_NO_TASK != n->delayed_disconnect_task)
+ {
+ GNUNET_SCHEDULER_cancel (n->delayed_disconnect_task);
+ n->delayed_disconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ }
+
/* Cancel the master task */
if (GNUNET_SCHEDULER_NO_TASK != n->task)
{
{
struct SessionDisconnectMessage disconnect_msg;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Sending DISCONNECT message to peer `%4s'\n",
GNUNET_i2s (&n->id));
disconnect_msg.header.size = htons (sizeof (struct SessionDisconnectMessage));
&disconnect_msg.purpose,
&disconnect_msg.signature));
- (void) send_with_session (n,
- (const char *) &disconnect_msg, sizeof (disconnect_msg),
- UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_NO, &send_disconnect_cont, NULL);
+ (void) send_with_session (n, (const char *) &disconnect_msg,
+ sizeof (disconnect_msg), UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_NO, &send_disconnect_cont, NULL );
GNUNET_STATISTICS_update (GST_stats,
gettext_noop
("# DISCONNECT messages sent"), 1,
break;
case GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS:
/* we never ACK'ed the other peer's request, no need to send DISCONNECT */
- set_state (n, GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED);
free_neighbour (n, GNUNET_NO);
return;
case GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK:
send_disconnect (n);
set_state (n, GNUNET_TRANSPORT_PS_DISCONNECT);
break;
+ case GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT:
case GNUNET_TRANSPORT_PS_CONNECTED:
case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
/* we are currently connected, need to send disconnect and do
set_state (n, GNUNET_TRANSPORT_PS_DISCONNECT);
break;
case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
- /* ATS address request timeout, disconnect without sending disconnect message */
- GNUNET_STATISTICS_set (GST_stats,
- gettext_noop ("# peers connected"),
- --neighbours_connected,
- GNUNET_NO);
- disconnect_notify_cb (callback_cls, &n->id);
- set_state (n, GNUNET_TRANSPORT_PS_DISCONNECT);
- break;
+ /* Disconnecting while waiting for an ATS address to reconnect,
+ * cannot send DISCONNECT */
+ free_neighbour (n, GNUNET_NO);
+ return;
case GNUNET_TRANSPORT_PS_DISCONNECT:
/* already disconnected, ignore */
break;
("# transmission failures for messages to other peers"),
1, GNUNET_NO);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending message to `%s' of type %u was a %s\n",
+ "Sending message to `%s' of type %u with %u bytes was a %s\n",
GNUNET_i2s (receiver),
ntohs (((struct GNUNET_MessageHeader *) mq->message_buf)->type),
+ mq->message_buf_size,
(success == GNUNET_OK) ? "success" : "FAILURE");
if (NULL != mq->cont)
mq->cont (mq->cont_cls, success, size_payload, physical);
return; /* no more messages */
GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq);
n->is_active = mq;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Giving message with %u bytes to plugin session %p\n",
+ mq->message_buf_size, n->primary_address.session);
+
(void) send_with_session (n,
mq->message_buf, mq->message_buf_size,
0 /* priority */, timeout, GNUNET_NO,
mq->message_buf = (const char *) &mq[1];
mq->message_buf_size = msg_size;
mq->timeout = GNUNET_TIME_relative_to_absolute (timeout);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Enqueueing %u bytes to send to peer %s\n",
+ msg_size, GNUNET_i2s (target));
+
GNUNET_CONTAINER_DLL_insert_tail (n->messages_head, n->messages_tail, mq);
- if ( (NULL != n->is_active) ||
- ( (NULL == n->primary_address.session) && (NULL == n->primary_address.address)) )
- return;
if (GNUNET_SCHEDULER_NO_TASK != n->task)
GNUNET_SCHEDULER_cancel (n->task);
n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
n->primary_address.session);
GNUNET_ATS_address_destroyed (GST_ats, n->primary_address.address, NULL );
unset_primary_address (n);
- set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS,
+ set_state_and_timeout (n, GNUNET_TRANSPORT_PS_INIT_ATS,
GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT));
break;
case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
n->primary_address.session);
GNUNET_ATS_address_destroyed (GST_ats, n->primary_address.address, NULL );
unset_primary_address (n);
- set_state_and_timeout (n, GNUNET_TRANSPORT_PS_INIT_ATS,
+ set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS,
GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
break;
case GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT:
/* Remove address and request and go back to primary address */
+ GNUNET_STATISTICS_update (GST_stats, gettext_noop
+ ("# Failed attempts to switch addresses (failed to send CONNECT CONT)"), 1, GNUNET_NO);
GNUNET_ATS_address_destroyed (GST_ats, n->alternative_address.address,
n->alternative_address.session);
GNUNET_ATS_address_destroyed (GST_ats, n->alternative_address.address,
GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
break;
default:
- GNUNET_break(0);
disconnect_neighbour (n);
break;
}
case GNUNET_TRANSPORT_PS_CONNECT_SENT:
/* Remove address and request and additional one */
unset_primary_address (n);
- set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS,
+ set_state_and_timeout (n, GNUNET_TRANSPORT_PS_INIT_ATS,
GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT));
/* Hard failure to send the CONNECT message with this address:
Destroy address and session */
case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
/* Remove address and request and additional one */
unset_primary_address (n);
- set_state_and_timeout (n, GNUNET_TRANSPORT_PS_INIT_ATS,
+ set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS,
GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
break;
case GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT:
+ GNUNET_STATISTICS_update (GST_stats, gettext_noop
+ ("# Failed attempts to switch addresses (failed to send CONNECT)"), 1, GNUNET_NO);
/* Remove address and request and additional one */
unset_alternative_address (n);
set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECTED,
GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
break;
default:
- GNUNET_break (0);
disconnect_neighbour (n);
break;
}
return GNUNET_OK;
}
-static
-int
+static int
free_notification_cb(void *cls, const struct GNUNET_PeerIdentity *key,
void *value)
{
/* struct NeighbourMapEntry *n = cls; */
struct QuotaNotificationRequest *qnr = value;
- GNUNET_CONTAINER_multipeermap_remove (registered_quota_notifications, key,
- qnr);
+ GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (registered_quota_notifications, key,
+ qnr));
GNUNET_free(qnr->plugin);
GNUNET_free(qnr);
n->ack_state = ACK_SEND_CONNECT_ACK;
n->connect_ack_timestamp = ts;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Received CONNECT for peer `%s' in state %s/%s\n",
GNUNET_i2s (peer),
GNUNET_TRANSPORT_ps2s (n->state),
struct GNUNET_TRANSPORT_PluginFunctions *papi;
struct NeighbourMapEntry *n;
+ papi = GST_plugins_find (blc_ctx->address->transport_name);
+
if ( (NULL == (n = lookup_neighbour (peer))) || (result == GNUNET_NO) ||
- (NULL == (papi = GST_plugins_find (blc_ctx->address->transport_name))) )
+ (NULL == (papi)) )
{
if (NULL == n)
{
blc_ctx->session,
GNUNET_i2s (&blc_ctx->address->peer));
}
- if (NULL == (papi = GST_plugins_find (blc_ctx->address->transport_name)))
+ if (NULL == papi)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Plugin `%s' for suggested address `%s' session %p for peer `%s' is not available\n",
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Blacklist accepted to switch to suggested address `%s' session %p for peer `%s'\n",
+ "Blacklist accepted address `%s' session %p for peer `%s'\n",
GST_plugins_a2s (blc_ctx->address),
blc_ctx->session,
GNUNET_i2s (&blc_ctx->address->peer));
blc_ctx->bandwidth_in, blc_ctx->bandwidth_out);
set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT,
GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
+ GNUNET_STATISTICS_update (GST_stats, gettext_noop
+ ("# Attempts to switch addresses"), 1, GNUNET_NO);
send_session_connect (&n->alternative_address);
break;
case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
send_session_connect (&n->primary_address);
break;
case GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT:
- if (n->primary_address.session == blc_ctx->session)
+ if ( (0 == GNUNET_HELLO_address_cmp(n->primary_address.address,
+ blc_ctx->address) && n->primary_address.session == blc_ctx->session) )
{
/* ATS switches back to still-active session */
free_address (&n->alternative_address);
{
struct NeighbourMapEntry *n;
struct GST_BlacklistCheck *blc;
- struct GNUNET_TRANSPORT_PluginFunctions *papi;
struct BlacklistCheckSwitchContext *blc_ctx;
int c;
}
/* Check if plugin is available */
- if (NULL == (papi = GST_plugins_find (address->transport_name)))
+ if (NULL == (GST_plugins_find (address->transport_name)))
{
/* we don't have the plugin for this address */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
}
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "ATS tells us to switch to %s address '%s' session %p for "
+ "ATS suggests %s address '%s' session %p for "
"peer `%s' in state %s/%s (quota in/out %u %u )\n",
GNUNET_HELLO_address_check_option (address,
GNUNET_HELLO_ADDRESS_INFO_INBOUND) ? "inbound" : "outbound",
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Connection to `%s' timed out, missing KEEPALIVE_RESPONSEs (after trying to CONNECT on alternative address)\n",
GNUNET_i2s (&n->id));
+ GNUNET_STATISTICS_update (GST_stats, gettext_noop
+ ("# Failed attempts to switch addresses (no response)"), 1, GNUNET_NO);
disconnect_neighbour (n);
return;
}
1, GNUNET_NO);
break;
case GNUNET_TRANSPORT_PS_CONNECTED:
- /* duplicate CONNECT_ACK, let's answer by duplciate SESSION_ACK just in case */
+ /* duplicate CONNECT_ACK, let's answer by duplicate SESSION_ACK just in case */
send_session_ack_message (n);
break;
case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
GNUNET_break (GNUNET_NO == n->alternative_address.ats_active);
+ /* Notify about session... perhaps we obtained it */
GST_ats_add_address (n->alternative_address.address,
- n->alternative_address.session,
- NULL, 0);
+ n->alternative_address.session, NULL, 0);
+ /* Set primary addresses */
set_primary_address (n, n->alternative_address.address,
n->alternative_address.session, n->alternative_address.bandwidth_in,
n->alternative_address.bandwidth_out, GNUNET_YES);
+ GNUNET_STATISTICS_update (GST_stats, gettext_noop
+ ("# Successful attempts to switch addresses"), 1, GNUNET_NO);
free_address (&n->alternative_address);
send_session_ack_message (n);
if ( (GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT == n->state) )
set_state (n, GNUNET_TRANSPORT_PS_CONNECTED);
else
- GNUNET_break (0);
- free_address (&n->alternative_address);
+ free_address (&n->alternative_address);
}
return GNUNET_NO; /* doesn't affect us further */
}
free_neighbour (n, GNUNET_NO);
return GNUNET_YES;
case GNUNET_TRANSPORT_PS_CONNECTED:
+ /* Our primary connection died, try a fast reconnect */
unset_primary_address (n);
set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS,
GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
/* primary went down while we were waiting for CONNECT_ACK on secondary;
secondary as primary */
- /* Destroy the address since it cannot be used */
- GNUNET_ATS_address_destroyed (GST_ats, n->primary_address.address, NULL);
+ /* Destroy the inbound address since it cannot be used */
+ if (GNUNET_YES
+ == GNUNET_HELLO_address_check_option (n->primary_address.address,
+ GNUNET_HELLO_ADDRESS_INFO_INBOUND))
+ GNUNET_ATS_address_destroyed (GST_ats, n->primary_address.address, NULL);
free_address (&n->primary_address);
n->primary_address = n->alternative_address;
memset (&n->alternative_address, 0, sizeof (struct NeighbourAddress));
- set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS, GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT));
+ set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS,
+ GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT));
break;
case GNUNET_TRANSPORT_PS_DISCONNECT:
free_address (&n->primary_address);
{
struct NeighbourMapEntry *n;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received SESSION_ACK message from peer `%s'\n",
GNUNET_i2s (peer));
if (ntohs (message->size) != sizeof (struct GNUNET_MessageHeader))
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
- /* check if we are in a plausible state for having sent
- a CONNECT_ACK. If not, return, otherwise break */
- /* TODO I have no idea we we should state GNUNET_TRANSPORT_PS_CONNECT_SENT
- * Perhaps SWITCHING? Have to check */
- if ( (GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK != n->state) /*&&
- (GNUNET_TRANSPORT_PS_RECONNECT_SENT != n->state) ) ||
- (ACK_SEND_SESSION_ACK != n->ack_state)*/)
- {
- GNUNET_break (0); /* TESTING */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Received %s for peer `%s' in state %s/%s\n",
+ "SESSION_ACK",
+ GNUNET_i2s (peer),
+ GNUNET_TRANSPORT_ps2s (n->state),
+ print_ack_state (n->ack_state));
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ /* Check if we are in a plausible state for having sent
+ a CONNECT_ACK. If not, return, otherwise break.
+
+ The remote peers sends a SESSION_ACK as a response for a CONNECT_ACK
+ message.
+
+ We expect a SESSION_ACK:
+ - If a remote peer has sent a CONNECT, we responded with a CONNECT_ACK and
+ now wait for the ACK to finally be connected
+ - If we sent a CONNECT_ACK to this peer before */
+
+ if ( (GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK != n->state) &&
+ (ACK_SEND_SESSION_ACK != n->ack_state))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Received unexpected SESSION_ACK message from peer `%s' in state %s/%s\n",
GNUNET_i2s (peer),
GNUNET_TRANSPORT_ps2s (n->state),
print_ack_state (n->ack_state));
+
GNUNET_STATISTICS_update (GST_stats,
gettext_noop ("# unexpected SESSION_ACK messages"), 1,
GNUNET_NO);
}
/* We are connected */
- set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECTED, GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
- GNUNET_STATISTICS_set (GST_stats,
- gettext_noop ("# peers connected"),
- ++neighbours_connected,
- GNUNET_NO);
-
- /* Notify about connection */
- connect_notify_cb (callback_cls, &n->id,
+ if (GNUNET_NO == GST_neighbours_test_connected(&n->id))
+ {
+ /* Notify about connection */
+ connect_notify_cb (callback_cls, &n->id,
n->primary_address.bandwidth_in,
- n->primary_address.bandwidth_out);
+ n->primary_address.bandwidth_out);\
+
+ GNUNET_STATISTICS_set (GST_stats,
+ gettext_noop ("# peers connected"),
+ ++neighbours_connected,
+ GNUNET_NO);
+ }
+
+ if (GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT == n->state)
+ {
+ /* We tried to switch addresses while being connect. We explicitly wait
+ * for a CONNECT_ACK before going to GNUNET_TRANSPORT_PS_CONNECTED,
+ * so we do not want to set the address as in use! */
+ return GNUNET_OK;
+ }
+
+ set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECTED,
+ GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
/* Add session to ATS since no session was given (NULL) and we may have
* obtained a new session */
disconnect_neighbour (n);
}
+void delayed_disconnect (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext* tc)
+{
+ struct NeighbourMapEntry *n = cls;
+
+ n->delayed_disconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Disconnecting by request from peer %s\n",
+ GNUNET_i2s (&n->id));
+ free_neighbour (n, GNUNET_NO);
+}
+
/**
* We received a disconnect message from the given peer,
GNUNET_i2s (peer));
if (ntohs (msg->size) != sizeof (struct SessionDisconnectMessage))
{
- // GNUNET_break_op (0);
+ GNUNET_break_op (0);
GNUNET_STATISTICS_update (GST_stats,
gettext_noop
- ("# disconnect messages ignored (old format)"), 1,
+ ("# disconnect messages ignored (malformed)"), 1,
GNUNET_NO);
return;
}
GNUNET_break_op (0);
return;
}
- if (GNUNET_YES == test_connected (n))
- GNUNET_STATISTICS_update (GST_stats,
- gettext_noop
- ("# other peer asked to disconnect from us"), 1,
- GNUNET_NO);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting by request from peer %s\n",
- GNUNET_i2s (peer));
- disconnect_neighbour (n);
+ n->delayed_disconnect_task = GNUNET_SCHEDULER_add_now (&delayed_disconnect, n);
}
util_transmission_tk = GNUNET_SCHEDULER_NO_TASK;
}
- GNUNET_CONTAINER_multipeermap_iterate (neighbours,
- &disconnect_all_neighbours,
- NULL);
+ GNUNET_CONTAINER_multipeermap_iterate (neighbours, &disconnect_all_neighbours,
+ NULL );
GNUNET_CONTAINER_multipeermap_destroy (neighbours);
next = pending_bc_head;