aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-12-11 22:50:10 +0000
committerChristian Grothoff <christian@grothoff.org>2013-12-11 22:50:10 +0000
commit9dbf3b587010260ad2e26450a86a37ecd298df11 (patch)
treeb475c461b0dd6906f885b9992a98e13cec5f36d2
parent6f5773151141852cdb07a14edb2d5974d89814c2 (diff)
downloadgnunet-9dbf3b587010260ad2e26450a86a37ecd298df11.tar.gz
gnunet-9dbf3b587010260ad2e26450a86a37ecd298df11.zip
-more logging, etc.
-rw-r--r--src/dv/test_transport_dv_data.conf10
-rw-r--r--src/include/gnunet_transport_plugin.h58
-rw-r--r--src/transport/gnunet-service-transport.c2
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c44
-rw-r--r--src/transport/plugin_transport_tcp.c217
5 files changed, 185 insertions, 146 deletions
diff --git a/src/dv/test_transport_dv_data.conf b/src/dv/test_transport_dv_data.conf
index 77dda946f..44ae1f0fd 100644
--- a/src/dv/test_transport_dv_data.conf
+++ b/src/dv/test_transport_dv_data.conf
@@ -3,12 +3,16 @@
3[transport] 3[transport]
4PORT = 2565 4PORT = 2565
5PLUGINS = tcp dv 5PLUGINS = tcp dv
6PREFIX = valgrind 6PREFIX = valgrind --leak-check=full --track-fds=yes --leak-resolution=high
7 7
8[dv] 8[dv]
9AUTOSTART = YES 9AUTOSTART = YES
10#PREFIX = valgrind 10PREFIX = valgrind --leak-check=full --track-fds=yes --leak-resolution=high
11 11
12[set] 12[set]
13AUTOSTART = YES 13AUTOSTART = YES
14#PREFIX = valgrind 14PREFIX = valgrind --leak-check=full --track-fds=yes --leak-resolution=high
15
16[core]
17PREFIX = valgrind --leak-check=full --track-fds=yes --leak-resolution=high
18
diff --git a/src/include/gnunet_transport_plugin.h b/src/include/gnunet_transport_plugin.h
index f835bdcd8..7df04edfe 100644
--- a/src/include/gnunet_transport_plugin.h
+++ b/src/include/gnunet_transport_plugin.h
@@ -90,7 +90,7 @@ typedef void (*GNUNET_TRANSPORT_SessionEnd) (void *cls,
90 * @param peer peer 90 * @param peer peer
91 * @param plugin plugin 91 * @param plugin plugin
92 * @param address address 92 * @param address address
93 * @param address_len length of the address 93 * @param address_len length of the @a address
94 * @param session session 94 * @param session session
95 * @param ats ATS information 95 * @param ats ATS information
96 * @param ats_count number of ATS information contained 96 * @param ats_count number of ATS information contained
@@ -122,7 +122,7 @@ typedef void
122 * for inbound TCP/UDP connections since it it not clear 122 * for inbound TCP/UDP connections since it it not clear
123 * that we could establish ourselves a connection to that 123 * that we could establish ourselves a connection to that
124 * IP address and get the same system) 124 * IP address and get the same system)
125 * @param sender_address_len number of bytes in sender_address 125 * @param sender_address_len number of bytes in @a sender_address
126 * @return how long the plugin should wait until receiving more data 126 * @return how long the plugin should wait until receiving more data
127 * (plugins that do not support this, can ignore the return value) 127 * (plugins that do not support this, can ignore the return value)
128 */ 128 */
@@ -141,7 +141,7 @@ typedef struct
141 * 141 *
142 * @param cls closure 142 * @param cls closure
143 * @param addr binary address 143 * @param addr binary address
144 * @param addrlen length of the address 144 * @param addrlen length of the @a addr
145 * @return ATS Information containing the network type 145 * @return ATS Information containing the network type
146 */ 146 */
147typedef struct GNUNET_ATS_Information 147typedef struct GNUNET_ATS_Information
@@ -156,10 +156,10 @@ typedef struct GNUNET_ATS_Information
156 * @param cls closure 156 * @param cls closure
157 * @param peer peer 157 * @param peer peer
158 * @param address address 158 * @param address address
159 * @param address_len length of the address 159 * @param address_len length of the @a address
160 * @param session session 160 * @param session session
161 * @param ats ATS information 161 * @param ats ATS information
162 * @param ats_count number of ATS information contained 162 * @param ats_count number of ATS information contained in @a ats
163 */ 163 */
164typedef void 164typedef void
165(*GNUNET_TRANSPORT_UpdateAddressMetrics) (void *cls, 165(*GNUNET_TRANSPORT_UpdateAddressMetrics) (void *cls,
@@ -183,7 +183,7 @@ typedef void
183 * @param dest_plugin plugin to use this address with 183 * @param dest_plugin plugin to use this address with
184 */ 184 */
185typedef void (*GNUNET_TRANSPORT_AddressNotification) (void *cls, 185typedef void (*GNUNET_TRANSPORT_AddressNotification) (void *cls,
186 int add_remove, 186 int add_remove,
187 const void *addr, 187 const void *addr,
188 size_t addrlen, 188 size_t addrlen,
189 const char *dest_plugin); 189 const char *dest_plugin);
@@ -312,19 +312,19 @@ struct GNUNET_TRANSPORT_PluginEnvironment
312 * 312 *
313 * @param cls closure 313 * @param cls closure
314 * @param target who was the recipient of the message? 314 * @param target who was the recipient of the message?
315 * @param result GNUNET_OK on success 315 * @param result #GNUNET_OK on success
316 * GNUNET_SYSERR if the target disconnected; 316 * #GNUNET_SYSERR if the target disconnected;
317 * disconnect will ALSO be signalled using 317 * disconnect will ALSO be signalled using
318 * the ReceiveCallback. 318 * the ReceiveCallback.
319 * @param size_payload bytes of payload from transport service in message 319 * @param size_payload bytes of payload from transport service in message
320 * @param size_on_wire bytes required on wire for transmission, 320 * @param size_on_wire bytes required on wire for transmission,
321 * 0 if result == GNUNET_SYSERR 321 * 0 if result == #GNUNET_SYSERR
322 */ 322 */
323typedef void (*GNUNET_TRANSPORT_TransmitContinuation) (void *cls, 323typedef void (*GNUNET_TRANSPORT_TransmitContinuation) (void *cls,
324 const struct GNUNET_PeerIdentity *target, 324 const struct GNUNET_PeerIdentity *target,
325 int result, 325 int result,
326 size_t size_payload, 326 size_t size_payload,
327 size_t size_on_wire); 327 size_t size_on_wire);
328 328
329/** 329/**
330 * The new send function with just the session and no address 330 * The new send function with just the session and no address
@@ -339,7 +339,7 @@ typedef void (*GNUNET_TRANSPORT_TransmitContinuation) (void *cls,
339 * @param cls closure 339 * @param cls closure
340 * @param session which session must be used 340 * @param session which session must be used
341 * @param msgbuf the message to transmit 341 * @param msgbuf the message to transmit
342 * @param msgbuf_size number of bytes in 'msgbuf' 342 * @param msgbuf_size number of bytes in @a msgbuf
343 * @param priority how important is the message (most plugins will 343 * @param priority how important is the message (most plugins will
344 * ignore message priority and just FIFO) 344 * ignore message priority and just FIFO)
345 * @param to how long to wait at most for the transmission (does not 345 * @param to how long to wait at most for the transmission (does not
@@ -409,16 +409,16 @@ typedef void (*GNUNET_TRANSPORT_AddressStringCallback) (void *cls,
409 * @param numeric should (IP) addresses be displayed in numeric form? 409 * @param numeric should (IP) addresses be displayed in numeric form?
410 * @param timeout after how long should we give up? 410 * @param timeout after how long should we give up?
411 * @param asc function to call on each string 411 * @param asc function to call on each string
412 * @param asc_cls closure for asc 412 * @param asc_cls closure for @a asc
413 */ 413 */
414typedef void (*GNUNET_TRANSPORT_AddressPrettyPrinter) (void *cls, 414typedef void (*GNUNET_TRANSPORT_AddressPrettyPrinter) (void *cls,
415 const char *type, 415 const char *type,
416 const void *addr, 416 const void *addr,
417 size_t addrlen, 417 size_t addrlen,
418 int numeric, 418 int numeric,
419 struct GNUNET_TIME_Relative timeout, 419 struct GNUNET_TIME_Relative timeout,
420 GNUNET_TRANSPORT_AddressStringCallback asc, 420 GNUNET_TRANSPORT_AddressStringCallback asc,
421 void *asc_cls); 421 void *asc_cls);
422 422
423 423
424/** 424/**
@@ -431,12 +431,12 @@ typedef void (*GNUNET_TRANSPORT_AddressPrettyPrinter) (void *cls,
431 * and not some potential man-in-the-middle). 431 * and not some potential man-in-the-middle).
432 * 432 *
433 * @param addr pointer to the address 433 * @param addr pointer to the address
434 * @param addrlen length of addr 434 * @param addrlen length of @a addr
435 * @return GNUNET_OK if this is a plausible address for this peer 435 * @return #GNUNET_OK if this is a plausible address for this peer
436 * and transport, GNUNET_SYSERR if not 436 * and transport, #GNUNET_SYSERR if not
437 */ 437 */
438typedef int (*GNUNET_TRANSPORT_CheckAddress) (void *cls, 438typedef int (*GNUNET_TRANSPORT_CheckAddress) (void *cls,
439 const void *addr, 439 const void *addr,
440 size_t addrlen); 440 size_t addrlen);
441 441
442/** 442/**
@@ -473,11 +473,11 @@ typedef const char *(*GNUNET_TRANSPORT_AddressToString) (void *cls,
473 * 473 *
474 * @param cls closure ('struct Plugin*') 474 * @param cls closure ('struct Plugin*')
475 * @param addr string address 475 * @param addr string address
476 * @param addrlen length of the address including \0 termination 476 * @param addrlen length of the address including '\0' termination
477 * @param buf location to store the buffer 477 * @param buf location to store the buffer
478 * If the function returns GNUNET_SYSERR, its contents are undefined. 478 * If the function returns #GNUNET_SYSERR, its contents are undefined.
479 * @param added length of created address 479 * @param added length of created address
480 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 480 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
481 */ 481 */
482typedef int (*GNUNET_TRANSPORT_StringToAddress) (void *cls, 482typedef int (*GNUNET_TRANSPORT_StringToAddress) (void *cls,
483 const char *addr, 483 const char *addr,
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index 50faeae89..d96a284c7 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -194,7 +194,7 @@ process_payload (const struct GNUNET_PeerIdentity *peer,
194 * for inbound TCP/UDP connections since it it not clear 194 * for inbound TCP/UDP connections since it it not clear
195 * that we could establish ourselves a connection to that 195 * that we could establish ourselves a connection to that
196 * IP address and get the same system) 196 * IP address and get the same system)
197 * @param sender_address_len number of bytes in sender_address 197 * @param sender_address_len number of bytes in @a sender_address
198 * @return how long the plugin should wait until receiving more data 198 * @return how long the plugin should wait until receiving more data
199 * (plugins that do not support this, can ignore the return value) 199 * (plugins that do not support this, can ignore the return value)
200 */ 200 */
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 58d2d7ea2..38c44c1ec 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -378,7 +378,7 @@ enum State
378 * from the map. We should never find a 'struct NeighbourMapEntry' 378 * from the map. We should never find a 'struct NeighbourMapEntry'
379 * in this state in the map. Accessing a 'struct NeighbourMapEntry' 379 * in this state in the map. Accessing a 'struct NeighbourMapEntry'
380 * in this state virtually always means using memory that has been 380 * in this state virtually always means using memory that has been
381 * freed (the exception being the cleanup code in 'free_neighbour'). 381 * freed (the exception being the cleanup code in #free_neighbour()).
382 */ 382 */
383 S_DISCONNECT_FINISHED 383 S_DISCONNECT_FINISHED
384}; 384};
@@ -875,8 +875,8 @@ set_address (struct NeighbourAddress *na,
875 * Free a neighbour map entry. 875 * Free a neighbour map entry.
876 * 876 *
877 * @param n entry to free 877 * @param n entry to free
878 * @param keep_sessions GNUNET_NO to tell plugin to terminate sessions, 878 * @param keep_sessions #GNUNET_NO to tell plugin to terminate sessions,
879 * GNUNET_YES to keep all sessions 879 * #GNUNET_YES to keep all sessions
880 */ 880 */
881static void 881static void
882free_neighbour (struct NeighbourMapEntry *n, int keep_sessions) 882free_neighbour (struct NeighbourMapEntry *n, int keep_sessions)
@@ -909,7 +909,7 @@ free_neighbour (struct NeighbourMapEntry *n, int keep_sessions)
909 909
910 if (NULL != n->primary_address.address) 910 if (NULL != n->primary_address.address)
911 { 911 {
912 backup_primary = GNUNET_HELLO_address_copy(n->primary_address.address); 912 backup_primary = GNUNET_HELLO_address_copy (n->primary_address.address);
913 } 913 }
914 else 914 else
915 backup_primary = NULL; 915 backup_primary = NULL;
@@ -959,6 +959,7 @@ free_neighbour (struct NeighbourMapEntry *n, int keep_sessions)
959 GNUNET_free (n); 959 GNUNET_free (n);
960} 960}
961 961
962
962/** 963/**
963 * Transmit a message using the current session of the given 964 * Transmit a message using the current session of the given
964 * neighbour. 965 * neighbour.
@@ -1592,14 +1593,22 @@ send_session_connect (struct NeighbourAddress *na)
1592 connect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT); 1593 connect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT);
1593 connect_msg.reserved = htonl (0); 1594 connect_msg.reserved = htonl (0);
1594 connect_msg.timestamp = GNUNET_TIME_absolute_hton (na->connect_timestamp); 1595 connect_msg.timestamp = GNUNET_TIME_absolute_hton (na->connect_timestamp);
1595 (void) papi->send (papi->cls, 1596 if (-1 ==
1596 na->session, 1597 papi->send (papi->cls,
1597 (const char *) &connect_msg, sizeof (struct SessionConnectMessage), 1598 na->session,
1598 UINT_MAX, 1599 (const char *) &connect_msg, sizeof (struct SessionConnectMessage),
1599 GNUNET_TIME_UNIT_FOREVER_REL, 1600 UINT_MAX,
1600 NULL, NULL); 1601 GNUNET_TIME_UNIT_FOREVER_REL,
1602 NULL, NULL))
1603 {
1604 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1605 _("Failed to transmit CONNECT message via plugin to %s\n"),
1606 GST_plugins_a2s (na->address));
1607 }
1601 GST_neighbours_notify_data_sent (&na->address->peer, 1608 GST_neighbours_notify_data_sent (&na->address->peer,
1602 na->address, na->session, sizeof (struct SessionConnectMessage)); 1609 na->address,
1610 na->session,
1611 sizeof (struct SessionConnectMessage));
1603 1612
1604} 1613}
1605 1614
@@ -2191,10 +2200,8 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
2191 struct Session *session, 2200 struct Session *session,
2192 const struct GNUNET_ATS_Information *ats, 2201 const struct GNUNET_ATS_Information *ats,
2193 uint32_t ats_count, 2202 uint32_t ats_count,
2194 struct GNUNET_BANDWIDTH_Value32NBO 2203 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
2195 bandwidth_in, 2204 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
2196 struct GNUNET_BANDWIDTH_Value32NBO
2197 bandwidth_out)
2198{ 2205{
2199 struct NeighbourMapEntry *n; 2206 struct NeighbourMapEntry *n;
2200 struct GNUNET_TRANSPORT_PluginFunctions *papi; 2207 struct GNUNET_TRANSPORT_PluginFunctions *papi;
@@ -3083,8 +3090,13 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
3083 (S_CONNECT_SENT != n->state) ) || 3090 (S_CONNECT_SENT != n->state) ) ||
3084 (2 != n->send_connect_ack) ) 3091 (2 != n->send_connect_ack) )
3085 { 3092 {
3093 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3094 "Received SESSION_ACK message from peer `%s' in state %s/%d\n",
3095 GNUNET_i2s (peer),
3096 print_state (n->state),
3097 n->send_connect_ack);
3086 GNUNET_STATISTICS_update (GST_stats, 3098 GNUNET_STATISTICS_update (GST_stats,
3087 gettext_noop ("# unexpected SESSION ACK messages"), 1, 3099 gettext_noop ("# unexpected SESSION_ACK messages"), 1,
3088 GNUNET_NO); 3100 GNUNET_NO);
3089 return; 3101 return;
3090 } 3102 }
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index 113cb70c5..273d39873 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -139,10 +139,10 @@ GNUNET_NETWORK_STRUCT_BEGIN
139 */ 139 */
140struct IPv4TcpAddress 140struct IPv4TcpAddress
141{ 141{
142 /** 142 /**
143 * Optional options and flags for this address 143 * Optional options and flags for this address
144 */ 144 */
145 uint32_t options; 145 uint32_t options;
146 146
147 /** 147 /**
148 * IPv4 address, in network byte order. 148 * IPv4 address, in network byte order.
@@ -162,10 +162,10 @@ struct IPv4TcpAddress
162 */ 162 */
163struct IPv6TcpAddress 163struct IPv6TcpAddress
164{ 164{
165 /** 165 /**
166 * Optional flags for this address 166 * Optional flags for this address
167 */ 167 */
168 uint32_t options; 168 uint32_t options;
169 169
170 /** 170 /**
171 * IPv6 address. 171 * IPv6 address.
@@ -314,12 +314,12 @@ struct Session
314 struct GNUNET_TIME_Absolute last_activity; 314 struct GNUNET_TIME_Absolute last_activity;
315 315
316 /** 316 /**
317 * Are we still expecting the welcome message? (GNUNET_YES/GNUNET_NO) 317 * Are we still expecting the welcome message? (#GNUNET_YES/#GNUNET_NO)
318 */ 318 */
319 int expecting_welcome; 319 int expecting_welcome;
320 320
321 /** 321 /**
322 * Was this a connection that was inbound (we accepted)? (GNUNET_YES/GNUNET_NO) 322 * Was this a connection that was inbound (we accepted)? (#GNUNET_YES/#GNUNET_NO)
323 */ 323 */
324 int inbound; 324 int inbound;
325 325
@@ -441,6 +441,8 @@ reschedule_session_timeout (struct Session *s);
441 441
442/** 442/**
443 * Cancel timeout 443 * Cancel timeout
444 *
445 * @param s session to cancel timeout for
444 */ 446 */
445static void 447static void
446stop_session_timeout (struct Session *s); 448stop_session_timeout (struct Session *s);
@@ -458,34 +460,39 @@ static void
458inc_sessions (struct Plugin *plugin, struct Session *session, int line) 460inc_sessions (struct Plugin *plugin, struct Session *session, int line)
459{ 461{
460 sessions++; 462 sessions++;
461 unsigned int size = GNUNET_CONTAINER_multipeermap_size(plugin->sessionmap); 463 unsigned int size = GNUNET_CONTAINER_multipeermap_size (plugin->sessionmap);
462 if (sessions != size) 464 if (sessions != size)
463 LOG (GNUNET_ERROR_TYPE_DEBUG, "Inconsistent sessions %u <-> session map size: %u\n", 465 LOG (GNUNET_ERROR_TYPE_DEBUG,
464 sessions, size); 466 "Inconsistent sessions %u <-> session map size: %u\n",
465 LOG (GNUNET_ERROR_TYPE_DEBUG, "%4i Session increased to %u (session map size: %u): `%s' `%s'\n", 467 sessions, size);
466 line, 468 LOG (GNUNET_ERROR_TYPE_DEBUG,
467 sessions, 469 "%4i Session increased to %u (session map size: %u): `%s' `%s'\n",
468 size, 470 line,
469 GNUNET_i2s (&session->target), 471 sessions,
470 tcp_address_to_string (NULL, session->addr, session->addrlen)); 472 size,
473 GNUNET_i2s (&session->target),
474 tcp_address_to_string (NULL, session->addr, session->addrlen));
471} 475}
472 476
473 477
474static void 478static void
475dec_sessions (struct Plugin *plugin, struct Session *session, int line) 479dec_sessions (struct Plugin *plugin,
480 struct Session *session, int line)
476{ 481{
477 GNUNET_assert (sessions > 0); 482 GNUNET_assert (sessions > 0);
478 unsigned int size = GNUNET_CONTAINER_multipeermap_size(plugin->sessionmap); 483 unsigned int size = GNUNET_CONTAINER_multipeermap_size(plugin->sessionmap);
479 sessions--; 484 sessions--;
480 if (sessions != size) 485 if (sessions != size)
481 LOG (GNUNET_ERROR_TYPE_DEBUG, "Inconsistent sessions %u <-> session map size: %u\n", 486 LOG (GNUNET_ERROR_TYPE_DEBUG,
482 sessions, size); 487 "Inconsistent sessions %u <-> session map size: %u\n",
483 LOG (GNUNET_ERROR_TYPE_DEBUG, "%4i Session decreased to %u (session map size: %u): `%s' `%s'\n", 488 sessions, size);
484 line, 489 LOG (GNUNET_ERROR_TYPE_DEBUG,
485 sessions, 490 "%4i Session decreased to %u (session map size: %u): `%s' `%s'\n",
486 size, 491 line,
487 GNUNET_i2s (&session->target), 492 sessions,
488 tcp_address_to_string (NULL, session->addr, session->addrlen)); 493 size,
494 GNUNET_i2s (&session->target),
495 tcp_address_to_string (NULL, session->addr, session->addrlen));
489} 496}
490/* DEBUG CODE */ 497/* DEBUG CODE */
491 498
@@ -499,7 +506,7 @@ dec_sessions (struct Plugin *plugin, struct Session *session, int line)
499 * @param ucred credentials, if available, otherwise NULL 506 * @param ucred credentials, if available, otherwise NULL
500 * @param addr address 507 * @param addr address
501 * @param addrlen length of address 508 * @param addrlen length of address
502 * @return GNUNET_YES to allow, GNUNET_NO to deny, GNUNET_SYSERR 509 * @return #GNUNET_YES to allow, #GNUNET_NO to deny, #GNUNET_SYSERR
503 * for unknown address family (will be denied). 510 * for unknown address family (will be denied).
504 */ 511 */
505static int 512static int
@@ -522,7 +529,7 @@ plugin_tcp_access_check (void *cls,
522 * Our external IP address/port mapping has changed. 529 * Our external IP address/port mapping has changed.
523 * 530 *
524 * @param cls closure, the 'struct LocalAddrList' 531 * @param cls closure, the 'struct LocalAddrList'
525 * @param add_remove GNUNET_YES to mean the new public IP address, GNUNET_NO to mean 532 * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean
526 * the previous (now invalid) one 533 * the previous (now invalid) one
527 * @param addr either the previous or the new public IP address 534 * @param addr either the previous or the new public IP address
528 * @param addrlen actual lenght of the address 535 * @param addrlen actual lenght of the address
@@ -647,12 +654,14 @@ tcp_address_to_string (void *cls, const void *addr, size_t addrlen)
647 * @param addrlen length of the address 654 * @param addrlen length of the address
648 * @param buf location to store the buffer 655 * @param buf location to store the buffer
649 * @param added location to store the number of bytes in the buffer. 656 * @param added location to store the number of bytes in the buffer.
650 * If the function returns GNUNET_SYSERR, its contents are undefined. 657 * If the function returns #GNUNET_SYSERR, its contents are undefined.
651 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 658 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
652 */ 659 */
653static int 660static int
654tcp_string_to_address (void *cls, const char *addr, uint16_t addrlen, 661tcp_string_to_address (void *cls,
655 void **buf, size_t *added) 662 const char *addr,
663 uint16_t addrlen,
664 void **buf, size_t *added)
656{ 665{
657 struct sockaddr_storage socket_address; 666 struct sockaddr_storage socket_address;
658 char *address; 667 char *address;
@@ -1024,17 +1033,25 @@ disconnect_session (struct Session *session)
1024 1033
1025 stop_session_timeout (session); 1034 stop_session_timeout (session);
1026 1035
1027 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (plugin->sessionmap, &session->target, session)) 1036 if (GNUNET_YES ==
1037 GNUNET_CONTAINER_multipeermap_remove (plugin->sessionmap,
1038 &session->target,
1039 session))
1028 { 1040 {
1029 GNUNET_STATISTICS_update (session->plugin->env->stats, 1041 GNUNET_STATISTICS_update (session->plugin->env->stats,
1030 gettext_noop ("# TCP sessions active"), -1, 1042 gettext_noop ("# TCP sessions active"), -1,
1031 GNUNET_NO); 1043 GNUNET_NO);
1032 dec_sessions (plugin, session, __LINE__); 1044 dec_sessions (plugin, session, __LINE__);
1033 } 1045 }
1034 else GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, &session->target, session)); 1046 else
1035 1047 {
1048 GNUNET_assert (GNUNET_YES ==
1049 GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns,
1050 &session->target,
1051 session));
1052 }
1036 /* clean up state */ 1053 /* clean up state */
1037 if (session->transmit_handle != NULL) 1054 if (NULL != session->transmit_handle)
1038 { 1055 {
1039 GNUNET_SERVER_notify_transmit_ready_cancel (session->transmit_handle); 1056 GNUNET_SERVER_notify_transmit_ready_cancel (session->transmit_handle);
1040 session->transmit_handle = NULL; 1057 session->transmit_handle = NULL;
@@ -1630,29 +1647,29 @@ struct PrettyPrinterContext
1630}; 1647};
1631 1648
1632 1649
1633 1650static void
1634void 1651ppc_cancel_task (void *cls,
1635ppc_cancel_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1652 const struct GNUNET_SCHEDULER_TaskContext *tc)
1636{ 1653{
1637 int count = 0; 1654 int count = 0;
1638 struct PrettyPrinterContext *ppc = cls; 1655 struct PrettyPrinterContext *ppc = cls;
1639 struct PrettyPrinterContext *cur; 1656 struct PrettyPrinterContext *cur;
1640 for (cur = ppc_dll_head; (NULL != cur); cur = cur->next) 1657
1641 { 1658 for (cur = ppc_dll_head; (NULL != cur); cur = cur->next)
1642 if (cur != ppc) 1659 {
1643 count++; 1660 if (cur != ppc)
1644 } 1661 count++;
1645 1662 }
1646 // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cancel request %p, %u pending\n", ppc, count); 1663
1647 ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1664 // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cancel request %p, %u pending\n", ppc, count);
1648 if (NULL != ppc->resolver_handle) 1665 ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1649 { 1666 if (NULL != ppc->resolver_handle)
1650 GNUNET_RESOLVER_request_cancel (ppc->resolver_handle); 1667 {
1651 ppc->resolver_handle = NULL; 1668 GNUNET_RESOLVER_request_cancel (ppc->resolver_handle);
1652 } 1669 ppc->resolver_handle = NULL;
1653 1670 }
1654 GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, ppc); 1671 GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, ppc);
1655 GNUNET_free (ppc); 1672 GNUNET_free (ppc);
1656} 1673}
1657 1674
1658 1675
@@ -1670,12 +1687,12 @@ append_port (void *cls, const char *hostname)
1670 char *ret; 1687 char *ret;
1671 int count = 0; 1688 int count = 0;
1672 1689
1673 for (cur = ppc_dll_head; (NULL != cur); cur = cur->next) 1690 for (cur = ppc_dll_head; (NULL != cur); cur = cur->next)
1674 { 1691 {
1675 if (cur != ppc) 1692 if (cur != ppc)
1676 count++; 1693 count++;
1677 } 1694 }
1678 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Callback request %p == %s, %u pending\n", ppc, hostname, count); 1695 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Callback request %p == %s, %u pending\n", ppc, hostname, count);
1679 if (hostname == NULL) 1696 if (hostname == NULL)
1680 { 1697 {
1681 ppc->asc (ppc->asc_cls, NULL); 1698 ppc->asc (ppc->asc_cls, NULL);
@@ -1786,19 +1803,20 @@ tcp_plugin_address_pretty_printer (void *cls, const char *type,
1786 ppc->port = port; 1803 ppc->port = port;
1787 ppc->options = options; 1804 ppc->options = options;
1788 ppc->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(timeout, 2), 1805 ppc->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(timeout, 2),
1789 &ppc_cancel_task, ppc); 1806 &ppc_cancel_task, ppc);
1790 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, 1807 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric,
1791 timeout, &append_port, ppc); 1808 timeout,
1792 if (NULL != ppc->resolver_handle) 1809 &append_port, ppc);
1793 { 1810 if (NULL != ppc->resolver_handle)
1794 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Adding request %p\n", ppc); 1811 {
1795 GNUNET_CONTAINER_DLL_insert (ppc_dll_head, ppc_dll_tail, ppc); 1812 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Adding request %p\n", ppc);
1796 } 1813 GNUNET_CONTAINER_DLL_insert (ppc_dll_head, ppc_dll_tail, ppc);
1797 else 1814 }
1798 { 1815 else
1799 GNUNET_break (0); 1816 {
1800 GNUNET_free (ppc); 1817 GNUNET_break (0);
1801 } 1818 GNUNET_free (ppc);
1819 }
1802} 1820}
1803 1821
1804 1822
@@ -2372,7 +2390,7 @@ notify_send_probe (void *cls, size_t size, void *buf)
2372 * 2390 *
2373 * @param cls closure 2391 * @param cls closure
2374 * @param addr address to try 2392 * @param addr address to try
2375 * @param addrlen number of bytes in addr 2393 * @param addrlen number of bytes in @a addr
2376 */ 2394 */
2377static void 2395static void
2378try_connection_reversal (void *cls, const struct sockaddr *addr, 2396try_connection_reversal (void *cls, const struct sockaddr *addr,
@@ -2421,9 +2439,9 @@ try_connection_reversal (void *cls, const struct sockaddr *addr,
2421 * Session was idle, so disconnect it 2439 * Session was idle, so disconnect it
2422 */ 2440 */
2423static void 2441static void
2424session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 2442session_timeout (void *cls,
2443 const struct GNUNET_SCHEDULER_TaskContext *tc)
2425{ 2444{
2426 GNUNET_assert (NULL != cls);
2427 struct Session *s = cls; 2445 struct Session *s = cls;
2428 2446
2429 s->timeout_task = GNUNET_SCHEDULER_NO_TASK; 2447 s->timeout_task = GNUNET_SCHEDULER_NO_TASK;
@@ -2433,7 +2451,7 @@ session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2433 GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2451 GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
2434 GNUNET_YES)); 2452 GNUNET_YES));
2435 /* call session destroy function */ 2453 /* call session destroy function */
2436 disconnect_session(s); 2454 disconnect_session (s);
2437} 2455}
2438 2456
2439 2457
@@ -2445,7 +2463,7 @@ start_session_timeout (struct Session *s)
2445{ 2463{
2446 GNUNET_assert (NULL != s); 2464 GNUNET_assert (NULL != s);
2447 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task); 2465 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task);
2448 s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2466 s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
2449 &session_timeout, 2467 &session_timeout,
2450 s); 2468 s);
2451 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -2466,9 +2484,9 @@ reschedule_session_timeout (struct Session *s)
2466 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task); 2484 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task);
2467 2485
2468 GNUNET_SCHEDULER_cancel (s->timeout_task); 2486 GNUNET_SCHEDULER_cancel (s->timeout_task);
2469 s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2487 s->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
2470 &session_timeout, 2488 &session_timeout,
2471 s); 2489 s);
2472 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2490 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2473 "Timeout rescheduled for session %p set to %s\n", 2491 "Timeout rescheduled for session %p set to %s\n",
2474 s, 2492 s,
@@ -2478,7 +2496,9 @@ reschedule_session_timeout (struct Session *s)
2478 2496
2479 2497
2480/** 2498/**
2481 * Cancel timeout 2499 * Cancel timeout.
2500 *
2501 * @param s session to cancel timeout for
2482 */ 2502 */
2483static void 2503static void
2484stop_session_timeout (struct Session *s) 2504stop_session_timeout (struct Session *s)
@@ -2634,7 +2654,7 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2634 GNUNET_YES, 0, 0, NULL, NULL, NULL, 2654 GNUNET_YES, 0, 0, NULL, NULL, NULL,
2635 &try_connection_reversal, plugin); 2655 &try_connection_reversal, plugin);
2636 } 2656 }
2637 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); 2657 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
2638 api->cls = plugin; 2658 api->cls = plugin;
2639 api->send = &tcp_plugin_send; 2659 api->send = &tcp_plugin_send;
2640 api->get_session = &tcp_plugin_get_session; 2660 api->get_session = &tcp_plugin_get_session;
@@ -2716,23 +2736,26 @@ libgnunet_plugin_transport_tcp_done (void *cls)
2716 GNUNET_free (api); 2736 GNUNET_free (api);
2717 return NULL; 2737 return NULL;
2718 } 2738 }
2719 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down TCP plugin\n"); 2739 LOG (GNUNET_ERROR_TYPE_DEBUG,
2740 "Shutting down TCP plugin\n");
2720 2741
2721 /* Removing leftover sessions */ 2742 /* Removing leftover sessions */
2722 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessionmap, &session_disconnect_it, NULL); 2743 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap,
2744 &session_disconnect_it, NULL);
2723 /* Removing leftover NAT sessions */ 2745 /* Removing leftover NAT sessions */
2724 GNUNET_CONTAINER_multipeermap_iterate(plugin->nat_wait_conns, &session_disconnect_it, NULL); 2746 GNUNET_CONTAINER_multipeermap_iterate (plugin->nat_wait_conns,
2747 &session_disconnect_it, NULL);
2725 2748
2726 next = ppc_dll_head; 2749 next = ppc_dll_head;
2727 for (cur = next; NULL != cur; cur = next) 2750 for (cur = next; NULL != cur; cur = next)
2728 { 2751 {
2729 next = cur->next; 2752 next = cur->next;
2730 GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, cur); 2753 GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, cur);
2731 if (NULL != cur->resolver_handle) 2754 if (NULL != cur->resolver_handle)
2732 GNUNET_RESOLVER_request_cancel (cur->resolver_handle); 2755 GNUNET_RESOLVER_request_cancel (cur->resolver_handle);
2733 GNUNET_SCHEDULER_cancel (cur->timeout_task); 2756 GNUNET_SCHEDULER_cancel (cur->timeout_task);
2734 GNUNET_free (cur); 2757 GNUNET_free (cur);
2735 GNUNET_break (0); 2758 GNUNET_break (0);
2736 } 2759 }
2737 2760
2738 if (plugin->service != NULL) 2761 if (plugin->service != NULL)