aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-01-29 15:36:37 +0000
committerNathan S. Evans <evans@in.tum.de>2010-01-29 15:36:37 +0000
commitaf174b47bc58e51c3d5616776e3a540462ccec11 (patch)
tree5eb2f59ddefd775b1441a58521adbbe75899299e /src
parent1d331d111abd6285148321262a50ca7784eaaf97 (diff)
downloadgnunet-af174b47bc58e51c3d5616776e3a540462ccec11.tar.gz
gnunet-af174b47bc58e51c3d5616776e3a540462ccec11.zip
hopefully partially fixing non worky problems on various machines. but since I haven't tested it on any other machines, we shall see if this is the case. Previous issues likely related to the ack_received stuff which was still present which caused tcp connections to have undesirable behavior
Diffstat (limited to 'src')
-rw-r--r--src/transport/gnunet-service-transport.c112
-rw-r--r--src/transport/test_transport_api.c20
-rw-r--r--src/transport/transport.h2
-rw-r--r--src/transport/transport_api.c107
4 files changed, 177 insertions, 64 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index fde9d8128..ff2dc2630 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -1122,62 +1122,57 @@ find_ready_address(struct NeighborList *neighbor)
1122{ 1122{
1123 struct ReadyList *head = neighbor->plugins; 1123 struct ReadyList *head = neighbor->plugins;
1124 struct PeerAddressList *addresses; 1124 struct PeerAddressList *addresses;
1125 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
1126 struct GNUNET_TIME_Relative min_latency = GNUNET_TIME_relative_get_forever();
1127 struct PeerAddressList *best_address;
1128
1129 best_address = NULL;
1125 while (head != NULL) 1130 while (head != NULL)
1126 { 1131 {
1127 addresses = head->addresses; 1132 addresses = head->addresses;
1128 while ((addresses != NULL) &&
1129 ((addresses->connected != GNUNET_YES) ||
1130 (addresses->transmit_ready != GNUNET_YES)))
1131 {
1132 addresses = addresses->next;
1133 }
1134 1133
1135 if (addresses != NULL) 1134 while (addresses != NULL)
1136 { 1135 {
1136 if ((addresses->timeout.value < now.value) && (addresses->connected == GNUNET_YES))
1137 {
1137#if DEBUG_TRANSPORT 1138#if DEBUG_TRANSPORT
1138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1139 "Found ready address, connected is %d\n", 1140 "Marking long-time inactive connection to `%4s' as down.\n",
1140 addresses->connected); 1141 GNUNET_i2s (&addresses->ready_list->neighbor->id));
1141#endif 1142#endif
1142 return addresses; 1143 addresses->connected = GNUNET_NO;
1144 }
1145 addresses = addresses->next;
1143 } 1146 }
1144 1147
1145 1148 addresses = head->addresses;
1146 head = head->next; 1149 while (addresses != NULL)
1147 }
1148 return NULL;
1149
1150#if 0 /* Do some checks to keep everything sane, return lowest latency connection */
1151 while (pos != NULL)
1152 {
1153 /* set plugins that are inactive for a long time back to disconnected */
1154 if ((pos->timeout.value < now.value) && (pos->connected == GNUNET_YES))
1155 { 1150 {
1151 if ((addresses->connected == GNUNET_YES) &&
1152 (addresses->transmit_ready == GNUNET_YES) &&
1153 ((addresses->latency.value < min_latency.value) || (best_address == NULL)))
1154 {
1156#if DEBUG_TRANSPORT 1155#if DEBUG_TRANSPORT
1157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1158 "Marking long-time inactive connection to `%4s' as down.\n", 1157 "Found address with latency %llu, setting as best found yet!\n",
1159 GNUNET_i2s (&neighbor->id)); 1158 addresses->latency.value);
1160#endif 1159#endif
1161 pos->connected = GNUNET_NO; 1160 best_address = addresses;
1161 }
1162 addresses = addresses->next;
1162 } 1163 }
1163 if (GNUNET_YES == pos->transmit_ready) 1164 head = head->next;
1164 { 1165 }
1165#if DEBUG_TRANSPORT 1166#if DEBUG_TRANSPORT
1166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1167 if (best_address != NULL)
1167 "Found transmit_ready flag...\n"); 1168 {
1168#endif 1169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1169 } 1170 "Best address found has latency of %llu!\n",
1170 if (((GNUNET_YES == pos->transmit_ready) || 1171 best_address->latency.value);
1171 (mq->internal_msg)) &&
1172 (pos->connect_attempts < MAX_CONNECT_RETRY) &&
1173 ((rl == NULL) || (min_latency.value > pos->latency.value)))
1174 {
1175 rl = pos;
1176 min_latency = pos->latency;
1177 }
1178 pos = pos->next;
1179 } 1172 }
1180#endif 1173#endif
1174 return best_address;
1175
1181} 1176}
1182 1177
1183/** 1178/**
@@ -2223,7 +2218,7 @@ process_hello (struct TransportPlugin *plugin,
2223 * The peer specified by the given neighbor has timed-out or a plugin 2218 * The peer specified by the given neighbor has timed-out or a plugin
2224 * has disconnected. We may either need to do nothing (other plugins 2219 * has disconnected. We may either need to do nothing (other plugins
2225 * still up), or trigger a full disconnect and clean up. This 2220 * still up), or trigger a full disconnect and clean up. This
2226 * function updates our state and do the necessary notifications. 2221 * function updates our state and does the necessary notifications.
2227 * Also notifies our clients that the neighbor is now officially 2222 * Also notifies our clients that the neighbor is now officially
2228 * gone. 2223 * gone.
2229 * 2224 *
@@ -2233,14 +2228,27 @@ process_hello (struct TransportPlugin *plugin,
2233 * disconnect? 2228 * disconnect?
2234 */ 2229 */
2235static void 2230static void
2236disconnect_neighbor (struct NeighborList *n, int check) 2231disconnect_neighbor (struct NeighborList *current_handle, int check)
2237{ 2232{
2238 struct ReadyList *rpos; 2233 struct ReadyList *rpos;
2239 struct NeighborList *npos; 2234 struct NeighborList *npos;
2240 struct NeighborList *nprev; 2235 struct NeighborList *nprev;
2236 struct NeighborList *n;
2241 struct MessageQueue *mq; 2237 struct MessageQueue *mq;
2242 struct PeerAddressList *peer_addresses; 2238 struct PeerAddressList *peer_addresses;
2243 2239
2240 if (neighbors == NULL)
2241 return; /* We don't have any neighbors, so client has an already removed handle! */
2242
2243 npos = neighbors;
2244 while ((npos != NULL) && (current_handle != npos))
2245 npos = npos->next;
2246
2247 if (npos == NULL)
2248 return; /* Couldn't find neighbor in existing list, must have been already removed! */
2249 else
2250 n = npos;
2251
2244 if (GNUNET_YES == check) 2252 if (GNUNET_YES == check)
2245 { 2253 {
2246 rpos = n->plugins; 2254 rpos = n->plugins;
@@ -2749,21 +2757,29 @@ handle_try_connect (void *cls,
2749 const struct GNUNET_MessageHeader *message) 2757 const struct GNUNET_MessageHeader *message)
2750{ 2758{
2751 const struct TryConnectMessage *tcm; 2759 const struct TryConnectMessage *tcm;
2752 2760 struct NeighborList *neighbor;
2753 tcm = (const struct TryConnectMessage *) message; 2761 tcm = (const struct TryConnectMessage *) message;
2754#if DEBUG_TRANSPORT 2762#if DEBUG_TRANSPORT
2755 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2756 "Received `%s' request from client %p asking to connect to `%4s'\n", 2764 "Received `%s' request from client %p asking to connect to `%4s'\n",
2757 "TRY_CONNECT", client, GNUNET_i2s (&tcm->peer)); 2765 "TRY_CONNECT", client, GNUNET_i2s (&tcm->peer));
2758#endif 2766#endif
2759 if (NULL == find_neighbor (&tcm->peer)) 2767 neighbor = find_neighbor(&tcm->peer);
2768
2769 if (neighbor == NULL)
2760 setup_new_neighbor (&tcm->peer); 2770 setup_new_neighbor (&tcm->peer);
2761#if DEBUG_TRANSPORT
2762 else 2771 else
2763 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2772 {
2764 "Client asked to connect to `%4s', but connection already exists\n", 2773#if DEBUG_TRANSPORT
2765 "TRY_CONNECT", GNUNET_i2s (&tcm->peer)); 2774 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2775 "Client asked to connect to `%4s', but connection already exists\n",
2776 "TRY_CONNECT", GNUNET_i2s (&tcm->peer));
2766#endif 2777#endif
2778 transmit_to_peer (NULL, NULL, 0,
2779 (const char *) our_hello, GNUNET_HELLO_size(our_hello),
2780 GNUNET_YES, neighbor);
2781 notify_clients_connect (&tcm->peer, GNUNET_TIME_UNIT_FOREVER_REL);
2782 }
2767 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2783 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2768} 2784}
2769 2785
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c
index 5fd7124d7..c03f9dec7 100644
--- a/src/transport/test_transport_api.c
+++ b/src/transport/test_transport_api.c
@@ -31,7 +31,7 @@
31#include "gnunet_transport_service.h" 31#include "gnunet_transport_service.h"
32#include "transport.h" 32#include "transport.h"
33 33
34#define VERBOSE GNUNET_YES 34#define VERBOSE GNUNET_NO
35 35
36#define VERBOSE_ARM GNUNET_NO 36#define VERBOSE_ARM GNUNET_NO
37 37
@@ -125,11 +125,13 @@ notify_receive (void *cls,
125{ 125{
126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ok is (%d)!\n", 126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ok is (%d)!\n",
127 ok); 127 ok);
128 GNUNET_assert (ok == 7); 128
129 OKPP;
130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %d from peer (%p)!\n", 129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %d from peer (%p)!\n",
131 ntohs(message->type), cls); 130 ntohs(message->type), cls);
132 131
132 GNUNET_assert (ok == 7);
133 OKPP;
134
133 GNUNET_assert (MTYPE == ntohs (message->type)); 135 GNUNET_assert (MTYPE == ntohs (message->type));
134 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == 136 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) ==
135 ntohs (message->size)); 137 ntohs (message->size));
@@ -220,17 +222,19 @@ exchange_hello_last (void *cls,
220 message, &me->id)); 222 message, &me->id));
221 223
222 GNUNET_TRANSPORT_offer_hello (p1.th, message); 224 GNUNET_TRANSPORT_offer_hello (p1.th, message);
225
226 /*sleep(10);*/ /* Make sure we are not falling prey to the "favorable timing" bug...
227
228 /* both HELLOs exchanged, get ready to test transmission! */
223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
224 "Finished exchanging HELLOs, now waiting for transmission!\n"); 230 "Finished exchanging HELLOs, now waiting for transmission!\n");
225 231
226 /* both HELLOs exchanged, get ready to test transmission! */
227 GNUNET_TRANSPORT_notify_transmit_ready (p1.th, 232 GNUNET_TRANSPORT_notify_transmit_ready (p1.th,
228 &p2.id, 233 &p2.id,
229 256, 0, TIMEOUT, &notify_ready, 234 256, 0, TIMEOUT, &notify_ready,
230 &p1); 235 &p1);
231} 236}
232 237
233
234static void 238static void
235exchange_hello (void *cls, 239exchange_hello (void *cls,
236 const struct GNUNET_MessageHeader *message) 240 const struct GNUNET_MessageHeader *message)
diff --git a/src/transport/transport.h b/src/transport/transport.h
index 603f1bbc1..89f004ab8 100644
--- a/src/transport/transport.h
+++ b/src/transport/transport.h
@@ -30,7 +30,7 @@
30#include "gnunet_time_lib.h" 30#include "gnunet_time_lib.h"
31#include "gnunet_transport_service.h" 31#include "gnunet_transport_service.h"
32 32
33#define DEBUG_TRANSPORT GNUNET_YES 33#define DEBUG_TRANSPORT GNUNET_NO
34 34
35/** 35/**
36 * For how long do we allow unused bandwidth 36 * For how long do we allow unused bandwidth
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c
index c6269e562..cbcabfb3b 100644
--- a/src/transport/transport_api.c
+++ b/src/transport/transport_api.c
@@ -946,9 +946,23 @@ request_connect (void *cls, size_t size, void *buf)
946 struct GNUNET_TRANSPORT_TransmitHandle *th = cls; 946 struct GNUNET_TRANSPORT_TransmitHandle *th = cls;
947 struct TryConnectMessage *tcm; 947 struct TryConnectMessage *tcm;
948 struct GNUNET_TRANSPORT_Handle *h; 948 struct GNUNET_TRANSPORT_Handle *h;
949 struct NeighbourList *n;
949 950
950 GNUNET_assert (th->notify_delay_task == GNUNET_SCHEDULER_NO_TASK); 951 GNUNET_assert (th->notify_delay_task == GNUNET_SCHEDULER_NO_TASK);
951 h = th->handle; 952 h = th->handle;
953
954 n = find_neighbour(h, &tcm->peer);
955
956 if (n != NULL)
957 {
958#if DEBUG_TRANSPORT
959 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
960 "Asked to TRY_CONNECT to already connected peer!\n");
961#endif
962 return GNUNET_YES;
963 }
964
965
952 if (buf == NULL) 966 if (buf == NULL)
953 { 967 {
954#if DEBUG_TRANSPORT 968#if DEBUG_TRANSPORT
@@ -1356,8 +1370,10 @@ add_neighbour (struct GNUNET_TRANSPORT_Handle *h,
1356 h->connect_wait_head = next; 1370 h->connect_wait_head = next;
1357 else 1371 else
1358 prev->next = next; 1372 prev->next = next;
1359// if (GNUNET_YES == n->received_ack) 1373#if ACK
1360// { 1374 if (GNUNET_YES == n->received_ack)
1375 {
1376#endif
1361#if DEBUG_TRANSPORT 1377#if DEBUG_TRANSPORT
1362 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1378 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1363 "Found pending request for `%4s' will trigger it now.\n", 1379 "Found pending request for `%4s' will trigger it now.\n",
@@ -1369,7 +1385,9 @@ add_neighbour (struct GNUNET_TRANSPORT_Handle *h,
1369 pos->notify_delay_task = GNUNET_SCHEDULER_NO_TASK; 1385 pos->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
1370 } 1386 }
1371 schedule_request (pos); 1387 schedule_request (pos);
1372// } 1388#if ACK
1389 }
1390#endif
1373 1391
1374 break; 1392 break;
1375 } 1393 }
@@ -1529,6 +1547,10 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
1529 struct NeighbourList *n; 1547 struct NeighbourList *n;
1530 struct GNUNET_PeerIdentity me; 1548 struct GNUNET_PeerIdentity me;
1531 struct GNUNET_TRANSPORT_TransmitHandle *th; 1549 struct GNUNET_TRANSPORT_TransmitHandle *th;
1550
1551 struct GNUNET_TRANSPORT_TransmitHandle *prev;
1552 struct GNUNET_TRANSPORT_TransmitHandle *pos;
1553 struct GNUNET_TRANSPORT_TransmitHandle *next;
1532 uint16_t size; 1554 uint16_t size;
1533 1555
1534 if ((msg == NULL) || (h->client == NULL)) 1556 if ((msg == NULL) || (h->client == NULL))
@@ -1614,9 +1636,80 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
1614 "Receiving `%s' message for `%4s'.\n", 1636 "Receiving `%s' message for `%4s'.\n",
1615 "CONNECT", GNUNET_i2s (&cim->id)); 1637 "CONNECT", GNUNET_i2s (&cim->id));
1616#endif 1638#endif
1617 add_neighbour (h, 1639 if (find_neighbour(h, &cim->id) == NULL)
1618 ntohl (cim->quota_out), 1640 {
1619 GNUNET_TIME_relative_ntoh (cim->latency), ntohs(cim->distance), &cim->id); 1641#if DEBUG_TRANSPORT
1642 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1643 "Don't know neighbor, adding!\n");
1644#endif
1645 add_neighbour (h,
1646 ntohl (cim->quota_out),
1647 GNUNET_TIME_relative_ntoh (cim->latency), ntohs(cim->distance), &cim->id);
1648 }
1649 else
1650 {
1651#if DEBUG_TRANSPORT
1652 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1653 "Do know neighbor, scheduling transmission!\n");
1654#endif
1655 n = find_neighbour(h, &cim->id);
1656 n->received_ack = GNUNET_YES;
1657 if (NULL != n->transmit_handle)
1658 {
1659#if DEBUG_TRANSPORT
1660 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1661 "Peer connected, scheduling delayed message for delivery now.\n");
1662#endif
1663 schedule_request (n->transmit_handle);
1664 }
1665 else
1666 {
1667#if DEBUG_TRANSPORT
1668 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1669 "Transmit handle is null... Checking for pending stuff(?)\n");
1670#endif
1671 prev = NULL;
1672 pos = h->connect_wait_head;
1673 while (pos != NULL)
1674 {
1675 next = pos->next;
1676 if (0 == memcmp (&cim->id,
1677 &pos->target, sizeof (struct GNUNET_PeerIdentity)))
1678 {
1679 pos->neighbour = n;
1680 GNUNET_assert (NULL == n->transmit_handle);
1681 n->transmit_handle = pos;
1682 if (prev == NULL)
1683 h->connect_wait_head = next;
1684 else
1685 prev->next = next;
1686#if ACK
1687 if (GNUNET_YES == n->received_ack)
1688 {
1689#endif
1690 #if DEBUG_TRANSPORT
1691 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1692 "Found pending request for `%4s' will trigger it now.\n",
1693 GNUNET_i2s (&pos->target));
1694 #endif
1695 if (pos->notify_delay_task != GNUNET_SCHEDULER_NO_TASK)
1696 {
1697 GNUNET_SCHEDULER_cancel (h->sched, pos->notify_delay_task);
1698 pos->notify_delay_task = GNUNET_SCHEDULER_NO_TASK;
1699 }
1700 schedule_request (pos);
1701#if ACK
1702 }
1703#endif
1704
1705 break;
1706 }
1707 prev = pos;
1708 pos = next;
1709 }
1710 }
1711 }
1712
1620 break; 1713 break;
1621 case GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT: 1714 case GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT:
1622 if (size != sizeof (struct DisconnectInfoMessage)) 1715 if (size != sizeof (struct DisconnectInfoMessage))
@@ -1882,7 +1975,7 @@ GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle
1882#endif 1975#endif
1883 GNUNET_assert (NULL == n->transmit_handle); 1976 GNUNET_assert (NULL == n->transmit_handle);
1884 n->transmit_handle = th; 1977 n->transmit_handle = th;
1885 if (GNUNET_YES != n->received_ack) 1978 if (GNUNET_YES != n->transmit_ok)
1886 { 1979 {
1887#if DEBUG_TRANSPORT 1980#if DEBUG_TRANSPORT
1888 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1981 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,