#include "gnunet_protocols.h"
#include "gnunet_service_lib.h"
#include "gnunet_signatures.h"
-#include "plugin_transport.h"
+#include "gnunet_transport_plugin.h"
#include "transport.h"
-#define DEBUG_BLACKLIST GNUNET_NO
+#define DEBUG_BLACKLIST GNUNET_YES
-#define DEBUG_PING_PONG GNUNET_NO
+#define DEBUG_PING_PONG GNUNET_YES
#define DEBUG_TRANSPORT_HELLO GNUNET_YES
*/
int public_key_valid;
+ /**
+ * Performance data for the peer.
+ */
+ struct GNUNET_TRANSPORT_ATS_Information *ats;
+
+ /**
+ * Identity of the neighbour.
+ */
+ struct GNUNET_PeerIdentity peer;
+
};
/**
*/
static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
-/**
- * Our scheduler.
- */
-struct GNUNET_SCHEDULER_Handle *sched;
-
/**
* Our configuration.
*/
*
* @param cls closure, identifies the entry on the
* message queue that was transmitted and the
- * client responsible for queueing the message
+ * client responsible for queuing the message
* @param target the peer receiving the message
* @param result GNUNET_OK on success, if the transmission
* failed, we should not tell the client to transmit
addresses = head->addresses;
while (addresses != NULL)
{
- if ( (addresses->timeout.value < now.value) &&
+ if ( (addresses->timeout.abs_value < now.abs_value) &&
(addresses->connected == GNUNET_YES) )
{
#if DEBUG_TRANSPORT
addresses->in_transmit,
addresses->validated,
addresses->connect_attempts,
- (unsigned long long) addresses->timeout.value,
+ (unsigned long long) addresses->timeout.abs_value,
(unsigned int) addresses->distance);
#endif
if ( ( (best_address == NULL) ||
(best_address->connected == GNUNET_NO) ) &&
(addresses->in_transmit == GNUNET_NO) &&
( (best_address == NULL) ||
- (addresses->latency.value < best_address->latency.value)) )
+ (addresses->latency.rel_value < best_address->latency.rel_value)) )
best_address = addresses;
/* FIXME: also give lower-latency addresses that are not
connected a chance some times... */
best_address->addr,
best_address->addrlen)
: "<inbound>",
- best_address->latency.value);
+ best_address->latency.rel_value);
#endif
}
else
1,
GNUNET_NO);
timeout = GNUNET_TIME_absolute_get_remaining (mq->timeout);
- if (timeout.value == 0)
+ if (timeout.rel_value == 0)
{
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1,
GNUNET_NO);
if (neighbour->retry_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (sched,
- neighbour->retry_task);
- neighbour->retry_task = GNUNET_SCHEDULER_add_delayed (sched,
- timeout,
+ GNUNET_SCHEDULER_cancel (neighbour->retry_task);
+ neighbour->retry_task = GNUNET_SCHEDULER_add_delayed (timeout,
&retry_transmission_task,
neighbour);
#if DEBUG_TRANSPORT
"No validated destination address available to transmit message of size %u to peer `%4s', will wait %llums to find an address.\n",
mq->message_buf_size,
GNUNET_i2s (&mq->neighbour_id),
- timeout.value);
+ timeout.rel_value);
#endif
/* FIXME: might want to trigger peerinfo lookup here
(unless that's already pending...) */
* expired
*/
static void
-update_addresses (struct TransportPlugin *plugin, int fresh)
+update_addresses (struct TransportPlugin *plugin,
+ int fresh)
{
static struct GNUNET_TIME_Absolute last_update;
struct GNUNET_TIME_Relative min_remaining;
int expired;
if (plugin->address_update_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (plugin->env.sched, plugin->address_update_task);
+ GNUNET_SCHEDULER_cancel (plugin->address_update_task);
plugin->address_update_task = GNUNET_SCHEDULER_NO_TASK;
now = GNUNET_TIME_absolute_get ();
min_remaining = GNUNET_TIME_UNIT_FOREVER_REL;
- expired = (GNUNET_TIME_absolute_get_duration (last_update).value > (HELLO_ADDRESS_EXPIRATION.value / 4));
+ expired = (GNUNET_TIME_absolute_get_duration (last_update).rel_value > (HELLO_ADDRESS_EXPIRATION.rel_value / 4));
prev = NULL;
pos = plugin->addresses;
while (pos != NULL)
{
next = pos->next;
- if (pos->expires.value < now.value)
+ if (pos->expires.abs_value < now.abs_value)
{
expired = GNUNET_YES;
if (prev == NULL)
else
{
remaining = GNUNET_TIME_absolute_get_remaining (pos->expires);
- if (remaining.value < min_remaining.value)
+ if (remaining.rel_value < min_remaining.rel_value)
min_remaining = remaining;
prev = pos;
}
GNUNET_TIME_relative_divide (HELLO_ADDRESS_EXPIRATION,
2));
plugin->address_update_task
- = GNUNET_SCHEDULER_add_delayed (plugin->env.sched,
- min_remaining,
+ = GNUNET_SCHEDULER_add_delayed (min_remaining,
&expire_address_task, plugin);
}
prev->next = pos->next;
if (GNUNET_SCHEDULER_NO_TASK != pos->revalidate_task)
{
- GNUNET_SCHEDULER_cancel (sched,
- pos->revalidate_task);
+ GNUNET_SCHEDULER_cancel (pos->revalidate_task);
pos->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
}
GNUNET_free (pos);
while (al != NULL)
{
if ((addrlen == al->addrlen) && (0 == memcmp (addr, &al[1], addrlen)))
- {
- if (al->expires.value < abex.value)
- al->expires = abex;
+ {
+ al->expires = abex;
+ update_addresses (p, GNUNET_NO);
return;
}
al = al->next;
static void
notify_clients_connect (const struct GNUNET_PeerIdentity *peer,
struct GNUNET_TIME_Relative latency,
- uint32_t distance)
+ uint32_t distance)
{
- struct ConnectInfoMessage cim;
+ struct ConnectInfoMessage * cim;
struct TransportClient *cpos;
+ uint32_t ats_count;
+ size_t size;
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
gettext_noop ("# peers connected"),
1,
GNUNET_NO);
- cim.header.size = htons (sizeof (struct ConnectInfoMessage));
- cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
- cim.distance = htonl (distance);
- cim.latency = GNUNET_TIME_relative_hton (latency);
- memcpy (&cim.id, peer, sizeof (struct GNUNET_PeerIdentity));
+
+ ats_count = 2;
+ size = sizeof (struct ConnectInfoMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
+ if (size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
+ {
+ GNUNET_break(0);
+ }
+ cim = GNUNET_malloc (size);
+
+ cim->header.size = htons (size);
+ cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
+ cim->ats_count = htonl(2);
+ (&(cim->ats))[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
+ (&(cim->ats))[0].value = htonl (distance);
+ (&(cim->ats))[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
+ (&(cim->ats))[1].value = htonl ((uint32_t) latency.rel_value);
+ (&(cim->ats))[2].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
+ (&(cim->ats))[2].value = htonl (0);
+ memcpy (&cim->id, peer, sizeof (struct GNUNET_PeerIdentity));
cpos = clients;
while (cpos != NULL)
{
- transmit_to_client (cpos, &cim.header, GNUNET_NO);
+ transmit_to_client (cpos, &(cim->header), GNUNET_NO);
cpos = cpos->next;
}
+ GNUNET_free (cim);
}
struct ValidationEntry *va = value;
if (GNUNET_SCHEDULER_NO_TASK != va->timeout_task)
- GNUNET_SCHEDULER_cancel (sched, va->timeout_task);
+ GNUNET_SCHEDULER_cancel (va->timeout_task);
GNUNET_free (va->transport_name);
if (va->chvc != NULL)
{
a2s (tname, addr, addrlen),
tname,
GNUNET_i2s (&n->id),
- expiration.value);
+ expiration.abs_value);
#endif
fal = add_peer_address (n, tname, NULL, addr, addrlen);
if (fal == NULL)
}
n->latency = GNUNET_TIME_UNIT_FOREVER_REL;
n->distance = -1;
- n->timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ n->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
&neighbour_timeout_task, n);
if (do_hello)
{
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# peerinfo iterate requests"),
+ gettext_noop ("# peerinfo new neighbor iterate requests"),
1,
GNUNET_NO);
GNUNET_STATISTICS_update (stats,
if (size == 0)
{
GNUNET_assert (bc->task == GNUNET_SCHEDULER_NO_TASK);
- bc->task = GNUNET_SCHEDULER_add_now (sched,
- &do_blacklist_check,
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
bc);
return 0;
}
bc->cont = cont;
bc->cont_cls = cont_cls;
bc->bl_pos = bl_head;
- bc->task = GNUNET_SCHEDULER_add_now (sched,
- &do_blacklist_check,
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
bc);
}
bc->bl_pos = bl;
if (n == neighbours) /* all would wait for the same client, no need to
create more than just the first task right now */
- bc->task = GNUNET_SCHEDULER_add_now (sched,
- &do_blacklist_check,
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
bc);
n = n->next;
}
else
{
bc->bl_pos = bc->bl_pos->next;
- bc->task = GNUNET_SCHEDULER_add_now (sched,
- &do_blacklist_check,
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
bc);
}
/* check if any other bc's are waiting for this blacklister */
{
if ( (bc->bl_pos == bl) &&
(GNUNET_SCHEDULER_NO_TASK == bc->task) )
- bc->task = GNUNET_SCHEDULER_add_now (sched,
- &do_blacklist_check,
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
bc);
bc = bc->next;
}
}
va = GNUNET_malloc (sizeof (struct ValidationEntry) + peer_address->addrlen);
va->transport_name = GNUNET_strdup (tp->short_name);
- va->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ va->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
UINT_MAX);
va->send_time = GNUNET_TIME_absolute_get();
va->session = peer_address->session;
&neighbour->publicKey,
sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
- va->timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
- HELLO_VERIFICATION_TIMEOUT,
+ va->timeout_task = GNUNET_SCHEDULER_add_delayed (HELLO_VERIFICATION_TIMEOUT,
&timeout_hello_validation,
va);
GNUNET_CONTAINER_multihashmap_put (validation_map,
ping.challenge = htonl(va->challenge);
memcpy(&ping.target, &neighbour->id, sizeof(struct GNUNET_PeerIdentity));
if (peer_address->validated != GNUNET_YES)
- memcpy(message_buf, our_hello, hello_size);
+ {
+ memcpy(message_buf, our_hello, hello_size);
+ }
if (peer_address->addr != NULL)
{
{
ping.header.size = htons(sizeof(struct TransportPingMessage));
}
+
memcpy(&message_buf[hello_size],
&ping,
sizeof(struct TransportPingMessage));
#endif
if (peer_address->validated != GNUNET_YES)
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# PING+HELLO messages sent"),
+ gettext_noop ("# PING with HELLO messages sent"),
+ 1,
+ GNUNET_NO);
+ else
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# PING without HELLO messages sent"),
1,
GNUNET_NO);
-
-
GNUNET_STATISTICS_update (stats,
gettext_noop ("# PING messages sent for re-validation"),
1,
if (fal->revalidate_task != GNUNET_SCHEDULER_NO_TASK)
return;
delay = GNUNET_TIME_absolute_get_remaining (fal->expires);
- delay.value /= 2; /* do before expiration */
+ delay.rel_value /= 2; /* do before expiration */
delay = GNUNET_TIME_relative_min (delay,
LATENCY_EVALUATION_MAX_DELAY);
if (GNUNET_YES != fal->estimated)
delay = GNUNET_TIME_relative_max (delay,
GNUNET_TIME_UNIT_SECONDS);
/* randomize a bit (to avoid doing all at the same time) */
- delay.value += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000);
- fal->revalidate_task = GNUNET_SCHEDULER_add_delayed(sched,
- delay,
+ delay.rel_value += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000);
+ fal->revalidate_task = GNUNET_SCHEDULER_add_delayed(delay,
&send_periodic_ping,
fal);
}
*/
static void
handle_payload_message (const struct GNUNET_MessageHeader *message,
- struct NeighbourList *n)
+ struct NeighbourList *n)
{
struct InboundMessage *im;
struct TransportClient *cpos;
msize,
GNUNET_NO);
/* transmit message to all clients */
- im = GNUNET_malloc (sizeof (struct InboundMessage) + msize);
- im->header.size = htons (sizeof (struct InboundMessage) + msize);
+ uint32_t ats_count = 2;
+ size_t size = sizeof (struct InboundMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) + msize;
+ if (size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
+ GNUNET_break(0);
+
+ im = GNUNET_malloc (size);
+ im->header.size = htons (size);
im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
- im->latency = GNUNET_TIME_relative_hton (n->latency);
im->peer = n->id;
- im->distance = ntohl(n->distance);
- memcpy (&im[1], message, msize);
+ im->ats_count = htonl(ats_count);
+ /* Setting ATS data */
+ (&(im->ats))[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
+ (&(im->ats))[0].value = htonl (n->distance);
+ (&(im->ats))[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
+ (&(im->ats))[1].value = htonl ((uint32_t) n->latency.rel_value);
+ (&(im->ats))[ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
+ (&(im->ats))[ats_count].value = htonl (0);
+
+ memcpy (&((&(im->ats))[ats_count+1]), message, msize);
cpos = clients;
while (cpos != NULL)
{
}
addr = (const char*) &pong[1];
slen = strlen (ve->transport_name) + 1;
- if ( (ps - sizeof (struct TransportPongMessage) != ve->addrlen + slen) ||
+ if ( (ps - sizeof (struct TransportPongMessage) < slen) ||
(ve->challenge != challenge) ||
(addr[slen-1] != '\0') ||
(0 != strcmp (addr, ve->transport_name)) ||
!= sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
sizeof (uint32_t) +
sizeof (struct GNUNET_TIME_AbsoluteNBO) +
- sizeof (struct GNUNET_PeerIdentity) + ve->addrlen + slen) )
+ sizeof (struct GNUNET_PeerIdentity) + ps - sizeof (struct TransportPongMessage)) )
{
return GNUNET_YES;
}
#endif
break;
case GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING:
- if (ve->addrlen != 0)
- {
- return GNUNET_YES; /* different entry, keep trying */
- }
- if ( (0 != memcmp (&pong->pid,
+ if (0 != memcmp (&pong->pid,
&my_identity,
- sizeof (struct GNUNET_PeerIdentity))) ||
- (ve->addrlen != 0) )
+ sizeof (struct GNUNET_PeerIdentity)))
{
GNUNET_break_op (0);
return GNUNET_NO;
}
+ if (ve->addrlen != 0)
+ {
+ /* must have been for a different validation entry */
+ return GNUNET_YES;
+ }
tp = find_transport (ve->transport_name);
if (tp == NULL)
{
GNUNET_break_op (0);
return GNUNET_NO;
}
- if (GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (pong->expiration)).value == 0)
+ if (GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value == 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
_("Received expired signature. Check system time.\n"));
GNUNET_NO);
fal->latency = GNUNET_TIME_absolute_get_duration (ve->send_time);
schedule_next_ping (fal);
- if (n->latency.value == GNUNET_TIME_UNIT_FOREVER_REL.value)
+ if (n->latency.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
n->latency = fal->latency;
else
- n->latency.value = (fal->latency.value + n->latency.value) / 2;
+ n->latency.rel_value = (fal->latency.rel_value + n->latency.rel_value) / 2;
n->distance = fal->distance;
if (GNUNET_NO == n->received_pong)
}
if (n->retry_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel (sched,
- n->retry_task);
+ GNUNET_SCHEDULER_cancel (n->retry_task);
n->retry_task = GNUNET_SCHEDULER_NO_TASK;
try_transmission_to_peer (n);
}
va->chvc = chvc;
chvc->ve_count++;
va->transport_name = GNUNET_strdup (tname);
- va->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
+ va->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
UINT_MAX);
va->send_time = GNUNET_TIME_absolute_get();
va->addr = (const void*) &va[1];
va->addrlen = addrlen;
GNUNET_HELLO_get_key (chvc->hello,
&va->publicKey);
- va->timeout_task = GNUNET_SCHEDULER_add_delayed (sched,
- HELLO_VERIFICATION_TIMEOUT,
+ va->timeout_task = GNUNET_SCHEDULER_add_delayed (HELLO_VERIFICATION_TIMEOUT,
&timeout_hello_validation,
va);
GNUNET_CONTAINER_multihashmap_put (validation_map,
const struct GNUNET_HELLO_Message *hello;
struct CheckHelloValidatedContext *chvc;
struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded publicKey;
-#if DEBUG_TRANSPORT_HELLO
+#if DEBUG_TRANSPORT_HELLO > 2
char *my_id;
#endif
hsize = ntohs (message->size);
GNUNET_NO);
/* first, check if load is too high */
- if (GNUNET_SCHEDULER_get_load (sched,
- GNUNET_SCHEDULER_PRIORITY_BACKGROUND) > MAX_HELLO_LOAD)
+ if (GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_BACKGROUND) > MAX_HELLO_LOAD)
{
GNUNET_STATISTICS_update (stats,
gettext_noop ("# HELLOs ignored due to high load"),
{
if (GNUNET_HELLO_equals (hello,
chvc->hello,
- GNUNET_TIME_absolute_get ()).value > 0)
+ GNUNET_TIME_absolute_get ()).abs_value > 0)
{
-#if DEBUG_TRANSPORT_HELLO
+#if DEBUG_TRANSPORT_HELLO > 2
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received duplicate `%s' message for `%4s'; ignored\n",
"HELLO",
GNUNET_HELLO_size(hello)));
chvc = chvc->next;
}
-#if DEBUG_TRANSPORT_HELLO
+
+#if BREAK_TESTS
+ struct NeighbourList *temp_neighbor = find_neighbour(&target);
+ if ((NULL != temp_neighbor))
+ {
+ fprintf(stderr, "Already know peer, ignoring hello\n");
+ return GNUNET_OK;
+ }
+#endif
+
+#if DEBUG_TRANSPORT_HELLO > 2
if (plugin != NULL)
{
my_id = GNUNET_strdup(GNUNET_i2s(plugin->env.my_identity));
/* finally, check if HELLO was previously validated
(continuation will then schedule actual validation) */
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# peerinfo iterate requests"),
+ gettext_noop ("# peerinfo process hello iterate requests"),
1,
GNUNET_NO);
GNUNET_STATISTICS_update (stats,
GNUNET_NO);
if (GNUNET_SCHEDULER_NO_TASK != peer_pos->revalidate_task)
{
- GNUNET_SCHEDULER_cancel (sched,
- peer_pos->revalidate_task);
+ GNUNET_SCHEDULER_cancel (peer_pos->revalidate_task);
peer_pos->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
}
GNUNET_free(peer_pos);
}
if (n->timeout_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel (sched, n->timeout_task);
+ GNUNET_SCHEDULER_cancel (n->timeout_task);
n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
}
if (n->retry_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel (sched, n->retry_task);
+ GNUNET_SCHEDULER_cancel (n->retry_task);
n->retry_task = GNUNET_SCHEDULER_NO_TASK;
}
if (n->piter != NULL)
sizeof (struct GNUNET_PeerIdentity)))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Received `%s' message not destined for me!\n"),
- "PING");
+ _("Received `%s' message from `%s' destined for `%s' which is not me!\n"),
+ "PING",
+ (sender_address != NULL)
+ ? a2s (plugin->short_name,
+ (const struct sockaddr *)sender_address,
+ sender_address_len)
+ : "<inbound>",
+ GNUNET_i2s (&ping->target));
return GNUNET_SYSERR;
}
#if DEBUG_PING_PONG
memcpy (&((char*)&pong[1])[slen],
sender_address,
sender_address_len);
- if (GNUNET_TIME_absolute_get_remaining (session_header->pong_sig_expires).value < PONG_SIGNATURE_LIFETIME.value / 4)
+ if (GNUNET_TIME_absolute_get_remaining (session_header->pong_sig_expires).rel_value < PONG_SIGNATURE_LIFETIME.rel_value / 4)
{
/* create / update cached sig */
#if DEBUG_TRANSPORT
memcpy (&pong[1], plugin->short_name, slen);
memcpy (&((char*)&pong[1])[slen], addr, alen);
if ( (oal != NULL) &&
- (GNUNET_TIME_absolute_get_remaining (oal->pong_sig_expires).value < PONG_SIGNATURE_LIFETIME.value / 4) )
+ (GNUNET_TIME_absolute_get_remaining (oal->pong_sig_expires).rel_value < PONG_SIGNATURE_LIFETIME.rel_value / 4) )
{
/* create / update cached sig */
#if DEBUG_TRANSPORT
* @param session identifier used for this session (can be NULL)
* @param sender_address binary address of the sender (if observed)
* @param sender_address_len number of bytes in sender_address
- * @return how long the plugin should wait until receiving more data
+ * @return how long in ms the plugin should wait until receiving more data
* (plugins that do not support this, can ignore the return value)
*/
static struct GNUNET_TIME_Relative
plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- uint32_t distance,
- struct Session *session,
- const char *sender_address,
+ const struct GNUNET_TRANSPORT_ATS_Information *ats,
+ uint32_t ats_count,
+ struct Session *session,
+ const char *sender_address,
uint16_t sender_address_len)
{
struct TransportPlugin *plugin = cls;
struct GNUNET_TIME_Relative ret;
if (is_blacklisted (peer, plugin))
return GNUNET_TIME_UNIT_FOREVER_REL;
+ uint32_t distance;
+ int c;
n = find_neighbour (peer);
if (n == NULL)
service_context = service_context->next;
GNUNET_assert ((plugin->api->send == NULL) || (service_context != NULL));
peer_address = NULL;
+ distance = 1;
+ for (c=0; c<ats_count; c++)
+ {
+ if (ntohl(ats[c].type) == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE)
+ {
+ distance = ntohl(ats[c].value);
+ }
+ }
+
if (message != NULL)
{
if ( (session != NULL) ||
n->peer_timeout =
GNUNET_TIME_relative_to_absolute
(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
- GNUNET_SCHEDULER_cancel (sched,
- n->timeout_task);
+ GNUNET_SCHEDULER_cancel (n->timeout_task);
n->timeout_task =
- GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
&neighbour_timeout_task, n);
if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD)
{
}
}
ret = GNUNET_BANDWIDTH_tracker_get_delay (&n->in_tracker, 0);
- if (ret.value > 0)
+ if (ret.rel_value > 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Throttling read (%llu bytes excess at %u b/s), waiting %llums before reading more.\n",
(unsigned long long) n->in_tracker.consumption_since_last_update__,
(unsigned int) n->in_tracker.available_bytes_per_s__,
- (unsigned long long) ret.value);
+ (unsigned long long) ret.rel_value);
GNUNET_STATISTICS_update (stats,
gettext_noop ("# ms throttling suggested"),
- (int64_t) ret.value,
+ (int64_t) ret.rel_value,
GNUNET_NO);
}
return ret;
{
const struct StartMessage *start;
struct TransportClient *c;
- struct ConnectInfoMessage cim;
+ struct ConnectInfoMessage * cim;
struct NeighbourList *n;
+ uint32_t ats_count;
+ size_t size;
start = (const struct StartMessage*) message;
#if DEBUG_TRANSPORT
clients = c;
c->client = client;
if (our_hello != NULL)
- {
+ {
#if DEBUG_TRANSPORT
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending our own `%s' to new client\n", "HELLO");
(const struct GNUNET_MessageHeader *) our_hello,
GNUNET_NO);
/* tell new client about all existing connections */
- cim.header.size = htons (sizeof (struct ConnectInfoMessage));
- cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
+ ats_count = 2;
+ size = sizeof (struct ConnectInfoMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
+ if (size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
+ {
+ GNUNET_break(0);
+ }
+ cim = GNUNET_malloc (size);
+
+ cim->header.size = htons (size);
+ cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
+ cim->ats_count = htonl(ats_count);
+ (&(cim->ats))[2].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
+ (&(cim->ats))[2].value = htonl (0);
n = neighbours;
while (n != NULL)
- {
- if (GNUNET_YES == n->received_pong)
- {
- cim.id = n->id;
- cim.latency = GNUNET_TIME_relative_hton (n->latency);
- cim.distance = htonl (n->distance);
- transmit_to_client (c, &cim.header, GNUNET_NO);
- }
+ {
+ if (GNUNET_YES == n->received_pong)
+ {
+ (&(cim->ats))[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
+ (&(cim->ats))[0].value = htonl (n->distance);
+ (&(cim->ats))[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
+ (&(cim->ats))[1].value = htonl ((uint32_t) n->latency.rel_value);
+ cim->id = n->id;
+ transmit_to_client (c, &cim->header, GNUNET_NO);
+ }
n = n->next;
- }
- }
+ }
+ }
GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ GNUNET_free(cim);
}
create_environment (struct TransportPlugin *plug)
{
plug->env.cfg = cfg;
- plug->env.sched = sched;
plug->env.my_identity = &my_identity;
plug->env.our_hello = &our_hello;
plug->env.cls = plug;
bc->th = NULL;
}
if (bc->task == GNUNET_SCHEDULER_NO_TASK)
- bc->task = GNUNET_SCHEDULER_add_now (sched,
- &do_blacklist_check,
+ bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
bc);
break;
}
plugins = plug->next;
if (plug->address_update_task != GNUNET_SCHEDULER_NO_TASK)
{
- GNUNET_SCHEDULER_cancel (plug->env.sched,
- plug->address_update_task);
+ GNUNET_SCHEDULER_cancel (plug->address_update_task);
plug->address_update_task = GNUNET_SCHEDULER_NO_TASK;
}
GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
* Initiate transport service.
*
* @param cls closure
- * @param s scheduler to use
* @param server the initialized server
* @param c configuration to use
*/
static void
run (void *cls,
- struct GNUNET_SCHEDULER_Handle *s,
struct GNUNET_SERVER_Handle *server,
const struct GNUNET_CONFIGURATION_Handle *c)
{
unsigned long long tneigh;
char *keyfile;
- sched = s;
cfg = c;
- stats = GNUNET_STATISTICS_create (sched, "transport", cfg);
+ stats = GNUNET_STATISTICS_create ("transport", cfg);
validation_map = GNUNET_CONTAINER_multihashmap_create (64);
/* parse configuration */
if ((GNUNET_OK !=
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_
("Transport service is lacking key configuration settings. Exiting.\n"));
- GNUNET_SCHEDULER_shutdown (s);
+ GNUNET_SCHEDULER_shutdown ();
if (stats != NULL)
{
GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
return;
}
max_connect_per_transport = (uint32_t) tneigh;
- peerinfo = GNUNET_PEERINFO_connect (sched, cfg);
+ peerinfo = GNUNET_PEERINFO_connect (cfg);
if (peerinfo == NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Could not access PEERINFO service. Exiting.\n"));
- GNUNET_SCHEDULER_shutdown (s);
+ GNUNET_SCHEDULER_shutdown ();
if (stats != NULL)
{
GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_
("Transport service could not access hostkey. Exiting.\n"));
- GNUNET_SCHEDULER_shutdown (s);
+ GNUNET_SCHEDULER_shutdown ();
if (stats != NULL)
{
GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
}
GNUNET_free (plugs);
}
- GNUNET_SCHEDULER_add_delayed (sched,
- GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&shutdown_task, NULL);
if (no_transports)
refresh_hello ();