- /* Blacklist disagreed on connecting to a peer with this address
- * Destroy address because we are not allowed to use it
- */
- if (NULL != bcc->na.session)
- GNUNET_ATS_address_destroyed (GST_ats, bcc->na.address, bcc->na.session);
- GNUNET_ATS_address_destroyed (GST_ats, bcc->na.address, NULL);
- }
- if (NULL == (n = lookup_neighbour (peer)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "No neighbor entry for peer `%s', ignoring blacklist result\n",
- GNUNET_i2s (peer));
- goto cleanup; /* nobody left to care about new address */
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received blacklist result for peer `%s' in state %s/%d\n",
- GNUNET_i2s (peer),
- GNUNET_TRANSPORT_ps2s (n->state),
- n->send_connect_ack);
- switch (n->state)
- {
- case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
- /* this should not be possible */
- GNUNET_break (0);
- free_neighbour (n, GNUNET_NO);
- break;
- case GNUNET_TRANSPORT_PS_INIT_ATS:
- /* waiting on ATS suggestion; still, pass address to ATS as a
- possibility */
- break;
- case GNUNET_TRANSPORT_PS_INIT_BLACKLIST:
- /* check if the address the blacklist was fine with matches
- ATS suggestion, if so, we can move on! */
- if ( (GNUNET_OK == result) &&
- (1 == n->send_connect_ack) )
- {
- n->send_connect_ack = 2;
- send_session_connect_ack_message (bcc->na.address,
- bcc->na.session,
- n->connect_ack_timestamp);
- }
- if (GNUNET_YES != address_matches (&bcc->na, &n->primary_address))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Blacklist result for peer %s is for non-primary address, ignored\n",
- GNUNET_i2s (peer));
- break; /* result for an address we currently don't care about */
- }
- if (GNUNET_OK == result)
- {
- set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECT_SENT,
- GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
- send_session_connect (&n->primary_address);
- }
- else
- {
- free_address (&n->primary_address);
- GNUNET_break (0);
- set_state_and_timeout (n, GNUNET_TRANSPORT_PS_INIT_ATS,
- GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
- }
- break;
- case GNUNET_TRANSPORT_PS_CONNECT_SENT:
- /* waiting on CONNECT_ACK, send ACK if one is pending */
- if ( (GNUNET_OK == result) &&
- (1 == n->send_connect_ack) )
- {
- n->send_connect_ack = 2;
- send_session_connect_ack_message (n->primary_address.address,
- n->primary_address.session,
- n->connect_ack_timestamp);
- }
- break;
- case GNUNET_TRANSPORT_PS_CONNECT_RECV_BLACKLIST_INBOUND:
- set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS,
- GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
- GNUNET_ATS_reset_backoff (GST_ats, peer);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Suggesting address for peer %s to ATS\n",
- GNUNET_i2s (peer));
- n->suggest_handle = GNUNET_ATS_suggest_address (GST_ats, peer,
- &address_suggest_cont, n);
- break;
- case GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS:
- /* waiting on ATS suggestion, don't care about blacklist */
- break;
- case GNUNET_TRANSPORT_PS_CONNECT_RECV_BLACKLIST:
- if (GNUNET_YES != address_matches (&bcc->na, &n->primary_address))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Blacklist result ignored, as it is not for our primary address\n");
- break; /* result for an address we currently don't care about */
- }
- if (GNUNET_OK == result)
- {
- set_state_and_timeout (n, GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK,
- GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
- send_session_connect_ack_message (bcc->na.address,
- bcc->na.session,
- n->connect_ack_timestamp);
- if (1 == n->send_connect_ack)
- n->send_connect_ack = 2;
- }
- else
- {
- struct GNUNET_TRANSPORT_PluginFunctions *plugin;
-
- plugin = GST_plugins_find (bcc->na.address->transport_name);
- if ( (NULL != plugin) &&
- (NULL != bcc->na.session) )
- {
- plugin->disconnect_session (plugin->cls,
- bcc->na.session);
- break;
- }
- GNUNET_break (NULL != plugin);
- free_address (&n->primary_address);
- set_state_and_timeout (n, GNUNET_TRANSPORT_PS_INIT_ATS,
- GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
- GNUNET_ATS_reset_backoff (GST_ats, peer);
- }
- break;
- case GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK:
- /* waiting on SESSION_ACK, send ACK if one is pending */
- if ( (GNUNET_OK == result) &&
- (1 == n->send_connect_ack) )
- {
- n->send_connect_ack = 2;
- send_session_connect_ack_message (n->primary_address.address,
- n->primary_address.session,
- n->connect_ack_timestamp);
- }
- break;
- case GNUNET_TRANSPORT_PS_CONNECTED:
- /* already connected, don't care about blacklist */
- break;
- case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
- /* still waiting on ATS suggestion, don't care about blacklist */
- break;
- case GNUNET_TRANSPORT_PS_RECONNECT_BLACKLIST:
- if ( (GNUNET_OK == result) &&
- (1 == n->send_connect_ack) )
- {
- n->send_connect_ack = 2;
- send_session_connect_ack_message (bcc->na.address,
- bcc->na.session,
- n->connect_ack_timestamp);
- }
- if (GNUNET_YES != address_matches (&bcc->na, &n->primary_address))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Blacklist result ignored, as it is not for our primary address\n");
- break; /* result for an address we currently don't care about */
- }
- if (GNUNET_OK == result)
- {
- set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_SENT, GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT));
- send_session_connect (&n->primary_address);
- }
- else
- {
- set_state_and_timeout (n, GNUNET_TRANSPORT_PS_RECONNECT_ATS, GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
- }
- break;
- case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
- /* waiting on CONNECT_ACK, don't care about blacklist */
- if ( (GNUNET_OK == result) &&
- (1 == n->send_connect_ack) )
- {
- n->send_connect_ack = 2;
- send_session_connect_ack_message (n->primary_address.address,
- n->primary_address.session,
- n->connect_ack_timestamp);
- }
- break;
- case GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_BLACKLIST:
- if (GNUNET_YES != address_matches (&bcc->na, &n->alternative_address))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Blacklist result ignored, as it is not for our primary address\n");
- break; /* result for an address we currently don't care about */
- }
- if (GNUNET_OK == result)
- {
- send_session_connect (&n->alternative_address);
- set_state (n, GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT);
- }
- else
- {
- set_state(n, GNUNET_TRANSPORT_PS_CONNECTED);
- free_address (&n->alternative_address);
- }
- break;
- case GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT:
- /* waiting on CONNECT_ACK, don't care about blacklist */
- if ( (GNUNET_OK == result) &&
- (1 == n->send_connect_ack) )
- {
- n->send_connect_ack = 2;
- send_session_connect_ack_message (n->primary_address.address,
- n->primary_address.session,
- n->connect_ack_timestamp);
- }
- break;
- case GNUNET_TRANSPORT_PS_DISCONNECT:
- /* Nothing to do here, ATS will already do what can be done */
- break;
- case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
- /* should not be possible */
- GNUNET_assert (0);
- break;
- default:
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Unhandled state `%s'\n",
- GNUNET_TRANSPORT_ps2s (n->state));
- GNUNET_break (0);
- free_neighbour (n, GNUNET_NO);
- break;
- }
- cleanup:
- GNUNET_HELLO_address_free (bcc->na.address);
- GNUNET_free (bcc);
-}
-
-
-/**
- * We want to know if connecting to a particular peer via
- * a particular address is allowed. Check it!
- *
- * @param peer identity of the peer to switch the address for
- * @param ts time at which the check was initiated
- * @param address address of the other peer, NULL if other peer
- * connected to us
- * @param session session to use (or NULL)
- */
-static void
-check_blacklist (const struct GNUNET_PeerIdentity *peer,
- struct GNUNET_TIME_Absolute ts,
- const struct GNUNET_HELLO_Address *address,
- struct Session *session)
-{
- struct BlackListCheckContext *bcc;
- struct GST_BlacklistCheck *bc;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Checking peer `%s' against blacklist\n",
- GNUNET_i2s (peer));
- bcc = GNUNET_new (struct BlackListCheckContext);
- bcc->na.address = GNUNET_HELLO_address_copy (address);
- bcc->na.session = session;
- bcc->na.connect_timestamp = ts;
- GNUNET_CONTAINER_DLL_insert (bc_head,
- bc_tail,
- bcc);
- if (NULL != (bc = GST_blacklist_test_allowed (peer,
- address->transport_name,
- &handle_test_blacklist_cont, bcc)))
- bcc->bc = bc;
- /* if NULL == bc, 'cont' was already called and 'bcc' already free'd, so
- we must only store 'bc' if 'bc' is non-NULL... */
-}
-
-
-/**
- * We received a 'SESSION_CONNECT' message from the other peer.
- * Consider switching to it.
- *
- * @param message possibly a 'struct SessionConnectMessage' (check format)
- * @param peer identity of the peer to switch the address for
- * @param address address of the other peer, NULL if other peer
- * connected to us
- * @param session session to use (or NULL)
- * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
- */
-int
-GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Address *address,
- struct Session *session)
-{
- const struct SessionConnectMessage *scm;
- struct NeighbourMapEntry *n;
- struct GNUNET_TIME_Absolute ts;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received CONNECT message from peer `%s'\n",
- GNUNET_i2s (peer));
- if (ntohs (message->size) != sizeof (struct SessionConnectMessage))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;