aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_tcp.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-05-15 17:41:14 +0000
committerChristian Grothoff <christian@grothoff.org>2012-05-15 17:41:14 +0000
commit214c0be64317f667bc79bcc604b8d0c87a33bab6 (patch)
treea214db4370ebb5b79d9369ec0014b899e2f1b851 /src/transport/plugin_transport_tcp.c
parent6f4938c5e2f793184876829095a9182cbac67ae5 (diff)
downloadgnunet-214c0be64317f667bc79bcc604b8d0c87a33bab6.tar.gz
gnunet-214c0be64317f667bc79bcc604b8d0c87a33bab6.zip
-cleaning up TCP logging
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r--src/transport/plugin_transport_tcp.c300
1 files changed, 148 insertions, 152 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index 30ed32068..8ef73d182 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -39,6 +39,7 @@
39#include "gnunet_transport_plugin.h" 39#include "gnunet_transport_plugin.h"
40#include "transport.h" 40#include "transport.h"
41 41
42#define LOG(kind,...) GNUNET_log_from (kind, "transport-tcp",__VA_ARGS__)
42 43
43/** 44/**
44 * How long until we give up on establishing an NAT connection? 45 * How long until we give up on establishing an NAT connection?
@@ -410,9 +411,9 @@ static void inc_sessions (struct Plugin *plugin, struct Session *session, int li
410 sessions ++; 411 sessions ++;
411 unsigned int size = GNUNET_CONTAINER_multihashmap_size(plugin->sessionmap); 412 unsigned int size = GNUNET_CONTAINER_multihashmap_size(plugin->sessionmap);
412 if (sessions != size) 413 if (sessions != size)
413 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", "Inconsistent sessions %u <-> session map size: %u\n", 414 LOG (GNUNET_ERROR_TYPE_DEBUG, "Inconsistent sessions %u <-> session map size: %u\n",
414 sessions, size); 415 sessions, size);
415 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", "%4i Session increased to %u (session map size: %u): `%s' `%s'\n", 416 LOG (GNUNET_ERROR_TYPE_DEBUG, "%4i Session increased to %u (session map size: %u): `%s' `%s'\n",
416 line, 417 line,
417 sessions, 418 sessions,
418 size, 419 size,
@@ -426,9 +427,9 @@ static void dec_sessions (struct Plugin *plugin, struct Session *session, int li
426 unsigned int size = GNUNET_CONTAINER_multihashmap_size(plugin->sessionmap); 427 unsigned int size = GNUNET_CONTAINER_multihashmap_size(plugin->sessionmap);
427 sessions --; 428 sessions --;
428 if (sessions != size) 429 if (sessions != size)
429 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", "Inconsistent sessions %u <-> session map size: %u\n", 430 LOG (GNUNET_ERROR_TYPE_DEBUG, "Inconsistent sessions %u <-> session map size: %u\n",
430 sessions, size); 431 sessions, size);
431 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", "%4i Session decreased to %u (session map size: %u): `%s' `%s'\n", 432 LOG (GNUNET_ERROR_TYPE_DEBUG, "%4i Session decreased to %u (session map size: %u): `%s' `%s'\n",
432 line, 433 line,
433 sessions, 434 sessions,
434 size, 435 size,
@@ -457,8 +458,8 @@ plugin_tcp_access_check (void *cls,
457{ 458{
458 struct Plugin *plugin = cls; 459 struct Plugin *plugin = cls;
459 460
460 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 461 LOG (GNUNET_ERROR_TYPE_DEBUG,
461 "Accepting new incoming TCP connection\n"); 462 "Accepting new incoming TCP connection\n");
462 if (0 == plugin->max_connections) 463 if (0 == plugin->max_connections)
463 return GNUNET_NO; 464 return GNUNET_NO;
464 plugin->max_connections--; 465 plugin->max_connections--;
@@ -485,9 +486,9 @@ tcp_nat_port_map_callback (void *cls, int add_remove,
485 void *arg; 486 void *arg;
486 size_t args; 487 size_t args;
487 488
488 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 489 LOG (GNUNET_ERROR_TYPE_DEBUG,
489 "NPMC called with %d for address `%s'\n", add_remove, 490 "NPMC called with %d for address `%s'\n", add_remove,
490 GNUNET_a2s (addr, addrlen)); 491 GNUNET_a2s (addr, addrlen));
491 /* convert 'addr' to our internal format */ 492 /* convert 'addr' to our internal format */
492 switch (addr->sa_family) 493 switch (addr->sa_family)
493 { 494 {
@@ -557,9 +558,9 @@ tcp_address_to_string (void *cls, const void *addr, size_t addrlen)
557 } 558 }
558 else 559 else
559 { 560 {
560 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp", 561 LOG (GNUNET_ERROR_TYPE_ERROR,
561 _("Unexpected address length: %u bytes\n"), 562 _("Unexpected address length: %u bytes\n"),
562 (unsigned int) addrlen); 563 (unsigned int) addrlen);
563 GNUNET_break (0); 564 GNUNET_break (0);
564 return NULL; 565 return NULL;
565 } 566 }
@@ -713,9 +714,9 @@ create_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *target,
713 else 714 else
714 GNUNET_assert (client == NULL); 715 GNUNET_assert (client == NULL);
715 716
716 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 717 LOG (GNUNET_ERROR_TYPE_DEBUG,
717 "Creating new session for peer `%4s'\n", 718 "Creating new session for peer `%4s'\n",
718 GNUNET_i2s (target)); 719 GNUNET_i2s (target));
719 ret = GNUNET_malloc (sizeof (struct Session)); 720 ret = GNUNET_malloc (sizeof (struct Session));
720 ret->last_activity = GNUNET_TIME_absolute_get (); 721 ret->last_activity = GNUNET_TIME_absolute_get ();
721 ret->plugin = plugin; 722 ret->plugin = plugin;
@@ -787,9 +788,9 @@ do_transmit (void *cls, size_t size, void *buf)
787 plugin = session->plugin; 788 plugin = session->plugin;
788 if (buf == NULL) 789 if (buf == NULL)
789 { 790 {
790 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 791 LOG (GNUNET_ERROR_TYPE_DEBUG,
791 "Timeout trying to transmit to peer `%4s', discarding message queue.\n", 792 "Timeout trying to transmit to peer `%4s', discarding message queue.\n",
792 GNUNET_i2s (&session->target)); 793 GNUNET_i2s (&session->target));
793 /* timeout; cancel all messages that have already expired */ 794 /* timeout; cancel all messages that have already expired */
794 hd = NULL; 795 hd = NULL;
795 tl = NULL; 796 tl = NULL;
@@ -800,9 +801,9 @@ do_transmit (void *cls, size_t size, void *buf)
800 { 801 {
801 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, 802 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
802 session->pending_messages_tail, pos); 803 session->pending_messages_tail, pos);
803 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 804 LOG (GNUNET_ERROR_TYPE_DEBUG,
804 "Failed to transmit %u byte message to `%4s'.\n", 805 "Failed to transmit %u byte message to `%4s'.\n",
805 pos->message_size, GNUNET_i2s (&session->target)); 806 pos->message_size, GNUNET_i2s (&session->target));
806 ret += pos->message_size; 807 ret += pos->message_size;
807 GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos); 808 GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos);
808 } 809 }
@@ -841,9 +842,9 @@ do_transmit (void *cls, size_t size, void *buf)
841 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, 842 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
842 session->pending_messages_tail, pos); 843 session->pending_messages_tail, pos);
843 GNUNET_assert (size >= pos->message_size); 844 GNUNET_assert (size >= pos->message_size);
844 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 845 LOG (GNUNET_ERROR_TYPE_DEBUG,
845 "Transmitting message of type %u\n", 846 "Transmitting message of type %u\n",
846 ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type)); 847 ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type));
847 /* FIXME: this memcpy can be up to 7% of our total runtime */ 848 /* FIXME: this memcpy can be up to 7% of our total runtime */
848 memcpy (cbuf, pos->msg, pos->message_size); 849 memcpy (cbuf, pos->msg, pos->message_size);
849 cbuf += pos->message_size; 850 cbuf += pos->message_size;
@@ -868,7 +869,7 @@ do_transmit (void *cls, size_t size, void *buf)
868 } 869 }
869 GNUNET_assert (hd == NULL); 870 GNUNET_assert (hd == NULL);
870 GNUNET_assert (tl == NULL); 871 GNUNET_assert (tl == NULL);
871 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", "Transmitting %u bytes\n", 872 LOG (GNUNET_ERROR_TYPE_DEBUG, "Transmitting %u bytes\n",
872 ret); 873 ret);
873 GNUNET_STATISTICS_update (plugin->env->stats, 874 GNUNET_STATISTICS_update (plugin->env->stats,
874 gettext_noop ("# bytes currently in TCP buffers"), 875 gettext_noop ("# bytes currently in TCP buffers"),
@@ -918,11 +919,10 @@ disconnect_session (struct Session *session)
918 struct PendingMessage *pm; 919 struct PendingMessage *pm;
919 struct Plugin * plugin = session->plugin; 920 struct Plugin * plugin = session->plugin;
920 921
921 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 922 LOG (GNUNET_ERROR_TYPE_DEBUG,
922 "Disconnecting session %p for peer `%s' address `%s'\n", 923 "Disconnecting session of peer `%s' address `%s'\n",
923 session, 924 GNUNET_i2s (&session->target),
924 GNUNET_i2s (&session->target), 925 tcp_address_to_string(NULL, session->addr, session->addrlen));
925 tcp_address_to_string(NULL, session->addr, session->addrlen));
926 926
927 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(plugin->sessionmap, &session->target.hashPubKey, session)) 927 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(plugin->sessionmap, &session->target.hashPubKey, session))
928 { 928 {
@@ -950,11 +950,11 @@ disconnect_session (struct Session *session)
950 950
951 while (NULL != (pm = session->pending_messages_head)) 951 while (NULL != (pm = session->pending_messages_head))
952 { 952 {
953 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 953 LOG (GNUNET_ERROR_TYPE_DEBUG,
954 pm->transmit_cont != 954 pm->transmit_cont !=
955 NULL ? "Could not deliver message to `%4s'.\n" : 955 NULL ? "Could not deliver message to `%4s'.\n" :
956 "Could not deliver message to `%4s', notifying.\n", 956 "Could not deliver message to `%4s', notifying.\n",
957 GNUNET_i2s (&session->target)); 957 GNUNET_i2s (&session->target));
958 GNUNET_STATISTICS_update (session->plugin->env->stats, 958 GNUNET_STATISTICS_update (session->plugin->env->stats,
959 gettext_noop ("# bytes currently in TCP buffers"), 959 gettext_noop ("# bytes currently in TCP buffers"),
960 -(int64_t) pm->message_size, GNUNET_NO); 960 -(int64_t) pm->message_size, GNUNET_NO);
@@ -1038,10 +1038,9 @@ tcp_plugin_send (void *cls,
1038 pm->transmit_cont = cont; 1038 pm->transmit_cont = cont;
1039 pm->transmit_cont_cls = cont_cls; 1039 pm->transmit_cont_cls = cont_cls;
1040 1040
1041 1041 LOG (GNUNET_ERROR_TYPE_DEBUG,
1042 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 1042 "Asked to transmit %u bytes to `%s', added message to list.\n",
1043 "Asked to transmit %u bytes to `%s', added message to list.\n", 1043 msgbuf_size, GNUNET_i2s (&session->target));
1044 msgbuf_size, GNUNET_i2s (&session->target));
1045 1044
1046 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains_value(plugin->sessionmap, &session->target.hashPubKey, session)) 1045 if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains_value(plugin->sessionmap, &session->target.hashPubKey, session))
1047 { 1046 {
@@ -1062,9 +1061,9 @@ tcp_plugin_send (void *cls,
1062 } 1061 }
1063 else if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains_value(plugin->nat_wait_conns, &session->target.hashPubKey, session)) 1062 else if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains_value(plugin->nat_wait_conns, &session->target.hashPubKey, session))
1064 { 1063 {
1065 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 1064 LOG (GNUNET_ERROR_TYPE_DEBUG,
1066 "This NAT WAIT session for peer `%s' is not yet ready!\n", 1065 "This NAT WAIT session for peer `%s' is not yet ready!\n",
1067 GNUNET_i2s (&session->target)); 1066 GNUNET_i2s (&session->target));
1068 1067
1069 GNUNET_STATISTICS_update (plugin->env->stats, 1068 GNUNET_STATISTICS_update (plugin->env->stats,
1070 gettext_noop ("# bytes currently in TCP buffers"), 1069 gettext_noop ("# bytes currently in TCP buffers"),
@@ -1102,12 +1101,12 @@ session_lookup_it (void *cls,
1102#if 0 1101#if 0
1103 char * a1 = strdup (tcp_address_to_string(NULL, session->addr, session->addrlen)); 1102 char * a1 = strdup (tcp_address_to_string(NULL, session->addr, session->addrlen));
1104 char * a2 = strdup (tcp_address_to_string(NULL, si_ctx->addr, si_ctx->addrlen)); 1103 char * a2 = strdup (tcp_address_to_string(NULL, si_ctx->addr, si_ctx->addrlen));
1105 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp", 1104 LOG (GNUNET_ERROR_TYPE_DEBUG,
1106 "Comparing: %s %u <-> %s %u\n", 1105 "Comparing: %s %u <-> %s %u\n",
1107 a1, 1106 a1,
1108 session->addrlen, 1107 session->addrlen,
1109 a2, 1108 a2,
1110 si_ctx->addrlen); 1109 si_ctx->addrlen);
1111 GNUNET_free (a1); 1110 GNUNET_free (a1);
1112 GNUNET_free (a2); 1111 GNUNET_free (a2);
1113#endif 1112#endif
@@ -1122,12 +1121,12 @@ session_lookup_it (void *cls,
1122#if 0 1121#if 0
1123 a1 = strdup (tcp_address_to_string(NULL, session->addr, session->addrlen)); 1122 a1 = strdup (tcp_address_to_string(NULL, session->addr, session->addrlen));
1124 a2 = strdup (tcp_address_to_string(NULL, si_ctx->addr, si_ctx->addrlen)); 1123 a2 = strdup (tcp_address_to_string(NULL, si_ctx->addr, si_ctx->addrlen));
1125 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp", 1124 LOG (GNUNET_ERROR_TYPE_DEBUG,
1126 "Comparing: %s %u <-> %s %u , OK!\n", 1125 "Comparing: %s %u <-> %s %u , OK!\n",
1127 a1, 1126 a1,
1128 session->addrlen, 1127 session->addrlen,
1129 a2, 1128 a2,
1130 si_ctx->addrlen); 1129 si_ctx->addrlen);
1131 GNUNET_free (a1); 1130 GNUNET_free (a1);
1132 GNUNET_free (a2); 1131 GNUNET_free (a2);
1133#endif 1132#endif
@@ -1145,9 +1144,9 @@ nat_connect_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1145{ 1144{
1146 struct Session *session = cls; 1145 struct Session *session = cls;
1147 1146
1148 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 1147 LOG (GNUNET_ERROR_TYPE_DEBUG,
1149 "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n", 1148 "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n",
1150 GNUNET_i2s (&session->target), tcp_address_to_string(NULL, session->addr, session->addrlen)); 1149 GNUNET_i2s (&session->target), tcp_address_to_string(NULL, session->addr, session->addrlen));
1151 disconnect_session (session); 1150 disconnect_session (session);
1152} 1151}
1153 1152
@@ -1182,10 +1181,10 @@ tcp_plugin_get_session (void *cls,
1182 GNUNET_assert (plugin != NULL); 1181 GNUNET_assert (plugin != NULL);
1183 GNUNET_assert (address != NULL); 1182 GNUNET_assert (address != NULL);
1184 addrlen = address->address_length; 1183 addrlen = address->address_length;
1185 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp", 1184 LOG (GNUNET_ERROR_TYPE_ERROR,
1186 "Trying to get session for `%s' address of peer `%s'\n", 1185 "Trying to get session for `%s' address of peer `%s'\n",
1187 tcp_address_to_string(NULL, address->address, address->address_length), 1186 tcp_address_to_string(NULL, address->address, address->address_length),
1188 GNUNET_i2s (&address->peer)); 1187 GNUNET_i2s (&address->peer));
1189 1188
1190 /* look for existing session */ 1189 /* look for existing session */
1191 if (GNUNET_YES == 1190 if (GNUNET_YES ==
@@ -1202,18 +1201,17 @@ tcp_plugin_get_session (void *cls,
1202 if (si_ctx.result != NULL) 1201 if (si_ctx.result != NULL)
1203 { 1202 {
1204 session = si_ctx.result; 1203 session = si_ctx.result;
1205 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 1204 LOG (GNUNET_ERROR_TYPE_DEBUG,
1206 "Found exisiting session for `%s' address `%s' session %p\n", 1205 "Found exisiting session for `%s' address `%s' session %p\n",
1207 GNUNET_i2s (&address->peer), 1206 GNUNET_i2s (&address->peer),
1208 tcp_address_to_string(NULL, address->address, address->address_length), 1207 tcp_address_to_string(NULL, address->address, address->address_length),
1209 session); 1208 session);
1210 return session; 1209 return session;
1211 } 1210 }
1212 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp", 1211 LOG (GNUNET_ERROR_TYPE_DEBUG,
1213 "Existing sessions did not match address `%s' or peer `%s'\n", 1212 "Existing sessions did not match address `%s' or peer `%s'\n",
1214 tcp_address_to_string(NULL, address->address, address->address_length), 1213 tcp_address_to_string(NULL, address->address, address->address_length),
1215 GNUNET_i2s (&address->peer)); 1214 GNUNET_i2s (&address->peer));
1216
1217 } 1215 }
1218 1216
1219 if (addrlen == sizeof (struct IPv6TcpAddress)) 1217 if (addrlen == sizeof (struct IPv6TcpAddress))
@@ -1252,8 +1250,8 @@ tcp_plugin_get_session (void *cls,
1252 } 1250 }
1253 else 1251 else
1254 { 1252 {
1255 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp", 1253 LOG (GNUNET_ERROR_TYPE_ERROR,
1256 _("Address of unexpected length: %u\n"), addrlen); 1254 _("Address of unexpected length: %u\n"), addrlen);
1257 GNUNET_break (0); 1255 GNUNET_break (0);
1258 return NULL; 1256 return NULL;
1259 } 1257 }
@@ -1286,8 +1284,8 @@ tcp_plugin_get_session (void *cls,
1286 GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns, 1284 GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns,
1287 &address->peer.hashPubKey))) 1285 &address->peer.hashPubKey)))
1288 { 1286 {
1289 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 1287 LOG (GNUNET_ERROR_TYPE_DEBUG,
1290 "Found valid IPv4 NAT address (creating session)!\n") ; 1288 "Found valid IPv4 NAT address (creating session)!\n") ;
1291 session = create_session (plugin, &address->peer, NULL, GNUNET_YES); 1289 session = create_session (plugin, &address->peer, NULL, GNUNET_YES);
1292 session->addrlen = 0; 1290 session->addrlen = 0;
1293 session->addr = NULL; 1291 session->addr = NULL;
@@ -1300,18 +1298,17 @@ tcp_plugin_get_session (void *cls,
1300 (plugin->nat_wait_conns, &address->peer.hashPubKey, session, 1298 (plugin->nat_wait_conns, &address->peer.hashPubKey, session,
1301 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) == GNUNET_OK); 1299 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) == GNUNET_OK);
1302 1300
1303 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 1301 LOG (GNUNET_ERROR_TYPE_DEBUG,
1304 "Created NAT WAIT connection to `%4s' at `%s'\n", 1302 "Created NAT WAIT connection to `%4s' at `%s'\n",
1305 GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs)); 1303 GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs));
1306 1304
1307 if (GNUNET_OK == GNUNET_NAT_run_client (plugin->nat, &a4)) 1305 if (GNUNET_OK == GNUNET_NAT_run_client (plugin->nat, &a4))
1308 return session; 1306 return session;
1309 else 1307 else
1310 { 1308 {
1311 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 1309 LOG (GNUNET_ERROR_TYPE_DEBUG,
1312 "Running NAT client for `%4s' at `%s' failed\n", 1310 "Running NAT client for `%4s' at `%s' failed\n",
1313 GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs)); 1311 GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs));
1314
1315 disconnect_session (session); 1312 disconnect_session (session);
1316 return NULL; 1313 return NULL;
1317 } 1314 }
@@ -1322,16 +1319,16 @@ tcp_plugin_get_session (void *cls,
1322 sa = GNUNET_CONNECTION_create_from_sockaddr (af, sb, sbs); 1319 sa = GNUNET_CONNECTION_create_from_sockaddr (af, sb, sbs);
1323 if (sa == NULL) 1320 if (sa == NULL)
1324 { 1321 {
1325 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 1322 LOG (GNUNET_ERROR_TYPE_DEBUG,
1326 "Failed to create connection to `%4s' at `%s'\n", 1323 "Failed to create connection to `%4s' at `%s'\n",
1327 GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs)); 1324 GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs));
1328 return NULL; 1325 return NULL;
1329 } 1326 }
1330 plugin->max_connections--; 1327 plugin->max_connections--;
1331 1328
1332 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp", 1329 LOG (GNUNET_ERROR_TYPE_DEBUG,
1333 "Asked to transmit to `%4s', creating fresh session using address `%s'.\n", 1330 "Asked to transmit to `%4s', creating fresh session using address `%s'.\n",
1334 GNUNET_i2s (&address->peer), GNUNET_a2s (sb, sbs)); 1331 GNUNET_i2s (&address->peer), GNUNET_a2s (sb, sbs));
1335 1332
1336 session = create_session (plugin, 1333 session = create_session (plugin,
1337 &address->peer, 1334 &address->peer,
@@ -1344,12 +1341,11 @@ tcp_plugin_get_session (void *cls,
1344 1341
1345 GNUNET_CONTAINER_multihashmap_put(plugin->sessionmap, &address->peer.hashPubKey, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1342 GNUNET_CONTAINER_multihashmap_put(plugin->sessionmap, &address->peer.hashPubKey, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1346 inc_sessions (plugin, session, __LINE__); 1343 inc_sessions (plugin, session, __LINE__);
1347 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 1344 LOG (GNUNET_ERROR_TYPE_DEBUG,
1348 "Creating new session for `%s' address `%s' session %p\n", 1345 "Creating new session for `%s' address `%s' session %p\n",
1349 GNUNET_i2s (&address->peer), 1346 GNUNET_i2s (&address->peer),
1350 tcp_address_to_string(NULL, address->address, address->address_length), 1347 tcp_address_to_string(NULL, address->address, address->address_length),
1351 session); 1348 session);
1352
1353 /* Send TCP Welcome */ 1349 /* Send TCP Welcome */
1354 process_pending_messages (session); 1350 process_pending_messages (session);
1355 1351
@@ -1393,8 +1389,8 @@ tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
1393{ 1389{
1394 struct Plugin *plugin = cls; 1390 struct Plugin *plugin = cls;
1395 1391
1396 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 1392 LOG (GNUNET_ERROR_TYPE_DEBUG,
1397 "Disconnecting peer `%4s'\n", GNUNET_i2s (target)); 1393 "Disconnecting peer `%4s'\n", GNUNET_i2s (target));
1398 GNUNET_CONTAINER_multihashmap_get_multiple (plugin->sessionmap, &target->hashPubKey, &session_disconnect_it, plugin); 1394 GNUNET_CONTAINER_multihashmap_get_multiple (plugin->sessionmap, &target->hashPubKey, &session_disconnect_it, plugin);
1399 GNUNET_CONTAINER_multihashmap_get_multiple (plugin->nat_wait_conns, &target->hashPubKey, &session_disconnect_it, plugin); 1395 GNUNET_CONTAINER_multihashmap_get_multiple (plugin->nat_wait_conns, &target->hashPubKey, &session_disconnect_it, plugin);
1400} 1396}
@@ -1628,7 +1624,7 @@ handle_tcp_nat_probe (void *cls, struct GNUNET_SERVER_Client *client,
1628 const struct sockaddr_in *s4; 1624 const struct sockaddr_in *s4;
1629 const struct sockaddr_in6 *s6; 1625 const struct sockaddr_in6 *s6;
1630 1626
1631 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", "received NAT probe\n"); 1627 LOG (GNUNET_ERROR_TYPE_DEBUG, "received NAT probe\n");
1632 1628
1633 /* We have received a TCP NAT probe, meaning we (hopefully) initiated 1629 /* We have received a TCP NAT probe, meaning we (hopefully) initiated
1634 * a connection to this peer by running gnunet-nat-client. This peer 1630 * a connection to this peer by running gnunet-nat-client. This peer
@@ -1659,13 +1655,13 @@ handle_tcp_nat_probe (void *cls, struct GNUNET_SERVER_Client *client,
1659 clientIdentity.hashPubKey); 1655 clientIdentity.hashPubKey);
1660 if (session == NULL) 1656 if (session == NULL)
1661 { 1657 {
1662 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 1658 LOG (GNUNET_ERROR_TYPE_DEBUG,
1663 "Did NOT find session for NAT probe!\n"); 1659 "Did NOT find session for NAT probe!\n");
1664 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1660 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1665 return; 1661 return;
1666 } 1662 }
1667 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 1663 LOG (GNUNET_ERROR_TYPE_DEBUG,
1668 "Found session for NAT probe!\n"); 1664 "Found session for NAT probe!\n");
1669 1665
1670 if (session->nat_connection_timeout != GNUNET_SCHEDULER_NO_TASK) 1666 if (session->nat_connection_timeout != GNUNET_SCHEDULER_NO_TASK)
1671 { 1667 {
@@ -1689,9 +1685,9 @@ handle_tcp_nat_probe (void *cls, struct GNUNET_SERVER_Client *client,
1689 session->client = client; 1685 session->client = client;
1690 session->last_activity = GNUNET_TIME_absolute_get (); 1686 session->last_activity = GNUNET_TIME_absolute_get ();
1691 session->inbound = GNUNET_NO; 1687 session->inbound = GNUNET_NO;
1692 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 1688 LOG (GNUNET_ERROR_TYPE_DEBUG,
1693 "Found address `%s' for incoming connection\n", 1689 "Found address `%s' for incoming connection\n",
1694 GNUNET_a2s (vaddr, alen)); 1690 GNUNET_a2s (vaddr, alen));
1695 switch (((const struct sockaddr *) vaddr)->sa_family) 1691 switch (((const struct sockaddr *) vaddr)->sa_family)
1696 { 1692 {
1697 case AF_INET: 1693 case AF_INET:
@@ -1712,9 +1708,8 @@ handle_tcp_nat_probe (void *cls, struct GNUNET_SERVER_Client *client,
1712 break; 1708 break;
1713 default: 1709 default:
1714 GNUNET_break_op (0); 1710 GNUNET_break_op (0);
1715 1711 LOG (GNUNET_ERROR_TYPE_DEBUG,
1716 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 1712 "Bad address for incoming connection!\n");
1717 "Bad address for incoming connection!\n");
1718 GNUNET_free (vaddr); 1713 GNUNET_free (vaddr);
1719 1714
1720 GNUNET_SERVER_client_drop (client); 1715 GNUNET_SERVER_client_drop (client);
@@ -1764,9 +1759,9 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client,
1764 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1759 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1765 return; 1760 return;
1766 } 1761 }
1767 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp", 1762 LOG (GNUNET_ERROR_TYPE_ERROR,
1768 "Received %s message from `%4s'\n", "WELCOME", 1763 "Received %s message from `%4s'\n", "WELCOME",
1769 GNUNET_i2s (&wm->clientIdentity)); 1764 GNUNET_i2s (&wm->clientIdentity));
1770 GNUNET_STATISTICS_update (plugin->env->stats, 1765 GNUNET_STATISTICS_update (plugin->env->stats,
1771 gettext_noop ("# TCP WELCOME messages received"), 1, 1766 gettext_noop ("# TCP WELCOME messages received"), 1,
1772 GNUNET_NO); 1767 GNUNET_NO);
@@ -1775,10 +1770,10 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client,
1775 { 1770 {
1776 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) 1771 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
1777 { 1772 {
1778 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 1773 LOG (GNUNET_ERROR_TYPE_DEBUG,
1779 "Found existing session %p for peer `%s'\n", 1774 "Found existing session %p for peer `%s'\n",
1780 session, 1775 session,
1781 GNUNET_a2s (vaddr, alen)); 1776 GNUNET_a2s (vaddr, alen));
1782 GNUNET_free (vaddr); 1777 GNUNET_free (vaddr);
1783 } 1778 }
1784 } 1779 }
@@ -1816,8 +1811,8 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client,
1816 } 1811 }
1817 else 1812 else
1818 { 1813 {
1819 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 1814 LOG (GNUNET_ERROR_TYPE_DEBUG,
1820 "Did not obtain TCP socket address for incoming connection\n"); 1815 "Did not obtain TCP socket address for incoming connection\n");
1821 } 1816 }
1822 GNUNET_CONTAINER_multihashmap_put(plugin->sessionmap, &wm->clientIdentity.hashPubKey, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1817 GNUNET_CONTAINER_multihashmap_put(plugin->sessionmap, &wm->clientIdentity.hashPubKey, session, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1823 inc_sessions (plugin, session, __LINE__); 1818 inc_sessions (plugin, session, __LINE__);
@@ -1899,8 +1894,9 @@ handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client,
1899 /* No inbound session found */ 1894 /* No inbound session found */
1900 void *vaddr; 1895 void *vaddr;
1901 size_t alen; 1896 size_t alen;
1897
1902 GNUNET_SERVER_client_get_address (client, &vaddr, &alen); 1898 GNUNET_SERVER_client_get_address (client, &vaddr, &alen);
1903 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp", 1899 LOG (GNUNET_ERROR_TYPE_ERROR,
1904 "Received unexpected %u bytes of type %u from `%s'\n", 1900 "Received unexpected %u bytes of type %u from `%s'\n",
1905 (unsigned int) ntohs (message->size), 1901 (unsigned int) ntohs (message->size),
1906 (unsigned int) ntohs (message->type), 1902 (unsigned int) ntohs (message->type),
@@ -1915,12 +1911,13 @@ handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client,
1915 /* Session is expecting WELCOME message */ 1911 /* Session is expecting WELCOME message */
1916 void *vaddr; 1912 void *vaddr;
1917 size_t alen; 1913 size_t alen;
1914
1918 GNUNET_SERVER_client_get_address (client, &vaddr, &alen); 1915 GNUNET_SERVER_client_get_address (client, &vaddr, &alen);
1919 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp", 1916 LOG (GNUNET_ERROR_TYPE_ERROR,
1920 "Received unexpected %u bytes of type %u from `%s'\n", 1917 "Received unexpected %u bytes of type %u from `%s'\n",
1921 (unsigned int) ntohs (message->size), 1918 (unsigned int) ntohs (message->size),
1922 (unsigned int) ntohs (message->type), 1919 (unsigned int) ntohs (message->type),
1923 GNUNET_a2s(vaddr, alen)); 1920 GNUNET_a2s(vaddr, alen));
1924 GNUNET_break_op (0); 1921 GNUNET_break_op (0);
1925 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1922 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1926 GNUNET_free_non_null(vaddr); 1923 GNUNET_free_non_null(vaddr);
@@ -1928,8 +1925,7 @@ handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client,
1928 } 1925 }
1929 1926
1930 session->last_activity = GNUNET_TIME_absolute_get (); 1927 session->last_activity = GNUNET_TIME_absolute_get ();
1931 1928 LOG (GNUNET_ERROR_TYPE_DEBUG,
1932 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp",
1933 "Passing %u bytes of type %u from `%4s' to transport service.\n", 1929 "Passing %u bytes of type %u from `%4s' to transport service.\n",
1934 (unsigned int) ntohs (message->size), 1930 (unsigned int) ntohs (message->size),
1935 (unsigned int) ntohs (message->type), 1931 (unsigned int) ntohs (message->type),
@@ -1959,10 +1955,10 @@ handle_tcp_data (void *cls, struct GNUNET_SERVER_Client *client,
1959 } 1955 }
1960 else 1956 else
1961 { 1957 {
1962 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 1958 LOG (GNUNET_ERROR_TYPE_DEBUG,
1963 "Throttling receiving from `%s' for %llu ms\n", 1959 "Throttling receiving from `%s' for %llu ms\n",
1964 GNUNET_i2s (&session->target), 1960 GNUNET_i2s (&session->target),
1965 (unsigned long long) delay.rel_value); 1961 (unsigned long long) delay.rel_value);
1966 GNUNET_SERVER_disable_receive_done_warning (client); 1962 GNUNET_SERVER_disable_receive_done_warning (client);
1967 session->receive_delay_task = 1963 session->receive_delay_task =
1968 GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session); 1964 GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session);
@@ -1989,14 +1985,14 @@ disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client)
1989 session = lookup_session_by_client (plugin, client); 1985 session = lookup_session_by_client (plugin, client);
1990 if (session == NULL) 1986 if (session == NULL)
1991 return; /* unknown, nothing to do */ 1987 return; /* unknown, nothing to do */
1992 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", 1988 LOG (GNUNET_ERROR_TYPE_DEBUG,
1993 "Destroying session of `%4s' with %s due to network-level disconnect.\n", 1989 "Destroying session of `%4s' with %s due to network-level disconnect.\n",
1994 GNUNET_i2s (&session->target), 1990 GNUNET_i2s (&session->target),
1995 (session->addr != 1991 (session->addr !=
1996 NULL) ? tcp_address_to_string (session->plugin, 1992 NULL) ? tcp_address_to_string (session->plugin,
1997 session->addr, 1993 session->addr,
1998 session->addrlen) : 1994 session->addrlen) :
1999 "*"); 1995 "*");
2000 GNUNET_STATISTICS_update (session->plugin->env->stats, 1996 GNUNET_STATISTICS_update (session->plugin->env->stats,
2001 gettext_noop 1997 gettext_noop
2002 ("# network-level TCP disconnect events"), 1, 1998 ("# network-level TCP disconnect events"), 1,
@@ -2148,10 +2144,10 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2148 "ADVERTISED-PORT", &aport)) && 2144 "ADVERTISED-PORT", &aport)) &&
2149 (aport > 65535))) 2145 (aport > 65535)))
2150 { 2146 {
2151 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp", 2147 LOG (GNUNET_ERROR_TYPE_ERROR,
2152 _ 2148 _
2153 ("Require valid port number for service `%s' in configuration!\n"), 2149 ("Require valid port number for service `%s' in configuration!\n"),
2154 "transport-tcp"); 2150 "transport-tcp");
2155 return NULL; 2151 return NULL;
2156 } 2152 }
2157 if (aport == 0) 2153 if (aport == 0)
@@ -2163,8 +2159,8 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2163 service = GNUNET_SERVICE_start ("transport-tcp", env->cfg, GNUNET_SERVICE_OPTION_NONE); 2159 service = GNUNET_SERVICE_start ("transport-tcp", env->cfg, GNUNET_SERVICE_OPTION_NONE);
2164 if (service == NULL) 2160 if (service == NULL)
2165 { 2161 {
2166 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "tcp", 2162 LOG (GNUNET_ERROR_TYPE_WARNING,
2167 _("Failed to start service.\n")); 2163 _("Failed to start service.\n"));
2168 return NULL; 2164 return NULL;
2169 } 2165 }
2170 } 2166 }
@@ -2225,9 +2221,9 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2225 GNUNET_CONFIGURATION_get_value_time (env->cfg, "transport-tcp", 2221 GNUNET_CONFIGURATION_get_value_time (env->cfg, "transport-tcp",
2226 "TIMEOUT", &idle_timeout)) 2222 "TIMEOUT", &idle_timeout))
2227 { 2223 {
2228 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "tcp", 2224 LOG (GNUNET_ERROR_TYPE_ERROR,
2229 _("Failed to find option %s in section %s!\n"), 2225 _("Failed to find option %s in section %s!\n"),
2230 "TIMEOUT", "transport-tcp"); 2226 "TIMEOUT", "transport-tcp");
2231 if (plugin->nat != NULL) 2227 if (plugin->nat != NULL)
2232 GNUNET_NAT_unregister (plugin->nat); 2228 GNUNET_NAT_unregister (plugin->nat);
2233 GNUNET_free (plugin); 2229 GNUNET_free (plugin);
@@ -2248,14 +2244,14 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2248 GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin); 2244 GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin);
2249 plugin->nat_wait_conns = GNUNET_CONTAINER_multihashmap_create (16); 2245 plugin->nat_wait_conns = GNUNET_CONTAINER_multihashmap_create (16);
2250 if (bport != 0) 2246 if (bport != 0)
2251 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "tcp", 2247 LOG (GNUNET_ERROR_TYPE_INFO,
2252 _("TCP transport listening on port %llu\n"), bport); 2248 _("TCP transport listening on port %llu\n"), bport);
2253 else 2249 else
2254 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "tcp", 2250 LOG (GNUNET_ERROR_TYPE_INFO,
2255 _ 2251 _
2256 ("TCP transport not listening on any port (client only)\n")); 2252 ("TCP transport not listening on any port (client only)\n"));
2257 if (aport != bport) 2253 if (aport != bport)
2258 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "tcp", 2254 LOG (GNUNET_ERROR_TYPE_INFO,
2259 _ 2255 _
2260 ("TCP transport advertises itself as being on port %llu\n"), 2256 ("TCP transport advertises itself as being on port %llu\n"),
2261 aport); 2257 aport);
@@ -2282,7 +2278,7 @@ libgnunet_plugin_transport_tcp_done (void *cls)
2282 GNUNET_free (api); 2278 GNUNET_free (api);
2283 return NULL; 2279 return NULL;
2284 } 2280 }
2285 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", "Shutting down TCP plugin\n"); 2281 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down TCP plugin\n");
2286 2282
2287 /* Removing leftover sessions */ 2283 /* Removing leftover sessions */
2288 GNUNET_CONTAINER_multihashmap_iterate(plugin->sessionmap, &session_disconnect_it, NULL); 2284 GNUNET_CONTAINER_multihashmap_iterate(plugin->sessionmap, &session_disconnect_it, NULL);