{
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;
}
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 >
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;
}
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)
{
}
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 >
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);
* 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)
{
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)))
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);
}
* 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;
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);
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);
* 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;
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);
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 */
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);
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);
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");
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));
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 a1<a2, 1 if a1>a2.
+ */
+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 */
* 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;
}
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;
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);
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)
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;
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) ||
(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;
}
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;
}
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)
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)
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;
{
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;
* 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;
#include "gnunet_constants.h"
#include "gnunet_util_lib.h"
+#include "gnunet_hello_lib.h"
/**
* 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
* @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
* 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);
* 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 ***************************** */
* 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,
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 a1<a2, 1 if a1>a2.
+ */
+int
+GNUNET_HELLO_address_cmp (const struct GNUNET_HELLO_Address *a1,
+ const struct GNUNET_HELLO_Address *a2);
+
+
+
/**
* Free an address.
*
* 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);
* 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);
/**
* @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,
* 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;
* 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);
* 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;
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;
}
{
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;
}
#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;
* 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;
*/
#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"
* @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;
* (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,
{
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;
#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)
: "<inbound>");
#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)
: "<inbound>");
#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);
#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,
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);
}
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));
"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);
}
* 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,
#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);
}
* @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;
* @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;
*
* @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");
* @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);
}
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
*/
struct GNUNET_CRYPTO_RsaSignature pong_signature;
- /**
- * Length of addr.
- */
- size_t addrlen;
-
};
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;
}
* 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;
(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;
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 ();
}
/**
* 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]
* 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;
#include "gnunet_statistics_service.h"
#include "gnunet_transport_service.h"
#include "gnunet_util_lib.h"
+#include "gnunet_hello_lib.h"
* 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]
* 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 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.
*/
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,
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)
#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);
#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);
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)
{
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)
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)
{
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;
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);
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)
{
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;
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)
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));
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);
}
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);
}
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",
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);
}
#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) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr,
- n->addrlen), n->session);
+ 0) ? "<inbound>" : 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);
#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) ? "<inbound>" : GST_plugins_a2s (n->plugin_name, n->addr,
- n->addrlen), n->session);
+ 0) ? "<inbound>" : 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);
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);
}
/**
#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) ? "<inbound>" : GST_plugins_a2s (n->plugin_name,
- n->addr,
- n->addrlen),
+ GNUNET_i2s (&n->id), n->address->transport_name,
+ (n->addrlen == 0) ? "<inbound>" : 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);
* 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
*/
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,
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");
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;
#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) ? "<inbound>" : GST_plugins_a2s (plugin_name,
- address,
- address_len),
+ address->transport_name,
+ (address_len == 0) ? "<inbound>" : GST_plugins_a2s (address),
session, (is_connected (n) ? "CONNECTED" : "NOT CONNECTED"),
GNUNET_i2s (peer));
#endif
}
// 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);
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);
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;
}
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) ? "<inbound>" : 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;
}
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);
}
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)))
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
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;
}
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)
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)
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,
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) ? "<inbound>" : 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)
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) ? "<inbound>" : 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);
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)
{
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;
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);
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,
#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) ? "<inbound>" : 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);
struct Session *session;
- char *sender_address;
-
- uint16_t sender_address_len;
-
- char *plugin_name;
+ struct GNUNET_HELLO_Address *address;
struct GNUNET_TIME_Absolute ts;
};
/* not allowed */
if (GNUNET_OK != result)
{
+ GNUNET_HELLO_address_free (bcc->address);
GNUNET_free (bcc);
return;
}
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;
}
*
* @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)
/* 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;
}
}
/* 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);
}
* @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);
/**
* 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
* 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
*
* @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);
+
+/**
+ * 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);
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);
* 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 "<inbound>";
+ 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);
}
#include "gnunet_transport_service.h"
#include "gnunet_transport_plugin.h"
#include "gnunet_util_lib.h"
+#include "gnunet_hello_lib.h"
/**
* 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
{
/**
- * 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).
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;
*/
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?
*/
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;
};
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;
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);
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;
"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];
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
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)
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... */
* 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;
}
* 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;
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;
}
* @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);
}
*
* @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;
size_t alen;
size_t slen;
ssize_t ret;
+ struct GNUNET_HELLO_Address address;
if (ntohs (hdr->size) < sizeof (struct TransportPingMessage))
{
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;
}
}
/* 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,
* (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);
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);
}
size_t slen;
size_t size;
struct GNUNET_HELLO_Message *hello;
+ struct GNUNET_HELLO_Address address;
if (ntohs (hdr->size) < sizeof (struct TransportPongMessage))
{
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,
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;
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;
}
* 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);
* 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;
#include "gnunet_statistics_service.h"
#include "gnunet_transport_plugin.h"
#include "gnunet_util_lib.h"
+#include "gnunet_hello_lib.h"
/**
* 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);
* 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);
/**
*
* @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);
/**
*
* @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);
/**