From a983a0267109b1b6a8e16e476e2f2956a8771b94 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 8 Nov 2011 23:20:42 +0000 Subject: [PATCH] refactoring how we handle peer addresses in peerinfo/ats/transport/hello subsystems -- use a struct instead of 3--4 arguments --- src/ats/ats_api_performance.c | 19 +- src/ats/ats_api_scheduling.c | 101 +++--- src/ats/test_ats_api_scheduling.c | 38 +- src/hello/address.c | 45 +++ src/hello/hello.c | 102 +++--- src/hello/test_hello.c | 39 +- src/hostlist/hostlist-server.c | 9 +- src/include/gnunet_ats_service.h | 54 +-- src/include/gnunet_hello_lib.h | 43 ++- src/include/gnunet_transport_service.h | 1 + src/peerinfo-tool/gnunet-peerinfo.c | 25 +- src/peerinfo/gnunet-service-peerinfo.c | 13 +- src/peerinfo/test_peerinfo_api.c | 26 +- src/testing/testing.c | 6 +- src/topology/gnunet-daemon-topology.c | 9 +- src/transport/gnunet-service-transport.c | 74 ++-- .../gnunet-service-transport_blacklist.c | 8 +- .../gnunet-service-transport_clients.c | 42 +-- .../gnunet-service-transport_hello.c | 55 ++- .../gnunet-service-transport_hello.h | 17 +- .../gnunet-service-transport_neighbours.c | 337 +++++++----------- .../gnunet-service-transport_neighbours.h | 52 ++- .../gnunet-service-transport_plugins.c | 16 +- .../gnunet-service-transport_plugins.h | 7 +- .../gnunet-service-transport_validation.c | 203 +++++------ .../gnunet-service-transport_validation.h | 44 +-- 26 files changed, 619 insertions(+), 766 deletions(-) diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c index ca489e4a6..8ac88ec63 100644 --- a/src/ats/ats_api_performance.c +++ b/src/ats/ats_api_performance.c @@ -269,9 +269,10 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, { const struct PeerInformationMessage *pi; const struct GNUNET_ATS_Information *atsi; - const char *address; + const char *plugin_address; const char *plugin_name; - uint16_t address_length; + struct GNUNET_HELLO_Address address; + uint16_t plugin_address_length; uint16_t plugin_name_length; uint32_t ats_count; @@ -287,12 +288,12 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, } pi = (const struct PeerInformationMessage *) msg; ats_count = ntohl (pi->ats_count); - address_length = ntohs (pi->address_length); + plugin_address_length = ntohs (pi->address_length); plugin_name_length = ntohs (pi->plugin_name_length); atsi = (const struct GNUNET_ATS_Information *) &pi[1]; - address = (const char *) &atsi[ats_count]; - plugin_name = &address[address_length]; - if ((address_length + plugin_name_length + + plugin_address = (const char *) &atsi[ats_count]; + plugin_name = &plugin_address[plugin_address_length]; + if ((plugin_address_length + plugin_name_length + ats_count * sizeof (struct GNUNET_ATS_Information) + sizeof (struct PeerInformationMessage) != ntohs (msg->size)) || (ats_count > @@ -302,7 +303,11 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph, GNUNET_break (0); return GNUNET_SYSERR; } - ph->infocb (ph->infocb_cls, &pi->peer, plugin_name, address, address_length, + address.peer = pi->peer; + address.address = plugin_address; + address.address_length = plugin_address_length; + address.transport_name = plugin_name; + ph->infocb (ph->infocb_cls, &address, pi->bandwidth_out, pi->bandwidth_in, atsi, ats_count); return GNUNET_OK; } diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c index c2e7c0ea9..0885f53e9 100644 --- a/src/ats/ats_api_scheduling.c +++ b/src/ats/ats_api_scheduling.c @@ -440,11 +440,12 @@ process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg) struct GNUNET_ATS_SchedulingHandle *sh = cls; const struct AddressSuggestionMessage *m; const struct GNUNET_ATS_Information *atsi; - const char *address; + const char *plugin_address; const char *plugin_name; - uint16_t address_length; + uint16_t plugin_address_length; uint16_t plugin_name_length; uint32_t ats_count; + struct GNUNET_HELLO_Address address; if (NULL == msg) { @@ -470,12 +471,12 @@ process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg) } m = (const struct AddressSuggestionMessage *) msg; ats_count = ntohl (m->ats_count); - address_length = ntohs (m->address_length); + plugin_address_length = ntohs (m->address_length); atsi = (const struct GNUNET_ATS_Information *) &m[1]; - address = (const char *) &atsi[ats_count]; - plugin_name = &address[address_length]; + plugin_address = (const char *) &atsi[ats_count]; + plugin_name = &plugin_address[plugin_address_length]; plugin_name_length = ntohs (m->plugin_name_length); - if ((address_length + plugin_name_length + + if ((plugin_address_length + plugin_name_length + ats_count * sizeof (struct GNUNET_ATS_Information) + sizeof (struct AddressSuggestionMessage) != ntohs (msg->size)) || (ats_count > @@ -500,9 +501,11 @@ process_ats_message (void *cls, const struct GNUNET_MessageHeader *msg) GNUNET_break (0); } } - - sh->suggest_cb (sh->suggest_cb_cls, &m->peer, plugin_name, address, - address_length, s, m->bandwidth_out, + address.peer = m->peer; + address.address = plugin_address; + address.address_length = plugin_address_length; + address.transport_name = plugin_name; + sh->suggest_cb (sh->suggest_cb_cls, &address, s, m->bandwidth_out, m->bandwidth_in, atsi, ats_count); @@ -637,19 +640,15 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh, * for later use). Update bandwidth assignments. * * @param sh handle - * @param peer identity of the new peer - * @param plugin_name name of the transport plugin - * @param plugin_addr address (if available) - * @param plugin_addr_len number of bytes in plugin_addr + * @param address the address * @param session session handle (if available) * @param ats performance data for the address * @param ats_count number of performance records in 'ats' */ void GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, - const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, const void *plugin_addr, - size_t plugin_addr_len, struct Session *session, + const struct GNUNET_HELLO_Address *address, + struct Session *session, const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { @@ -660,12 +659,12 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, size_t namelen; size_t msize; - namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1; + namelen = (address->transport_name == NULL) ? 0 : strlen (address->transport_name) + 1; msize = - sizeof (struct AddressUpdateMessage) + plugin_addr_len + + sizeof (struct AddressUpdateMessage) + address->address_length + ats_count * sizeof (struct GNUNET_ATS_Information) + namelen; if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || - (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || + (address->address_length >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || (ats_count >= GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information))) @@ -681,15 +680,15 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE); m->header.size = htons (msize); m->ats_count = htonl (ats_count); - m->peer = *peer; - m->address_length = htons (plugin_addr_len); + m->peer = address->peer; + m->address_length = htons (address->address_length); m->plugin_name_length = htons (namelen); - m->session_id = htonl (get_session_id (sh, session, peer)); + m->session_id = htonl (get_session_id (sh, session, &address->peer)); am = (struct GNUNET_ATS_Information *) &m[1]; memcpy (am, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); pm = (char *) &am[ats_count]; - memcpy (pm, plugin_addr, plugin_addr_len); - memcpy (&pm[plugin_addr_len], plugin_name, namelen); + memcpy (pm, address->address, address->address_length); + memcpy (&pm[address->address_length], address->transport_name, namelen); GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p); do_transmit (sh); } @@ -699,19 +698,15 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, * An address is now in use or not used any more. * * @param sh handle - * @param peer identity of the peer - * @param plugin_name name of the transport plugin - * @param plugin_addr address (if available) - * @param plugin_addr_len number of bytes in plugin_addr + * @param address the address * @param session session handle * @param in_use GNUNET_YES if this address is now used, GNUNET_NO * if address is not used any more */ void GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, - const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, const void *plugin_addr, - size_t plugin_addr_len, struct Session *session, + const struct GNUNET_HELLO_Address *address, + struct Session *session, int in_use) { struct PendingMessage *p; @@ -720,10 +715,10 @@ GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, size_t namelen; size_t msize; - namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1; - msize = sizeof (struct AddressUseMessage) + plugin_addr_len + namelen; + namelen = (address->transport_name == NULL) ? 0 : strlen (address->transport_name) + 1; + msize = sizeof (struct AddressUseMessage) + address->address_length + namelen; if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || - (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || + (address->address_length >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE)) { GNUNET_break (0); @@ -736,14 +731,14 @@ GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, m = (struct AddressUseMessage *) &p[1]; m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE); m->header.size = htons (msize); - m->peer = *peer; + m->peer = address->peer; m->in_use = htons (in_use); - m->address_length = htons (plugin_addr_len); + m->address_length = htons (address->address_length); m->plugin_name_length = htons (namelen); - m->session_id = htonl (get_session_id (sh, session, peer)); + m->session_id = htonl (get_session_id (sh, session, &address->peer)); pm = (char *) &m[1]; - memcpy (pm, plugin_addr, plugin_addr_len); - memcpy (&pm[plugin_addr_len], plugin_name, namelen); + memcpy (pm, address->address, address->address_length); + memcpy (&pm[address->address_length], address->transport_name, namelen); GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p); do_transmit (sh); @@ -753,17 +748,13 @@ GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, * A session got destroyed, stop including it as a valid address. * * @param sh handle - * @param peer identity of the peer - * @param plugin_name name of the transport plugin - * @param plugin_addr address (if available) - * @param plugin_addr_len number of bytes in plugin_addr + * @param address the address * @param session session handle that is no longer valid */ void GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh, - const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, const void *plugin_addr, - size_t plugin_addr_len, struct Session *session) + const struct GNUNET_HELLO_Address *address, + struct Session *session) { struct PendingMessage *p; struct AddressDestroyedMessage *m; @@ -772,10 +763,10 @@ GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh, size_t msize; uint32_t session_id; - namelen = (plugin_name == NULL) ? 0 : strlen (plugin_name) + 1; - msize = sizeof (struct AddressDestroyedMessage) + plugin_addr_len + namelen; + namelen = (address->transport_name == NULL) ? 0 : strlen (address->transport_name) + 1; + msize = sizeof (struct AddressDestroyedMessage) + address->address_length + namelen; if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || - (plugin_addr_len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || + (address->address_length >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || (namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE)) { GNUNET_break (0); @@ -790,17 +781,17 @@ GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh, m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED); m->header.size = htons (msize); m->reserved = htonl (0); - m->peer = *peer; - m->address_length = htons (plugin_addr_len); + m->peer = address->peer; + m->address_length = htons (address->address_length); m->plugin_name_length = htons (namelen); - session_id = get_session_id (sh, session, peer); + session_id = get_session_id (sh, session, &address->peer); m->session_id = htonl (session_id); pm = (char *) &m[1]; - memcpy (pm, plugin_addr, plugin_addr_len); - memcpy (&pm[plugin_addr_len], plugin_name, namelen); + memcpy (pm, address->address, address->address_length); + memcpy (&pm[address->address_length], address->transport_name, namelen); GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p); do_transmit (sh); - remove_session (sh, session_id, peer); + remove_session (sh, session_id, &address->peer); } /* end of ats_api_scheduling.c */ diff --git a/src/ats/test_ats_api_scheduling.c b/src/ats/test_ats_api_scheduling.c index a2ee7f060..d24bb2c73 100644 --- a/src/ats/test_ats_api_scheduling.c +++ b/src/ats/test_ats_api_scheduling.c @@ -118,22 +118,22 @@ end () static void -address_suggest_cb (void *cls, const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, const void *plugin_addr, - size_t plugin_addr_len, struct Session *session, +address_suggest_cb (void *cls, + const struct GNUNET_HELLO_Address *address, + struct Session *session, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggests address `%s'\n", - GNUNET_i2s (peer)); + GNUNET_i2s (&address->peer)); GNUNET_assert (0 == - memcmp (peer, &p[0].id, sizeof (struct GNUNET_PeerIdentity))); - GNUNET_assert (0 == strcmp (plugin_name, addr[0].plugin)); - GNUNET_assert (plugin_addr_len == addr[0].addr_len); - GNUNET_assert (0 == memcmp (plugin_addr, addr[0].plugin, plugin_addr_len)); + memcmp (&address->peer, &p[0].id, sizeof (struct GNUNET_PeerIdentity))); + GNUNET_assert (0 == strcmp (address->transport_name, addr[0].plugin)); + GNUNET_assert (address->address_length == addr[0].addr_len); + GNUNET_assert (0 == memcmp (address->address, addr[0].plugin, address->address_length)); GNUNET_assert (addr[0].session == session); @@ -166,6 +166,8 @@ static void check (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) { + struct GNUNET_HELLO_Address address0; + ret = GNUNET_SYSERR; die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); @@ -198,16 +200,18 @@ check (void *cls, char *const *args, const char *cfgfile, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing address creation\n"); - GNUNET_ATS_address_update (ats, &p[0].id, addr[0].plugin, addr[0].addr, - addr[0].addr_len, addr[0].session, NULL, 0); + address0.peer = p[0].id; + address0.transport_name = addr[0].plugin; + address0.address = addr[0].addr; + address0.address_length = addr[0].addr_len; + GNUNET_ATS_address_update (ats, &address0, addr[0].session, NULL, 0); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing ATS info creation\n"); atsi[0].type = htonl (GNUNET_ATS_UTILIZATION_UP); atsi[0].value = htonl (1024); - GNUNET_ATS_address_update (ats, &p[0].id, addr[0].plugin, addr[0].addr, - addr[0].addr_len, addr[0].session, atsi, 1); + GNUNET_ATS_address_update (ats, &address0, addr[0].session, atsi, 1); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing ATS info update\n"); @@ -217,14 +221,12 @@ check (void *cls, char *const *args, const char *cfgfile, atsi[1].type = htonl (GNUNET_ATS_UTILIZATION_DOWN); atsi[1].value = htonl (1024); - GNUNET_ATS_address_update (ats, &p[0].id, addr[0].plugin, addr[0].addr, - addr[0].addr_len, addr[0].session, atsi, 2); + GNUNET_ATS_address_update (ats, &address0, addr[0].session, atsi, 2); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testing manual address deletion \n"); - GNUNET_ATS_address_update (ats, &p[1].id, addr[0].plugin, addr[0].addr, - addr[0].addr_len, addr[0].session, NULL, 0); - GNUNET_ATS_address_destroyed (ats, &p[1].id, addr[0].plugin, addr[0].addr, - addr[0].addr_len, addr[0].session); + address0.peer = p[1].id; // FIXME: why? typo in old code? + GNUNET_ATS_address_update (ats, &address0, addr[0].session, NULL, 0); + GNUNET_ATS_address_destroyed (ats, &address0, addr[0].session); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting peer `%s'\n", GNUNET_i2s (&p[0].id)); diff --git a/src/hello/address.c b/src/hello/address.c index 51fb296c3..5cfa10185 100644 --- a/src/hello/address.c +++ b/src/hello/address.c @@ -61,4 +61,49 @@ GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer, return addr; } + +/** + * Copy an address struct. + * + * @param address address to copy + * @return a copy of the address struct + */ +struct GNUNET_HELLO_Address * +GNUNET_HELLO_address_copy (const struct GNUNET_HELLO_Address *address) +{ + return GNUNET_HELLO_address_allocate (&address->peer, + address->transport_name, + address->address, + address->address_length); +} + + +/** + * Compare two addresses. Does NOT compare the peer identity, + * that is assumed already to match! + * + * @param a1 first address + * @param a2 second address + * @return 0 if the addresses are equal, -1 if a1a2. + */ +int +GNUNET_HELLO_address_cmp (const struct GNUNET_HELLO_Address *a1, + const struct GNUNET_HELLO_Address *a2) +{ + int ret; + + ret = strcmp (a1->transport_name, + a2->transport_name); + if (0 != ret) + return ret; + if (a1->address_length < a2->address_length) + return -1; + if (a1->address_length > a2->address_length) + return 1; + return memcmp (a1->address, + a1->address, + a1->address_length); +} + + /* end of address.c */ diff --git a/src/hello/hello.c b/src/hello/hello.c index a95c0eee2..b7f29f539 100644 --- a/src/hello/hello.c +++ b/src/hello/hello.c @@ -65,38 +65,36 @@ struct GNUNET_HELLO_Message * Copy the given address information into * the given buffer using the format of HELLOs. * - * @param tname name of the transport plugin + * @param addess the address * @param expiration expiration for the address - * @param addr the address - * @param addr_len length of the address in bytes * @param target where to copy the address * @param max maximum number of bytes to copy to target * @return number of bytes copied, 0 if * the target buffer was not big enough. */ size_t -GNUNET_HELLO_add_address (const char *tname, +GNUNET_HELLO_add_address (const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration, - const void *addr, uint16_t addr_len, char *target, + char *target, size_t max) { uint16_t alen; size_t slen; struct GNUNET_TIME_AbsoluteNBO exp; - slen = strlen (tname) + 1; + slen = strlen (address->transport_name) + 1; if (slen + sizeof (uint16_t) + sizeof (struct GNUNET_TIME_AbsoluteNBO) + - addr_len > max) + address->address_length > max) return 0; exp = GNUNET_TIME_absolute_hton (expiration); - alen = htons (addr_len); - memcpy (target, tname, slen); + alen = htons ((uint16_t) address->address_length); + memcpy (target, address->transport_name, slen); memcpy (&target[slen], &alen, sizeof (uint16_t)); slen += sizeof (uint16_t); memcpy (&target[slen], &exp, sizeof (struct GNUNET_TIME_AbsoluteNBO)); slen += sizeof (struct GNUNET_TIME_AbsoluteNBO); - memcpy (&target[slen], addr, addr_len); - slen += addr_len; + memcpy (&target[slen], address->address, address->address_length); + slen += address->address_length; return slen; } @@ -207,6 +205,7 @@ GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg, int return_modified, GNUNET_HELLO_AddressIterator it, void *it_cls) { + struct GNUNET_HELLO_Address address; uint16_t msize; struct GNUNET_HELLO_Message *ret; const char *inptr; @@ -232,6 +231,9 @@ GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg, insize = msize - sizeof (struct GNUNET_HELLO_Message); wpos = 0; woff = (ret != NULL) ? (char *) &ret[1] : NULL; + GNUNET_CRYPTO_hash (&msg->publicKey, + sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), + &address.peer.hashPubKey); while (insize > 0) { esize = get_hello_address_size (inptr, insize, &alen); @@ -244,9 +246,10 @@ GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg, memcpy (&expire, &inptr[esize - alen - sizeof (struct GNUNET_TIME_AbsoluteNBO)], sizeof (struct GNUNET_TIME_AbsoluteNBO)); - iret = - it (it_cls, inptr, GNUNET_TIME_absolute_ntoh (expire), - &inptr[esize - alen], alen); + address.address = &inptr[esize - alen]; + address.address_length = alen; + address.transport_name = inptr; + iret = it (it_cls, &address, GNUNET_TIME_absolute_ntoh (expire)); if (iret == GNUNET_SYSERR) { if (ret != NULL) @@ -270,23 +273,21 @@ GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg, struct ExpireContext { - const void *addr; - const char *tname; - uint16_t addrlen; + const struct GNUNET_HELLO_Address *address; int found; struct GNUNET_TIME_Absolute expiration; }; static int -get_match_exp (void *cls, const char *tname, - struct GNUNET_TIME_Absolute expiration, const void *addr, - uint16_t addrlen) +get_match_exp (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { struct ExpireContext *ec = cls; - if ((addrlen == ec->addrlen) && (0 == memcmp (addr, ec->addr, addrlen)) && - (0 == strcmp (tname, ec->tname))) + if (0 == GNUNET_HELLO_address_cmp (address, + ec->address)) { ec->found = GNUNET_YES; ec->expiration = expiration; @@ -310,17 +311,15 @@ struct MergeContext static int -copy_latest (void *cls, const char *tname, - struct GNUNET_TIME_Absolute expiration, const void *addr, - uint16_t addrlen) +copy_latest (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { struct MergeContext *mc = cls; struct ExpireContext ec; - ec.addr = addr; - ec.addrlen = addrlen; + ec.address = address; ec.found = GNUNET_NO; - ec.tname = tname; GNUNET_HELLO_iterate_addresses (mc->other, GNUNET_NO, &get_match_exp, &ec); if ((ec.found == GNUNET_NO) || (ec.expiration.abs_value < expiration.abs_value) || @@ -328,8 +327,9 @@ copy_latest (void *cls, const char *tname, (mc->take_equal == GNUNET_YES))) { mc->ret += - GNUNET_HELLO_add_address (tname, expiration, addr, addrlen, - &mc->buf[mc->ret], mc->max - mc->ret); + GNUNET_HELLO_add_address (address, + expiration, + &mc->buf[mc->ret], mc->max - mc->ret); } return GNUNET_OK; } @@ -388,25 +388,23 @@ struct DeltaContext static int -delta_match (void *cls, const char *tname, - struct GNUNET_TIME_Absolute expiration, const void *addr, - uint16_t addrlen) +delta_match (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { struct DeltaContext *dc = cls; int ret; struct ExpireContext ec; - ec.addr = addr; - ec.addrlen = addrlen; + ec.address = address; ec.found = GNUNET_NO; - ec.tname = tname; GNUNET_HELLO_iterate_addresses (dc->old_hello, GNUNET_NO, &get_match_exp, &ec); if ((ec.found == GNUNET_YES) && ((ec.expiration.abs_value > expiration.abs_value) || (ec.expiration.abs_value >= dc->expiration_limit.abs_value))) return GNUNET_YES; /* skip */ - ret = dc->it (dc->it_cls, tname, expiration, addr, addrlen); + ret = dc->it (dc->it_cls, address, expiration); return ret; } @@ -532,30 +530,26 @@ struct EqualsContext const struct GNUNET_HELLO_Message *h2; - const char *tname; - - const void *addr; + const struct GNUNET_HELLO_Address *address; struct GNUNET_TIME_Absolute expiration; int found; - uint16_t addrlen; - }; static int -find_other_matching (void *cls, const char *tname, - struct GNUNET_TIME_Absolute expiration, const void *addr, - uint16_t addrlen) +find_other_matching (void *cls, const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { struct EqualsContext *ec = cls; if (expiration.abs_value < ec->expiration_limit.abs_value) return GNUNET_YES; - if ((addrlen == ec->addrlen) && (0 == strcmp (tname, ec->tname)) && - (0 == memcmp (addr, ec->addr, addrlen))) + if (0 == + GNUNET_HELLO_address_cmp (address, + ec->address)) { ec->found = GNUNET_YES; if (expiration.abs_value < ec->expiration.abs_value) @@ -567,18 +561,15 @@ find_other_matching (void *cls, const char *tname, static int -find_matching (void *cls, const char *tname, - struct GNUNET_TIME_Absolute expiration, const void *addr, - uint16_t addrlen) +find_matching (void *cls, const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { struct EqualsContext *ec = cls; if (expiration.abs_value < ec->expiration_limit.abs_value) return GNUNET_YES; - ec->tname = tname; + ec->address = address; ec->expiration = expiration; - ec->addr = addr; - ec->addrlen = addrlen; ec->found = GNUNET_NO; GNUNET_HELLO_iterate_addresses (ec->h2, GNUNET_NO, &find_other_matching, ec); if (ec->found == GNUNET_NO) @@ -630,9 +621,8 @@ GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1, static int -find_min_expire (void *cls, const char *tname, - struct GNUNET_TIME_Absolute expiration, const void *addr, - uint16_t addrlen) +find_min_expire (void *cls, const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { struct GNUNET_TIME_Absolute *min = cls; diff --git a/src/hello/test_hello.c b/src/hello/test_hello.c index b6cdfcf66..ca69dfc18 100644 --- a/src/hello/test_hello.c +++ b/src/hello/test_hello.c @@ -35,55 +35,58 @@ my_addr_gen (void *cls, size_t max, void *buf) { unsigned int *i = cls; size_t ret; + struct GNUNET_HELLO_Address address; #if DEBUG fprintf (stderr, "DEBUG: my_addr_gen called with i = %d\n", *i); #endif if (0 == *i) return 0; + memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity)); + address.address = "address_information"; + address.transport_name = "test"; + address.address_length = *i; ret = - GNUNET_HELLO_add_address ("test", GNUNET_TIME_absolute_get (), - "address_information", *i, buf, max); + GNUNET_HELLO_add_address (&address, GNUNET_TIME_absolute_get (), + buf, max); (*i)--; return ret; } static int -check_addr (void *cls, const char *tname, - struct GNUNET_TIME_Absolute expiration, const void *addr, - uint16_t addrlen) +check_addr (void *cls, const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { unsigned int *i = cls; #if DEBUG fprintf (stderr, "DEBUG: check_addr called with i = %d and addrlen = %u\n", - *i, addrlen); + *i, address->address_length); #endif - GNUNET_assert (addrlen > 0); - GNUNET_assert (*i & (1 << (addrlen - 1))); - *i -= (1 << (addrlen - 1)); - GNUNET_assert (0 == strncmp ("address_information", addr, addrlen)); - GNUNET_assert (0 == strcmp ("test", tname)); + GNUNET_assert (address->address_length > 0); + GNUNET_assert (*i & (1 << (address->address_length - 1))); + *i -= (1 << (address->address_length - 1)); + GNUNET_assert (0 == strncmp ("address_information", address->address, address->address_length)); + GNUNET_assert (0 == strcmp ("test", address->transport_name)); return GNUNET_OK; } static int -remove_some (void *cls, const char *tname, - struct GNUNET_TIME_Absolute expiration, const void *addr, - uint16_t addrlen) +remove_some (void *cls, const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { unsigned int *i = cls; #if DEBUG fprintf (stderr, "DEBUG: remove_some called with i = %d and addrlen = %u\n", - *i, addrlen); + *i, address->address_length); #endif - GNUNET_assert (addrlen > 0); - if (*i & (1 << (addrlen - 1))) + GNUNET_assert (address->address_length > 0); + if (*i & (1 << (address->address_length - 1))) { - *i -= (1 << (addrlen - 1)); + *i -= (1 << (address->address_length - 1)); return GNUNET_NO; } return GNUNET_OK; diff --git a/src/hostlist/hostlist-server.c b/src/hostlist/hostlist-server.c index 69d83b4d4..8e79ace1b 100644 --- a/src/hostlist/hostlist-server.c +++ b/src/hostlist/hostlist-server.c @@ -141,16 +141,13 @@ finish_response (struct HostSet *results) * Set 'cls' to GNUNET_YES (we have an address!). * * @param cls closure, an 'int*' - * @param tname name of the transport (ignored) + * @param address the address (ignored) * @param expiration expiration time (call is ignored if this is in the past) - * @param addr the address (ignored) - * @param addrlen length of the address (ignored) * @return GNUNET_SYSERR to stop iterating (unless expiration has occured) */ static int -check_has_addr (void *cls, const char *tname, - struct GNUNET_TIME_Absolute expiration, const void *addr, - uint16_t addrlen) +check_has_addr (void *cls, const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { int *arg = cls; diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h index ac963ce1d..a6edc786c 100644 --- a/src/include/gnunet_ats_service.h +++ b/src/include/gnunet_ats_service.h @@ -28,6 +28,7 @@ #include "gnunet_constants.h" #include "gnunet_util_lib.h" +#include "gnunet_hello_lib.h" /** @@ -439,10 +440,7 @@ struct Session; * and address preferences as determined by ATS. * * @param cls closure - * @param peer identity of the new peer - * @param plugin_name name of the plugin, NULL if we have no suggestion - * @param plugin_addr suggested address, NULL if we have no suggestion - * @param plugin_addr_len number of bytes in plugin_addr + * @param address suggested address (including peer identity of the peer) * @param session session to use * @param bandwidth_out assigned outbound bandwidth for the connection * @param bandwidth_in assigned inbound bandwidth for the connection @@ -450,12 +448,7 @@ struct Session; * @param ats_count number of performance records in 'ats' */ typedef void (*GNUNET_ATS_AddressSuggestionCallback) (void *cls, - const struct - GNUNET_PeerIdentity * - peer, - const char *plugin_name, - const void *plugin_addr, - size_t plugin_addr_len, + const struct GNUNET_HELLO_Address *address, struct Session * session, struct GNUNET_BANDWIDTH_Value32NBO @@ -512,19 +505,15 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_SchedulingHandle *sh, * for later use). Update bandwidth assignments. * * @param sh handle - * @param peer identity of the new peer - * @param plugin_name name of the transport plugin - * @param plugin_addr address (if available) - * @param plugin_addr_len number of bytes in plugin_addr + * @param address updated address * @param session session handle (if available) * @param ats performance data for the address * @param ats_count number of performance records in 'ats' */ void GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, - const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, const void *plugin_addr, - size_t plugin_addr_len, struct Session *session, + const struct GNUNET_HELLO_Address *address, + struct Session *session, const struct GNUNET_ATS_Information *ats, uint32_t ats_count); @@ -533,36 +522,28 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, * An address is now in use or not used any more. * * @param sh handle - * @param peer identity of the peer - * @param plugin_name name of the transport plugin - * @param plugin_addr address (if available) - * @param plugin_addr_len number of bytes in plugin_addr + * @param address the address * @param session session handle * @param in_use GNUNET_YES if this address is now used, GNUNET_NO * if address is not used any more */ void GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh, - const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, const void *plugin_addr, - size_t plugin_addr_len, struct Session *session, + const struct GNUNET_HELLO_Address *address, + struct Session *session, int in_use); /** * A session got destroyed, stop including it as a valid address. * * @param sh handle - * @param peer identity of the peer - * @param plugin_name name of the transport plugin - * @param plugin_addr address (if available) - * @param plugin_addr_len number of bytes in plugin_addr + * @param address the address * @param session session handle that is no longer valid (if available) */ void GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh, - const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, const void *plugin_addr, - size_t plugin_addr_len, struct Session *session); + const struct GNUNET_HELLO_Address *address, + struct Session *session); /* ******************************** Performance API ***************************** */ @@ -577,21 +558,14 @@ struct GNUNET_ATS_PerformanceHandle; * Signature of a function that is called with QoS information about a peer. * * @param cls closure - * @param peer identity of the new peer - * @param plugin_name name of the plugin, NULL if we have no suggestion - * @param plugin_addr suggested address, NULL if we have no suggestion - * @param plugin_addr_len number of bytes in plugin_addr + * @param address the address * @param bandwidth_out assigned outbound bandwidth for the connection * @param bandwidth_in assigned inbound bandwidth for the connection * @param ats performance data for the address (as far as known) * @param ats_count number of performance records in 'ats' */ typedef void (*GNUNET_ATS_PeerInformationCallback) (void *cls, - const struct - GNUNET_PeerIdentity * peer, - const char *plugin_name, - const void *plugin_addr, - size_t plugin_addr_len, + const struct GNUNET_HELLO_Address *address, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, diff --git a/src/include/gnunet_hello_lib.h b/src/include/gnunet_hello_lib.h index 4e8554b52..886a41093 100644 --- a/src/include/gnunet_hello_lib.h +++ b/src/include/gnunet_hello_lib.h @@ -88,6 +88,30 @@ GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer, size_t address_length); +/** + * Copy an address struct. + * + * @param address address to copy + * @return a copy of the address struct + */ +struct GNUNET_HELLO_Address * +GNUNET_HELLO_address_copy (const struct GNUNET_HELLO_Address *address); + + +/** + * Compare two addresses. Does NOT compare the peer identity, + * that is assumed already to match! + * + * @param a1 first address + * @param a2 second address + * @return 0 if the addresses are equal, -1 if a1a2. + */ +int +GNUNET_HELLO_address_cmp (const struct GNUNET_HELLO_Address *a1, + const struct GNUNET_HELLO_Address *a2); + + + /** * Free an address. * @@ -109,19 +133,17 @@ struct GNUNET_HELLO_Message; * Copy the given address information into * the given buffer using the format of HELLOs. * - * @param tname name of the transport plugin + * @param address address to add * @param expiration expiration for the address - * @param addr the address - * @param addr_len length of the address in bytes * @param target where to copy the address * @param max maximum number of bytes to copy to target * @return number of bytes copied, 0 if * the target buffer was not big enough. */ size_t -GNUNET_HELLO_add_address (const char *tname, +GNUNET_HELLO_add_address (const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration, - const void *addr, uint16_t addr_len, char *target, + char *target, size_t max); @@ -204,18 +226,15 @@ GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1, * Iterator callback to go over all addresses. * * @param cls closure - * @param tname name of the transport + * @param address the address * @param expiration expiration time - * @param addr the address - * @param addrlen length of the address * @return GNUNET_OK to keep the address, * GNUNET_NO to delete it from the HELLO * GNUNET_SYSERR to stop iterating (but keep current address) */ -typedef int (*GNUNET_HELLO_AddressIterator) (void *cls, const char *tname, - struct GNUNET_TIME_Absolute - expiration, const void *addr, - uint16_t addrlen); +typedef int (*GNUNET_HELLO_AddressIterator) (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration); /** diff --git a/src/include/gnunet_transport_service.h b/src/include/gnunet_transport_service.h index de764e7a6..2f027656b 100644 --- a/src/include/gnunet_transport_service.h +++ b/src/include/gnunet_transport_service.h @@ -293,6 +293,7 @@ struct GNUNET_TRANSPORT_AddressLookupContext; * @param aluc_cls closure for aluc * @return handle to cancel the operation, NULL on error */ +// FIXME: use 'GNUNET_HELLO_Address' here! struct GNUNET_TRANSPORT_AddressLookupContext * GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *address, size_t addressLen, diff --git a/src/peerinfo-tool/gnunet-peerinfo.c b/src/peerinfo-tool/gnunet-peerinfo.c index 00ab22993..e40615a9b 100644 --- a/src/peerinfo-tool/gnunet-peerinfo.c +++ b/src/peerinfo-tool/gnunet-peerinfo.c @@ -96,16 +96,14 @@ process_resolved_address (void *cls, const char *address) * Iterator callback to go over all addresses. * * @param cls closure - * @param tname name of the transport + * @param address the address * @param expiration expiration time - * @param addr the address - * @param addrlen length of the address * @return GNUNET_OK to keep the address and continue */ static int -count_address (void *cls, const char *tname, - struct GNUNET_TIME_Absolute expiration, const void *addr, - uint16_t addrlen) +count_address (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { struct PrintContext *pc = cls; @@ -118,20 +116,21 @@ count_address (void *cls, const char *tname, * Iterator callback to go over all addresses. * * @param cls closure - * @param tname name of the transport + * @param address the address * @param expiration expiration time - * @param addr the address - * @param addrlen length of the address * @return GNUNET_OK to keep the address and continue */ static int -print_address (void *cls, const char *tname, - struct GNUNET_TIME_Absolute expiration, const void *addr, - uint16_t addrlen) +print_address (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { struct PrintContext *pc = cls; - GNUNET_TRANSPORT_address_lookup (cfg, addr, addrlen, no_resolve, tname, + GNUNET_TRANSPORT_address_lookup (cfg, + address->address, + address->address_length, no_resolve, + address->transport_name, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), &process_resolved_address, pc); diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index e453621d2..fc7cc781f 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c @@ -117,23 +117,22 @@ make_info_message (const struct HostEntry *he) * Address iterator that causes expired entries to be discarded. * * @param cls pointer to the current time - * @param tname name of the transport + * @param address the address * @param expiration expiration time for the address - * @param addr the address - * @param addrlen length of addr in bytes * @return GNUNET_NO if expiration smaller than the current time */ static int -discard_expired (void *cls, const char *tname, - struct GNUNET_TIME_Absolute expiration, const void *addr, - uint16_t addrlen) +discard_expired (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { const struct GNUNET_TIME_Absolute *now = cls; if (now->abs_value > expiration.abs_value) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Removing expired address of transport `%s'\n"), tname); + _("Removing expired address of transport `%s'\n"), + address->transport_name); return GNUNET_NO; } return GNUNET_OK; diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c index bbdc591f4..607c1fa4e 100644 --- a/src/peerinfo/test_peerinfo_api.c +++ b/src/peerinfo/test_peerinfo_api.c @@ -45,16 +45,17 @@ static struct GNUNET_PEERINFO_Handle *h; static unsigned int retries; static int -check_it (void *cls, const char *tname, struct GNUNET_TIME_Absolute expiration, - const void *addr, uint16_t addrlen) +check_it (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { unsigned int *agc = cls; - if (addrlen > 0) + if (address != NULL) { - GNUNET_assert (0 == strcmp ("peerinfotest", tname)); - GNUNET_assert (0 == strncmp ("Address", addr, addrlen)); - (*agc) -= (1 << (addrlen - 1)); + GNUNET_assert (0 == strcmp ("peerinfotest", address->transport_name)); + GNUNET_assert (0 == strncmp ("Address", address->address, address->address_length)); + (*agc) -= (1 << (address->address_length - 1)); } return GNUNET_OK; } @@ -65,14 +66,19 @@ address_generator (void *cls, size_t max, void *buf) { size_t *agc = cls; size_t ret; + struct GNUNET_HELLO_Address address; if (0 == *agc) return 0; + memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity)); + address.address = "Address"; + address.transport_name = "peerinfotest"; + address.address_length = *agc; ret = - GNUNET_HELLO_add_address ("peerinfotest", - GNUNET_TIME_relative_to_absolute - (GNUNET_TIME_UNIT_HOURS), "Address", *agc, buf, - max); + GNUNET_HELLO_add_address (&address, + GNUNET_TIME_relative_to_absolute + (GNUNET_TIME_UNIT_HOURS), buf, + max); (*agc)--; return ret; } diff --git a/src/testing/testing.c b/src/testing/testing.c index 175888621..8524e62ed 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c @@ -65,9 +65,9 @@ static struct GNUNET_CORE_MessageHandler no_handlers[] = { {NULL, 0, 0} }; #if EMPTY_HACK static int -test_address (void *cls, const char *tname, - struct GNUNET_TIME_Absolute expiration, const void *addr, - uint16_t addrlen) +test_address (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { int *empty = cls; diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index 3e4fd2685..38a648afc 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c @@ -774,16 +774,13 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) * Iterator called on each address. * * @param cls flag that we will set if we see any addresses - * @param tname name of the transport + * @param address the address of the peer * @param expiration when will the given address expire - * @param addr the address of the peer - * @param addrlen number of bytes in addr * @return GNUNET_SYSERR always, to terminate iteration */ static int -address_iterator (void *cls, const char *tname, - struct GNUNET_TIME_Absolute expiration, const void *addr, - uint16_t addrlen) +address_iterator (void *cls, const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { int *flag = cls; diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 11a8e23ae..542eb743e 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -25,6 +25,7 @@ */ #include "platform.h" #include "gnunet_util_lib.h" +#include "gnunet_hello_lib.h" #include "gnunet_statistics_service.h" #include "gnunet_transport_service.h" #include "gnunet_peerinfo_service.h" @@ -83,15 +84,13 @@ struct GNUNET_ATS_SchedulingHandle *GST_ats; * @param target a connected neighbour * @param ats performance information (unused) * @param ats_count number of records in ats (unused) - * @param transport plugin - * @param addr address - * @param addrlen address length + * @param address the address */ static void transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target, const struct GNUNET_ATS_Information *ats, - uint32_t ats_count, const char *transport, const void *addr, - size_t addrlen) + uint32_t ats_count, + const struct GNUNET_HELLO_Address *address) { const struct GNUNET_MessageHeader *hello = cls; @@ -200,7 +199,8 @@ process_payload (const struct GNUNET_PeerIdentity *peer, * (plugins that do not support this, can ignore the return value) */ static struct GNUNET_TIME_Relative -plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer, +plugin_env_receive_callback (void *cls, + const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *ats, uint32_t ats_count, struct Session *session, @@ -209,8 +209,13 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer, { const char *plugin_name = cls; struct GNUNET_TIME_Relative ret; + struct GNUNET_HELLO_Address address; uint16_t type; + address.peer = *peer; + address.address = sender_address; + address.address_length = sender_address_len; + address.transport_name = plugin_name; ret = GNUNET_TIME_UNIT_ZERO; if (NULL == message) goto end; @@ -229,37 +234,29 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer, #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, "Processing `%s' from `%s'\n", "PING", - (sender_address != NULL) ? GST_plugins_a2s (plugin_name, - sender_address, - sender_address_len) + (sender_address != NULL) ? GST_plugins_a2s (&address) : ""); #endif - GST_validation_handle_ping (peer, message, plugin_name, session, - sender_address, sender_address_len); + GST_validation_handle_ping (peer, message, &address, session); break; case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, "Processing `%s' from `%s'\n", "PONG", - (sender_address != NULL) ? GST_plugins_a2s (plugin_name, - sender_address, - sender_address_len) + (sender_address != NULL) ? GST_plugins_a2s (&address) : ""); #endif GST_validation_handle_pong (peer, message); break; case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT: - GST_neighbours_handle_connect (message, peer, plugin_name, sender_address, - sender_address_len, session, ats, ats_count); + GST_neighbours_handle_connect (message, peer, &address, session, ats, ats_count); break; case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK: - GST_neighbours_handle_connect_ack (message, peer, plugin_name, - sender_address, sender_address_len, + GST_neighbours_handle_connect_ack (message, peer, &address, session, ats, ats_count); break; case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: - GST_neighbours_handle_ack (message, peer, plugin_name, sender_address, - sender_address_len, session, ats, ats_count); + GST_neighbours_handle_ack (message, peer, &address, session, ats, ats_count); break; case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: GST_neighbours_handle_disconnect_message (peer, message); @@ -276,8 +273,7 @@ end: #if 1 /* FIXME: this should not be needed, and not sure it's good to have it, but without * this connections seem to go extra-slow */ - GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address, - sender_address_len, session, ats, ats_count); + GNUNET_ATS_address_update (GST_ats, &address, session, ats, ats_count); #endif #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -304,8 +300,13 @@ plugin_env_address_change_notification (void *cls, int add_remove, const void *addr, size_t addrlen) { const char *plugin_name = cls; + struct GNUNET_HELLO_Address address; - GST_hello_modify_addresses (add_remove, plugin_name, addr, addrlen); + address.peer = GST_my_identity; + address.transport_name = plugin_name; + address.address = addr; + address.address_length = addrlen; + GST_hello_modify_addresses (add_remove, &address); } @@ -326,6 +327,8 @@ static void plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, struct Session *session) { + struct GNUNET_HELLO_Address address; + #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Session %X to peer `%s' ended \n", session, GNUNET_i2s (peer)); @@ -335,7 +338,11 @@ plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, "transport-ats", "Telling ATS to destroy session %p from peer %s\n", session, GNUNET_i2s (peer)); - GNUNET_ATS_address_destroyed (GST_ats, peer, NULL, NULL, 0, session); + address.peer = *peer; + address.address = NULL; + address.address_length = 0; + address.transport_name = cls; + GNUNET_ATS_address_destroyed (GST_ats, &address, session); GST_neighbours_session_terminated (peer, session); } @@ -348,18 +355,15 @@ plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, * actually happened. * * @param cls closure - * @param peer identity of the peer - * @param plugin_name name of the transport plugin, NULL to disconnect + * @param address address to use (for peer given in address) * @param session session to use (if available) - * @param plugin_addr address to use (if available) - * @param plugin_addr_len number of bytes in addr * @param bandwidth_out assigned outbound bandwidth for the connection, 0 to disconnect from peer * @param bandwidth_in assigned inbound bandwidth for the connection, 0 to disconnect from peer */ static void -ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, const void *plugin_addr, - size_t plugin_addr_len, struct Session *session, +ats_request_address_change (void *cls, + const struct GNUNET_HELLO_Address *address, + struct Session *session, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, const struct GNUNET_ATS_Information *ats, @@ -374,14 +378,14 @@ ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer, #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS tells me to disconnect from peer `%s'\n", - GNUNET_i2s (peer)); + GNUNET_i2s (&address->peer)); #endif - GST_neighbours_force_disconnect (peer); + GST_neighbours_force_disconnect (&address->peer); return; } /* will never return GNUNET_YES since connection is to be established */ - GST_neighbours_switch_to_address_3way (peer, plugin_name, plugin_addr, - plugin_addr_len, session, ats, + GST_neighbours_switch_to_address_3way (&address->peer, + address, session, ats, ats_count, bandwidth_in, bandwidth_out); } diff --git a/src/transport/gnunet-service-transport_blacklist.c b/src/transport/gnunet-service-transport_blacklist.c index 78eea2ff9..b3edc01db 100644 --- a/src/transport/gnunet-service-transport_blacklist.c +++ b/src/transport/gnunet-service-transport_blacklist.c @@ -550,15 +550,13 @@ struct TestConnectionContext * @param neighbour neighbour's identity * @param ats performance data * @param ats_count number of entries in ats (excluding 0-termination) - * @param transport plugin - * @param addr address - * @param addrlen address length + * @param address the address */ static void test_connection_ok (void *cls, const struct GNUNET_PeerIdentity *neighbour, const struct GNUNET_ATS_Information *ats, - uint32_t ats_count, const char *transport, const void *addr, - size_t addrlen) + uint32_t ats_count, + const struct GNUNET_HELLO_Address *address) { struct TestConnectionContext *tcc = cls; struct GST_BlacklistCheck *bc; diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index ebab72db6..aee592d29 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c @@ -325,16 +325,14 @@ client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client) * @param peer identity of the neighbour * @param ats performance data * @param ats_count number of entries in ats (excluding 0-termination) - * @param transport plugin - * @param addr address - * @param addrlen address length + * @param address the address */ static void notify_client_about_neighbour (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *ats, - uint32_t ats_count, const char *transport, - const void *addr, size_t addrlen) + uint32_t ats_count, + const struct GNUNET_HELLO_Address *address) { struct TransportClient *tc = cls; struct ConnectInfoMessage *cim; @@ -719,33 +717,28 @@ clients_handle_address_lookup (void *cls, struct GNUNET_SERVER_Client *client, * * @param cls our 'struct GNUNET_SERVER_TransmitContext' (for sending) * @param public_key public key for the peer, never NULL - * @param target peer this change is about, never NULL * @param valid_until until what time do we consider the address valid? * @param validation_block is FOREVER if the address is for an unsupported plugin (from PEERINFO) * is ZERO if the address is considered valid (no validation needed) * is a time in the future if we're currently denying re-validation - * @param plugin_name name of the plugin - * @param plugin_address binary address - * @param plugin_address_len length of address + * @param address address to transmit */ static void send_address_to_client (void *cls, const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded - *public_key, const struct GNUNET_PeerIdentity *target, + *public_key, struct GNUNET_TIME_Absolute valid_until, struct GNUNET_TIME_Absolute validation_block, - const char *plugin_name, const void *plugin_address, - size_t plugin_address_len) + const struct GNUNET_HELLO_Address *address) { struct GNUNET_SERVER_TransmitContext *tc = cls; char *addr_buf; /* FIXME: move to a binary format!!! */ GNUNET_asprintf (&addr_buf, "%s --- %s, %s", - GST_plugins_a2s (plugin_name, plugin_address, - plugin_address_len), + GST_plugins_a2s (address), (GNUNET_YES == - GST_neighbours_test_connected (target)) ? "CONNECTED" : + GST_neighbours_test_connected (&address->peer)) ? "CONNECTED" : "DISCONNECTED", (GNUNET_TIME_absolute_get_remaining (valid_until).rel_value > 0) ? "VALIDATED" : "UNVALIDATED"); @@ -789,27 +782,26 @@ clients_handle_peer_address_lookup (void *cls, * @param neighbour identity of the neighbour * @param ats performance data * @param ats_count number of entries in ats (excluding 0-termination) - * @param transport plugin - * @param addr address - * @param addrlen address length + * @param address the address */ static void output_addresses (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *ats, uint32_t ats_count, - const char *transport, const void *addr, size_t addrlen) + const struct GNUNET_HELLO_Address *address) { struct GNUNET_SERVER_TransmitContext *tc = cls; struct AddressIterateResponseMessage *msg; size_t size; + size_t slen; - size = - (sizeof (struct AddressIterateResponseMessage) + strlen (transport) + 1); + slen = strlen (address->transport_name) + 1; + size = (sizeof (struct AddressIterateResponseMessage) + slen); msg = GNUNET_malloc (size); memcpy (&msg->peer, peer, sizeof (struct GNUNET_PeerIdentity)); - memcpy (&msg[0], transport, strlen (transport) + 1); - msg->addrlen = ntohs (addrlen); - msg->pluginlen = ntohs (strlen (transport) + 1); - + memcpy (&msg[0], address->transport_name, slen); + msg->addrlen = ntohs (address->address_length); + msg->pluginlen = ntohs (slen); + // FIXME: what about 'address->address'!? transmit_binary_to_client (tc, msg, size); GNUNET_free (msg); } diff --git a/src/transport/gnunet-service-transport_hello.c b/src/transport/gnunet-service-transport_hello.c index 45fdf0a26..8b38a673e 100644 --- a/src/transport/gnunet-service-transport_hello.c +++ b/src/transport/gnunet-service-transport_hello.c @@ -56,9 +56,9 @@ struct OwnAddressList struct OwnAddressList *prev; /** - * Name of the plugin. + * The address. */ - char *plugin_name; + struct GNUNET_HELLO_Address *address; /** * How long until the current signature expires? (ZERO if the @@ -71,11 +71,6 @@ struct OwnAddressList */ struct GNUNET_CRYPTO_RsaSignature pong_signature; - /** - * Length of addr. - */ - size_t addrlen; - }; @@ -143,9 +138,8 @@ address_generator (void *cls, size_t max, void *buf) if (NULL == gc->addr_pos) return 0; ret = - GNUNET_HELLO_add_address (gc->addr_pos->plugin_name, gc->expiration, - &gc->addr_pos[1], gc->addr_pos->addrlen, buf, - max); + GNUNET_HELLO_add_address (gc->addr_pos->address, gc->expiration, + buf, max); gc->addr_pos = gc->addr_pos->next; return ret; } @@ -253,14 +247,11 @@ GST_hello_get () * Add or remove an address from this peer's HELLO message. * * @param addremove GNUNET_YES to add, GNUNET_NO to remove - * @param plugin_name name of the plugin for which this is an address - * @param plugin_address address in a plugin-specific format - * @param plugin_address_len number of bytes in plugin_address + * @param address address to add or remove */ void -GST_hello_modify_addresses (int addremove, const char *plugin_name, - const void *plugin_address, - size_t plugin_address_len) +GST_hello_modify_addresses (int addremove, + const struct GNUNET_HELLO_Address *address) { struct OwnAddressList *al; @@ -269,18 +260,18 @@ GST_hello_modify_addresses (int addremove, const char *plugin_name, (add_remove == GNUNET_YES) ? "Adding `%s':%s to the set of our addresses\n" : "Removing `%s':%s from the set of our addresses\n", - GST_plugins_a2s (plugin_name, addr, addrlen), p->short_name); + GST_plugins_a2s (address), p->short_name); #endif - GNUNET_assert (plugin_address != NULL); + GNUNET_assert (address != NULL); if (GNUNET_NO == addremove) { for (al = oal_head; al != NULL; al = al->next) - if ((plugin_address_len == al->addrlen) && - (0 == strcmp (al->plugin_name, plugin_name)) && - (0 == memcmp (plugin_address, &al[1], plugin_address_len))) - { + if (0 == + GNUNET_HELLO_address_cmp (address, + al->address)) + { GNUNET_CONTAINER_DLL_remove (oal_head, oal_tail, al); - GNUNET_free (al->plugin_name); + GNUNET_HELLO_address_free (al->address); GNUNET_free (al); refresh_hello (); return; @@ -289,11 +280,9 @@ GST_hello_modify_addresses (int addremove, const char *plugin_name, GNUNET_break (0); return; } - al = GNUNET_malloc (sizeof (struct OwnAddressList) + plugin_address_len); + al = GNUNET_malloc (sizeof (struct OwnAddressList)); GNUNET_CONTAINER_DLL_insert (oal_head, oal_tail, al); - al->plugin_name = GNUNET_strdup (plugin_name); - al->addrlen = plugin_address_len; - memcpy (&al[1], plugin_address, plugin_address_len); + al->address = GNUNET_HELLO_address_copy (address); refresh_hello (); } @@ -301,9 +290,7 @@ GST_hello_modify_addresses (int addremove, const char *plugin_name, /** * Test if a particular address is one of ours. * - * @param plugin_name name of the plugin for which this is an address - * @param plugin_address address in a plugin-specific format - * @param plugin_address_len number of bytes in plugin_address + * @param address address to test * @param sig location where to cache PONG signatures for this address [set] * @param sig_expiration how long until the current 'sig' expires? * (ZERO if sig was never created) [set] @@ -311,17 +298,15 @@ GST_hello_modify_addresses (int addremove, const char *plugin_name, * GNUNET_NO if not */ int -GST_hello_test_address (const char *plugin_name, const void *plugin_address, - size_t plugin_address_len, +GST_hello_test_address (const struct GNUNET_HELLO_Address *address, struct GNUNET_CRYPTO_RsaSignature **sig, struct GNUNET_TIME_Absolute **sig_expiration) { struct OwnAddressList *al; for (al = oal_head; al != NULL; al = al->next) - if ((plugin_address_len == al->addrlen) && - (0 == strcmp (al->plugin_name, plugin_name)) && - (0 == memcmp (plugin_address, &al[1], plugin_address_len))) + if (0 == GNUNET_HELLO_address_cmp (address, + al->address)) { *sig = &al->pong_signature; *sig_expiration = &al->pong_sig_expires; diff --git a/src/transport/gnunet-service-transport_hello.h b/src/transport/gnunet-service-transport_hello.h index 8d15ec6b5..168dd4364 100644 --- a/src/transport/gnunet-service-transport_hello.h +++ b/src/transport/gnunet-service-transport_hello.h @@ -29,6 +29,7 @@ #include "gnunet_statistics_service.h" #include "gnunet_transport_service.h" #include "gnunet_util_lib.h" +#include "gnunet_hello_lib.h" @@ -72,22 +73,17 @@ GST_hello_get (void); * Add or remove an address from this peer's HELLO message. * * @param addremove GNUNET_YES to add, GNUNET_NO to remove - * @param plugin_name name of the plugin for which this is an address - * @param plugin_address address in a plugin-specific format - * @param plugin_address_len number of bytes in plugin_address + * @param address address to add or remove */ void -GST_hello_modify_addresses (int addremove, const char *plugin_name, - const void *plugin_address, - size_t plugin_address_len); +GST_hello_modify_addresses (int addremove, + const struct GNUNET_HELLO_Address *address); /** * Test if a particular address is one of ours. * - * @param plugin_name name of the plugin for which this is an address - * @param plugin_address address in a plugin-specific format - * @param plugin_address_len number of bytes in plugin_address + * @param address the address to test * @param sig location where to cache PONG signatures for this address [set] * @param sig_expiration how long until the current 'sig' expires? * (ZERO if sig was never created) [set] @@ -95,8 +91,7 @@ GST_hello_modify_addresses (int addremove, const char *plugin_name, * GNUNET_NO if not */ int -GST_hello_test_address (const char *plugin_name, const void *plugin_address, - size_t plugin_address_len, +GST_hello_test_address (const struct GNUNET_HELLO_Address *address, struct GNUNET_CRYPTO_RsaSignature **sig, struct GNUNET_TIME_Absolute **sig_expiration); diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c index e6b298f4f..a127209dd 100644 --- a/src/transport/gnunet-service-transport_neighbours.c +++ b/src/transport/gnunet-service-transport_neighbours.c @@ -234,19 +234,9 @@ struct NeighbourMapEntry struct Session *session; /** - * Name of the plugin we currently use. + * Address we currently use. */ - char *plugin_name; - - /** - * Address used for communicating with the peer, NULL for inbound connections. - */ - void *addr; - - /** - * Number of bytes in 'addr'. - */ - size_t addrlen; + struct GNUNET_HELLO_Address *address; /** * Identity of this neighbour. @@ -432,8 +422,7 @@ reset_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) */ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Information for developers: Connection to peer `%s' %s failed in state `%s', resetting connection attempt \n", - GNUNET_i2s (&n->id), GST_plugins_a2s (n->plugin_name, n->addr, - n->addrlen), + GNUNET_i2s (&n->id), GST_plugins_a2s (n->address), print_state (n->state)); GNUNET_STATISTICS_update (GST_stats, @@ -445,8 +434,7 @@ reset_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) n->state = S_NOT_CONNECTED; /* destroying address */ - GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr, - n->addrlen, NULL); + GNUNET_ATS_address_destroyed (GST_ats, n->address, NULL); /* request new address */ if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) @@ -496,8 +484,7 @@ change (struct NeighbourMapEntry *n, int state, int line) #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n", - GNUNET_i2s (&n->id), GST_plugins_a2s (n->plugin_name, - n->addr, n->addrlen), + GNUNET_i2s (&n->id), GST_plugins_a2s (n->address), print_state (n->state), print_state (state)); #endif GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK); @@ -520,8 +507,7 @@ change (struct NeighbourMapEntry *n, int state, int line) #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Removed reset task for peer `%s' %s failed in state transition `%s' -> `%s' \n", - GNUNET_i2s (&n->id), GST_plugins_a2s (n->plugin_name, - n->addr, n->addrlen), + GNUNET_i2s (&n->id), GST_plugins_a2s (n->address), print_state (n->state), print_state (state)); #endif GNUNET_assert (n->state_reset != GNUNET_SCHEDULER_NO_TASK); @@ -580,7 +566,7 @@ static ssize_t send_with_plugin (const struct GNUNET_PeerIdentity *target, const char *msgbuf, size_t msgbuf_size, uint32_t priority, struct GNUNET_TIME_Relative timeout, struct Session *session, - const char *plugin_name, const void *addr, size_t addrlen, + const struct GNUNET_HELLO_Address *address, int force_address, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) { @@ -588,21 +574,21 @@ send_with_plugin (const struct GNUNET_PeerIdentity *target, const char *msgbuf, size_t ret = GNUNET_SYSERR; /* FIXME : ats returns an address with all values 0 */ - if (plugin_name == NULL) + if (address == NULL) { if (cont != NULL) cont (cont_cls, target, GNUNET_SYSERR); return GNUNET_SYSERR; } - if ((session == NULL) && (addr == NULL) && (addrlen == 0)) + if ((session == NULL) && (address == NULL)) { if (cont != NULL) cont (cont_cls, target, GNUNET_SYSERR); return GNUNET_SYSERR; } - papi = GST_plugins_find (plugin_name); + papi = GST_plugins_find (address->transport_name); if (papi == NULL) { if (cont != NULL) @@ -612,7 +598,8 @@ send_with_plugin (const struct GNUNET_PeerIdentity *target, const char *msgbuf, ret = papi->send (papi->cls, target, msgbuf, msgbuf_size, 0, timeout, session, - addr, addrlen, GNUNET_YES, cont, cont_cls); + address->address, + address->address_length, GNUNET_YES, cont, cont_cls); if (ret == -1) { @@ -706,7 +693,7 @@ try_transmission_to_peer (struct NeighbourMapEntry *n) if (NULL == mq) return; /* no more messages */ - if (GST_plugins_find (n->plugin_name) == NULL) + if (GST_plugins_find (n->address->transport_name) == NULL) { GNUNET_break (0); return; @@ -715,9 +702,10 @@ try_transmission_to_peer (struct NeighbourMapEntry *n) n->is_active = mq; mq->n = n; - if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen == 0)) + if ( (n->session == NULL) && (NULL == n->address) ) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No address for peer `%s'\n", + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "No address for peer `%s'\n", GNUNET_i2s (&n->id)); transmit_send_continuation (mq, &n->id, GNUNET_SYSERR); GNUNET_assert (n->transmission_task == GNUNET_SCHEDULER_NO_TASK); @@ -727,8 +715,8 @@ try_transmission_to_peer (struct NeighbourMapEntry *n) ret = send_with_plugin (&n->id, mq->message_buf, mq->message_buf_size, 0, - timeout, n->session, n->plugin_name, n->addr, - n->addrlen, GNUNET_YES, &transmit_send_continuation, + timeout, n->session, n->address, + GNUNET_YES, &transmit_send_continuation, mq); if (ret == -1) { @@ -789,8 +777,8 @@ send_disconnect_cont (void *cls, const struct GNUNET_PeerIdentity *target, static int send_disconnect (const struct GNUNET_PeerIdentity *target, - const char *plugin_name, const char *sender_address, - uint16_t sender_address_len, struct Session *session) + const struct GNUNET_HELLO_Address *address, + struct Session *session) { size_t ret; struct SessionDisconnectMessage disconnect_msg; @@ -821,8 +809,8 @@ send_disconnect (const struct GNUNET_PeerIdentity *target, ret = send_with_plugin (target, (const char *) &disconnect_msg, sizeof (disconnect_msg), UINT32_MAX, - GNUNET_TIME_UNIT_FOREVER_REL, session, plugin_name, - sender_address, sender_address_len, GNUNET_YES, + GNUNET_TIME_UNIT_FOREVER_REL, session, address, + GNUNET_YES, &send_disconnect_cont, NULL); if (ret == GNUNET_SYSERR) @@ -850,7 +838,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n) if (is_connected (n) || is_connecting (n)) { if (GNUNET_OK == - send_disconnect (&n->id, n->plugin_name, n->addr, n->addrlen, + send_disconnect (&n->id, n->address, n->session)) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent DISCONNECT_MSG to `%s'\n", GNUNET_i2s (&n->id)); @@ -862,8 +850,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n) if (is_connected(n)) { - GNUNET_ATS_address_in_use (GST_ats, &n->id, n->plugin_name, - n->addr, n->addrlen, n->session, GNUNET_NO); + GNUNET_ATS_address_in_use (GST_ats, n->address, n->session, GNUNET_NO); } @@ -871,16 +858,14 @@ disconnect_neighbour (struct NeighbourMapEntry *n) return; change_state (n, S_DISCONNECT); GST_validation_set_address_use (&n->id, - n->plugin_name, + n->address, n->session, - n->addr, - n->addrlen, GNUNET_NO); - if (n->plugin_name != NULL) + if (n->address != NULL) { struct GNUNET_TRANSPORT_PluginFunctions *papi; - papi = GST_plugins_find (n->plugin_name); + papi = GST_plugins_find (n->address->transport_name); if (papi != NULL) papi->disconnect (papi->cls, &n->id); } @@ -926,16 +911,10 @@ disconnect_neighbour (struct NeighbourMapEntry *n) GNUNET_SCHEDULER_cancel (n->transmission_task); n->transmission_task = GNUNET_SCHEDULER_NO_TASK; } - if (NULL != n->plugin_name) - { - GNUNET_free (n->plugin_name); - n->plugin_name = NULL; - } - if (NULL != n->addr) + if (NULL != n->address) { - GNUNET_free (n->addr); - n->addr = NULL; - n->addrlen = 0; + GNUNET_HELLO_address_free (n->address); + n->address = NULL; } n->session = NULL; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Deleting peer `%4s', %X\n", @@ -990,8 +969,8 @@ neighbour_keepalive_task (void *cls, send_with_plugin (&n->id, (const void *) &m, sizeof (m), UINT32_MAX /* priority */ , - GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->plugin_name, - n->addr, n->addrlen, GNUNET_YES, NULL, NULL); + GNUNET_TIME_UNIT_FOREVER_REL, n->session, n->address, + GNUNET_YES, NULL, NULL); } @@ -1083,14 +1062,12 @@ send_connect_continuation (void *cls, const struct GNUNET_PeerIdentity *target, #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n", - GNUNET_i2s (&n->id), n->plugin_name, + GNUNET_i2s (&n->id), n->address->transport_name, (n->addrlen == - 0) ? "" : GST_plugins_a2s (n->plugin_name, n->addr, - n->addrlen), n->session); + 0) ? "" : GST_plugins_a2s (n->address), n->session); #endif - GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr, - n->addrlen, NULL); + GNUNET_ATS_address_destroyed (GST_ats, n->address, NULL); change_state (n, S_NOT_CONNECTED); @@ -1131,14 +1108,12 @@ send_switch_address_continuation (void *cls, #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to switch connected peer `%s' to plugin `%s' address '%s' session %X, asking ATS for new address \n", - GNUNET_i2s (&n->id), n->plugin_name, + GNUNET_i2s (&n->id), n->address->transport_name, (n->addrlen == - 0) ? "" : GST_plugins_a2s (n->plugin_name, n->addr, - n->addrlen), n->session); + 0) ? "" : GST_plugins_a2s (n->address), n->session); #endif - GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr, - n->addrlen, NULL); + GNUNET_ATS_address_destroyed (GST_ats, n->address, NULL); if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (n->ats_suggest); @@ -1149,8 +1124,7 @@ send_switch_address_continuation (void *cls, return; } /* Tell ATS that switching addresses was successful */ - GNUNET_ATS_address_in_use (GST_ats, &n->id, n->plugin_name, n->addr, - n->addrlen, n->addr, GNUNET_YES); + GNUNET_ATS_address_in_use (GST_ats, n->address, n->session, GNUNET_YES); } /** @@ -1177,16 +1151,13 @@ send_connect_ack_continuation (void *cls, #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to send CONNECT_MSG to peer `%4s' with plugin `%s' address '%s' session %X, asking ATS for new address \n", - GNUNET_i2s (&n->id), n->plugin_name, - (n->addrlen == 0) ? "" : GST_plugins_a2s (n->plugin_name, - n->addr, - n->addrlen), + GNUNET_i2s (&n->id), n->address->transport_name, + (n->addrlen == 0) ? "" : GST_plugins_a2s (n->address), n->session); #endif change_state (n, S_NOT_CONNECTED); - GNUNET_ATS_address_destroyed (GST_ats, &n->id, n->plugin_name, n->addr, - n->addrlen, NULL); + GNUNET_ATS_address_destroyed (GST_ats, n->address, NULL); if (n->ats_suggest != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (n->ats_suggest); @@ -1201,10 +1172,8 @@ send_connect_ack_continuation (void *cls, * the given address. * * @param peer identity of the peer to switch the address for - * @param plugin_name name of transport that delivered the PONG * @param address address of the other peer, NULL if other peer * connected to us - * @param address_len number of bytes in address * @param session session to use (or NULL) * @param ats performance data * @param ats_count number of entries in ats @@ -1213,8 +1182,7 @@ send_connect_ack_continuation (void *cls, */ int GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const void *address, size_t address_len, + const struct GNUNET_HELLO_Address *address, struct Session *session, const struct GNUNET_ATS_Information *ats, uint32_t ats_count, @@ -1237,14 +1205,14 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, checks_failed = GNUNET_NO; - if (plugin_name == NULL) + if (address == NULL) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "ATS offered suggested us empty address: plugin NULL"); GNUNET_break_op (0); checks_failed = GNUNET_YES; } - if ((address == NULL) && (address_len == 0) && (session == NULL)) + if ( (session == NULL) && (address == NULL) ) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "ATS offered suggested us empty address: address NULL & session NULL"); @@ -1258,8 +1226,7 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, if (checks_failed == GNUNET_YES) { - GNUNET_ATS_address_destroyed (GST_ats, peer, plugin_name, address, - address_len, session); + GNUNET_ATS_address_destroyed (GST_ats, address, session); if (n != NULL) GNUNET_ATS_suggest_address (GST_ats, peer); return GNUNET_NO; @@ -1269,10 +1236,8 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS tells us to switch to plugin `%s' address '%s' session %X for %s peer `%s'\n", - plugin_name, - (address_len == 0) ? "" : GST_plugins_a2s (plugin_name, - address, - address_len), + address->transport_name, + (address_len == 0) ? "" : GST_plugins_a2s (address), session, (is_connected (n) ? "CONNECTED" : "NOT CONNECTED"), GNUNET_i2s (peer)); #endif @@ -1284,66 +1249,57 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, } // do not switch addresses just update quotas - if ((is_connected (n)) && (address_len == n->addrlen)) + if ( (is_connected (n)) && + (0 == GNUNET_HELLO_address_cmp (address, + n->address)) && + (n->session == session) ) { - if ((0 == memcmp (address, n->addr, address_len)) && - (n->session == session)) - { - struct QuotaSetMessage q_msg; - + struct QuotaSetMessage q_msg; + #if DEBUG_TRANSPORT - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Sending outbound quota of %u Bps and inbound quota of %u Bps for peer `%s' to all clients\n", - ntohl (n->bandwidth_out.value__), - ntohl (n->bandwidth_in.value__), GNUNET_i2s (peer)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Sending outbound quota of %u Bps and inbound quota of %u Bps for peer `%s' to all clients\n", + ntohl (n->bandwidth_out.value__), + ntohl (n->bandwidth_in.value__), GNUNET_i2s (peer)); #endif - - n->bandwidth_in = bandwidth_in; - n->bandwidth_out = bandwidth_out; - GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in); - - q_msg.header.size = htons (sizeof (struct QuotaSetMessage)); - q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); - q_msg.quota = n->bandwidth_out; - q_msg.peer = (*peer); - GST_clients_broadcast (&q_msg.header, GNUNET_NO); - return GNUNET_NO; - } + + n->bandwidth_in = bandwidth_in; + n->bandwidth_out = bandwidth_out; + GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in); + + q_msg.header.size = htons (sizeof (struct QuotaSetMessage)); + q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); + q_msg.quota = n->bandwidth_out; + q_msg.peer = (*peer); + GST_clients_broadcast (&q_msg.header, GNUNET_NO); + return GNUNET_NO; } if (n->state == S_CONNECTED) GST_validation_set_address_use (&n->id, - n->plugin_name, + n->address, n->session, - n->addr, - n->addrlen, GNUNET_NO); /* This will be a connection switch, tell ATS about it */ if (n->state == S_CONNECTED) { - GNUNET_ATS_address_in_use (GST_ats, &n->id, n->plugin_name, n->addr, - n->addrlen, n->addr, GNUNET_NO); + GNUNET_ATS_address_in_use (GST_ats, n->address, n->session, GNUNET_NO); } /* set new address */ - GNUNET_free_non_null (n->addr); - n->addr = GNUNET_malloc (address_len); - memcpy (n->addr, address, address_len); + if (NULL != n->address) + GNUNET_HELLO_address_free (n->address); + n->address = GNUNET_HELLO_address_copy (address); n->bandwidth_in = bandwidth_in; n->bandwidth_out = bandwidth_out; - n->addrlen = address_len; n->session = session; - GNUNET_free_non_null (n->plugin_name); - n->plugin_name = GNUNET_strdup (plugin_name); GNUNET_SCHEDULER_cancel (n->timeout_task); n->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &neighbour_timeout_task, n); if (n->state == S_CONNECTED) GST_validation_set_address_use (&n->id, - n->plugin_name, + n->address, n->session, - n->addr, - n->addrlen, GNUNET_YES); @@ -1368,7 +1324,7 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, ret = send_with_plugin (peer, (const char *) &connect_msg, msg_len, UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, - plugin_name, address, address_len, GNUNET_YES, + address, GNUNET_YES, &send_connect_continuation, n); @@ -1388,7 +1344,7 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, ret = send_with_plugin (&n->id, (const void *) &connect_msg, msg_len, UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, - plugin_name, address, address_len, GNUNET_YES, + address, GNUNET_YES, &send_connect_ack_continuation, n); return GNUNET_NO; } @@ -1406,16 +1362,14 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, ret = send_with_plugin (peer, (const char *) &connect_msg, msg_len, UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, session, - plugin_name, address, address_len, GNUNET_YES, + address, GNUNET_YES, &send_switch_address_continuation, n); if (ret == GNUNET_SYSERR) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Failed to send CONNECT_MESSAGE to `%4s' using plugin `%s' address '%s' session %X\n", - GNUNET_i2s (peer), plugin_name, - (address_len == - 0) ? "" : GST_plugins_a2s (plugin_name, address, - address_len), session); + "Failed to send CONNECT_MESSAGE to `%4s' using address '%s' session %X\n", + GNUNET_i2s (peer), + GST_plugins_a2s (address), session); } return GNUNET_NO; } @@ -1446,10 +1400,8 @@ GST_neighbour_get_latency (const struct GNUNET_PeerIdentity *peer) if (NULL == n) return GNUNET_TIME_UNIT_FOREVER_REL; return GST_validation_get_address_latency (peer, - n->plugin_name, - n->session, - n->addr, - n->addrlen); + n->address, + n->session); } @@ -1587,9 +1539,11 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, return; /* doesn't affect us */ n->session = NULL; - GNUNET_free (n->addr); - n->addr = NULL; - n->addrlen = 0; + if (NULL != n->address) + { + GNUNET_HELLO_address_free (n->address); + n->address = NULL; + } /* not connected anymore anyway, shouldn't matter */ if ((!is_connected (n)) && (!is_connecting (n))) @@ -1656,7 +1610,7 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg, return; } - if ((n->session == NULL) && (n->addr == NULL) && (n->addrlen == 0)) + if ((n->session == NULL) && (n->address == NULL) ) { GNUNET_STATISTICS_update (GST_stats, gettext_noop @@ -1898,7 +1852,7 @@ neighbours_iterate (void *cls, const GNUNET_HashCode * key, void *value) if (!is_connected (n)) return GNUNET_OK; - ic->cb (ic->cb_cls, &n->id, NULL, 0, n->plugin_name, n->addr, n->addrlen); + ic->cb (ic->cb_cls, &n->id, NULL, 0, n->address); return GNUNET_OK; } @@ -1946,7 +1900,7 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target) return; /* not active */ if (is_connected (n)) { - send_disconnect (&n->id, n->plugin_name, n->addr, n->addrlen, n->session); + send_disconnect (&n->id, n->address, n->session); n = lookup_neighbour (target); if (NULL == n) @@ -2028,26 +1982,23 @@ GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity GST_neighbours_force_disconnect (peer); } + /** * We received a 'SESSION_CONNECT_ACK' message from the other peer. * Consider switching to it. * * @param message possibly a 'struct SessionConnectMessage' (check format) * @param peer identity of the peer to switch the address for - * @param plugin_name name of transport that delivered the PONG * @param address address of the other peer, NULL if other peer * connected to us - * @param address_len number of bytes in address * @param session session to use (or NULL) * @param ats performance data * @param ats_count number of entries in ats - */ + */ void GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const char *sender_address, - uint16_t sender_address_len, + const struct GNUNET_HELLO_Address *address, struct Session *session, const struct GNUNET_ATS_Information *ats, uint32_t ats_count) @@ -2090,24 +2041,20 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, "transport-ats", "Giving ATS session %p of plugin %s for peer %s\n", - session, plugin_name, GNUNET_i2s (peer)); - GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address, - sender_address_len, session, ats, ats_count); + session, address->transport_name, GNUNET_i2s (peer)); + GNUNET_ATS_address_update (GST_ats, address, session, ats, ats_count); was_connected = is_connected (n); if (!is_connected (n)) { change_state (n, S_CONNECTED); GST_validation_set_address_use (&n->id, - n->plugin_name, + n->address, n->session, - n->addr, - n->addrlen, GNUNET_YES); } - GNUNET_ATS_address_in_use (GST_ats, &n->id, n->plugin_name, n->addr, - n->addrlen, n->addr, GNUNET_YES); + GNUNET_ATS_address_in_use (GST_ats, n->address, NULL, GNUNET_YES); #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -2124,16 +2071,14 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, ret = send_with_plugin (&n->id, (const char *) &msg, msg_len, UINT32_MAX, GNUNET_TIME_UNIT_FOREVER_REL, n->session, - n->plugin_name, n->addr, n->addrlen, GNUNET_YES, NULL, + n->address, GNUNET_YES, NULL, NULL); if (ret == GNUNET_SYSERR) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Failed to send SESSION_ACK to `%4s' using plugin `%s' address '%s' session %X\n", - GNUNET_i2s (&n->id), n->plugin_name, - (n->addrlen == - 0) ? "" : GST_plugins_a2s (n->plugin_name, n->addr, - n->addrlen), n->session); + "Failed to send SESSION_ACK to `%4s' using address '%s' session %X\n", + GNUNET_i2s (&n->id), + GST_plugins_a2s (n->address), n->session); if (!was_connected) @@ -2148,11 +2093,9 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, GNUNET_NO); #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Notify about connect of `%4s' using plugin `%s' address '%s' session %X LINE %u\n", - GNUNET_i2s (&n->id), n->plugin_name, - (n->addrlen == - 0) ? "" : GST_plugins_a2s (n->plugin_name, n->addr, - n->addrlen), n->session, + "Notify about connect of `%4s' using address '%s' session %X LINE %u\n", + GNUNET_i2s (&n->id), + GST_plugins_a2s (n->address), n->session, __LINE__); #endif connect_notify_cb (callback_cls, &n->id, ats, ats_count); @@ -2174,8 +2117,8 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, void GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, const char *sender_address, - uint16_t sender_address_len, struct Session *session, + const struct GNUNET_HELLO_Address *address, + struct Session *session, const struct GNUNET_ATS_Information *ats, uint32_t ats_count) { @@ -2197,7 +2140,7 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, n = lookup_neighbour (peer); if (NULL == n) { - send_disconnect (peer, plugin_name, sender_address, sender_address_len, + send_disconnect (peer, address, session); GNUNET_break (0); return; @@ -2217,15 +2160,13 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, "transport-ats", "Giving ATS session %p of plugin %s for peer %s\n", - session, plugin_name, GNUNET_i2s (peer)); - GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address, - sender_address_len, session, ats, ats_count); + session, address->transport_name, GNUNET_i2s (peer)); + GNUNET_ATS_address_update (GST_ats, address, session, ats, ats_count); was_connected = is_connected (n); change_state (n, S_CONNECTED); - GNUNET_ATS_address_in_use (GST_ats, &n->id, n->plugin_name, n->addr, - n->addrlen, n->addr, GNUNET_YES); + GNUNET_ATS_address_in_use (GST_ats, n->address, n->session, GNUNET_YES); GST_neighbours_set_incoming_quota (&n->id, n->bandwidth_in); @@ -2237,10 +2178,8 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, if (!was_connected) { GST_validation_set_address_use (&n->id, - n->plugin_name, + n->address, n->session, - n->addr, - n->addrlen, GNUNET_YES); neighbours_connected++; GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# peers connected"), 1, @@ -2248,11 +2187,9 @@ GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Notify about connect of `%4s' using plugin `%s' address '%s' session %X LINE %u\n", - GNUNET_i2s (&n->id), n->plugin_name, - (n->addrlen == - 0) ? "" : GST_plugins_a2s (n->plugin_name, n->addr, - n->addrlen), n->session, + "Notify about connect of `%4s' using address '%s' session %X LINE %u\n", + GNUNET_i2s (&n->id), + GST_plugins_a2s (n->address), n->session, __LINE__); #endif connect_notify_cb (callback_cls, &n->id, ats, ats_count); @@ -2277,11 +2214,7 @@ struct BlackListCheckContext struct Session *session; - char *sender_address; - - uint16_t sender_address_len; - - char *plugin_name; + struct GNUNET_HELLO_Address *address; struct GNUNET_TIME_Absolute ts; }; @@ -2305,6 +2238,7 @@ handle_connect_blacklist_cont (void *cls, /* not allowed */ if (GNUNET_OK != result) { + GNUNET_HELLO_address_free (bcc->address); GNUNET_free (bcc); return; } @@ -2318,13 +2252,11 @@ handle_connect_blacklist_cont (void *cls, if (NULL != bcc->session) GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, "transport-ats", - "Giving ATS session %p of plugin %s address `%s' for peer %s\n", - bcc->session, bcc->plugin_name, - GST_plugins_a2s (bcc->plugin_name, bcc->sender_address, - bcc->sender_address_len), + "Giving ATS session %p of address `%s' for peer %s\n", + bcc->session, + GST_plugins_a2s (bcc->address), GNUNET_i2s (peer)); - GNUNET_ATS_address_update (GST_ats, peer, bcc->plugin_name, - bcc->sender_address, bcc->sender_address_len, + GNUNET_ATS_address_update (GST_ats, bcc->address, bcc->session, bcc->ats, bcc->ats_count); n->connect_ts = bcc->ts; } @@ -2349,20 +2281,16 @@ handle_connect_blacklist_cont (void *cls, * * @param message possibly a 'struct SessionConnectMessage' (check format) * @param peer identity of the peer to switch the address for - * @param plugin_name name of transport that delivered the PONG * @param address address of the other peer, NULL if other peer * connected to us - * @param address_len number of bytes in address * @param session session to use (or NULL) * @param ats performance data * @param ats_count number of entries in ats (excluding 0-termination) - */ + */ void GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message, const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const char *sender_address, - uint16_t sender_address_len, + const struct GNUNET_HELLO_Address *address, struct Session *session, const struct GNUNET_ATS_Information *ats, uint32_t ats_count) @@ -2391,8 +2319,7 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message, /* connected peer switches addresses */ if (is_connected (n)) { - GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address, - sender_address_len, session, ats, ats_count); + GNUNET_ATS_address_update (GST_ats, address, session, ats, ats_count); return; } } @@ -2401,26 +2328,16 @@ GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message, /* do blacklist check */ bcc = GNUNET_malloc (sizeof (struct BlackListCheckContext) + - sizeof (struct GNUNET_ATS_Information) * (ats_count + 1) + - sender_address_len + strlen (plugin_name) + 1); - + sizeof (struct GNUNET_ATS_Information) * (ats_count + 1)); bcc->ts = GNUNET_TIME_absolute_ntoh (scm->timestamp); - bcc->ats_count = ats_count + 1; - bcc->sender_address_len = sender_address_len; + bcc->address = GNUNET_HELLO_address_copy (address); bcc->session = session; - bcc->ats = (struct GNUNET_ATS_Information *) &bcc[1]; memcpy (bcc->ats, ats, sizeof (struct GNUNET_ATS_Information) * ats_count); bcc->ats[ats_count].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); bcc->ats[ats_count].value = htonl ((uint32_t) GST_neighbour_get_latency (peer).rel_value); - bcc->sender_address = (char *) &bcc->ats[ats_count + 1]; - memcpy (bcc->sender_address, sender_address, sender_address_len); - - bcc->plugin_name = &bcc->sender_address[sender_address_len]; - strcpy (bcc->plugin_name, plugin_name); - - GST_blacklist_test_allowed (peer, plugin_name, handle_connect_blacklist_cont, + GST_blacklist_test_allowed (peer, address->transport_name, handle_connect_blacklist_cont, bcc); } diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h index 48e54e656..72ced636d 100644 --- a/src/transport/gnunet-service-transport_neighbours.h +++ b/src/transport/gnunet-service-transport_neighbours.h @@ -152,17 +152,14 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target); * @param neighbour identity of the neighbour * @param ats performance data * @param ats_count number of entries in ats (including 0-termination) - * @param transport plugin - * @param addr address - * @param addrlen address length + * @param address the address (or NULL) */ typedef void (*GST_NeighbourIterator) (void *cls, const struct GNUNET_PeerIdentity * neighbour, const struct GNUNET_ATS_Information * ats, uint32_t ats_count, - const char *transport, const void *addr, - size_t addrlen); + const struct GNUNET_HELLO_Address *address); /** @@ -191,10 +188,8 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, * use the given address. * * @param peer identity of the peer to switch the address for - * @param plugin_name name of transport that delivered the PONG * @param address address of the other peer, NULL if other peer * connected to us - * @param address_len number of bytes in address * @param session session to use (or NULL) * @param ats performance data * @param ats_count number of entries in ats @@ -204,19 +199,11 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, * connection is not up (yet) */ int -GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, const void *address, - size_t address_len, struct Session *session, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count); - -int GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const void *address, size_t address_len, - struct Session *session, - const struct GNUNET_ATS_Information *ats, - uint32_t ats_count, + const struct GNUNET_HELLO_Address *address, + struct Session *session, + const struct GNUNET_ATS_Information *ats, + uint32_t ats_count, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, struct GNUNET_BANDWIDTH_Value32NBO @@ -229,10 +216,8 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, * * @param message possibly a 'struct SessionConnectMessage' (check format) * @param peer identity of the peer to switch the address for - * @param plugin_name name of transport that delivered the PONG * @param address address of the other peer, NULL if other peer * connected to us - * @param address_len number of bytes in address * @param session session to use (or NULL) * @param ats performance data * @param ats_count number of entries in ats (excluding 0-termination) @@ -240,19 +225,28 @@ GST_neighbours_switch_to_address_3way (const struct GNUNET_PeerIdentity *peer, void GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message, const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const char *sender_address, - uint16_t sender_address_len, + const struct GNUNET_HELLO_Address *address, struct Session *session, const struct GNUNET_ATS_Information *ats, uint32_t ats_count); + +/** + * We received a 'SESSION_CONNECT_ACK' message from the other peer. + * Consider switching to it. + * + * @param message possibly a 'struct SessionConnectMessage' (check format) + * @param peer identity of the peer to switch the address for + * @param address address of the other peer, NULL if other peer + * connected to us + * @param session session to use (or NULL) + * @param ats performance data + * @param ats_count number of entries in ats + */ void GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, - const char *sender_address, - uint16_t sender_address_len, + const struct GNUNET_HELLO_Address *address, struct Session *session, const struct GNUNET_ATS_Information *ats, uint32_t ats_count); @@ -260,8 +254,8 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, void GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, const struct GNUNET_PeerIdentity *peer, - const char *plugin_name, const char *sender_address, - uint16_t sender_address_len, struct Session *session, + const struct GNUNET_HELLO_Address *address, + struct Session *session, const struct GNUNET_ATS_Information *ats, uint32_t ats_count); diff --git a/src/transport/gnunet-service-transport_plugins.c b/src/transport/gnunet-service-transport_plugins.c index 52fcf661d..3c4466753 100644 --- a/src/transport/gnunet-service-transport_plugins.c +++ b/src/transport/gnunet-service-transport_plugins.c @@ -189,22 +189,20 @@ GST_plugins_find (const char *name) * Convert a given address to a human-readable format. Note that the * return value will be overwritten on the next call to this function. * - * @param name plugin name - * @param addr binary address in plugin-specific format - * @param addrlen number of bytes in 'addr' + * @param address the address to convert * @return statically allocated (!) human-readable address */ const char * -GST_plugins_a2s (const char *name, const void *addr, size_t addrlen) +GST_plugins_a2s (const struct GNUNET_HELLO_Address *address) { struct GNUNET_TRANSPORT_PluginFunctions *api; - if (name == NULL) + if (address == NULL) + return ""; + api = GST_plugins_find (address->transport_name); + if ((api == NULL) || (address->address_length == 0) || (address->address == NULL)) return NULL; - api = GST_plugins_find (name); - if ((api == NULL) || (addrlen == 0) || (addr == NULL)) - return NULL; - return api->address_to_string (NULL, addr, addrlen); + return api->address_to_string (NULL, address->address, address->address_length); } diff --git a/src/transport/gnunet-service-transport_plugins.h b/src/transport/gnunet-service-transport_plugins.h index 3a49f004f..3cca3ce10 100644 --- a/src/transport/gnunet-service-transport_plugins.h +++ b/src/transport/gnunet-service-transport_plugins.h @@ -30,6 +30,7 @@ #include "gnunet_transport_service.h" #include "gnunet_transport_plugin.h" #include "gnunet_util_lib.h" +#include "gnunet_hello_lib.h" /** @@ -69,13 +70,11 @@ GST_plugins_find (const char *name); * Convert a given address to a human-readable format. Note that the * return value will be overwritten on the next call to this function. * - * @param name plugin name - * @param addr binary address in plugin-specific format - * @param addrlen number of bytes in 'addr' + * @param address address to convert * @return statically allocated (!) human-readable address */ const char * -GST_plugins_a2s (const char *name, const void *addr, size_t addrlen); +GST_plugins_a2s (const struct GNUNET_HELLO_Address *address); #endif diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c index afc35a3a6..9b93c7508 100644 --- a/src/transport/gnunet-service-transport_validation.c +++ b/src/transport/gnunet-service-transport_validation.c @@ -175,15 +175,9 @@ struct ValidationEntry { /** - * Name of the transport. + * The address. */ - char *transport_name; - - /** - * The address, actually a pointer to the end - * of this struct. Do not free! - */ - const void *addr; + struct GNUNET_HELLO_Address *address; /** * Handle to the blacklist check (if we're currently in it). @@ -196,7 +190,7 @@ struct ValidationEntry struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; /** - * The identity of the peer. + * The identity of the peer. FIXME: duplicated (also in 'address') */ struct GNUNET_PeerIdentity pid; @@ -240,11 +234,6 @@ struct ValidationEntry */ uint32_t challenge; - /** - * Length of addr. - */ - size_t addrlen; - /** * When passing the address in 'add_valid_peer_address', did we * copy the address to the HELLO yet? @@ -317,20 +306,11 @@ struct ValidationEntryMatchContext */ struct ValidationEntry *ve; - /** - * Transport name we're looking for. - */ - const char *transport_name; - /** * Address we're interested in. */ - const char *addr; + const struct GNUNET_HELLO_Address *address; - /** - * Number of bytes in 'addr'. - */ - size_t addrlen; }; @@ -349,9 +329,9 @@ validation_entry_match (void *cls, const GNUNET_HashCode * key, void *value) struct ValidationEntryMatchContext *vemc = cls; struct ValidationEntry *ve = value; - if ((ve->addrlen == vemc->addrlen) && - (0 == memcmp (ve->addr, vemc->addr, ve->addrlen)) && - (0 == strcmp (ve->transport_name, vemc->transport_name))) + if (0 == + GNUNET_HELLO_address_cmp (ve->address, + vemc->address)) { vemc->ve = ve; return GNUNET_NO; @@ -381,7 +361,7 @@ cleanup_validation_entry (void *cls, const GNUNET_HashCode * key, void *value) GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multihashmap_remove (validation_map, &ve->pid.hashPubKey, ve)); - GNUNET_free (ve->transport_name); + GNUNET_HELLO_address_free (ve->address); if (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task) { GNUNET_SCHEDULER_cancel (ve->timeout_task); @@ -454,16 +434,15 @@ transmit_ping_if_allowed (void *cls, const struct GNUNET_PeerIdentity *pid, ve->bc = NULL; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting plain PING to `%s' %s\n", - GNUNET_i2s (pid), GST_plugins_a2s (ve->transport_name, ve->addr, - ve->addrlen)); + GNUNET_i2s (pid), GST_plugins_a2s (ve->address)); - slen = strlen (ve->transport_name) + 1; + slen = strlen (ve->address->transport_name) + 1; hello = GST_hello_get (); hsize = ntohs (hello->size); - tsize = sizeof (struct TransportPingMessage) + ve->addrlen + slen + hsize; + tsize = sizeof (struct TransportPingMessage) + ve->address->address_length + slen + hsize; ping.header.size = - htons (sizeof (struct TransportPingMessage) + ve->addrlen + slen); + htons (sizeof (struct TransportPingMessage) + ve->address->address_length + slen); ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING); ping.challenge = htonl (ve->challenge); ping.target = *pid; @@ -476,7 +455,7 @@ transmit_ping_if_allowed (void *cls, const struct GNUNET_PeerIdentity *pid, "HELLO", "PING", (unsigned int) tsize); /* message too big (!?), get rid of HELLO */ hsize = 0; - tsize = sizeof (struct TransportPingMessage) + ve->addrlen + slen + hsize; + tsize = sizeof (struct TransportPingMessage) + ve->address->address_length + slen + hsize; } { char message_buf[tsize]; @@ -486,10 +465,10 @@ transmit_ping_if_allowed (void *cls, const struct GNUNET_PeerIdentity *pid, memcpy (message_buf, hello, hsize); memcpy (&message_buf[hsize], &ping, sizeof (struct TransportPingMessage)); memcpy (&message_buf[sizeof (struct TransportPingMessage) + hsize], - ve->transport_name, slen); + ve->address->transport_name, slen); memcpy (&message_buf[sizeof (struct TransportPingMessage) + slen + hsize], - ve->addr, ve->addrlen); - papi = GST_plugins_find (ve->transport_name); + ve->address, ve->address->address_length); + papi = GST_plugins_find (ve->address->transport_name); if (papi == NULL) ret = -1; else @@ -498,7 +477,8 @@ transmit_ping_if_allowed (void *cls, const struct GNUNET_PeerIdentity *pid, ret = papi->send (papi->cls, pid, message_buf, tsize, PING_PRIORITY, ACCEPTABLE_PING_DELAY, NULL /* no session */ , - ve->addr, ve->addrlen, GNUNET_YES, NULL, NULL); + ve->address->address, ve->address->address_length, + GNUNET_YES, NULL, NULL); } } if (-1 != ret) @@ -566,7 +546,8 @@ revalidate_address (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_STATISTICS_update (GST_stats, gettext_noop ("# address revalidations started"), 1, GNUNET_NO); - bc = GST_blacklist_test_allowed (&ve->pid, ve->transport_name, &transmit_ping_if_allowed, ve); + bc = GST_blacklist_test_allowed (&ve->pid, ve->address->transport_name, + &transmit_ping_if_allowed, ve); if (NULL != bc) ve->bc = bc; /* only set 'bc' if 'transmit_ping_if_allowed' was not already called... */ @@ -579,45 +560,36 @@ revalidate_address (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) * without starting any validation). * * @param public_key public key of the peer, NULL for unknown - * @param neighbour which peer we care about - * @param tname name of the transport plugin - * @param addr binary address - * @param addrlen length of addr + * @param address address to find * @return validation entry matching the given specifications, NULL * if we don't have an existing entry and no public key was given */ static struct ValidationEntry * find_validation_entry (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded - *public_key, const struct GNUNET_PeerIdentity *neighbour, - const char *tname, const char *addr, size_t addrlen) + *public_key, const struct GNUNET_HELLO_Address *address) { struct ValidationEntryMatchContext vemc; struct ValidationEntry *ve; vemc.ve = NULL; - vemc.transport_name = tname; - vemc.addr = addr; - vemc.addrlen = addrlen; + vemc.address = address; GNUNET_CONTAINER_multihashmap_get_multiple (validation_map, - &neighbour->hashPubKey, + &address->peer.hashPubKey, &validation_entry_match, &vemc); if (NULL != (ve = vemc.ve)) return ve; if (public_key == NULL) return NULL; - ve = GNUNET_malloc (sizeof (struct ValidationEntry) + addrlen); - ve->transport_name = GNUNET_strdup (tname); - ve->addr = (void *) &ve[1]; + ve = GNUNET_malloc (sizeof (struct ValidationEntry)); + ve->address = GNUNET_HELLO_address_copy (address); ve->public_key = *public_key; - ve->pid = *neighbour; + ve->pid = address->peer; ve->latency = GNUNET_TIME_UNIT_FOREVER_REL; ve->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); ve->timeout_task = GNUNET_SCHEDULER_add_delayed (UNVALIDATED_PING_KEEPALIVE, &timeout_hello_validation, ve); - memcpy (&ve[1], addr, addrlen); - ve->addrlen = addrlen; - GNUNET_CONTAINER_multihashmap_put (validation_map, &neighbour->hashPubKey, ve, + GNUNET_CONTAINER_multihashmap_put (validation_map, &address->peer.hashPubKey, ve, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); return ve; } @@ -628,16 +600,14 @@ find_validation_entry (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded * addresses. * * @param cls original HELLO message - * @param tname name of the transport + * @param address the address * @param expiration expiration time - * @param addr the address - * @param addrlen length of the address * @return GNUNET_OK (keep the address) */ static int -add_valid_address (void *cls, const char *tname, - struct GNUNET_TIME_Absolute expiration, const void *addr, - uint16_t addrlen) +add_valid_address (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { const struct GNUNET_HELLO_Message *hello = cls; struct ValidationEntry *ve; @@ -652,11 +622,11 @@ add_valid_address (void *cls, const char *tname, GNUNET_break (0); return GNUNET_OK; /* invalid HELLO !? */ } - ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen); + ve = find_validation_entry (&public_key, address); ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, expiration); if (GNUNET_SCHEDULER_NO_TASK == ve->revalidation_task) ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve); - GNUNET_ATS_address_update (GST_ats, &pid, tname, addr, addrlen, NULL, NULL, + GNUNET_ATS_address_update (GST_ats, address, NULL, NULL, 0); return GNUNET_OK; } @@ -728,29 +698,27 @@ GST_validation_stop () * @param validation_block is FOREVER if the address is for an unsupported plugin (from PEERINFO) * is ZERO if the address is considered valid (no validation needed) * otherwise a time in the future if we're currently denying re-validation - * @param plugin_name name of the plugin - * @param plugin_address binary address - * @param plugin_address_len length of address + * @param adress target address */ static void multicast_pong (void *cls, const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded - *public_key, const struct GNUNET_PeerIdentity *target, + *public_key, struct GNUNET_TIME_Absolute valid_until, struct GNUNET_TIME_Absolute validation_block, - const char *plugin_name, const void *plugin_address, - size_t plugin_address_len) + const struct GNUNET_HELLO_Address *address) { struct TransportPongMessage *pong = cls; struct GNUNET_TRANSPORT_PluginFunctions *papi; - papi = GST_plugins_find (plugin_name); + papi = GST_plugins_find (address->transport_name); if (papi == NULL) return; - (void) papi->send (papi->cls, target, (const char *) pong, + (void) papi->send (papi->cls, &address->peer, (const char *) pong, ntohs (pong->header.size), PONG_PRIORITY, - ACCEPTABLE_PING_DELAY, NULL, plugin_address, - plugin_address_len, GNUNET_YES, NULL, NULL); + ACCEPTABLE_PING_DELAY, NULL, + address->address, + address->address_length, GNUNET_YES, NULL, NULL); } @@ -759,18 +727,14 @@ multicast_pong (void *cls, * * @param sender peer sending the PING * @param hdr the PING + * @param sender_address the sender address as we got it * @param session session we got the PING from - * @param plugin_name name of plugin that received the PING - * @param sender_address address of the sender as known to the plugin, NULL - * if we did not initiate the connection - * @param sender_address_len number of bytes in sender_address */ void GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *hdr, - const char *plugin_name, struct Session *session, - const void *sender_address, - size_t sender_address_len) + const struct GNUNET_HELLO_Address *sender_address, + struct Session *session) { const struct TransportPingMessage *ping; struct TransportPongMessage *pong; @@ -782,6 +746,7 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, size_t alen; size_t slen; ssize_t ret; + struct GNUNET_HELLO_Address address; if (ntohs (hdr->size) < sizeof (struct TransportPingMessage)) { @@ -821,15 +786,18 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, addrend++; slen = strlen (addr) + 1; alen -= slen; - + address.address = addrend; + address.address_length = alen; + address.transport_name = addr; + address.peer = *sender; if (GNUNET_YES != - GST_hello_test_address (addr, addrend, alen, &sig_cache, + GST_hello_test_address (&address, &sig_cache, &sig_cache_exp)) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, _ ("Not confirming PING with address `%s' since I cannot confirm having this address.\n"), - GST_plugins_a2s (addr, addrend, alen)); + GST_plugins_a2s (&address)); return; } } @@ -879,15 +847,17 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, /* first see if the session we got this PING from can be used to transmit * a response reliably */ - papi = GST_plugins_find (plugin_name); + papi = GST_plugins_find (sender_address->transport_name); if (papi == NULL) ret = -1; else ret = papi->send (papi->cls, sender, (const char *) pong, ntohs (pong->header.size), PONG_PRIORITY, - ACCEPTABLE_PING_DELAY, session, sender_address, - sender_address_len, GNUNET_SYSERR, NULL, NULL); + ACCEPTABLE_PING_DELAY, session, + sender_address->address, + sender_address->address_length, + GNUNET_SYSERR, NULL, NULL); if (ret != -1) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, @@ -934,24 +904,21 @@ struct ValidateAddressContext * (unless blocked or already validated). * * @param cls pointer to a 'struct ValidateAddressContext' - * @param tname name of the transport + * @param address the address * @param expiration expiration time - * @param addr the address - * @param addrlen length of the address * @return GNUNET_OK (keep the address) */ static int -validate_address_iterator (void *cls, const char *tname, - struct GNUNET_TIME_Absolute expiration, const void *addr, - uint16_t addrlen) +validate_address_iterator (void *cls, + const struct GNUNET_HELLO_Address *address, + struct GNUNET_TIME_Absolute expiration) { const struct ValidateAddressContext *vac = cls; - const struct GNUNET_PeerIdentity *pid = &vac->pid; struct ValidationEntry *ve; if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0) return GNUNET_OK; /* expired */ - ve = find_validation_entry (&vac->public_key, pid, tname, addr, addrlen); + ve = find_validation_entry (&vac->public_key, address); if (GNUNET_SCHEDULER_NO_TASK == ve->revalidation_task) ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve); @@ -976,8 +943,8 @@ add_valid_peer_address (void *cls, size_t max, void *buf) if (GNUNET_YES == ve->copied) return 0; /* terminate */ ve->copied = GNUNET_YES; - return GNUNET_HELLO_add_address (ve->transport_name, ve->valid_until, - ve->addr, ve->addrlen, buf, max); + return GNUNET_HELLO_add_address (ve->address, ve->valid_until, + buf, max); } @@ -1000,6 +967,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, size_t slen; size_t size; struct GNUNET_HELLO_Message *hello; + struct GNUNET_HELLO_Address address; if (ntohs (hdr->size) < sizeof (struct TransportPongMessage)) { @@ -1022,8 +990,11 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, addr++; slen = strlen (tname) + 1; addrlen = size - slen; - - ve = find_validation_entry (NULL, sender, tname, addr, addrlen); + address.peer = *sender; + address.address = addr; + address.address_length = addrlen; + address.transport_name = tname; + ve = find_validation_entry (NULL, &address); if (NULL == ve) { GNUNET_STATISTICS_update (GST_stats, @@ -1071,8 +1042,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, ats.type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); ats.value = htonl ((uint32_t) ve->latency.rel_value); - GNUNET_ATS_address_update (GST_ats, &ve->pid, ve->transport_name, ve->addr, - ve->addrlen, NULL, &ats, 1); + GNUNET_ATS_address_update (GST_ats, ve->address, NULL, &ats, 1); } /* build HELLO to store in PEERINFO */ ve->copied = GNUNET_NO; @@ -1153,8 +1123,8 @@ iterate_addresses (void *cls, const GNUNET_HashCode * key, void *value) struct IteratorContext *ic = cls; struct ValidationEntry *ve = value; - ic->cb (ic->cb_cls, &ve->public_key, &ve->pid, ve->valid_until, - ve->revalidation_block, ve->transport_name, ve->addr, ve->addrlen); + ic->cb (ic->cb_cls, &ve->public_key, ve->valid_until, + ve->revalidation_block, ve->address); return GNUNET_OK; } @@ -1186,25 +1156,20 @@ GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target, * Based on this, the validation module will measure latency for the * address more or less often. * - * @param sender peer - * @param plugin_name name of plugin - * @param session session - * @param sender_address address of the sender as known to the plugin, NULL - * if we did not initiate the connection - * @param sender_address_len number of bytes in sender_address + * @param sender peer FIXME: redundant! + * @param address the address * @param in_use GNUNET_YES if we are now using the address for a connection, * GNUNET_NO if we are no longer using the address for a connection */ void GST_validation_set_address_use (const struct GNUNET_PeerIdentity *sender, - const char *plugin_name, struct Session *session, - const void *sender_address, - size_t sender_address_len, + const struct GNUNET_HELLO_Address *address, + struct Session *session, int in_use) { struct ValidationEntry *ve; - ve = find_validation_entry (NULL, sender, plugin_name, sender_address, sender_address_len); + ve = find_validation_entry (NULL, address); if (NULL == ve) { /* FIXME: this can happen for inbound connections (sender_address_len == 0); @@ -1231,23 +1196,19 @@ GST_validation_set_address_use (const struct GNUNET_PeerIdentity *sender, * address. * * @param sender peer - * @param plugin_name name of plugin + * @param address the address * @param session session - * @param sender_address address of the sender as known to the plugin, NULL - * if we did not initiate the connection - * @param sender_address_len number of bytes in sender_address * @return observed latency of the address, FOREVER if the address was * never successfully validated */ struct GNUNET_TIME_Relative GST_validation_get_address_latency (const struct GNUNET_PeerIdentity *sender, - const char *plugin_name, struct Session *session, - const void *sender_address, - size_t sender_address_len) + const struct GNUNET_HELLO_Address *address, + struct Session *session) { struct ValidationEntry *ve; - ve = find_validation_entry (NULL, sender, plugin_name, sender_address, sender_address_len); + ve = find_validation_entry (NULL, address); if (NULL == ve) return GNUNET_TIME_UNIT_FOREVER_REL; return ve->latency; diff --git a/src/transport/gnunet-service-transport_validation.h b/src/transport/gnunet-service-transport_validation.h index 2d93e508e..a3692e3cf 100644 --- a/src/transport/gnunet-service-transport_validation.h +++ b/src/transport/gnunet-service-transport_validation.h @@ -29,6 +29,7 @@ #include "gnunet_statistics_service.h" #include "gnunet_transport_plugin.h" #include "gnunet_util_lib.h" +#include "gnunet_hello_lib.h" /** @@ -50,20 +51,16 @@ GST_validation_stop (void); * Based on this, the validation module will measure latency for the * address more or less often. * - * @param sender peer - * @param plugin_name name of plugin + * @param sender peer FIXME: redundant! + * @param address the address * @param session session - * @param sender_address address of the sender as known to the plugin, NULL - * if we did not initiate the connection - * @param sender_address_len number of bytes in sender_address * @param in_use GNUNET_YES if we are now using the address for a connection, * GNUNET_NO if we are no longer using the address for a connection */ void GST_validation_set_address_use (const struct GNUNET_PeerIdentity *sender, - const char *plugin_name, struct Session *session, - const void *sender_address, - size_t sender_address_len, + const struct GNUNET_HELLO_Address *address, + struct Session *session, int in_use); @@ -72,19 +69,15 @@ GST_validation_set_address_use (const struct GNUNET_PeerIdentity *sender, * address. * * @param sender peer - * @param plugin_name name of plugin + * @param address the address * @param session session - * @param sender_address address of the sender as known to the plugin, NULL - * if we did not initiate the connection - * @param sender_address_len number of bytes in sender_address * @return observed latency of the address, FOREVER if the address was * never successfully validated */ struct GNUNET_TIME_Relative GST_validation_get_address_latency (const struct GNUNET_PeerIdentity *sender, - const char *plugin_name, struct Session *session, - const void *sender_address, - size_t sender_address_len); + const struct GNUNET_HELLO_Address *address, + struct Session *session); /** @@ -92,18 +85,14 @@ GST_validation_get_address_latency (const struct GNUNET_PeerIdentity *sender, * * @param sender peer sending the PING * @param hdr the PING - * @param plugin_name name of plugin that received the PING + * @param sender_address address of the sender, NULL if we did not initiate * @param session session we got the PING from - * @param sender_address address of the sender as known to the plugin, NULL - * if we did not initiate the connection - * @param sender_address_len number of bytes in sender_address */ void GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *hdr, - const char *plugin_name, struct Session *session, - const void *sender_address, - size_t sender_address_len); + const struct GNUNET_HELLO_Address *sender_address, + struct Session *session); /** @@ -134,29 +123,22 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello); * * @param cls closure * @param public_key public key for the peer, never NULL - * @param target peer this change is about, never NULL * @param valid_until is ZERO if we never validated the address, * otherwise a time up to when we consider it (or was) valid * @param validation_block is FOREVER if the address is for an unsupported plugin (from PEERINFO) * is ZERO if the address is considered valid (no validation needed) * otherwise a time in the future if we're currently denying re-validation - * @param plugin_name name of the plugin - * @param plugin_address binary address - * @param plugin_address_len length of address + * @param address the address */ typedef void (*GST_ValidationAddressCallback) (void *cls, const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded * public_key, - const struct GNUNET_PeerIdentity - * target, struct GNUNET_TIME_Absolute valid_until, struct GNUNET_TIME_Absolute validation_block, - const char *plugin_name, - const void *plugin_address, - size_t plugin_address_len); + const struct GNUNET_HELLO_Address *address); /** -- 2.25.1