diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-12-22 00:38:42 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-12-22 00:38:42 +0000 |
commit | f466a1d88a3880670b18d79d54f609ab9f43dd07 (patch) | |
tree | 05ba57cd721dc3252633a2dc21fbf4e574ef8635 /src/transport/plugin_transport_tcp.c | |
parent | cda323e3494aff476386b5db3f80a3c9fb2347e5 (diff) | |
download | gnunet-f466a1d88a3880670b18d79d54f609ab9f43dd07.tar.gz gnunet-f466a1d88a3880670b18d79d54f609ab9f43dd07.zip |
-code hygene
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 126 |
1 files changed, 53 insertions, 73 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 04fac9cde..2ce9d9592 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -1129,8 +1129,8 @@ process_pending_messages (struct Session *session) | |||
1129 | { | 1129 | { |
1130 | struct PendingMessage *pm; | 1130 | struct PendingMessage *pm; |
1131 | 1131 | ||
1132 | GNUNET_assert (session->client != NULL); | 1132 | GNUNET_assert (NULL != session->client); |
1133 | if (session->transmit_handle != NULL) | 1133 | if (NULL != session->transmit_handle) |
1134 | return; | 1134 | return; |
1135 | if (NULL == (pm = session->pending_messages_head)) | 1135 | if (NULL == (pm = session->pending_messages_head)) |
1136 | return; | 1136 | return; |
@@ -1284,7 +1284,7 @@ tcp_plugin_send (void *cls, | |||
1284 | &session->target, | 1284 | &session->target, |
1285 | session)) | 1285 | session)) |
1286 | { | 1286 | { |
1287 | GNUNET_assert (session->client != NULL); | 1287 | GNUNET_assert (NULL != session->client); |
1288 | GNUNET_SERVER_client_set_timeout (session->client, | 1288 | GNUNET_SERVER_client_set_timeout (session->client, |
1289 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 1289 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
1290 | GNUNET_STATISTICS_update (plugin->env->stats, | 1290 | GNUNET_STATISTICS_update (plugin->env->stats, |
@@ -1298,7 +1298,10 @@ tcp_plugin_send (void *cls, | |||
1298 | process_pending_messages (session); | 1298 | process_pending_messages (session); |
1299 | return msgbuf_size; | 1299 | return msgbuf_size; |
1300 | } | 1300 | } |
1301 | else if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains_value(plugin->nat_wait_conns, &session->target, session)) | 1301 | else if (GNUNET_YES == |
1302 | GNUNET_CONTAINER_multipeermap_contains_value(plugin->nat_wait_conns, | ||
1303 | &session->target, | ||
1304 | session)) | ||
1302 | { | 1305 | { |
1303 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1306 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1304 | "This NAT WAIT session for peer `%s' is not yet ready!\n", | 1307 | "This NAT WAIT session for peer `%s' is not yet ready!\n", |
@@ -1317,7 +1320,11 @@ tcp_plugin_send (void *cls, | |||
1317 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1320 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1318 | "Invalid session %p\n", session); | 1321 | "Invalid session %p\n", session); |
1319 | if (NULL != cont) | 1322 | if (NULL != cont) |
1320 | cont (cont_cls, &session->target, GNUNET_SYSERR, pm->message_size, 0); | 1323 | cont (cont_cls, |
1324 | &session->target, | ||
1325 | GNUNET_SYSERR, | ||
1326 | pm->message_size, | ||
1327 | 0); | ||
1321 | GNUNET_break (0); | 1328 | GNUNET_break (0); |
1322 | GNUNET_free (pm); | 1329 | GNUNET_free (pm); |
1323 | return GNUNET_SYSERR; /* session does not exist here */ | 1330 | return GNUNET_SYSERR; /* session does not exist here */ |
@@ -1362,34 +1369,11 @@ session_lookup_it (void *cls, | |||
1362 | { | 1369 | { |
1363 | struct SessionItCtx * si_ctx = cls; | 1370 | struct SessionItCtx * si_ctx = cls; |
1364 | struct Session * session = value; | 1371 | struct Session * session = value; |
1365 | #if 0 | 1372 | |
1366 | char * a1 = strdup (tcp_address_to_string(NULL, session->addr, session->addrlen)); | ||
1367 | char * a2 = strdup (tcp_address_to_string(NULL, si_ctx->addr, si_ctx->addrlen)); | ||
1368 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1369 | "Comparing: %s %u <-> %s %u\n", | ||
1370 | a1, | ||
1371 | session->addrlen, | ||
1372 | a2, | ||
1373 | si_ctx->addrlen); | ||
1374 | GNUNET_free (a1); | ||
1375 | GNUNET_free (a2); | ||
1376 | #endif | ||
1377 | if (session->addrlen != si_ctx->addrlen) | 1373 | if (session->addrlen != si_ctx->addrlen) |
1378 | return GNUNET_YES; | 1374 | return GNUNET_YES; |
1379 | if (0 != memcmp (session->addr, si_ctx->addr, si_ctx->addrlen)) | 1375 | if (0 != memcmp (session->addr, si_ctx->addr, si_ctx->addrlen)) |
1380 | return GNUNET_YES; | 1376 | return GNUNET_YES; |
1381 | #if 0 | ||
1382 | a1 = strdup (tcp_address_to_string (NULL, session->addr, session->addrlen)); | ||
1383 | a2 = strdup (tcp_address_to_string (NULL, si_ctx->addr, si_ctx->addrlen)); | ||
1384 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1385 | "Comparing: %s %u <-> %s %u , OK!\n", | ||
1386 | a1, | ||
1387 | session->addrlen, | ||
1388 | a2, | ||
1389 | si_ctx->addrlen); | ||
1390 | GNUNET_free (a1); | ||
1391 | GNUNET_free (a2); | ||
1392 | #endif | ||
1393 | /* Found existing session */ | 1377 | /* Found existing session */ |
1394 | si_ctx->result = session; | 1378 | si_ctx->result = session; |
1395 | return GNUNET_NO; | 1379 | return GNUNET_NO; |
@@ -1418,15 +1402,16 @@ nat_connect_timeout (void *cls, | |||
1418 | session); | 1402 | session); |
1419 | } | 1403 | } |
1420 | 1404 | ||
1405 | |||
1421 | static void | 1406 | static void |
1422 | tcp_plugin_update_session_timeout (void *cls, | 1407 | tcp_plugin_update_session_timeout (void *cls, |
1423 | const struct GNUNET_PeerIdentity *peer, | 1408 | const struct GNUNET_PeerIdentity *peer, |
1424 | struct Session *session) | 1409 | struct Session *session) |
1425 | { | 1410 | { |
1426 | struct Plugin *plugin = cls; | 1411 | struct Plugin *plugin = cls; |
1412 | |||
1427 | if (GNUNET_SYSERR == find_session (plugin, session)) | 1413 | if (GNUNET_SYSERR == find_session (plugin, session)) |
1428 | return; | 1414 | return; |
1429 | |||
1430 | reschedule_session_timeout (session); | 1415 | reschedule_session_timeout (session); |
1431 | } | 1416 | } |
1432 | 1417 | ||
@@ -1606,7 +1591,7 @@ tcp_plugin_get_session (void *cls, | |||
1606 | /* create new outbound session */ | 1591 | /* create new outbound session */ |
1607 | GNUNET_assert (plugin->cur_connections <= plugin->max_connections); | 1592 | GNUNET_assert (plugin->cur_connections <= plugin->max_connections); |
1608 | sa = GNUNET_CONNECTION_create_from_sockaddr (af, sb, sbs); | 1593 | sa = GNUNET_CONNECTION_create_from_sockaddr (af, sb, sbs); |
1609 | if (sa == NULL) | 1594 | if (NULL == sa) |
1610 | { | 1595 | { |
1611 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1596 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1612 | "Failed to create connection to `%4s' at `%s'\n", | 1597 | "Failed to create connection to `%4s' at `%s'\n", |
@@ -1764,17 +1749,8 @@ static void | |||
1764 | ppc_cancel_task (void *cls, | 1749 | ppc_cancel_task (void *cls, |
1765 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 1750 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
1766 | { | 1751 | { |
1767 | int count = 0; | ||
1768 | struct PrettyPrinterContext *ppc = cls; | 1752 | struct PrettyPrinterContext *ppc = cls; |
1769 | struct PrettyPrinterContext *cur; | ||
1770 | |||
1771 | for (cur = ppc_dll_head; (NULL != cur); cur = cur->next) | ||
1772 | { | ||
1773 | if (cur != ppc) | ||
1774 | count++; | ||
1775 | } | ||
1776 | 1753 | ||
1777 | // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cancel request %p, %u pending\n", ppc, count); | ||
1778 | ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 1754 | ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
1779 | if (NULL != ppc->resolver_handle) | 1755 | if (NULL != ppc->resolver_handle) |
1780 | { | 1756 | { |
@@ -1798,40 +1774,40 @@ append_port (void *cls, const char *hostname) | |||
1798 | struct PrettyPrinterContext *ppc = cls; | 1774 | struct PrettyPrinterContext *ppc = cls; |
1799 | struct PrettyPrinterContext *cur; | 1775 | struct PrettyPrinterContext *cur; |
1800 | char *ret; | 1776 | char *ret; |
1801 | int count = 0; | ||
1802 | 1777 | ||
1803 | for (cur = ppc_dll_head; (NULL != cur); cur = cur->next) | 1778 | if (NULL == hostname) |
1804 | { | ||
1805 | if (cur != ppc) | ||
1806 | count++; | ||
1807 | } | ||
1808 | //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Callback request %p == %s, %u pending\n", ppc, hostname, count); | ||
1809 | if (hostname == NULL) | ||
1810 | { | 1779 | { |
1811 | ppc->asc (ppc->asc_cls, NULL); | 1780 | ppc->asc (ppc->asc_cls, NULL); |
1812 | GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, ppc); | 1781 | GNUNET_CONTAINER_DLL_remove (ppc_dll_head, ppc_dll_tail, ppc); |
1813 | GNUNET_SCHEDULER_cancel (ppc->timeout_task); | 1782 | GNUNET_SCHEDULER_cancel (ppc->timeout_task); |
1814 | ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 1783 | ppc->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
1815 | ppc->resolver_handle = NULL; | 1784 | ppc->resolver_handle = NULL; |
1816 | //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Done request %p, %u pending\n", ppc, count); | ||
1817 | GNUNET_free (ppc); | 1785 | GNUNET_free (ppc); |
1818 | return; | 1786 | return; |
1819 | } | 1787 | } |
1820 | for (cur = ppc_dll_head; (NULL != cur); cur = cur->next) | 1788 | for (cur = ppc_dll_head; (NULL != cur); cur = cur->next) |
1821 | { | 1789 | if (cur == ppc) |
1822 | if (cur == ppc) | 1790 | break; |
1823 | break; | ||
1824 | } | ||
1825 | if (NULL == cur) | 1791 | if (NULL == cur) |
1826 | { | 1792 | { |
1827 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Invalid callback for PPC %p \n", ppc); | 1793 | GNUNET_break (0); |
1828 | return; | 1794 | return; |
1829 | } | 1795 | } |
1830 | 1796 | ||
1831 | if (GNUNET_YES == ppc->ipv6) | 1797 | if (GNUNET_YES == ppc->ipv6) |
1832 | GNUNET_asprintf (&ret, "%s.%u.[%s]:%d", PLUGIN_NAME, ppc->options, hostname, ppc->port); | 1798 | GNUNET_asprintf (&ret, |
1799 | "%s.%u.[%s]:%d", | ||
1800 | PLUGIN_NAME, | ||
1801 | ppc->options, | ||
1802 | hostname, | ||
1803 | ppc->port); | ||
1833 | else | 1804 | else |
1834 | GNUNET_asprintf (&ret, "%s.%u.%s:%d", PLUGIN_NAME, ppc->options, hostname, ppc->port); | 1805 | GNUNET_asprintf (&ret, |
1806 | "%s.%u.%s:%d", | ||
1807 | PLUGIN_NAME, | ||
1808 | ppc->options, | ||
1809 | hostname, | ||
1810 | ppc->port); | ||
1835 | ppc->asc (ppc->asc_cls, ret); | 1811 | ppc->asc (ppc->asc_cls, ret); |
1836 | GNUNET_free (ret); | 1812 | GNUNET_free (ret); |
1837 | } | 1813 | } |
@@ -1977,9 +1953,8 @@ tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen) | |||
1977 | if ((addrlen != sizeof (struct IPv4TcpAddress)) && | 1953 | if ((addrlen != sizeof (struct IPv4TcpAddress)) && |
1978 | (addrlen != sizeof (struct IPv6TcpAddress))) | 1954 | (addrlen != sizeof (struct IPv6TcpAddress))) |
1979 | { | 1955 | { |
1980 | 1956 | GNUNET_break_op (0); | |
1981 | 1957 | return GNUNET_SYSERR; | |
1982 | return GNUNET_SYSERR; | ||
1983 | } | 1958 | } |
1984 | 1959 | ||
1985 | if (addrlen == sizeof (struct IPv4TcpAddress)) | 1960 | if (addrlen == sizeof (struct IPv4TcpAddress)) |
@@ -1987,8 +1962,8 @@ tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen) | |||
1987 | v4 = (struct IPv4TcpAddress *) addr; | 1962 | v4 = (struct IPv4TcpAddress *) addr; |
1988 | if (0 != memcmp (&v4->options, &myoptions, sizeof (myoptions))) | 1963 | if (0 != memcmp (&v4->options, &myoptions, sizeof (myoptions))) |
1989 | { | 1964 | { |
1990 | GNUNET_break (0); | 1965 | GNUNET_break (0); |
1991 | return GNUNET_SYSERR; | 1966 | return GNUNET_SYSERR; |
1992 | } | 1967 | } |
1993 | if (GNUNET_OK != check_port (plugin, ntohs (v4->t4_port))) | 1968 | if (GNUNET_OK != check_port (plugin, ntohs (v4->t4_port))) |
1994 | return GNUNET_SYSERR; | 1969 | return GNUNET_SYSERR; |
@@ -2196,9 +2171,10 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client, | |||
2196 | gettext_noop ("# TCP WELCOME messages received"), 1, | 2171 | gettext_noop ("# TCP WELCOME messages received"), 1, |
2197 | GNUNET_NO); | 2172 | GNUNET_NO); |
2198 | session = lookup_session_by_client (plugin, client); | 2173 | session = lookup_session_by_client (plugin, client); |
2199 | if (session != NULL) | 2174 | if (NULL != session) |
2200 | { | 2175 | { |
2201 | if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) | 2176 | if (GNUNET_OK == |
2177 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) | ||
2202 | { | 2178 | { |
2203 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2179 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2204 | "Found existing session %p for peer `%s'\n", | 2180 | "Found existing session %p for peer `%s'\n", |
@@ -2210,7 +2186,7 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client, | |||
2210 | else | 2186 | else |
2211 | { | 2187 | { |
2212 | GNUNET_SERVER_client_keep (client); | 2188 | GNUNET_SERVER_client_keep (client); |
2213 | if (plugin->service != NULL) /* Otherwise value is incremented in tcp_access_check */ | 2189 | if (NULL != plugin->service) /* Otherwise value is incremented in tcp_access_check */ |
2214 | plugin->cur_connections++; | 2190 | plugin->cur_connections++; |
2215 | if (plugin->cur_connections == plugin->max_connections) | 2191 | if (plugin->cur_connections == plugin->max_connections) |
2216 | GNUNET_SERVER_suspend (plugin->server); /* Maximum number of connections rechead */ | 2192 | GNUNET_SERVER_suspend (plugin->server); /* Maximum number of connections rechead */ |
@@ -2274,14 +2250,14 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client, | |||
2274 | /* Notify transport and ATS about new session */ | 2250 | /* Notify transport and ATS about new session */ |
2275 | if (GNUNET_YES == session->inbound) | 2251 | if (GNUNET_YES == session->inbound) |
2276 | { | 2252 | { |
2277 | plugin->env->session_start (NULL, &wm->clientIdentity, PLUGIN_NAME, | 2253 | plugin->env->session_start (NULL, |
2278 | (GNUNET_YES == session->inbound) ? NULL : session->addr, | 2254 | &wm->clientIdentity, |
2279 | (GNUNET_YES == session->inbound) ? 0 : session->addrlen, | 2255 | PLUGIN_NAME, |
2280 | session, &ats, 1); | 2256 | (GNUNET_YES == session->inbound) ? NULL : session->addr, |
2257 | (GNUNET_YES == session->inbound) ? 0 : session->addrlen, | ||
2258 | session, &ats, 1); | ||
2281 | } | 2259 | } |
2282 | |||
2283 | process_pending_messages (session); | 2260 | process_pending_messages (session); |
2284 | |||
2285 | GNUNET_SERVER_client_set_timeout (client, | 2261 | GNUNET_SERVER_client_set_timeout (client, |
2286 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 2262 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
2287 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2263 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -2292,11 +2268,12 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client, | |||
2292 | * Task to signal the server that we can continue | 2268 | * Task to signal the server that we can continue |
2293 | * receiving from the TCP client now. | 2269 | * receiving from the TCP client now. |
2294 | * | 2270 | * |
2295 | * @param cls the 'struct Session*' | 2271 | * @param cls the `struct Session*` |
2296 | * @param tc task context (unused) | 2272 | * @param tc task context (unused) |
2297 | */ | 2273 | */ |
2298 | static void | 2274 | static void |
2299 | delayed_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 2275 | delayed_done (void *cls, |
2276 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
2300 | { | 2277 | { |
2301 | struct Session *session = cls; | 2278 | struct Session *session = cls; |
2302 | 2279 | ||
@@ -2752,6 +2729,9 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2752 | 2729 | ||
2753 | /** | 2730 | /** |
2754 | * Exit point from the plugin. | 2731 | * Exit point from the plugin. |
2732 | * | ||
2733 | * @param cls the `struct GNUNET_TRANSPORT_PluginFunctions` | ||
2734 | * @return NULL | ||
2755 | */ | 2735 | */ |
2756 | void * | 2736 | void * |
2757 | libgnunet_plugin_transport_tcp_done (void *cls) | 2737 | libgnunet_plugin_transport_tcp_done (void *cls) |