return;
}
if (0 != strcmp (record->key,
- GNUNET_HELLO_PEERSTORE_KEY))
+ GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY))
{
GNUNET_break (0);
return;
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 ==
/* 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.
#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
*/
*/
typedef void
(*GNUNET_TRANSPORT_CommunicatorNotify) (void *cls,
- const struct GNUNET_PeerIdentity *sender,
+ const struct GNUNET_PeerIdentity *sender,
const struct GNUNET_MessageHeader *msg);
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);
/**
* @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
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);
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);
*/
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 */
#include "gnunet_statistics_service.h"
#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,
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;
&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);
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);
}
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);
}
*/
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) &&
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);
}
*/
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;
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);
}
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));
}
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);
}
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);
gcry_cipher_close (queue->in_cipher);
queue->rekeyed = GNUNET_YES;
setup_in_cipher (&rekey->ephemeral,
- 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:
sizeof (rekeyz),
&tmac);
if (0 != memcmp (&tmac,
- &fin->hmac,
- sizeof (tmac)))
+ &fin->hmac,
+ sizeof (tmac)))
{
GNUNET_break_op (0);
queue_finish (queue);
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)
(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) &&
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;
}
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;
}
/* 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);
}
*/
static struct sockaddr *
tcp_address_to_sockaddr (const char *bindto,
- socklen_t *sock_len)
+ socklen_t *sock_len)
{
struct sockaddr *in;
unsigned int port;
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;
*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;
}
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;
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;
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);
}
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));
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;
}
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;
}
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
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
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);
}
*/
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);
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)
GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
queue->sock,
&queue_write,
- queue);
+ queue);
}
*/
static void
mq_destroy (struct GNUNET_MQ_Handle *mq,
- void *impl_state)
+ void *impl_state)
{
struct Queue *queue = impl_state;
*/
static void
mq_cancel (struct GNUNET_MQ_Handle *mq,
- void *impl_state)
+ void *impl_state)
{
struct Queue *queue = impl_state;
*/
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);
}
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;
{
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);
}
}
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;
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);
}
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);
}
*/
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;
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);
}
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);
}
*/
#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.
*/
&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);
}
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);
}
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);
}
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);
}
*/
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;
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))
hdr = plaintext + ntohs (hdr->size);
}
GNUNET_STATISTICS_update (stats,
- "# bytes padding discarded",
- plaintext_len,
- GNUNET_NO);
+ "# bytes padding discarded",
+ plaintext_len,
+ GNUNET_NO);
}
*/
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));
}
*/
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);
ss = GNUNET_new (struct SharedSecret);
GNUNET_CRYPTO_eddsa_ecdh (my_private_key,
- ephemeral,
- &ss->master);
+ ephemeral,
+ &ss->master);
return ss;
}
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;
}
*/
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;
ss = ss->next)
{
if (0 == memcmp (&ack->cmac,
- &ss->cmac,
- sizeof (struct GNUNET_HashCode)))
+ &ss->cmac,
+ sizeof (struct GNUNET_HashCode)))
{
uint32_t allowed;
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;
}
*/
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;
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);
}
}
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);
*/
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)];
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",
}
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);
}
*/
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! */
*/
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 = {
};
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);
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;
}
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,
}
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);
}
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);
*/
static struct sockaddr *
udp_address_to_sockaddr (const char *bindto,
- socklen_t *sock_len)
+ socklen_t *sock_len)
{
struct sockaddr *in;
unsigned int port;
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;
*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;
}
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;
}
{
v4.sin_port = htons ((uint16_t) port);
in = GNUNET_memdup (&v4,
- sizeof (v4));
+ sizeof (v4));
*sock_len = sizeof (v4);
GNUNET_free (cp);
return in;
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;
*/
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 = {
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)));
}
*/
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);
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));
&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],
/* 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 */
/* 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;
}
*/
static void
mq_destroy (struct GNUNET_MQ_Handle *mq,
- void *impl_state)
+ void *impl_state)
{
struct ReceiverAddress *receiver = impl_state;
*/
static void
mq_cancel (struct GNUNET_MQ_Handle *mq,
- void *impl_state)
+ void *impl_state)
{
/* Cancellation is impossible with UDP; bail */
GNUNET_assert (0);
*/
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);
}
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);
}
* 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,
if (NULL == timeout_task)
timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts,
- NULL);
+ NULL);
return receiver;
}
*/
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;
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;
}
*/
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;
*/
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;
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);
if (NULL != stats)
{
GNUNET_STATISTICS_destroy (stats,
- GNUNET_NO);
+ GNUNET_NO);
stats = NULL;
}
if (NULL != my_private_key)
}
if (NULL != is)
{
- GNUNET_NT_scanner_done (is);
- is = NULL;
+ GNUNET_NT_scanner_done (is);
+ is = NULL;
}
}
}
ack = (const struct UDPAck *) msg;
GNUNET_CONTAINER_multipeermap_get_multiple (receivers,
- sender,
- &handle_ack,
- (void *) ack);
+ sender,
+ &handle_ack,
+ (void *) ack);
}
*/
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;
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;
}
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,
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:
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:
(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 */
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;
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;
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) )
{
GNUNET_assert (1 ==
inet_pton (AF_INET6,
- "FF05::13B",
+ "FF05::13B",
&bi->mcreq.ipv6mr_multiaddr));
/* http://tools.ietf.org/html/rfc2553#section-5.2:
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");
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)
}
broadcast_task
= GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY,
- &do_broadcast,
- NULL);
+ &do_broadcast,
+ NULL);
}
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");
if (GNUNET_OK !=
GNUNET_STRINGS_get_utf8_args (argc, argv,
- &argc, &argv))
+ &argc, &argv))
return 2;
ret =
*/
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),
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;
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);
}
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) &&
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);
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)
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)
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;
* 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:
* 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
*/
PMT_ACKNOWLEDGEMENT = 3
-
};
*/
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.
};
-
-
/**
* Head of linked list of all clients to this service.
*/
cim->quota_out = quota_out;
cim->id = *pid;
GNUNET_MQ_send (tc->mq,
- env);
+ env);
}
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);
}
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,
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;
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;
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);
}
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);
}
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);
}
}
-/**
- * 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 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;
.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,
&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,
}
+/**
+ * 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.
}
start_address_validation (&hdr->peer,
address,
- expiration,
- nt);
+ expiration);
GNUNET_free (address);
GNUNET_SERVICE_client_continue (tc->client);
}
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);
}
*/
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.
*/
* @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
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)
{
(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;
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;
}