aboutsummaryrefslogtreecommitdiff
path: root/src/transport/transport_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/transport_api.c')
-rw-r--r--src/transport/transport_api.c107
1 files changed, 100 insertions, 7 deletions
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,