aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-communicator-tcp.c
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2019-12-25 19:38:59 +0900
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-12-25 19:38:59 +0900
commitd0f2906ee9d65568ae9c859680706cf7b0bdaf0c (patch)
tree7b7cc4bbcfe5aa7d0466aa940a229855b3defdc1 /src/transport/gnunet-communicator-tcp.c
parent99d3589e5515d251be07f9b4d72bdcc75c300a33 (diff)
downloadgnunet-d0f2906ee9d65568ae9c859680706cf7b0bdaf0c.tar.gz
gnunet-d0f2906ee9d65568ae9c859680706cf7b0bdaf0c.zip
more minor communicator fixes
Diffstat (limited to 'src/transport/gnunet-communicator-tcp.c')
-rw-r--r--src/transport/gnunet-communicator-tcp.c51
1 files changed, 38 insertions, 13 deletions
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c
index b577a96a6..7207eb922 100644
--- a/src/transport/gnunet-communicator-tcp.c
+++ b/src/transport/gnunet-communicator-tcp.c
@@ -1002,6 +1002,8 @@ queue_read (void *cls)
1002 rcvd = GNUNET_NETWORK_socket_recv (queue->sock, 1002 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
1003 &queue->cread_buf[queue->cread_off], 1003 &queue->cread_buf[queue->cread_off],
1004 BUF_SIZE - queue->cread_off); 1004 BUF_SIZE - queue->cread_off);
1005 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1006 "Received %lu bytes from TCP queue\n", rcvd);
1005 if (-1 == rcvd) 1007 if (-1 == rcvd)
1006 { 1008 {
1007 if ((EAGAIN != errno) && (EINTR != errno)) 1009 if ((EAGAIN != errno) && (EINTR != errno))
@@ -1011,6 +1013,7 @@ queue_read (void *cls)
1011 return; 1013 return;
1012 } 1014 }
1013 /* try again */ 1015 /* try again */
1016 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
1014 queue->read_task = 1017 queue->read_task =
1015 GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue); 1018 GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
1016 return; 1019 return;
@@ -1052,7 +1055,8 @@ queue_read (void *cls)
1052 wrong key for everything after the rekey; in that case, we have 1055 wrong key for everything after the rekey; in that case, we have
1053 to re-do the decryption at 'total' instead of at 'max'. If there 1056 to re-do the decryption at 'total' instead of at 'max'. If there
1054 is no rekey and the last message is incomplete (max > total), 1057 is no rekey and the last message is incomplete (max > total),
1055 it is safe to keep the decryption so we shift by 'max' */if (GNUNET_YES == queue->rekeyed) 1058 it is safe to keep the decryption so we shift by 'max' */
1059 if (GNUNET_YES == queue->rekeyed)
1056 { 1060 {
1057 max = total; 1061 max = total;
1058 queue->rekeyed = GNUNET_NO; 1062 queue->rekeyed = GNUNET_NO;
@@ -1069,6 +1073,7 @@ queue_read (void *cls)
1069 if (max_queue_length < queue->backpressure) 1073 if (max_queue_length < queue->backpressure)
1070 { 1074 {
1071 /* continue reading */ 1075 /* continue reading */
1076 left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
1072 queue->read_task = 1077 queue->read_task =
1073 GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue); 1078 GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
1074 } 1079 }
@@ -1122,7 +1127,7 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
1122 i4->sin_family = AF_INET; 1127 i4->sin_family = AF_INET;
1123 i4->sin_port = htons ((uint16_t) port); 1128 i4->sin_port = htons ((uint16_t) port);
1124#if HAVE_SOCKADDR_IN_SIN_LEN 1129#if HAVE_SOCKADDR_IN_SIN_LEN
1125 sa4.sin_len = sizeof(sizeof(struct sockaddr_in)); 1130 i4->sin_len = sizeof(sizeof(struct sockaddr_in));
1126#endif 1131#endif
1127 *sock_len = sizeof(struct sockaddr_in); 1132 *sock_len = sizeof(struct sockaddr_in);
1128 in = (struct sockaddr *) i4; 1133 in = (struct sockaddr *) i4;
@@ -1135,7 +1140,7 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
1135 i6->sin6_family = AF_INET6; 1140 i6->sin6_family = AF_INET6;
1136 i6->sin6_port = htons ((uint16_t) port); 1141 i6->sin6_port = htons ((uint16_t) port);
1137#if HAVE_SOCKADDR_IN_SIN_LEN 1142#if HAVE_SOCKADDR_IN_SIN_LEN
1138 sa6.sin6_len = sizeof(sizeof(struct sockaddr_in6)); 1143 i6->sin6_len = sizeof(sizeof(struct sockaddr_in6));
1139#endif 1144#endif
1140 *sock_len = sizeof(struct sockaddr_in6); 1145 *sock_len = sizeof(struct sockaddr_in6);
1141 in = (struct sockaddr *) i6; 1146 in = (struct sockaddr *) i6;
@@ -1182,6 +1187,7 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
1182 1187
1183 if (1 == inet_pton (AF_INET, cp, &v4)) 1188 if (1 == inet_pton (AF_INET, cp, &v4))
1184 { 1189 {
1190 v4.sin_family = AF_INET;
1185 v4.sin_port = htons ((uint16_t) port); 1191 v4.sin_port = htons ((uint16_t) port);
1186 in = GNUNET_memdup (&v4, sizeof(v4)); 1192 in = GNUNET_memdup (&v4, sizeof(v4));
1187 *sock_len = sizeof(v4); 1193 *sock_len = sizeof(v4);
@@ -1202,6 +1208,7 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
1202 } 1208 }
1203 if (1 == inet_pton (AF_INET6, start, &v6)) 1209 if (1 == inet_pton (AF_INET6, start, &v6))
1204 { 1210 {
1211 v6.sin6_family = AF_INET6;
1205 v6.sin6_port = htons ((uint16_t) port); 1212 v6.sin6_port = htons ((uint16_t) port);
1206 in = GNUNET_memdup (&v6, sizeof(v6)); 1213 in = GNUNET_memdup (&v6, sizeof(v6));
1207 *sock_len = sizeof(v6); 1214 *sock_len = sizeof(v6);
@@ -1283,13 +1290,15 @@ queue_write (void *cls)
1283{ 1290{
1284 struct Queue *queue = cls; 1291 struct Queue *queue = cls;
1285 ssize_t sent; 1292 ssize_t sent;
1286 1293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "In queue write\n");
1287 queue->write_task = NULL; 1294 queue->write_task = NULL;
1288 if (0 != queue->cwrite_off) 1295 if (0 != queue->cwrite_off)
1289 { 1296 {
1290 sent = GNUNET_NETWORK_socket_send (queue->sock, 1297 sent = GNUNET_NETWORK_socket_send (queue->sock,
1291 queue->cwrite_buf, 1298 queue->cwrite_buf,
1292 queue->cwrite_off); 1299 queue->cwrite_off);
1300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1301 "Sent %lu bytes to TCP queue\n", sent);
1293 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno)) 1302 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1294 { 1303 {
1295 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); 1304 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send");
@@ -1299,18 +1308,21 @@ queue_write (void *cls)
1299 if (sent > 0) 1308 if (sent > 0)
1300 { 1309 {
1301 size_t usent = (size_t) sent; 1310 size_t usent = (size_t) sent;
1302 1311 queue->cwrite_off -= usent;
1303 memmove (queue->cwrite_buf, 1312 memmove (queue->cwrite_buf,
1304 &queue->cwrite_buf[usent], 1313 &queue->cwrite_buf[usent],
1305 queue->cwrite_off - usent); 1314 queue->cwrite_off);
1306 reschedule_queue_timeout (queue); 1315 reschedule_queue_timeout (queue);
1307 } 1316 }
1308 } 1317 }
1309 /* can we encrypt more? (always encrypt full messages, needed 1318 /* can we encrypt more? (always encrypt full messages, needed
1310 such that #mq_cancel() can work!) */ 1319 such that #mq_cancel() can work!) */
1311 if ((0 < queue->rekey_left_bytes) && 1320 if ((0 < queue->rekey_left_bytes) &&
1321 (queue->pwrite_off > 0) &&
1312 (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE)) 1322 (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE))
1313 { 1323 {
1324 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1325 "Encrypting %lu bytes\n", queue->pwrite_off);
1314 GNUNET_assert (0 == 1326 GNUNET_assert (0 ==
1315 gcry_cipher_encrypt (queue->out_cipher, 1327 gcry_cipher_encrypt (queue->out_cipher,
1316 &queue->cwrite_buf[queue->cwrite_off], 1328 &queue->cwrite_buf[queue->cwrite_off],
@@ -1342,6 +1354,8 @@ queue_write (void *cls)
1342 /* did we just finish writing 'finish'? */ 1354 /* did we just finish writing 'finish'? */
1343 if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing)) 1355 if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing))
1344 { 1356 {
1357 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1358 "Finishing queue\n");
1345 queue_destroy (queue); 1359 queue_destroy (queue);
1346 return; 1360 return;
1347 } 1361 }
@@ -1371,18 +1385,23 @@ mq_send (struct GNUNET_MQ_Handle *mq,
1371 struct Queue *queue = impl_state; 1385 struct Queue *queue = impl_state;
1372 uint16_t msize = ntohs (msg->size); 1386 uint16_t msize = ntohs (msg->size);
1373 struct TCPBox box; 1387 struct TCPBox box;
1374 1388 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1389 "In MQ send. Queue finishing: %s; write task running: %s\n",
1390 (GNUNET_YES == queue->finishing) ? "yes" : "no",
1391 (NULL == queue->write_task) ? "yes" : "no");
1375 GNUNET_assert (mq == queue->mq); 1392 GNUNET_assert (mq == queue->mq);
1376 if (GNUNET_YES == queue->finishing) 1393 if (GNUNET_YES == queue->finishing)
1377 return; /* this queue is dying, drop msg */ 1394 return; /* this queue is dying, drop msg */
1378 GNUNET_assert (0 == queue->pread_off); 1395 GNUNET_assert (0 == queue->pwrite_off);
1379 box.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX); 1396 box.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX);
1380 box.header.size = htons (msize); 1397 box.header.size = htons (msize);
1381 calculate_hmac (&queue->out_hmac, msg, msize, &box.hmac); 1398 calculate_hmac (&queue->out_hmac, msg, msize, &box.hmac);
1382 memcpy (&queue->pread_buf[queue->pread_off], &box, sizeof(box)); 1399 memcpy (&queue->pwrite_buf[queue->pwrite_off], &box, sizeof(box));
1383 queue->pread_off += sizeof(box); 1400 queue->pwrite_off += sizeof(box);
1384 memcpy (&queue->pread_buf[queue->pread_off], msg, msize); 1401 memcpy (&queue->pwrite_buf[queue->pwrite_off], msg, msize);
1385 queue->pread_off += msize; 1402 queue->pwrite_off += msize;
1403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1404 "%lu bytes of plaintext to send\n", queue->pwrite_off);
1386 GNUNET_assert (NULL != queue->sock); 1405 GNUNET_assert (NULL != queue->sock);
1387 if (NULL == queue->write_task) 1406 if (NULL == queue->write_task)
1388 queue->write_task = 1407 queue->write_task =
@@ -1659,6 +1678,8 @@ proto_read_kx (void *cls)
1659 rcvd = GNUNET_NETWORK_socket_recv (pq->sock, 1678 rcvd = GNUNET_NETWORK_socket_recv (pq->sock,
1660 &pq->ibuf[pq->ibuf_off], 1679 &pq->ibuf[pq->ibuf_off],
1661 sizeof(pq->ibuf) - pq->ibuf_off); 1680 sizeof(pq->ibuf) - pq->ibuf_off);
1681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1682 "Received %lu bytes for KX\n", rcvd);
1662 if (-1 == rcvd) 1683 if (-1 == rcvd)
1663 { 1684 {
1664 if ((EAGAIN != errno) && (EINTR != errno)) 1685 if ((EAGAIN != errno) && (EINTR != errno))
@@ -1787,6 +1808,7 @@ queue_read_kx (void *cls)
1787 rcvd = GNUNET_NETWORK_socket_recv (queue->sock, 1808 rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
1788 &queue->cread_buf[queue->cread_off], 1809 &queue->cread_buf[queue->cread_off],
1789 BUF_SIZE - queue->cread_off); 1810 BUF_SIZE - queue->cread_off);
1811 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %lu bytes for KX\n", rcvd);
1790 if (-1 == rcvd) 1812 if (-1 == rcvd)
1791 { 1813 {
1792 if ((EAGAIN != errno) && (EINTR != errno)) 1814 if ((EAGAIN != errno) && (EINTR != errno))
@@ -1867,6 +1889,8 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
1867 socklen_t in_len; 1889 socklen_t in_len;
1868 struct GNUNET_NETWORK_Handle *sock; 1890 struct GNUNET_NETWORK_Handle *sock;
1869 1891
1892 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1893 "Connecting to %s\n", address);
1870 if (0 != strncmp (address, 1894 if (0 != strncmp (address,
1871 COMMUNICATOR_ADDRESS_PREFIX "-", 1895 COMMUNICATOR_ADDRESS_PREFIX "-",
1872 strlen (COMMUNICATOR_ADDRESS_PREFIX "-"))) 1896 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
@@ -1887,7 +1911,8 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
1887 GNUNET_free (in); 1911 GNUNET_free (in);
1888 return GNUNET_SYSERR; 1912 return GNUNET_SYSERR;
1889 } 1913 }
1890 if (GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len)) 1914 if (GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len) &&
1915 (errno != EINPROGRESS))
1891 { 1916 {
1892 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1917 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1893 "connect to `%s' failed: %s", 1918 "connect to `%s' failed: %s",