summaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-12-12 16:17:10 +0000
committerChristian Grothoff <christian@grothoff.org>2013-12-12 16:17:10 +0000
commitb10f26ae8caab6299b94f00a319a6424be57a386 (patch)
tree5764c07a2a61a8e2fb8f0a94c885942b5fb028a5 /src/transport
parent54811540b75f59ca8dd54f96d6fe9f8f3743011d (diff)
-be stricter during handshake, close sessions with broken interactions aggressively
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-transport.c78
-rw-r--r--src/transport/gnunet-service-transport.h4
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c112
-rw-r--r--src/transport/gnunet-service-transport_neighbours.h66
-rw-r--r--src/transport/gnunet-service-transport_plugins.h1
-rw-r--r--src/transport/gnunet-service-transport_validation.c121
-rw-r--r--src/transport/gnunet-service-transport_validation.h9
-rw-r--r--src/transport/plugin_transport_tcp.c38
-rw-r--r--src/transport/test_transport_defaults.conf4
-rw-r--r--src/transport/transport.conf.in2
10 files changed, 273 insertions, 162 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index d96a284c7..6b62c17fe 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -124,7 +124,6 @@ process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello)
}
-
/**
* We received some payload. Prepare to pass it on to our clients.
*
@@ -178,14 +177,36 @@ process_payload (const struct GNUNET_PeerIdentity *peer,
/**
+ * Force plugin to terminate session due to communication
+ * issue.
+ *
+ * @param plugin_name name of the plugin
+ * @param session session to termiante
+ */
+static void
+kill_session (const char *plugin_name,
+ struct Session *session)
+{
+ struct GNUNET_TRANSPORT_PluginFunctions *plugin;
+
+ plugin = GST_plugins_find (plugin_name);
+ if (NULL == plugin)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ plugin->disconnect_session (plugin->cls,
+ session);
+}
+
+
+/**
* Function called by the transport for each received message.
- * This function should also be called with "NULL" for the
- * message to signal that the other peer disconnected.
*
* @param cls closure, const char* with the name of the plugin we received the message from
* @param peer (claimed) identity of the other peer
* @param message the message, NULL if we only care about
- * learning about the delay until we should receive again -- FIXME!
+ * learning about the delay until we should receive again
* @param session identifier used for this session (NULL for plugins
* that do not offer bi-directional communication to the sender
* using the same "connection")
@@ -236,30 +257,57 @@ GST_receive_callback (void *cls,
/* Legacy HELLO message, discard */
return ret;
case GNUNET_MESSAGE_TYPE_HELLO:
- GST_validation_handle_hello (message);
+ if (GNUNET_OK !=
+ GST_validation_handle_hello (message))
+ {
+ GNUNET_break_op (0);
+ kill_session (plugin_name, session);
+ }
return ret;
case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
"Processing `%s' from `%s'\n", "PING",
(sender_address !=
NULL) ? GST_plugins_a2s (&address) : TRANSPORT_SESSION_INBOUND_STRING);
- GST_validation_handle_ping (peer, message, &address, session);
+ if (GNUNET_OK !=
+ GST_validation_handle_ping (peer, message, &address, session))
+ kill_session (plugin_name, session);
break;
case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
"Processing `%s' from `%s'\n", "PONG",
(sender_address !=
NULL) ? GST_plugins_a2s (&address) : TRANSPORT_SESSION_INBOUND_STRING);
- GST_validation_handle_pong (peer, message);
+ if (GNUNET_OK !=
+ GST_validation_handle_pong (peer, message))
+ {
+ GNUNET_break_op (0);
+ kill_session (plugin_name, session);
+ }
break;
case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT:
- GST_neighbours_handle_connect (message, peer, &address, session);
+ if (GNUNET_OK !=
+ GST_neighbours_handle_connect (message, peer, &address, session))
+ {
+ GNUNET_break_op (0);
+ kill_session (plugin_name, session);
+ }
break;
case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK:
- GST_neighbours_handle_connect_ack (message, peer, &address, session);
+ if (GNUNET_OK !=
+ GST_neighbours_handle_connect_ack (message, peer, &address, session))
+ {
+ GNUNET_break_op (0);
+ kill_session (plugin_name, session);
+ }
break;
case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK:
- GST_neighbours_handle_session_ack (message, peer, &address, session);
+ if (GNUNET_OK !=
+ GST_neighbours_handle_session_ack (message, peer, &address, session))
+ {
+ GNUNET_break_op (0);
+ kill_session (plugin_name, session);
+ }
break;
case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT:
GST_neighbours_handle_disconnect_message (peer, message);
@@ -370,6 +418,7 @@ plugin_env_address_to_type (void *cls,
size_t addrlen)
{
struct GNUNET_ATS_Information ats;
+
ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
ats.value = htonl (GNUNET_ATS_NET_UNSPECIFIED);
if (GST_ats == NULL)
@@ -381,9 +430,10 @@ plugin_env_address_to_type (void *cls,
((addr->sa_family != AF_INET6) && (addrlen != sizeof (struct sockaddr_in6))) &&
(addr->sa_family != AF_UNIX))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed address with length %u `%s'\n",
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Malformed address with length %u `%s'\n",
addrlen,
- GNUNET_a2s(addr, addrlen));
+ GNUNET_a2s (addr, addrlen));
GNUNET_break (0);
return ats;
}
@@ -621,8 +671,8 @@ ats_request_address_change (void *cls,
return;
}
GST_neighbours_switch_to_address (&address->peer, address, session, ats,
- ats_count, bandwidth_in,
- bandwidth_out);
+ ats_count, bandwidth_in,
+ bandwidth_out);
}
diff --git a/src/transport/gnunet-service-transport.h b/src/transport/gnunet-service-transport.h
index 66da0163e..01a821a4e 100644
--- a/src/transport/gnunet-service-transport.h
+++ b/src/transport/gnunet-service-transport.h
@@ -101,7 +101,7 @@ GST_receive_callback (void *cls,
*/
void
GST_ats_add_address (const struct GNUNET_HELLO_Address *address,
- struct Session *session);
+ struct Session *session);
/**
@@ -111,7 +111,7 @@ GST_ats_add_address (const struct GNUNET_HELLO_Address *address,
* @param address the address
* @param session the session
* @param ats performance information
- * @param ats_count number of elements in ats
+ * @param ats_count number of elements in @a ats
*/
void
GST_ats_update_metrics (const struct GNUNET_PeerIdentity *peer,
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index a3b5639a0..fe3cadc56 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -774,7 +774,7 @@ send_outbound_quota (const struct GNUNET_PeerIdentity *target,
* Release its resources and give appropriate notifications
* to ATS and other subsystems.
*
- * @param na address we are done with; 'na' itself must NOT be 'free'd, only the contents!
+ * @param na address we are done with; @a na itself must NOT be 'free'd, only the contents!
*/
static void
free_address (struct NeighbourAddress *na)
@@ -1817,10 +1817,15 @@ handle_test_blacklist_cont (void *cls,
struct NeighbourMapEntry *n;
bcc->bc = NULL;
+ GNUNET_CONTAINER_DLL_remove (bc_head,
+ bc_tail,
+ bcc);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Connection to new address of peer `%s' based on blacklist is `%s'\n",
GNUNET_i2s (peer),
(GNUNET_OK == result) ? "allowed" : "FORBIDDEN");
+ if (GNUNET_OK == result)
+ GST_ats_add_address (bcc->na.address, bcc->na.session);
if (NULL == (n = lookup_neighbour (peer)))
goto cleanup; /* nobody left to care about new address */
switch (n->state)
@@ -1831,7 +1836,8 @@ handle_test_blacklist_cont (void *cls,
free_neighbour (n, GNUNET_NO);
break;
case S_INIT_ATS:
- /* still waiting on ATS suggestion */
+ /* waiting on ATS suggestion; still, pass address to ATS as a
+ possibility */
break;
case S_INIT_BLACKLIST:
/* check if the address the blacklist was fine with matches
@@ -1877,20 +1883,21 @@ handle_test_blacklist_cont (void *cls,
}
break;
case S_CONNECT_RECV_BLACKLIST_INBOUND:
- if (GNUNET_OK == result)
- GST_ats_add_address (bcc->na.address, bcc->na.session);
-
n->state = S_CONNECT_RECV_ATS;
n->timeout = GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT);
GNUNET_ATS_reset_backoff (GST_ats, peer);
n->suggest_handle = GNUNET_ATS_suggest_address (GST_ats, peer);
break;
case S_CONNECT_RECV_ATS:
- /* still waiting on ATS suggestion, don't care about blacklist */
+ /* waiting on ATS suggestion, don't care about blacklist */
break;
case S_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)
{
n->timeout = GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT);
@@ -1903,10 +1910,20 @@ handle_test_blacklist_cont (void *cls,
}
else
{
- // FIXME: should also possibly destroy session with plugin!?
+ 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);
GNUNET_ATS_address_destroyed (GST_ats,
- bcc->na.address,
- NULL);
+ bcc->na.address,
+ NULL);
free_address (&n->primary_address);
n->state = S_INIT_ATS;
n->timeout = GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT);
@@ -2016,9 +2033,6 @@ handle_test_blacklist_cont (void *cls,
}
cleanup:
GNUNET_HELLO_address_free (bcc->na.address);
- GNUNET_CONTAINER_DLL_remove (bc_head,
- bc_tail,
- bcc);
GNUNET_free (bcc);
}
@@ -2042,7 +2056,7 @@ check_blacklist (const struct GNUNET_PeerIdentity *peer,
struct BlackListCheckContext *bcc;
struct GST_BlacklistCheck *bc;
- bcc = GNUNET_malloc (sizeof (struct BlackListCheckContext));
+ bcc = GNUNET_new (struct BlackListCheckContext);
bcc->na.address = GNUNET_HELLO_address_copy (address);
bcc->na.session = session;
bcc->na.connect_timestamp = ts;
@@ -2067,8 +2081,9 @@ check_blacklist (const struct GNUNET_PeerIdentity *peer,
* @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
*/
-void
+int
GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_HELLO_Address *address,
@@ -2084,14 +2099,19 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
if (ntohs (message->size) != sizeof (struct SessionConnectMessage))
{
GNUNET_break_op (0);
- return;
+ return GNUNET_SYSERR;
}
GNUNET_STATISTICS_update (GST_stats,
gettext_noop
("# CONNECT messages received"),
1, GNUNET_NO);
if (NULL == neighbours)
- return; /* we're shutting down */
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ _("CONNECT request from peer `%s' ignored due impending shutdown\n"),
+ GNUNET_i2s (peer));
+ return GNUNET_OK; /* we're shutting down */
+ }
scm = (const struct SessionConnectMessage *) message;
GNUNET_break_op (0 == ntohl (scm->reserved));
ts = GNUNET_TIME_absolute_ntoh (scm->timestamp);
@@ -2169,9 +2189,9 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
"Unhandled state `%s'\n",
print_state (n->state));
GNUNET_break (0);
- free_neighbour (n, GNUNET_NO);
- break;
+ return GNUNET_SYSERR;
}
+ return GNUNET_OK;
}
@@ -2485,33 +2505,32 @@ utilization_transmission (void *cls,
}
+
void
GST_neighbours_notify_data_recv (const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Address *address,
- struct Session *session,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_HELLO_Address *address,
+ struct Session *session,
+ const struct GNUNET_MessageHeader *message)
{
struct NeighbourMapEntry *n;
+
n = lookup_neighbour (peer);
if (NULL == n)
- {
- return;
- }
+ return;
n->util_total_bytes_recv += ntohs(message->size);
}
+
void
GST_neighbours_notify_payload_recv (const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Address *address,
- struct Session *session,
- const struct GNUNET_MessageHeader *message)
+ const struct GNUNET_HELLO_Address *address,
+ struct Session *session,
+ const struct GNUNET_MessageHeader *message)
{
struct NeighbourMapEntry *n;
n = lookup_neighbour (peer);
if (NULL == n)
- {
- return;
- }
+ return;
n->util_payload_bytes_recv += ntohs(message->size);
}
@@ -2779,8 +2798,9 @@ send_session_ack_message (struct NeighbourMapEntry *n)
* @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
*/
-void
+int
GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_HELLO_Address *address,
@@ -2797,7 +2817,7 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
if (ntohs (message->size) != sizeof (struct SessionConnectMessage))
{
GNUNET_break_op (0);
- return;
+ return GNUNET_SYSERR;
}
GNUNET_STATISTICS_update (GST_stats,
gettext_noop
@@ -2811,7 +2831,7 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
gettext_noop
("# unexpected CONNECT_ACK messages (no peer)"),
1, GNUNET_NO);
- return;
+ return GNUNET_SYSERR;
}
ts = GNUNET_TIME_absolute_ntoh (scm->timestamp);
switch (n->state)
@@ -2819,7 +2839,7 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
case S_NOT_CONNECTED:
GNUNET_break (0);
free_neighbour (n, GNUNET_NO);
- return;
+ return GNUNET_SYSERR;
case S_INIT_ATS:
case S_INIT_BLACKLIST:
GNUNET_STATISTICS_update (GST_stats,
@@ -2829,7 +2849,11 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
break;
case S_CONNECT_SENT:
if (ts.abs_value_us != n->primary_address.connect_timestamp.abs_value_us)
- break; /* ACK does not match our original CONNECT message */
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "CONNECT_ACK ignored as the timestamp does not match our CONNECT request\n");
+ return GNUNET_OK;
+ }
n->state = S_CONNECTED;
n->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
GNUNET_STATISTICS_set (GST_stats,
@@ -2901,7 +2925,7 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
gettext_noop
("# unexpected CONNECT_ACK messages (disconnecting)"),
1, GNUNET_NO);
- break;
+ return GNUNET_SYSERR;
case S_DISCONNECT_FINISHED:
GNUNET_assert (0);
break;
@@ -2910,8 +2934,9 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
"Unhandled state `%s'\n",
print_state (n->state));
GNUNET_break (0);
- break;
+ return GNUNET_SYSERR;
}
+ return GNUNET_OK;
}
@@ -2939,7 +2964,8 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
bcc_next = bcc->next;
if (bcc->na.session == session)
{
- GST_blacklist_test_cancel (bcc->bc);
+ if (NULL != bcc->bc)
+ GST_blacklist_test_cancel (bcc->bc);
GNUNET_HELLO_address_free (bcc->na.address);
GNUNET_CONTAINER_DLL_remove (bc_head,
bc_tail,
@@ -3057,8 +3083,9 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
* @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
*/
-void
+int
GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_HELLO_Address *address,
@@ -3072,14 +3099,14 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
if (ntohs (message->size) != sizeof (struct GNUNET_MessageHeader))
{
GNUNET_break_op (0);
- return;
+ return GNUNET_SYSERR;
}
GNUNET_STATISTICS_update (GST_stats,
gettext_noop
("# SESSION_ACK messages received"),
1, GNUNET_NO);
if (NULL == (n = lookup_neighbour (peer)))
- return;
+ return GNUNET_SYSERR;
/* check if we are in a plausible state for having sent
a CONNECT_ACK. If not, return, otherwise break */
if ( ( (S_CONNECT_RECV_ACK != n->state) &&
@@ -3094,7 +3121,7 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
GNUNET_STATISTICS_update (GST_stats,
gettext_noop ("# unexpected SESSION_ACK messages"), 1,
GNUNET_NO);
- return;
+ return GNUNET_SYSERR;
}
n->state = S_CONNECTED;
n->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
@@ -3113,6 +3140,7 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
n->primary_address.bandwidth_in,
n->primary_address.bandwidth_out,
GNUNET_YES);
+ return GNUNET_OK;
}
diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h
index 9ba1918c3..f58a74faf 100644
--- a/src/transport/gnunet-service-transport_neighbours.h
+++ b/src/transport/gnunet-service-transport_neighbours.h
@@ -48,7 +48,7 @@
*/
void
GST_neighbours_start (void *cls,
- NotifyConnect connect_cb,
+ NotifyConnect connect_cb,
GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb,
GNUNET_TRANSPORT_PeerIterateCallback peer_address_cb,
unsigned int max_fds);
@@ -74,7 +74,7 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target);
* Test if we're connected to the given peer.
*
* @param target peer to test
- * @return GNUNET_YES if we are connected, GNUNET_NO if not
+ * @return #GNUNET_YES if we are connected, #GNUNET_NO if not
*/
int
GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target);
@@ -84,7 +84,7 @@ GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target);
* Function called after the transmission is done.
*
* @param cls closure
- * @param success GNUNET_OK on success, GNUNET_NO on failure, GNUNET_SYSERR if we're not connected
+ * @param success #GNUNET_OK on success, #GNUNET_NO on failure, #GNUNET_SYSERR if we're not connected
*/
typedef void (*GST_NeighbourSendContinuation) (void *cls, int success,
size_t bytes_payload,
@@ -96,10 +96,10 @@ typedef void (*GST_NeighbourSendContinuation) (void *cls, int success,
*
* @param target destination
* @param msg message to send
- * @param msg_size number of bytes in msg
+ * @param msg_size number of bytes in @a msg
* @param timeout when to fail with timeout
* @param cont function to call when done
- * @param cont_cls closure for 'cont'
+ * @param cont_cls closure for @a cont
*/
void
GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
@@ -114,8 +114,8 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
*
* @param sender sender of the message
* @param size size of the message
- * @param do_forward set to GNUNET_YES if the message should be forwarded to clients
- * GNUNET_NO if the neighbour is not connected or violates the quota
+ * @param do_forward set to #GNUNET_YES if the message should be forwarded to clients
+ * #GNUNET_NO if the neighbour is not connected or violates the quota
* @return how long to wait before reading more from this sender
*/
struct GNUNET_TIME_Relative
@@ -185,7 +185,7 @@ typedef void (*GST_NeighbourIterator) (void *cls,
* Iterate over all connected neighbours.
*
* @param cb function to call
- * @param cb_cls closure for cb
+ * @param cb_cls closure for @a cb
*/
void
GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls);
@@ -196,7 +196,7 @@ GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls);
*
* @param peer identity of the peer where the session died
* @param session session that is gone
- * @return GNUNET_YES if this was a session used, GNUNET_NO if
+ * @return #GNUNET_YES if this was a session used, #GNUNET_NO if
* this session was not in use
*/
int
@@ -206,25 +206,29 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
void
GST_neighbours_notify_data_recv (const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Address *address,
- struct Session *session,
- const struct GNUNET_MessageHeader *message);
+ const struct GNUNET_HELLO_Address *address,
+ struct Session *session,
+ const struct GNUNET_MessageHeader *message);
+
void
GST_neighbours_notify_payload_recv (const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Address *address,
- struct Session *session,
- const struct GNUNET_MessageHeader *message);
+ const struct GNUNET_HELLO_Address *address,
+ struct Session *session,
+ const struct GNUNET_MessageHeader *message);
+
void
GST_neighbours_notify_payload_sent (const struct GNUNET_PeerIdentity *peer,
- size_t size);
+ size_t size);
+
void
GST_neighbours_notify_data_sent (const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Address *address,
- struct Session *session,
- size_t size);
+ const struct GNUNET_HELLO_Address *address,
+ struct Session *session,
+ size_t size);
+
/**
* For an existing neighbour record, set the active connection to
@@ -241,12 +245,12 @@ GST_neighbours_notify_data_sent (const struct GNUNET_PeerIdentity *peer,
*/
void
GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Address
- *address, struct Session *session,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
+ const struct GNUNET_HELLO_Address *address,
+ struct Session *session,
+ const struct GNUNET_ATS_Information *ats,
+ uint32_t ats_count,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
/**
@@ -258,8 +262,9 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
* @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
*/
-void
+int
GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_HELLO_Address *address,
@@ -275,8 +280,9 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
* @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
*/
-void
+int
GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_HELLO_Address *address,
@@ -285,15 +291,17 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
/**
* We received a 'SESSION_ACK' message from the other peer.
- * FIXME: describe what this means!
+ * If we sent a 'CONNECT_ACK' last, this means we are now
+ * connected. Otherwise, do nothing.
*
* @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
*/
-void
+int
GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_HELLO_Address *address,
diff --git a/src/transport/gnunet-service-transport_plugins.h b/src/transport/gnunet-service-transport_plugins.h
index 2dc91de73..9d8d503f8 100644
--- a/src/transport/gnunet-service-transport_plugins.h
+++ b/src/transport/gnunet-service-transport_plugins.h
@@ -70,6 +70,7 @@ GST_plugins_unload (void);
struct GNUNET_TRANSPORT_PluginFunctions *
GST_plugins_find (const char *name);
+
/**
* Obtain the plugin API based on a the stripped plugin name after the underscore.
*
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index afe7ac467..c0e605114 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -931,8 +931,9 @@ multicast_pong (void *cls,
* @param hdr the PING
* @param sender_address the sender address as we got it
* @param session session we got the PING from
+ * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
*/
-void
+int
GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
const struct GNUNET_MessageHeader *hdr,
const struct GNUNET_HELLO_Address *sender_address,
@@ -956,7 +957,7 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
if (ntohs (hdr->size) < sizeof (struct TransportPingMessage))
{
GNUNET_break_op (0);
- return;
+ return GNUNET_SYSERR;
}
ping = (const struct TransportPingMessage *) hdr;
if (0 !=
@@ -967,7 +968,7 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
gettext_noop
("# PING message for different peer received"), 1,
GNUNET_NO);
- return;
+ return GNUNET_SYSERR;
}
GNUNET_STATISTICS_update (GST_stats,
gettext_noop ("# PING messages received"), 1,
@@ -986,7 +987,7 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
if (NULL == addrend)
{
GNUNET_break_op (0);
- return;
+ return GNUNET_SYSERR;
}
addrend++;
slen = strlen (addr) + 1;
@@ -998,38 +999,40 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
if (NULL == address.transport_name)
{
- GNUNET_break (0);
+ GNUNET_break (0);
}
if (0 != strstr (address.transport_name, "_client"))
- {
- plugin_name = GNUNET_strdup (address.transport_name);
- pos = strstr (plugin_name, "_client");
- GNUNET_assert (NULL != pos);
- GNUNET_snprintf (pos, strlen ("_server") + 1, "%s", "_server");
- }
+ {
+ plugin_name = GNUNET_strdup (address.transport_name);
+ pos = strstr (plugin_name, "_client");
+ GNUNET_assert (NULL != pos);
+ GNUNET_snprintf (pos, strlen ("_server") + 1, "%s", "_server");
+ }
else
- plugin_name = GNUNET_strdup (address.transport_name);
+ plugin_name = GNUNET_strdup (address.transport_name);
if (NULL == (papi = GST_plugins_find (plugin_name)))
{
/* we don't have the plugin for this address */
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Plugin `%s' not available, cannot confirm having this address \n",
- plugin_name);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Plugin `%s' not available, cannot confirm having this address\n"),
+ plugin_name);
GNUNET_free (plugin_name);
- return;
+ return GNUNET_SYSERR;
}
GNUNET_free (plugin_name);
if (GNUNET_OK != papi->check_address (papi->cls, addrend, alen))
- {
+ {
GNUNET_STATISTICS_update (GST_stats,
gettext_noop
("# failed address checks during validation"), 1,
GNUNET_NO);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Address `%s' is not one of my addresses, not confirming PING\n",
- GST_plugins_a2s (&address));
- return;
- }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Address `%s' is not one of my addresses, not confirming PING\n"),
+ GST_plugins_a2s (&address));
+ return GNUNET_SYSERR;
+ }
else
{
GNUNET_STATISTICS_update (GST_stats,
@@ -1046,10 +1049,10 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
if (GNUNET_NO == buggy)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Not confirming PING from peer `%s' with address `%s' since I cannot confirm having this address.\n",
+ _("Not confirming PING from peer `%s' with address `%s' since I cannot confirm having this address.\n"),
GNUNET_i2s (sender),
GST_plugins_a2s (&address));
- return;
+ return GNUNET_SYSERR;
}
else
{
@@ -1145,8 +1148,8 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
NULL, NULL);
if (-1 != ret)
GST_neighbours_notify_data_sent (sender,
- sender_address, session, pong->header.size);
-
+ sender_address, session,
+ pong->header.size);
}
}
if (ret != -1)
@@ -1160,7 +1163,7 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
("# PONGs unicast via reliable transport"), 1,
GNUNET_NO);
GNUNET_free (pong);
- return;
+ return GNUNET_OK;
}
/* no reliable method found, try transmission via all known addresses */
@@ -1168,13 +1171,15 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
gettext_noop
("# PONGs multicast to all available addresses"), 1,
GNUNET_NO);
- GST_validation_get_addresses (sender, &multicast_pong, pong);
+ GST_validation_get_addresses (sender,
+ &multicast_pong, pong);
GNUNET_free (pong);
+ return GNUNET_OK;
}
/**
- * Context for the 'validate_address' function
+ * Context for the #validate_address_iterator() function
*/
struct ValidateAddressContext
{
@@ -1187,6 +1192,7 @@ struct ValidateAddressContext
* Public key of the peer whose address is being validated.
*/
struct GNUNET_CRYPTO_EddsaPublicKey public_key;
+
};
@@ -1194,7 +1200,7 @@ struct ValidateAddressContext
* Iterator callback to go over all addresses and try to validate them
* (unless blocked or already validated).
*
- * @param cls pointer to a 'struct ValidateAddressContext'
+ * @param cls pointer to a `struct ValidateAddressContext`
* @param address the address
* @param expiration expiration time
* @return #GNUNET_OK (keep the address)
@@ -1218,7 +1224,7 @@ validate_address_iterator (void *cls,
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting validation for fresh address %s\n",
- GST_plugins_a2s (ve->address));
+ GST_plugins_a2s (ve->address));
ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
}
return GNUNET_OK;
@@ -1252,8 +1258,9 @@ add_valid_peer_address (void *cls, size_t max, void *buf)
*
* @param sender peer sending the PONG
* @param hdr the PONG
+ * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
*/
-void
+int
GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
const struct GNUNET_MessageHeader *hdr)
{
@@ -1272,7 +1279,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
if (ntohs (hdr->size) < sizeof (struct TransportPongMessage))
{
GNUNET_break_op (0);
- return;
+ return GNUNET_SYSERR;
}
GNUNET_STATISTICS_update (GST_stats,
gettext_noop ("# PONG messages received"), 1,
@@ -1288,7 +1295,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
if (NULL == addr)
{
GNUNET_break_op (0);
- return;
+ return GNUNET_SYSERR;
}
addr++;
slen = strlen (tname) + 1;
@@ -1304,13 +1311,13 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
gettext_noop
("# PONGs dropped, no matching pending validation"),
1, GNUNET_NO);
- return;
+ return GNUNET_OK;
}
/* now check that PONG is well-formed */
if (0 != memcmp (&ve->pid, sender, sizeof (struct GNUNET_PeerIdentity)))
{
GNUNET_break_op (0);
- return;
+ return GNUNET_SYSERR;
}
if (GNUNET_TIME_absolute_get_remaining
(GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value_us == 0)
@@ -1319,7 +1326,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
gettext_noop
("# PONGs dropped, signature expired"), 1,
GNUNET_NO);
- return;
+ return GNUNET_SYSERR;
}
sig_res = GNUNET_SYSERR;
@@ -1348,13 +1355,20 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
&pong->purpose, &pong->signature,
&ve->public_key);
if (sig_res == GNUNET_SYSERR)
+ {
+ GNUNET_break_op (0);
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Failed to verify: invalid signature on address %s:%s from peer `%s'\n",
- tname, GST_plugins_a2s (ve->address),GNUNET_i2s (sender));
+ tname,
+ GST_plugins_a2s (ve->address),
+ GNUNET_i2s (sender));
+ }
}
-
if (sig_res == GNUNET_SYSERR)
- return;
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Address validated for peer `%s' with plugin `%s': `%s'\n",
@@ -1367,6 +1381,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
ve->latency = GNUNET_TIME_absolute_get_duration (ve->send_time);
{
struct GNUNET_ATS_Information ats[2];
+
ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
ats[0].value = htonl ((uint32_t) ve->latency.rel_value_us);
ats[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
@@ -1381,7 +1396,9 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
validations_running);
}
else
- GNUNET_break (0);
+ {
+ GNUNET_break (0);
+ }
/* build HELLO to store in PEERINFO */
ve->copied = GNUNET_NO;
@@ -1390,6 +1407,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
GNUNET_NO);
GNUNET_PEERINFO_add_peer (GST_peerinfo, hello, NULL, NULL);
GNUNET_free (hello);
+ return GNUNET_OK;
}
@@ -1398,8 +1416,9 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
* validation.
*
* @param hello the HELLO we received
+ * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
*/
-void
+int
GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
{
const struct GNUNET_HELLO_Message *hm =
@@ -1409,17 +1428,18 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
int friend;
friend = GNUNET_HELLO_is_friend_only (hm);
- if (((GNUNET_YES != friend) && (GNUNET_NO != friend)) ||
- (GNUNET_OK != GNUNET_HELLO_get_id (hm, &vac.pid)) ||
- (GNUNET_OK != GNUNET_HELLO_get_key (hm, &vac.public_key)))
+ if ( ( (GNUNET_YES != friend) &&
+ (GNUNET_NO != friend) ) ||
+ (GNUNET_OK != GNUNET_HELLO_get_id (hm, &vac.pid)) ||
+ (GNUNET_OK != GNUNET_HELLO_get_key (hm, &vac.public_key)))
{
/* malformed HELLO */
- GNUNET_break (0);
- return;
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
}
if (0 ==
memcmp (&GST_my_identity, &vac.pid, sizeof (struct GNUNET_PeerIdentity)))
- return;
+ return GNUNET_OK;
/* Add peer identity without addresses to peerinfo service */
h = GNUNET_HELLO_create (&vac.public_key, NULL, NULL, friend);
GNUNET_PEERINFO_add_peer (GST_peerinfo, h, NULL, NULL);
@@ -1433,11 +1453,12 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
GNUNET_HELLO_iterate_addresses (hm, GNUNET_NO,
&validate_address_iterator,
&vac));
+ return GNUNET_OK;
}
/**
- * Closure for 'iterate_addresses'
+ * Closure for #iterate_addresses().
*/
struct IteratorContext
{
@@ -1447,7 +1468,7 @@ struct IteratorContext
GST_ValidationAddressCallback cb;
/**
- * Closure for 'cb'.
+ * Closure for @e cb.
*/
void *cb_cls;
@@ -1457,9 +1478,9 @@ struct IteratorContext
/**
* Call the callback in the closure for each validation entry.
*
- * @param cls the 'struct GST_ValidationIteratorContext'
+ * @param cls the `struct IteratorContext`
* @param key the peer's identity
- * @param value the 'struct ValidationEntry'
+ * @param value the `struct ValidationEntry`
* @return #GNUNET_OK (continue to iterate)
*/
static int
diff --git a/src/transport/gnunet-service-transport_validation.h b/src/transport/gnunet-service-transport_validation.h
index 3408f50bb..c37484f13 100644
--- a/src/transport/gnunet-service-transport_validation.h
+++ b/src/transport/gnunet-service-transport_validation.h
@@ -89,8 +89,9 @@ GST_validation_get_address_latency (const struct GNUNET_PeerIdentity *sender,
* @param hdr the PING
* @param sender_address address of the sender, NULL if we did not initiate
* @param session session we got the PING from
+ * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
*/
-void
+int
GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
const struct GNUNET_MessageHeader *hdr,
const struct GNUNET_HELLO_Address *sender_address,
@@ -103,8 +104,9 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
*
* @param sender peer sending the PONG
* @param hdr the PONG
+ * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
*/
-void
+int
GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
const struct GNUNET_MessageHeader *hdr);
@@ -114,8 +116,9 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
* validation.
*
* @param hello the HELLO we received
+ * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
*/
-void
+int
GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello);
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index c70bb8ef7..72ac5b2b8 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -1608,25 +1608,25 @@ static struct PrettyPrinterContext *ppc_dll_tail;
*/
struct PrettyPrinterContext
{
- /**
- * DLL
- */
- struct PrettyPrinterContext *next;
-
- /**
- * DLL
- */
- struct PrettyPrinterContext *prev;
-
- /**
- * Timeout task
- */
- GNUNET_SCHEDULER_TaskIdentifier timeout_task;
-
- /**
- * Resolver handle
- */
- struct GNUNET_RESOLVER_RequestHandle *resolver_handle;
+ /**
+ * DLL
+ */
+ struct PrettyPrinterContext *next;
+
+ /**
+ * DLL
+ */
+ struct PrettyPrinterContext *prev;
+
+ /**
+ * Timeout task
+ */
+ GNUNET_SCHEDULER_TaskIdentifier timeout_task;
+
+ /**
+ * Resolver handle
+ */
+ struct GNUNET_RESOLVER_RequestHandle *resolver_handle;
/**
* Function to call with the result.
diff --git a/src/transport/test_transport_defaults.conf b/src/transport/test_transport_defaults.conf
index d34b60dbc..7a064fa21 100644
--- a/src/transport/test_transport_defaults.conf
+++ b/src/transport/test_transport_defaults.conf
@@ -5,10 +5,10 @@ GNUNET_TEST_HOME = /tmp/test-transport-api/
TIMEOUT = 300 s
[arm]
-DEFAULTSERVICES =
+DEFAULTSERVICES =
[transport]
-PREFIX =
+PREFIX = valgrind
[core]
AUTOSTART = NO
diff --git a/src/transport/transport.conf.in b/src/transport/transport.conf.in
index 14867c572..0464ba841 100644
--- a/src/transport/transport.conf.in
+++ b/src/transport/transport.conf.in
@@ -3,7 +3,7 @@ AUTOSTART = @AUTOSTART@
@JAVAPORT@PORT = 2091
HOSTNAME = localhost
BINARY = gnunet-service-transport
-#PREFIX = valgrind
+# PREFIX = valgrind
NEIGHBOUR_LIMIT = 50
ACCEPT_FROM = 127.0.0.1;
ACCEPT_FROM6 = ::1;