diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-10 16:45:26 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-10 16:45:26 +0000 |
commit | 75264ef067a70a1b0c01dcab46264d4f31217a5f (patch) | |
tree | 690c7ade80810c6cb33bd83e1562d30ca2a0fd06 /src/transport/plugin_transport_tcp.c | |
parent | 6cf96e80986552390556f36bd6e464d48c1a4b88 (diff) | |
download | gnunet-75264ef067a70a1b0c01dcab46264d4f31217a5f.tar.gz gnunet-75264ef067a70a1b0c01dcab46264d4f31217a5f.zip |
-fixing some memory leaks from #3667, also reindentation and code cleanup
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 231 |
1 files changed, 135 insertions, 96 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index f95e11f80..5396d5247 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -269,7 +269,7 @@ struct Session | |||
269 | /** | 269 | /** |
270 | * Task cleaning up a NAT client connection establishment attempt; | 270 | * Task cleaning up a NAT client connection establishment attempt; |
271 | */ | 271 | */ |
272 | struct GNUNET_SCHEDULER_Task * nat_connection_timeout; | 272 | struct GNUNET_SCHEDULER_Task *nat_connection_timeout; |
273 | 273 | ||
274 | /** | 274 | /** |
275 | * Messages currently pending for transmission | 275 | * Messages currently pending for transmission |
@@ -296,12 +296,12 @@ struct Session | |||
296 | /** | 296 | /** |
297 | * ID of task used to delay receiving more to throttle sender. | 297 | * ID of task used to delay receiving more to throttle sender. |
298 | */ | 298 | */ |
299 | struct GNUNET_SCHEDULER_Task * receive_delay_task; | 299 | struct GNUNET_SCHEDULER_Task *receive_delay_task; |
300 | 300 | ||
301 | /** | 301 | /** |
302 | * Session timeout task | 302 | * Session timeout task |
303 | */ | 303 | */ |
304 | struct GNUNET_SCHEDULER_Task * timeout_task; | 304 | struct GNUNET_SCHEDULER_Task *timeout_task; |
305 | 305 | ||
306 | /** | 306 | /** |
307 | * When will this session time out? | 307 | * When will this session time out? |
@@ -891,7 +891,7 @@ tcp_plugin_disconnect_session (void *cls, | |||
891 | session, | 891 | session, |
892 | GNUNET_TRANSPORT_SS_DONE); | 892 | GNUNET_TRANSPORT_SS_DONE); |
893 | 893 | ||
894 | if (session->receive_delay_task != NULL) | 894 | if (NULL != session->receive_delay_task) |
895 | { | 895 | { |
896 | GNUNET_SCHEDULER_cancel (session->receive_delay_task); | 896 | GNUNET_SCHEDULER_cancel (session->receive_delay_task); |
897 | if (NULL != session->client) | 897 | if (NULL != session->client) |
@@ -1101,8 +1101,8 @@ do_transmit (void *cls, size_t size, void *buf) | |||
1101 | tl = NULL; | 1101 | tl = NULL; |
1102 | ret = 0; | 1102 | ret = 0; |
1103 | now = GNUNET_TIME_absolute_get (); | 1103 | now = GNUNET_TIME_absolute_get (); |
1104 | while ((NULL != (pos = session->pending_messages_head)) | 1104 | while ( (NULL != (pos = session->pending_messages_head)) && |
1105 | && (pos->timeout.abs_value_us <= now.abs_value_us)) | 1105 | (pos->timeout.abs_value_us <= now.abs_value_us) ) |
1106 | { | 1106 | { |
1107 | GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, | 1107 | GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, |
1108 | session->pending_messages_tail, | 1108 | session->pending_messages_tail, |
@@ -1116,7 +1116,10 @@ do_transmit (void *cls, size_t size, void *buf) | |||
1116 | pos->message_size, | 1116 | pos->message_size, |
1117 | GNUNET_i2s (&session->target)); | 1117 | GNUNET_i2s (&session->target)); |
1118 | ret += pos->message_size; | 1118 | ret += pos->message_size; |
1119 | GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos); | 1119 | GNUNET_CONTAINER_DLL_insert_after (hd, |
1120 | tl, | ||
1121 | tl, | ||
1122 | pos); | ||
1120 | } | 1123 | } |
1121 | /* do this call before callbacks (so that if callbacks destroy | 1124 | /* do this call before callbacks (so that if callbacks destroy |
1122 | * session, they have a chance to cancel actions done by this | 1125 | * session, they have a chance to cancel actions done by this |
@@ -1127,12 +1130,15 @@ do_transmit (void *cls, size_t size, void *buf) | |||
1127 | * the callbacks may abort the session */ | 1130 | * the callbacks may abort the session */ |
1128 | while (NULL != (pos = hd)) | 1131 | while (NULL != (pos = hd)) |
1129 | { | 1132 | { |
1130 | GNUNET_CONTAINER_DLL_remove (hd, tl, pos); | 1133 | GNUNET_CONTAINER_DLL_remove (hd, |
1131 | if (pos->transmit_cont != NULL) | 1134 | tl, |
1135 | pos); | ||
1136 | if (NULL != pos->transmit_cont) | ||
1132 | pos->transmit_cont (pos->transmit_cont_cls, | 1137 | pos->transmit_cont (pos->transmit_cont_cls, |
1133 | &pid, | 1138 | &pid, |
1134 | GNUNET_SYSERR, | 1139 | GNUNET_SYSERR, |
1135 | pos->message_size, 0); | 1140 | pos->message_size, |
1141 | 0); | ||
1136 | GNUNET_free (pos); | 1142 | GNUNET_free (pos); |
1137 | } | 1143 | } |
1138 | GNUNET_STATISTICS_update (plugin->env->stats, | 1144 | GNUNET_STATISTICS_update (plugin->env->stats, |
@@ -1165,19 +1171,23 @@ do_transmit (void *cls, size_t size, void *buf) | |||
1165 | GNUNET_assert (pos->message_size <= session->bytes_in_queue); | 1171 | GNUNET_assert (pos->message_size <= session->bytes_in_queue); |
1166 | session->bytes_in_queue -= pos->message_size; | 1172 | session->bytes_in_queue -= pos->message_size; |
1167 | GNUNET_assert(size >= pos->message_size); | 1173 | GNUNET_assert(size >= pos->message_size); |
1168 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1174 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1169 | "Transmitting message of type %u size %u to %s\n", | 1175 | "Transmitting message of type %u size %u to %s\n", |
1170 | ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type), | 1176 | ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type), |
1171 | pos->message_size, | 1177 | pos->message_size, |
1172 | tcp_plugin_address_to_string (session->plugin, | 1178 | tcp_plugin_address_to_string (session->plugin, |
1173 | session->address->address, | 1179 | session->address->address, |
1174 | session->address->address_length)); | 1180 | session->address->address_length)); |
1175 | /* FIXME: this memcpy can be up to 7% of our total runtime */ | 1181 | /* FIXME: this memcpy can be up to 7% of our total runtime */ |
1176 | memcpy (cbuf, pos->msg, pos->message_size); | 1182 | memcpy (cbuf, |
1183 | pos->msg, | ||
1184 | pos->message_size); | ||
1177 | cbuf += pos->message_size; | 1185 | cbuf += pos->message_size; |
1178 | ret += pos->message_size; | 1186 | ret += pos->message_size; |
1179 | size -= pos->message_size; | 1187 | size -= pos->message_size; |
1180 | GNUNET_CONTAINER_DLL_insert_tail (hd, tl, pos); | 1188 | GNUNET_CONTAINER_DLL_insert_tail (hd, |
1189 | tl, | ||
1190 | pos); | ||
1181 | } | 1191 | } |
1182 | notify_session_monitor (session->plugin, | 1192 | notify_session_monitor (session->plugin, |
1183 | session, | 1193 | session, |
@@ -1193,19 +1203,19 @@ do_transmit (void *cls, size_t size, void *buf) | |||
1193 | while (NULL != (pos = hd)) | 1203 | while (NULL != (pos = hd)) |
1194 | { | 1204 | { |
1195 | GNUNET_CONTAINER_DLL_remove (hd, tl, pos); | 1205 | GNUNET_CONTAINER_DLL_remove (hd, tl, pos); |
1196 | if (pos->transmit_cont != NULL) | 1206 | if (NULL != pos->transmit_cont) |
1197 | pos->transmit_cont (pos->transmit_cont_cls, | 1207 | pos->transmit_cont (pos->transmit_cont_cls, |
1198 | &pid, | 1208 | &pid, |
1199 | GNUNET_OK, | 1209 | GNUNET_OK, |
1200 | pos->message_size, | 1210 | pos->message_size, |
1201 | pos->message_size); /* FIXME: include TCP overhead */ | 1211 | pos->message_size); /* FIXME: include TCP overhead */ |
1202 | GNUNET_free(pos); | 1212 | GNUNET_free (pos); |
1203 | } | 1213 | } |
1204 | GNUNET_assert (NULL == hd); | 1214 | GNUNET_assert (NULL == hd); |
1205 | GNUNET_assert (NULL == tl); | 1215 | GNUNET_assert (NULL == tl); |
1206 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1216 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1207 | "Transmitting %u bytes\n", | 1217 | "Transmitting %u bytes\n", |
1208 | ret); | 1218 | ret); |
1209 | GNUNET_STATISTICS_update (plugin->env->stats, | 1219 | GNUNET_STATISTICS_update (plugin->env->stats, |
1210 | gettext_noop ("# bytes currently in TCP buffers"), | 1220 | gettext_noop ("# bytes currently in TCP buffers"), |
1211 | - (int64_t) ret, | 1221 | - (int64_t) ret, |
@@ -1294,7 +1304,8 @@ tcp_plugin_send (void *cls, | |||
1294 | 1304 | ||
1295 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1305 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1296 | "Asked to transmit %u bytes to `%s', added message to list.\n", | 1306 | "Asked to transmit %u bytes to `%s', added message to list.\n", |
1297 | msgbuf_size, GNUNET_i2s (&session->target)); | 1307 | msgbuf_size, |
1308 | GNUNET_i2s (&session->target)); | ||
1298 | 1309 | ||
1299 | if (GNUNET_YES == | 1310 | if (GNUNET_YES == |
1300 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, | 1311 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, |
@@ -1303,10 +1314,11 @@ tcp_plugin_send (void *cls, | |||
1303 | { | 1314 | { |
1304 | GNUNET_assert (NULL != session->client); | 1315 | GNUNET_assert (NULL != session->client); |
1305 | GNUNET_SERVER_client_set_timeout (session->client, | 1316 | GNUNET_SERVER_client_set_timeout (session->client, |
1306 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 1317 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
1307 | GNUNET_STATISTICS_update (plugin->env->stats, | 1318 | GNUNET_STATISTICS_update (plugin->env->stats, |
1308 | gettext_noop ("# bytes currently in TCP buffers"), msgbuf_size, | 1319 | gettext_noop ("# bytes currently in TCP buffers"), |
1309 | GNUNET_NO); | 1320 | msgbuf_size, |
1321 | GNUNET_NO); | ||
1310 | 1322 | ||
1311 | /* append pm to pending_messages list */ | 1323 | /* append pm to pending_messages list */ |
1312 | GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head, | 1324 | GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head, |
@@ -1320,10 +1332,10 @@ tcp_plugin_send (void *cls, | |||
1320 | process_pending_messages (session); | 1332 | process_pending_messages (session); |
1321 | return msgbuf_size; | 1333 | return msgbuf_size; |
1322 | } | 1334 | } |
1323 | else if (GNUNET_YES == | 1335 | if (GNUNET_YES == |
1324 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->nat_wait_conns, | 1336 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->nat_wait_conns, |
1325 | &session->target, | 1337 | &session->target, |
1326 | session)) | 1338 | session)) |
1327 | { | 1339 | { |
1328 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1340 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1329 | "This NAT WAIT session for peer `%s' is not yet ready!\n", | 1341 | "This NAT WAIT session for peer `%s' is not yet ready!\n", |
@@ -1342,23 +1354,21 @@ tcp_plugin_send (void *cls, | |||
1342 | GNUNET_TRANSPORT_SS_HANDSHAKE); | 1354 | GNUNET_TRANSPORT_SS_HANDSHAKE); |
1343 | return msgbuf_size; | 1355 | return msgbuf_size; |
1344 | } | 1356 | } |
1345 | else | 1357 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1346 | { | 1358 | "Invalid session %p\n", |
1347 | LOG(GNUNET_ERROR_TYPE_ERROR, | 1359 | session); |
1348 | "Invalid session %p\n", | 1360 | if (NULL != cont) |
1349 | session); | 1361 | cont (cont_cls, |
1350 | if (NULL != cont) | 1362 | &session->target, |
1351 | cont (cont_cls, | 1363 | GNUNET_SYSERR, |
1352 | &session->target, | 1364 | pm->message_size, |
1353 | GNUNET_SYSERR, | 1365 | 0); |
1354 | pm->message_size, | 1366 | GNUNET_break (0); |
1355 | 0); | 1367 | GNUNET_free (pm); |
1356 | GNUNET_break (0); | 1368 | return GNUNET_SYSERR; /* session does not exist here */ |
1357 | GNUNET_free (pm); | ||
1358 | return GNUNET_SYSERR; /* session does not exist here */ | ||
1359 | } | ||
1360 | } | 1369 | } |
1361 | 1370 | ||
1371 | |||
1362 | /** | 1372 | /** |
1363 | * Closure for #session_lookup_it(). | 1373 | * Closure for #session_lookup_it(). |
1364 | */ | 1374 | */ |
@@ -1390,12 +1400,13 @@ session_lookup_it (void *cls, | |||
1390 | const struct GNUNET_PeerIdentity *key, | 1400 | const struct GNUNET_PeerIdentity *key, |
1391 | void *value) | 1401 | void *value) |
1392 | { | 1402 | { |
1393 | struct SessionItCtx * si_ctx = cls; | 1403 | struct SessionItCtx *si_ctx = cls; |
1394 | struct Session * session = value; | 1404 | struct Session *session = value; |
1395 | 1405 | ||
1396 | if (0 != GNUNET_HELLO_address_cmp (si_ctx->address, session->address)) | 1406 | if (0 != |
1407 | GNUNET_HELLO_address_cmp (si_ctx->address, | ||
1408 | session->address)) | ||
1397 | return GNUNET_YES; | 1409 | return GNUNET_YES; |
1398 | /* Found existing session */ | ||
1399 | si_ctx->result = session; | 1410 | si_ctx->result = session; |
1400 | return GNUNET_NO; | 1411 | return GNUNET_NO; |
1401 | } | 1412 | } |
@@ -2273,12 +2284,16 @@ handle_tcp_welcome (void *cls, | |||
2273 | sizeof(struct GNUNET_PeerIdentity))) | 2284 | sizeof(struct GNUNET_PeerIdentity))) |
2274 | { | 2285 | { |
2275 | /* refuse connections from ourselves */ | 2286 | /* refuse connections from ourselves */ |
2276 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2287 | GNUNET_SERVER_receive_done (client, |
2277 | if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) | 2288 | GNUNET_SYSERR); |
2289 | if (GNUNET_OK == | ||
2290 | GNUNET_SERVER_client_get_address (client, | ||
2291 | &vaddr, | ||
2292 | &alen)) | ||
2278 | { | 2293 | { |
2279 | LOG (GNUNET_ERROR_TYPE_INFO, | 2294 | LOG (GNUNET_ERROR_TYPE_INFO, |
2280 | "Received %s message from my own identity `%4s' on address `%s'\n", | 2295 | "Received WELCOME message from my own identity `%4s' on address `%s'\n", |
2281 | "WELCOME", GNUNET_i2s (&wm->clientIdentity), | 2296 | GNUNET_i2s (&wm->clientIdentity), |
2282 | GNUNET_a2s (vaddr, alen)); | 2297 | GNUNET_a2s (vaddr, alen)); |
2283 | GNUNET_free(vaddr); | 2298 | GNUNET_free(vaddr); |
2284 | } | 2299 | } |
@@ -2286,9 +2301,9 @@ handle_tcp_welcome (void *cls, | |||
2286 | } | 2301 | } |
2287 | 2302 | ||
2288 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2303 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2289 | "Received %s message from `%4s' %p\n", | 2304 | "Received WELCOME message from `%4s' %p\n", |
2290 | "WELCOME", | 2305 | GNUNET_i2s (&wm->clientIdentity), |
2291 | GNUNET_i2s (&wm->clientIdentity), client); | 2306 | client); |
2292 | GNUNET_STATISTICS_update (plugin->env->stats, | 2307 | GNUNET_STATISTICS_update (plugin->env->stats, |
2293 | gettext_noop ("# TCP WELCOME messages received"), | 2308 | gettext_noop ("# TCP WELCOME messages received"), |
2294 | 1, | 2309 | 1, |
@@ -2296,7 +2311,8 @@ handle_tcp_welcome (void *cls, | |||
2296 | session = lookup_session_by_client (plugin, client); | 2311 | session = lookup_session_by_client (plugin, client); |
2297 | if (NULL != session) | 2312 | if (NULL != session) |
2298 | { | 2313 | { |
2299 | if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) | 2314 | if (GNUNET_OK == |
2315 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) | ||
2300 | { | 2316 | { |
2301 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2317 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2302 | "Found existing session %p for peer `%s'\n", | 2318 | "Found existing session %p for peer `%s'\n", |
@@ -2313,7 +2329,8 @@ handle_tcp_welcome (void *cls, | |||
2313 | if (plugin->cur_connections == plugin->max_connections) | 2329 | if (plugin->cur_connections == plugin->max_connections) |
2314 | GNUNET_SERVER_suspend (plugin->server); /* Maximum number of connections rechead */ | 2330 | GNUNET_SERVER_suspend (plugin->server); /* Maximum number of connections rechead */ |
2315 | 2331 | ||
2316 | if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) | 2332 | if (GNUNET_OK == |
2333 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) | ||
2317 | { | 2334 | { |
2318 | if (alen == sizeof(struct sockaddr_in)) | 2335 | if (alen == sizeof(struct sockaddr_in)) |
2319 | { | 2336 | { |
@@ -2336,8 +2353,10 @@ handle_tcp_welcome (void *cls, | |||
2336 | t6.t6_port = s6->sin6_port; | 2353 | t6.t6_port = s6->sin6_port; |
2337 | memcpy (&t6.ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); | 2354 | memcpy (&t6.ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); |
2338 | address = GNUNET_HELLO_address_allocate (&wm->clientIdentity, | 2355 | address = GNUNET_HELLO_address_allocate (&wm->clientIdentity, |
2339 | PLUGIN_NAME, &t6, sizeof (t6), | 2356 | PLUGIN_NAME, |
2340 | GNUNET_HELLO_ADDRESS_INFO_INBOUND); | 2357 | &t6, |
2358 | sizeof (t6), | ||
2359 | GNUNET_HELLO_ADDRESS_INFO_INBOUND); | ||
2341 | } | 2360 | } |
2342 | else | 2361 | else |
2343 | { | 2362 | { |
@@ -2345,9 +2364,15 @@ handle_tcp_welcome (void *cls, | |||
2345 | GNUNET_free_non_null (vaddr); | 2364 | GNUNET_free_non_null (vaddr); |
2346 | return; | 2365 | return; |
2347 | } | 2366 | } |
2348 | session = create_session (plugin, address, client, GNUNET_NO); | 2367 | session = create_session (plugin, |
2368 | address, | ||
2369 | client, | ||
2370 | GNUNET_NO); | ||
2349 | GNUNET_HELLO_address_free (address); | 2371 | GNUNET_HELLO_address_free (address); |
2350 | session->ats_address_network_type = plugin->env->get_address_type (plugin->env->cls, vaddr, alen); | 2372 | session->ats_address_network_type |
2373 | = plugin->env->get_address_type (plugin->env->cls, | ||
2374 | vaddr, | ||
2375 | alen); | ||
2351 | ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); | 2376 | ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); |
2352 | ats.value = htonl (session->ats_address_network_type); | 2377 | ats.value = htonl (session->ats_address_network_type); |
2353 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2378 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -2418,13 +2443,15 @@ handle_tcp_data (void *cls, | |||
2418 | struct Session *session; | 2443 | struct Session *session; |
2419 | struct GNUNET_TIME_Relative delay; | 2444 | struct GNUNET_TIME_Relative delay; |
2420 | uint16_t type; | 2445 | uint16_t type; |
2446 | struct GNUNET_ATS_Information distance; | ||
2421 | 2447 | ||
2422 | type = ntohs (message->type); | 2448 | type = ntohs (message->type); |
2423 | if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) | 2449 | if ( (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) || |
2424 | || (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type)) | 2450 | (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type) ) |
2425 | { | 2451 | { |
2426 | /* We don't want to propagate WELCOME and NAT Probe messages up! */ | 2452 | /* We don't want to propagate WELCOME and NAT Probe messages up! */ |
2427 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2453 | GNUNET_SERVER_receive_done (client, |
2454 | GNUNET_OK); | ||
2428 | return; | 2455 | return; |
2429 | } | 2456 | } |
2430 | session = lookup_session_by_client (plugin, client); | 2457 | session = lookup_session_by_client (plugin, client); |
@@ -2434,14 +2461,19 @@ handle_tcp_data (void *cls, | |||
2434 | void *vaddr; | 2461 | void *vaddr; |
2435 | size_t alen; | 2462 | size_t alen; |
2436 | 2463 | ||
2437 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen); | 2464 | GNUNET_SERVER_client_get_address (client, |
2438 | LOG(GNUNET_ERROR_TYPE_ERROR, | 2465 | &vaddr, |
2439 | "Received unexpected %u bytes of type %u from `%s'\n", | 2466 | &alen); |
2440 | (unsigned int) ntohs (message->size), | 2467 | LOG (GNUNET_ERROR_TYPE_ERROR, |
2441 | (unsigned int) ntohs (message->type), GNUNET_a2s (vaddr, alen)); | 2468 | "Received unexpected %u bytes of type %u from `%s'\n", |
2469 | (unsigned int) ntohs (message->size), | ||
2470 | (unsigned int) ntohs (message->type), | ||
2471 | GNUNET_a2s (vaddr, | ||
2472 | alen)); | ||
2442 | GNUNET_break_op(0); | 2473 | GNUNET_break_op(0); |
2443 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2474 | GNUNET_SERVER_receive_done (client, |
2444 | GNUNET_free_non_null(vaddr); | 2475 | GNUNET_SYSERR); |
2476 | GNUNET_free_non_null (vaddr); | ||
2445 | return; | 2477 | return; |
2446 | } | 2478 | } |
2447 | else if (GNUNET_YES == session->expecting_welcome) | 2479 | else if (GNUNET_YES == session->expecting_welcome) |
@@ -2451,35 +2483,37 @@ handle_tcp_data (void *cls, | |||
2451 | size_t alen; | 2483 | size_t alen; |
2452 | 2484 | ||
2453 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen); | 2485 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen); |
2454 | LOG(GNUNET_ERROR_TYPE_ERROR, | 2486 | LOG (GNUNET_ERROR_TYPE_ERROR, |
2455 | "Received unexpected %u bytes of type %u from `%s'\n", | 2487 | "Received unexpected %u bytes of type %u from `%s'\n", |
2456 | (unsigned int) ntohs (message->size), | 2488 | (unsigned int) ntohs (message->size), |
2457 | (unsigned int) ntohs (message->type), GNUNET_a2s (vaddr, alen)); | 2489 | (unsigned int) ntohs (message->type), |
2490 | GNUNET_a2s (vaddr, alen)); | ||
2458 | GNUNET_break_op(0); | 2491 | GNUNET_break_op(0); |
2459 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2492 | GNUNET_SERVER_receive_done (client, |
2460 | GNUNET_free_non_null(vaddr); | 2493 | GNUNET_SYSERR); |
2494 | GNUNET_free_non_null (vaddr); | ||
2461 | return; | 2495 | return; |
2462 | } | 2496 | } |
2463 | 2497 | ||
2464 | session->last_activity = GNUNET_TIME_absolute_get (); | 2498 | session->last_activity = GNUNET_TIME_absolute_get (); |
2465 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2499 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2466 | "Passing %u bytes of type %u from `%4s' to transport service.\n", | 2500 | "Passing %u bytes of type %u from `%4s' to transport service.\n", |
2467 | (unsigned int) ntohs (message->size), | 2501 | (unsigned int) ntohs (message->size), |
2468 | (unsigned int) ntohs (message->type), GNUNET_i2s (&session->target)); | 2502 | (unsigned int) ntohs (message->type), |
2503 | GNUNET_i2s (&session->target)); | ||
2469 | 2504 | ||
2470 | GNUNET_STATISTICS_update (plugin->env->stats, | 2505 | GNUNET_STATISTICS_update (plugin->env->stats, |
2471 | gettext_noop ("# bytes received via TCP"), ntohs (message->size), | 2506 | gettext_noop ("# bytes received via TCP"), |
2472 | GNUNET_NO); | 2507 | ntohs (message->size), |
2473 | struct GNUNET_ATS_Information distance; | 2508 | GNUNET_NO); |
2474 | 2509 | ||
2475 | distance.type = htonl (GNUNET_ATS_NETWORK_TYPE); | 2510 | distance.type = htonl (GNUNET_ATS_NETWORK_TYPE); |
2476 | distance.value = htonl ((uint32_t) session->ats_address_network_type); | 2511 | distance.value = htonl ((uint32_t) session->ats_address_network_type); |
2477 | GNUNET_break(session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); | 2512 | GNUNET_break (session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); |
2478 | |||
2479 | GNUNET_assert(GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, | ||
2480 | &session->target, | ||
2481 | session)); | ||
2482 | 2513 | ||
2514 | GNUNET_assert (GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, | ||
2515 | &session->target, | ||
2516 | session)); | ||
2483 | delay = plugin->env->receive (plugin->env->cls, | 2517 | delay = plugin->env->receive (plugin->env->cls, |
2484 | session->address, | 2518 | session->address, |
2485 | session, | 2519 | session, |
@@ -2722,9 +2756,11 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2722 | { | 2756 | { |
2723 | static const struct GNUNET_SERVER_MessageHandler my_handlers[] = { | 2757 | static const struct GNUNET_SERVER_MessageHandler my_handlers[] = { |
2724 | { &handle_tcp_welcome, NULL, | 2758 | { &handle_tcp_welcome, NULL, |
2725 | GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, sizeof(struct WelcomeMessage) }, | 2759 | GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, |
2760 | sizeof(struct WelcomeMessage) }, | ||
2726 | { &handle_tcp_nat_probe, NULL, | 2761 | { &handle_tcp_nat_probe, NULL, |
2727 | GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, sizeof(struct TCP_NAT_ProbeMessage) }, | 2762 | GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, |
2763 | sizeof(struct TCP_NAT_ProbeMessage) }, | ||
2728 | { &handle_tcp_data, NULL, | 2764 | { &handle_tcp_data, NULL, |
2729 | GNUNET_MESSAGE_TYPE_ALL, 0 }, | 2765 | GNUNET_MESSAGE_TYPE_ALL, 0 }, |
2730 | { NULL, NULL, 0, 0 } | 2766 | { NULL, NULL, 0, 0 } |
@@ -2936,8 +2972,11 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2936 | for (i = 0;i < sizeof(my_handlers) / sizeof(struct GNUNET_SERVER_MessageHandler);i++) | 2972 | for (i = 0;i < sizeof(my_handlers) / sizeof(struct GNUNET_SERVER_MessageHandler);i++) |
2937 | plugin->handlers[i].callback_cls = plugin; | 2973 | plugin->handlers[i].callback_cls = plugin; |
2938 | 2974 | ||
2939 | GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers); | 2975 | GNUNET_SERVER_add_handlers (plugin->server, |
2940 | GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin); | 2976 | plugin->handlers); |
2977 | GNUNET_SERVER_disconnect_notify (plugin->server, | ||
2978 | &disconnect_notify, | ||
2979 | plugin); | ||
2941 | plugin->nat_wait_conns = GNUNET_CONTAINER_multipeermap_create (16, | 2980 | plugin->nat_wait_conns = GNUNET_CONTAINER_multipeermap_create (16, |
2942 | GNUNET_YES); | 2981 | GNUNET_YES); |
2943 | if (0 != bport) | 2982 | if (0 != bport) |