From e7006a361e7df7f32cb02db78ef1c31b376842a3 Mon Sep 17 00:00:00 2001 From: "Nathan S. Evans" Date: Thu, 21 Jan 2010 14:07:41 +0000 Subject: [PATCH] it compiles, but definitely doesn't work --- src/transport/plugin_transport_tcp.c | 12 ++++++------ src/transport/plugin_transport_udp.c | 5 ++--- src/transport/transport.h | 10 ++++++++++ src/transport/transport_api.c | 29 ++++++++++++++-------------- 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 8b9a2b695..481c52ba8 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c @@ -513,10 +513,11 @@ disconnect_session (struct Session *session) know about this one, so we need to notify transport service about disconnect */ session->plugin->env->receive (session->plugin->env->cls, - 1, + NULL, + &session->target, + 1, session->connect_addr, - session->connect_alen, - &session->target, NULL); + session->connect_alen); } if (session->client != NULL) { @@ -1089,10 +1090,9 @@ handle_tcp_data (void *cls, (unsigned int) msize, (unsigned int) ntohs (msg->type)); #endif - plugin->env->receive (plugin->env->cls, 1, + plugin->env->receive (plugin->env->cls, message, &session->target, 1, session->connect_addr, - session->connect_alen, - &session->target, message); + session->connect_alen); /* update bandwidth used */ session->last_received += msize; update_quota (session, GNUNET_NO); diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index c3f97aed5..e9e243969 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c @@ -330,9 +330,8 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) ("msg reports message type of %d\n"), ntohs (hdr->type)); #endif - - plugin->env->receive (plugin->env->cls, UDP_DIRECT_DISTANCE,(char *)&addr, fromlen, sender, - &msg->header); + plugin->env->receive (plugin->env->cls, + &msg->header, sender, UDP_DIRECT_DISTANCE, (char *)&addr, fromlen); GNUNET_free (sender); GNUNET_free (buf); diff --git a/src/transport/transport.h b/src/transport/transport.h index edbf16685..0970b3648 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h @@ -64,6 +64,11 @@ struct ConnectInfoMessage */ struct GNUNET_TIME_RelativeNBO latency; + /* + * Transport distance metric (i.e. hops for DV) + */ + uint16_t distance; + /** * Identity of the new neighbour. */ @@ -175,6 +180,11 @@ struct InboundMessage */ struct GNUNET_PeerIdentity peer; + /* + * Distance metric. + */ + uint16_t distance; + }; diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index e17ba742e..8bf2cf621 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c @@ -138,7 +138,7 @@ struct HelloWaitList /** * Callback to call once we got our HELLO. */ - GNUNET_TRANSPORT_ReceiveCallback rec; + GNUNET_TRANSPORT_HelloUpdateCallback rec; /** * Closure for rec. @@ -818,7 +818,7 @@ hello_wait_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) else prev->next = hwl->next; if (hwl->rec != NULL) - hwl->rec (hwl->rec_cls, GNUNET_TIME_UNIT_ZERO, NULL, NULL); + hwl->rec (hwl->rec_cls, NULL); GNUNET_free (hwl); } @@ -836,8 +836,7 @@ hello_wait_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ void GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle, - struct GNUNET_TIME_Relative timeout, - GNUNET_TRANSPORT_ReceiveCallback rec, + GNUNET_TRANSPORT_HelloUpdateCallback rec, void *rec_cls) { struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pk; @@ -852,10 +851,14 @@ GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle, hwl->handle = handle; hwl->rec = rec; hwl->rec_cls = rec_cls; - hwl->timeout = GNUNET_TIME_relative_to_absolute (timeout); + /* hwl->timeout = GNUNET_TIME_relative_to_absolute (timeout); + * Timeout not needed, because we should notify on change. + * FIXME: set up scheduler to notify on modification? + hwl->task = GNUNET_SCHEDULER_add_delayed (handle->sched, timeout, &hello_wait_timeout, hwl); + */ return; } GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_key (handle->my_hello, &pk)); @@ -863,9 +866,7 @@ GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &me.hashPubKey); - rec (rec_cls, - GNUNET_TIME_UNIT_ZERO, - &me, (const struct GNUNET_MessageHeader *) handle->my_hello); + rec (rec_cls, (const struct GNUNET_MessageHeader *) handle->my_hello); } @@ -1342,6 +1343,7 @@ static void add_neighbour (struct GNUNET_TRANSPORT_Handle *h, uint32_t quota_out, struct GNUNET_TIME_Relative latency, + uint16_t distance, const struct GNUNET_PeerIdentity *pid) { struct NeighbourList *n; @@ -1367,7 +1369,7 @@ add_neighbour (struct GNUNET_TRANSPORT_Handle *h, n->transmit_ok = GNUNET_YES; h->neighbours = n; if (h->nc_cb != NULL) - h->nc_cb (h->cls, &n->id, latency); + h->nc_cb (h->cls, &n->id, latency, distance); prev = NULL; pos = h->connect_wait_head; while (pos != NULL) @@ -1512,7 +1514,7 @@ GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle) ("Disconnect while trying to obtain `%s' from transport service.\n"), "HELLO"); if (hwl->rec != NULL) - hwl->rec (hwl->rec_cls, GNUNET_TIME_UNIT_ZERO, NULL, NULL); + hwl->rec (hwl->rec_cls, NULL); GNUNET_free (hwl); } if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK) @@ -1631,7 +1633,6 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg) h->hwl_head = hwl->next; GNUNET_SCHEDULER_cancel (h->sched, hwl->task); GNUNET_TRANSPORT_get_hello (h, - GNUNET_TIME_UNIT_ZERO, hwl->rec, hwl->rec_cls); GNUNET_free (hwl); } @@ -1650,7 +1651,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg) #endif add_neighbour (h, ntohl (cim->quota_out), - GNUNET_TIME_relative_ntoh (cim->latency), &cim->id); + GNUNET_TIME_relative_ntoh (cim->latency), ntohs(cim->distance), &cim->id); break; case GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT: if (size != sizeof (struct DisconnectInfoMessage)) @@ -1748,8 +1749,8 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg) ntohs (imm->type), GNUNET_i2s (&im->peer)); #endif if (h->rec != NULL) - h->rec (h->cls, - GNUNET_TIME_relative_ntoh (im->latency), &im->peer, imm); + h->rec (h->cls, &im->peer, imm, + GNUNET_TIME_relative_ntoh (im->latency), ntohs(im->distance)); break; } break; -- 2.25.1