diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-06-23 19:03:23 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-06-23 19:03:23 +0000 |
commit | cb0dcdd39476f0d8d8b599a8b8673c8b7b10fe32 (patch) | |
tree | 42eec6dd8b0d297537c553239f91d1655a332e56 /src/transport/plugin_transport_tcp.c | |
parent | 889216c8f47d57a49a7eadd876c837a5df90c8f0 (diff) | |
download | gnunet-cb0dcdd39476f0d8d8b599a8b8673c8b7b10fe32.tar.gz gnunet-cb0dcdd39476f0d8d8b599a8b8673c8b7b10fe32.zip |
-code cleanup, doxygen
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 331 |
1 files changed, 145 insertions, 186 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 1175e442c..31d85966e 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -39,8 +39,6 @@ | |||
39 | 39 | ||
40 | #define PLUGIN_NAME "tcp" | 40 | #define PLUGIN_NAME "tcp" |
41 | 41 | ||
42 | #define EXTRA_CHECKS ALLOW_EXTRA_CHECKS | ||
43 | |||
44 | /** | 42 | /** |
45 | * How long until we give up on establishing an NAT connection? | 43 | * How long until we give up on establishing an NAT connection? |
46 | * Must be > 4 RTT | 44 | * Must be > 4 RTT |
@@ -287,6 +285,12 @@ struct Session | |||
287 | struct GNUNET_TIME_Absolute timeout; | 285 | struct GNUNET_TIME_Absolute timeout; |
288 | 286 | ||
289 | /** | 287 | /** |
288 | * When will we continue to read from the socket? | ||
289 | * (used to enforce inbound quota). | ||
290 | */ | ||
291 | struct GNUNET_TIME_Absolute receive_delay; | ||
292 | |||
293 | /** | ||
290 | * Last activity on this connection. Used to select preferred | 294 | * Last activity on this connection. Used to select preferred |
291 | * connection. | 295 | * connection. |
292 | */ | 296 | */ |
@@ -445,9 +449,8 @@ notify_session_monitor (struct Plugin *plugin, | |||
445 | info.is_inbound = GNUNET_SYSERR; /* hard to say */ | 449 | info.is_inbound = GNUNET_SYSERR; /* hard to say */ |
446 | info.num_msg_pending = session->msgs_in_queue; | 450 | info.num_msg_pending = session->msgs_in_queue; |
447 | info.num_bytes_pending = session->bytes_in_queue; | 451 | info.num_bytes_pending = session->bytes_in_queue; |
448 | /* info.receive_delay remains zero as this is not supported by UDP | 452 | if (GNUNET_SCHEDULER_NO_TASK != session->receive_delay_task) |
449 | (cannot selectively not receive from 'some' peer while continuing | 453 | info.receive_delay = session->receive_delay; |
450 | to receive from others) */ | ||
451 | info.session_timeout = session->timeout; | 454 | info.session_timeout = session->timeout; |
452 | info.address = session->address; | 455 | info.address = session->address; |
453 | plugin->sic (plugin->sic_cls, | 456 | plugin->sic (plugin->sic_cls, |
@@ -468,9 +471,9 @@ notify_session_monitor (struct Plugin *plugin, | |||
468 | * @return string representing the same address | 471 | * @return string representing the same address |
469 | */ | 472 | */ |
470 | static const char * | 473 | static const char * |
471 | tcp_address_to_string (void *cls, | 474 | tcp_plugin_address_to_string (void *cls, |
472 | const void *addr, | 475 | const void *addr, |
473 | size_t addrlen); | 476 | size_t addrlen); |
474 | 477 | ||
475 | 478 | ||
476 | /** | 479 | /** |
@@ -576,7 +579,7 @@ tcp_nat_port_map_callback (void *cls, | |||
576 | * @return string representing the same address | 579 | * @return string representing the same address |
577 | */ | 580 | */ |
578 | static const char * | 581 | static const char * |
579 | tcp_address_to_string (void *cls, | 582 | tcp_plugin_address_to_string (void *cls, |
580 | const void *addr, | 583 | const void *addr, |
581 | size_t addrlen) | 584 | size_t addrlen) |
582 | { | 585 | { |
@@ -612,7 +615,7 @@ tcp_address_to_string (void *cls, | |||
612 | default: | 615 | default: |
613 | LOG (GNUNET_ERROR_TYPE_WARNING, | 616 | LOG (GNUNET_ERROR_TYPE_WARNING, |
614 | _("Unexpected address length: %u bytes\n"), | 617 | _("Unexpected address length: %u bytes\n"), |
615 | (unsigned int ) addrlen); | 618 | (unsigned int) addrlen); |
616 | return NULL ; | 619 | return NULL ; |
617 | } | 620 | } |
618 | if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN)) | 621 | if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN)) |
@@ -644,11 +647,11 @@ tcp_address_to_string (void *cls, | |||
644 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 647 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
645 | */ | 648 | */ |
646 | static int | 649 | static int |
647 | tcp_string_to_address (void *cls, | 650 | tcp_plugin_string_to_address (void *cls, |
648 | const char *addr, | 651 | const char *addr, |
649 | uint16_t addrlen, | 652 | uint16_t addrlen, |
650 | void **buf, | 653 | void **buf, |
651 | size_t *added) | 654 | size_t *added) |
652 | { | 655 | { |
653 | struct sockaddr_storage socket_address; | 656 | struct sockaddr_storage socket_address; |
654 | char *address; | 657 | char *address; |
@@ -766,8 +769,8 @@ lookup_session_by_client (struct Plugin *plugin, | |||
766 | * @return #GNUNET_OK on success | 769 | * @return #GNUNET_OK on success |
767 | */ | 770 | */ |
768 | static int | 771 | static int |
769 | tcp_disconnect_session (void *cls, | 772 | tcp_plugin_disconnect_session (void *cls, |
770 | struct Session *session) | 773 | struct Session *session) |
771 | { | 774 | { |
772 | struct Plugin *plugin = cls; | 775 | struct Plugin *plugin = cls; |
773 | struct PendingMessage *pm; | 776 | struct PendingMessage *pm; |
@@ -775,7 +778,7 @@ tcp_disconnect_session (void *cls, | |||
775 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 778 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
776 | "Disconnecting session of peer `%s' address `%s'\n", | 779 | "Disconnecting session of peer `%s' address `%s'\n", |
777 | GNUNET_i2s (&session->target), | 780 | GNUNET_i2s (&session->target), |
778 | tcp_address_to_string (NULL, | 781 | tcp_plugin_address_to_string (NULL, |
779 | session->address->address, | 782 | session->address->address, |
780 | session->address->address_length)); | 783 | session->address->address_length)); |
781 | 784 | ||
@@ -860,7 +863,7 @@ tcp_disconnect_session (void *cls, | |||
860 | session, | 863 | session, |
861 | GNUNET_TRANSPORT_SS_UP); | 864 | GNUNET_TRANSPORT_SS_UP); |
862 | 865 | ||
863 | if (session->receive_delay_task != GNUNET_SCHEDULER_NO_TASK ) | 866 | if (session->receive_delay_task != GNUNET_SCHEDULER_NO_TASK) |
864 | { | 867 | { |
865 | GNUNET_SCHEDULER_cancel (session->receive_delay_task); | 868 | GNUNET_SCHEDULER_cancel (session->receive_delay_task); |
866 | if (NULL != session->client) | 869 | if (NULL != session->client) |
@@ -888,7 +891,7 @@ tcp_disconnect_session (void *cls, | |||
888 | * @return keepalive factor | 891 | * @return keepalive factor |
889 | */ | 892 | */ |
890 | static unsigned int | 893 | static unsigned int |
891 | tcp_query_keepalive_factor (void *cls) | 894 | tcp_plugin_query_keepalive_factor (void *cls) |
892 | { | 895 | { |
893 | return 3; | 896 | return 3; |
894 | } | 897 | } |
@@ -921,13 +924,13 @@ session_timeout (void *cls, | |||
921 | s); | 924 | s); |
922 | return; | 925 | return; |
923 | } | 926 | } |
924 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 927 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
925 | "Session %p was idle for %s, disconnecting\n", | 928 | "Session %p was idle for %s, disconnecting\n", |
926 | s, | 929 | s, |
927 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 930 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
928 | GNUNET_YES)); | 931 | GNUNET_YES)); |
929 | /* call session destroy function */ | 932 | /* call session destroy function */ |
930 | tcp_disconnect_session (s->plugin, s); | 933 | tcp_plugin_disconnect_session (s->plugin, s); |
931 | } | 934 | } |
932 | 935 | ||
933 | 936 | ||
@@ -966,9 +969,9 @@ create_session (struct Plugin *plugin, | |||
966 | struct WelcomeMessage welcome; | 969 | struct WelcomeMessage welcome; |
967 | 970 | ||
968 | if (GNUNET_YES != is_nat) | 971 | if (GNUNET_YES != is_nat) |
969 | GNUNET_assert(NULL != client); | 972 | GNUNET_assert (NULL != client); |
970 | else | 973 | else |
971 | GNUNET_assert(NULL == client); | 974 | GNUNET_assert (NULL == client); |
972 | 975 | ||
973 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 976 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
974 | "Creating new session for peer `%4s'\n", | 977 | "Creating new session for peer `%4s'\n", |
@@ -1139,7 +1142,7 @@ do_transmit (void *cls, size_t size, void *buf) | |||
1139 | GNUNET_assert(size >= pos->message_size); | 1142 | GNUNET_assert(size >= pos->message_size); |
1140 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1143 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1141 | "Transmitting message of type %u size %u\n", | 1144 | "Transmitting message of type %u size %u\n", |
1142 | ntohs (((struct GNUNET_MessageHeader * ) pos->msg)->type), | 1145 | ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type), |
1143 | pos->message_size); | 1146 | pos->message_size); |
1144 | /* FIXME: this memcpy can be up to 7% of our total runtime */ | 1147 | /* FIXME: this memcpy can be up to 7% of our total runtime */ |
1145 | memcpy (cbuf, pos->msg, pos->message_size); | 1148 | memcpy (cbuf, pos->msg, pos->message_size); |
@@ -1170,14 +1173,19 @@ do_transmit (void *cls, size_t size, void *buf) | |||
1170 | pos->message_size); /* FIXME: include TCP overhead */ | 1173 | pos->message_size); /* FIXME: include TCP overhead */ |
1171 | GNUNET_free(pos); | 1174 | GNUNET_free(pos); |
1172 | } | 1175 | } |
1173 | GNUNET_assert(hd == NULL); | 1176 | GNUNET_assert (NULL == hd); |
1174 | GNUNET_assert(tl == NULL); | 1177 | GNUNET_assert (NULL == tl); |
1175 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Transmitting %u bytes\n", ret); | 1178 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1179 | "Transmitting %u bytes\n", | ||
1180 | ret); | ||
1176 | GNUNET_STATISTICS_update (plugin->env->stats, | 1181 | GNUNET_STATISTICS_update (plugin->env->stats, |
1177 | gettext_noop ("# bytes currently in TCP buffers"), -(int64_t) ret, | 1182 | gettext_noop ("# bytes currently in TCP buffers"), |
1178 | GNUNET_NO); | 1183 | - (int64_t) ret, |
1184 | GNUNET_NO); | ||
1179 | GNUNET_STATISTICS_update (plugin->env->stats, | 1185 | GNUNET_STATISTICS_update (plugin->env->stats, |
1180 | gettext_noop ("# bytes transmitted via TCP"), ret, GNUNET_NO); | 1186 | gettext_noop ("# bytes transmitted via TCP"), |
1187 | ret, | ||
1188 | GNUNET_NO); | ||
1181 | return ret; | 1189 | return ret; |
1182 | } | 1190 | } |
1183 | 1191 | ||
@@ -1193,88 +1201,18 @@ process_pending_messages (struct Session *session) | |||
1193 | { | 1201 | { |
1194 | struct PendingMessage *pm; | 1202 | struct PendingMessage *pm; |
1195 | 1203 | ||
1196 | GNUNET_assert(NULL != session->client); | 1204 | GNUNET_assert (NULL != session->client); |
1197 | if (NULL != session->transmit_handle) | 1205 | if (NULL != session->transmit_handle) |
1198 | return; | 1206 | return; |
1199 | if (NULL == (pm = session->pending_messages_head)) | 1207 | if (NULL == (pm = session->pending_messages_head)) |
1200 | return; | 1208 | return; |
1201 | 1209 | ||
1202 | session->transmit_handle = GNUNET_SERVER_notify_transmit_ready ( | 1210 | session->transmit_handle = GNUNET_SERVER_notify_transmit_ready (session->client, |
1203 | session->client, pm->message_size, | 1211 | pm->message_size, |
1204 | GNUNET_TIME_absolute_get_remaining (pm->timeout), &do_transmit, session); | 1212 | GNUNET_TIME_absolute_get_remaining (pm->timeout), |
1205 | } | 1213 | &do_transmit, |
1206 | 1214 | session); | |
1207 | #if EXTRA_CHECKS | ||
1208 | /** | ||
1209 | * Closure for #session_it(). | ||
1210 | */ | ||
1211 | struct FindSessionContext | ||
1212 | { | ||
1213 | /** | ||
1214 | * Session we are looking for. | ||
1215 | */ | ||
1216 | struct Session *s; | ||
1217 | |||
1218 | /** | ||
1219 | * Set to #GNUNET_OK if we found the session. | ||
1220 | */ | ||
1221 | int res; | ||
1222 | }; | ||
1223 | |||
1224 | |||
1225 | /** | ||
1226 | * Function called to check if a session is in our maps. | ||
1227 | * | ||
1228 | * @param cls the `struct FindSessionContext` | ||
1229 | * @param key peer identity | ||
1230 | * @param value session in the map | ||
1231 | * @return #GNUNET_YES to continue looking, #GNUNET_NO if we found the session | ||
1232 | */ | ||
1233 | static int | ||
1234 | session_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) | ||
1235 | { | ||
1236 | struct FindSessionContext *res = cls; | ||
1237 | struct Session *session = value; | ||
1238 | |||
1239 | if (res->s == session) | ||
1240 | { | ||
1241 | res->res = GNUNET_OK; | ||
1242 | return GNUNET_NO; | ||
1243 | } | ||
1244 | return GNUNET_YES; | ||
1245 | } | ||
1246 | |||
1247 | |||
1248 | /** | ||
1249 | * Check that the given session is known to the plugin and | ||
1250 | * is in one of our maps. | ||
1251 | * | ||
1252 | * @param plugin the plugin to check against | ||
1253 | * @param session the session to check | ||
1254 | * @return #GNUNET_OK if all is well, #GNUNET_SYSERR if the session is invalid | ||
1255 | */ | ||
1256 | static int | ||
1257 | find_session (struct Plugin *plugin, struct Session *session) | ||
1258 | { | ||
1259 | struct FindSessionContext session_map_res; | ||
1260 | struct FindSessionContext nat_map_res; | ||
1261 | |||
1262 | session_map_res.s = session; | ||
1263 | session_map_res.res = GNUNET_SYSERR; | ||
1264 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, &session_it, | ||
1265 | &session_map_res); | ||
1266 | if (GNUNET_SYSERR != session_map_res.res) | ||
1267 | return GNUNET_OK; | ||
1268 | nat_map_res.s = session; | ||
1269 | nat_map_res.res = GNUNET_SYSERR; | ||
1270 | GNUNET_CONTAINER_multipeermap_iterate (plugin->nat_wait_conns, &session_it, | ||
1271 | &nat_map_res); | ||
1272 | if (GNUNET_SYSERR != nat_map_res.res) | ||
1273 | return GNUNET_OK; | ||
1274 | GNUNET_break(0); | ||
1275 | return GNUNET_SYSERR; | ||
1276 | } | 1215 | } |
1277 | #endif | ||
1278 | 1216 | ||
1279 | 1217 | ||
1280 | /** | 1218 | /** |
@@ -1317,14 +1255,6 @@ tcp_plugin_send (void *cls, | |||
1317 | struct Plugin * plugin = cls; | 1255 | struct Plugin * plugin = cls; |
1318 | struct PendingMessage *pm; | 1256 | struct PendingMessage *pm; |
1319 | 1257 | ||
1320 | #if EXTRA_CHECKS | ||
1321 | if (GNUNET_SYSERR == find_session (plugin, session)) | ||
1322 | { | ||
1323 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Trying to send with invalid session %p\n")); | ||
1324 | GNUNET_assert(0); | ||
1325 | return GNUNET_SYSERR; | ||
1326 | } | ||
1327 | #endif | ||
1328 | /* create new message entry */ | 1258 | /* create new message entry */ |
1329 | pm = GNUNET_malloc (sizeof (struct PendingMessage) + msgbuf_size); | 1259 | pm = GNUNET_malloc (sizeof (struct PendingMessage) + msgbuf_size); |
1330 | pm->msg = (const char *) &pm[1]; | 1260 | pm->msg = (const char *) &pm[1]; |
@@ -1459,23 +1389,32 @@ nat_connect_timeout (void *cls, | |||
1459 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1389 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1460 | "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n", | 1390 | "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n", |
1461 | GNUNET_i2s (&session->target), | 1391 | GNUNET_i2s (&session->target), |
1462 | tcp_address_to_string (NULL, session->address->address, session->address->address_length)); | 1392 | tcp_plugin_address_to_string (NULL, |
1463 | tcp_disconnect_session (session->plugin, session); | 1393 | session->address->address, |
1394 | session->address->address_length)); | ||
1395 | tcp_plugin_disconnect_session (session->plugin, | ||
1396 | session); | ||
1464 | } | 1397 | } |
1465 | 1398 | ||
1466 | 1399 | ||
1400 | /** | ||
1401 | * Function that will be called whenever the transport service wants to | ||
1402 | * notify the plugin that a session is still active and in use and | ||
1403 | * therefore the session timeout for this session has to be updated | ||
1404 | * | ||
1405 | * @param cls closure | ||
1406 | * @param peer which peer was the session for | ||
1407 | * @param session which session is being updated | ||
1408 | */ | ||
1467 | static void | 1409 | static void |
1468 | tcp_plugin_update_session_timeout (void *cls, | 1410 | tcp_plugin_update_session_timeout (void *cls, |
1469 | const struct GNUNET_PeerIdentity *peer, | 1411 | const struct GNUNET_PeerIdentity *peer, |
1470 | struct Session *session) | 1412 | struct Session *session) |
1471 | { | 1413 | { |
1472 | struct Plugin *plugin = cls; | ||
1473 | |||
1474 | if (GNUNET_SYSERR == find_session (plugin, session)) | ||
1475 | return; | ||
1476 | reschedule_session_timeout (session); | 1414 | reschedule_session_timeout (session); |
1477 | } | 1415 | } |
1478 | 1416 | ||
1417 | |||
1479 | /** | 1418 | /** |
1480 | * Task to signal the server that we can continue | 1419 | * Task to signal the server that we can continue |
1481 | * receiving from the TCP client now. | 1420 | * receiving from the TCP client now. |
@@ -1484,7 +1423,8 @@ tcp_plugin_update_session_timeout (void *cls, | |||
1484 | * @param tc task context (unused) | 1423 | * @param tc task context (unused) |
1485 | */ | 1424 | */ |
1486 | static void | 1425 | static void |
1487 | delayed_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1426 | delayed_done (void *cls, |
1427 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1488 | { | 1428 | { |
1489 | struct Session *session = cls; | 1429 | struct Session *session = cls; |
1490 | 1430 | ||
@@ -1495,6 +1435,16 @@ delayed_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1495 | } | 1435 | } |
1496 | 1436 | ||
1497 | 1437 | ||
1438 | /** | ||
1439 | * Function that will be called whenever the transport service wants to | ||
1440 | * notify the plugin that the inbound quota changed and that the plugin | ||
1441 | * should update it's delay for the next receive value | ||
1442 | * | ||
1443 | * @param cls closure | ||
1444 | * @param peer which peer was the session for | ||
1445 | * @param session which session is being updated | ||
1446 | * @param delay new delay to use for receiving | ||
1447 | */ | ||
1498 | static void | 1448 | static void |
1499 | tcp_plugin_update_inbound_delay (void *cls, | 1449 | tcp_plugin_update_inbound_delay (void *cls, |
1500 | const struct GNUNET_PeerIdentity *peer, | 1450 | const struct GNUNET_PeerIdentity *peer, |
@@ -1503,13 +1453,15 @@ tcp_plugin_update_inbound_delay (void *cls, | |||
1503 | { | 1453 | { |
1504 | if (GNUNET_SCHEDULER_NO_TASK == session->receive_delay_task) | 1454 | if (GNUNET_SCHEDULER_NO_TASK == session->receive_delay_task) |
1505 | return; | 1455 | return; |
1506 | 1456 | LOG (GNUNET_ERROR_TYPE_DEBUG, | |
1507 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1457 | "New inbound delay %s\n", |
1508 | "New inbound delay %llu us\n",delay.rel_value_us); | 1458 | GNUNET_STRINGS_relative_time_to_string (delay, |
1509 | 1459 | GNUNET_NO)); | |
1460 | session->receive_delay = GNUNET_TIME_relative_to_absolute (delay); | ||
1510 | GNUNET_SCHEDULER_cancel (session->receive_delay_task); | 1461 | GNUNET_SCHEDULER_cancel (session->receive_delay_task); |
1511 | session->receive_delay_task = GNUNET_SCHEDULER_add_delayed (delay, | 1462 | session->receive_delay_task = GNUNET_SCHEDULER_add_delayed (delay, |
1512 | &delayed_done, session); | 1463 | &delayed_done, |
1464 | session); | ||
1513 | } | 1465 | } |
1514 | 1466 | ||
1515 | 1467 | ||
@@ -1543,7 +1495,7 @@ tcp_plugin_get_session (void *cls, | |||
1543 | addrlen = address->address_length; | 1495 | addrlen = address->address_length; |
1544 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1496 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1545 | "Trying to get session for `%s' address of peer `%s'\n", | 1497 | "Trying to get session for `%s' address of peer `%s'\n", |
1546 | tcp_address_to_string(NULL, address->address, address->address_length), | 1498 | tcp_plugin_address_to_string(NULL, address->address, address->address_length), |
1547 | GNUNET_i2s (&address->peer)); | 1499 | GNUNET_i2s (&address->peer)); |
1548 | 1500 | ||
1549 | if (GNUNET_HELLO_address_check_option(address, GNUNET_HELLO_ADDRESS_INFO_INBOUND)) | 1501 | if (GNUNET_HELLO_address_check_option(address, GNUNET_HELLO_ADDRESS_INFO_INBOUND)) |
@@ -1563,19 +1515,19 @@ tcp_plugin_get_session (void *cls, | |||
1563 | 1515 | ||
1564 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, | 1516 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, |
1565 | &address->peer, &session_lookup_it, &si_ctx); | 1517 | &address->peer, &session_lookup_it, &si_ctx); |
1566 | if (si_ctx.result != NULL ) | 1518 | if (si_ctx.result != NULL) |
1567 | { | 1519 | { |
1568 | session = si_ctx.result; | 1520 | session = si_ctx.result; |
1569 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1521 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1570 | "Found existing session for `%s' address `%s' session %p\n", | 1522 | "Found existing session for `%s' address `%s' session %p\n", |
1571 | GNUNET_i2s (&address->peer), | 1523 | GNUNET_i2s (&address->peer), |
1572 | tcp_address_to_string(NULL, address->address, address->address_length), | 1524 | tcp_plugin_address_to_string(NULL, address->address, address->address_length), |
1573 | session); | 1525 | session); |
1574 | return session; | 1526 | return session; |
1575 | } | 1527 | } |
1576 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1528 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1577 | "Existing sessions did not match address `%s' or peer `%s'\n", | 1529 | "Existing sessions did not match address `%s' or peer `%s'\n", |
1578 | tcp_address_to_string(NULL, address->address, address->address_length), | 1530 | tcp_plugin_address_to_string(NULL, address->address, address->address_length), |
1579 | GNUNET_i2s (&address->peer)); | 1531 | GNUNET_i2s (&address->peer)); |
1580 | } | 1532 | } |
1581 | 1533 | ||
@@ -1670,9 +1622,11 @@ tcp_plugin_get_session (void *cls, | |||
1670 | { | 1622 | { |
1671 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1623 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1672 | "Running NAT client for `%4s' at `%s' failed\n", | 1624 | "Running NAT client for `%4s' at `%s' failed\n", |
1673 | GNUNET_i2s (&session->target), GNUNET_a2s (sb, sbs)); | 1625 | GNUNET_i2s (&session->target), |
1674 | tcp_disconnect_session (plugin, session); | 1626 | GNUNET_a2s (sb, sbs)); |
1675 | return NULL ; | 1627 | tcp_plugin_disconnect_session (plugin, |
1628 | session); | ||
1629 | return NULL; | ||
1676 | } | 1630 | } |
1677 | } | 1631 | } |
1678 | 1632 | ||
@@ -1705,7 +1659,7 @@ tcp_plugin_get_session (void *cls, | |||
1705 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1659 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1706 | "Creating new session for `%s' address `%s' session %p\n", | 1660 | "Creating new session for `%s' address `%s' session %p\n", |
1707 | GNUNET_i2s (&address->peer), | 1661 | GNUNET_i2s (&address->peer), |
1708 | tcp_address_to_string(NULL, address->address, address->address_length), | 1662 | tcp_plugin_address_to_string(NULL, address->address, address->address_length), |
1709 | session); | 1663 | session); |
1710 | /* Send TCP Welcome */ | 1664 | /* Send TCP Welcome */ |
1711 | process_pending_messages (session); | 1665 | process_pending_messages (session); |
@@ -1722,9 +1676,12 @@ session_disconnect_it (void *cls, | |||
1722 | struct Plugin *plugin = cls; | 1676 | struct Plugin *plugin = cls; |
1723 | struct Session *session = value; | 1677 | struct Session *session = value; |
1724 | 1678 | ||
1725 | GNUNET_STATISTICS_update (session->plugin->env->stats, gettext_noop | 1679 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
1726 | ("# transport-service disconnect requests for TCP"), 1, GNUNET_NO); | 1680 | gettext_noop ("# transport-service disconnect requests for TCP"), |
1727 | tcp_disconnect_session (plugin, session); | 1681 | 1, |
1682 | GNUNET_NO); | ||
1683 | tcp_plugin_disconnect_session (plugin, | ||
1684 | session); | ||
1728 | return GNUNET_YES; | 1685 | return GNUNET_YES; |
1729 | } | 1686 | } |
1730 | 1687 | ||
@@ -2104,7 +2061,7 @@ handle_tcp_nat_probe (void *cls, | |||
2104 | 2061 | ||
2105 | session = GNUNET_CONTAINER_multipeermap_get (plugin->nat_wait_conns, | 2062 | session = GNUNET_CONTAINER_multipeermap_get (plugin->nat_wait_conns, |
2106 | &tcp_nat_probe->clientIdentity); | 2063 | &tcp_nat_probe->clientIdentity); |
2107 | if (session == NULL ) | 2064 | if (session == NULL) |
2108 | { | 2065 | { |
2109 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Did NOT find session for NAT probe!\n"); | 2066 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Did NOT find session for NAT probe!\n"); |
2110 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2067 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -2112,7 +2069,7 @@ handle_tcp_nat_probe (void *cls, | |||
2112 | } | 2069 | } |
2113 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Found session for NAT probe!\n"); | 2070 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Found session for NAT probe!\n"); |
2114 | 2071 | ||
2115 | if (session->nat_connection_timeout != GNUNET_SCHEDULER_NO_TASK ) | 2072 | if (session->nat_connection_timeout != GNUNET_SCHEDULER_NO_TASK) |
2116 | { | 2073 | { |
2117 | GNUNET_SCHEDULER_cancel (session->nat_connection_timeout); | 2074 | GNUNET_SCHEDULER_cancel (session->nat_connection_timeout); |
2118 | session->nat_connection_timeout = GNUNET_SCHEDULER_NO_TASK; | 2075 | session->nat_connection_timeout = GNUNET_SCHEDULER_NO_TASK; |
@@ -2122,7 +2079,8 @@ handle_tcp_nat_probe (void *cls, | |||
2122 | { | 2079 | { |
2123 | GNUNET_break(0); | 2080 | GNUNET_break(0); |
2124 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2081 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2125 | tcp_disconnect_session (plugin, session); | 2082 | tcp_plugin_disconnect_session (plugin, |
2083 | session); | ||
2126 | return; | 2084 | return; |
2127 | } | 2085 | } |
2128 | GNUNET_assert( | 2086 | GNUNET_assert( |
@@ -2159,10 +2117,12 @@ handle_tcp_nat_probe (void *cls, | |||
2159 | break; | 2117 | break; |
2160 | default: | 2118 | default: |
2161 | GNUNET_break_op(0); | 2119 | GNUNET_break_op(0); |
2162 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Bad address for incoming connection!\n"); | 2120 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2121 | "Bad address for incoming connection!\n"); | ||
2163 | GNUNET_free(vaddr); | 2122 | GNUNET_free(vaddr); |
2164 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2123 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2165 | tcp_disconnect_session (plugin, session); | 2124 | tcp_plugin_disconnect_session (plugin, |
2125 | session); | ||
2166 | return; | 2126 | return; |
2167 | } | 2127 | } |
2168 | GNUNET_free(vaddr); | 2128 | GNUNET_free(vaddr); |
@@ -2277,7 +2237,7 @@ handle_tcp_welcome (void *cls, | |||
2277 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Creating new%s session %p for peer `%s' client %p \n", | 2237 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Creating new%s session %p for peer `%s' client %p \n", |
2278 | GNUNET_HELLO_address_check_option (session->address, | 2238 | GNUNET_HELLO_address_check_option (session->address, |
2279 | GNUNET_HELLO_ADDRESS_INFO_INBOUND) ? " inbound" : "", session, | 2239 | GNUNET_HELLO_ADDRESS_INFO_INBOUND) ? " inbound" : "", session, |
2280 | tcp_address_to_string(NULL, (void *) session->address->address, | 2240 | tcp_plugin_address_to_string(NULL, (void *) session->address->address, |
2281 | session->address->address_length), | 2241 | session->address->address_length), |
2282 | client); | 2242 | client); |
2283 | GNUNET_free(vaddr); | 2243 | GNUNET_free(vaddr); |
@@ -2350,8 +2310,8 @@ handle_tcp_data (void *cls, | |||
2350 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen); | 2310 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen); |
2351 | LOG(GNUNET_ERROR_TYPE_ERROR, | 2311 | LOG(GNUNET_ERROR_TYPE_ERROR, |
2352 | "Received unexpected %u bytes of type %u from `%s'\n", | 2312 | "Received unexpected %u bytes of type %u from `%s'\n", |
2353 | (unsigned int ) ntohs (message->size), | 2313 | (unsigned int) ntohs (message->size), |
2354 | (unsigned int ) ntohs (message->type), GNUNET_a2s (vaddr, alen)); | 2314 | (unsigned int) ntohs (message->type), GNUNET_a2s (vaddr, alen)); |
2355 | GNUNET_break_op(0); | 2315 | GNUNET_break_op(0); |
2356 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2316 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2357 | GNUNET_free_non_null(vaddr); | 2317 | GNUNET_free_non_null(vaddr); |
@@ -2366,8 +2326,8 @@ handle_tcp_data (void *cls, | |||
2366 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen); | 2326 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen); |
2367 | LOG(GNUNET_ERROR_TYPE_ERROR, | 2327 | LOG(GNUNET_ERROR_TYPE_ERROR, |
2368 | "Received unexpected %u bytes of type %u from `%s'\n", | 2328 | "Received unexpected %u bytes of type %u from `%s'\n", |
2369 | (unsigned int ) ntohs (message->size), | 2329 | (unsigned int) ntohs (message->size), |
2370 | (unsigned int ) ntohs (message->type), GNUNET_a2s (vaddr, alen)); | 2330 | (unsigned int) ntohs (message->type), GNUNET_a2s (vaddr, alen)); |
2371 | GNUNET_break_op(0); | 2331 | GNUNET_break_op(0); |
2372 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2332 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2373 | GNUNET_free_non_null(vaddr); | 2333 | GNUNET_free_non_null(vaddr); |
@@ -2377,8 +2337,8 @@ handle_tcp_data (void *cls, | |||
2377 | session->last_activity = GNUNET_TIME_absolute_get (); | 2337 | session->last_activity = GNUNET_TIME_absolute_get (); |
2378 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2338 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2379 | "Passing %u bytes of type %u from `%4s' to transport service.\n", | 2339 | "Passing %u bytes of type %u from `%4s' to transport service.\n", |
2380 | (unsigned int ) ntohs (message->size), | 2340 | (unsigned int) ntohs (message->size), |
2381 | (unsigned int ) ntohs (message->type), GNUNET_i2s (&session->target)); | 2341 | (unsigned int) ntohs (message->type), GNUNET_i2s (&session->target)); |
2382 | 2342 | ||
2383 | GNUNET_STATISTICS_update (plugin->env->stats, | 2343 | GNUNET_STATISTICS_update (plugin->env->stats, |
2384 | gettext_noop ("# bytes received via TCP"), ntohs (message->size), | 2344 | gettext_noop ("# bytes received via TCP"), ntohs (message->size), |
@@ -2427,7 +2387,8 @@ handle_tcp_data (void *cls, | |||
2427 | * @param client identification of the client | 2387 | * @param client identification of the client |
2428 | */ | 2388 | */ |
2429 | static void | 2389 | static void |
2430 | disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client) | 2390 | disconnect_notify (void *cls, |
2391 | struct GNUNET_SERVER_Client *client) | ||
2431 | { | 2392 | { |
2432 | struct Plugin *plugin = cls; | 2393 | struct Plugin *plugin = cls; |
2433 | struct Session *session; | 2394 | struct Session *session; |
@@ -2440,7 +2401,7 @@ disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client) | |||
2440 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2401 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2441 | "Destroying session of `%4s' with %s due to network-level disconnect.\n", | 2402 | "Destroying session of `%4s' with %s due to network-level disconnect.\n", |
2442 | GNUNET_i2s (&session->target), | 2403 | GNUNET_i2s (&session->target), |
2443 | tcp_address_to_string (session->plugin, session->address->address, | 2404 | tcp_plugin_address_to_string (session->plugin, session->address->address, |
2444 | session->address->address_length)); | 2405 | session->address->address_length)); |
2445 | 2406 | ||
2446 | if (plugin->cur_connections == plugin->max_connections) | 2407 | if (plugin->cur_connections == plugin->max_connections) |
@@ -2455,7 +2416,7 @@ disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client) | |||
2455 | ("# network-level TCP disconnect events"), | 2416 | ("# network-level TCP disconnect events"), |
2456 | 1, | 2417 | 1, |
2457 | GNUNET_NO); | 2418 | GNUNET_NO); |
2458 | tcp_disconnect_session (plugin, session); | 2419 | tcp_plugin_disconnect_session (plugin, session); |
2459 | } | 2420 | } |
2460 | 2421 | ||
2461 | 2422 | ||
@@ -2519,28 +2480,30 @@ try_connection_reversal (void *cls, | |||
2519 | * that wants to connect to us! Send a message to establish a connection. | 2480 | * that wants to connect to us! Send a message to establish a connection. |
2520 | */ | 2481 | */ |
2521 | sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen); | 2482 | sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen); |
2522 | if (sock == NULL ) | 2483 | if (sock == NULL) |
2523 | { | 2484 | { |
2524 | /* failed for some odd reason (out of sockets?); ignore attempt */ | 2485 | /* failed for some odd reason (out of sockets?); ignore attempt */ |
2525 | return; | 2486 | return; |
2526 | } | 2487 | } |
2527 | 2488 | ||
2528 | tcp_probe_ctx = GNUNET_new (struct TCPProbeContext); | 2489 | tcp_probe_ctx = GNUNET_new (struct TCPProbeContext); |
2529 | tcp_probe_ctx->message.header.size = htons ( | 2490 | tcp_probe_ctx->message.header.size |
2530 | sizeof(struct TCP_NAT_ProbeMessage)); | 2491 | = htons (sizeof (struct TCP_NAT_ProbeMessage)); |
2531 | tcp_probe_ctx->message.header.type = htons ( | 2492 | tcp_probe_ctx->message.header.type |
2532 | GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE); | 2493 | = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE); |
2533 | memcpy (&tcp_probe_ctx->message.clientIdentity, plugin->env->my_identity, | 2494 | tcp_probe_ctx->message.clientIdentity |
2534 | sizeof(struct GNUNET_PeerIdentity)); | 2495 | = *plugin->env->my_identity; |
2535 | tcp_probe_ctx->plugin = plugin; | 2496 | tcp_probe_ctx->plugin = plugin; |
2536 | tcp_probe_ctx->sock = sock; | 2497 | tcp_probe_ctx->sock = sock; |
2537 | GNUNET_CONTAINER_DLL_insert (plugin->probe_head, | 2498 | GNUNET_CONTAINER_DLL_insert (plugin->probe_head, |
2538 | plugin->probe_tail, | 2499 | plugin->probe_tail, |
2539 | tcp_probe_ctx); | 2500 | tcp_probe_ctx); |
2540 | tcp_probe_ctx->transmit_handle = GNUNET_CONNECTION_notify_transmit_ready ( | 2501 | tcp_probe_ctx->transmit_handle |
2541 | sock, ntohs (tcp_probe_ctx->message.header.size), | 2502 | = GNUNET_CONNECTION_notify_transmit_ready (sock, |
2542 | GNUNET_TIME_UNIT_FOREVER_REL, ¬ify_send_probe, tcp_probe_ctx); | 2503 | ntohs (tcp_probe_ctx->message.header.size), |
2543 | 2504 | GNUNET_TIME_UNIT_FOREVER_REL, | |
2505 | ¬ify_send_probe, | ||
2506 | tcp_probe_ctx); | ||
2544 | } | 2507 | } |
2545 | 2508 | ||
2546 | 2509 | ||
@@ -2552,15 +2515,9 @@ try_connection_reversal (void *cls, | |||
2552 | * @return the network type in HBO or #GNUNET_SYSERR | 2515 | * @return the network type in HBO or #GNUNET_SYSERR |
2553 | */ | 2516 | */ |
2554 | static enum GNUNET_ATS_Network_Type | 2517 | static enum GNUNET_ATS_Network_Type |
2555 | tcp_get_network (void *cls, | 2518 | tcp_plugin_get_network (void *cls, |
2556 | struct Session *session) | 2519 | struct Session *session) |
2557 | { | 2520 | { |
2558 | struct Plugin * plugin = cls; | ||
2559 | |||
2560 | GNUNET_assert (NULL != plugin); | ||
2561 | GNUNET_assert (NULL != session); | ||
2562 | if (GNUNET_SYSERR == find_session (plugin,session)) | ||
2563 | return GNUNET_ATS_NET_UNSPECIFIED; | ||
2564 | return session->ats_address_network_type; | 2521 | return session->ats_address_network_type; |
2565 | } | 2522 | } |
2566 | 2523 | ||
@@ -2624,8 +2581,8 @@ tcp_plugin_setup_monitor (void *cls, | |||
2624 | /** | 2581 | /** |
2625 | * Entry point for the plugin. | 2582 | * Entry point for the plugin. |
2626 | * | 2583 | * |
2627 | * @param cls closure, the 'struct GNUNET_TRANSPORT_PluginEnvironment*' | 2584 | * @param cls closure, the `struct GNUNET_TRANSPORT_PluginEnvironment *` |
2628 | * @return the 'struct GNUNET_TRANSPORT_PluginFunctions*' or NULL on error | 2585 | * @return the `struct GNUNET_TRANSPORT_PluginFunctions *` or NULL on error |
2629 | */ | 2586 | */ |
2630 | void * | 2587 | void * |
2631 | libgnunet_plugin_transport_tcp_init (void *cls) | 2588 | libgnunet_plugin_transport_tcp_init (void *cls) |
@@ -2660,8 +2617,8 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2660 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); | 2617 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
2661 | api->cls = NULL; | 2618 | api->cls = NULL; |
2662 | api->address_pretty_printer = &tcp_plugin_address_pretty_printer; | 2619 | api->address_pretty_printer = &tcp_plugin_address_pretty_printer; |
2663 | api->address_to_string = &tcp_address_to_string; | 2620 | api->address_to_string = &tcp_plugin_address_to_string; |
2664 | api->string_to_address = &tcp_string_to_address; | 2621 | api->string_to_address = &tcp_plugin_string_to_address; |
2665 | return api; | 2622 | return api; |
2666 | } | 2623 | } |
2667 | 2624 | ||
@@ -2748,14 +2705,14 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2748 | api->cls = plugin; | 2705 | api->cls = plugin; |
2749 | api->send = &tcp_plugin_send; | 2706 | api->send = &tcp_plugin_send; |
2750 | api->get_session = &tcp_plugin_get_session; | 2707 | api->get_session = &tcp_plugin_get_session; |
2751 | api->disconnect_session = &tcp_disconnect_session; | 2708 | api->disconnect_session = &tcp_plugin_disconnect_session; |
2752 | api->query_keepalive_factor = &tcp_query_keepalive_factor; | 2709 | api->query_keepalive_factor = &tcp_plugin_query_keepalive_factor; |
2753 | api->disconnect_peer = &tcp_plugin_disconnect; | 2710 | api->disconnect_peer = &tcp_plugin_disconnect; |
2754 | api->address_pretty_printer = &tcp_plugin_address_pretty_printer; | 2711 | api->address_pretty_printer = &tcp_plugin_address_pretty_printer; |
2755 | api->check_address = &tcp_plugin_check_address; | 2712 | api->check_address = &tcp_plugin_check_address; |
2756 | api->address_to_string = &tcp_address_to_string; | 2713 | api->address_to_string = &tcp_plugin_address_to_string; |
2757 | api->string_to_address = &tcp_string_to_address; | 2714 | api->string_to_address = &tcp_plugin_string_to_address; |
2758 | api->get_network = &tcp_get_network; | 2715 | api->get_network = &tcp_plugin_get_network; |
2759 | api->update_session_timeout = &tcp_plugin_update_session_timeout; | 2716 | api->update_session_timeout = &tcp_plugin_update_session_timeout; |
2760 | api->update_inbound_delay = &tcp_plugin_update_inbound_delay; | 2717 | api->update_inbound_delay = &tcp_plugin_update_inbound_delay; |
2761 | api->setup_monitor = &tcp_plugin_setup_monitor; | 2718 | api->setup_monitor = &tcp_plugin_setup_monitor; |
@@ -2810,7 +2767,9 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2810 | /* Initially set connections to 0 */ | 2767 | /* Initially set connections to 0 */ |
2811 | GNUNET_assert(NULL != plugin->env->stats); | 2768 | GNUNET_assert(NULL != plugin->env->stats); |
2812 | GNUNET_STATISTICS_set (plugin->env->stats, | 2769 | GNUNET_STATISTICS_set (plugin->env->stats, |
2813 | gettext_noop ("# TCP sessions active"), 0, GNUNET_NO); | 2770 | gettext_noop ("# TCP sessions active"), |
2771 | 0, | ||
2772 | GNUNET_NO); | ||
2814 | return api; | 2773 | return api; |
2815 | } | 2774 | } |
2816 | 2775 | ||