diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-09-03 15:28:43 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-09-03 15:28:43 +0000 |
commit | 2e0b0c8b13496bde84f42a45c8dc72ed78a86971 (patch) | |
tree | f941a6470ae93de3778e4228b736a221388ef8ff /src/transport/transport_api.c | |
parent | eb243bc1d82bef705576b5f5b38122b04f51b634 (diff) | |
download | gnunet-2e0b0c8b13496bde84f42a45c8dc72ed78a86971.tar.gz gnunet-2e0b0c8b13496bde84f42a45c8dc72ed78a86971.zip |
making core request connect work
Diffstat (limited to 'src/transport/transport_api.c')
-rw-r--r-- | src/transport/transport_api.c | 72 |
1 files changed, 65 insertions, 7 deletions
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index fa06f7fdb..4809981f5 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c | |||
@@ -456,6 +456,9 @@ schedule_peer_transmission (struct GNUNET_TRANSPORT_Handle *h) | |||
456 | next = n->next; | 456 | next = n->next; |
457 | if (n->transmit_stage != TS_QUEUED) | 457 | if (n->transmit_stage != TS_QUEUED) |
458 | continue; /* not eligible */ | 458 | continue; /* not eligible */ |
459 | if (n->is_connected != GNUNET_YES) | ||
460 | continue; | ||
461 | |||
459 | th = &n->transmit_handle; | 462 | th = &n->transmit_handle; |
460 | GNUNET_break (n == th->neighbour); | 463 | GNUNET_break (n == th->neighbour); |
461 | /* check outgoing quota */ | 464 | /* check outgoing quota */ |
@@ -500,6 +503,7 @@ schedule_peer_transmission (struct GNUNET_TRANSPORT_Handle *h) | |||
500 | th->notify_size - sizeof (struct OutboundMessage), | 503 | th->notify_size - sizeof (struct OutboundMessage), |
501 | GNUNET_i2s (&n->id)); | 504 | GNUNET_i2s (&n->id)); |
502 | #endif | 505 | #endif |
506 | |||
503 | if ( (ret == NULL) || | 507 | if ( (ret == NULL) || |
504 | (ret->priority < th->priority) ) | 508 | (ret->priority < th->priority) ) |
505 | ret = th; | 509 | ret = th; |
@@ -664,7 +668,7 @@ schedule_transmission (struct GNUNET_TRANSPORT_Handle *h) | |||
664 | return; | 668 | return; |
665 | if (h->client == NULL) | 669 | if (h->client == NULL) |
666 | { | 670 | { |
667 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 671 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
668 | _("Could not yet schedule transmission: we are not yet connected to the transport service!\n")); | 672 | _("Could not yet schedule transmission: we are not yet connected to the transport service!\n")); |
669 | return; /* not yet connected */ | 673 | return; /* not yet connected */ |
670 | } | 674 | } |
@@ -688,6 +692,10 @@ schedule_transmission (struct GNUNET_TRANSPORT_Handle *h) | |||
688 | size = th->notify_size; | 692 | size = th->notify_size; |
689 | timeout = GNUNET_TIME_absolute_get_remaining (th->timeout); | 693 | timeout = GNUNET_TIME_absolute_get_remaining (th->timeout); |
690 | } | 694 | } |
695 | #if DEBUG_TRANSPORT | ||
696 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
697 | "Calling notify_transmit_ready\n"); | ||
698 | #endif | ||
691 | h->network_handle = | 699 | h->network_handle = |
692 | GNUNET_CLIENT_notify_transmit_ready (h->client, | 700 | GNUNET_CLIENT_notify_transmit_ready (h->client, |
693 | size, | 701 | size, |
@@ -979,7 +987,7 @@ send_hello (void *cls, size_t size, void *buf) | |||
979 | if (buf == NULL) | 987 | if (buf == NULL) |
980 | { | 988 | { |
981 | #if DEBUG_TRANSPORT_TIMEOUT | 989 | #if DEBUG_TRANSPORT_TIMEOUT |
982 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 990 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
983 | "Timeout while trying to transmit `%s' request.\n", | 991 | "Timeout while trying to transmit `%s' request.\n", |
984 | "HELLO"); | 992 | "HELLO"); |
985 | #endif | 993 | #endif |
@@ -1247,6 +1255,40 @@ schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h) | |||
1247 | 1255 | ||
1248 | 1256 | ||
1249 | /** | 1257 | /** |
1258 | * Send request connect message to the service. | ||
1259 | * | ||
1260 | * @param cls the TransportRequestConnectMessage | ||
1261 | * @param size number of bytes available in buf | ||
1262 | * @param buf where to copy the message | ||
1263 | * @return number of bytes copied to buf | ||
1264 | */ | ||
1265 | static size_t | ||
1266 | send_transport_request_connect (void *cls, size_t size, void *buf) | ||
1267 | { | ||
1268 | struct TransportRequestConnectMessage *trcm = cls; | ||
1269 | |||
1270 | if (buf == NULL) | ||
1271 | { | ||
1272 | #if DEBUG_TRANSPORT | ||
1273 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1274 | "Buffer null for %s\n", | ||
1275 | "REQUEST_CONNECT"); | ||
1276 | #endif | ||
1277 | GNUNET_free (trcm); | ||
1278 | return 0; | ||
1279 | } | ||
1280 | #if DEBUG_TRANSPORT | ||
1281 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1282 | "Transmitting `%s' request for `%4s'.\n", | ||
1283 | "REQUEST_CONNECT", | ||
1284 | GNUNET_i2s (&trcm->peer)); | ||
1285 | #endif | ||
1286 | GNUNET_assert (size >= sizeof (struct TransportRequestConnectMessage)); | ||
1287 | memcpy(buf, trcm, sizeof(struct TransportRequestConnectMessage)); | ||
1288 | return sizeof(struct TransportRequestConnectMessage); | ||
1289 | } | ||
1290 | |||
1291 | /** | ||
1250 | * Add neighbour to our list | 1292 | * Add neighbour to our list |
1251 | * | 1293 | * |
1252 | * @return NULL if this API is currently disconnecting from the service | 1294 | * @return NULL if this API is currently disconnecting from the service |
@@ -1256,6 +1298,7 @@ neighbour_add (struct GNUNET_TRANSPORT_Handle *h, | |||
1256 | const struct GNUNET_PeerIdentity *pid) | 1298 | const struct GNUNET_PeerIdentity *pid) |
1257 | { | 1299 | { |
1258 | struct NeighbourList *n; | 1300 | struct NeighbourList *n; |
1301 | struct TransportRequestConnectMessage *trcm; | ||
1259 | 1302 | ||
1260 | if (GNUNET_YES == h->in_disconnect) | 1303 | if (GNUNET_YES == h->in_disconnect) |
1261 | return NULL; | 1304 | return NULL; |
@@ -1278,6 +1321,15 @@ neighbour_add (struct GNUNET_TRANSPORT_Handle *h, | |||
1278 | n->next = h->neighbours; | 1321 | n->next = h->neighbours; |
1279 | n->h = h; | 1322 | n->h = h; |
1280 | h->neighbours = n; | 1323 | h->neighbours = n; |
1324 | |||
1325 | trcm = GNUNET_malloc(sizeof(struct TransportRequestConnectMessage)); | ||
1326 | trcm->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT); | ||
1327 | trcm->header.size = htons(sizeof(struct TransportRequestConnectMessage)); | ||
1328 | memcpy(&trcm->peer, pid, sizeof(struct GNUNET_PeerIdentity)); | ||
1329 | schedule_control_transmit (h, | ||
1330 | sizeof (struct TransportRequestConnectMessage), | ||
1331 | GNUNET_NO, | ||
1332 | GNUNET_TIME_UNIT_FOREVER_REL, &send_transport_request_connect, trcm); | ||
1281 | return n; | 1333 | return n; |
1282 | } | 1334 | } |
1283 | 1335 | ||
@@ -1655,7 +1707,7 @@ peer_transmit_timeout (void *cls, | |||
1655 | th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK; | 1707 | th->notify_delay_task = GNUNET_SCHEDULER_NO_TASK; |
1656 | n = th->neighbour; | 1708 | n = th->neighbour; |
1657 | #if DEBUG_TRANSPORT | 1709 | #if DEBUG_TRANSPORT |
1658 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1710 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1659 | "Triggering timeout for request to transmit to `%4s' (%d)\n", | 1711 | "Triggering timeout for request to transmit to `%4s' (%d)\n", |
1660 | GNUNET_i2s (&n->id), | 1712 | GNUNET_i2s (&n->id), |
1661 | n->transmit_stage); | 1713 | n->transmit_stage); |
@@ -1729,18 +1781,24 @@ GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle | |||
1729 | GNUNET_break (0); | 1781 | GNUNET_break (0); |
1730 | return NULL; | 1782 | return NULL; |
1731 | } | 1783 | } |
1732 | #if DEBUG_TRANSPORT | 1784 | |
1733 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1785 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1734 | "Asking transport service for transmission of %u bytes to peer `%4s' within %llu ms.\n", | 1786 | "Asking transport service for transmission of %u bytes to peer `%4s' within %llu ms.\n", |
1735 | size, GNUNET_i2s (target), | 1787 | size, GNUNET_i2s (target), |
1736 | (unsigned long long) timeout.value); | 1788 | (unsigned long long) timeout.value); |
1737 | #endif | 1789 | |
1738 | n = neighbour_find (handle, target); | 1790 | n = neighbour_find (handle, target); |
1739 | if (n == NULL) | 1791 | if (n == NULL) |
1740 | n = neighbour_add (handle, target); | 1792 | { |
1793 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1794 | "Created neighbour entry for peer `%s'\n", | ||
1795 | GNUNET_i2s (target)); | ||
1796 | n = neighbour_add (handle, target); | ||
1797 | |||
1798 | } | ||
1741 | if (n == NULL) | 1799 | if (n == NULL) |
1742 | { | 1800 | { |
1743 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1801 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1744 | "Could not create neighbour entry for peer `%s'\n", | 1802 | "Could not create neighbour entry for peer `%s'\n", |
1745 | GNUNET_i2s (target)); | 1803 | GNUNET_i2s (target)); |
1746 | return NULL; | 1804 | return NULL; |