aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-10-02 13:02:40 +0000
committerChristian Grothoff <christian@grothoff.org>2009-10-02 13:02:40 +0000
commit469af5f00bfb33005f4243b8ec69eba5ad1f13b0 (patch)
tree7889d3b040e4d8572193321a42f2d4e5175d3bc5 /src/transport
parentefa85025f9c5d19fa371881f23098ae02b781329 (diff)
downloadgnunet-469af5f00bfb33005f4243b8ec69eba5ad1f13b0.tar.gz
gnunet-469af5f00bfb33005f4243b8ec69eba5ad1f13b0.zip
misc bugfixes
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-transport.c92
-rw-r--r--src/transport/plugin_transport_tcp.c57
-rw-r--r--src/transport/test_transport_api.c5
-rw-r--r--src/transport/test_transport_api_peer1.conf5
-rw-r--r--src/transport/test_transport_api_peer2.conf3
-rw-r--r--src/transport/transport_api.c4
6 files changed, 114 insertions, 52 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index 09f87d444..49ed6f468 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -67,8 +67,13 @@
67 67
68/** 68/**
69 * How long until a HELLO verification attempt should time out? 69 * How long until a HELLO verification attempt should time out?
70 * Must be rather small, otherwise a partially successful HELLO
71 * validation (some addresses working) might not be available
72 * before a client's request for a connection fails for good.
73 * Besides, if a single request to an address takes a long time,
74 * then the peer is unlikely worthwhile anyway.
70 */ 75 */
71#define HELLO_VERIFICATION_TIMEOUT GNUNET_TIME_UNIT_MINUTES 76#define HELLO_VERIFICATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
72 77
73/** 78/**
74 * How often do we re-add (cheaper) plugins to our list of plugins 79 * How often do we re-add (cheaper) plugins to our list of plugins
@@ -692,6 +697,11 @@ transmit_to_client_callback (void *cls, size_t size, void *buf)
692 msize = ntohs (msg->size); 697 msize = ntohs (msg->size);
693 if (msize + tsize > size) 698 if (msize + tsize > size)
694 break; 699 break;
700#if DEBUG_TRANSPORT
701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
702 "Transmitting message of type %u to client.\n",
703 ntohs (msg->type));
704#endif
695 client->message_queue_head = q->next; 705 client->message_queue_head = q->next;
696 if (q->next == NULL) 706 if (q->next == NULL)
697 client->message_queue_tail = NULL; 707 client->message_queue_tail = NULL;
@@ -1451,6 +1461,7 @@ cleanup_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1451 struct ValidationList *pos; 1461 struct ValidationList *pos;
1452 struct ValidationList *prev; 1462 struct ValidationList *prev;
1453 struct GNUNET_TIME_Absolute now; 1463 struct GNUNET_TIME_Absolute now;
1464 struct GNUNET_TIME_Absolute first;
1454 struct GNUNET_HELLO_Message *hello; 1465 struct GNUNET_HELLO_Message *hello;
1455 struct GNUNET_PeerIdentity pid; 1466 struct GNUNET_PeerIdentity pid;
1456 struct NeighbourList *n; 1467 struct NeighbourList *n;
@@ -1506,16 +1517,22 @@ cleanup_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1506 1517
1507 /* finally, reschedule cleanup if needed; list is 1518 /* finally, reschedule cleanup if needed; list is
1508 ordered by timeout, so we need the last element... */ 1519 ordered by timeout, so we need the last element... */
1509 pos = pending_validations; 1520 if (NULL != pending_validations)
1510 while ((pos != NULL) && (pos->next != NULL)) 1521 {
1511 pos = pos->next; 1522 first = pos->timeout;
1512 if (NULL != pos) 1523 pos = pending_validations;
1513 GNUNET_SCHEDULER_add_delayed (sched, 1524 while (pos != NULL)
1514 GNUNET_NO, 1525 {
1515 GNUNET_SCHEDULER_PRIORITY_IDLE, 1526 first = GNUNET_TIME_absolute_min (first, pos->timeout);
1516 GNUNET_SCHEDULER_NO_TASK, 1527 pos = pos->next;
1517 GNUNET_TIME_absolute_get_remaining 1528 }
1518 (pos->timeout), &cleanup_validation, NULL); 1529 GNUNET_SCHEDULER_add_delayed (sched,
1530 GNUNET_NO,
1531 GNUNET_SCHEDULER_PRIORITY_IDLE,
1532 GNUNET_SCHEDULER_NO_TASK,
1533 GNUNET_TIME_absolute_get_remaining (first),
1534 &cleanup_validation, NULL);
1535 }
1519} 1536}
1520 1537
1521 1538
@@ -1543,7 +1560,7 @@ plugin_env_notify_validation (void *cls,
1543 uint32_t challenge, 1560 uint32_t challenge,
1544 const char *sender_addr) 1561 const char *sender_addr)
1545{ 1562{
1546 int all_done; 1563 unsigned int not_done;
1547 int matched; 1564 int matched;
1548 struct ValidationList *pos; 1565 struct ValidationList *pos;
1549 struct ValidationAddress *va; 1566 struct ValidationAddress *va;
@@ -1570,7 +1587,7 @@ plugin_env_notify_validation (void *cls,
1570 GNUNET_i2s(peer)); 1587 GNUNET_i2s(peer));
1571 return; 1588 return;
1572 } 1589 }
1573 all_done = GNUNET_YES; 1590 not_done = 0;
1574 matched = GNUNET_NO; 1591 matched = GNUNET_NO;
1575 va = pos->addresses; 1592 va = pos->addresses;
1576 while (va != NULL) 1593 while (va != NULL)
@@ -1579,7 +1596,10 @@ plugin_env_notify_validation (void *cls,
1579 { 1596 {
1580#if DEBUG_TRANSPORT 1597#if DEBUG_TRANSPORT
1581 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1598 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1582 "Confirmed validity of peer address.\n"); 1599 "Confirmed validity of address, peer `%4s' has address `%s'.\n",
1600 GNUNET_i2s (peer),
1601 GNUNET_a2s ((const struct sockaddr*) &va[1],
1602 va->addr_len));
1583#endif 1603#endif
1584 GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, 1604 GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
1585 _("Another peer saw us using the address `%s' via `%s'. If this is not plausible, this address should be listed in the configuration as implausible to avoid MiM attacks.\n"), 1605 _("Another peer saw us using the address `%s' via `%s'. If this is not plausible, this address should be listed in the configuration as implausible to avoid MiM attacks.\n"),
@@ -1591,7 +1611,7 @@ plugin_env_notify_validation (void *cls,
1591 matched = GNUNET_YES; 1611 matched = GNUNET_YES;
1592 } 1612 }
1593 if (va->ok != GNUNET_YES) 1613 if (va->ok != GNUNET_YES)
1594 all_done = GNUNET_NO; 1614 not_done++;
1595 va = va->next; 1615 va = va->next;
1596 } 1616 }
1597 if (GNUNET_NO == matched) 1617 if (GNUNET_NO == matched)
@@ -1602,8 +1622,14 @@ plugin_env_notify_validation (void *cls,
1602 ("Received `%s' message but have no record of a matching `%s' message. Ignoring.\n"), 1622 ("Received `%s' message but have no record of a matching `%s' message. Ignoring.\n"),
1603 "PONG", "PING"); 1623 "PONG", "PING");
1604 } 1624 }
1605 if (GNUNET_YES == all_done) 1625 if (0 == not_done)
1606 { 1626 {
1627#if DEBUG_TRANSPORT
1628 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1629 "All addresses validated, will now construct `%s' for `%4s'.\n",
1630 "HELLO",
1631 GNUNET_i2s (peer));
1632#endif
1607 pos->timeout.value = 0; 1633 pos->timeout.value = 0;
1608 GNUNET_SCHEDULER_add_delayed (sched, 1634 GNUNET_SCHEDULER_add_delayed (sched,
1609 GNUNET_NO, 1635 GNUNET_NO,
@@ -1612,6 +1638,17 @@ plugin_env_notify_validation (void *cls,
1612 GNUNET_TIME_UNIT_ZERO, 1638 GNUNET_TIME_UNIT_ZERO,
1613 &cleanup_validation, NULL); 1639 &cleanup_validation, NULL);
1614 } 1640 }
1641 else
1642 {
1643#if DEBUG_TRANSPORT
1644 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1645 "Still waiting for %u additional `%s' messages before constructing `%s' for `%4s'.\n",
1646 not_done,
1647 "PONG",
1648 "HELLO",
1649 GNUNET_i2s (peer));
1650#endif
1651 }
1615} 1652}
1616 1653
1617 1654
@@ -1731,14 +1768,21 @@ check_hello_validated (void *cls,
1731 GNUNET_assert (GNUNET_OK == 1768 GNUNET_assert (GNUNET_OK ==
1732 GNUNET_HELLO_get_id (chvc->hello, 1769 GNUNET_HELLO_get_id (chvc->hello,
1733 &apeer)); 1770 &apeer));
1771#if DEBUG_TRANSPORT
1772 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1773 "Ready to validate addresses from `%s' message for peer `%4s'\n",
1774 "HELLO", GNUNET_i2s (&apeer));
1775#endif
1734 va = chvc->e->addresses; 1776 va = chvc->e->addresses;
1735 while (va != NULL) 1777 while (va != NULL)
1736 { 1778 {
1737#if DEBUG_TRANSPORT 1779#if DEBUG_TRANSPORT
1738 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1780 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1739 "Establishing `%s' connection to validate `%s' of `%4s'\n", 1781 "Establishing `%s' connection to validate `%s' address `%s' of `%4s'\n",
1740 va->transport_name, 1782 va->transport_name,
1741 "HELLO", 1783 "HELLO",
1784 GNUNET_a2s ((const struct sockaddr*) &va[1],
1785 va->addr_len),
1742 GNUNET_i2s (&apeer)); 1786 GNUNET_i2s (&apeer));
1743#endif 1787#endif
1744 tp = find_transport (va->transport_name); 1788 tp = find_transport (va->transport_name);
@@ -1753,14 +1797,12 @@ check_hello_validated (void *cls,
1753 va->ok = GNUNET_SYSERR; 1797 va->ok = GNUNET_SYSERR;
1754 va = va->next; 1798 va = va->next;
1755 } 1799 }
1756 if (chvc->e->next == NULL) 1800 GNUNET_SCHEDULER_add_delayed (sched,
1757 GNUNET_SCHEDULER_add_delayed (sched, 1801 GNUNET_NO,
1758 GNUNET_NO, 1802 GNUNET_SCHEDULER_PRIORITY_IDLE,
1759 GNUNET_SCHEDULER_PRIORITY_IDLE, 1803 GNUNET_SCHEDULER_NO_TASK,
1760 GNUNET_SCHEDULER_NO_TASK, 1804 GNUNET_TIME_absolute_get_remaining (chvc->e->timeout),
1761 GNUNET_TIME_absolute_get_remaining 1805 &cleanup_validation, NULL);
1762 (chvc->e->timeout), &cleanup_validation,
1763 NULL);
1764 GNUNET_free (chvc); 1806 GNUNET_free (chvc);
1765} 1807}
1766 1808
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index bfa17d275..15afeab3d 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -39,7 +39,7 @@
39#include "plugin_transport.h" 39#include "plugin_transport.h"
40#include "transport.h" 40#include "transport.h"
41 41
42#define DEBUG_TCP GNUNET_NO 42#define DEBUG_TCP GNUNET_YES
43 43
44/** 44/**
45 * After how long do we expire an address that we 45 * After how long do we expire an address that we
@@ -1490,8 +1490,17 @@ handle_tcp_ping (void *cls,
1490 void *addr; 1490 void *addr;
1491 1491
1492#if DEBUG_TRANSPORT 1492#if DEBUG_TRANSPORT
1493 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 1493 if (GNUNET_OK ==
1494 "Processing PING\n"); 1494 GNUNET_SERVER_client_get_address (client,
1495 (void **) &addr,
1496 &addrlen))
1497 {
1498 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
1499 "Processing `%s' from `%s'\n",
1500 "PING",
1501 GNUNET_a2s (addr, addrlen));
1502 GNUNET_free (addr);
1503 }
1495#endif 1504#endif
1496 msize = ntohs (message->size); 1505 msize = ntohs (message->size);
1497 if (msize < sizeof (struct ValidationChallengeMessage)) 1506 if (msize < sizeof (struct ValidationChallengeMessage))
@@ -1570,23 +1579,10 @@ handle_tcp_ping (void *cls,
1570 1579
1571 1580
1572/** 1581/**
1573 * Handle PING-message. If the plugin that gave us the message is 1582 * Handle PONG-message.
1574 * able to queue the PONG immediately, we only queue one PONG.
1575 * Otherwise we send at most TWO PONG messages, one via an unconfirmed
1576 * transport and one via a confirmed transport. Both addresses are
1577 * selected randomly among those available.
1578 *
1579 * @param plugin plugin that gave us the message
1580 * @param sender claimed sender of the PING
1581 * @param plugin_context context that might be used to send response
1582 * @param message the actual message
1583 */
1584/**
1585 * We've received a PING from this peer via TCP.
1586 * Send back our PONG.
1587 * 1583 *
1588 * @param cls closure 1584 * @param plugin handle for this plugin
1589 * @param client identification of the client 1585 * @param sender claimed sender of the PONG
1590 * @param message the actual message 1586 * @param message the actual message
1591 */ 1587 */
1592static void 1588static void
@@ -1604,8 +1600,19 @@ handle_tcp_pong (void *cls,
1604 struct sockaddr_in6 v6; 1600 struct sockaddr_in6 v6;
1605 1601
1606#if DEBUG_TRANSPORT 1602#if DEBUG_TRANSPORT
1607 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 1603 struct sockaddr *claddr;
1608 "Processing PONG\n"); 1604
1605 if (GNUNET_OK ==
1606 GNUNET_SERVER_client_get_address (client,
1607 (void**) &claddr,
1608 &addrlen))
1609 {
1610 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
1611 "Processing `%s' from `%s'\n",
1612 "PONG",
1613 GNUNET_a2s (claddr, addrlen));
1614 GNUNET_free (claddr);
1615 }
1609#endif 1616#endif
1610 if (ntohs(message->size) < sizeof(struct ValidationChallengeResponse)) 1617 if (ntohs(message->size) < sizeof(struct ValidationChallengeResponse))
1611 { 1618 {
@@ -2002,9 +2009,11 @@ process_hostname_ips (void *cls,
2002 2009
2003 if (addr == NULL) 2010 if (addr == NULL)
2004 return; 2011 return;
2005 plugin->env->notify_address (plugin->env->cls, 2012 process_interfaces (plugin,
2006 "tcp", 2013 "<hostname>",
2007 addr, addrlen, GNUNET_TIME_UNIT_FOREVER_REL); 2014 GNUNET_YES,
2015 addr,
2016 addrlen);
2008} 2017}
2009 2018
2010 2019
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c
index 2aa12bcbd..881c75019 100644
--- a/src/transport/test_transport_api.c
+++ b/src/transport/test_transport_api.c
@@ -223,7 +223,8 @@ exchange_hello (void *cls,
223 GNUNET_assert (GNUNET_OK == 223 GNUNET_assert (GNUNET_OK ==
224 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 224 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
225 message, &me->id)); 225 message, &me->id));
226 GNUNET_TRANSPORT_get_hello (p2.th, GNUNET_TIME_UNIT_MINUTES, 226 GNUNET_TRANSPORT_get_hello (p2.th,
227 TIMEOUT,
227 &exchange_hello_last, &p2); 228 &exchange_hello_last, &p2);
228} 229}
229 230
@@ -241,7 +242,7 @@ run (void *cls,
241 setup_peer (&p1, "test_transport_api_peer1.conf"); 242 setup_peer (&p1, "test_transport_api_peer1.conf");
242 setup_peer (&p2, "test_transport_api_peer2.conf"); 243 setup_peer (&p2, "test_transport_api_peer2.conf");
243 GNUNET_TRANSPORT_get_hello (p1.th, 244 GNUNET_TRANSPORT_get_hello (p1.th,
244 GNUNET_TIME_UNIT_MINUTES, &exchange_hello, &p1); 245 TIMEOUT, &exchange_hello, &p1);
245} 246}
246 247
247 248
diff --git a/src/transport/test_transport_api_peer1.conf b/src/transport/test_transport_api_peer1.conf
index 2957ec3e7..606ab8224 100644
--- a/src/transport/test_transport_api_peer1.conf
+++ b/src/transport/test_transport_api_peer1.conf
@@ -9,7 +9,10 @@ HOSTNAME = localhost
9[transport] 9[transport]
10PORT = 12365 10PORT = 12365
11PLUGINS = tcp 11PLUGINS = tcp
12#DEBUG = YES 12DEBUG = YES
13#PREFIX = xterm -T t1 -e gdb -x cmd --args
14#BINARY = /home/grothoff/bin/gnunet-service-transport
15#PREFIX = valgrind --tool=memcheck
13 16
14[arm] 17[arm]
15PORT = 12366 18PORT = 12366
diff --git a/src/transport/test_transport_api_peer2.conf b/src/transport/test_transport_api_peer2.conf
index 7f98ba3cf..ea746f9c1 100644
--- a/src/transport/test_transport_api_peer2.conf
+++ b/src/transport/test_transport_api_peer2.conf
@@ -10,6 +10,9 @@ HOSTNAME = localhost
10PORT = 22365 10PORT = 22365
11PLUGINS = tcp 11PLUGINS = tcp
12#DEBUG = YES 12#DEBUG = YES
13#PREFIX = xterm -T t2 -e gdb -x cmd --args
14#BINARY = /home/grothoff/bin/gnunet-service-transport
15#PREFIX = valgrind --tool=memcheck
13 16
14[arm] 17[arm]
15PORT = 22366 18PORT = 22366
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c
index aa1a3f9a1..49462fd5d 100644
--- a/src/transport/transport_api.c
+++ b/src/transport/transport_api.c
@@ -1108,6 +1108,10 @@ remove_neighbour (struct GNUNET_TRANSPORT_Handle *h,
1108 } 1108 }
1109 else 1109 else
1110 { 1110 {
1111 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1112 _("Connection with `%4s' failed, will keep trying for %llu ms to deliver message\n"),
1113 GNUNET_i2s (peer),
1114 GNUNET_TIME_absolute_get_remaining (th->timeout).value);
1111 /* try again in a bit */ 1115 /* try again in a bit */
1112 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == th->notify_delay_task); 1116 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == th->notify_delay_task);
1113 th->notify_delay_task 1117 th->notify_delay_task