aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-communicator-tcp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-communicator-tcp.c')
-rw-r--r--src/transport/gnunet-communicator-tcp.c92
1 files changed, 65 insertions, 27 deletions
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c
index ed82dba9f..9dd2797df 100644
--- a/src/transport/gnunet-communicator-tcp.c
+++ b/src/transport/gnunet-communicator-tcp.c
@@ -739,7 +739,6 @@ struct Addresses
739}; 739};
740 740
741 741
742
743/** 742/**
744 * Maximum queue length before we stop reading towards the transport service. 743 * Maximum queue length before we stop reading towards the transport service.
745 */ 744 */
@@ -878,12 +877,14 @@ queue_destroy (struct Queue *queue)
878{ 877{
879 struct ListenTask *lt = NULL; 878 struct ListenTask *lt = NULL;
880 struct GNUNET_HashCode h_sock; 879 struct GNUNET_HashCode h_sock;
880 int sockfd;
881 881
882 GNUNET_CRYPTO_hash (queue->listen_sock, 882 sockfd = GNUNET_NETWORK_get_fd (queue->listen_sock);
883 sizeof(queue->listen_sock), 883 GNUNET_CRYPTO_hash (&sockfd,
884 sizeof(int),
884 &h_sock); 885 &h_sock);
885 886
886 lt = GNUNET_CONTAINER_multihashmap_get (lt_map, &h_sock); 887 lt = GNUNET_CONTAINER_multihashmap_get (lt_map, &h_sock);
887 888
888 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
889 "Disconnecting queue for peer `%s'\n", 890 "Disconnecting queue for peer `%s'\n",
@@ -953,6 +954,9 @@ queue_destroy (struct Queue *queue)
953 else 954 else
954 GNUNET_free (queue); 955 GNUNET_free (queue);
955 956
957 if (NULL == lt)
958 return;
959
956 if ((! shutdown_running) && (NULL == lt->listen_task)) 960 if ((! shutdown_running) && (NULL == lt->listen_task))
957 { 961 {
958 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 962 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1193,6 +1197,7 @@ setup_cipher (const struct GNUNET_HashCode *dh,
1193 0)); 1197 0));
1194} 1198}
1195 1199
1200
1196/** 1201/**
1197 * Callback called when peerstore store operation for rekey monotime value is finished. 1202 * Callback called when peerstore store operation for rekey monotime value is finished.
1198 * @param cls Queue context the store operation was executed. 1203 * @param cls Queue context the store operation was executed.
@@ -1210,6 +1215,7 @@ rekey_monotime_store_cb (void *cls, int success)
1210 queue->rekey_monotime_sc = NULL; 1215 queue->rekey_monotime_sc = NULL;
1211} 1216}
1212 1217
1218
1213/** 1219/**
1214 * Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY 1220 * Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY
1215 * where found. 1221 * where found.
@@ -1259,13 +1265,15 @@ rekey_monotime_cb (void *cls,
1259 pid, 1265 pid,
1260 GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY, 1266 GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY,
1261 rekey_monotonic_time, 1267 rekey_monotonic_time,
1262 sizeof(rekey_monotonic_time), 1268 sizeof(*
1269 rekey_monotonic_time),
1263 GNUNET_TIME_UNIT_FOREVER_ABS, 1270 GNUNET_TIME_UNIT_FOREVER_ABS,
1264 GNUNET_PEERSTORE_STOREOPTION_REPLACE, 1271 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
1265 &rekey_monotime_store_cb, 1272 &rekey_monotime_store_cb,
1266 queue); 1273 queue);
1267} 1274}
1268 1275
1276
1269/** 1277/**
1270 * Setup cipher of @a queue for decryption. 1278 * Setup cipher of @a queue for decryption.
1271 * 1279 *
@@ -1344,6 +1352,7 @@ do_rekey (struct Queue *queue, const struct TCPRekey *rekey)
1344 setup_in_cipher (&rekey->ephemeral, queue); 1352 setup_in_cipher (&rekey->ephemeral, queue);
1345} 1353}
1346 1354
1355
1347/** 1356/**
1348 * Callback called when peerstore store operation for handshake ack monotime value is finished. 1357 * Callback called when peerstore store operation for handshake ack monotime value is finished.
1349 * @param cls Queue context the store operation was executed. 1358 * @param cls Queue context the store operation was executed.
@@ -1362,6 +1371,7 @@ handshake_ack_monotime_store_cb (void *cls, int success)
1362 queue->handshake_ack_monotime_sc = NULL; 1371 queue->handshake_ack_monotime_sc = NULL;
1363} 1372}
1364 1373
1374
1365/** 1375/**
1366 * Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK 1376 * Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK
1367 * where found. 1377 * where found.
@@ -1406,20 +1416,21 @@ handshake_ack_monotime_cb (void *cls,
1406 queue_finish (queue); 1416 queue_finish (queue);
1407 return; 1417 return;
1408 } 1418 }
1409 queue->handshake_ack_monotime_sc = GNUNET_PEERSTORE_store (peerstore, 1419 queue->handshake_ack_monotime_sc =
1410 "transport_tcp_communicator", 1420 GNUNET_PEERSTORE_store (peerstore,
1411 pid, 1421 "transport_tcp_communicator",
1412 GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK, 1422 pid,
1413 handshake_ack_monotonic_time, 1423 GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK,
1414 sizeof( 1424 handshake_ack_monotonic_time,
1415 handshake_ack_monotonic_time), 1425 sizeof(*handshake_ack_monotonic_time),
1416 GNUNET_TIME_UNIT_FOREVER_ABS, 1426 GNUNET_TIME_UNIT_FOREVER_ABS,
1417 GNUNET_PEERSTORE_STOREOPTION_REPLACE, 1427 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
1418 & 1428 &
1419 handshake_ack_monotime_store_cb, 1429 handshake_ack_monotime_store_cb,
1420 queue); 1430 queue);
1421} 1431}
1422 1432
1433
1423/** 1434/**
1424 * Sending challenge with TcpConfirmationAck back to sender of ephemeral key. 1435 * Sending challenge with TcpConfirmationAck back to sender of ephemeral key.
1425 * 1436 *
@@ -1465,6 +1476,7 @@ send_challenge (struct ChallengeNonceP challenge, struct Queue *queue)
1465 "sending challenge done\n"); 1476 "sending challenge done\n");
1466} 1477}
1467 1478
1479
1468/** 1480/**
1469 * Setup cipher for outgoing data stream based on target and 1481 * Setup cipher for outgoing data stream based on target and
1470 * our ephemeral private key. 1482 * our ephemeral private key.
@@ -1545,6 +1557,7 @@ inject_rekey (struct Queue *queue)
1545 setup_out_cipher (queue); 1557 setup_out_cipher (queue);
1546} 1558}
1547 1559
1560
1548/** 1561/**
1549 * We have been notified that our socket is ready to write. 1562 * We have been notified that our socket is ready to write.
1550 * Then reschedule this function to be called again once more is available. 1563 * Then reschedule this function to be called again once more is available.
@@ -1634,6 +1647,7 @@ queue_write (void *cls)
1634 queue); 1647 queue);
1635} 1648}
1636 1649
1650
1637/** 1651/**
1638 * Test if we have received a full message in plaintext. 1652 * Test if we have received a full message in plaintext.
1639 * If so, handle it. 1653 * If so, handle it.
@@ -1778,7 +1792,7 @@ try_handle_plaintext (struct Queue *queue)
1778 queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch, 1792 queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch,
1779 &queue->target, 1793 &queue->target,
1780 foreign_addr, 1794 foreign_addr,
1781 0 /* no MTU */, 1795 UINT32_MAX, /* no MTU */
1782 GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, 1796 GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED,
1783 0, /* Priority */ 1797 0, /* Priority */
1784 queue->nt, 1798 queue->nt,
@@ -1975,6 +1989,7 @@ queue_read (void *cls)
1975 queue_finish (queue); 1989 queue_finish (queue);
1976} 1990}
1977 1991
1992
1978/** 1993/**
1979 * Convert a `struct sockaddr_in6 to a `struct sockaddr *` 1994 * Convert a `struct sockaddr_in6 to a `struct sockaddr *`
1980 * 1995 *
@@ -2001,6 +2016,7 @@ tcp_address_to_sockaddr_numeric_v6 (socklen_t *sock_len, struct sockaddr_in6 v6,
2001 return in; 2016 return in;
2002} 2017}
2003 2018
2019
2004/** 2020/**
2005 * Convert a `struct sockaddr_in4 to a `struct sockaddr *` 2021 * Convert a `struct sockaddr_in4 to a `struct sockaddr *`
2006 * 2022 *
@@ -2024,6 +2040,7 @@ tcp_address_to_sockaddr_numeric_v4 (socklen_t *sock_len, struct sockaddr_in v4,
2024 return in; 2040 return in;
2025} 2041}
2026 2042
2043
2027/** 2044/**
2028 * Convert TCP bind specification to a `struct PortOnlyIpv4Ipv6 *` 2045 * Convert TCP bind specification to a `struct PortOnlyIpv4Ipv6 *`
2029 * 2046 *
@@ -2083,6 +2100,7 @@ tcp_address_to_sockaddr_port_only (const char *bindto, unsigned int *port)
2083 return po; 2100 return po;
2084} 2101}
2085 2102
2103
2086/** 2104/**
2087 * This Method extracts the address part of the BINDTO string. 2105 * This Method extracts the address part of the BINDTO string.
2088 * 2106 *
@@ -2117,7 +2135,8 @@ extract_address (const char *bindto)
2117 start++; /* skip over '['*/ 2135 start++; /* skip over '['*/
2118 cp[strlen (cp) - 1] = '\0'; /* eat ']'*/ 2136 cp[strlen (cp) - 1] = '\0'; /* eat ']'*/
2119 } 2137 }
2120 else { 2138 else
2139 {
2121 token = strtok_r (cp, "]", &rest); 2140 token = strtok_r (cp, "]", &rest);
2122 if (strlen (bindto) == strlen (token)) 2141 if (strlen (bindto) == strlen (token))
2123 { 2142 {
@@ -2139,6 +2158,7 @@ extract_address (const char *bindto)
2139 return start; 2158 return start;
2140} 2159}
2141 2160
2161
2142/** 2162/**
2143 * This Method extracts the port part of the BINDTO string. 2163 * This Method extracts the port part of the BINDTO string.
2144 * 2164 *
@@ -2217,6 +2237,7 @@ extract_port (const char *addr_and_port)
2217 return port; 2237 return port;
2218} 2238}
2219 2239
2240
2220/** 2241/**
2221 * Convert TCP bind specification to a `struct sockaddr *` 2242 * Convert TCP bind specification to a `struct sockaddr *`
2222 * 2243 *
@@ -2245,7 +2266,6 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
2245 bindto); 2266 bindto);
2246 2267
2247 2268
2248
2249 if (1 == inet_pton (AF_INET, start, &v4.sin_addr)) 2269 if (1 == inet_pton (AF_INET, start, &v4.sin_addr))
2250 { 2270 {
2251 // colon = strrchr (cp, ':'); 2271 // colon = strrchr (cp, ':');
@@ -2263,7 +2283,8 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
2263 port = extract_port (bindto); 2283 port = extract_port (bindto);
2264 in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port); 2284 in = tcp_address_to_sockaddr_numeric_v6 (sock_len, v6, port);
2265 } 2285 }
2266 else{ 2286 else
2287 {
2267 GNUNET_assert (0); 2288 GNUNET_assert (0);
2268 } 2289 }
2269 2290
@@ -2272,6 +2293,7 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
2272 return in; 2293 return in;
2273} 2294}
2274 2295
2296
2275/** 2297/**
2276 * Signature of functions implementing the sending functionality of a 2298 * Signature of functions implementing the sending functionality of a
2277 * message queue. 2299 * message queue.
@@ -2510,6 +2532,7 @@ start_initial_kx_out (struct Queue *queue)
2510 transmit_kx (queue, &epub); 2532 transmit_kx (queue, &epub);
2511} 2533}
2512 2534
2535
2513/** 2536/**
2514 * Callback called when peerstore store operation for handshake monotime is finished. 2537 * Callback called when peerstore store operation for handshake monotime is finished.
2515 * @param cls Queue context the store operation was executed. 2538 * @param cls Queue context the store operation was executed.
@@ -2527,6 +2550,7 @@ handshake_monotime_store_cb (void *cls, int success)
2527 queue->handshake_monotime_sc = NULL; 2550 queue->handshake_monotime_sc = NULL;
2528} 2551}
2529 2552
2553
2530/** 2554/**
2531 * Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE 2555 * Callback called by peerstore when records for GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE
2532 * where found. 2556 * where found.
@@ -2585,6 +2609,7 @@ handshake_monotime_cb (void *cls,
2585 queue); 2609 queue);
2586} 2610}
2587 2611
2612
2588/** 2613/**
2589 * We have received the first bytes from the other side on a @a queue. 2614 * We have received the first bytes from the other side on a @a queue.
2590 * Decrypt the @a tc contained in @a ibuf and check the signature. 2615 * Decrypt the @a tc contained in @a ibuf and check the signature.
@@ -2651,6 +2676,7 @@ free_proto_queue (struct ProtoQueue *pq)
2651 GNUNET_free (pq); 2676 GNUNET_free (pq);
2652} 2677}
2653 2678
2679
2654/** 2680/**
2655 * Read from the socket of the proto queue until we have enough data 2681 * Read from the socket of the proto queue until we have enough data
2656 * to upgrade to full queue. 2682 * to upgrade to full queue.
@@ -2892,6 +2918,7 @@ queue_read_kx (void *cls)
2892 queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue); 2918 queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue);
2893} 2919}
2894 2920
2921
2895/** 2922/**
2896 * Function called by the transport service to initialize a 2923 * Function called by the transport service to initialize a
2897 * message queue given address information about another peer. 2924 * message queue given address information about another peer.
@@ -2991,6 +3018,7 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
2991 return GNUNET_OK; 3018 return GNUNET_OK;
2992} 3019}
2993 3020
3021
2994/** 3022/**
2995 * Iterator over all ListenTasks to clean up. 3023 * Iterator over all ListenTasks to clean up.
2996 * 3024 *
@@ -3021,6 +3049,7 @@ get_lt_delete_it (void *cls,
3021 return GNUNET_OK; 3049 return GNUNET_OK;
3022} 3050}
3023 3051
3052
3024/** 3053/**
3025 * Iterator over all message queues to clean up. 3054 * Iterator over all message queues to clean up.
3026 * 3055 *
@@ -3042,6 +3071,7 @@ get_queue_delete_it (void *cls,
3042 return GNUNET_OK; 3071 return GNUNET_OK;
3043} 3072}
3044 3073
3074
3045/** 3075/**
3046 * Shutdown the UNIX communicator. 3076 * Shutdown the UNIX communicator.
3047 * 3077 *
@@ -3182,6 +3212,7 @@ nat_address_cb (void *cls,
3182 } 3212 }
3183} 3213}
3184 3214
3215
3185/** 3216/**
3186 * This method adds addresses to the DLL, that are later register at the NAT service. 3217 * This method adds addresses to the DLL, that are later register at the NAT service.
3187 */ 3218 */
@@ -3211,6 +3242,7 @@ add_addr (struct sockaddr *in, socklen_t in_len)
3211 addrs_lens++; 3242 addrs_lens++;
3212} 3243}
3213 3244
3245
3214/** 3246/**
3215 * This method launch network interactions for each address we like to bind to. 3247 * This method launch network interactions for each address we like to bind to.
3216 * 3248 *
@@ -3226,6 +3258,7 @@ init_socket (struct sockaddr *addr,
3226 socklen_t sto_len; 3258 socklen_t sto_len;
3227 struct GNUNET_NETWORK_Handle *listen_sock; 3259 struct GNUNET_NETWORK_Handle *listen_sock;
3228 struct ListenTask *lt; 3260 struct ListenTask *lt;
3261 int sockfd;
3229 struct GNUNET_HashCode h_sock; 3262 struct GNUNET_HashCode h_sock;
3230 3263
3231 if (NULL == addr) 3264 if (NULL == addr)
@@ -3314,8 +3347,9 @@ init_socket (struct sockaddr *addr,
3314 3347
3315 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3316 "creating hash\n"); 3349 "creating hash\n");
3317 GNUNET_CRYPTO_hash (lt->listen_sock, 3350 sockfd = GNUNET_NETWORK_get_fd (lt->listen_sock);
3318 sizeof(lt->listen_sock), 3351 GNUNET_CRYPTO_hash (&sockfd,
3352 sizeof(int),
3319 &h_sock); 3353 &h_sock);
3320 3354
3321 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3355 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -3336,7 +3370,7 @@ init_socket (struct sockaddr *addr,
3336 if (NULL == queue_map) 3370 if (NULL == queue_map)
3337 queue_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); 3371 queue_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
3338 3372
3339 if (NULL == ch ) 3373 if (NULL == ch)
3340 ch = GNUNET_TRANSPORT_communicator_connect (cfg, 3374 ch = GNUNET_TRANSPORT_communicator_connect (cfg,
3341 COMMUNICATOR_CONFIG_SECTION, 3375 COMMUNICATOR_CONFIG_SECTION,
3342 COMMUNICATOR_ADDRESS_PREFIX, 3376 COMMUNICATOR_ADDRESS_PREFIX,
@@ -3360,6 +3394,7 @@ init_socket (struct sockaddr *addr,
3360 3394
3361} 3395}
3362 3396
3397
3363/** 3398/**
3364 * This method reads from the DLL addrs_head to register them at the NAT service. 3399 * This method reads from the DLL addrs_head to register them at the NAT service.
3365 */ 3400 */
@@ -3421,6 +3456,7 @@ nat_register ()
3421 } 3456 }
3422} 3457}
3423 3458
3459
3424/** 3460/**
3425 * This method is the callback called by the resolver API, and wraps method init_socket. 3461 * This method is the callback called by the resolver API, and wraps method init_socket.
3426 * 3462 *
@@ -3476,6 +3512,7 @@ init_socket_resolv (void *cls,
3476 } 3512 }
3477} 3513}
3478 3514
3515
3479/** 3516/**
3480 * Setup communicator and launch network interactions. 3517 * Setup communicator and launch network interactions.
3481 * 3518 *
@@ -3532,6 +3569,7 @@ run (void *cls,
3532 peerstore = GNUNET_PEERSTORE_connect (cfg); 3569 peerstore = GNUNET_PEERSTORE_connect (cfg);
3533 if (NULL == peerstore) 3570 if (NULL == peerstore)
3534 { 3571 {
3572 GNUNET_free (bindto);
3535 GNUNET_break (0); 3573 GNUNET_break (0);
3536 GNUNET_SCHEDULER_shutdown (); 3574 GNUNET_SCHEDULER_shutdown ();
3537 return; 3575 return;
@@ -3564,7 +3602,6 @@ run (void *cls,
3564 GNUNET_free (po); 3602 GNUNET_free (po);
3565 nat_register (); 3603 nat_register ();
3566 GNUNET_free (bindto); 3604 GNUNET_free (bindto);
3567
3568 return; 3605 return;
3569 } 3606 }
3570 3607
@@ -3577,8 +3614,8 @@ run (void *cls,
3577 in = tcp_address_to_sockaddr_numeric_v4 (&in_len, v4, bind_port); 3614 in = tcp_address_to_sockaddr_numeric_v4 (&in_len, v4, bind_port);
3578 init_socket (in, in_len); 3615 init_socket (in, in_len);
3579 nat_register (); 3616 nat_register ();
3617 GNUNET_free (start);
3580 GNUNET_free (bindto); 3618 GNUNET_free (bindto);
3581
3582 return; 3619 return;
3583 } 3620 }
3584 3621
@@ -3588,8 +3625,8 @@ run (void *cls,
3588 in = tcp_address_to_sockaddr_numeric_v6 (&in_len, v6, bind_port); 3625 in = tcp_address_to_sockaddr_numeric_v6 (&in_len, v6, bind_port);
3589 init_socket (in, in_len); 3626 init_socket (in, in_len);
3590 nat_register (); 3627 nat_register ();
3628 GNUNET_free (start);
3591 GNUNET_free (bindto); 3629 GNUNET_free (bindto);
3592
3593 return; 3630 return;
3594 } 3631 }
3595 3632
@@ -3603,6 +3640,7 @@ run (void *cls,
3603 &init_socket_resolv, 3640 &init_socket_resolv,
3604 &port); 3641 &port);
3605 GNUNET_free (bindto); 3642 GNUNET_free (bindto);
3643 GNUNET_free (start);
3606} 3644}
3607 3645
3608 3646