summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ats/plugin_ats2_simple.c4
-rw-r--r--src/include/gnunet_hello_lib.h4
-rw-r--r--src/include/gnunet_peerstore_service.h12
-rw-r--r--src/include/gnunet_transport_communication_service.h22
-rw-r--r--src/transport/gnunet-communicator-tcp.c460
-rw-r--r--src/transport/gnunet-communicator-udp.c692
-rw-r--r--src/transport/gnunet-communicator-unix.c117
-rw-r--r--src/transport/gnunet-service-tng.c294
-rw-r--r--src/transport/transport.h6
-rw-r--r--src/transport/transport_api2_communication.c23
10 files changed, 849 insertions, 785 deletions
diff --git a/src/ats/plugin_ats2_simple.c b/src/ats/plugin_ats2_simple.c
index dacd2e122..449b50fb7 100644
--- a/src/ats/plugin_ats2_simple.c
+++ b/src/ats/plugin_ats2_simple.c
@@ -500,7 +500,7 @@ watch_cb (void *cls,
return;
}
if (0 != strcmp (record->key,
- GNUNET_HELLO_PEERSTORE_KEY))
+ GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY))
{
GNUNET_break (0);
return;
@@ -590,7 +590,7 @@ peer_add (struct SimpleHandle *h,
p->wc = GNUNET_PEERSTORE_watch (h->ps,
"transport",
&p->pid,
- GNUNET_HELLO_PEERSTORE_KEY,
+ GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY,
&watch_cb,
p);
GNUNET_assert (GNUNET_YES ==
diff --git a/src/include/gnunet_hello_lib.h b/src/include/gnunet_hello_lib.h
index 5e2190cc6..c46e847f1 100644
--- a/src/include/gnunet_hello_lib.h
+++ b/src/include/gnunet_hello_lib.h
@@ -478,10 +478,6 @@ GNUNET_HELLO_parse_uri (const char *uri,
/* NG API */
#include "gnunet_nt_lib.h"
-/**
- * Key used for storing HELLOs in the peerstore
- */
-#define GNUNET_HELLO_PEERSTORE_KEY "hello"
/**
* Build address record by signing raw information with private key.
diff --git a/src/include/gnunet_peerstore_service.h b/src/include/gnunet_peerstore_service.h
index 31567c004..1d7e2259a 100644
--- a/src/include/gnunet_peerstore_service.h
+++ b/src/include/gnunet_peerstore_service.h
@@ -43,6 +43,18 @@ extern "C"
#endif
#endif
+
+/**
+ * Key used for storing addresses in URL format in the peerstore
+ */
+#define GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY "transport-address"
+
+/**
+ * Key used for storing HELLOs in the peerstore
+ */
+#define GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY "transport-address"
+
+
/**
* Options for storing values in PEERSTORE
*/
diff --git a/src/include/gnunet_transport_communication_service.h b/src/include/gnunet_transport_communication_service.h
index b3dfccc9a..b4a0ce9c8 100644
--- a/src/include/gnunet_transport_communication_service.h
+++ b/src/include/gnunet_transport_communication_service.h
@@ -121,7 +121,7 @@ enum GNUNET_TRANSPORT_CommunicatorCharacteristics {
*/
typedef void
(*GNUNET_TRANSPORT_CommunicatorNotify) (void *cls,
- const struct GNUNET_PeerIdentity *sender,
+ const struct GNUNET_PeerIdentity *sender,
const struct GNUNET_MessageHeader *msg);
@@ -144,12 +144,12 @@ typedef void
struct GNUNET_TRANSPORT_CommunicatorHandle *
GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
const char *config_section_name,
- const char *addr_prefix,
+ const char *addr_prefix,
enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc,
GNUNET_TRANSPORT_CommunicatorMqInit mq_init,
void *mq_init_cls,
- GNUNET_TRANSPORT_CommunicatorNotify notify_cb,
- void *notify_cb_cls);
+ GNUNET_TRANSPORT_CommunicatorNotify notify_cb,
+ void *notify_cb_cls);
/**
@@ -184,6 +184,9 @@ typedef void
* @param sender presumed sender of the message (details to be checked
* by higher layers)
* @param msg the message
+ * @param expected_addr_validity how long does the communicator believe it
+ * will continue to be able to receive messages from the same address
+ * on which it received this message?
* @param cb function to call once handling the message is done, NULL if
* flow control is not supported by this communicator
* @param cb_cls closure for @a cb
@@ -197,6 +200,7 @@ int
GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
const struct GNUNET_PeerIdentity *sender,
const struct GNUNET_MessageHeader *msg,
+ struct GNUNET_TIME_Relative expected_addr_validity,
GNUNET_TRANSPORT_MessageCompletedCallback cb,
void *cb_cls);
@@ -251,9 +255,9 @@ struct GNUNET_TRANSPORT_QueueHandle *
GNUNET_TRANSPORT_communicator_mq_add (struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
const struct GNUNET_PeerIdentity *peer,
const char *address,
- uint32_t mtu,
+ uint32_t mtu,
enum GNUNET_NetworkType nt,
- enum GNUNET_TRANSPORT_ConnectionStatus cs,
+ enum GNUNET_TRANSPORT_ConnectionStatus cs,
struct GNUNET_MQ_Handle *mq);
@@ -320,9 +324,9 @@ GNUNET_TRANSPORT_communicator_address_remove (struct GNUNET_TRANSPORT_AddressIde
*/
void
GNUNET_TRANSPORT_communicator_notify (struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
- const struct GNUNET_PeerIdentity *pid,
- const char *comm,
- const struct GNUNET_MessageHeader *header);
+ const struct GNUNET_PeerIdentity *pid,
+ const char *comm,
+ const struct GNUNET_MessageHeader *header);
#if 0 /* keep Emacsens' auto-indent happy */
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c
index 95719852c..a8f88c5e4 100644
--- a/src/transport/gnunet-communicator-tcp.c
+++ b/src/transport/gnunet-communicator-tcp.c
@@ -43,6 +43,12 @@
#include "gnunet_transport_communication_service.h"
/**
+ * How long do we believe our addresses to remain up (before
+ * the other peer should revalidate).
+ */
+#define ADDRESS_VALIDITY_PERIOD GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
+
+/**
* How many messages do we keep at most in the queue to the
* transport service before we start to drop (default,
* can be changed via the configuration file).
@@ -582,8 +588,8 @@ queue_destroy (struct Queue *queue)
struct GNUNET_MQ_Handle *mq;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting queue for peer `%s'\n",
- GNUNET_i2s (&queue->target));
+ "Disconnecting queue for peer `%s'\n",
+ GNUNET_i2s (&queue->target));
if (NULL != (mq = queue->mq))
{
queue->mq = NULL;
@@ -599,9 +605,9 @@ queue_destroy (struct Queue *queue)
&queue->target,
queue));
GNUNET_STATISTICS_set (stats,
- "# queues active",
- GNUNET_CONTAINER_multipeermap_size (queue_map),
- GNUNET_NO);
+ "# queues active",
+ GNUNET_CONTAINER_multipeermap_size (queue_map),
+ GNUNET_NO);
if (NULL != queue->read_task)
{
GNUNET_SCHEDULER_cancel (queue->read_task);
@@ -622,9 +628,9 @@ queue_destroy (struct Queue *queue)
GNUNET_free (queue);
if (NULL == listen_task)
listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- listen_sock,
- &listen_cb,
- NULL);
+ listen_sock,
+ &listen_cb,
+ NULL);
}
@@ -645,18 +651,18 @@ calculate_hmac (struct GNUNET_HashCode *hmac_secret,
struct GNUNET_HashCode mac;
GNUNET_CRYPTO_hmac_raw (hmac_secret,
- sizeof (struct GNUNET_HashCode),
- buf,
- buf_size,
- &mac);
+ sizeof (struct GNUNET_HashCode),
+ buf,
+ buf_size,
+ &mac);
/* truncate to `struct GNUNET_ShortHashCode` */
memcpy (smac,
- &mac,
- sizeof (struct GNUNET_ShortHashCode));
+ &mac,
+ sizeof (struct GNUNET_ShortHashCode));
/* ratchet hmac key */
GNUNET_CRYPTO_hash (hmac_secret,
- sizeof (struct GNUNET_HashCode),
- hmac_secret);
+ sizeof (struct GNUNET_HashCode),
+ hmac_secret);
}
@@ -728,15 +734,15 @@ queue_read (void *cls);
*/
static void
core_read_finished_cb (void *cls,
- int success)
+ int success)
{
struct Queue *queue = cls;
if (GNUNET_OK != success)
GNUNET_STATISTICS_update (stats,
- "# messages lost in communicator API towards CORE",
- 1,
- GNUNET_NO);
+ "# messages lost in communicator API towards CORE",
+ 1,
+ GNUNET_NO);
queue->backpressure--;
/* handle deferred queue destruction */
if ( (queue->destroyed) &&
@@ -750,9 +756,9 @@ core_read_finished_cb (void *cls,
if (NULL == queue->read_task)
queue->read_task
= GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining (queue->timeout),
- queue->sock,
- &queue_read,
- queue);
+ queue->sock,
+ &queue_read,
+ queue);
}
@@ -767,8 +773,8 @@ core_read_finished_cb (void *cls,
*/
static void
pass_plaintext_to_core (struct Queue *queue,
- const void *plaintext,
- size_t plaintext_len)
+ const void *plaintext,
+ size_t plaintext_len)
{
const struct GNUNET_MessageHeader *hdr = plaintext;
int ret;
@@ -781,18 +787,19 @@ pass_plaintext_to_core (struct Queue *queue,
return;
}
ret = GNUNET_TRANSPORT_communicator_receive (ch,
- &queue->target,
- hdr,
- &core_read_finished_cb,
- queue);
+ &queue->target,
+ hdr,
+ ADDRESS_VALIDITY_PERIOD,
+ &core_read_finished_cb,
+ queue);
if (GNUNET_OK == ret)
queue->backpressure++;
GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */
if (GNUNET_SYSERR == ret)
GNUNET_STATISTICS_update (stats,
- "# bytes lost due to CORE not running",
- plaintext_len,
- GNUNET_NO);
+ "# bytes lost due to CORE not running",
+ plaintext_len,
+ GNUNET_NO);
}
@@ -815,45 +822,45 @@ setup_cipher (const struct GNUNET_HashCode *dh,
char ctr[128/8];
gcry_cipher_open (cipher,
- GCRY_CIPHER_AES256 /* low level: go for speed */,
- GCRY_CIPHER_MODE_CTR,
- 0 /* flags */);
+ GCRY_CIPHER_AES256 /* low level: go for speed */,
+ GCRY_CIPHER_MODE_CTR,
+ 0 /* flags */);
GNUNET_assert (GNUNET_YES ==
- GNUNET_CRYPTO_kdf (key,
- sizeof (key),
- "TCP-key",
- strlen ("TCP-key"),
- dh,
- sizeof (*dh),
- pid,
- sizeof (*pid),
- NULL, 0));
+ GNUNET_CRYPTO_kdf (key,
+ sizeof (key),
+ "TCP-key",
+ strlen ("TCP-key"),
+ dh,
+ sizeof (*dh),
+ pid,
+ sizeof (*pid),
+ NULL, 0));
gcry_cipher_setkey (*cipher,
- key,
- sizeof (key));
+ key,
+ sizeof (key));
GNUNET_assert (GNUNET_YES ==
- GNUNET_CRYPTO_kdf (ctr,
- sizeof (ctr),
- "TCP-ctr",
- strlen ("TCP-ctr"),
- dh,
- sizeof (*dh),
- pid,
- sizeof (*pid),
- NULL, 0));
+ GNUNET_CRYPTO_kdf (ctr,
+ sizeof (ctr),
+ "TCP-ctr",
+ strlen ("TCP-ctr"),
+ dh,
+ sizeof (*dh),
+ pid,
+ sizeof (*pid),
+ NULL, 0));
gcry_cipher_setctr (*cipher,
- ctr,
- sizeof (ctr));
+ ctr,
+ sizeof (ctr));
GNUNET_assert (GNUNET_YES ==
- GNUNET_CRYPTO_kdf (hmac_key,
- sizeof (struct GNUNET_HashCode),
- "TCP-hmac",
- strlen ("TCP-hmac"),
- dh,
- sizeof (*dh),
- pid,
- sizeof (*pid),
- NULL, 0));
+ GNUNET_CRYPTO_kdf (hmac_key,
+ sizeof (struct GNUNET_HashCode),
+ "TCP-hmac",
+ strlen ("TCP-hmac"),
+ dh,
+ sizeof (*dh),
+ pid,
+ sizeof (*pid),
+ NULL, 0));
}
@@ -870,12 +877,12 @@ setup_in_cipher (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral,
struct GNUNET_HashCode dh;
GNUNET_CRYPTO_eddsa_ecdh (my_private_key,
- ephemeral,
- &dh);
+ ephemeral,
+ &dh);
setup_cipher (&dh,
- &my_identity,
- &queue->in_cipher,
- &queue->in_hmac);
+ &my_identity,
+ &queue->in_cipher,
+ &queue->in_hmac);
}
@@ -901,9 +908,9 @@ do_rekey (struct Queue *queue,
thp.monotonic_time = rekey->monotonic_time;
if (GNUNET_OK !=
GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY,
- &thp.purpose,
- &rekey->sender_sig,
- &queue->target.public_key))
+ &thp.purpose,
+ &rekey->sender_sig,
+ &queue->target.public_key))
{
GNUNET_break (0);
queue_finish (queue);
@@ -912,7 +919,7 @@ do_rekey (struct Queue *queue,
gcry_cipher_close (queue->in_cipher);
queue->rekeyed = GNUNET_YES;
setup_in_cipher (&rekey->ephemeral,
- queue);
+ queue);
}
@@ -954,16 +961,16 @@ try_handle_plaintext (struct Queue *queue)
ntohs (hdr->size),
&tmac);
if (0 != memcmp (&tmac,
- &box->hmac,
- sizeof (tmac)))
+ &box->hmac,
+ sizeof (tmac)))
{
GNUNET_break_op (0);
queue_finish (queue);
return 0;
}
pass_plaintext_to_core (queue,
- (const void *) &box[1],
- ntohs (hdr->size));
+ (const void *) &box[1],
+ ntohs (hdr->size));
size = ntohs (hdr->size) + sizeof (*box);
break;
case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY:
@@ -1013,8 +1020,8 @@ try_handle_plaintext (struct Queue *queue)
sizeof (rekeyz),
&tmac);
if (0 != memcmp (&tmac,
- &fin->hmac,
- sizeof (tmac)))
+ &fin->hmac,
+ sizeof (tmac)))
{
GNUNET_break_op (0);
queue_finish (queue);
@@ -1047,24 +1054,24 @@ queue_read (void *cls)
queue->read_task = NULL;
rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
- &queue->cread_buf[queue->cread_off],
- BUF_SIZE - queue->cread_off);
+ &queue->cread_buf[queue->cread_off],
+ BUF_SIZE - queue->cread_off);
if (-1 == rcvd)
{
if ( (EAGAIN != errno) &&
(EINTR != errno) )
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG,
- "recv");
+ "recv");
queue_finish (queue);
return;
}
/* try again */
queue->read_task
= GNUNET_SCHEDULER_add_read_net (left,
- queue->sock,
- &queue_read,
- queue);
+ queue->sock,
+ &queue_read,
+ queue);
return;
}
if (0 != rcvd)
@@ -1074,16 +1081,16 @@ queue_read (void *cls)
(queue->cread_off > 0) )
{
size_t max = GNUNET_MIN (sizeof (queue->pread_buf) - queue->pread_off,
- queue->cread_off);
+ queue->cread_off);
size_t done;
size_t total;
GNUNET_assert (0 ==
- gcry_cipher_decrypt (queue->in_cipher,
- &queue->pread_buf[queue->pread_off],
- max,
- queue->cread_buf,
- max));
+ gcry_cipher_decrypt (queue->in_cipher,
+ &queue->pread_buf[queue->pread_off],
+ max,
+ queue->cread_buf,
+ max));
queue->pread_off += max;
total = 0;
while ( (GNUNET_NO == queue->rekeyed) &&
@@ -1095,8 +1102,8 @@ queue_read (void *cls)
avoided if we pass 'total' into try_handle_plaintext()
and use it at an offset into the buffer there! */
memmove (queue->pread_buf,
- &queue->pread_buf[done],
- queue->pread_off - done);
+ &queue->pread_buf[done],
+ queue->pread_off - done);
queue->pread_off -= done;
total += done;
}
@@ -1111,8 +1118,8 @@ queue_read (void *cls)
queue->rekeyed = GNUNET_NO;
}
memmove (queue->cread_buf,
- &queue->cread_buf[max],
- queue->cread_off - max);
+ &queue->cread_buf[max],
+ queue->cread_off - max);
queue->cread_off -= max;
}
@@ -1126,17 +1133,17 @@ queue_read (void *cls)
/* continue reading */
queue->read_task
= GNUNET_SCHEDULER_add_read_net (left,
- queue->sock,
- &queue_read,
- queue);
+ queue->sock,
+ &queue_read,
+ queue);
}
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Queue %p was idle for %s, disconnecting\n",
- queue,
- GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
- GNUNET_YES));
+ "Queue %p was idle for %s, disconnecting\n",
+ queue,
+ GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ GNUNET_YES));
queue_finish (queue);
}
@@ -1150,7 +1157,7 @@ queue_read (void *cls)
*/
static struct sockaddr *
tcp_address_to_sockaddr (const char *bindto,
- socklen_t *sock_len)
+ socklen_t *sock_len)
{
struct sockaddr *in;
unsigned int port;
@@ -1159,24 +1166,24 @@ tcp_address_to_sockaddr (const char *bindto,
char *cp;
if (1 == SSCANF (bindto,
- "%u%1s",
- &port,
- dummy))
+ "%u%1s",
+ &port,
+ dummy))
{
/* interpreting value as just a PORT number */
if (port > UINT16_MAX)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "BINDTO specification `%s' invalid: value too large for port\n",
- bindto);
+ "BINDTO specification `%s' invalid: value too large for port\n",
+ bindto);
return NULL;
}
if ( (GNUNET_NO ==
- GNUNET_NETWORK_test_pf (PF_INET6)) ||
- (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
- COMMUNICATOR_CONFIG_SECTION,
- "DISABLE_V6")) )
+ GNUNET_NETWORK_test_pf (PF_INET6)) ||
+ (GNUNET_YES ==
+ GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ COMMUNICATOR_CONFIG_SECTION,
+ "DISABLE_V6")) )
{
struct sockaddr_in *i4;
@@ -1206,25 +1213,25 @@ tcp_address_to_sockaddr (const char *bindto,
*colon = '\0';
colon++;
if (1 == SSCANF (colon,
- "%u%1s",
- &port,
- dummy))
+ "%u%1s",
+ &port,
+ dummy))
{
/* interpreting value as just a PORT number */
if (port > UINT16_MAX)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "BINDTO specification `%s' invalid: value too large for port\n",
- bindto);
- GNUNET_free (cp);
- return NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "BINDTO specification `%s' invalid: value too large for port\n",
+ bindto);
+ GNUNET_free (cp);
+ return NULL;
}
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "BINDTO specification `%s' invalid: last ':' not followed by number\n",
- bindto);
+ "BINDTO specification `%s' invalid: last ':' not followed by number\n",
+ bindto);
GNUNET_free (cp);
return NULL;
}
@@ -1239,12 +1246,12 @@ tcp_address_to_sockaddr (const char *bindto,
struct sockaddr_in v4;
if (1 == inet_pton (AF_INET,
- cp,
- &v4))
+ cp,
+ &v4))
{
v4.sin_port = htons ((uint16_t) port);
in = GNUNET_memdup (&v4,
- sizeof (v4));
+ sizeof (v4));
*sock_len = sizeof (v4);
GNUNET_free (cp);
return in;
@@ -1263,12 +1270,12 @@ tcp_address_to_sockaddr (const char *bindto,
cp[strlen (cp) -1] = '\0'; /* eat ']' */
}
if (1 == inet_pton (AF_INET6,
- start,
- &v6))
+ start,
+ &v6))
{
v6.sin6_port = htons ((uint16_t) port);
in = GNUNET_memdup (&v6,
- sizeof (v6));
+ sizeof (v6));
*sock_len = sizeof (v6);
GNUNET_free (cp);
return in;
@@ -1292,20 +1299,19 @@ setup_out_cipher (struct Queue *queue)
struct GNUNET_HashCode dh;
GNUNET_CRYPTO_ecdh_eddsa (&queue->ephemeral,
- &queue->target.public_key,
- &dh);
+ &queue->target.public_key,
+ &dh);
/* we don't need the private key anymore, drop it! */
memset (&queue->ephemeral,
- 0,
- sizeof (queue->ephemeral));
+ 0,
+ sizeof (queue->ephemeral));
setup_cipher (&dh,
- &queue->target,
- &queue->out_cipher,
- &queue->out_hmac);
-
+ &queue->target,
+ &queue->out_cipher,
+ &queue->out_hmac);
queue->rekey_time = GNUNET_TIME_relative_to_absolute (REKEY_TIME_INTERVAL);
queue->rekey_left_bytes = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- REKEY_MAX_BYTES);
+ REKEY_MAX_BYTES);
}
@@ -1323,14 +1329,14 @@ inject_rekey (struct Queue *queue)
GNUNET_assert (0 == queue->pwrite_off);
memset (&rekey,
- 0,
- sizeof (rekey));
+ 0,
+ sizeof (rekey));
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral));
+ GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral));
rekey.header.type = ntohs (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY);
rekey.header.size = ntohs (sizeof (rekey));
GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral,
- &rekey.ephemeral);
+ &rekey.ephemeral);
rekey.monotonic_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg));
thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY);
thp.purpose.size = htonl (sizeof (thp));
@@ -1339,16 +1345,16 @@ inject_rekey (struct Queue *queue)
thp.ephemeral = rekey.ephemeral;
thp.monotonic_time = rekey.monotonic_time;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_eddsa_sign (my_private_key,
- &thp.purpose,
- &rekey.sender_sig));
+ GNUNET_CRYPTO_eddsa_sign (my_private_key,
+ &thp.purpose,
+ &rekey.sender_sig));
calculate_hmac (&queue->out_hmac,
&rekey,
sizeof (rekey),
&rekey.hmac);
memcpy (queue->pwrite_buf,
- &rekey,
- sizeof (rekey));
+ &rekey,
+ sizeof (rekey));
queue->rekey_state = GNUNET_YES;
}
@@ -1380,14 +1386,14 @@ queue_write (void *cls)
queue->write_task = NULL;
sent = GNUNET_NETWORK_socket_send (queue->sock,
- queue->cwrite_buf,
- queue->cwrite_off);
+ queue->cwrite_buf,
+ queue->cwrite_off);
if ( (-1 == sent) &&
(EAGAIN != errno) &&
(EINTR != errno) )
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "send");
+ "send");
queue_destroy (queue);
return;
}
@@ -1396,8 +1402,8 @@ queue_write (void *cls)
size_t usent = (size_t) sent;
memmove (queue->cwrite_buf,
- &queue->cwrite_buf[usent],
- queue->cwrite_off - usent);
+ &queue->cwrite_buf[usent],
+ queue->cwrite_off - usent);
reschedule_queue_timeout (queue);
}
/* can we encrypt more? (always encrypt full messages, needed
@@ -1405,11 +1411,11 @@ queue_write (void *cls)
if (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE)
{
GNUNET_assert (0 ==
- gcry_cipher_encrypt (queue->out_cipher,
- &queue->cwrite_buf[queue->cwrite_off],
- queue->pwrite_off,
- queue->pwrite_buf,
- queue->pwrite_off));
+ gcry_cipher_encrypt (queue->out_cipher,
+ &queue->cwrite_buf[queue->cwrite_off],
+ queue->pwrite_off,
+ queue->pwrite_buf,
+ queue->pwrite_off));
if (queue->rekey_left_bytes > queue->pwrite_off)
queue->rekey_left_bytes -= queue->pwrite_off;
else
@@ -1442,9 +1448,9 @@ queue_write (void *cls)
if (0 < queue->cwrite_off)
queue->write_task
= GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
- queue->sock,
- &queue_write,
- queue);
+ queue->sock,
+ &queue_write,
+ queue);
}
@@ -1458,8 +1464,8 @@ queue_write (void *cls)
*/
static void
mq_send (struct GNUNET_MQ_Handle *mq,
- const struct GNUNET_MessageHeader *msg,
- void *impl_state)
+ const struct GNUNET_MessageHeader *msg,
+ void *impl_state)
{
struct Queue *queue = impl_state;
uint16_t msize = ntohs (msg->size);
@@ -1476,12 +1482,12 @@ mq_send (struct GNUNET_MQ_Handle *mq,
msize,
&box.hmac);
memcpy (&queue->pread_buf[queue->pread_off],
- &box,
- sizeof (box));
+ &box,
+ sizeof (box));
queue->pread_off += sizeof (box);
memcpy (&queue->pread_buf[queue->pread_off],
- msg,
- msize);
+ msg,
+ msize);
queue->pread_off += msize;
GNUNET_assert (NULL != queue->sock);
if (NULL == queue->write_task)
@@ -1489,7 +1495,7 @@ mq_send (struct GNUNET_MQ_Handle *mq,
GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
queue->sock,
&queue_write,
- queue);
+ queue);
}
@@ -1503,7 +1509,7 @@ mq_send (struct GNUNET_MQ_Handle *mq,
*/
static void
mq_destroy (struct GNUNET_MQ_Handle *mq,
- void *impl_state)
+ void *impl_state)
{
struct Queue *queue = impl_state;
@@ -1523,7 +1529,7 @@ mq_destroy (struct GNUNET_MQ_Handle *mq,
*/
static void
mq_cancel (struct GNUNET_MQ_Handle *mq,
- void *impl_state)
+ void *impl_state)
{
struct Queue *queue = impl_state;
@@ -1543,14 +1549,14 @@ mq_cancel (struct GNUNET_MQ_Handle *mq,
*/
static void
mq_error (void *cls,
- enum GNUNET_MQ_Error error)
+ enum GNUNET_MQ_Error error)
{
struct Queue *queue = cls;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "MQ error in queue to %s: %d\n",
- GNUNET_i2s (&queue->target),
- (int) error);
+ "MQ error in queue to %s: %d\n",
+ GNUNET_i2s (&queue->target),
+ (int) error);
queue_finish (queue);
}
@@ -1567,26 +1573,26 @@ boot_queue (struct Queue *queue,
enum GNUNET_TRANSPORT_ConnectionStatus cs)
{
queue->nt = GNUNET_NT_scanner_get_type (is,
- queue->address,
- queue->address_len);
+ queue->address,
+ queue->address_len);
(void) GNUNET_CONTAINER_multipeermap_put (queue_map,
- &queue->target,
- queue,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ &queue->target,
+ queue,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
GNUNET_STATISTICS_set (stats,
- "# queues active",
- GNUNET_CONTAINER_multipeermap_size (queue_map),
- GNUNET_NO);
+ "# queues active",
+ GNUNET_CONTAINER_multipeermap_size (queue_map),
+ GNUNET_NO);
queue->timeout
= GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
queue->mq
= GNUNET_MQ_queue_for_callbacks (&mq_send,
- &mq_destroy,
- &mq_cancel,
- queue,
- NULL,
- &mq_error,
- queue);
+ &mq_destroy,
+ &mq_cancel,
+ queue,
+ NULL,
+ &mq_error,
+ queue);
{
char *foreign_addr;
@@ -1594,29 +1600,29 @@ boot_queue (struct Queue *queue,
{
case AF_INET:
GNUNET_asprintf (&foreign_addr,
- "%s-%s",
- COMMUNICATOR_ADDRESS_PREFIX,
- GNUNET_a2s(queue->address,
- queue->address_len));
+ "%s-%s",
+ COMMUNICATOR_ADDRESS_PREFIX,
+ GNUNET_a2s(queue->address,
+ queue->address_len));
break;
case AF_INET6:
GNUNET_asprintf (&foreign_addr,
- "%s-%s",
- COMMUNICATOR_ADDRESS_PREFIX,
- GNUNET_a2s(queue->address,
- queue->address_len));
+ "%s-%s",
+ COMMUNICATOR_ADDRESS_PREFIX,
+ GNUNET_a2s(queue->address,
+ queue->address_len));
break;
default:
GNUNET_assert (0);
}
queue->qh
= GNUNET_TRANSPORT_communicator_mq_add (ch,
- &queue->target,
- foreign_addr,
- 0 /* no MTU */,
- queue->nt,
- cs,
- queue->mq);
+ &queue->target,
+ foreign_addr,
+ 0 /* no MTU */,
+ queue->nt,
+ cs,
+ queue->mq);
GNUNET_free (foreign_addr);
}
}
@@ -1640,8 +1646,8 @@ transmit_kx (struct Queue *queue,
struct TCPConfirmation tc;
memcpy (queue->cwrite_buf,
- epub,
- sizeof (*epub));
+ epub,
+ sizeof (*epub));
queue->cwrite_off = sizeof (epub);
/* compute 'tc' and append in encrypted format to cwrite_buf */
tc.sender = my_identity;
@@ -1653,15 +1659,15 @@ transmit_kx (struct Queue *queue,
ths.ephemeral = *epub;
ths.monotonic_time = tc.monotonic_time;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_eddsa_sign (my_private_key,
- &ths.purpose,
- &tc.sender_sig));
+ GNUNET_CRYPTO_eddsa_sign (my_private_key,
+ &ths.purpose,
+ &tc.sender_sig));
GNUNET_assert (0 ==
- gcry_cipher_encrypt (queue->out_cipher,
- &queue->cwrite_buf[queue->cwrite_off],
- sizeof (tc),
- &tc,
- sizeof (tc)));
+ gcry_cipher_encrypt (queue->out_cipher,
+ &queue->cwrite_buf[queue->cwrite_off],
+ sizeof (tc),
+ &tc,
+ sizeof (tc)));
queue->cwrite_off += sizeof (tc);
}
@@ -1681,10 +1687,10 @@ start_initial_kx_out (struct Queue *queue)
GNUNET_assert (GNUNET_OK ==
GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral));
GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral,
- &epub);
+ &epub);
setup_out_cipher (queue);
transmit_kx (queue,
- &epub);
+ &epub);
}
@@ -1701,17 +1707,17 @@ start_initial_kx_out (struct Queue *queue)
*/
static int
decrypt_and_check_tc (struct Queue *queue,
- struct TCPConfirmation *tc,
- char *ibuf)
+ struct TCPConfirmation *tc,
+ char *ibuf)
{
struct TcpHandshakeSignature ths;
GNUNET_assert (0 ==
- gcry_cipher_decrypt (queue->in_cipher,
- tc,
- sizeof (*tc),
- &ibuf[sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)],
- sizeof (tc)));
+ gcry_cipher_decrypt (queue->in_cipher,
+ tc,
+ sizeof (*tc),
+ &ibuf[sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)],
+ sizeof (tc)));
ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE);
ths.purpose.size = htonl (sizeof (ths));
ths.sender = tc->sender;
@@ -1721,9 +1727,9 @@ decrypt_and_check_tc (struct Queue *queue,
sizeof (struct GNUNET_CRYPTO_EcdhePublicKey));
ths.monotonic_time = tc->monotonic_time;
return GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE,
- &ths.purpose,
- &tc->sender_sig,
- &tc->sender.public_key);
+ &ths.purpose,
+ &tc->sender_sig,
+ &tc->sender.public_key);
}
@@ -1738,8 +1744,8 @@ free_proto_queue (struct ProtoQueue *pq)
GNUNET_NETWORK_socket_close (pq->sock);
GNUNET_free (pq->address);
GNUNET_CONTAINER_DLL_remove (proto_head,
- proto_tail,
- pq);
+ proto_tail,
+ pq);
GNUNET_free (pq);
}
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c
index f101d2d75..1db5bba6b 100644
--- a/src/transport/gnunet-communicator-udp.c
+++ b/src/transport/gnunet-communicator-udp.c
@@ -69,6 +69,12 @@
#define INTERFACE_SCAN_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
/**
+ * How long do we believe our addresses to remain up (before
+ * the other peer should revalidate).
+ */
+#define ADDRESS_VALIDITY_PERIOD GNUNET_TIME_UNIT_HOURS
+
+/**
* AES key size.
*/
#define AES_KEY_SIZE (256/8)
@@ -964,11 +970,11 @@ sender_destroy (struct SenderAddress *sender)
&sender->target,
sender));
GNUNET_assert (sender ==
- GNUNET_CONTAINER_heap_remove_node (sender->hn));
+ GNUNET_CONTAINER_heap_remove_node (sender->hn));
GNUNET_STATISTICS_set (stats,
- "# senders active",
- GNUNET_CONTAINER_multipeermap_size (senders),
- GNUNET_NO);
+ "# senders active",
+ GNUNET_CONTAINER_multipeermap_size (senders),
+ GNUNET_NO);
GNUNET_free (sender->address);
GNUNET_free (sender);
}
@@ -992,22 +998,22 @@ get_iv_key (const struct GNUNET_HashCode *msec,
char res[AES_KEY_SIZE + AES_IV_SIZE];
GNUNET_CRYPTO_hkdf (res,
- sizeof (res),
- GCRY_MD_SHA512,
- GCRY_MD_SHA256,
- &sid,
- sizeof (sid),
- msec,
- sizeof (*msec),
- "UDP-IV-KEY",
- strlen ("UDP-IV-KEY"),
- NULL, 0);
+ sizeof (res),
+ GCRY_MD_SHA512,
+ GCRY_MD_SHA256,
+ &sid,
+ sizeof (sid),
+ msec,
+ sizeof (*msec),
+ "UDP-IV-KEY",
+ strlen ("UDP-IV-KEY"),
+ NULL, 0);
memcpy (key,
- res,
- AES_KEY_SIZE);
+ res,
+ AES_KEY_SIZE);
memcpy (iv,
- &res[AES_KEY_SIZE],
- AES_IV_SIZE);
+ &res[AES_KEY_SIZE],
+ AES_IV_SIZE);
}
@@ -1022,7 +1028,7 @@ reschedule_sender_timeout (struct SenderAddress *sender)
sender->timeout
= GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
GNUNET_CONTAINER_heap_update_cost (sender->hn,
- sender->timeout.abs_value_us);
+ sender->timeout.abs_value_us);
}
@@ -1091,16 +1097,16 @@ static void
calculate_cmac (struct SharedSecret *ss)
{
GNUNET_CRYPTO_hkdf (&ss->cmac,
- sizeof (ss->cmac),
- GCRY_MD_SHA512,
- GCRY_MD_SHA256,
- "CMAC",
- strlen ("CMAC"),
- &ss->master,
- sizeof (ss->master),
- "UDP-CMAC",
- strlen ("UDP-CMAC"),
- NULL, 0);
+ sizeof (ss->cmac),
+ GCRY_MD_SHA512,
+ GCRY_MD_SHA256,
+ "CMAC",
+ strlen ("CMAC"),
+ &ss->master,
+ sizeof (ss->master),
+ "UDP-CMAC",
+ strlen ("UDP-CMAC"),
+ NULL, 0);
}
@@ -1114,8 +1120,8 @@ calculate_cmac (struct SharedSecret *ss)
*/
static void
pass_plaintext_to_core (struct SenderAddress *sender,
- const void *plaintext,
- size_t plaintext_len)
+ const void *plaintext,
+ size_t plaintext_len)
{
const struct GNUNET_MessageHeader *hdr = plaintext;
@@ -1126,10 +1132,11 @@ pass_plaintext_to_core (struct SenderAddress *sender,
ntohs (hdr->size),
GNUNET_NO);
(void) GNUNET_TRANSPORT_communicator_receive (ch,
- &sender->target,
- hdr,
- NULL /* no flow control possible */,
- NULL);
+ &sender->target,
+ hdr,
+ ADDRESS_VALIDITY_PERIOD,
+ NULL /* no flow control possible */,
+ NULL);
/* move on to next message, if any */
plaintext_len -= ntohs (hdr->size);
if (plaintext_len < sizeof (*hdr))
@@ -1137,9 +1144,9 @@ pass_plaintext_to_core (struct SenderAddress *sender,
hdr = plaintext + ntohs (hdr->size);
}
GNUNET_STATISTICS_update (stats,
- "# bytes padding discarded",
- plaintext_len,
- GNUNET_NO);
+ "# bytes padding discarded",
+ plaintext_len,
+ GNUNET_NO);
}
@@ -1153,26 +1160,26 @@ pass_plaintext_to_core (struct SenderAddress *sender,
*/
static void
setup_cipher (const struct GNUNET_HashCode *msec,
- uint32_t serial,
- gcry_cipher_hd_t *cipher)
+ uint32_t serial,
+ gcry_cipher_hd_t *cipher)
{
char key[AES_KEY_SIZE];
char iv[AES_IV_SIZE];
gcry_cipher_open (cipher,
- GCRY_CIPHER_AES256 /* low level: go for speed */,
- GCRY_CIPHER_MODE_GCM,
- 0 /* flags */);
+ GCRY_CIPHER_AES256 /* low level: go for speed */,
+ GCRY_CIPHER_MODE_GCM,
+ 0 /* flags */);
get_iv_key (msec,
- serial,
- key,
- iv);
+ serial,
+ key,
+ iv);
gcry_cipher_setkey (*cipher,
- key,
- sizeof (key));
+ key,
+ sizeof (key));
gcry_cipher_setiv (*cipher,
- iv,
- sizeof (iv));
+ iv,
+ sizeof (iv));
}
@@ -1190,33 +1197,33 @@ setup_cipher (const struct GNUNET_HashCode *msec,
*/
static int
try_decrypt (const struct SharedSecret *ss,
- const char tag[GCM_TAG_SIZE],
- uint32_t serial,
- const char *in_buf,
- size_t in_buf_size,
- char *out_buf)
+ const char tag[GCM_TAG_SIZE],
+ uint32_t serial,
+ const char *in_buf,
+ size_t in_buf_size,
+ char *out_buf)
{
gcry_cipher_hd_t cipher;
setup_cipher (&ss->master,
- serial,
- &cipher);
+ serial,
+ &cipher);
GNUNET_assert (0 ==
- gcry_cipher_decrypt (cipher,
- out_buf,
- in_buf_size,
- in_buf,
- in_buf_size));
+ gcry_cipher_decrypt (cipher,
+ out_buf,
+ in_buf_size,
+ in_buf,
+ in_buf_size));
if (0 !=
gcry_cipher_checktag (cipher,
- tag,
- GCM_TAG_SIZE))
+ tag,
+ GCM_TAG_SIZE))
{
gcry_cipher_close (cipher);
GNUNET_STATISTICS_update (stats,
- "# AEAD authentication failures",
- 1,
- GNUNET_NO);
+ "# AEAD authentication failures",
+ 1,
+ GNUNET_NO);
return GNUNET_SYSERR;
}
gcry_cipher_close (cipher);
@@ -1237,8 +1244,8 @@ setup_shared_secret_dec (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral)
ss = GNUNET_new (struct SharedSecret);
GNUNET_CRYPTO_eddsa_ecdh (my_private_key,
- ephemeral,
- &ss->master);
+ ephemeral,
+ &ss->master);
return ss;
}
@@ -1258,18 +1265,18 @@ setup_shared_secret_enc (const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral,
ss = GNUNET_new (struct SharedSecret);
GNUNET_CRYPTO_ecdh_eddsa (ephemeral,
- &receiver->target.public_key,
- &ss->master);
+ &receiver->target.public_key,
+ &ss->master);
calculate_cmac (ss);
ss->receiver = receiver;
GNUNET_CONTAINER_DLL_insert (receiver->ss_head,
- receiver->ss_tail,
- ss);
+ receiver->ss_tail,
+ ss);
receiver->num_secrets++;
GNUNET_STATISTICS_update (stats,
- "# Secrets active",
- 1,
- GNUNET_NO);
+ "# Secrets active",
+ 1,
+ GNUNET_NO);
return ss;
}
@@ -1297,8 +1304,8 @@ setup_receiver_mq (struct ReceiverAddress *receiver);
*/
static int
handle_ack (void *cls,
- const struct GNUNET_PeerIdentity *pid,
- void *value)
+ const struct GNUNET_PeerIdentity *pid,
+ void *value)
{
const struct UDPAck *ack = cls;
struct ReceiverAddress *receiver = value;
@@ -1309,8 +1316,8 @@ handle_ack (void *cls,
ss = ss->next)
{
if (0 == memcmp (&ack->cmac,
- &ss->cmac,
- sizeof (struct GNUNET_HashCode)))
+ &ss->cmac,
+ sizeof (struct GNUNET_HashCode)))
{
uint32_t allowed;
@@ -1318,21 +1325,21 @@ handle_ack (void *cls,
if (allowed > ss->sequence_allowed)
{
- receiver->acks_available += (allowed - ss->sequence_allowed);
- if ((allowed - ss->sequence_allowed)
- == receiver->acks_available)
- {
- /* we just incremented from zero => MTU change! */
- setup_receiver_mq (receiver);
- }
- ss->sequence_allowed = allowed;
- /* move ss to head to avoid discarding it anytime soon! */
- GNUNET_CONTAINER_DLL_remove (receiver->ss_head,
- receiver->ss_tail,
- ss);
- GNUNET_CONTAINER_DLL_insert (receiver->ss_head,
- receiver->ss_tail,
- ss);
+ receiver->acks_available += (allowed - ss->sequence_allowed);
+ if ((allowed - ss->sequence_allowed)
+ == receiver->acks_available)
+ {
+ /* we just incremented from zero => MTU change! */
+ setup_receiver_mq (receiver);
+ }
+ ss->sequence_allowed = allowed;
+ /* move ss to head to avoid discarding it anytime soon! */
+ GNUNET_CONTAINER_DLL_remove (receiver->ss_head,
+ receiver->ss_tail,
+ ss);
+ GNUNET_CONTAINER_DLL_insert (receiver->ss_head,
+ receiver->ss_tail,
+ ss);
}
return GNUNET_NO;
}
@@ -1351,8 +1358,8 @@ handle_ack (void *cls,
*/
static void
try_handle_plaintext (struct SenderAddress *sender,
- const void *buf,
- size_t buf_size)
+ const void *buf,
+ size_t buf_size)
{
const struct GNUNET_MessageHeader *hdr
= (const struct GNUNET_MessageHeader *) buf;
@@ -1370,23 +1377,23 @@ try_handle_plaintext (struct SenderAddress *sender,
case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK:
/* lookup master secret by 'cmac', then update sequence_max */
GNUNET_CONTAINER_multipeermap_get_multiple (receivers,
- &sender->target,
- &handle_ack,
- (void *) ack);
+ &sender->target,
+ &handle_ack,
+ (void *) ack);
/* There could be more messages after the ACK, handle those as well */
buf += ntohs (hdr->size);
buf_size -= ntohs (hdr->size);
pass_plaintext_to_core (sender,
- buf,
- buf_size);
+ buf,
+ buf_size);
break;
case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD:
/* skip padding */
break;
default:
pass_plaintext_to_core (sender,
- buf,
- buf_size);
+ buf,
+ buf_size);
}
}
@@ -1413,7 +1420,7 @@ consider_ss_ack (struct SharedSecret *ss)
while (ss->active_kce_count < KCN_TARGET)
kce_generate (ss,
- ++ss->sequence_allowed);
+ ++ss->sequence_allowed);
ack.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK);
ack.header.size = htons (sizeof (ack));
ack.sequence_max = htonl (ss->sequence_allowed);
@@ -1435,8 +1442,8 @@ consider_ss_ack (struct SharedSecret *ss)
*/
static void
decrypt_box (const struct UDPBox *box,
- size_t box_len,
- struct KeyCacheEntry *kce)
+ size_t box_len,
+ struct KeyCacheEntry *kce)
{
struct SharedSecret *ss = kce->ss;
char out_buf[box_len - sizeof (*box)];
@@ -1444,11 +1451,11 @@ decrypt_box (const struct UDPBox *box,
GNUNET_assert (NULL != ss->sender);
if (GNUNET_OK !=
try_decrypt (ss,
- box->gcm_tag,
- kce->sequence_number,
- (const char *) &box[1],
- sizeof (out_buf),
- out_buf))
+ box->gcm_tag,
+ kce->sequence_number,
+ (const char *) &box[1],
+ sizeof (out_buf),
+ out_buf))
{
GNUNET_STATISTICS_update (stats,
"# Decryption failures with valid KCE",
@@ -1459,12 +1466,12 @@ decrypt_box (const struct UDPBox *box,
}
kce_destroy (kce);
GNUNET_STATISTICS_update (stats,
- "# bytes decrypted with BOX",
- sizeof (out_buf),
- GNUNET_NO);
+ "# bytes decrypted with BOX",
+ sizeof (out_buf),
+ GNUNET_NO);
try_handle_plaintext (ss->sender,
- out_buf,
- sizeof (out_buf));
+ out_buf,
+ sizeof (out_buf));
consider_ss_ack (ss);
}
@@ -1501,16 +1508,16 @@ struct SearchContext
*/
static int
find_sender_by_address (void *cls,
- const struct GNUNET_PeerIdentity *key,
- void *value)
+ const struct GNUNET_PeerIdentity *key,
+ void *value)
{
struct SearchContext *sc = cls;
struct SenderAddress *sender = value;
if ( (sender->address_len == sc->address_len) &&
(0 == memcmp (sender->address,
- sc->address,
- sender->address_len)) )
+ sc->address,
+ sender->address_len)) )
{
sc->sender = sender;
return GNUNET_NO; /* stop iterating! */
@@ -1532,8 +1539,8 @@ find_sender_by_address (void *cls,
*/
static struct SenderAddress *
setup_sender (const struct GNUNET_PeerIdentity *target,
- const struct sockaddr *address,
- socklen_t address_len)
+ const struct sockaddr *address,
+ socklen_t address_len)
{
struct SenderAddress *sender;
struct SearchContext sc = {
@@ -1543,9 +1550,9 @@ setup_sender (const struct GNUNET_PeerIdentity *target,
};
GNUNET_CONTAINER_multipeermap_get_multiple (senders,
- target,
- &find_sender_by_address,
- &sc);
+ target,
+ &find_sender_by_address,
+ &sc);
if (NULL != sc.sender)
{
reschedule_sender_timeout (sc.sender);
@@ -1554,27 +1561,27 @@ setup_sender (const struct GNUNET_PeerIdentity *target,
sender = GNUNET_new (struct SenderAddress);
sender->target = *target;
sender->address = GNUNET_memdup (address,
- address_len);
+ address_len);
sender->address_len = address_len;
(void) GNUNET_CONTAINER_multipeermap_put (senders,
- &sender->target,
- sender,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ &sender->target,
+ sender,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
GNUNET_STATISTICS_set (stats,
- "# senders active",
- GNUNET_CONTAINER_multipeermap_size (receivers),
- GNUNET_NO);
+ "# senders active",
+ GNUNET_CONTAINER_multipeermap_size (receivers),
+ GNUNET_NO);
sender->timeout
= GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
sender->hn = GNUNET_CONTAINER_heap_insert (senders_heap,
- sender,
- sender->timeout.abs_value_us);
+ sender,
+ sender->timeout.abs_value_us);
sender->nt = GNUNET_NT_scanner_get_type (is,
- address,
- address_len);
+ address,
+ address_len);
if (NULL == timeout_task)
timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts,
- NULL);
+ NULL);
return sender;
}
@@ -1759,11 +1766,11 @@ sock_read (void *cls)
ss = setup_shared_secret_dec (&kx->ephemeral);
if (GNUNET_OK !=
try_decrypt (ss,
- kx->gcm_tag,
- 0,
- &buf[sizeof (*kx)],
- sizeof (pbuf),
- pbuf))
+ kx->gcm_tag,
+ 0,
+ &buf[sizeof (*kx)],
+ sizeof (pbuf),
+ pbuf))
{
GNUNET_free (ss);
GNUNET_STATISTICS_update (stats,
@@ -1774,8 +1781,8 @@ sock_read (void *cls)
}
uc = (const struct UDPConfirmation *) pbuf;
if (GNUNET_OK !=
- verify_confirmation (&kx->ephemeral,
- uc))
+ verify_confirmation (&kx->ephemeral,
+ uc))
{
GNUNET_break_op (0);
GNUNET_free (ss);
@@ -1787,24 +1794,24 @@ sock_read (void *cls)
}
calculate_cmac (ss);
sender = setup_sender (&uc->sender,
- (const struct sockaddr *) &sa,
- salen);
+ (const struct sockaddr *) &sa,
+ salen);
ss->sender = sender;
GNUNET_CONTAINER_DLL_insert (sender->ss_head,
- sender->ss_tail,
- ss);
+ sender->ss_tail,
+ ss);
sender->num_secrets++;
GNUNET_STATISTICS_update (stats,
- "# Secrets active",
- 1,
- GNUNET_NO);
+ "# Secrets active",
+ 1,
+ GNUNET_NO);
GNUNET_STATISTICS_update (stats,
- "# messages decrypted without BOX",
- 1,
- GNUNET_NO);
+ "# messages decrypted without BOX",
+ 1,
+ GNUNET_NO);
try_handle_plaintext (sender,
- &uc[1],
- sizeof (pbuf) - sizeof (*uc));
+ &uc[1],
+ sizeof (pbuf) - sizeof (*uc));
consider_ss_ack (ss);
if (sender->num_secrets > MAX_SECRETS)
secret_destroy (sender->ss_tail);
@@ -1821,7 +1828,7 @@ sock_read (void *cls)
*/
static struct sockaddr *
udp_address_to_sockaddr (const char *bindto,
- socklen_t *sock_len)
+ socklen_t *sock_len)
{
struct sockaddr *in;
unsigned int port;
@@ -1830,24 +1837,24 @@ udp_address_to_sockaddr (const char *bindto,
char *cp;
if (1 == SSCANF (bindto,
- "%u%1s",
- &port,
- dummy))
+ "%u%1s",
+ &port,
+ dummy))
{
/* interpreting value as just a PORT number */
if (port > UINT16_MAX)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "BINDTO specification `%s' invalid: value too large for port\n",
- bindto);
+ "BINDTO specification `%s' invalid: value too large for port\n",
+ bindto);
return NULL;
}
if ( (GNUNET_NO ==
- GNUNET_NETWORK_test_pf (PF_INET6)) ||
- (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
- COMMUNICATOR_CONFIG_SECTION,
- "DISABLE_V6")) )
+ GNUNET_NETWORK_test_pf (PF_INET6)) ||
+ (GNUNET_YES ==
+ GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ COMMUNICATOR_CONFIG_SECTION,
+ "DISABLE_V6")) )
{
struct sockaddr_in *i4;
@@ -1877,16 +1884,16 @@ udp_address_to_sockaddr (const char *bindto,
*colon = '\0';
colon++;
if (1 == SSCANF (colon,
- "%u%1s",
- &port,
- dummy))
+ "%u%1s",
+ &port,
+ dummy))
{
/* interpreting value as just a PORT number */
if (port > UINT16_MAX)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "BINDTO specification `%s' invalid: value too large for port\n",
- bindto);
+ "BINDTO specification `%s' invalid: value too large for port\n",
+ bindto);
GNUNET_free (cp);
return NULL;
}
@@ -1894,8 +1901,8 @@ udp_address_to_sockaddr (const char *bindto,
else
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "BINDTO specification `%s' invalid: last ':' not followed by number\n",
- bindto);
+ "BINDTO specification `%s' invalid: last ':' not followed by number\n",
+ bindto);
GNUNET_free (cp);
return NULL;
}
@@ -1915,7 +1922,7 @@ udp_address_to_sockaddr (const char *bindto,
{
v4.sin_port = htons ((uint16_t) port);
in = GNUNET_memdup (&v4,
- sizeof (v4));
+ sizeof (v4));
*sock_len = sizeof (v4);
GNUNET_free (cp);
return in;
@@ -1934,12 +1941,12 @@ udp_address_to_sockaddr (const char *bindto,
cp[strlen (cp) -1] = '\0'; /* eat ']' */
}
if (1 == inet_pton (AF_INET6,
- start,
- &v6))
+ start,
+ &v6))
{
v6.sin6_port = htons ((uint16_t) port);
in = GNUNET_memdup (&v6,
- sizeof (v6));
+ sizeof (v6));
*sock_len = sizeof (v6);
GNUNET_free (cp);
return in;
@@ -1960,14 +1967,14 @@ udp_address_to_sockaddr (const char *bindto,
*/
static void
do_pad (gcry_cipher_hd_t out_cipher,
- char *dgram,
- size_t pad_size)
+ char *dgram,
+ size_t pad_size)
{
char pad[pad_size];
GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
- pad,
- sizeof (pad));
+ pad,
+ sizeof (pad));
if (sizeof (pad) > sizeof (struct GNUNET_MessageHeader))
{
struct GNUNET_MessageHeader hdr = {
@@ -1980,11 +1987,11 @@ do_pad (gcry_cipher_hd_t out_cipher,
sizeof (hdr));
}
GNUNET_assert (0 ==
- gcry_cipher_encrypt (out_cipher,
- dgram,
- sizeof (pad),
- pad,
- sizeof (pad)));
+ gcry_cipher_encrypt (out_cipher,
+ dgram,
+ sizeof (pad),
+ pad,
+ sizeof (pad)));
}
@@ -1998,8 +2005,8 @@ do_pad (gcry_cipher_hd_t out_cipher,
*/
static void
mq_send (struct GNUNET_MQ_Handle *mq,
- const struct GNUNET_MessageHeader *msg,
- void *impl_state)
+ const struct GNUNET_MessageHeader *msg,
+ void *impl_state)
{
struct ReceiverAddress *receiver = impl_state;
uint16_t msize = ntohs (msg->size);
@@ -2021,21 +2028,21 @@ mq_send (struct GNUNET_MQ_Handle *mq,
struct InitialKX kx;
struct GNUNET_CRYPTO_EcdhePrivateKey epriv;
char dgram[receiver->mtu +
- sizeof (uc) +
- sizeof (kx)];
+ sizeof (uc) +
+ sizeof (kx)];
size_t dpos;
gcry_cipher_hd_t out_cipher;
struct SharedSecret *ss;
/* setup key material */
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_ecdhe_key_create2 (&epriv));
+ GNUNET_CRYPTO_ecdhe_key_create2 (&epriv));
ss = setup_shared_secret_enc (&epriv,
- receiver);
+ receiver);
setup_cipher (&ss->master,
- 0,
- &out_cipher);
+ 0,
+ &out_cipher);
/* compute 'uc' */
uc.sender = my_identity;
uc.monotonic_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg));
@@ -2047,26 +2054,26 @@ mq_send (struct GNUNET_MQ_Handle *mq,
&uhs.ephemeral);
uhs.monotonic_time = uc.monotonic_time;
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_eddsa_sign (my_private_key,
- &uhs.purpose,
- &uc.sender_sig));
+ GNUNET_CRYPTO_eddsa_sign (my_private_key,
+ &uhs.purpose,
+ &uc.sender_sig));
/* Leave space for kx */
dpos = sizeof (struct GNUNET_CRYPTO_EcdhePublicKey);
/* Append encrypted uc to dgram */
GNUNET_assert (0 ==
- gcry_cipher_encrypt (out_cipher,
- &dgram[dpos],
- sizeof (uc),
- &uc,
- sizeof (uc)));
+ gcry_cipher_encrypt (out_cipher,
+ &dgram[dpos],
+ sizeof (uc),
+ &uc,
+ sizeof (uc)));
dpos += sizeof (uc);
/* Append encrypted payload to dgram */
GNUNET_assert (0 ==
- gcry_cipher_encrypt (out_cipher,
- &dgram[dpos],
- msize,
- msg,
- msize));
+ gcry_cipher_encrypt (out_cipher,
+ &dgram[dpos],
+ msize,
+ msg,
+ msize));
dpos += msize;
do_pad (out_cipher,
&dgram[dpos],
@@ -2074,21 +2081,21 @@ mq_send (struct GNUNET_MQ_Handle *mq,
/* Datagram starts with kx */
kx.ephemeral = uhs.ephemeral;
GNUNET_assert (0 ==
- gcry_cipher_gettag (out_cipher,
- kx.gcm_tag,
- sizeof (kx.gcm_tag)));
+ gcry_cipher_gettag (out_cipher,
+ kx.gcm_tag,
+ sizeof (kx.gcm_tag)));
gcry_cipher_close (out_cipher);
memcpy (dgram,
- &kx,
- sizeof (kx));
+ &kx,
+ sizeof (kx));
if (-1 ==
- GNUNET_NETWORK_socket_sendto (udp_sock,
- dgram,
- sizeof (dgram),
- receiver->address,
- receiver->address_len))
+ GNUNET_NETWORK_socket_sendto (udp_sock,
+ dgram,
+ sizeof (dgram),
+ receiver->address,
+ receiver->address_len))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "send");
+ "send");
GNUNET_MQ_impl_send_continue (mq);
return;
} /* End of KX encryption method */
@@ -2116,34 +2123,34 @@ mq_send (struct GNUNET_MQ_Handle *mq,
/* Append encrypted payload to dgram */
dpos = sizeof (struct UDPBox);
GNUNET_assert (0 ==
- gcry_cipher_encrypt (out_cipher,
- &dgram[dpos],
- msize,
- msg,
- msize));
+ gcry_cipher_encrypt (out_cipher,
+ &dgram[dpos],
+ msize,
+ msg,
+ msize));
dpos += msize;
do_pad (out_cipher,
- &dgram[dpos],
- sizeof (dgram) - dpos);
+ &dgram[dpos],
+ sizeof (dgram) - dpos);
GNUNET_assert (0 ==
- gcry_cipher_gettag (out_cipher,
- box->gcm_tag,
- sizeof (box->gcm_tag)));
+ gcry_cipher_gettag (out_cipher,
+ box->gcm_tag,
+ sizeof (box->gcm_tag)));
gcry_cipher_close (out_cipher);
if (-1 ==
- GNUNET_NETWORK_socket_sendto (udp_sock,
- dgram,
- sizeof (dgram),
- receiver->address,
- receiver->address_len))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "send");
+ GNUNET_NETWORK_socket_sendto (udp_sock,
+ dgram,
+ sizeof (dgram),
+ receiver->address,
+ receiver->address_len))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "send");
GNUNET_MQ_impl_send_continue (mq);
receiver->acks_available--;
if (0 == receiver->acks_available)
{
- /* We have no more ACKs => MTU change! */
- setup_receiver_mq (receiver);
+ /* We have no more ACKs => MTU change! */
+ setup_receiver_mq (receiver);
}
return;
}
@@ -2162,7 +2169,7 @@ mq_send (struct GNUNET_MQ_Handle *mq,
*/
static void
mq_destroy (struct GNUNET_MQ_Handle *mq,
- void *impl_state)
+ void *impl_state)
{
struct ReceiverAddress *receiver = impl_state;
@@ -2182,7 +2189,7 @@ mq_destroy (struct GNUNET_MQ_Handle *mq,
*/
static void
mq_cancel (struct GNUNET_MQ_Handle *mq,
- void *impl_state)
+ void *impl_state)
{
/* Cancellation is impossible with UDP; bail */
GNUNET_assert (0);
@@ -2200,14 +2207,14 @@ mq_cancel (struct GNUNET_MQ_Handle *mq,
*/
static void
mq_error (void *cls,
- enum GNUNET_MQ_Error error)
+ enum GNUNET_MQ_Error error)
{
struct ReceiverAddress *receiver = cls;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "MQ error in queue to %s: %d\n",
- GNUNET_i2s (&receiver->target),
- (int) error);
+ "MQ error in queue to %s: %d\n",
+ GNUNET_i2s (&receiver->target),
+ (int) error);
receiver_destroy (receiver);
}
@@ -2266,20 +2273,20 @@ setup_receiver_mq (struct ReceiverAddress *receiver)
1404 (IPv4 + Box) bytes, depending on circumstances... */
receiver->mq
= GNUNET_MQ_queue_for_callbacks (&mq_send,
- &mq_destroy,
- &mq_cancel,
- receiver,
- NULL,
- &mq_error,
- receiver);
+ &mq_destroy,
+ &mq_cancel,
+ receiver,
+ NULL,
+ &mq_error,
+ receiver);
receiver->qh
= GNUNET_TRANSPORT_communicator_mq_add (ch,
- &receiver->target,
- receiver->foreign_addr,
- receiver->mtu,
- receiver->nt,
- GNUNET_TRANSPORT_CS_OUTBOUND,
- receiver->mq);
+ &receiver->target,
+ receiver->foreign_addr,
+ receiver->mtu,
+ receiver->nt,
+ GNUNET_TRANSPORT_CS_OUTBOUND,
+ receiver->mq);
}
@@ -2287,7 +2294,10 @@ setup_receiver_mq (struct ReceiverAddress *receiver)
* Setup a receiver for transmission. Setup the MQ processing and
* inform transport that the queue is ready.
*
- * @param
+ * @param target which peer are we talking to
+ * @param address address of the peer
+ * @param address_len number of bytes in @a address
+ * @return handle for the address
*/
static struct ReceiverAddress *
receiver_setup (const struct GNUNET_PeerIdentity *target,
@@ -2323,7 +2333,7 @@ receiver_setup (const struct GNUNET_PeerIdentity *target,
if (NULL == timeout_task)
timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts,
- NULL);
+ NULL);
return receiver;
}
@@ -2347,8 +2357,8 @@ receiver_setup (const struct GNUNET_PeerIdentity *target,
*/
static int
mq_init (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const char *address)
+ const struct GNUNET_PeerIdentity *peer,
+ const char *address)
{
struct ReceiverAddress *receiver;
const char *path;
@@ -2356,18 +2366,18 @@ mq_init (void *cls,
socklen_t in_len;
if (0 != strncmp (address,
- COMMUNICATOR_ADDRESS_PREFIX "-",
- strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
+ COMMUNICATOR_ADDRESS_PREFIX "-",
+ strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
{
GNUNET_break_op (0);
return GNUNET_SYSERR;
}
path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
in = udp_address_to_sockaddr (path,
- &in_len);
+ &in_len);
receiver = receiver_setup (peer,
- in,
- in_len);
+ in,
+ in_len);
(void) receiver;
return GNUNET_OK;
}
@@ -2383,8 +2393,8 @@ mq_init (void *cls,
*/
static int
get_receiver_delete_it (void *cls,
- const struct GNUNET_PeerIdentity *target,
- void *value)
+ const struct GNUNET_PeerIdentity *target,
+ void *value)
{
struct ReceiverAddress *receiver = value;
@@ -2405,8 +2415,8 @@ get_receiver_delete_it (void *cls,
*/
static int
get_sender_delete_it (void *cls,
- const struct GNUNET_PeerIdentity *target,
- void *value)
+ const struct GNUNET_PeerIdentity *target,
+ void *value)
{
struct SenderAddress *sender = value;
@@ -2449,11 +2459,11 @@ do_shutdown (void *cls)
udp_sock = NULL;
}
GNUNET_CONTAINER_multipeermap_iterate (receivers,
- &get_receiver_delete_it,
+ &get_receiver_delete_it,
NULL);
GNUNET_CONTAINER_multipeermap_destroy (receivers);
GNUNET_CONTAINER_multipeermap_iterate (senders,
- &get_sender_delete_it,
+ &get_sender_delete_it,
NULL);
GNUNET_CONTAINER_multipeermap_destroy (senders);
GNUNET_CONTAINER_multishortmap_destroy (key_cache);
@@ -2472,7 +2482,7 @@ do_shutdown (void *cls)
if (NULL != stats)
{
GNUNET_STATISTICS_destroy (stats,
- GNUNET_NO);
+ GNUNET_NO);
stats = NULL;
}
if (NULL != my_private_key)
@@ -2482,8 +2492,8 @@ do_shutdown (void *cls)
}
if (NULL != is)
{
- GNUNET_NT_scanner_done (is);
- is = NULL;
+ GNUNET_NT_scanner_done (is);
+ is = NULL;
}
}
@@ -2513,9 +2523,9 @@ enc_notify_cb (void *cls,
}
ack = (const struct UDPAck *) msg;
GNUNET_CONTAINER_multipeermap_get_multiple (receivers,
- sender,
- &handle_ack,
- (void *) ack);
+ sender,
+ &handle_ack,
+ (void *) ack);
}
@@ -2534,11 +2544,11 @@ enc_notify_cb (void *cls,
*/
static void
nat_address_cb (void *cls,
- void **app_ctx,
- int add_remove,
- enum GNUNET_NAT_AddressClass ac,
- const struct sockaddr *addr,
- socklen_t addrlen)
+ void **app_ctx,
+ int add_remove,
+ enum GNUNET_NAT_AddressClass ac,
+ const struct sockaddr *addr,
+ socklen_t addrlen)
{
char *my_addr;
struct GNUNET_TRANSPORT_AddressIdentifier *ai;
@@ -2556,9 +2566,9 @@ nat_address_cb (void *cls,
addr,
addrlen);
ai = GNUNET_TRANSPORT_communicator_address_add (ch,
- my_addr,
- nt,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ my_addr,
+ nt,
+ GNUNET_TIME_UNIT_FOREVER_REL);
GNUNET_free (my_addr);
*app_ctx = ai;
}
@@ -2584,7 +2594,7 @@ ifc_broadcast (void *cls)
delay = BROADCAST_FREQUENCY;
delay.rel_value_us = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- delay.rel_value_us);
+ delay.rel_value_us);
bi->broadcast_task
= GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY,
&ifc_broadcast,
@@ -2598,29 +2608,29 @@ ifc_broadcast (void *cls)
ssize_t sent;
if (GNUNET_OK !=
- GNUNET_NETWORK_socket_setsockopt (udp_sock,
- SOL_SOCKET,
- SO_BROADCAST,
- &yes,
- sizeof (int)))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "setsockopt");
+ GNUNET_NETWORK_socket_setsockopt (udp_sock,
+ SOL_SOCKET,
+ SO_BROADCAST,
+ &yes,
+ sizeof (int)))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "setsockopt");
sent = GNUNET_NETWORK_socket_sendto (udp_sock,
- &bi->bcm,
- sizeof (bi->bcm),
- bi->ba,
- bi->salen);
+ &bi->bcm,
+ sizeof (bi->bcm),
+ bi->ba,
+ bi->salen);
if (-1 == sent)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "sendto");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "sendto");
if (GNUNET_OK !=
- GNUNET_NETWORK_socket_setsockopt (udp_sock,
- SOL_SOCKET,
- SO_BROADCAST,
- &no,
- sizeof (int)))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "setsockopt");
+ GNUNET_NETWORK_socket_setsockopt (udp_sock,
+ SOL_SOCKET,
+ SO_BROADCAST,
+ &no,
+ sizeof (int)))
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "setsockopt");
break;
}
case AF_INET6:
@@ -2634,14 +2644,14 @@ ifc_broadcast (void *cls)
dst.sin6_scope_id = ((struct sockaddr_in6*) bi->ba)->sin6_scope_id;
sent = GNUNET_NETWORK_socket_sendto (udp_sock,
- &bi->bcm,
- sizeof (bi->bcm),
- (const struct sockaddr *)
- &dst,
- sizeof (dst));
+ &bi->bcm,
+ sizeof (bi->bcm),
+ (const struct sockaddr *)
+ &dst,
+ sizeof (dst));
if (-1 == sent)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
- "sendto");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
+ "sendto");
break;
}
default:
@@ -2679,8 +2689,8 @@ iface_proc (void *cls,
(void) cls;
(void) netmask;
network = GNUNET_NT_scanner_get_type (is,
- addr,
- addrlen);
+ addr,
+ addrlen);
if (GNUNET_NT_LOOPBACK == network)
{
/* Broadcasting on loopback does not make sense */
@@ -2691,9 +2701,9 @@ iface_proc (void *cls,
for (bi = bi_head; NULL != bi; bi = bi->next)
{
if ( (bi->salen == addrlen) &&
- (0 == memcmp (addr,
- bi->sa,
- addrlen)) )
+ (0 == memcmp (addr,
+ bi->sa,
+ addrlen)) )
{
bi->found = GNUNET_YES;
return GNUNET_OK;
@@ -2709,10 +2719,10 @@ iface_proc (void *cls,
bi = GNUNET_new (struct BroadcastInterface);
bi->sa = GNUNET_memdup (addr,
- addrlen);
+ addrlen);
if (NULL != broadcast_addr)
bi->ba = GNUNET_memdup (broadcast_addr,
- addrlen);
+ addrlen);
bi->salen = addrlen;
bi->found = GNUNET_YES;
bi->bcm.sender = my_identity;
@@ -2720,17 +2730,17 @@ iface_proc (void *cls,
ubs.purpose.size = htonl (sizeof (ubs));
ubs.sender = my_identity;
GNUNET_CRYPTO_hash (addr,
- addrlen,
- &ubs.h_address);
+ addrlen,
+ &ubs.h_address);
GNUNET_assert (GNUNET_OK ==
- GNUNET_CRYPTO_eddsa_sign (my_private_key,
- &ubs.purpose,
- &bi->bcm.sender_sig));
+ GNUNET_CRYPTO_eddsa_sign (my_private_key,
+ &ubs.purpose,
+ &bi->bcm.sender_sig));
bi->broadcast_task = GNUNET_SCHEDULER_add_now (&ifc_broadcast,
- bi);
+ bi);
GNUNET_CONTAINER_DLL_insert (bi_head,
- bi_tail,
- bi);
+ bi_tail,
+ bi);
if ( (AF_INET6 == addr->sa_family) &&
(NULL != broadcast_addr) )
{
@@ -2740,7 +2750,7 @@ iface_proc (void *cls,
GNUNET_assert (1 ==
inet_pton (AF_INET6,
- "FF05::13B",
+ "FF05::13B",
&bi->mcreq.ipv6mr_multiaddr));
/* http://tools.ietf.org/html/rfc2553#section-5.2:
@@ -2760,10 +2770,10 @@ iface_proc (void *cls,
if (GNUNET_OK !=
GNUNET_NETWORK_socket_setsockopt
(udp_sock,
- IPPROTO_IPV6,
- IPV6_JOIN_GROUP,
+ IPPROTO_IPV6,
+ IPV6_JOIN_GROUP,
&bi->mcreq,
- sizeof (bi->mcreq)))
+ sizeof (bi->mcreq)))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
"setsockopt");
@@ -2789,7 +2799,7 @@ do_broadcast (void *cls)
bi = bi->next)
bi->found = GNUNET_NO;
GNUNET_OS_network_interfaces_list (&iface_proc,
- NULL);
+ NULL);
for (struct BroadcastInterface *bi = bi_head;
NULL != bi;
bi = bin)
@@ -2800,8 +2810,8 @@ do_broadcast (void *cls)
}
broadcast_task
= GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY,
- &do_broadcast,
- NULL);
+ &do_broadcast,
+ NULL);
}
@@ -2829,10 +2839,10 @@ run (void *cls,
cfg = c;
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg,
- COMMUNICATOR_CONFIG_SECTION,
- "BINDTO",
- &bindto))
- {
+ COMMUNICATOR_CONFIG_SECTION,
+ "BINDTO",
+ &bindto))
+ {
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
COMMUNICATOR_CONFIG_SECTION,
"BINDTO");
@@ -2996,7 +3006,7 @@ main (int argc,
if (GNUNET_OK !=
GNUNET_STRINGS_get_utf8_args (argc, argv,
- &argc, &argv))
+ &argc, &argv))
return 2;
ret =
diff --git a/src/transport/gnunet-communicator-unix.c b/src/transport/gnunet-communicator-unix.c
index d30acbd5f..642703f29 100644
--- a/src/transport/gnunet-communicator-unix.c
+++ b/src/transport/gnunet-communicator-unix.c
@@ -634,21 +634,21 @@ mq_error (void *cls,
*/
static struct Queue *
setup_queue (const struct GNUNET_PeerIdentity *target,
- enum GNUNET_TRANSPORT_ConnectionStatus cs,
- const struct sockaddr_un *un,
- socklen_t un_len)
+ enum GNUNET_TRANSPORT_ConnectionStatus cs,
+ const struct sockaddr_un *un,
+ socklen_t un_len)
{
struct Queue *queue;
queue = GNUNET_new (struct Queue);
queue->target = *target;
queue->address = GNUNET_memdup (un,
- un_len);
+ un_len);
queue->address_len = un_len;
(void) GNUNET_CONTAINER_multipeermap_put (queue_map,
- &queue->target,
- queue,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ &queue->target,
+ queue,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
GNUNET_STATISTICS_set (stats,
"# queues active",
GNUNET_CONTAINER_multipeermap_size (queue_map),
@@ -656,37 +656,37 @@ setup_queue (const struct GNUNET_PeerIdentity *target,
queue->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
queue->timeout_task
= GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
- &queue_timeout,
- queue);
+ &queue_timeout,
+ queue);
queue->mq
= GNUNET_MQ_queue_for_callbacks (&mq_send,
- &mq_destroy,
- &mq_cancel,
- queue,
- NULL,
- &mq_error,
- queue);
+ &mq_destroy,
+ &mq_cancel,
+ queue,
+ NULL,
+ &mq_error,
+ queue);
{
char *foreign_addr;
if ('\0' == un->sun_path[0])
GNUNET_asprintf (&foreign_addr,
- "%s-@%s",
- COMMUNICATOR_ADDRESS_PREFIX,
- &un->sun_path[1]);
+ "%s-@%s",
+ COMMUNICATOR_ADDRESS_PREFIX,
+ &un->sun_path[1]);
else
GNUNET_asprintf (&foreign_addr,
- "%s-%s",
- COMMUNICATOR_ADDRESS_PREFIX,
- un->sun_path);
+ "%s-%s",
+ COMMUNICATOR_ADDRESS_PREFIX,
+ un->sun_path);
queue->qh
= GNUNET_TRANSPORT_communicator_mq_add (ch,
- &queue->target,
- foreign_addr,
- UNIX_MTU,
- GNUNET_NT_LOOPBACK,
- cs,
- queue->mq);
+ &queue->target,
+ foreign_addr,
+ UNIX_MTU,
+ GNUNET_NT_LOOPBACK,
+ cs,
+ queue->mq);
GNUNET_free (foreign_addr);
}
return queue;
@@ -718,16 +718,16 @@ receive_complete_cb (void *cls,
delivering_messages--;
if (GNUNET_OK != success)
GNUNET_STATISTICS_update (stats,
- "# transport transmission failures",
- 1,
- GNUNET_NO);
+ "# transport transmission failures",
+ 1,
+ GNUNET_NO);
GNUNET_assert (NULL != unix_sock);
if ( (NULL == read_task) &&
(delivering_messages < max_queue_length) )
read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- unix_sock,
- &select_read_cb,
- NULL);
+ unix_sock,
+ &select_read_cb,
+ NULL);
}
@@ -751,16 +751,16 @@ select_read_cb (void *cls)
GNUNET_assert (NULL != unix_sock);
read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
- unix_sock,
- &select_read_cb,
- NULL);
+ unix_sock,
+ &select_read_cb,
+ NULL);
addrlen = sizeof (un);
memset (&un,
0,
sizeof (un));
ret = GNUNET_NETWORK_socket_recvfrom (unix_sock,
buf,
- sizeof (buf),
+ sizeof (buf),
(struct sockaddr *) &un,
&addrlen);
if ( (-1 == ret) &&
@@ -774,9 +774,9 @@ select_read_cb (void *cls)
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Read %d bytes from socket %s\n",
- (int) ret,
- un.sun_path);
+ "Read %d bytes from socket %s\n",
+ (int) ret,
+ un.sun_path);
GNUNET_assert (AF_UNIX == (un.sun_family));
msg = (struct UNIXMessage *) buf;
msize = ntohs (msg->header.size);
@@ -787,13 +787,13 @@ select_read_cb (void *cls)
return;
}
queue = lookup_queue (&msg->sender,
- &un,
- addrlen);
+ &un,
+ addrlen);
if (NULL == queue)
queue = setup_queue (&msg->sender,
- GNUNET_TRANSPORT_CS_INBOUND,
- &un,
- addrlen);
+ GNUNET_TRANSPORT_CS_INBOUND,
+ &un,
+ addrlen);
else
reschedule_queue_timeout (queue);
if (NULL == queue)
@@ -821,16 +821,17 @@ select_read_cb (void *cls)
sizeof (al_hdr));
csize = ntohs (al_hdr.size);
if ( (csize < sizeof (struct GNUNET_MessageHeader)) ||
- (csize > tsize - offset))
+ (csize > tsize - offset))
{
- GNUNET_break_op (0);
- break;
+ GNUNET_break_op (0);
+ break;
}
ret = GNUNET_TRANSPORT_communicator_receive (ch,
- &msg->sender,
- currhdr,
- &receive_complete_cb,
- NULL);
+ &msg->sender,
+ currhdr,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &receive_complete_cb,
+ NULL);
if (GNUNET_SYSERR == ret)
return; /* transport not up */
if (GNUNET_NO == ret)
@@ -898,16 +899,16 @@ mq_init (void *cls,
return GNUNET_OK;
}
queue = setup_queue (peer,
- GNUNET_TRANSPORT_CS_OUTBOUND,
- un,
- un_len);
+ GNUNET_TRANSPORT_CS_OUTBOUND,
+ un,
+ un_len);
GNUNET_free (un);
if (NULL == queue)
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Failed to setup queue to %s at `%s'\n",
- GNUNET_i2s (peer),
- path);
+ "Failed to setup queue to %s at `%s'\n",
+ GNUNET_i2s (peer),
+ path);
return GNUNET_NO;
}
return GNUNET_OK;
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index ecff6b6e1..342b4c2bc 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -33,14 +33,6 @@
* transport-to-transport traffic)
*
* Implement next:
- * - address validation: what is our plan here?
- * #1 Peerstore only gets 'validated' addresses
- * #2 transport should use validation to also establish
- * effective flow control (for uni-directional transports!)
- * #3 only validated addresses are selected for scheduling; that
- * also ensures we know the RTT
- * #4 to ensure flow control and RTT are OK, we always do the
- * 'validation', even if address comes from PEERSTORE???
* - ACK handling / retransmission
* - track RTT, distance, loss, etc.
* - DV data structures:
@@ -67,7 +59,7 @@
* Design realizations / discussion:
* - communicators do flow control by calling MQ "notify sent"
* when 'ready'. They determine flow implicitly (i.e. TCP blocking)
- * or explicitly via background channel FC ACKs. As long as the
+ * or explicitly via backchannel FC ACKs. As long as the
* channel is not full, they may 'notify sent' even if the other
* peer has not yet confirmed receipt. The other peer confirming
* is _only_ for FC, not for more reliable transmission; reliable
@@ -1236,7 +1228,6 @@ enum PendingMessageType
*/
PMT_ACKNOWLEDGEMENT = 3
-
};
@@ -1658,11 +1649,6 @@ struct ValidationState
struct GNUNET_PEERSTORE_StoreContext *sc;
/**
- * Network type (presumably) associated with @e address. NEEDED?
- */
- enum GNUNET_NetworkType nt;
-
- /**
* We are technically ready to send the challenge, but we are waiting for
* the respective queue to become available for transmission.
*/
@@ -1671,8 +1657,6 @@ struct ValidationState
};
-
-
/**
* Head of linked list of all clients to this service.
*/
@@ -2133,7 +2117,7 @@ core_send_connect_info (struct TransportClient *tc,
cim->quota_out = quota_out;
cim->id = *pid;
GNUNET_MQ_send (tc->mq,
- env);
+ env);
}
@@ -2967,6 +2951,15 @@ static void
route_message (const struct GNUNET_PeerIdentity *target,
struct GNUNET_MessageHeader *hdr)
{
+ // FIXME: this one is tricky:
+ // - we could try a direct, reliable channel
+ // - if that is unavailable / for load balancing, we may try:
+ // * multiple (?) direct unreliable channels - depending on loss rate?
+ // * some (?) DV channels - if above unavailable / too lossy?
+ // * _random_ other peers ("broadcasting") in hope of *discovering*
+ // a path back! - if all else fails
+ // => need more on DV first!
+
// FIXME: send hdr to target, free hdr (possibly using DV, possibly broadcasting)
GNUNET_free (hdr);
}
@@ -3096,20 +3089,29 @@ static void
store_pi (void *cls)
{
struct AddressListEntry *ale = cls;
+ void *addr;
+ size_t addr_len;
struct GNUNET_TIME_Absolute expiration;
ale->st = NULL;
expiration = GNUNET_TIME_relative_to_absolute (ale->expiration);
+ GNUNET_HELLO_sign_address (ale->address,
+ ale->nt,
+ expiration,
+ GST_my_private_key,
+ &addr,
+ &addr_len);
ale->sc = GNUNET_PEERSTORE_store (peerstore,
"transport",
&GST_my_identity,
- GNUNET_HELLO_PEERSTORE_KEY,
- ale->address,
- strlen (ale->address) + 1,
+ GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY,
+ addr,
+ addr_len,
expiration,
GNUNET_PEERSTORE_STOREOPTION_MULTIPLE,
&peerstore_store_own_cb,
ale);
+ GNUNET_free (addr);
if (NULL == ale->sc)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -3359,7 +3361,7 @@ send_fragment_ack (struct ReassemblyContext *rc)
ack->reassembly_timeout
= GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout));
route_message (&rc->neighbour->pid,
- &ack->header);
+ &ack->header);
rc->avg_ack_delay = GNUNET_TIME_UNIT_ZERO;
rc->num_acks = 0;
rc->extra_acks = 0LLU;
@@ -3425,10 +3427,10 @@ handle_fragment_box (void *cls,
rc,
rc->reassembly_timeout.abs_value_us);
GNUNET_assert (GNUNET_OK ==
- GNUNET_CONTAINER_multishortmap_put (n->reassembly_map,
- &rc->msg_uuid,
- rc,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ GNUNET_CONTAINER_multishortmap_put (n->reassembly_map,
+ &rc->msg_uuid,
+ rc,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
target = (char *) &rc[1];
rc->bitfield = (uint8_t *) (target + rc->msg_size);
rc->msg_missing = rc->msg_size;
@@ -3601,14 +3603,14 @@ handle_reliability_box (void *cls,
ack->header.size = htons (sizeof (*ack) +
sizeof (struct GNUNET_ShortHashCode));
memcpy (&ack[1],
- &rb->msg_uuid,
- sizeof (struct GNUNET_ShortHashCode));
+ &rb->msg_uuid,
+ sizeof (struct GNUNET_ShortHashCode));
route_message (&cmc->im.sender,
- &ack->header);
+ &ack->header);
}
/* continue with inner message */
demultiplex_with_cmc (cmc,
- inbox);
+ inbox);
}
@@ -3846,8 +3848,37 @@ handle_validation_challenge (void *cls,
const struct TransportValidationChallenge *tvc)
{
struct CommunicatorMessageContext *cmc = cls;
+ struct TransportValidationResponse *tvr;
+
+ if (cmc->total_hops > 0)
+ {
+ /* DV routing is not allowed for validation challenges! */
+ GNUNET_break_op (0);
+ finish_cmc_handling (cmc);
+ return;
+ }
+ tvr = GNUNET_new (struct TransportValidationResponse);
+ tvr->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE);
+ tvr->header.size = htons (sizeof (*tvr));
+ tvr->challenge = tvc->challenge;
+ tvr->origin_time = tvc->sender_time;
+ tvr->validity_duration = cmc->im.expected_address_validity;
+ {
+ /* create signature */
+ struct TransportValidationPS tvp = {
+ .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE),
+ .purpose.size = htonl (sizeof (tvp)),
+ .validity_duration = tvr->validity_duration,
+ .challenge = tvc->challenge
+ };
- // FIXME: sign challenge and try to get it back to the origin!
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_eddsa_sign (GST_my_private_key,
+ &tvp.purpose,
+ &tvr->signature));
+ }
+ route_message (&cmc->im.sender,
+ &tvr->header);
finish_cmc_handling (cmc);
}
@@ -4054,15 +4085,14 @@ handle_validation_response (void *cls,
vs->sc = GNUNET_PEERSTORE_store (peerstore,
"transport",
&cmc->im.sender,
- GNUNET_HELLO_PEERSTORE_KEY,
+ GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY,
vs->address,
strlen (vs->address) + 1,
vs->valid_until,
GNUNET_PEERSTORE_STOREOPTION_MULTIPLE,
&peerstore_store_validation_cb,
vs);
- // FIXME: now that we know that the address is *valid*,
- // do we need to trigger _using_ it for something?
+ // FIXME: should we find the matching queue and update the RTT?
finish_cmc_handling (cmc);
}
@@ -5183,97 +5213,6 @@ handle_queue_create_fail (void *cls,
/**
- * Function called by PEERSTORE for each matching record.
- *
- * @param cls closure
- * @param record peerstore record information
- * @param emsg error message, or NULL if no errors
- */
-static void
-handle_hello (void *cls,
- const struct GNUNET_PEERSTORE_Record *record,
- const char *emsg)
-{
- struct PeerRequest *pr = cls;
- const char *val;
-
- if (NULL != emsg)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Got failure from PEERSTORE: %s\n",
- emsg);
- return;
- }
- val = record->value;
- if ( (0 == record->value_size) ||
- ('\0' != val[record->value_size - 1]) )
- {
- GNUNET_break (0);
- return;
- }
- suggest_to_connect (&pr->pid,
- (const char *) record->value);
-}
-
-
-/**
- * We have received a `struct ExpressPreferenceMessage` from an application client.
- *
- * @param cls handle to the client
- * @param msg the start message
- */
-static void
-handle_suggest (void *cls,
- const struct ExpressPreferenceMessage *msg)
-{
- struct TransportClient *tc = cls;
- struct PeerRequest *pr;
-
- if (CT_NONE == tc->type)
- {
- tc->type = CT_APPLICATION;
- tc->details.application.requests
- = GNUNET_CONTAINER_multipeermap_create (16,
- GNUNET_YES);
- }
- if (CT_APPLICATION != tc->type)
- {
- GNUNET_break (0);
- GNUNET_SERVICE_client_drop (tc->client);
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Client suggested we talk to %s with preference %d at rate %u\n",
- GNUNET_i2s (&msg->peer),
- (int) ntohl (msg->pk),
- (int) ntohl (msg->bw.value__));
- pr = GNUNET_new (struct PeerRequest);
- pr->tc = tc;
- pr->pid = msg->peer;
- pr->bw = msg->bw;
- pr->pk = (enum GNUNET_MQ_PreferenceKind) ntohl (msg->pk);
- if (GNUNET_YES !=
- GNUNET_CONTAINER_multipeermap_put (tc->details.application.requests,
- &pr->pid,
- pr,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
- {
- GNUNET_break (0);
- GNUNET_free (pr);
- GNUNET_SERVICE_client_drop (tc->client);
- return;
- }
- pr->wc = GNUNET_PEERSTORE_watch (peerstore,
- "transport",
- &pr->pid,
- GNUNET_HELLO_PEERSTORE_KEY,
- &handle_hello,
- pr);
- GNUNET_SERVICE_client_continue (tc->client);
-}
-
-
-/**
* We have received a `struct ExpressPreferenceMessage` from an application client.
*
* @param cls handle to the client
@@ -5374,13 +5313,11 @@ check_known_address (void *cls,
* @param pid peer the @a address is for
* @param address an address to reach @a pid (presumably)
* @param expiration when did @a pid claim @a address will become invalid
- * @param nt network type of @a address
*/
static void
start_address_validation (const struct GNUNET_PeerIdentity *pid,
const char *address,
- struct GNUNET_TIME_Absolute expiration,
- enum GNUNET_NetworkType nt)
+ struct GNUNET_TIME_Absolute expiration)
{
struct GNUNET_TIME_Absolute now;
struct ValidationState *vs;
@@ -5389,10 +5326,8 @@ start_address_validation (const struct GNUNET_PeerIdentity *pid,
.vs = NULL
};
-
if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
return; /* expired */
-
(void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map,
pid,
&check_known_address,
@@ -5421,7 +5356,6 @@ start_address_validation (const struct GNUNET_PeerIdentity *pid,
&vs->challenge,
sizeof (vs->challenge));
vs->address = GNUNET_strdup (address);
- vs->nt = nt;
GNUNET_assert (GNUNET_YES ==
GNUNET_CONTAINER_multipeermap_put (validation_map,
&vs->pid,
@@ -5433,6 +5367,98 @@ start_address_validation (const struct GNUNET_PeerIdentity *pid,
/**
+ * Function called by PEERSTORE for each matching record.
+ *
+ * @param cls closure
+ * @param record peerstore record information
+ * @param emsg error message, or NULL if no errors
+ */
+static void
+handle_hello (void *cls,
+ const struct GNUNET_PEERSTORE_Record *record,
+ const char *emsg)
+{
+ struct PeerRequest *pr = cls;
+ const char *val;
+
+ if (NULL != emsg)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Got failure from PEERSTORE: %s\n",
+ emsg);
+ return;
+ }
+ val = record->value;
+ if ( (0 == record->value_size) ||
+ ('\0' != val[record->value_size - 1]) )
+ {
+ GNUNET_break (0);
+ return;
+ }
+ start_address_validation (&pr->pid,
+ (const char *) record->value,
+ record->expiry);
+}
+
+
+/**
+ * We have received a `struct ExpressPreferenceMessage` from an application client.
+ *
+ * @param cls handle to the client
+ * @param msg the start message
+ */
+static void
+handle_suggest (void *cls,
+ const struct ExpressPreferenceMessage *msg)
+{
+ struct TransportClient *tc = cls;
+ struct PeerRequest *pr;
+
+ if (CT_NONE == tc->type)
+ {
+ tc->type = CT_APPLICATION;
+ tc->details.application.requests
+ = GNUNET_CONTAINER_multipeermap_create (16,
+ GNUNET_YES);
+ }
+ if (CT_APPLICATION != tc->type)
+ {
+ GNUNET_break (0);
+ GNUNET_SERVICE_client_drop (tc->client);
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client suggested we talk to %s with preference %d at rate %u\n",
+ GNUNET_i2s (&msg->peer),
+ (int) ntohl (msg->pk),
+ (int) ntohl (msg->bw.value__));
+ pr = GNUNET_new (struct PeerRequest);
+ pr->tc = tc;
+ pr->pid = msg->peer;
+ pr->bw = msg->bw;
+ pr->pk = (enum GNUNET_MQ_PreferenceKind) ntohl (msg->pk);
+ if (GNUNET_YES !=
+ GNUNET_CONTAINER_multipeermap_put (tc->details.application.requests,
+ &pr->pid,
+ pr,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+ {
+ GNUNET_break (0);
+ GNUNET_free (pr);
+ GNUNET_SERVICE_client_drop (tc->client);
+ return;
+ }
+ pr->wc = GNUNET_PEERSTORE_watch (peerstore,
+ "transport",
+ &pr->pid,
+ GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY,
+ &handle_hello,
+ pr);
+ GNUNET_SERVICE_client_continue (tc->client);
+}
+
+
+/**
* Given another peers address, consider checking it for validity
* and then adding it to the Peerstore.
*
@@ -5465,8 +5491,7 @@ handle_address_consider_verify (void *cls,
}
start_address_validation (&hdr->peer,
address,
- expiration,
- nt);
+ expiration);
GNUNET_free (address);
GNUNET_SERVICE_client_continue (tc->client);
}
@@ -5504,8 +5529,7 @@ handle_request_hello_validation (void *cls,
start_address_validation (&m->peer,
(const char *) &m[1],
- GNUNET_TIME_absolute_ntoh (m->expiration),
- (enum GNUNET_NetworkType) ntohl (m->nt));
+ GNUNET_TIME_absolute_ntoh (m->expiration));
GNUNET_SERVICE_client_continue (tc->client);
}
diff --git a/src/transport/transport.h b/src/transport/transport.h
index 7e0d9c2d4..b9c61f306 100644
--- a/src/transport/transport.h
+++ b/src/transport/transport.h
@@ -743,6 +743,12 @@ struct GNUNET_TRANSPORT_IncomingMessage
uint64_t fc_id GNUNET_PACKED;
/**
+ * How long does the communicator believe the address on which
+ * the message was received to remain valid?
+ */
+ struct GNUNET_TIME_RelativeNBO expected_address_validity;
+
+ /**
* Sender identifier.
*/
struct GNUNET_PeerIdentity sender;
diff --git a/src/transport/transport_api2_communication.c b/src/transport/transport_api2_communication.c
index 33092fb2a..6d497c967 100644
--- a/src/transport/transport_api2_communication.c
+++ b/src/transport/transport_api2_communication.c
@@ -906,6 +906,9 @@ GNUNET_TRANSPORT_communicator_disconnect (struct GNUNET_TRANSPORT_CommunicatorHa
* @param sender presumed sender of the message (details to be checked
* by higher layers)
* @param msg the message
+ * @param expected_addr_validity how long does the communicator believe it
+ * will continue to be able to receive messages from the same address
+ * on which it received this message?
* @param cb function to call once handling the message is done, NULL if
* flow control is not supported by this communicator
* @param cb_cls closure for @a cb
@@ -919,6 +922,7 @@ int
GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
const struct GNUNET_PeerIdentity *sender,
const struct GNUNET_MessageHeader *msg,
+ struct GNUNET_TIME_Relative expected_addr_validity,
GNUNET_TRANSPORT_MessageCompletedCallback cb,
void *cb_cls)
{
@@ -932,24 +936,25 @@ GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandl
(GNUNET_MQ_get_length (ch->mq) >= ch->max_queue_length) )
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- "Dropping message: transprot is too slow, queue length %llu exceeded\n",
- ch->max_queue_length);
+ "Dropping message: transprot is too slow, queue length %llu exceeded\n",
+ ch->max_queue_length);
return GNUNET_NO;
}
msize = ntohs (msg->size);
env = GNUNET_MQ_msg_extra (im,
- msize,
- GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG);
+ msize,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG);
if (NULL == env)
{
GNUNET_break (0);
return GNUNET_SYSERR;
}
+ im->expected_address_validity = GNUNET_TIME_relative_hton (expected_addr_validity);
im->sender = *sender;
memcpy (&im[1],
- msg,
- msize);
+ msg,
+ msize);
if (NULL != cb)
{
struct FlowControl *fc;
@@ -962,11 +967,11 @@ GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandl
fc->cb = cb;
fc->cb_cls = cb_cls;
GNUNET_CONTAINER_DLL_insert (ch->fc_head,
- ch->fc_tail,
- fc);
+ ch->fc_tail,
+ fc);
}
GNUNET_MQ_send (ch->mq,
- env);
+ env);
return GNUNET_OK;
}