aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-communicator-tcp.c
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-01-05 13:19:57 +0100
committert3sserakt <t3ss@posteo.de>2021-01-05 13:19:57 +0100
commit5affc9ad078e8d90c47a2972d67cd9d65529792d (patch)
treefe02ace1af4d386044c64ddbb78ad6db0d791d09 /src/transport/gnunet-communicator-tcp.c
parent561596641606ecc0b5f71658c34eab1312ad8f18 (diff)
downloadgnunet-5affc9ad078e8d90c47a2972d67cd9d65529792d.tar.gz
gnunet-5affc9ad078e8d90c47a2972d67cd9d65529792d.zip
- started making tng communicator test code more resilient
Diffstat (limited to 'src/transport/gnunet-communicator-tcp.c')
-rw-r--r--src/transport/gnunet-communicator-tcp.c111
1 files changed, 83 insertions, 28 deletions
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c
index 59f42496a..0c79fc1b4 100644
--- a/src/transport/gnunet-communicator-tcp.c
+++ b/src/transport/gnunet-communicator-tcp.c
@@ -541,6 +541,11 @@ struct Queue
541 enum GNUNET_NetworkType nt; 541 enum GNUNET_NetworkType nt;
542 542
543 /** 543 /**
544 * The connection status of this queue.
545 */
546 enum GNUNET_TRANSPORT_ConnectionStatus cs;
547
548 /**
544 * Is MQ awaiting a #GNUNET_MQ_impl_send_continue() call? 549 * Is MQ awaiting a #GNUNET_MQ_impl_send_continue() call?
545 */ 550 */
546 int mq_awaits_continue; 551 int mq_awaits_continue;
@@ -828,7 +833,8 @@ int addrs_lens;
828/** 833/**
829 * Size of data received without KX challenge played back. 834 * Size of data received without KX challenge played back.
830 */ 835 */
831size_t unverified_size; 836// TODO remove?
837// size_t unverified_size;
832 838
833/** 839/**
834 * Database for peer's HELLOs. 840 * Database for peer's HELLOs.
@@ -1434,6 +1440,9 @@ try_handle_plaintext (struct Queue *queue)
1434 struct TcpHandshakeAckSignature thas; 1440 struct TcpHandshakeAckSignature thas;
1435 const struct ChallengeNonceP challenge = queue->challenge; 1441 const struct ChallengeNonceP challenge = queue->challenge;
1436 1442
1443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1444 "try handle plaintext!\n");
1445
1437 if ((sizeof(*hdr) > queue->pread_off)) 1446 if ((sizeof(*hdr) > queue->pread_off))
1438 { 1447 {
1439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1448 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1441,16 +1450,16 @@ try_handle_plaintext (struct Queue *queue)
1441 return 0; /* not even a header */ 1450 return 0; /* not even a header */
1442 } 1451 }
1443 1452
1444 if ((-1 != unverified_size) && (unverified_size > INITIAL_CORE_KX_SIZE)) 1453 /* if ((-1 != unverified_size) && (unverified_size > INITIAL_CORE_KX_SIZE)) */
1445 { 1454 /* { */
1446 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1455 /* GNUNET_log (GNUNET_ERROR_TYPE_ERROR, */
1447 "Already received data of size %lu bigger than KX size %lu!\n", 1456 /* "Already received data of size %lu bigger than KX size %lu!\n", */
1448 unverified_size, 1457 /* unverified_size, */
1449 INITIAL_CORE_KX_SIZE); 1458 /* INITIAL_CORE_KX_SIZE); */
1450 GNUNET_break_op (0); 1459 /* GNUNET_break_op (0); */
1451 queue_finish (queue); 1460 /* queue_finish (queue); */
1452 return 0; 1461 /* return 0; */
1453 } 1462 /* } */
1454 1463
1455 type = ntohs (hdr->type); 1464 type = ntohs (hdr->type);
1456 switch (type) 1465 switch (type)
@@ -1513,7 +1522,41 @@ try_handle_plaintext (struct Queue *queue)
1513 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1514 "Handling plaintext, ack processed!"); 1523 "Handling plaintext, ack processed!");
1515 1524
1516 unverified_size = -1; 1525 // unverified_size = -1;
1526
1527 /* char *foreign_addr; */
1528
1529 /* switch (queue->address->sa_family) */
1530 /* { */
1531 /* case AF_INET: */
1532 /* GNUNET_asprintf (&foreign_addr, */
1533 /* "%s-%s", */
1534 /* COMMUNICATOR_ADDRESS_PREFIX, */
1535 /* GNUNET_a2s (queue->address, queue->address_len)); */
1536 /* break; */
1537
1538 /* case AF_INET6: */
1539 /* GNUNET_asprintf (&foreign_addr, */
1540 /* "%s-%s", */
1541 /* COMMUNICATOR_ADDRESS_PREFIX, */
1542 /* GNUNET_a2s (queue->address, queue->address_len)); */
1543 /* break; */
1544
1545 /* default: */
1546 /* GNUNET_assert (0); */
1547 /* } */
1548
1549 /* queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch, */
1550 /* &queue->target, */
1551 /* foreign_addr, */
1552 /* 0 /\* no MTU *\/, */
1553 /* GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, */
1554 /* 0, /\* Priority *\/ */
1555 /* queue->nt, */
1556 /* queue->cs, */
1557 /* queue->mq); */
1558
1559 /* GNUNET_free (foreign_addr); */
1517 1560
1518 size = ntohs (hdr->size); 1561 size = ntohs (hdr->size);
1519 break; 1562 break;
@@ -1590,8 +1633,8 @@ try_handle_plaintext (struct Queue *queue)
1590 return 0; 1633 return 0;
1591 } 1634 }
1592 GNUNET_assert (0 != size); 1635 GNUNET_assert (0 != size);
1593 if (-1 != unverified_size) 1636 /* if (-1 != unverified_size) */
1594 unverified_size += size; 1637 /* unverified_size += size; */
1595 return size; 1638 return size;
1596} 1639}
1597 1640
@@ -2139,11 +2182,12 @@ queue_write (void *cls)
2139 queue->cwrite_off += queue->pwrite_off; 2182 queue->cwrite_off += queue->pwrite_off;
2140 queue->pwrite_off = 0; 2183 queue->pwrite_off = 0;
2141 } 2184 }
2142 if ((-1 != unverified_size)&& ((0 == queue->pwrite_off) && 2185 // if ((-1 != unverified_size)&& ((0 == queue->pwrite_off) &&
2143 ((0 == queue->rekey_left_bytes) || 2186 if (((0 == queue->pwrite_off) &&
2144 (0 == 2187 ((0 == queue->rekey_left_bytes) ||
2145 GNUNET_TIME_absolute_get_remaining ( 2188 (0 ==
2146 queue->rekey_time).rel_value_us)))) 2189 GNUNET_TIME_absolute_get_remaining (
2190 queue->rekey_time).rel_value_us))))
2147 { 2191 {
2148 inject_rekey (queue); 2192 inject_rekey (queue);
2149 } 2193 }
@@ -2282,7 +2326,7 @@ mq_error (void *cls, enum GNUNET_MQ_Error error)
2282 * @param queue queue to boot 2326 * @param queue queue to boot
2283 */ 2327 */
2284static void 2328static void
2285boot_queue (struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs) 2329boot_queue (struct Queue *queue)
2286{ 2330{
2287 queue->nt = 2331 queue->nt =
2288 GNUNET_NT_scanner_get_type (is, queue->address, queue->address_len); 2332 GNUNET_NT_scanner_get_type (is, queue->address, queue->address_len);
@@ -2333,7 +2377,7 @@ boot_queue (struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs)
2333 GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, 2377 GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED,
2334 0, /* Priority */ 2378 0, /* Priority */
2335 queue->nt, 2379 queue->nt,
2336 cs, 2380 queue->cs,
2337 queue->mq); 2381 queue->mq);
2338 GNUNET_free (foreign_addr); 2382 GNUNET_free (foreign_addr);
2339 } 2383 }
@@ -2557,7 +2601,7 @@ free_proto_queue (struct ProtoQueue *pq)
2557 * @param queue The queue context. 2601 * @param queue The queue context.
2558 */ 2602 */
2559static void 2603static void
2560send_challenge (struct TCPConfirmation tc, struct Queue *queue) 2604send_challenge (struct ChallengeNonceP challenge, struct Queue *queue)
2561{ 2605{
2562 struct TCPConfirmationAck tca; 2606 struct TCPConfirmationAck tca;
2563 struct TcpHandshakeAckSignature thas; 2607 struct TcpHandshakeAckSignature thas;
@@ -2569,7 +2613,7 @@ send_challenge (struct TCPConfirmation tc, struct Queue *queue)
2569 tca.header.type = ntohs ( 2613 tca.header.type = ntohs (
2570 GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK); 2614 GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_CONFIRMATION_ACK);
2571 tca.header.size = ntohs (sizeof(tca)); 2615 tca.header.size = ntohs (sizeof(tca));
2572 tca.challenge = tc.challenge; 2616 tca.challenge = challenge;
2573 tca.sender = my_identity; 2617 tca.sender = my_identity;
2574 tca.monotonic_time = 2618 tca.monotonic_time =
2575 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); 2619 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg));
@@ -2665,7 +2709,8 @@ proto_read_kx (void *cls)
2665 "start kx proto\n"); 2709 "start kx proto\n");
2666 2710
2667 start_initial_kx_out (queue); 2711 start_initial_kx_out (queue);
2668 boot_queue (queue, GNUNET_TRANSPORT_CS_INBOUND); 2712 queue->cs = GNUNET_TRANSPORT_CS_INBOUND;
2713 boot_queue (queue);
2669 queue->read_task = 2714 queue->read_task =
2670 GNUNET_SCHEDULER_add_read_net (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2715 GNUNET_SCHEDULER_add_read_net (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
2671 queue->sock, 2716 queue->sock,
@@ -2676,7 +2721,8 @@ proto_read_kx (void *cls)
2676 queue->sock, 2721 queue->sock,
2677 &queue_write, 2722 &queue_write,
2678 queue); 2723 queue);
2679 send_challenge (tc, queue); 2724 // TODO To early! Move it somewhere else.
2725 // send_challenge (tc, queue);
2680 2726
2681 GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq); 2727 GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq);
2682 GNUNET_free (pq); 2728 GNUNET_free (pq);
@@ -2762,7 +2808,9 @@ queue_read_kx (void *cls)
2762 rcvd = GNUNET_NETWORK_socket_recv (queue->sock, 2808 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
2763 &queue->cread_buf[queue->cread_off], 2809 &queue->cread_buf[queue->cread_off],
2764 BUF_SIZE - queue->cread_off); 2810 BUF_SIZE - queue->cread_off);
2765 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %lu bytes for KX\n", rcvd); 2811 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2812 "Received %lu bytes for KX\n",
2813 rcvd);
2766 if (-1 == rcvd) 2814 if (-1 == rcvd)
2767 { 2815 {
2768 if ((EAGAIN != errno) && (EINTR != errno)) 2816 if ((EAGAIN != errno) && (EINTR != errno))
@@ -2804,14 +2852,20 @@ queue_read_kx (void *cls)
2804 queue_destroy (queue); 2852 queue_destroy (queue);
2805 return; 2853 return;
2806 } 2854 }
2807 send_challenge (tc, queue); 2855 send_challenge (tc.challenge, queue);
2808 /* update queue timeout */ 2856 /* update queue timeout */
2809 reschedule_queue_timeout (queue); 2857 reschedule_queue_timeout (queue);
2810 /* prepare to continue with regular read task immediately */ 2858 /* prepare to continue with regular read task immediately */
2811 memmove (queue->cread_buf, 2859 memmove (queue->cread_buf,
2812 &queue->cread_buf[INITIAL_KX_SIZE], 2860 &queue->cread_buf[INITIAL_KX_SIZE],
2813 queue->cread_off - (INITIAL_KX_SIZE)); 2861 queue->cread_off - (INITIAL_KX_SIZE));
2862 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2863 "cread_off is %lu bytes before adjusting\n",
2864 queue->cread_off);
2814 queue->cread_off -= INITIAL_KX_SIZE; 2865 queue->cread_off -= INITIAL_KX_SIZE;
2866 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2867 "cread_off set to %lu bytes\n",
2868 queue->cread_off);
2815 if (0 < queue->cread_off) 2869 if (0 < queue->cread_off)
2816 queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue); 2870 queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue);
2817} 2871}
@@ -2893,7 +2947,8 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
2893 queue->address = in; 2947 queue->address = in;
2894 queue->address_len = in_len; 2948 queue->address_len = in_len;
2895 queue->sock = sock; 2949 queue->sock = sock;
2896 boot_queue (queue, GNUNET_TRANSPORT_CS_OUTBOUND); 2950 queue->cs = GNUNET_TRANSPORT_CS_OUTBOUND;
2951 boot_queue (queue);
2897 // queue->mq_awaits_continue = GNUNET_YES; 2952 // queue->mq_awaits_continue = GNUNET_YES;
2898 queue->read_task = 2953 queue->read_task =
2899 GNUNET_SCHEDULER_add_read_net (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2954 GNUNET_SCHEDULER_add_read_net (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,