summaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/communicator.h6
-rw-r--r--src/transport/gnunet-communicator-tcp.c1798
-rw-r--r--src/transport/gnunet-communicator-udp.c2214
-rw-r--r--src/transport/gnunet-communicator-unix.c911
-rw-r--r--src/transport/gnunet-helper-transport-bluetooth.c2585
-rw-r--r--src/transport/gnunet-helper-transport-wlan-dummy.c565
-rw-r--r--src/transport/gnunet-helper-transport-wlan.c1514
-rw-r--r--src/transport/gnunet-service-tng.c7587
-rw-r--r--src/transport/gnunet-service-transport.c2336
-rw-r--r--src/transport/gnunet-service-transport.h64
-rw-r--r--src/transport/gnunet-service-transport_ats.c750
-rw-r--r--src/transport/gnunet-service-transport_ats.h52
-rw-r--r--src/transport/gnunet-service-transport_hello.c205
-rw-r--r--src/transport/gnunet-service-transport_hello.h20
-rw-r--r--src/transport/gnunet-service-transport_manipulation.c478
-rw-r--r--src/transport/gnunet-service-transport_manipulation.h34
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c4423
-rw-r--r--src/transport/gnunet-service-transport_neighbours.h89
-rw-r--r--src/transport/gnunet-service-transport_plugins.c447
-rw-r--r--src/transport/gnunet-service-transport_plugins.h20
-rw-r--r--src/transport/gnunet-service-transport_validation.c1721
-rw-r--r--src/transport/gnunet-service-transport_validation.h28
-rw-r--r--src/transport/gnunet-transport-profiler.c529
-rw-r--r--src/transport/gnunet-transport-wlan-receiver.c120
-rw-r--r--src/transport/gnunet-transport-wlan-sender.c256
-rw-r--r--src/transport/gnunet-transport.c1202
-rw-r--r--src/transport/ieee80211_radiotap.h14
-rw-r--r--src/transport/plugin_transport_http.h96
-rw-r--r--src/transport/plugin_transport_http_client.c2473
-rw-r--r--src/transport/plugin_transport_http_common.c968
-rw-r--r--src/transport/plugin_transport_http_common.h96
-rw-r--r--src/transport/plugin_transport_http_server.c3550
-rw-r--r--src/transport/plugin_transport_smtp.c638
-rw-r--r--src/transport/plugin_transport_tcp.c3540
-rw-r--r--src/transport/plugin_transport_template.c183
-rw-r--r--src/transport/plugin_transport_udp.c3821
-rw-r--r--src/transport/plugin_transport_udp.h40
-rw-r--r--src/transport/plugin_transport_udp_broadcasting.c624
-rw-r--r--src/transport/plugin_transport_unix.c1566
-rw-r--r--src/transport/plugin_transport_wlan.c2059
-rw-r--r--src/transport/plugin_transport_wlan.h18
-rw-r--r--src/transport/tcp_connection_legacy.c1304
-rw-r--r--src/transport/tcp_server_legacy.c1256
-rw-r--r--src/transport/tcp_server_mst_legacy.c323
-rw-r--r--src/transport/tcp_service_legacy.c1639
-rw-r--r--src/transport/test_communicator_unix.c228
-rw-r--r--src/transport/test_http_common.c293
-rw-r--r--src/transport/test_plugin_transport.c826
-rw-r--r--src/transport/test_quota_compliance.c316
-rw-r--r--src/transport/test_transport_address_switch.c354
-rw-r--r--src/transport/test_transport_api.c75
-rw-r--r--src/transport/test_transport_api_blacklisting.c165
-rw-r--r--src/transport/test_transport_api_disconnect.c91
-rw-r--r--src/transport/test_transport_api_limited_sockets.c70
-rw-r--r--src/transport/test_transport_api_manipulation_cfg.c172
-rw-r--r--src/transport/test_transport_api_manipulation_recv_tcp.c171
-rw-r--r--src/transport/test_transport_api_manipulation_send_tcp.c169
-rw-r--r--src/transport/test_transport_api_monitor_peers.c191
-rw-r--r--src/transport/test_transport_api_reliability.c209
-rw-r--r--src/transport/test_transport_api_restart_reconnect.c169
-rw-r--r--src/transport/test_transport_api_timeout.c122
-rw-r--r--src/transport/test_transport_blacklisting.c737
-rw-r--r--src/transport/test_transport_testing_restart.c138
-rw-r--r--src/transport/test_transport_testing_startstop.c106
-rw-r--r--src/transport/transport-testing-filenames.c98
-rw-r--r--src/transport/transport-testing-loggers.c45
-rw-r--r--src/transport/transport-testing-main.c445
-rw-r--r--src/transport/transport-testing-send.c191
-rw-r--r--src/transport/transport-testing.c1027
-rw-r--r--src/transport/transport-testing.h78
-rw-r--r--src/transport/transport-testing2.c445
-rw-r--r--src/transport/transport-testing2.h62
-rw-r--r--src/transport/transport.h113
-rw-r--r--src/transport/transport_api2_application.c184
-rw-r--r--src/transport/transport_api2_communication.c455
-rw-r--r--src/transport/transport_api2_core.c484
-rw-r--r--src/transport/transport_api2_monitor.c127
-rw-r--r--src/transport/transport_api_address_to_string.c211
-rw-r--r--src/transport/transport_api_blacklist.c85
-rw-r--r--src/transport/transport_api_core.c600
-rw-r--r--src/transport/transport_api_hello_get.c137
-rw-r--r--src/transport/transport_api_manipulation.c131
-rw-r--r--src/transport/transport_api_monitor_peers.c362
-rw-r--r--src/transport/transport_api_monitor_plugins.c285
-rw-r--r--src/transport/transport_api_offer_hello.c72
85 files changed, 32597 insertions, 31804 deletions
diff --git a/src/transport/communicator.h b/src/transport/communicator.h
index 04a9857e5..ab7a25de6 100644
--- a/src/transport/communicator.h
+++ b/src/transport/communicator.h
@@ -41,7 +41,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
* just the recommended "generic" style, communicators are always free
* to implement original designs that better fit their requirements.
*/
-struct GNUNET_TRANSPORT_CommunicatorGenericKXConfirmation {
+struct GNUNET_TRANSPORT_CommunicatorGenericKXConfirmation
+{
/**
* Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_KX_CONFIRMATION
*/
@@ -88,7 +89,8 @@ struct GNUNET_TRANSPORT_CommunicatorGenericKXConfirmation {
* free to implement original designs that better fit their
* requirements.
*/
-struct GNUNET_TRANSPORT_CommunicatorGenericFCLimits {
+struct GNUNET_TRANSPORT_CommunicatorGenericFCLimits
+{
/**
* Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_FC_LIMITS
*/
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c
index a8d692940..f3ccbd262 100644
--- a/src/transport/gnunet-communicator-tcp.c
+++ b/src/transport/gnunet-communicator-tcp.c
@@ -47,7 +47,7 @@
* the other peer should revalidate).
*/
#define ADDRESS_VALIDITY_PERIOD \
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4)
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
/**
* How many messages do we keep at most in the queue to the
@@ -86,8 +86,8 @@
* directions.
*/
#define INITIAL_KX_SIZE \
- (sizeof(struct GNUNET_CRYPTO_EcdhePublicKey) + \
- sizeof(struct TCPConfirmation))
+ (sizeof(struct GNUNET_CRYPTO_EcdhePublicKey) \
+ + sizeof(struct TCPConfirmation))
/**
@@ -107,7 +107,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
* Signature we use to verify that the ephemeral key was really chosen by
* the specified sender.
*/
-struct TcpHandshakeSignature {
+struct TcpHandshakeSignature
+{
/**
* Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE
*/
@@ -139,7 +140,8 @@ struct TcpHandshakeSignature {
/**
* Encrypted continuation of TCP initial handshake.
*/
-struct TCPConfirmation {
+struct TCPConfirmation
+{
/**
* Sender's identity
*/
@@ -161,7 +163,8 @@ struct TCPConfirmation {
/**
* TCP message box. Always sent encrypted!
*/
-struct TCPBox {
+struct TCPBox
+{
/**
* Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX. Warning: the
* header size EXCLUDES the size of the `struct TCPBox`. We usually
@@ -189,7 +192,8 @@ struct TCPBox {
* TCP rekey message box. Always sent encrypted! Data after
* this message will use the new key.
*/
-struct TCPRekey {
+struct TCPRekey
+{
/**
* Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY.
*/
@@ -228,7 +232,8 @@ struct TCPRekey {
* Needed/useful in case we drop RST/FIN packets on the GNUnet
* port due to the possibility of malicious RST/FIN injection.
*/
-struct TCPFinish {
+struct TCPFinish
+{
/**
* Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH.
*/
@@ -252,7 +257,8 @@ GNUNET_NETWORK_STRUCT_END
/**
* Handle for a queue.
*/
-struct Queue {
+struct Queue
+{
/**
* To whom are we talking to.
*/
@@ -430,7 +436,8 @@ struct Queue {
* Handle for an incoming connection where we do not yet have enough
* information to setup a full queue.
*/
-struct ProtoQueue {
+struct ProtoQueue
+{
/**
* Kept in a DLL.
*/
@@ -553,7 +560,7 @@ static struct ProtoQueue *proto_tail;
* @param cls NULL
*/
static void
-listen_cb(void *cls);
+listen_cb (void *cls);
/**
@@ -564,53 +571,53 @@ listen_cb(void *cls);
* @param queue queue to close down
*/
static void
-queue_destroy(struct Queue *queue)
+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));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Disconnecting queue for peer `%s'\n",
+ GNUNET_i2s (&queue->target));
if (NULL != (mq = queue->mq))
- {
- queue->mq = NULL;
- GNUNET_MQ_destroy(mq);
- }
+ {
+ queue->mq = NULL;
+ GNUNET_MQ_destroy (mq);
+ }
if (NULL != queue->qh)
- {
- GNUNET_TRANSPORT_communicator_mq_del(queue->qh);
- queue->qh = NULL;
- }
- GNUNET_assert(
+ {
+ GNUNET_TRANSPORT_communicator_mq_del (queue->qh);
+ queue->qh = NULL;
+ }
+ GNUNET_assert (
GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove(queue_map, &queue->target, queue));
- GNUNET_STATISTICS_set(stats,
- "# queues active",
- GNUNET_CONTAINER_multipeermap_size(queue_map),
- GNUNET_NO);
+ GNUNET_CONTAINER_multipeermap_remove (queue_map, &queue->target, queue));
+ GNUNET_STATISTICS_set (stats,
+ "# queues active",
+ GNUNET_CONTAINER_multipeermap_size (queue_map),
+ GNUNET_NO);
if (NULL != queue->read_task)
- {
- GNUNET_SCHEDULER_cancel(queue->read_task);
- queue->read_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (queue->read_task);
+ queue->read_task = NULL;
+ }
if (NULL != queue->write_task)
- {
- GNUNET_SCHEDULER_cancel(queue->write_task);
- queue->write_task = NULL;
- }
- GNUNET_NETWORK_socket_close(queue->sock);
- gcry_cipher_close(queue->in_cipher);
- gcry_cipher_close(queue->out_cipher);
- GNUNET_free(queue->address);
+ {
+ GNUNET_SCHEDULER_cancel (queue->write_task);
+ queue->write_task = NULL;
+ }
+ GNUNET_NETWORK_socket_close (queue->sock);
+ gcry_cipher_close (queue->in_cipher);
+ gcry_cipher_close (queue->out_cipher);
+ GNUNET_free (queue->address);
if (0 != queue->backpressure)
queue->destroyed = GNUNET_YES;
else
- GNUNET_free(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_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ listen_sock,
+ &listen_cb,
+ NULL);
}
@@ -623,24 +630,24 @@ queue_destroy(struct Queue *queue)
* @param smac[out] where to write the HMAC
*/
static void
-calculate_hmac(struct GNUNET_HashCode *hmac_secret,
- const void *buf,
- size_t buf_size,
- struct GNUNET_ShortHashCode *smac)
+calculate_hmac (struct GNUNET_HashCode *hmac_secret,
+ const void *buf,
+ size_t buf_size,
+ struct GNUNET_ShortHashCode *smac)
{
struct GNUNET_HashCode mac;
- GNUNET_CRYPTO_hmac_raw(hmac_secret,
- sizeof(struct GNUNET_HashCode),
- buf,
- buf_size,
- &mac);
+ GNUNET_CRYPTO_hmac_raw (hmac_secret,
+ sizeof(struct GNUNET_HashCode),
+ buf,
+ buf_size,
+ &mac);
/* truncate to `struct GNUNET_ShortHashCode` */
- memcpy(smac, &mac, sizeof(struct GNUNET_ShortHashCode));
+ memcpy (smac, &mac, sizeof(struct GNUNET_ShortHashCode));
/* ratchet hmac key */
- GNUNET_CRYPTO_hash(hmac_secret,
- sizeof(struct GNUNET_HashCode),
- hmac_secret);
+ GNUNET_CRYPTO_hash (hmac_secret,
+ sizeof(struct GNUNET_HashCode),
+ hmac_secret);
}
@@ -651,18 +658,18 @@ calculate_hmac(struct GNUNET_HashCode *hmac_secret,
* @param queue queue to shut down nicely
*/
static void
-queue_finish(struct Queue *queue)
+queue_finish (struct Queue *queue)
{
struct TCPFinish fin;
- memset(&fin, 0, sizeof(fin));
- fin.header.size = htons(sizeof(fin));
- fin.header.type = htons(GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH);
- calculate_hmac(&queue->out_hmac, &fin, sizeof(fin), &fin.hmac);
+ memset (&fin, 0, sizeof(fin));
+ fin.header.size = htons (sizeof(fin));
+ fin.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH);
+ calculate_hmac (&queue->out_hmac, &fin, sizeof(fin), &fin.hmac);
/* if there is any message left in pwrite_buf, we
overwrite it (possibly dropping the last message
from CORE hard here) */
- memcpy(queue->pwrite_buf, &fin, sizeof(fin));
+ memcpy (queue->pwrite_buf, &fin, sizeof(fin));
queue->pwrite_off = sizeof(fin);
/* This flag will ensure that #queue_write() no longer
notifies CORE about the possibility of sending
@@ -680,10 +687,10 @@ queue_finish(struct Queue *queue)
* @param queue queue for which the timeout should be rescheduled
*/
static void
-reschedule_queue_timeout(struct Queue *queue)
+reschedule_queue_timeout (struct Queue *queue)
{
queue->timeout =
- GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
}
@@ -693,7 +700,7 @@ reschedule_queue_timeout(struct Queue *queue)
* @param cls the `struct Queue *` to disconnect
*/
static void
-queue_read(void *cls);
+queue_read (void *cls);
/**
@@ -704,31 +711,31 @@ queue_read(void *cls);
* @param success #GNUNET_OK on success
*/
static void
-core_read_finished_cb(void *cls, int success)
+core_read_finished_cb (void *cls, int success)
{
struct Queue *queue = cls;
if (GNUNET_OK != success)
- GNUNET_STATISTICS_update(stats,
- "# messages lost in communicator API towards CORE",
- 1,
- GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ "# messages lost in communicator API towards CORE",
+ 1,
+ GNUNET_NO);
queue->backpressure--;
/* handle deferred queue destruction */
if ((queue->destroyed) && (0 == queue->backpressure))
- {
- GNUNET_free(queue);
- return;
- }
- reschedule_queue_timeout(queue);
+ {
+ GNUNET_free (queue);
+ return;
+ }
+ reschedule_queue_timeout (queue);
/* possibly unchoke reading, now that CORE made progress */
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);
+ GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining (
+ queue->timeout),
+ queue->sock,
+ &queue_read,
+ queue);
}
@@ -742,34 +749,34 @@ core_read_finished_cb(void *cls, int success)
* @param plaintext_len number of bytes of plaintext received
*/
static void
-pass_plaintext_to_core(struct Queue *queue,
- const void *plaintext,
- size_t plaintext_len)
+pass_plaintext_to_core (struct Queue *queue,
+ const void *plaintext,
+ size_t plaintext_len)
{
const struct GNUNET_MessageHeader *hdr = plaintext;
int ret;
- if (ntohs(hdr->size) != plaintext_len)
- {
- /* NOTE: If we ever allow multiple CORE messages in one
- BOX, this will have to change! */
- GNUNET_break(0);
- return;
- }
- ret = GNUNET_TRANSPORT_communicator_receive(ch,
- &queue->target,
- hdr,
- ADDRESS_VALIDITY_PERIOD,
- &core_read_finished_cb,
- queue);
+ if (ntohs (hdr->size) != plaintext_len)
+ {
+ /* NOTE: If we ever allow multiple CORE messages in one
+ BOX, this will have to change! */
+ GNUNET_break (0);
+ return;
+ }
+ ret = GNUNET_TRANSPORT_communicator_receive (ch,
+ &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!? */
+ 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);
+ GNUNET_STATISTICS_update (stats,
+ "# bytes lost due to CORE not running",
+ plaintext_len,
+ GNUNET_NO);
}
@@ -783,51 +790,51 @@ pass_plaintext_to_core(struct Queue *queue,
* @param hmac_key[out] HMAC key to initialize
*/
static void
-setup_cipher(const struct GNUNET_HashCode *dh,
- const struct GNUNET_PeerIdentity *pid,
- gcry_cipher_hd_t *cipher,
- struct GNUNET_HashCode *hmac_key)
+setup_cipher (const struct GNUNET_HashCode *dh,
+ const struct GNUNET_PeerIdentity *pid,
+ gcry_cipher_hd_t *cipher,
+ struct GNUNET_HashCode *hmac_key)
{
char key[256 / 8];
char ctr[128 / 8];
- gcry_cipher_open(cipher,
- 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));
- gcry_cipher_setkey(*cipher, 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));
- gcry_cipher_setctr(*cipher, 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));
+ gcry_cipher_open (cipher,
+ 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));
+ gcry_cipher_setkey (*cipher, 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));
+ gcry_cipher_setctr (*cipher, 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));
}
@@ -838,13 +845,13 @@ setup_cipher(const struct GNUNET_HashCode *dh,
* @param queue[in,out] queue to initialize decryption cipher for
*/
static void
-setup_in_cipher(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral,
- struct Queue *queue)
+setup_in_cipher (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral,
+ struct Queue *queue)
{
struct GNUNET_HashCode dh;
- GNUNET_CRYPTO_eddsa_ecdh(my_private_key, ephemeral, &dh);
- setup_cipher(&dh, &my_identity, &queue->in_cipher, &queue->in_hmac);
+ GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &dh);
+ setup_cipher (&dh, &my_identity, &queue->in_cipher, &queue->in_hmac);
}
@@ -857,30 +864,30 @@ setup_in_cipher(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral,
* @param rekey the rekey message
*/
static void
-do_rekey(struct Queue *queue, const struct TCPRekey *rekey)
+do_rekey (struct Queue *queue, const struct TCPRekey *rekey)
{
struct TcpHandshakeSignature thp;
- thp.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY);
- thp.purpose.size = htonl(sizeof(thp));
+ thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY);
+ thp.purpose.size = htonl (sizeof(thp));
thp.sender = queue->target;
thp.receiver = my_identity;
thp.ephemeral = rekey->ephemeral;
thp.monotonic_time = rekey->monotonic_time;
/* FIXME: check monotonic time is monotonic... */
if (GNUNET_OK !=
- GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY,
- &thp.purpose,
- &rekey->sender_sig,
- &queue->target.public_key))
- {
- GNUNET_break(0);
- queue_finish(queue);
- return;
- }
- gcry_cipher_close(queue->in_cipher);
+ GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY,
+ &thp.purpose,
+ &rekey->sender_sig,
+ &queue->target.public_key))
+ {
+ GNUNET_break (0);
+ queue_finish (queue);
+ return;
+ }
+ gcry_cipher_close (queue->in_cipher);
queue->rekeyed = GNUNET_YES;
- setup_in_cipher(&rekey->ephemeral, queue);
+ setup_in_cipher (&rekey->ephemeral, queue);
}
@@ -892,13 +899,13 @@ do_rekey(struct Queue *queue, const struct TCPRekey *rekey)
* @return number of bytes of plaintext handled, 0 for none
*/
static size_t
-try_handle_plaintext(struct Queue *queue)
+try_handle_plaintext (struct Queue *queue)
{
const struct GNUNET_MessageHeader *hdr =
- (const struct GNUNET_MessageHeader *)queue->pread_buf;
- const struct TCPBox *box = (const struct TCPBox *)queue->pread_buf;
- const struct TCPRekey *rekey = (const struct TCPRekey *)queue->pread_buf;
- const struct TCPFinish *fin = (const struct TCPFinish *)queue->pread_buf;
+ (const struct GNUNET_MessageHeader *) queue->pread_buf;
+ const struct TCPBox *box = (const struct TCPBox *) queue->pread_buf;
+ const struct TCPRekey *rekey = (const struct TCPRekey *) queue->pread_buf;
+ const struct TCPFinish *fin = (const struct TCPFinish *) queue->pread_buf;
struct TCPRekey rekeyz;
struct TCPFinish finz;
struct GNUNET_ShortHashCode tmac;
@@ -907,74 +914,74 @@ try_handle_plaintext(struct Queue *queue)
if (sizeof(*hdr) > queue->pread_off)
return 0; /* not even a header */
- type = ntohs(hdr->type);
+ type = ntohs (hdr->type);
switch (type)
+ {
+ case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX:
+ /* Special case: header size excludes box itself! */
+ if (ntohs (hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
+ return 0;
+ calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac);
+ if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac)))
{
- case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX:
- /* Special case: header size excludes box itself! */
- if (ntohs(hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
- return 0;
- calculate_hmac(&queue->in_hmac, &box[1], ntohs(hdr->size), &tmac);
- if (0 != memcmp(&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));
- size = ntohs(hdr->size) + sizeof(*box);
- break;
-
- case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY:
- if (sizeof(*rekey) > queue->pread_off)
- return 0;
- if (ntohs(hdr->size) != sizeof(*rekey))
- {
- GNUNET_break_op(0);
- queue_finish(queue);
- return 0;
- }
- rekeyz = *rekey;
- memset(&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
- calculate_hmac(&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
- if (0 != memcmp(&tmac, &box->hmac, sizeof(tmac)))
- {
- GNUNET_break_op(0);
- queue_finish(queue);
- return 0;
- }
- do_rekey(queue, rekey);
- size = ntohs(hdr->size);
- break;
+ GNUNET_break_op (0);
+ queue_finish (queue);
+ return 0;
+ }
+ pass_plaintext_to_core (queue, (const void *) &box[1], ntohs (hdr->size));
+ size = ntohs (hdr->size) + sizeof(*box);
+ break;
- case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH:
- if (sizeof(*fin) > queue->pread_off)
- return 0;
- if (ntohs(hdr->size) != sizeof(*fin))
- {
- GNUNET_break_op(0);
- queue_finish(queue);
- return 0;
- }
- finz = *fin;
- memset(&finz.hmac, 0, sizeof(finz.hmac));
- calculate_hmac(&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
- if (0 != memcmp(&tmac, &fin->hmac, sizeof(tmac)))
- {
- GNUNET_break_op(0);
- queue_finish(queue);
- return 0;
- }
- /* handle FINISH by destroying queue */
- queue_destroy(queue);
- break;
+ case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY:
+ if (sizeof(*rekey) > queue->pread_off)
+ return 0;
+ if (ntohs (hdr->size) != sizeof(*rekey))
+ {
+ GNUNET_break_op (0);
+ queue_finish (queue);
+ return 0;
+ }
+ rekeyz = *rekey;
+ memset (&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
+ calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
+ if (0 != memcmp (&tmac, &box->hmac, sizeof(tmac)))
+ {
+ GNUNET_break_op (0);
+ queue_finish (queue);
+ return 0;
+ }
+ do_rekey (queue, rekey);
+ size = ntohs (hdr->size);
+ break;
- default:
- GNUNET_break_op(0);
- queue_finish(queue);
+ case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH:
+ if (sizeof(*fin) > queue->pread_off)
+ return 0;
+ if (ntohs (hdr->size) != sizeof(*fin))
+ {
+ GNUNET_break_op (0);
+ queue_finish (queue);
+ return 0;
+ }
+ finz = *fin;
+ memset (&finz.hmac, 0, sizeof(finz.hmac));
+ calculate_hmac (&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
+ if (0 != memcmp (&tmac, &fin->hmac, sizeof(tmac)))
+ {
+ GNUNET_break_op (0);
+ queue_finish (queue);
return 0;
}
- GNUNET_assert(0 != size);
+ /* handle FINISH by destroying queue */
+ queue_destroy (queue);
+ break;
+
+ default:
+ GNUNET_break_op (0);
+ queue_finish (queue);
+ return 0;
+ }
+ GNUNET_assert (0 != size);
return size;
}
@@ -985,96 +992,96 @@ try_handle_plaintext(struct Queue *queue)
* @param cls the `struct Queue *` to disconnect
*/
static void
-queue_read(void *cls)
+queue_read (void *cls)
{
struct Queue *queue = cls;
struct GNUNET_TIME_Relative left;
ssize_t rcvd;
queue->read_task = NULL;
- rcvd = GNUNET_NETWORK_socket_recv(queue->sock,
- &queue->cread_buf[queue->cread_off],
- BUF_SIZE - queue->cread_off);
+ rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
+ &queue->cread_buf[queue->cread_off],
+ BUF_SIZE - queue->cread_off);
if (-1 == rcvd)
+ {
+ if ((EAGAIN != errno) && (EINTR != errno))
{
- if ((EAGAIN != errno) && (EINTR != errno))
- {
- GNUNET_log_strerror(GNUNET_ERROR_TYPE_DEBUG, "recv");
- queue_finish(queue);
- return;
- }
- /* try again */
- queue->read_task =
- GNUNET_SCHEDULER_add_read_net(left, queue->sock, &queue_read, queue);
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv");
+ queue_finish (queue);
return;
}
+ /* try again */
+ queue->read_task =
+ GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
+ return;
+ }
if (0 != rcvd)
- reschedule_queue_timeout(queue);
+ reschedule_queue_timeout (queue);
queue->cread_off += rcvd;
while ((queue->pread_off < sizeof(queue->pread_buf)) &&
(queue->cread_off > 0))
- {
- size_t max = GNUNET_MIN(sizeof(queue->pread_buf) - queue->pread_off,
- queue->cread_off);
- size_t done;
- size_t total;
+ {
+ size_t max = GNUNET_MIN (sizeof(queue->pread_buf) - queue->pread_off,
+ queue->cread_off);
+ size_t done;
+ size_t total;
- GNUNET_assert(0 ==
- gcry_cipher_decrypt(queue->in_cipher,
+ GNUNET_assert (0 ==
+ 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) &&
- (0 != (done = try_handle_plaintext(queue))))
- {
- /* 'done' bytes of plaintext were used, shift buffer */
- GNUNET_assert(done <= queue->pread_off);
- /* NOTE: this memmove() could possibly sometimes be
- 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_off -= done;
- total += done;
- }
- /* when we encounter a rekey message, the decryption above uses the
- wrong key for everything after the rekey; in that case, we have
- to re-do the decryption at 'total' instead of at 'max'. If there
- is no rekey and the last message is incomplete (max > total),
- it is safe to keep the decryption so we shift by 'max' */
- if (GNUNET_YES == queue->rekeyed)
- {
- max = total;
- queue->rekeyed = GNUNET_NO;
- }
- memmove(queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
- queue->cread_off -= max;
+ queue->pread_off += max;
+ total = 0;
+ while ((GNUNET_NO == queue->rekeyed) &&
+ (0 != (done = try_handle_plaintext (queue))))
+ {
+ /* 'done' bytes of plaintext were used, shift buffer */
+ GNUNET_assert (done <= queue->pread_off);
+ /* NOTE: this memmove() could possibly sometimes be
+ 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_off -= done;
+ total += done;
+ }
+ /* when we encounter a rekey message, the decryption above uses the
+ wrong key for everything after the rekey; in that case, we have
+ to re-do the decryption at 'total' instead of at 'max'. If there
+ is no rekey and the last message is incomplete (max > total),
+ it is safe to keep the decryption so we shift by 'max' */
+ if (GNUNET_YES == queue->rekeyed)
+ {
+ max = total;
+ queue->rekeyed = GNUNET_NO;
}
+ memmove (queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
+ queue->cread_off -= max;
+ }
if (BUF_SIZE == queue->cread_off)
return; /* buffer full, suspend reading */
- left = GNUNET_TIME_absolute_get_remaining(queue->timeout);
+ left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
if (0 != left.rel_value_us)
+ {
+ if (max_queue_length < queue->backpressure)
{
- if (max_queue_length < queue->backpressure)
- {
- /* continue reading */
- queue->read_task =
- GNUNET_SCHEDULER_add_read_net(left, queue->sock, &queue_read, queue);
- }
- return;
+ /* continue reading */
+ queue->read_task =
+ GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
}
- 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_finish(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_finish (queue);
}
@@ -1086,7 +1093,7 @@ queue_read(void *cls)
* @return converted bindto specification
*/
static struct sockaddr *
-tcp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
+tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
{
struct sockaddr *in;
unsigned int port;
@@ -1094,88 +1101,88 @@ tcp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
char *colon;
char *cp;
- if (1 == sscanf(bindto, "%u%1s", &port, dummy))
+ if (1 == sscanf (bindto, "%u%1s", &port, dummy))
+ {
+ /* interpreting value as just a PORT number */
+ if (port > UINT16_MAX)
{
- /* 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);
- return NULL;
- }
- if ((GNUNET_NO == GNUNET_NETWORK_test_pf(PF_INET6)) ||
- (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno(cfg,
- COMMUNICATOR_CONFIG_SECTION,
- "DISABLE_V6")))
- {
- struct sockaddr_in *i4;
-
- i4 = GNUNET_malloc(sizeof(struct sockaddr_in));
- i4->sin_family = AF_INET;
- i4->sin_port = htons((uint16_t)port);
- *sock_len = sizeof(struct sockaddr_in);
- in = (struct sockaddr *)i4;
- }
- else
- {
- struct sockaddr_in6 *i6;
-
- i6 = GNUNET_malloc(sizeof(struct sockaddr_in6));
- i6->sin6_family = AF_INET6;
- i6->sin6_port = htons((uint16_t)port);
- *sock_len = sizeof(struct sockaddr_in6);
- in = (struct sockaddr *)i6;
- }
- return in;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "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")))
+ {
+ struct sockaddr_in *i4;
+
+ i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
+ i4->sin_family = AF_INET;
+ i4->sin_port = htons ((uint16_t) port);
+ *sock_len = sizeof(struct sockaddr_in);
+ in = (struct sockaddr *) i4;
+ }
+ else
+ {
+ struct sockaddr_in6 *i6;
+
+ i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
+ i6->sin6_family = AF_INET6;
+ i6->sin6_port = htons ((uint16_t) port);
+ *sock_len = sizeof(struct sockaddr_in6);
+ in = (struct sockaddr *) i6;
}
- cp = GNUNET_strdup(bindto);
- colon = strrchr(cp, ':');
+ return in;
+ }
+ cp = GNUNET_strdup (bindto);
+ colon = strrchr (cp, ':');
if (NULL != colon)
+ {
+ /* interpet value after colon as port */
+ *colon = '\0';
+ colon++;
+ if (1 == sscanf (colon, "%u%1s", &port, dummy))
{
- /* interpet value after colon as port */
- *colon = '\0';
- colon++;
- if (1 == sscanf(colon, "%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;
- }
- }
- else
- {
- GNUNET_log(
- GNUNET_ERROR_TYPE_ERROR,
- "BINDTO specification `%s' invalid: last ':' not followed by number\n",
- bindto);
- GNUNET_free(cp);
- return NULL;
- }
+ /* 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;
+ }
}
- else
+ else
{
- /* interpret missing port as 0, aka pick any free one */
- port = 0;
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ "BINDTO specification `%s' invalid: last ':' not followed by number\n",
+ bindto);
+ GNUNET_free (cp);
+ return NULL;
}
+ }
+ else
+ {
+ /* interpret missing port as 0, aka pick any free one */
+ port = 0;
+ }
{
/* try IPv4 */
struct sockaddr_in v4;
- if (1 == inet_pton(AF_INET, cp, &v4))
- {
- v4.sin_port = htons((uint16_t)port);
- in = GNUNET_memdup(&v4, sizeof(v4));
- *sock_len = sizeof(v4);
- GNUNET_free(cp);
- return in;
- }
+ if (1 == inet_pton (AF_INET, cp, &v4))
+ {
+ v4.sin_port = htons ((uint16_t) port);
+ in = GNUNET_memdup (&v4, sizeof(v4));
+ *sock_len = sizeof(v4);
+ GNUNET_free (cp);
+ return in;
+ }
}
{
/* try IPv6 */
@@ -1183,22 +1190,22 @@ tcp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
const char *start;
start = cp;
- if (('[' == *cp) && (']' == cp[strlen(cp) - 1]))
- {
- start++; /* skip over '[' */
- cp[strlen(cp) - 1] = '\0'; /* eat ']' */
- }
- if (1 == inet_pton(AF_INET6, start, &v6))
- {
- v6.sin6_port = htons((uint16_t)port);
- in = GNUNET_memdup(&v6, sizeof(v6));
- *sock_len = sizeof(v6);
- GNUNET_free(cp);
- return in;
- }
+ if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
+ {
+ start++; /* skip over '[' */
+ cp[strlen (cp) - 1] = '\0'; /* eat ']' */
+ }
+ if (1 == inet_pton (AF_INET6, start, &v6))
+ {
+ v6.sin6_port = htons ((uint16_t) port);
+ in = GNUNET_memdup (&v6, sizeof(v6));
+ *sock_len = sizeof(v6);
+ GNUNET_free (cp);
+ return in;
+ }
}
/* #5528 FIXME (feature!): maybe also try getnameinfo()? */
- GNUNET_free(cp);
+ GNUNET_free (cp);
return NULL;
}
@@ -1210,17 +1217,17 @@ tcp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
* @param queue queue to setup outgoing (encryption) cipher for
*/
static void
-setup_out_cipher(struct Queue *queue)
+setup_out_cipher (struct Queue *queue)
{
struct GNUNET_HashCode dh;
- GNUNET_CRYPTO_ecdh_eddsa(&queue->ephemeral, &queue->target.public_key, &dh);
+ GNUNET_CRYPTO_ecdh_eddsa (&queue->ephemeral, &queue->target.public_key, &dh);
/* we don't need the private key anymore, drop it! */
- memset(&queue->ephemeral, 0, sizeof(queue->ephemeral));
- setup_cipher(&dh, &queue->target, &queue->out_cipher, &queue->out_hmac);
- queue->rekey_time = GNUNET_TIME_relative_to_absolute(REKEY_TIME_INTERVAL);
+ memset (&queue->ephemeral, 0, sizeof(queue->ephemeral));
+ setup_cipher (&dh, &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);
+ GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, REKEY_MAX_BYTES);
}
@@ -1231,31 +1238,31 @@ setup_out_cipher(struct Queue *queue)
* @param queue queue to perform rekeying on
*/
static void
-inject_rekey(struct Queue *queue)
+inject_rekey (struct Queue *queue)
{
struct TCPRekey rekey;
struct TcpHandshakeSignature thp;
- GNUNET_assert(0 == queue->pwrite_off);
- memset(&rekey, 0, sizeof(rekey));
- GNUNET_assert(GNUNET_OK ==
- 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);
+ GNUNET_assert (0 == queue->pwrite_off);
+ memset (&rekey, 0, sizeof(rekey));
+ GNUNET_assert (GNUNET_OK ==
+ 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.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));
+ 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.sender = my_identity;
thp.receiver = queue->target;
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));
- calculate_hmac(&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac);
- memcpy(queue->pwrite_buf, &rekey, sizeof(rekey));
+ GNUNET_assert (GNUNET_OK == 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));
queue->pwrite_off = sizeof(rekey);
}
@@ -1267,79 +1274,79 @@ inject_rekey(struct Queue *queue)
* @param cls a `struct Queue`
*/
static void
-queue_write(void *cls)
+queue_write (void *cls)
{
struct Queue *queue = cls;
ssize_t sent;
queue->write_task = NULL;
if (0 != queue->cwrite_off)
+ {
+ sent = GNUNET_NETWORK_socket_send (queue->sock,
+ queue->cwrite_buf,
+ queue->cwrite_off);
+ if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send");
+ queue_destroy (queue);
+ return;
+ }
+ if (sent > 0)
{
- sent = GNUNET_NETWORK_socket_send(queue->sock,
- queue->cwrite_buf,
- queue->cwrite_off);
- if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
- {
- GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "send");
- queue_destroy(queue);
- return;
- }
- if (sent > 0)
- {
- size_t usent = (size_t)sent;
-
- memmove(queue->cwrite_buf,
- &queue->cwrite_buf[usent],
- queue->cwrite_off - usent);
- reschedule_queue_timeout(queue);
- }
+ size_t usent = (size_t) sent;
+
+ memmove (queue->cwrite_buf,
+ &queue->cwrite_buf[usent],
+ queue->cwrite_off - usent);
+ reschedule_queue_timeout (queue);
}
+ }
/* can we encrypt more? (always encrypt full messages, needed
such that #mq_cancel() can work!) */
if ((0 < queue->rekey_left_bytes) &&
(queue->cwrite_off + queue->pwrite_off <= BUF_SIZE))
- {
- GNUNET_assert(0 ==
- gcry_cipher_encrypt(queue->out_cipher,
+ {
+ GNUNET_assert (0 ==
+ 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
- queue->rekey_left_bytes = 0;
- queue->cwrite_off += queue->pwrite_off;
- queue->pwrite_off = 0;
- }
+ if (queue->rekey_left_bytes > queue->pwrite_off)
+ queue->rekey_left_bytes -= queue->pwrite_off;
+ else
+ queue->rekey_left_bytes = 0;
+ queue->cwrite_off += queue->pwrite_off;
+ queue->pwrite_off = 0;
+ }
if ((0 == queue->pwrite_off) &&
((0 == queue->rekey_left_bytes) ||
(0 ==
- GNUNET_TIME_absolute_get_remaining(queue->rekey_time).rel_value_us)))
- {
- gcry_cipher_close(queue->out_cipher);
- setup_out_cipher(queue);
- inject_rekey(queue);
- }
- if ((0 == queue->pwrite_off) && (!queue->finishing) &&
+ GNUNET_TIME_absolute_get_remaining (queue->rekey_time).rel_value_us)))
+ {
+ gcry_cipher_close (queue->out_cipher);
+ setup_out_cipher (queue);
+ inject_rekey (queue);
+ }
+ if ((0 == queue->pwrite_off) && (! queue->finishing) &&
(queue->mq_awaits_continue))
- {
- queue->mq_awaits_continue = GNUNET_NO;
- GNUNET_MQ_impl_send_continue(queue->mq);
- }
+ {
+ queue->mq_awaits_continue = GNUNET_NO;
+ GNUNET_MQ_impl_send_continue (queue->mq);
+ }
/* did we just finish writing 'finish'? */
if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing))
- {
- queue_destroy(queue);
- return;
- }
+ {
+ queue_destroy (queue);
+ return;
+ }
/* do we care to write more? */
if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off))
queue->write_task =
- GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL,
- queue->sock,
- &queue_write,
- queue);
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ queue->sock,
+ &queue_write,
+ queue);
}
@@ -1352,32 +1359,32 @@ queue_write(void *cls)
* @param impl_state our `struct Queue`
*/
static void
-mq_send(struct GNUNET_MQ_Handle *mq,
- const struct GNUNET_MessageHeader *msg,
- void *impl_state)
+mq_send (struct GNUNET_MQ_Handle *mq,
+ const struct GNUNET_MessageHeader *msg,
+ void *impl_state)
{
struct Queue *queue = impl_state;
- uint16_t msize = ntohs(msg->size);
+ uint16_t msize = ntohs (msg->size);
struct TCPBox box;
- GNUNET_assert(mq == queue->mq);
+ GNUNET_assert (mq == queue->mq);
if (GNUNET_YES == queue->finishing)
return; /* this queue is dying, drop msg */
- GNUNET_assert(0 == queue->pread_off);
- box.header.type = htons(GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX);
- box.header.size = htons(msize);
- calculate_hmac(&queue->out_hmac, msg, msize, &box.hmac);
- memcpy(&queue->pread_buf[queue->pread_off], &box, sizeof(box));
+ GNUNET_assert (0 == queue->pread_off);
+ box.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX);
+ box.header.size = htons (msize);
+ calculate_hmac (&queue->out_hmac, msg, msize, &box.hmac);
+ memcpy (&queue->pread_buf[queue->pread_off], &box, sizeof(box));
queue->pread_off += sizeof(box);
- memcpy(&queue->pread_buf[queue->pread_off], msg, msize);
+ memcpy (&queue->pread_buf[queue->pread_off], msg, msize);
queue->pread_off += msize;
- GNUNET_assert(NULL != queue->sock);
+ GNUNET_assert (NULL != queue->sock);
if (NULL == queue->write_task)
queue->write_task =
- GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL,
- queue->sock,
- &queue_write,
- queue);
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ queue->sock,
+ &queue_write,
+ queue);
}
@@ -1390,15 +1397,15 @@ mq_send(struct GNUNET_MQ_Handle *mq,
* @param impl_state our `struct Queue`
*/
static void
-mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
+mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
{
struct Queue *queue = impl_state;
if (mq == queue->mq)
- {
- queue->mq = NULL;
- queue_finish(queue);
- }
+ {
+ queue->mq = NULL;
+ queue_finish (queue);
+ }
}
@@ -1409,11 +1416,11 @@ mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
* @param impl_state our `struct Queue`
*/
static void
-mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
+mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
{
struct Queue *queue = impl_state;
- GNUNET_assert(0 != queue->pwrite_off);
+ GNUNET_assert (0 != queue->pwrite_off);
queue->pwrite_off = 0;
}
@@ -1428,15 +1435,15 @@ mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
* @param error error code
*/
static void
-mq_error(void *cls, enum GNUNET_MQ_Error error)
+mq_error (void *cls, 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);
- queue_finish(queue);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "MQ error in queue to %s: %d\n",
+ GNUNET_i2s (&queue->target),
+ (int) error);
+ queue_finish (queue);
}
@@ -1448,58 +1455,58 @@ mq_error(void *cls, enum GNUNET_MQ_Error error)
* @param queue queue to boot
*/
static void
-boot_queue(struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs)
+boot_queue (struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs)
{
queue->nt =
- GNUNET_NT_scanner_get_type(is, queue->address, queue->address_len);
- (void)GNUNET_CONTAINER_multipeermap_put(
+ GNUNET_NT_scanner_get_type (is, queue->address, queue->address_len);
+ (void) GNUNET_CONTAINER_multipeermap_put (
queue_map,
&queue->target,
queue,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
- GNUNET_STATISTICS_set(stats,
- "# queues active",
- GNUNET_CONTAINER_multipeermap_size(queue_map),
- GNUNET_NO);
+ GNUNET_STATISTICS_set (stats,
+ "# 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);
+ 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);
{
char *foreign_addr;
switch (queue->address->sa_family)
- {
- case AF_INET:
- GNUNET_asprintf(&foreign_addr,
- "%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));
- 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);
- GNUNET_free(foreign_addr);
+ {
+ case AF_INET:
+ GNUNET_asprintf (&foreign_addr,
+ "%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));
+ 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);
+ GNUNET_free (foreign_addr);
}
}
@@ -1515,33 +1522,33 @@ boot_queue(struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs)
* @param epub our public key for the KX
*/
static void
-transmit_kx(struct Queue *queue,
- const struct GNUNET_CRYPTO_EcdhePublicKey *epub)
+transmit_kx (struct Queue *queue,
+ const struct GNUNET_CRYPTO_EcdhePublicKey *epub)
{
struct TcpHandshakeSignature ths;
struct TCPConfirmation tc;
- memcpy(queue->cwrite_buf, epub, sizeof(*epub));
+ memcpy (queue->cwrite_buf, epub, sizeof(*epub));
queue->cwrite_off = sizeof(epub);
/* compute 'tc' and append in encrypted format to cwrite_buf */
tc.sender = my_identity;
tc.monotonic_time =
- GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_monotonic(cfg));
- ths.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE);
- ths.purpose.size = htonl(sizeof(ths));
+ GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg));
+ ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE);
+ ths.purpose.size = htonl (sizeof(ths));
ths.sender = my_identity;
ths.receiver = queue->target;
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_assert(0 ==
- gcry_cipher_encrypt(queue->out_cipher,
- &queue->cwrite_buf[queue->cwrite_off],
- sizeof(tc),
- &tc,
- sizeof(tc)));
+ GNUNET_assert (GNUNET_OK == 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)));
queue->cwrite_off += sizeof(tc);
}
@@ -1554,15 +1561,15 @@ transmit_kx(struct Queue *queue,
* @param queue the queue to setup
*/
static void
-start_initial_kx_out(struct Queue *queue)
+start_initial_kx_out (struct Queue *queue)
{
struct GNUNET_CRYPTO_EcdhePublicKey epub;
- GNUNET_assert(GNUNET_OK ==
- GNUNET_CRYPTO_ecdhe_key_create2(&queue->ephemeral));
- GNUNET_CRYPTO_ecdhe_key_get_public(&queue->ephemeral, &epub);
- setup_out_cipher(queue);
- transmit_kx(queue, &epub);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral));
+ GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, &epub);
+ setup_out_cipher (queue);
+ transmit_kx (queue, &epub);
}
@@ -1578,31 +1585,32 @@ start_initial_kx_out(struct Queue *queue)
* @return #GNUNET_OK if the signature was OK, #GNUNET_SYSERR if not
*/
static int
-decrypt_and_check_tc(struct Queue *queue,
- struct TCPConfirmation *tc,
- char *ibuf)
+decrypt_and_check_tc (struct Queue *queue,
+ struct TCPConfirmation *tc,
+ char *ibuf)
{
struct TcpHandshakeSignature ths;
- GNUNET_assert(
+ GNUNET_assert (
0 ==
- 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));
+ 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;
ths.receiver = my_identity;
- memcpy(&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
+ memcpy (&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
ths.monotonic_time = tc->monotonic_time;
/* FIXME: check monotonic time against previous mono times
from this sender! */
- return GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE,
- &ths.purpose,
- &tc->sender_sig,
- &tc->sender.public_key);
+ return GNUNET_CRYPTO_eddsa_verify (
+ GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE,
+ &ths.purpose,
+ &tc->sender_sig,
+ &tc->sender.public_key);
}
@@ -1612,12 +1620,12 @@ decrypt_and_check_tc(struct Queue *queue,
* @param pq proto queue to free
*/
static void
-free_proto_queue(struct ProtoQueue *pq)
+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);
- GNUNET_free(pq);
+ GNUNET_NETWORK_socket_close (pq->sock);
+ GNUNET_free (pq->address);
+ GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq);
+ GNUNET_free (pq);
}
@@ -1628,7 +1636,7 @@ free_proto_queue(struct ProtoQueue *pq)
* @param cls a `struct ProtoQueue`
*/
static void
-proto_read_kx(void *cls)
+proto_read_kx (void *cls)
{
struct ProtoQueue *pq = cls;
ssize_t rcvd;
@@ -1637,67 +1645,67 @@ proto_read_kx(void *cls)
struct TCPConfirmation tc;
pq->read_task = NULL;
- left = GNUNET_TIME_absolute_get_remaining(pq->timeout);
+ left = GNUNET_TIME_absolute_get_remaining (pq->timeout);
if (0 == left.rel_value_us)
- {
- free_proto_queue(pq);
- return;
- }
- rcvd = GNUNET_NETWORK_socket_recv(pq->sock,
- &pq->ibuf[pq->ibuf_off],
- sizeof(pq->ibuf) - pq->ibuf_off);
+ {
+ free_proto_queue (pq);
+ return;
+ }
+ rcvd = GNUNET_NETWORK_socket_recv (pq->sock,
+ &pq->ibuf[pq->ibuf_off],
+ sizeof(pq->ibuf) - pq->ibuf_off);
if (-1 == rcvd)
+ {
+ if ((EAGAIN != errno) && (EINTR != errno))
{
- if ((EAGAIN != errno) && (EINTR != errno))
- {
- GNUNET_log_strerror(GNUNET_ERROR_TYPE_DEBUG, "recv");
- free_proto_queue(pq);
- return;
- }
- /* try again */
- pq->read_task =
- GNUNET_SCHEDULER_add_read_net(left, pq->sock, &proto_read_kx, pq);
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv");
+ free_proto_queue (pq);
return;
}
+ /* try again */
+ pq->read_task =
+ GNUNET_SCHEDULER_add_read_net (left, pq->sock, &proto_read_kx, pq);
+ return;
+ }
pq->ibuf_off += rcvd;
if (pq->ibuf_off > sizeof(pq->ibuf))
- {
- /* read more */
- pq->read_task =
- GNUNET_SCHEDULER_add_read_net(left, pq->sock, &proto_read_kx, pq);
- return;
- }
+ {
+ /* read more */
+ pq->read_task =
+ GNUNET_SCHEDULER_add_read_net (left, pq->sock, &proto_read_kx, pq);
+ return;
+ }
/* we got all the data, let's find out who we are talking to! */
- queue = GNUNET_new(struct Queue);
- setup_in_cipher((const struct GNUNET_CRYPTO_EcdhePublicKey *)pq->ibuf,
- queue);
- if (GNUNET_OK != decrypt_and_check_tc(queue, &tc, pq->ibuf))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Invalid TCP KX received from %s\n",
- GNUNET_a2s(queue->address, queue->address_len));
- gcry_cipher_close(queue->in_cipher);
- GNUNET_free(queue);
- free_proto_queue(pq);
- return;
- }
+ queue = GNUNET_new (struct Queue);
+ setup_in_cipher ((const struct GNUNET_CRYPTO_EcdhePublicKey *) pq->ibuf,
+ queue);
+ if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Invalid TCP KX received from %s\n",
+ GNUNET_a2s (queue->address, queue->address_len));
+ gcry_cipher_close (queue->in_cipher);
+ GNUNET_free (queue);
+ free_proto_queue (pq);
+ return;
+ }
queue->address = pq->address; /* steals reference */
queue->address_len = pq->address_len;
queue->target = tc.sender;
- start_initial_kx_out(queue);
- boot_queue(queue, GNUNET_TRANSPORT_CS_INBOUND);
+ start_initial_kx_out (queue);
+ boot_queue (queue, GNUNET_TRANSPORT_CS_INBOUND);
queue->read_task =
- GNUNET_SCHEDULER_add_read_net(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
- queue->sock,
- &queue_read,
- queue);
- queue->write_task =
- GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_SCHEDULER_add_read_net (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
queue->sock,
- &queue_write,
+ &queue_read,
queue);
- GNUNET_CONTAINER_DLL_remove(proto_head, proto_tail, pq);
- GNUNET_free(pq);
+ queue->write_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ queue->sock,
+ &queue_write,
+ queue);
+ GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq);
+ GNUNET_free (pq);
}
@@ -1709,7 +1717,7 @@ proto_read_kx(void *cls)
* @param cls NULL
*/
static void
-listen_cb(void *cls)
+listen_cb (void *cls)
{
struct sockaddr_storage in;
socklen_t addrlen;
@@ -1717,35 +1725,35 @@ listen_cb(void *cls)
struct ProtoQueue *pq;
listen_task = NULL;
- GNUNET_assert(NULL != listen_sock);
+ GNUNET_assert (NULL != listen_sock);
addrlen = sizeof(in);
- memset(&in, 0, sizeof(in));
- sock = GNUNET_NETWORK_socket_accept(listen_sock,
- (struct sockaddr *)&in,
- &addrlen);
+ memset (&in, 0, sizeof(in));
+ sock = GNUNET_NETWORK_socket_accept (listen_sock,
+ (struct sockaddr *) &in,
+ &addrlen);
if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno)))
return; /* system limit reached, wait until connection goes down */
- listen_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL,
- listen_sock,
- &listen_cb,
- NULL);
+ listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ listen_sock,
+ &listen_cb,
+ NULL);
if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno)))
return;
if (NULL == sock)
- {
- GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "accept");
- return;
- }
- pq = GNUNET_new(struct ProtoQueue);
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "accept");
+ return;
+ }
+ pq = GNUNET_new (struct ProtoQueue);
pq->address_len = addrlen;
- pq->address = GNUNET_memdup(&in, addrlen);
- pq->timeout = GNUNET_TIME_relative_to_absolute(PROTO_QUEUE_TIMEOUT);
+ pq->address = GNUNET_memdup (&in, addrlen);
+ pq->timeout = GNUNET_TIME_relative_to_absolute (PROTO_QUEUE_TIMEOUT);
pq->sock = sock;
- pq->read_task = GNUNET_SCHEDULER_add_read_net(PROTO_QUEUE_TIMEOUT,
- pq->sock,
- &proto_read_kx,
- pq);
- GNUNET_CONTAINER_DLL_insert(proto_head, proto_tail, pq);
+ pq->read_task = GNUNET_SCHEDULER_add_read_net (PROTO_QUEUE_TIMEOUT,
+ pq->sock,
+ &proto_read_kx,
+ pq);
+ GNUNET_CONTAINER_DLL_insert (proto_head, proto_tail, pq);
}
@@ -1757,7 +1765,7 @@ listen_cb(void *cls)
* @param cls a `struct Queue`
*/
static void
-queue_read_kx(void *cls)
+queue_read_kx (void *cls)
{
struct Queue *queue = cls;
ssize_t rcvd;
@@ -1765,65 +1773,65 @@ queue_read_kx(void *cls)
struct TCPConfirmation tc;
queue->read_task = NULL;
- left = GNUNET_TIME_absolute_get_remaining(queue->timeout);
+ left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
if (0 == left.rel_value_us)
- {
- queue_destroy(queue);
- return;
- }
- rcvd = GNUNET_NETWORK_socket_recv(queue->sock,
- &queue->cread_buf[queue->cread_off],
- BUF_SIZE - queue->cread_off);
+ {
+ queue_destroy (queue);
+ return;
+ }
+ rcvd = GNUNET_NETWORK_socket_recv (queue->sock,
+ &queue->cread_buf[queue->cread_off],
+ BUF_SIZE - queue->cread_off);
if (-1 == rcvd)
+ {
+ if ((EAGAIN != errno) && (EINTR != errno))
{
- if ((EAGAIN != errno) && (EINTR != errno))
- {
- GNUNET_log_strerror(GNUNET_ERROR_TYPE_DEBUG, "recv");
- queue_destroy(queue);
- return;
- }
- queue->read_task =
- GNUNET_SCHEDULER_add_read_net(left, queue->sock, &queue_read_kx, queue);
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv");
+ queue_destroy (queue);
return;
}
+ queue->read_task =
+ GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
+ return;
+ }
queue->cread_off += rcvd;
if (queue->cread_off < INITIAL_KX_SIZE)
- {
- /* read more */
- queue->read_task =
- GNUNET_SCHEDULER_add_read_net(left, queue->sock, &queue_read_kx, queue);
- return;
- }
+ {
+ /* read more */
+ queue->read_task =
+ GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
+ return;
+ }
/* we got all the data, let's find out who we are talking to! */
- setup_in_cipher((const struct GNUNET_CRYPTO_EcdhePublicKey *)
- queue->cread_buf,
- queue);
- if (GNUNET_OK != decrypt_and_check_tc(queue, &tc, queue->cread_buf))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Invalid TCP KX received from %s\n",
- GNUNET_a2s(queue->address, queue->address_len));
- queue_destroy(queue);
- return;
- }
+ setup_in_cipher ((const struct GNUNET_CRYPTO_EcdhePublicKey *)
+ queue->cread_buf,
+ queue);
+ if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Invalid TCP KX received from %s\n",
+ GNUNET_a2s (queue->address, queue->address_len));
+ queue_destroy (queue);
+ return;
+ }
if (0 !=
- memcmp(&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Invalid sender in TCP KX received from %s\n",
- GNUNET_a2s(queue->address, queue->address_len));
- queue_destroy(queue);
- return;
- }
+ memcmp (&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Invalid sender in TCP KX received from %s\n",
+ GNUNET_a2s (queue->address, queue->address_len));
+ queue_destroy (queue);
+ return;
+ }
/* update queue timeout */
- reschedule_queue_timeout(queue);
+ reschedule_queue_timeout (queue);
/* prepare to continue with regular read task immediately */
- memmove(queue->cread_buf,
- &queue->cread_buf[INITIAL_KX_SIZE],
- queue->cread_off - (INITIAL_KX_SIZE));
+ memmove (queue->cread_buf,
+ &queue->cread_buf[INITIAL_KX_SIZE],
+ queue->cread_off - (INITIAL_KX_SIZE));
queue->cread_off -= INITIAL_KX_SIZE;
- queue->read_task = GNUNET_SCHEDULER_add_now(&queue_read, queue);
+ queue->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue);
}
@@ -1846,7 +1854,7 @@ queue_read_kx(void *cls)
* invalid
*/
static int
-mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
+mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
{
struct Queue *queue;
const char *path;
@@ -1854,54 +1862,54 @@ mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
socklen_t in_len;
struct GNUNET_NETWORK_Handle *sock;
- if (0 != strncmp(address,
- COMMUNICATOR_ADDRESS_PREFIX "-",
- strlen(COMMUNICATOR_ADDRESS_PREFIX "-")))
- {
- GNUNET_break_op(0);
- return GNUNET_SYSERR;
- }
- path = &address[strlen(COMMUNICATOR_ADDRESS_PREFIX "-")];
- in = tcp_address_to_sockaddr(path, &in_len);
+ if (0 != strncmp (address,
+ COMMUNICATOR_ADDRESS_PREFIX "-",
+ strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
+ in = tcp_address_to_sockaddr (path, &in_len);
- sock = GNUNET_NETWORK_socket_create(in->sa_family, SOCK_STREAM, IPPROTO_TCP);
+ sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP);
if (NULL == sock)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "socket(%d) failed: %s",
- in->sa_family,
- strerror(errno));
- GNUNET_free(in);
- return GNUNET_SYSERR;
- }
- if (GNUNET_OK != GNUNET_NETWORK_socket_connect(sock, in, in_len))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "connect to `%s' failed: %s",
- address,
- strerror(errno));
- GNUNET_NETWORK_socket_close(sock);
- GNUNET_free(in);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "socket(%d) failed: %s",
+ in->sa_family,
+ strerror (errno));
+ GNUNET_free (in);
+ return GNUNET_SYSERR;
+ }
+ if (GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "connect to `%s' failed: %s",
+ address,
+ strerror (errno));
+ GNUNET_NETWORK_socket_close (sock);
+ GNUNET_free (in);
+ return GNUNET_SYSERR;
+ }
- queue = GNUNET_new(struct Queue);
+ queue = GNUNET_new (struct Queue);
queue->target = *peer;
queue->address = in;
queue->address_len = in_len;
queue->sock = sock;
- boot_queue(queue, GNUNET_TRANSPORT_CS_OUTBOUND);
+ boot_queue (queue, GNUNET_TRANSPORT_CS_OUTBOUND);
queue->read_task =
- GNUNET_SCHEDULER_add_read_net(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
- queue->sock,
- &queue_read_kx,
- queue);
- start_initial_kx_out(queue);
- queue->write_task =
- GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_SCHEDULER_add_read_net (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
queue->sock,
- &queue_write,
+ &queue_read_kx,
queue);
+ start_initial_kx_out (queue);
+ queue->write_task =
+ GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ queue->sock,
+ &queue_write,
+ queue);
return GNUNET_OK;
}
@@ -1915,15 +1923,15 @@ mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
* @return #GNUNET_OK to continue to iterate
*/
static int
-get_queue_delete_it(void *cls,
- const struct GNUNET_PeerIdentity *target,
- void *value)
+get_queue_delete_it (void *cls,
+ const struct GNUNET_PeerIdentity *target,
+ void *value)
{
struct Queue *queue = value;
- (void)cls;
- (void)target;
- queue_destroy(queue);
+ (void) cls;
+ (void) target;
+ queue_destroy (queue);
return GNUNET_OK;
}
@@ -1934,47 +1942,47 @@ get_queue_delete_it(void *cls,
* @param cls NULL (always)
*/
static void
-do_shutdown(void *cls)
+do_shutdown (void *cls)
{
while (NULL != proto_head)
- free_proto_queue(proto_head);
+ free_proto_queue (proto_head);
if (NULL != nat)
- {
- GNUNET_NAT_unregister(nat);
- nat = NULL;
- }
+ {
+ GNUNET_NAT_unregister (nat);
+ nat = NULL;
+ }
if (NULL != listen_task)
- {
- GNUNET_SCHEDULER_cancel(listen_task);
- listen_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (listen_task);
+ listen_task = NULL;
+ }
if (NULL != listen_sock)
- {
- GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(listen_sock));
- listen_sock = NULL;
- }
- GNUNET_CONTAINER_multipeermap_iterate(queue_map, &get_queue_delete_it, NULL);
- GNUNET_CONTAINER_multipeermap_destroy(queue_map);
+ {
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (listen_sock));
+ listen_sock = NULL;
+ }
+ GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL);
+ GNUNET_CONTAINER_multipeermap_destroy (queue_map);
if (NULL != ch)
- {
- GNUNET_TRANSPORT_communicator_disconnect(ch);
- ch = NULL;
- }
+ {
+ GNUNET_TRANSPORT_communicator_disconnect (ch);
+ ch = NULL;
+ }
if (NULL != stats)
- {
- GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
- stats = NULL;
- }
+ {
+ GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
+ stats = NULL;
+ }
if (NULL != my_private_key)
- {
- GNUNET_free(my_private_key);
- my_private_key = NULL;
- }
+ {
+ GNUNET_free (my_private_key);
+ my_private_key = NULL;
+ }
if (NULL != is)
- {
- GNUNET_NT_scanner_done(is);
- is = NULL;
- }
+ {
+ GNUNET_NT_scanner_done (is);
+ is = NULL;
+ }
}
@@ -1990,14 +1998,14 @@ do_shutdown(void *cls)
* @param msg payload
*/
static void
-enc_notify_cb(void *cls,
- const struct GNUNET_PeerIdentity *sender,
- const struct GNUNET_MessageHeader *msg)
+enc_notify_cb (void *cls,
+ const struct GNUNET_PeerIdentity *sender,
+ const struct GNUNET_MessageHeader *msg)
{
- (void)cls;
- (void)sender;
- (void)msg;
- GNUNET_break_op(0);
+ (void) cls;
+ (void) sender;
+ (void) msg;
+ GNUNET_break_op (0);
}
@@ -2015,39 +2023,39 @@ enc_notify_cb(void *cls,
* @param addrlen actual length of the @a addr
*/
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)
+nat_address_cb (void *cls,
+ 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;
if (GNUNET_YES == add_remove)
- {
- enum GNUNET_NetworkType nt;
-
- GNUNET_asprintf(&my_addr,
- "%s-%s",
- COMMUNICATOR_ADDRESS_PREFIX,
- GNUNET_a2s(addr, addrlen));
- nt = GNUNET_NT_scanner_get_type(is, addr, addrlen);
- ai =
- GNUNET_TRANSPORT_communicator_address_add(ch,
- my_addr,
- nt,
- GNUNET_TIME_UNIT_FOREVER_REL);
- GNUNET_free(my_addr);
- *app_ctx = ai;
- }
+ {
+ enum GNUNET_NetworkType nt;
+
+ GNUNET_asprintf (&my_addr,
+ "%s-%s",
+ COMMUNICATOR_ADDRESS_PREFIX,
+ GNUNET_a2s (addr, addrlen));
+ nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
+ ai =
+ GNUNET_TRANSPORT_communicator_address_add (ch,
+ my_addr,
+ nt,
+ GNUNET_TIME_UNIT_FOREVER_REL);
+ GNUNET_free (my_addr);
+ *app_ctx = ai;
+ }
else
- {
- ai = *app_ctx;
- GNUNET_TRANSPORT_communicator_address_remove(ai);
- *app_ctx = NULL;
- }
+ {
+ ai = *app_ctx;
+ GNUNET_TRANSPORT_communicator_address_remove (ai);
+ *app_ctx = NULL;
+ }
}
@@ -2060,10 +2068,10 @@ nat_address_cb(void *cls,
* @param c configuration
*/
static void
-run(void *cls,
- char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *c)
{
char *bindto;
struct sockaddr *in;
@@ -2071,113 +2079,113 @@ run(void *cls,
struct sockaddr_storage in_sto;
socklen_t sto_len;
- (void)cls;
+ (void) cls;
cfg = c;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename(cfg,
- COMMUNICATOR_CONFIG_SECTION,
- "BINDTO",
- &bindto))
- {
- GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR,
- COMMUNICATOR_CONFIG_SECTION,
- "BINDTO");
- return;
- }
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ COMMUNICATOR_CONFIG_SECTION,
+ "BINDTO",
+ &bindto))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ COMMUNICATOR_CONFIG_SECTION,
+ "BINDTO");
+ return;
+ }
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number(cfg,
- COMMUNICATOR_CONFIG_SECTION,
- "MAX_QUEUE_LENGTH",
- &max_queue_length))
+ GNUNET_CONFIGURATION_get_value_number (cfg,
+ COMMUNICATOR_CONFIG_SECTION,
+ "MAX_QUEUE_LENGTH",
+ &max_queue_length))
max_queue_length = DEFAULT_MAX_QUEUE_LENGTH;
- in = tcp_address_to_sockaddr(bindto, &in_len);
+ in = tcp_address_to_sockaddr (bindto, &in_len);
if (NULL == in)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Failed to setup TCP socket address with path `%s'\n",
- bindto);
- GNUNET_free(bindto);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to setup TCP socket address with path `%s'\n",
+ bindto);
+ GNUNET_free (bindto);
+ return;
+ }
listen_sock =
- GNUNET_NETWORK_socket_create(in->sa_family, SOCK_STREAM, IPPROTO_TCP);
+ GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP);
if (NULL == listen_sock)
- {
- GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket");
- GNUNET_free(in);
- GNUNET_free(bindto);
- return;
- }
- if (GNUNET_OK != GNUNET_NETWORK_socket_bind(listen_sock, in, in_len))
- {
- GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "bind", bindto);
- GNUNET_NETWORK_socket_close(listen_sock);
- listen_sock = NULL;
- GNUNET_free(in);
- GNUNET_free(bindto);
- return;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
+ GNUNET_free (in);
+ GNUNET_free (bindto);
+ return;
+ }
+ if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, in, in_len))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", bindto);
+ GNUNET_NETWORK_socket_close (listen_sock);
+ listen_sock = NULL;
+ GNUNET_free (in);
+ GNUNET_free (bindto);
+ return;
+ }
/* We might have bound to port 0, allowing the OS to figure it out;
thus, get the real IN-address from the socket */
sto_len = sizeof(in_sto);
- if (0 != getsockname(GNUNET_NETWORK_get_fd(listen_sock),
- (struct sockaddr *)&in_sto,
- &sto_len))
- {
- memcpy(&in_sto, in, in_len);
- sto_len = in_len;
- }
- GNUNET_free(in);
- GNUNET_free(bindto);
- in = (struct sockaddr *)&in_sto;
+ if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock),
+ (struct sockaddr *) &in_sto,
+ &sto_len))
+ {
+ memcpy (&in_sto, in, in_len);
+ sto_len = in_len;
+ }
+ GNUNET_free (in);
+ GNUNET_free (bindto);
+ in = (struct sockaddr *) &in_sto;
in_len = sto_len;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Bound to `%s'\n",
- GNUNET_a2s((const struct sockaddr *)&in_sto, sto_len));
- stats = GNUNET_STATISTICS_create("C-TCP", cfg);
- GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL);
- is = GNUNET_NT_scanner_init();
- my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration(cfg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Bound to `%s'\n",
+ GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
+ stats = GNUNET_STATISTICS_create ("C-TCP", cfg);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
+ is = GNUNET_NT_scanner_init ();
+ my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
if (NULL == my_private_key)
- {
- GNUNET_log(
- GNUNET_ERROR_TYPE_ERROR,
- _(
- "Transport service is lacking key configuration settings. Exiting.\n"));
- GNUNET_SCHEDULER_shutdown();
- return;
- }
- GNUNET_CRYPTO_eddsa_key_get_public(my_private_key, &my_identity.public_key);
+ {
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ (
+ "Transport service is lacking key configuration settings. Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key);
/* start listening */
- listen_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL,
- listen_sock,
- &listen_cb,
+ listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ listen_sock,
+ &listen_cb,
+ NULL);
+ queue_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
+ ch = GNUNET_TRANSPORT_communicator_connect (cfg,
+ COMMUNICATOR_CONFIG_SECTION,
+ COMMUNICATOR_ADDRESS_PREFIX,
+ GNUNET_TRANSPORT_CC_RELIABLE,
+ &mq_init,
+ NULL,
+ &enc_notify_cb,
NULL);
- queue_map = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO);
- ch = GNUNET_TRANSPORT_communicator_connect(cfg,
- COMMUNICATOR_CONFIG_SECTION,
- COMMUNICATOR_ADDRESS_PREFIX,
- GNUNET_TRANSPORT_CC_RELIABLE,
- &mq_init,
- NULL,
- &enc_notify_cb,
- NULL);
if (NULL == ch)
- {
- GNUNET_break(0);
- GNUNET_SCHEDULER_shutdown();
- return;
- }
- nat = GNUNET_NAT_register(cfg,
- COMMUNICATOR_CONFIG_SECTION,
- IPPROTO_TCP,
- 1 /* one address */,
- (const struct sockaddr **)&in,
- &in_len,
- &nat_address_cb,
- NULL /* FIXME: support reversal: #5529 */,
- NULL /* closure */);
+ {
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ nat = GNUNET_NAT_register (cfg,
+ COMMUNICATOR_CONFIG_SECTION,
+ IPPROTO_TCP,
+ 1 /* one address */,
+ (const struct sockaddr **) &in,
+ &in_len,
+ &nat_address_cb,
+ NULL /* FIXME: support reversal: #5529 */,
+ NULL /* closure */);
}
@@ -2189,26 +2197,26 @@ run(void *cls,
* @return 0 ok, 1 on error
*/
int
-main(int argc, char *const *argv)
+main (int argc, char *const *argv)
{
static const struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_OPTION_END
};
int ret;
- if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
- ret = (GNUNET_OK == GNUNET_PROGRAM_run(argc,
- argv,
- "gnunet-communicator-tcp",
- _("GNUnet TCP communicator"),
- options,
- &run,
- NULL))
+ ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-communicator-tcp",
+ _ ("GNUnet TCP communicator"),
+ options,
+ &run,
+ NULL))
? 0
: 1;
- GNUNET_free((void *)argv);
+ GNUNET_free ((void *) argv);
return ret;
}
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c
index 228540b81..2d9fabfec 100644
--- a/src/transport/gnunet-communicator-udp.c
+++ b/src/transport/gnunet-communicator-udp.c
@@ -67,7 +67,7 @@
* How often do we scan for changes to our network interfaces?
*/
#define INTERFACE_SCAN_FREQUENCY \
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
/**
* How long do we believe our addresses to remain up (before
@@ -156,7 +156,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
* the specified sender. If possible, the receiver should respond with
* a `struct UDPAck` (possibly via backchannel).
*/
-struct UdpHandshakeSignature {
+struct UdpHandshakeSignature
+{
/**
* Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE
*/
@@ -189,7 +190,8 @@ struct UdpHandshakeSignature {
* "Plaintext" header at beginning of KX message. Followed
* by encrypted `struct UDPConfirmation`.
*/
-struct InitialKX {
+struct InitialKX
+{
/**
* Ephemeral key for KX.
*/
@@ -207,7 +209,8 @@ struct InitialKX {
* Encrypted continuation of UDP initial handshake, followed
* by message header with payload.
*/
-struct UDPConfirmation {
+struct UDPConfirmation
+{
/**
* Sender's identity
*/
@@ -234,7 +237,8 @@ struct UDPConfirmation {
* UDP key acknowledgement. May be sent via backchannel. Allows the
* sender to use `struct UDPBox` with the acknowledge key henceforth.
*/
-struct UDPAck {
+struct UDPAck
+{
/**
* Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK.
*/
@@ -261,7 +265,8 @@ struct UDPAck {
* be just any global peer -- an attacker must have at least
* shared a LAN with the peer they're pretending to be here.
*/
-struct UdpBroadcastSignature {
+struct UdpBroadcastSignature
+{
/**
* Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST
*/
@@ -285,7 +290,8 @@ struct UdpBroadcastSignature {
* recognized in LAN as GNUnet peers if this feature is enabled
* anyway. Also, the entire message is in cleartext.
*/
-struct UDPBroadcast {
+struct UDPBroadcast
+{
/**
* Sender's peer identity.
*/
@@ -303,7 +309,8 @@ struct UDPBroadcast {
* UDP message box. Always sent encrypted, only allowed after
* the receiver sent a `struct UDPAck` for the base key!
*/
-struct UDPBox {
+struct UDPBox
+{
/**
* Key and IV identification code. KDF applied to an acknowledged
* base key and a sequence number. Sequence numbers must be used
@@ -336,7 +343,8 @@ struct SharedSecret;
* Pre-generated "kid" code (key and IV identification code) to
* quickly derive master key for a `struct UDPBox`.
*/
-struct KeyCacheEntry {
+struct KeyCacheEntry
+{
/**
* Kept in a DLL.
*/
@@ -383,7 +391,8 @@ struct ReceiverAddress;
/**
* Shared secret we generated for a particular sender or receiver.
*/
-struct SharedSecret {
+struct SharedSecret
+{
/**
* Kept in a DLL.
*/
@@ -448,7 +457,8 @@ struct SharedSecret {
* Information we track per sender address we have recently been
* in contact with (we decrypt messages from the sender).
*/
-struct SenderAddress {
+struct SenderAddress
+{
/**
* To whom are we talking to.
*/
@@ -500,7 +510,8 @@ struct SenderAddress {
* Information we track per receiving address we have recently been
* in contact with (encryption to receiver).
*/
-struct ReceiverAddress {
+struct ReceiverAddress
+{
/**
* To whom are we talking to.
*/
@@ -578,7 +589,8 @@ struct ReceiverAddress {
/**
* Interface we broadcast our presence on.
*/
-struct BroadcastInterface {
+struct BroadcastInterface
+{
/**
* Kept in a DLL.
*/
@@ -739,25 +751,25 @@ static uint16_t my_port;
* @param bi entity to close down
*/
static void
-bi_destroy(struct BroadcastInterface *bi)
+bi_destroy (struct BroadcastInterface *bi)
{
if (AF_INET6 == bi->sa->sa_family)
+ {
+ /* Leave the multicast group */
+ if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock,
+ IPPROTO_IPV6,
+ IPV6_LEAVE_GROUP,
+ &bi->mcreq,
+ sizeof(bi->mcreq)))
{
- /* Leave the multicast group */
- if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt(udp_sock,
- IPPROTO_IPV6,
- IPV6_LEAVE_GROUP,
- &bi->mcreq,
- sizeof(bi->mcreq)))
- {
- GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "setsockopt");
- }
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
}
- GNUNET_CONTAINER_DLL_remove(bi_head, bi_tail, bi);
- GNUNET_SCHEDULER_cancel(bi->broadcast_task);
- GNUNET_free(bi->sa);
- GNUNET_free_non_null(bi->ba);
- GNUNET_free(bi);
+ }
+ GNUNET_CONTAINER_DLL_remove (bi_head, bi_tail, bi);
+ GNUNET_SCHEDULER_cancel (bi->broadcast_task);
+ GNUNET_free (bi->sa);
+ GNUNET_free_non_null (bi->ba);
+ GNUNET_free (bi);
}
@@ -767,35 +779,35 @@ bi_destroy(struct BroadcastInterface *bi)
* @param receiver entity to close down
*/
static void
-receiver_destroy(struct ReceiverAddress *receiver)
+receiver_destroy (struct ReceiverAddress *receiver)
{
struct GNUNET_MQ_Handle *mq;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting receiver for peer `%s'\n",
- GNUNET_i2s(&receiver->target));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Disconnecting receiver for peer `%s'\n",
+ GNUNET_i2s (&receiver->target));
if (NULL != (mq = receiver->mq))
- {
- receiver->mq = NULL;
- GNUNET_MQ_destroy(mq);
- }
+ {
+ receiver->mq = NULL;
+ GNUNET_MQ_destroy (mq);
+ }
if (NULL != receiver->qh)
- {
- GNUNET_TRANSPORT_communicator_mq_del(receiver->qh);
- receiver->qh = NULL;
- }
- GNUNET_assert(GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove(receivers,
- &receiver->target,
- receiver));
- GNUNET_assert(receiver == GNUNET_CONTAINER_heap_remove_node(receiver->hn));
- GNUNET_STATISTICS_set(stats,
- "# receivers active",
- GNUNET_CONTAINER_multipeermap_size(receivers),
- GNUNET_NO);
- GNUNET_free(receiver->address);
- GNUNET_free(receiver->foreign_addr);
- GNUNET_free(receiver);
+ {
+ GNUNET_TRANSPORT_communicator_mq_del (receiver->qh);
+ receiver->qh = NULL;
+ }
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_remove (receivers,
+ &receiver->target,
+ receiver));
+ GNUNET_assert (receiver == GNUNET_CONTAINER_heap_remove_node (receiver->hn));
+ GNUNET_STATISTICS_set (stats,
+ "# receivers active",
+ GNUNET_CONTAINER_multipeermap_size (receivers),
+ GNUNET_NO);
+ GNUNET_free (receiver->address);
+ GNUNET_free (receiver->foreign_addr);
+ GNUNET_free (receiver);
}
@@ -805,16 +817,16 @@ receiver_destroy(struct ReceiverAddress *receiver)
* @param kce the key cache entry
*/
static void
-kce_destroy(struct KeyCacheEntry *kce)
+kce_destroy (struct KeyCacheEntry *kce)
{
struct SharedSecret *ss = kce->ss;
ss->active_kce_count--;
- GNUNET_CONTAINER_DLL_remove(ss->kce_head, ss->kce_tail, kce);
- GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove(key_cache,
- &kce->kid,
- kce));
- GNUNET_free(kce);
+ GNUNET_CONTAINER_DLL_remove (ss->kce_head, ss->kce_tail, kce);
+ GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove (key_cache,
+ &kce->kid,
+ kce));
+ GNUNET_free (kce);
}
@@ -826,24 +838,24 @@ kce_destroy(struct KeyCacheEntry *kce)
* @param kid[out] where to write the key ID
*/
static void
-get_kid(const struct GNUNET_HashCode *msec,
- uint32_t serial,
- struct GNUNET_ShortHashCode *kid)
+get_kid (const struct GNUNET_HashCode *msec,
+ uint32_t serial,
+ struct GNUNET_ShortHashCode *kid)
{
- uint32_t sid = htonl(serial);
-
- GNUNET_CRYPTO_hkdf(kid,
- sizeof(*kid),
- GCRY_MD_SHA512,
- GCRY_MD_SHA256,
- &sid,
- sizeof(sid),
- msec,
- sizeof(*msec),
- "UDP-KID",
- strlen("UDP-KID"),
- NULL,
- 0);
+ uint32_t sid = htonl (serial);
+
+ GNUNET_CRYPTO_hkdf (kid,
+ sizeof(*kid),
+ GCRY_MD_SHA512,
+ GCRY_MD_SHA256,
+ &sid,
+ sizeof(sid),
+ msec,
+ sizeof(*msec),
+ "UDP-KID",
+ strlen ("UDP-KID"),
+ NULL,
+ 0);
}
@@ -854,26 +866,26 @@ get_kid(const struct GNUNET_HashCode *msec,
* @param seq sequence number for the key cache entry
*/
static void
-kce_generate(struct SharedSecret *ss, uint32_t seq)
+kce_generate (struct SharedSecret *ss, uint32_t seq)
{
struct KeyCacheEntry *kce;
- GNUNET_assert(0 < seq);
- kce = GNUNET_new(struct KeyCacheEntry);
+ GNUNET_assert (0 < seq);
+ kce = GNUNET_new (struct KeyCacheEntry);
kce->ss = ss;
kce->sequence_number = seq;
- get_kid(&ss->master, seq, &kce->kid);
- GNUNET_CONTAINER_DLL_insert(ss->kce_head, ss->kce_tail, kce);
+ get_kid (&ss->master, seq, &kce->kid);
+ GNUNET_CONTAINER_DLL_insert (ss->kce_head, ss->kce_tail, kce);
ss->active_kce_count++;
- (void)GNUNET_CONTAINER_multishortmap_put(
+ (void) GNUNET_CONTAINER_multishortmap_put (
key_cache,
&kce->kid,
kce,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
- GNUNET_STATISTICS_set(stats,
- "# KIDs active",
- GNUNET_CONTAINER_multishortmap_size(key_cache),
- GNUNET_NO);
+ GNUNET_STATISTICS_set (stats,
+ "# KIDs active",
+ GNUNET_CONTAINER_multishortmap_size (key_cache),
+ GNUNET_NO);
}
@@ -883,31 +895,31 @@ kce_generate(struct SharedSecret *ss, uint32_t seq)
* @param ss shared secret to destroy
*/
static void
-secret_destroy(struct SharedSecret *ss)
+secret_destroy (struct SharedSecret *ss)
{
struct SenderAddress *sender;
struct ReceiverAddress *receiver;
struct KeyCacheEntry *kce;
if (NULL != (sender = ss->sender))
- {
- GNUNET_CONTAINER_DLL_remove(sender->ss_head, sender->ss_tail, ss);
- sender->num_secrets--;
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (sender->ss_head, sender->ss_tail, ss);
+ sender->num_secrets--;
+ }
if (NULL != (receiver = ss->receiver))
- {
- GNUNET_CONTAINER_DLL_remove(receiver->ss_head, receiver->ss_tail, ss);
- receiver->num_secrets--;
- receiver->acks_available -= (ss->sequence_allowed - ss->sequence_used);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss);
+ receiver->num_secrets--;
+ receiver->acks_available -= (ss->sequence_allowed - ss->sequence_used);
+ }
while (NULL != (kce = ss->kce_head))
- kce_destroy(kce);
- GNUNET_STATISTICS_update(stats, "# Secrets active", -1, GNUNET_NO);
- GNUNET_STATISTICS_set(stats,
- "# KIDs active",
- GNUNET_CONTAINER_multishortmap_size(key_cache),
- GNUNET_NO);
- GNUNET_free(ss);
+ kce_destroy (kce);
+ GNUNET_STATISTICS_update (stats, "# Secrets active", -1, GNUNET_NO);
+ GNUNET_STATISTICS_set (stats,
+ "# KIDs active",
+ GNUNET_CONTAINER_multishortmap_size (key_cache),
+ GNUNET_NO);
+ GNUNET_free (ss);
}
@@ -918,18 +930,18 @@ secret_destroy(struct SharedSecret *ss)
* @param sender entity to close down
*/
static void
-sender_destroy(struct SenderAddress *sender)
+sender_destroy (struct SenderAddress *sender)
{
- GNUNET_assert(
+ GNUNET_assert (
GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove(senders, &sender->target, sender));
- GNUNET_assert(sender == GNUNET_CONTAINER_heap_remove_node(sender->hn));
- GNUNET_STATISTICS_set(stats,
- "# senders active",
- GNUNET_CONTAINER_multipeermap_size(senders),
- GNUNET_NO);
- GNUNET_free(sender->address);
- GNUNET_free(sender);
+ GNUNET_CONTAINER_multipeermap_remove (senders, &sender->target, sender));
+ GNUNET_assert (sender == GNUNET_CONTAINER_heap_remove_node (sender->hn));
+ GNUNET_STATISTICS_set (stats,
+ "# senders active",
+ GNUNET_CONTAINER_multipeermap_size (senders),
+ GNUNET_NO);
+ GNUNET_free (sender->address);
+ GNUNET_free (sender);
}
@@ -942,28 +954,28 @@ sender_destroy(struct SenderAddress *sender)
* @param iv[out] where to write the IV
*/
static void
-get_iv_key(const struct GNUNET_HashCode *msec,
- uint32_t serial,
- char key[AES_KEY_SIZE],
- char iv[AES_IV_SIZE])
+get_iv_key (const struct GNUNET_HashCode *msec,
+ uint32_t serial,
+ char key[AES_KEY_SIZE],
+ char iv[AES_IV_SIZE])
{
- uint32_t sid = htonl(serial);
+ uint32_t sid = htonl (serial);
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);
- memcpy(key, res, AES_KEY_SIZE);
- memcpy(iv, &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);
+ memcpy (key, res, AES_KEY_SIZE);
+ memcpy (iv, &res[AES_KEY_SIZE], AES_IV_SIZE);
}
@@ -973,11 +985,11 @@ get_iv_key(const struct GNUNET_HashCode *msec,
* @param sender address for which the timeout should be rescheduled
*/
static void
-reschedule_sender_timeout(struct SenderAddress *sender)
+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);
+ GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ GNUNET_CONTAINER_heap_update_cost (sender->hn, sender->timeout.abs_value_us);
}
@@ -987,12 +999,12 @@ reschedule_sender_timeout(struct SenderAddress *sender)
* @param receiver address for which the timeout should be rescheduled
*/
static void
-reschedule_receiver_timeout(struct ReceiverAddress *receiver)
+reschedule_receiver_timeout (struct ReceiverAddress *receiver)
{
receiver->timeout =
- GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
- GNUNET_CONTAINER_heap_update_cost(receiver->hn,
- receiver->timeout.abs_value_us);
+ GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ GNUNET_CONTAINER_heap_update_cost (receiver->hn,
+ receiver->timeout.abs_value_us);
}
@@ -1002,7 +1014,7 @@ reschedule_receiver_timeout(struct ReceiverAddress *receiver)
* @param cls unused, NULL
*/
static void
-check_timeouts(void *cls)
+check_timeouts (void *cls)
{
struct GNUNET_TIME_Relative st;
struct GNUNET_TIME_Relative rt;
@@ -1010,27 +1022,27 @@ check_timeouts(void *cls)
struct ReceiverAddress *receiver;
struct SenderAddress *sender;
- (void)cls;
+ (void) cls;
timeout_task = NULL;
rt = GNUNET_TIME_UNIT_FOREVER_REL;
- while (NULL != (receiver = GNUNET_CONTAINER_heap_peek(receivers_heap)))
- {
- rt = GNUNET_TIME_absolute_get_remaining(receiver->timeout);
- if (0 != rt.rel_value_us)
- break;
- receiver_destroy(receiver);
- }
+ while (NULL != (receiver = GNUNET_CONTAINER_heap_peek (receivers_heap)))
+ {
+ rt = GNUNET_TIME_absolute_get_remaining (receiver->timeout);
+ if (0 != rt.rel_value_us)
+ break;
+ receiver_destroy (receiver);
+ }
st = GNUNET_TIME_UNIT_FOREVER_REL;
- while (NULL != (sender = GNUNET_CONTAINER_heap_peek(senders_heap)))
- {
- st = GNUNET_TIME_absolute_get_remaining(sender->timeout);
- if (0 != st.rel_value_us)
- break;
- sender_destroy(sender);
- }
- delay = GNUNET_TIME_relative_min(rt, st);
+ while (NULL != (sender = GNUNET_CONTAINER_heap_peek (senders_heap)))
+ {
+ st = GNUNET_TIME_absolute_get_remaining (sender->timeout);
+ if (0 != st.rel_value_us)
+ break;
+ sender_destroy (sender);
+ }
+ delay = GNUNET_TIME_relative_min (rt, st);
if (delay.rel_value_us < GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
- timeout_task = GNUNET_SCHEDULER_add_delayed(delay, &check_timeouts, NULL);
+ timeout_task = GNUNET_SCHEDULER_add_delayed (delay, &check_timeouts, NULL);
}
@@ -1040,20 +1052,20 @@ check_timeouts(void *cls)
* @param ss[in,out] data structure to complete
*/
static void
-calculate_cmac(struct SharedSecret *ss)
+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);
+ 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);
}
@@ -1066,36 +1078,36 @@ calculate_cmac(struct SharedSecret *ss)
* @param plaintext_len number of bytes of plaintext received
*/
static void
-pass_plaintext_to_core(struct SenderAddress *sender,
- const void *plaintext,
- size_t plaintext_len)
+pass_plaintext_to_core (struct SenderAddress *sender,
+ const void *plaintext,
+ size_t plaintext_len)
{
const struct GNUNET_MessageHeader *hdr = plaintext;
- while (ntohs(hdr->size) < plaintext_len)
- {
- GNUNET_STATISTICS_update(stats,
- "# bytes given to core",
- ntohs(hdr->size),
- GNUNET_NO);
- (void)
- GNUNET_TRANSPORT_communicator_receive(ch,
- &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))
- break;
- hdr = plaintext + ntohs(hdr->size);
- }
- GNUNET_STATISTICS_update(stats,
- "# bytes padding discarded",
- plaintext_len,
- GNUNET_NO);
+ while (ntohs (hdr->size) < plaintext_len)
+ {
+ GNUNET_STATISTICS_update (stats,
+ "# bytes given to core",
+ ntohs (hdr->size),
+ GNUNET_NO);
+ (void)
+ GNUNET_TRANSPORT_communicator_receive (ch,
+ &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))
+ break;
+ hdr = plaintext + ntohs (hdr->size);
+ }
+ GNUNET_STATISTICS_update (stats,
+ "# bytes padding discarded",
+ plaintext_len,
+ GNUNET_NO);
}
@@ -1108,20 +1120,20 @@ pass_plaintext_to_core(struct SenderAddress *sender,
* @param cipher[out] cipher to initialize
*/
static void
-setup_cipher(const struct GNUNET_HashCode *msec,
- uint32_t serial,
- gcry_cipher_hd_t *cipher)
+setup_cipher (const struct GNUNET_HashCode *msec,
+ 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 */);
- get_iv_key(msec, serial, key, iv);
- gcry_cipher_setkey(*cipher, key, sizeof(key));
- gcry_cipher_setiv(*cipher, iv, sizeof(iv));
+ gcry_cipher_open (cipher,
+ GCRY_CIPHER_AES256 /* low level: go for speed */,
+ GCRY_CIPHER_MODE_GCM,
+ 0 /* flags */);
+ get_iv_key (msec, serial, key, iv);
+ gcry_cipher_setkey (*cipher, key, sizeof(key));
+ gcry_cipher_setiv (*cipher, iv, sizeof(iv));
}
@@ -1138,29 +1150,29 @@ setup_cipher(const struct GNUNET_HashCode *msec,
* @return #GNUNET_OK on success
*/
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)
+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)
{
gcry_cipher_hd_t cipher;
- setup_cipher(&ss->master, serial, &cipher);
- GNUNET_assert(
+ setup_cipher (&ss->master, serial, &cipher);
+ GNUNET_assert (
0 ==
- gcry_cipher_decrypt(cipher, out_buf, in_buf_size, in_buf, in_buf_size));
- if (0 != gcry_cipher_checktag(cipher, tag, GCM_TAG_SIZE))
- {
- gcry_cipher_close(cipher);
- GNUNET_STATISTICS_update(stats,
- "# AEAD authentication failures",
- 1,
- GNUNET_NO);
- return GNUNET_SYSERR;
- }
- gcry_cipher_close(cipher);
+ gcry_cipher_decrypt (cipher, out_buf, in_buf_size, in_buf, in_buf_size));
+ if (0 != gcry_cipher_checktag (cipher, tag, GCM_TAG_SIZE))
+ {
+ gcry_cipher_close (cipher);
+ GNUNET_STATISTICS_update (stats,
+ "# AEAD authentication failures",
+ 1,
+ GNUNET_NO);
+ return GNUNET_SYSERR;
+ }
+ gcry_cipher_close (cipher);
return GNUNET_OK;
}
@@ -1172,12 +1184,12 @@ try_decrypt(const struct SharedSecret *ss,
* @return new shared secret
*/
static struct SharedSecret *
-setup_shared_secret_dec(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral)
+setup_shared_secret_dec (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral)
{
struct SharedSecret *ss;
- ss = GNUNET_new(struct SharedSecret);
- GNUNET_CRYPTO_eddsa_ecdh(my_private_key, ephemeral, &ss->master);
+ ss = GNUNET_new (struct SharedSecret);
+ GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &ss->master);
return ss;
}
@@ -1190,20 +1202,20 @@ setup_shared_secret_dec(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral)
* @return new shared secret
*/
static struct SharedSecret *
-setup_shared_secret_enc(const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral,
- struct ReceiverAddress *receiver)
+setup_shared_secret_enc (const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral,
+ struct ReceiverAddress *receiver)
{
struct SharedSecret *ss;
- ss = GNUNET_new(struct SharedSecret);
- GNUNET_CRYPTO_ecdh_eddsa(ephemeral,
- &receiver->target.public_key,
- &ss->master);
- calculate_cmac(ss);
+ ss = GNUNET_new (struct SharedSecret);
+ GNUNET_CRYPTO_ecdh_eddsa (ephemeral,
+ &receiver->target.public_key,
+ &ss->master);
+ calculate_cmac (ss);
ss->receiver = receiver;
- GNUNET_CONTAINER_DLL_insert(receiver->ss_head, receiver->ss_tail, ss);
+ GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss);
receiver->num_secrets++;
- GNUNET_STATISTICS_update(stats, "# Secrets active", 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (stats, "# Secrets active", 1, GNUNET_NO);
return ss;
}
@@ -1216,7 +1228,7 @@ setup_shared_secret_enc(const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral,
* @param receiver receiver to setup MQ for
*/
static void
-setup_receiver_mq(struct ReceiverAddress *receiver);
+setup_receiver_mq (struct ReceiverAddress *receiver);
/**
@@ -1230,36 +1242,36 @@ setup_receiver_mq(struct ReceiverAddress *receiver);
* @return #GNUNET_YES to continue to iterate
*/
static int
-handle_ack(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
+handle_ack (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
{
const struct UDPAck *ack = cls;
struct ReceiverAddress *receiver = value;
- (void)pid;
+ (void) pid;
for (struct SharedSecret *ss = receiver->ss_head; NULL != ss; ss = ss->next)
+ {
+ if (0 == memcmp (&ack->cmac, &ss->cmac, sizeof(struct GNUNET_HashCode)))
{
- if (0 == memcmp(&ack->cmac, &ss->cmac, sizeof(struct GNUNET_HashCode)))
+ uint32_t allowed;
+
+ allowed = ntohl (ack->sequence_max);
+
+ if (allowed > ss->sequence_allowed)
+ {
+ receiver->acks_available += (allowed - ss->sequence_allowed);
+ if ((allowed - ss->sequence_allowed) == receiver->acks_available)
{
- uint32_t allowed;
-
- allowed = ntohl(ack->sequence_max);
-
- 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);
- }
- return GNUNET_NO;
+ /* 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;
}
+ }
return GNUNET_YES;
}
@@ -1273,41 +1285,41 @@ handle_ack(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
* @param buf_size number of bytes in @a buf
*/
static void
-try_handle_plaintext(struct SenderAddress *sender,
- const void *buf,
- size_t buf_size)
+try_handle_plaintext (struct SenderAddress *sender,
+ const void *buf,
+ size_t buf_size)
{
const struct GNUNET_MessageHeader *hdr =
- (const struct GNUNET_MessageHeader *)buf;
- const struct UDPAck *ack = (const struct UDPAck *)buf;
+ (const struct GNUNET_MessageHeader *) buf;
+ const struct UDPAck *ack = (const struct UDPAck *) buf;
uint16_t type;
if (sizeof(*hdr) > buf_size)
return; /* not even a header */
- if (ntohs(hdr->size) > buf_size)
+ if (ntohs (hdr->size) > buf_size)
return; /* not even a header */
- type = ntohs(hdr->type);
+ type = ntohs (hdr->type);
switch (type)
- {
- 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);
- /* 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);
- break;
-
- case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD:
- /* skip padding */
- break;
-
- default:
- pass_plaintext_to_core(sender, buf, buf_size);
- }
+ {
+ 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);
+ /* 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);
+ break;
+
+ case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD:
+ /* skip padding */
+ break;
+
+ default:
+ pass_plaintext_to_core (sender, buf, buf_size);
+ }
}
@@ -1320,29 +1332,29 @@ try_handle_plaintext(struct SenderAddress *sender,
* @param ss shared secret to generate ACKs for
*/
static void
-consider_ss_ack(struct SharedSecret *ss)
+consider_ss_ack (struct SharedSecret *ss)
{
- GNUNET_assert(NULL != ss->sender);
+ GNUNET_assert (NULL != ss->sender);
/* drop ancient KeyCacheEntries */
while ((NULL != ss->kce_head) &&
(MAX_SQN_DELTA <
ss->kce_head->sequence_number - ss->kce_tail->sequence_number))
- kce_destroy(ss->kce_tail);
+ kce_destroy (ss->kce_tail);
if (ss->active_kce_count < KCN_THRESHOLD)
- {
- struct UDPAck ack;
-
- while (ss->active_kce_count < KCN_TARGET)
- kce_generate(ss, ++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);
- ack.cmac = ss->cmac;
- GNUNET_TRANSPORT_communicator_notify(ch,
- &ss->sender->target,
- COMMUNICATOR_ADDRESS_PREFIX,
- &ack.header);
- }
+ {
+ struct UDPAck ack;
+
+ while (ss->active_kce_count < KCN_TARGET)
+ kce_generate (ss, ++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);
+ ack.cmac = ss->cmac;
+ GNUNET_TRANSPORT_communicator_notify (ch,
+ &ss->sender->target,
+ COMMUNICATOR_ADDRESS_PREFIX,
+ &ack.header);
+ }
}
@@ -1354,42 +1366,43 @@ consider_ss_ack(struct SharedSecret *ss)
* @param kce key index to decrypt @a box
*/
static void
-decrypt_box(const struct UDPBox *box,
- size_t box_len,
- struct KeyCacheEntry *kce)
+decrypt_box (const struct UDPBox *box,
+ 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))
- {
- GNUNET_STATISTICS_update(stats,
- "# Decryption failures with valid KCE",
- 1,
- GNUNET_NO);
- kce_destroy(kce);
- return;
- }
- kce_destroy(kce);
- GNUNET_STATISTICS_update(stats,
- "# bytes decrypted with BOX",
- sizeof(out_buf),
- GNUNET_NO);
- try_handle_plaintext(ss->sender, out_buf, sizeof(out_buf));
- consider_ss_ack(ss);
+ 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))
+ {
+ GNUNET_STATISTICS_update (stats,
+ "# Decryption failures with valid KCE",
+ 1,
+ GNUNET_NO);
+ kce_destroy (kce);
+ return;
+ }
+ kce_destroy (kce);
+ GNUNET_STATISTICS_update (stats,
+ "# bytes decrypted with BOX",
+ sizeof(out_buf),
+ GNUNET_NO);
+ try_handle_plaintext (ss->sender, out_buf, sizeof(out_buf));
+ consider_ss_ack (ss);
}
/**
* Closure for #find_sender_by_address()
*/
-struct SearchContext {
+struct SearchContext
+{
/**
* Address we are looking for.
*/
@@ -1416,19 +1429,19 @@ struct SearchContext {
* @return #GNUNET_YES if not found (continue to search), #GNUNET_NO if found
*/
static int
-find_sender_by_address(void *cls,
- const struct GNUNET_PeerIdentity *key,
- void *value)
+find_sender_by_address (void *cls,
+ 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->sender = sender;
- return GNUNET_NO; /* stop iterating! */
- }
+ (0 == memcmp (sender->address, sc->address, sender->address_len)))
+ {
+ sc->sender = sender;
+ return GNUNET_NO; /* stop iterating! */
+ }
return GNUNET_YES;
}
@@ -1445,45 +1458,45 @@ find_sender_by_address(void *cls,
* decrypting data from @a target
*/
static struct SenderAddress *
-setup_sender(const struct GNUNET_PeerIdentity *target,
- const struct sockaddr *address,
- socklen_t address_len)
+setup_sender (const struct GNUNET_PeerIdentity *target,
+ const struct sockaddr *address,
+ socklen_t address_len)
{
struct SenderAddress *sender;
struct SearchContext sc = { .address = address,
.address_len = address_len,
.sender = NULL };
- GNUNET_CONTAINER_multipeermap_get_multiple(senders,
- target,
- &find_sender_by_address,
- &sc);
+ GNUNET_CONTAINER_multipeermap_get_multiple (senders,
+ target,
+ &find_sender_by_address,
+ &sc);
if (NULL != sc.sender)
- {
- reschedule_sender_timeout(sc.sender);
- return sc.sender;
- }
- sender = GNUNET_new(struct SenderAddress);
+ {
+ reschedule_sender_timeout (sc.sender);
+ return sc.sender;
+ }
+ sender = GNUNET_new (struct SenderAddress);
sender->target = *target;
- sender->address = GNUNET_memdup(address, address_len);
+ sender->address = GNUNET_memdup (address, address_len);
sender->address_len = address_len;
- (void)GNUNET_CONTAINER_multipeermap_put(
+ (void) GNUNET_CONTAINER_multipeermap_put (
senders,
&sender->target,
sender,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
- GNUNET_STATISTICS_set(stats,
- "# senders active",
- GNUNET_CONTAINER_multipeermap_size(receivers),
- GNUNET_NO);
+ GNUNET_STATISTICS_set (stats,
+ "# 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->nt = GNUNET_NT_scanner_get_type(is, address, address_len);
+ 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->nt = GNUNET_NT_scanner_get_type (is, address, address_len);
if (NULL == timeout_task)
- timeout_task = GNUNET_SCHEDULER_add_now(&check_timeouts, NULL);
+ timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL);
return sender;
}
@@ -1496,21 +1509,22 @@ setup_sender(const struct GNUNET_PeerIdentity *target,
* @return #GNUNET_OK if signature is valid
*/
static int
-verify_confirmation(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral,
- const struct UDPConfirmation *uc)
+verify_confirmation (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral,
+ const struct UDPConfirmation *uc)
{
struct UdpHandshakeSignature uhs;
- uhs.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE);
- uhs.purpose.size = htonl(sizeof(uhs));
+ uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE);
+ uhs.purpose.size = htonl (sizeof(uhs));
uhs.sender = uc->sender;
uhs.receiver = my_identity;
uhs.ephemeral = *ephemeral;
uhs.monotonic_time = uc->monotonic_time;
- return GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE,
- &uhs.purpose,
- &uc->sender_sig,
- &uc->sender.public_key);
+ return GNUNET_CRYPTO_eddsa_verify (
+ GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE,
+ &uhs.purpose,
+ &uc->sender_sig,
+ &uc->sender.public_key);
}
@@ -1523,30 +1537,30 @@ verify_confirmation(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral,
* @return string representation of @a address
*/
static char *
-sockaddr_to_udpaddr_string(const struct sockaddr *address,
- socklen_t address_len)
+sockaddr_to_udpaddr_string (const struct sockaddr *address,
+ socklen_t address_len)
{
char *ret;
switch (address->sa_family)
- {
- case AF_INET:
- GNUNET_asprintf(&ret,
- "%s-%s",
- COMMUNICATOR_ADDRESS_PREFIX,
- GNUNET_a2s(address, address_len));
- break;
-
- case AF_INET6:
- GNUNET_asprintf(&ret,
- "%s-%s",
- COMMUNICATOR_ADDRESS_PREFIX,
- GNUNET_a2s(address, address_len));
- break;
-
- default:
- GNUNET_assert(0);
- }
+ {
+ case AF_INET:
+ GNUNET_asprintf (&ret,
+ "%s-%s",
+ COMMUNICATOR_ADDRESS_PREFIX,
+ GNUNET_a2s (address, address_len));
+ break;
+
+ case AF_INET6:
+ GNUNET_asprintf (&ret,
+ "%s-%s",
+ COMMUNICATOR_ADDRESS_PREFIX,
+ GNUNET_a2s (address, address_len));
+ break;
+
+ default:
+ GNUNET_assert (0);
+ }
return ret;
}
@@ -1557,87 +1571,87 @@ sockaddr_to_udpaddr_string(const struct sockaddr *address,
* @param cls NULL
*/
static void
-sock_read(void *cls)
+sock_read (void *cls)
{
struct sockaddr_storage sa;
socklen_t salen = sizeof(sa);
char buf[UINT16_MAX];
ssize_t rcvd;
- (void)cls;
- read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL,
- udp_sock,
- &sock_read,
- NULL);
- rcvd = GNUNET_NETWORK_socket_recvfrom(udp_sock,
- buf,
- sizeof(buf),
- (struct sockaddr *)&sa,
- &salen);
+ (void) cls;
+ read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ udp_sock,
+ &sock_read,
+ NULL);
+ rcvd = GNUNET_NETWORK_socket_recvfrom (udp_sock,
+ buf,
+ sizeof(buf),
+ (struct sockaddr *) &sa,
+ &salen);
if (-1 == rcvd)
- {
- GNUNET_log_strerror(GNUNET_ERROR_TYPE_DEBUG, "recv");
- return;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv");
+ return;
+ }
/* first, see if it is a UDPBox */
if (rcvd > sizeof(struct UDPBox))
- {
- const struct UDPBox *box;
- struct KeyCacheEntry *kce;
+ {
+ const struct UDPBox *box;
+ struct KeyCacheEntry *kce;
- box = (const struct UDPBox *)buf;
- kce = GNUNET_CONTAINER_multishortmap_get(key_cache, &box->kid);
- if (NULL != kce)
- {
- decrypt_box(box, (size_t)rcvd, kce);
- return;
- }
+ box = (const struct UDPBox *) buf;
+ kce = GNUNET_CONTAINER_multishortmap_get (key_cache, &box->kid);
+ if (NULL != kce)
+ {
+ decrypt_box (box, (size_t) rcvd, kce);
+ return;
}
+ }
/* next, check if it is a broadcast */
if (sizeof(struct UDPBroadcast) == rcvd)
+ {
+ const struct UDPBroadcast *ub;
+ struct UdpBroadcastSignature uhs;
+
+ ub = (const struct UDPBroadcast *) buf;
+ uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST);
+ uhs.purpose.size = htonl (sizeof(uhs));
+ uhs.sender = ub->sender;
+ GNUNET_CRYPTO_hash (&sa, salen, &uhs.h_address);
+ if (GNUNET_OK ==
+ GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST,
+ &uhs.purpose,
+ &ub->sender_sig,
+ &ub->sender.public_key))
{
- const struct UDPBroadcast *ub;
- struct UdpBroadcastSignature uhs;
-
- ub = (const struct UDPBroadcast *)buf;
- uhs.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST);
- uhs.purpose.size = htonl(sizeof(uhs));
- uhs.sender = ub->sender;
- GNUNET_CRYPTO_hash(&sa, salen, &uhs.h_address);
- if (GNUNET_OK ==
- GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST,
- &uhs.purpose,
- &ub->sender_sig,
- &ub->sender.public_key))
- {
- char *addr_s;
- enum GNUNET_NetworkType nt;
-
- addr_s =
- sockaddr_to_udpaddr_string((const struct sockaddr *)&sa, salen);
- GNUNET_STATISTICS_update(stats, "# broadcasts received", 1, GNUNET_NO);
- /* use our own mechanism to determine network type */
- nt =
- GNUNET_NT_scanner_get_type(is, (const struct sockaddr *)&sa, salen);
- GNUNET_TRANSPORT_application_validate(ah, &ub->sender, nt, addr_s);
- GNUNET_free(addr_s);
- return;
- }
- /* continue with KX, mostly for statistics... */
+ char *addr_s;
+ enum GNUNET_NetworkType nt;
+
+ addr_s =
+ sockaddr_to_udpaddr_string ((const struct sockaddr *) &sa, salen);
+ GNUNET_STATISTICS_update (stats, "# broadcasts received", 1, GNUNET_NO);
+ /* use our own mechanism to determine network type */
+ nt =
+ GNUNET_NT_scanner_get_type (is, (const struct sockaddr *) &sa, salen);
+ GNUNET_TRANSPORT_application_validate (ah, &ub->sender, nt, addr_s);
+ GNUNET_free (addr_s);
+ return;
}
+ /* continue with KX, mostly for statistics... */
+ }
/* finally, test if it is a KX */
if (rcvd < sizeof(struct UDPConfirmation) + sizeof(struct InitialKX))
- {
- GNUNET_STATISTICS_update(stats,
- "# messages dropped (no kid, too small for KX)",
- 1,
- GNUNET_NO);
- return;
- }
+ {
+ GNUNET_STATISTICS_update (stats,
+ "# messages dropped (no kid, too small for KX)",
+ 1,
+ GNUNET_NO);
+ return;
+ }
{
const struct InitialKX *kx;
@@ -1646,48 +1660,48 @@ sock_read(void *cls)
const struct UDPConfirmation *uc;
struct SenderAddress *sender;
- kx = (const struct InitialKX *)buf;
- ss = setup_shared_secret_dec(&kx->ephemeral);
- if (GNUNET_OK != try_decrypt(ss,
- kx->gcm_tag,
- 0,
- &buf[sizeof(*kx)],
- sizeof(pbuf),
- pbuf))
- {
- GNUNET_free(ss);
- GNUNET_STATISTICS_update(
- stats,
- "# messages dropped (no kid, AEAD decryption failed)",
- 1,
- GNUNET_NO);
- return;
- }
- uc = (const struct UDPConfirmation *)pbuf;
- if (GNUNET_OK != verify_confirmation(&kx->ephemeral, uc))
- {
- GNUNET_break_op(0);
- GNUNET_free(ss);
- GNUNET_STATISTICS_update(stats,
- "# messages dropped (sender signature invalid)",
- 1,
- GNUNET_NO);
- return;
- }
- calculate_cmac(ss);
- sender = setup_sender(&uc->sender, (const struct sockaddr *)&sa, salen);
+ kx = (const struct InitialKX *) buf;
+ ss = setup_shared_secret_dec (&kx->ephemeral);
+ if (GNUNET_OK != try_decrypt (ss,
+ kx->gcm_tag,
+ 0,
+ &buf[sizeof(*kx)],
+ sizeof(pbuf),
+ pbuf))
+ {
+ GNUNET_free (ss);
+ GNUNET_STATISTICS_update (
+ stats,
+ "# messages dropped (no kid, AEAD decryption failed)",
+ 1,
+ GNUNET_NO);
+ return;
+ }
+ uc = (const struct UDPConfirmation *) pbuf;
+ if (GNUNET_OK != verify_confirmation (&kx->ephemeral, uc))
+ {
+ GNUNET_break_op (0);
+ GNUNET_free (ss);
+ GNUNET_STATISTICS_update (stats,
+ "# messages dropped (sender signature invalid)",
+ 1,
+ GNUNET_NO);
+ return;
+ }
+ calculate_cmac (ss);
+ sender = setup_sender (&uc->sender, (const struct sockaddr *) &sa, salen);
ss->sender = sender;
- GNUNET_CONTAINER_DLL_insert(sender->ss_head, sender->ss_tail, ss);
+ GNUNET_CONTAINER_DLL_insert (sender->ss_head, sender->ss_tail, ss);
sender->num_secrets++;
- GNUNET_STATISTICS_update(stats, "# Secrets active", 1, GNUNET_NO);
- GNUNET_STATISTICS_update(stats,
- "# messages decrypted without BOX",
- 1,
- GNUNET_NO);
- try_handle_plaintext(sender, &uc[1], sizeof(pbuf) - sizeof(*uc));
- consider_ss_ack(ss);
+ GNUNET_STATISTICS_update (stats, "# Secrets active", 1, GNUNET_NO);
+ GNUNET_STATISTICS_update (stats,
+ "# messages decrypted without BOX",
+ 1,
+ GNUNET_NO);
+ try_handle_plaintext (sender, &uc[1], sizeof(pbuf) - sizeof(*uc));
+ consider_ss_ack (ss);
if (sender->num_secrets > MAX_SECRETS)
- secret_destroy(sender->ss_tail);
+ secret_destroy (sender->ss_tail);
}
}
@@ -1700,7 +1714,7 @@ sock_read(void *cls)
* @return converted bindto specification
*/
static struct sockaddr *
-udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
+udp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
{
struct sockaddr *in;
unsigned int port;
@@ -1708,88 +1722,88 @@ udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
char *colon;
char *cp;
- if (1 == sscanf(bindto, "%u%1s", &port, dummy))
+ if (1 == sscanf (bindto, "%u%1s", &port, dummy))
+ {
+ /* interpreting value as just a PORT number */
+ if (port > UINT16_MAX)
{
- /* 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);
- return NULL;
- }
- if ((GNUNET_NO == GNUNET_NETWORK_test_pf(PF_INET6)) ||
- (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno(cfg,
- COMMUNICATOR_CONFIG_SECTION,
- "DISABLE_V6")))
- {
- struct sockaddr_in *i4;
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "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")))
+ {
+ struct sockaddr_in *i4;
- i4 = GNUNET_malloc(sizeof(struct sockaddr_in));
- i4->sin_family = AF_INET;
- i4->sin_port = htons((uint16_t)port);
- *sock_len = sizeof(struct sockaddr_in);
- in = (struct sockaddr *)i4;
- }
- else
- {
- struct sockaddr_in6 *i6;
+ i4 = GNUNET_malloc (sizeof(struct sockaddr_in));
+ i4->sin_family = AF_INET;
+ i4->sin_port = htons ((uint16_t) port);
+ *sock_len = sizeof(struct sockaddr_in);
+ in = (struct sockaddr *) i4;
+ }
+ else
+ {
+ struct sockaddr_in6 *i6;
- i6 = GNUNET_malloc(sizeof(struct sockaddr_in6));
- i6->sin6_family = AF_INET6;
- i6->sin6_port = htons((uint16_t)port);
- *sock_len = sizeof(struct sockaddr_in6);
- in = (struct sockaddr *)i6;
- }
- return in;
+ i6 = GNUNET_malloc (sizeof(struct sockaddr_in6));
+ i6->sin6_family = AF_INET6;
+ i6->sin6_port = htons ((uint16_t) port);
+ *sock_len = sizeof(struct sockaddr_in6);
+ in = (struct sockaddr *) i6;
}
- cp = GNUNET_strdup(bindto);
- colon = strrchr(cp, ':');
+ return in;
+ }
+ cp = GNUNET_strdup (bindto);
+ colon = strrchr (cp, ':');
if (NULL != colon)
+ {
+ /* interpet value after colon as port */
+ *colon = '\0';
+ colon++;
+ if (1 == sscanf (colon, "%u%1s", &port, dummy))
{
- /* interpet value after colon as port */
- *colon = '\0';
- colon++;
- if (1 == sscanf(colon, "%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;
- }
- }
- else
- {
- GNUNET_log(
- GNUNET_ERROR_TYPE_ERROR,
- "BINDTO specification `%s' invalid: last ':' not followed by number\n",
- bindto);
- GNUNET_free(cp);
- return NULL;
- }
+ /* 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;
+ }
}
- else
+ else
{
- /* interpret missing port as 0, aka pick any free one */
- port = 0;
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ "BINDTO specification `%s' invalid: last ':' not followed by number\n",
+ bindto);
+ GNUNET_free (cp);
+ return NULL;
}
+ }
+ else
+ {
+ /* interpret missing port as 0, aka pick any free one */
+ port = 0;
+ }
{
/* try IPv4 */
struct sockaddr_in v4;
- if (1 == inet_pton(AF_INET, cp, &v4))
- {
- v4.sin_port = htons((uint16_t)port);
- in = GNUNET_memdup(&v4, sizeof(v4));
- *sock_len = sizeof(v4);
- GNUNET_free(cp);
- return in;
- }
+ if (1 == inet_pton (AF_INET, cp, &v4))
+ {
+ v4.sin_port = htons ((uint16_t) port);
+ in = GNUNET_memdup (&v4, sizeof(v4));
+ *sock_len = sizeof(v4);
+ GNUNET_free (cp);
+ return in;
+ }
}
{
/* try IPv6 */
@@ -1797,22 +1811,22 @@ udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
const char *start;
start = cp;
- if (('[' == *cp) && (']' == cp[strlen(cp) - 1]))
- {
- start++; /* skip over '[' */
- cp[strlen(cp) - 1] = '\0'; /* eat ']' */
- }
- if (1 == inet_pton(AF_INET6, start, &v6))
- {
- v6.sin6_port = htons((uint16_t)port);
- in = GNUNET_memdup(&v6, sizeof(v6));
- *sock_len = sizeof(v6);
- GNUNET_free(cp);
- return in;
- }
+ if (('[' == *cp) && (']' == cp[strlen (cp) - 1]))
+ {
+ start++; /* skip over '[' */
+ cp[strlen (cp) - 1] = '\0'; /* eat ']' */
+ }
+ if (1 == inet_pton (AF_INET6, start, &v6))
+ {
+ v6.sin6_port = htons ((uint16_t) port);
+ in = GNUNET_memdup (&v6, sizeof(v6));
+ *sock_len = sizeof(v6);
+ GNUNET_free (cp);
+ return in;
+ }
}
/* #5528 FIXME (feature!): maybe also try getnameinfo()? */
- GNUNET_free(cp);
+ GNUNET_free (cp);
return NULL;
}
@@ -1825,22 +1839,22 @@ udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
* @param pad_size number of bytes of padding to append
*/
static void
-do_pad(gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size)
+do_pad (gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size)
{
char pad[pad_size];
- GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, pad, sizeof(pad));
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, pad, sizeof(pad));
if (sizeof(pad) > sizeof(struct GNUNET_MessageHeader))
- {
- struct GNUNET_MessageHeader hdr =
- { .size = htons(sizeof(pad)),
- .type = htons(GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD) };
+ {
+ struct GNUNET_MessageHeader hdr =
+ { .size = htons (sizeof(pad)),
+ .type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD) };
- memcpy(pad, &hdr, sizeof(hdr));
- }
- GNUNET_assert(
+ memcpy (pad, &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)));
}
@@ -1853,123 +1867,123 @@ do_pad(gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size)
* @param impl_state our `struct ReceiverAddress`
*/
static void
-mq_send(struct GNUNET_MQ_Handle *mq,
- const struct GNUNET_MessageHeader *msg,
- void *impl_state)
+mq_send (struct GNUNET_MQ_Handle *mq,
+ const struct GNUNET_MessageHeader *msg,
+ void *impl_state)
{
struct ReceiverAddress *receiver = impl_state;
- uint16_t msize = ntohs(msg->size);
+ uint16_t msize = ntohs (msg->size);
- GNUNET_assert(mq == receiver->mq);
+ GNUNET_assert (mq == receiver->mq);
if (msize > receiver->mtu)
- {
- GNUNET_break(0);
- receiver_destroy(receiver);
- return;
- }
- reschedule_receiver_timeout(receiver);
+ {
+ GNUNET_break (0);
+ receiver_destroy (receiver);
+ return;
+ }
+ reschedule_receiver_timeout (receiver);
if (0 == receiver->acks_available)
- {
- /* use KX encryption method */
- struct UdpHandshakeSignature uhs;
- struct UDPConfirmation uc;
- struct InitialKX kx;
- struct GNUNET_CRYPTO_EcdhePrivateKey epriv;
- char dgram[receiver->mtu + 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));
-
- ss = setup_shared_secret_enc(&epriv, receiver);
- setup_cipher(&ss->master, 0, &out_cipher);
- /* compute 'uc' */
- uc.sender = my_identity;
- uc.monotonic_time =
- GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_monotonic(cfg));
- uhs.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE);
- uhs.purpose.size = htonl(sizeof(uhs));
- uhs.sender = my_identity;
- uhs.receiver = receiver->target;
- GNUNET_CRYPTO_ecdhe_key_get_public(&epriv, &uhs.ephemeral);
- uhs.monotonic_time = uc.monotonic_time;
- GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(my_private_key,
+ {
+ /* use KX encryption method */
+ struct UdpHandshakeSignature uhs;
+ struct UDPConfirmation uc;
+ struct InitialKX kx;
+ struct GNUNET_CRYPTO_EcdhePrivateKey epriv;
+ char dgram[receiver->mtu + 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));
+
+ ss = setup_shared_secret_enc (&epriv, receiver);
+ setup_cipher (&ss->master, 0, &out_cipher);
+ /* compute 'uc' */
+ uc.sender = my_identity;
+ uc.monotonic_time =
+ GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg));
+ uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE);
+ uhs.purpose.size = htonl (sizeof(uhs));
+ uhs.sender = my_identity;
+ uhs.receiver = receiver->target;
+ GNUNET_CRYPTO_ecdhe_key_get_public (&epriv, &uhs.ephemeral);
+ uhs.monotonic_time = uc.monotonic_time;
+ GNUNET_assert (GNUNET_OK == 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,
+ /* 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)));
- dpos += sizeof(uc);
- /* Append encrypted payload to dgram */
- GNUNET_assert(
- 0 == gcry_cipher_encrypt(out_cipher, &dgram[dpos], msize, msg, msize));
- dpos += msize;
- do_pad(out_cipher, &dgram[dpos], sizeof(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_close(out_cipher);
- memcpy(dgram, &kx, sizeof(kx));
- 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_MQ_impl_send_continue(mq);
- return;
- } /* End of KX encryption method */
+ dpos += sizeof(uc);
+ /* Append encrypted payload to dgram */
+ GNUNET_assert (
+ 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize));
+ dpos += msize;
+ do_pad (out_cipher, &dgram[dpos], sizeof(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_close (out_cipher);
+ memcpy (dgram, &kx, sizeof(kx));
+ 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_MQ_impl_send_continue (mq);
+ return;
+ } /* End of KX encryption method */
/* begin "BOX" encryption method, scan for ACKs from tail! */
for (struct SharedSecret *ss = receiver->ss_tail; NULL != ss; ss = ss->prev)
+ {
+ if (ss->sequence_used < ss->sequence_allowed)
{
- if (ss->sequence_used < ss->sequence_allowed)
- {
- char dgram[sizeof(struct UDPBox) + receiver->mtu];
- struct UDPBox *box;
- gcry_cipher_hd_t out_cipher;
- size_t dpos;
-
- box = (struct UDPBox *)dgram;
- ss->sequence_used++;
- get_kid(&ss->master, ss->sequence_used, &box->kid);
- setup_cipher(&ss->master, ss->sequence_used, &out_cipher);
- /* Append encrypted payload to dgram */
- dpos = sizeof(struct UDPBox);
- GNUNET_assert(
- 0 == gcry_cipher_encrypt(out_cipher, &dgram[dpos], msize, msg, msize));
- dpos += msize;
- do_pad(out_cipher, &dgram[dpos], sizeof(dgram) - dpos);
- GNUNET_assert(0 == 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_MQ_impl_send_continue(mq);
- receiver->acks_available--;
- if (0 == receiver->acks_available)
- {
- /* We have no more ACKs => MTU change! */
- setup_receiver_mq(receiver);
- }
- return;
- }
+ char dgram[sizeof(struct UDPBox) + receiver->mtu];
+ struct UDPBox *box;
+ gcry_cipher_hd_t out_cipher;
+ size_t dpos;
+
+ box = (struct UDPBox *) dgram;
+ ss->sequence_used++;
+ get_kid (&ss->master, ss->sequence_used, &box->kid);
+ setup_cipher (&ss->master, ss->sequence_used, &out_cipher);
+ /* Append encrypted payload to dgram */
+ dpos = sizeof(struct UDPBox);
+ GNUNET_assert (
+ 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize));
+ dpos += msize;
+ do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos);
+ GNUNET_assert (0 == 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_MQ_impl_send_continue (mq);
+ receiver->acks_available--;
+ if (0 == receiver->acks_available)
+ {
+ /* We have no more ACKs => MTU change! */
+ setup_receiver_mq (receiver);
+ }
+ return;
}
- GNUNET_assert(0);
+ }
+ GNUNET_assert (0);
}
@@ -1982,15 +1996,15 @@ mq_send(struct GNUNET_MQ_Handle *mq,
* @param impl_state our `struct ReceiverAddress`
*/
static void
-mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
+mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
{
struct ReceiverAddress *receiver = impl_state;
if (mq == receiver->mq)
- {
- receiver->mq = NULL;
- receiver_destroy(receiver);
- }
+ {
+ receiver->mq = NULL;
+ receiver_destroy (receiver);
+ }
}
@@ -2001,10 +2015,10 @@ mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
* @param impl_state our `struct RecvierAddress`
*/
static void
-mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
+mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
{
/* Cancellation is impossible with UDP; bail */
- GNUNET_assert(0);
+ GNUNET_assert (0);
}
@@ -2018,15 +2032,15 @@ mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
* @param error error code
*/
static void
-mq_error(void *cls, enum GNUNET_MQ_Error error)
+mq_error (void *cls, 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);
- receiver_destroy(receiver);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "MQ error in queue to %s: %d\n",
+ GNUNET_i2s (&receiver->target),
+ (int) error);
+ receiver_destroy (receiver);
}
@@ -2038,63 +2052,63 @@ mq_error(void *cls, enum GNUNET_MQ_Error error)
* @param receiver receiver to setup MQ for
*/
static void
-setup_receiver_mq(struct ReceiverAddress *receiver)
+setup_receiver_mq (struct ReceiverAddress *receiver)
{
size_t base_mtu;
if (NULL != receiver->qh)
- {
- GNUNET_TRANSPORT_communicator_mq_del(receiver->qh);
- receiver->qh = NULL;
- }
- GNUNET_assert(NULL == receiver->mq);
+ {
+ GNUNET_TRANSPORT_communicator_mq_del (receiver->qh);
+ receiver->qh = NULL;
+ }
+ GNUNET_assert (NULL == receiver->mq);
switch (receiver->address->sa_family)
- {
- case AF_INET:
- base_mtu = 1480 /* Ethernet MTU, 1500 - Ethernet header - VLAN tag */
- - sizeof(struct GNUNET_TUN_IPv4Header) /* 20 */
- - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */;
- break;
-
- case AF_INET6:
- base_mtu = 1280 /* Minimum MTU required by IPv6 */
- - sizeof(struct GNUNET_TUN_IPv6Header) /* 40 */
- - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */;
- break;
-
- default:
- GNUNET_assert(0);
- break;
- }
+ {
+ case AF_INET:
+ base_mtu = 1480 /* Ethernet MTU, 1500 - Ethernet header - VLAN tag */
+ - sizeof(struct GNUNET_TUN_IPv4Header) /* 20 */
+ - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */;
+ break;
+
+ case AF_INET6:
+ base_mtu = 1280 /* Minimum MTU required by IPv6 */
+ - sizeof(struct GNUNET_TUN_IPv6Header) /* 40 */
+ - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */;
+ break;
+
+ default:
+ GNUNET_assert (0);
+ break;
+ }
if (0 == receiver->acks_available)
- {
- /* MTU based on full KX messages */
- receiver->mtu = base_mtu - sizeof(struct InitialKX) /* 48 */
- - sizeof(struct UDPConfirmation); /* 104 */
- }
+ {
+ /* MTU based on full KX messages */
+ receiver->mtu = base_mtu - sizeof(struct InitialKX) /* 48 */
+ - sizeof(struct UDPConfirmation); /* 104 */
+ }
else
- {
- /* MTU based on BOXed messages */
- receiver->mtu = base_mtu - sizeof(struct UDPBox);
- }
+ {
+ /* MTU based on BOXed messages */
+ receiver->mtu = base_mtu - sizeof(struct UDPBox);
+ }
/* => Effective MTU for CORE will range from 1080 (IPv6 + KX) to
1404 (IPv4 + Box) bytes, depending on circumstances... */
if (NULL == receiver->mq)
- receiver->mq = GNUNET_MQ_queue_for_callbacks(&mq_send,
- &mq_destroy,
- &mq_cancel,
- receiver,
- NULL,
- &mq_error,
- receiver);
+ receiver->mq = GNUNET_MQ_queue_for_callbacks (&mq_send,
+ &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);
+ GNUNET_TRANSPORT_communicator_mq_add (ch,
+ &receiver->target,
+ receiver->foreign_addr,
+ receiver->mtu,
+ receiver->nt,
+ GNUNET_TRANSPORT_CS_OUTBOUND,
+ receiver->mq);
}
@@ -2117,47 +2131,47 @@ setup_receiver_mq(struct ReceiverAddress *receiver)
* invalid
*/
static int
-mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
+mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
{
struct ReceiverAddress *receiver;
const char *path;
struct sockaddr *in;
socklen_t in_len;
- if (0 != strncmp(address,
- 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);
+ if (0 != strncmp (address,
+ 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);
- receiver = GNUNET_new(struct ReceiverAddress);
+ receiver = GNUNET_new (struct ReceiverAddress);
receiver->address = in;
receiver->address_len = in_len;
receiver->target = *peer;
- receiver->nt = GNUNET_NT_scanner_get_type(is, in, in_len);
- (void)GNUNET_CONTAINER_multipeermap_put(
+ receiver->nt = GNUNET_NT_scanner_get_type (is, in, in_len);
+ (void) GNUNET_CONTAINER_multipeermap_put (
receivers,
&receiver->target,
receiver,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
receiver->timeout =
- GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
- receiver->hn = GNUNET_CONTAINER_heap_insert(receivers_heap,
- receiver,
- receiver->timeout.abs_value_us);
- GNUNET_STATISTICS_set(stats,
- "# receivers active",
- GNUNET_CONTAINER_multipeermap_size(receivers),
- GNUNET_NO);
+ GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ receiver->hn = GNUNET_CONTAINER_heap_insert (receivers_heap,
+ receiver,
+ receiver->timeout.abs_value_us);
+ GNUNET_STATISTICS_set (stats,
+ "# receivers active",
+ GNUNET_CONTAINER_multipeermap_size (receivers),
+ GNUNET_NO);
receiver->foreign_addr =
- sockaddr_to_udpaddr_string(receiver->address, receiver->address_len);
- setup_receiver_mq(receiver);
+ sockaddr_to_udpaddr_string (receiver->address, receiver->address_len);
+ setup_receiver_mq (receiver);
if (NULL == timeout_task)
- timeout_task = GNUNET_SCHEDULER_add_now(&check_timeouts, NULL);
+ timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL);
return GNUNET_OK;
}
@@ -2171,15 +2185,15 @@ mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
* @return #GNUNET_OK to continue to iterate
*/
static int
-get_receiver_delete_it(void *cls,
- const struct GNUNET_PeerIdentity *target,
- void *value)
+get_receiver_delete_it (void *cls,
+ const struct GNUNET_PeerIdentity *target,
+ void *value)
{
struct ReceiverAddress *receiver = value;
- (void)cls;
- (void)target;
- receiver_destroy(receiver);
+ (void) cls;
+ (void) target;
+ receiver_destroy (receiver);
return GNUNET_OK;
}
@@ -2193,15 +2207,15 @@ get_receiver_delete_it(void *cls,
* @return #GNUNET_OK to continue to iterate
*/
static int
-get_sender_delete_it(void *cls,
- const struct GNUNET_PeerIdentity *target,
- void *value)
+get_sender_delete_it (void *cls,
+ const struct GNUNET_PeerIdentity *target,
+ void *value)
{
struct SenderAddress *sender = value;
- (void)cls;
- (void)target;
- sender_destroy(sender);
+ (void) cls;
+ (void) target;
+ sender_destroy (sender);
return GNUNET_OK;
}
@@ -2212,64 +2226,64 @@ get_sender_delete_it(void *cls,
* @param cls NULL (always)
*/
static void
-do_shutdown(void *cls)
+do_shutdown (void *cls)
{
if (NULL != nat)
- {
- GNUNET_NAT_unregister(nat);
- nat = NULL;
- }
+ {
+ GNUNET_NAT_unregister (nat);
+ nat = NULL;
+ }
while (NULL != bi_head)
- bi_destroy(bi_head);
+ bi_destroy (bi_head);
if (NULL != broadcast_task)
- {
- GNUNET_SCHEDULER_cancel(broadcast_task);
- broadcast_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (broadcast_task);
+ broadcast_task = NULL;
+ }
if (NULL != read_task)
- {
- GNUNET_SCHEDULER_cancel(read_task);
- read_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (read_task);
+ read_task = NULL;
+ }
if (NULL != udp_sock)
- {
- GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(udp_sock));
- udp_sock = NULL;
- }
- GNUNET_CONTAINER_multipeermap_iterate(receivers,
- &get_receiver_delete_it,
- NULL);
- GNUNET_CONTAINER_multipeermap_destroy(receivers);
- GNUNET_CONTAINER_multipeermap_iterate(senders, &get_sender_delete_it, NULL);
- GNUNET_CONTAINER_multipeermap_destroy(senders);
- GNUNET_CONTAINER_multishortmap_destroy(key_cache);
- GNUNET_CONTAINER_heap_destroy(senders_heap);
- GNUNET_CONTAINER_heap_destroy(receivers_heap);
+ {
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (udp_sock));
+ udp_sock = NULL;
+ }
+ GNUNET_CONTAINER_multipeermap_iterate (receivers,
+ &get_receiver_delete_it,
+ NULL);
+ GNUNET_CONTAINER_multipeermap_destroy (receivers);
+ GNUNET_CONTAINER_multipeermap_iterate (senders, &get_sender_delete_it, NULL);
+ GNUNET_CONTAINER_multipeermap_destroy (senders);
+ GNUNET_CONTAINER_multishortmap_destroy (key_cache);
+ GNUNET_CONTAINER_heap_destroy (senders_heap);
+ GNUNET_CONTAINER_heap_destroy (receivers_heap);
if (NULL != ch)
- {
- GNUNET_TRANSPORT_communicator_disconnect(ch);
- ch = NULL;
- }
+ {
+ GNUNET_TRANSPORT_communicator_disconnect (ch);
+ ch = NULL;
+ }
if (NULL != ah)
- {
- GNUNET_TRANSPORT_application_done(ah);
- ah = NULL;
- }
+ {
+ GNUNET_TRANSPORT_application_done (ah);
+ ah = NULL;
+ }
if (NULL != stats)
- {
- GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
- stats = NULL;
- }
+ {
+ GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
+ stats = NULL;
+ }
if (NULL != my_private_key)
- {
- GNUNET_free(my_private_key);
- my_private_key = NULL;
- }
+ {
+ GNUNET_free (my_private_key);
+ my_private_key = NULL;
+ }
if (NULL != is)
- {
- GNUNET_NT_scanner_done(is);
- is = NULL;
- }
+ {
+ GNUNET_NT_scanner_done (is);
+ is = NULL;
+ }
}
@@ -2283,24 +2297,24 @@ do_shutdown(void *cls)
* @param msg payload
*/
static void
-enc_notify_cb(void *cls,
- const struct GNUNET_PeerIdentity *sender,
- const struct GNUNET_MessageHeader *msg)
+enc_notify_cb (void *cls,
+ const struct GNUNET_PeerIdentity *sender,
+ const struct GNUNET_MessageHeader *msg)
{
const struct UDPAck *ack;
- (void)cls;
- if ((ntohs(msg->type) != GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK) ||
- (ntohs(msg->size) != sizeof(struct UDPAck)))
- {
- GNUNET_break_op(0);
- return;
- }
- ack = (const struct UDPAck *)msg;
- GNUNET_CONTAINER_multipeermap_get_multiple(receivers,
- sender,
- &handle_ack,
- (void *)ack);
+ (void) cls;
+ if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK) ||
+ (ntohs (msg->size) != sizeof(struct UDPAck)))
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+ ack = (const struct UDPAck *) msg;
+ GNUNET_CONTAINER_multipeermap_get_multiple (receivers,
+ sender,
+ &handle_ack,
+ (void *) ack);
}
@@ -2318,39 +2332,39 @@ enc_notify_cb(void *cls,
* @param addrlen actual length of the @a addr
*/
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)
+nat_address_cb (void *cls,
+ 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;
if (GNUNET_YES == add_remove)
- {
- enum GNUNET_NetworkType nt;
-
- GNUNET_asprintf(&my_addr,
- "%s-%s",
- COMMUNICATOR_ADDRESS_PREFIX,
- GNUNET_a2s(addr, addrlen));
- nt = GNUNET_NT_scanner_get_type(is, addr, addrlen);
- ai =
- GNUNET_TRANSPORT_communicator_address_add(ch,
- my_addr,
- nt,
- GNUNET_TIME_UNIT_FOREVER_REL);
- GNUNET_free(my_addr);
- *app_ctx = ai;
- }
+ {
+ enum GNUNET_NetworkType nt;
+
+ GNUNET_asprintf (&my_addr,
+ "%s-%s",
+ COMMUNICATOR_ADDRESS_PREFIX,
+ GNUNET_a2s (addr, addrlen));
+ nt = GNUNET_NT_scanner_get_type (is, addr, addrlen);
+ ai =
+ GNUNET_TRANSPORT_communicator_address_add (ch,
+ my_addr,
+ nt,
+ GNUNET_TIME_UNIT_FOREVER_REL);
+ GNUNET_free (my_addr);
+ *app_ctx = ai;
+ }
else
- {
- ai = *app_ctx;
- GNUNET_TRANSPORT_communicator_address_remove(ai);
- *app_ctx = NULL;
- }
+ {
+ ai = *app_ctx;
+ GNUNET_TRANSPORT_communicator_address_remove (ai);
+ *app_ctx = NULL;
+ }
}
@@ -2360,69 +2374,69 @@ nat_address_cb(void *cls,
* @param cls a `struct BroadcastInterface`
*/
static void
-ifc_broadcast(void *cls)
+ifc_broadcast (void *cls)
{
struct BroadcastInterface *bi = cls;
struct GNUNET_TIME_Relative delay;
delay = BROADCAST_FREQUENCY;
delay.rel_value_us =
- GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, delay.rel_value_us);
+ GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, delay.rel_value_us);
bi->broadcast_task =
- GNUNET_SCHEDULER_add_delayed(INTERFACE_SCAN_FREQUENCY, &ifc_broadcast, bi);
+ GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY, &ifc_broadcast, bi);
switch (bi->sa->sa_family)
- {
- case AF_INET: {
+ {
+ case AF_INET: {
static int yes = 1;
static int no = 0;
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");
- sent = GNUNET_NETWORK_socket_sendto(udp_sock,
- &bi->bcm,
- sizeof(bi->bcm),
- bi->ba,
- bi->salen);
+ if (GNUNET_OK != 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);
if (-1 == sent)
- 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_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");
break;
}
- case AF_INET6: {
+ case AF_INET6: {
ssize_t sent;
struct sockaddr_in6 dst;
dst.sin6_family = AF_INET6;
- dst.sin6_port = htons(my_port);
+ dst.sin6_port = htons (my_port);
dst.sin6_addr = bi->mcreq.ipv6mr_multiaddr;
- dst.sin6_scope_id = ((struct sockaddr_in6 *)bi->ba)->sin6_scope_id;
+ 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));
+ sent = GNUNET_NETWORK_socket_sendto (udp_sock,
+ &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:
- GNUNET_break(0);
- break;
- }
+ default:
+ GNUNET_break (0);
+ break;
+ }
}
@@ -2441,90 +2455,90 @@ ifc_broadcast(void *cls)
* @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
*/
static int
-iface_proc(void *cls,
- const char *name,
- int isDefault,
- const struct sockaddr *addr,
- const struct sockaddr *broadcast_addr,
- const struct sockaddr *netmask,
- socklen_t addrlen)
+iface_proc (void *cls,
+ const char *name,
+ int isDefault,
+ const struct sockaddr *addr,
+ const struct sockaddr *broadcast_addr,
+ const struct sockaddr *netmask,
+ socklen_t addrlen)
{
struct BroadcastInterface *bi;
enum GNUNET_NetworkType network;
struct UdpBroadcastSignature ubs;
- (void)cls;
- (void)netmask;
+ (void) cls;
+ (void) netmask;
if (NULL == addr)
return GNUNET_YES; /* need to know our address! */
- network = GNUNET_NT_scanner_get_type(is, addr, addrlen);
+ network = GNUNET_NT_scanner_get_type (is, addr, addrlen);
if (GNUNET_NT_LOOPBACK == network)
- {
- /* Broadcasting on loopback does not make sense */
- return GNUNET_YES;
- }
+ {
+ /* Broadcasting on loopback does not make sense */
+ return GNUNET_YES;
+ }
for (bi = bi_head; NULL != bi; bi = bi->next)
+ {
+ if ((bi->salen == addrlen) && (0 == memcmp (addr, bi->sa, addrlen)))
{
- if ((bi->salen == addrlen) && (0 == memcmp(addr, bi->sa, addrlen)))
- {
- bi->found = GNUNET_YES;
- return GNUNET_OK;
- }
+ bi->found = GNUNET_YES;
+ return GNUNET_OK;
}
+ }
if ((AF_INET6 == addr->sa_family) && (NULL == broadcast_addr))
return GNUNET_OK; /* broadcast_addr is required for IPv6! */
if ((AF_INET6 == addr->sa_family) && (GNUNET_YES != have_v6_socket))
return GNUNET_OK; /* not using IPv6 */
- bi = GNUNET_new(struct BroadcastInterface);
- bi->sa = GNUNET_memdup(addr, addrlen);
+ bi = GNUNET_new (struct BroadcastInterface);
+ bi->sa = GNUNET_memdup (addr, addrlen);
if (NULL != broadcast_addr)
- bi->ba = GNUNET_memdup(broadcast_addr, addrlen);
+ bi->ba = GNUNET_memdup (broadcast_addr, addrlen);
bi->salen = addrlen;
bi->found = GNUNET_YES;
bi->bcm.sender = my_identity;
- ubs.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST);
- ubs.purpose.size = htonl(sizeof(ubs));
+ ubs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST);
+ ubs.purpose.size = htonl (sizeof(ubs));
ubs.sender = my_identity;
- GNUNET_CRYPTO_hash(addr, addrlen, &ubs.h_address);
- GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(my_private_key,
- &ubs.purpose,
- &bi->bcm.sender_sig));
- bi->broadcast_task = GNUNET_SCHEDULER_add_now(&ifc_broadcast, bi);
- GNUNET_CONTAINER_DLL_insert(bi_head, bi_tail, bi);
+ GNUNET_CRYPTO_hash (addr, addrlen, &ubs.h_address);
+ GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (my_private_key,
+ &ubs.purpose,
+ &bi->bcm.sender_sig));
+ bi->broadcast_task = GNUNET_SCHEDULER_add_now (&ifc_broadcast, bi);
+ GNUNET_CONTAINER_DLL_insert (bi_head, bi_tail, bi);
if ((AF_INET6 == addr->sa_family) && (NULL != broadcast_addr))
+ {
+ /* Create IPv6 multicast request */
+ const struct sockaddr_in6 *s6 =
+ (const struct sockaddr_in6 *) broadcast_addr;
+
+ GNUNET_assert (
+ 1 == inet_pton (AF_INET6, "FF05::13B", &bi->mcreq.ipv6mr_multiaddr));
+
+ /* http://tools.ietf.org/html/rfc2553#section-5.2:
+ *
+ * IPV6_JOIN_GROUP
+ *
+ * Join a multicast group on a specified local interface. If the
+ * interface index is specified as 0, the kernel chooses the local
+ * interface. For example, some kernels look up the multicast
+ * group in the normal IPv6 routing table and using the resulting
+ * interface; we do this for each interface, so no need to use
+ * zero (anymore...).
+ */
+ bi->mcreq.ipv6mr_interface = s6->sin6_scope_id;
+
+ /* Join the multicast group */
+ if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock,
+ IPPROTO_IPV6,
+ IPV6_JOIN_GROUP,
+ &bi->mcreq,
+ sizeof(bi->mcreq)))
{
- /* Create IPv6 multicast request */
- const struct sockaddr_in6 *s6 =
- (const struct sockaddr_in6 *)broadcast_addr;
-
- GNUNET_assert(
- 1 == inet_pton(AF_INET6, "FF05::13B", &bi->mcreq.ipv6mr_multiaddr));
-
- /* http://tools.ietf.org/html/rfc2553#section-5.2:
- *
- * IPV6_JOIN_GROUP
- *
- * Join a multicast group on a specified local interface. If the
- * interface index is specified as 0, the kernel chooses the local
- * interface. For example, some kernels look up the multicast
- * group in the normal IPv6 routing table and using the resulting
- * interface; we do this for each interface, so no need to use
- * zero (anymore...).
- */
- bi->mcreq.ipv6mr_interface = s6->sin6_scope_id;
-
- /* Join the multicast group */
- if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt(udp_sock,
- IPPROTO_IPV6,
- IPV6_JOIN_GROUP,
- &bi->mcreq,
- sizeof(bi->mcreq)))
- {
- GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "setsockopt");
- }
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
}
+ }
return GNUNET_OK;
}
@@ -2535,23 +2549,23 @@ iface_proc(void *cls,
* @param cls NULL, unused
*/
static void
-do_broadcast(void *cls)
+do_broadcast (void *cls)
{
struct BroadcastInterface *bin;
- (void)cls;
+ (void) cls;
for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bi->next)
bi->found = GNUNET_NO;
- GNUNET_OS_network_interfaces_list(&iface_proc, NULL);
+ GNUNET_OS_network_interfaces_list (&iface_proc, NULL);
for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bin)
- {
- bin = bi->next;
- if (GNUNET_NO == bi->found)
- bi_destroy(bi);
- }
- broadcast_task = GNUNET_SCHEDULER_add_delayed(INTERFACE_SCAN_FREQUENCY,
- &do_broadcast,
- NULL);
+ {
+ bin = bi->next;
+ if (GNUNET_NO == bi->found)
+ bi_destroy (bi);
+ }
+ broadcast_task = GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY,
+ &do_broadcast,
+ NULL);
}
@@ -2564,10 +2578,10 @@ do_broadcast(void *cls)
* @param c configuration
*/
static void
-run(void *cls,
- char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *c)
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *c)
{
char *bindto;
struct sockaddr *in;
@@ -2575,143 +2589,143 @@ run(void *cls,
struct sockaddr_storage in_sto;
socklen_t sto_len;
- (void)cls;
+ (void) cls;
cfg = c;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename(cfg,
- COMMUNICATOR_CONFIG_SECTION,
- "BINDTO",
- &bindto))
- {
- GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR,
- COMMUNICATOR_CONFIG_SECTION,
- "BINDTO");
- return;
- }
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ COMMUNICATOR_CONFIG_SECTION,
+ "BINDTO",
+ &bindto))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ COMMUNICATOR_CONFIG_SECTION,
+ "BINDTO");
+ return;
+ }
- in = udp_address_to_sockaddr(bindto, &in_len);
+ in = udp_address_to_sockaddr (bindto, &in_len);
if (NULL == in)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Failed to setup UDP socket address with path `%s'\n",
- bindto);
- GNUNET_free(bindto);
- return;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to setup UDP socket address with path `%s'\n",
+ bindto);
+ GNUNET_free (bindto);
+ return;
+ }
udp_sock =
- GNUNET_NETWORK_socket_create(in->sa_family, SOCK_DGRAM, IPPROTO_UDP);
+ GNUNET_NETWORK_socket_create (in->sa_family, SOCK_DGRAM, IPPROTO_UDP);
if (NULL == udp_sock)
- {
- GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket");
- GNUNET_free(in);
- GNUNET_free(bindto);
- return;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
+ GNUNET_free (in);
+ GNUNET_free (bindto);
+ return;
+ }
if (AF_INET6 == in->sa_family)
have_v6_socket = GNUNET_YES;
- if (GNUNET_OK != GNUNET_NETWORK_socket_bind(udp_sock, in, in_len))
- {
- GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "bind", bindto);
- GNUNET_NETWORK_socket_close(udp_sock);
- udp_sock = NULL;
- GNUNET_free(in);
- GNUNET_free(bindto);
- return;
- }
+ if (GNUNET_OK != GNUNET_NETWORK_socket_bind (udp_sock, in, in_len))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", bindto);
+ GNUNET_NETWORK_socket_close (udp_sock);
+ udp_sock = NULL;
+ GNUNET_free (in);
+ GNUNET_free (bindto);
+ return;
+ }
/* We might have bound to port 0, allowing the OS to figure it out;
thus, get the real IN-address from the socket */
sto_len = sizeof(in_sto);
- if (0 != getsockname(GNUNET_NETWORK_get_fd(udp_sock),
- (struct sockaddr *)&in_sto,
- &sto_len))
- {
- memcpy(&in_sto, in, in_len);
- sto_len = in_len;
- }
- GNUNET_free(in);
- GNUNET_free(bindto);
- in = (struct sockaddr *)&in_sto;
+ if (0 != getsockname (GNUNET_NETWORK_get_fd (udp_sock),
+ (struct sockaddr *) &in_sto,
+ &sto_len))
+ {
+ memcpy (&in_sto, in, in_len);
+ sto_len = in_len;
+ }
+ GNUNET_free (in);
+ GNUNET_free (bindto);
+ in = (struct sockaddr *) &in_sto;
in_len = sto_len;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Bound to `%s'\n",
- GNUNET_a2s((const struct sockaddr *)&in_sto, sto_len));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Bound to `%s'\n",
+ GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len));
switch (in->sa_family)
- {
- case AF_INET:
- my_port = ntohs(((struct sockaddr_in *)in)->sin_port);
- break;
+ {
+ case AF_INET:
+ my_port = ntohs (((struct sockaddr_in *) in)->sin_port);
+ break;
- case AF_INET6:
- my_port = ntohs(((struct sockaddr_in6 *)in)->sin6_port);
- break;
+ case AF_INET6:
+ my_port = ntohs (((struct sockaddr_in6 *) in)->sin6_port);
+ break;
- default:
- GNUNET_break(0);
- my_port = 0;
- }
- stats = GNUNET_STATISTICS_create("C-UDP", cfg);
- senders = GNUNET_CONTAINER_multipeermap_create(32, GNUNET_YES);
- receivers = GNUNET_CONTAINER_multipeermap_create(32, GNUNET_YES);
- senders_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN);
+ default:
+ GNUNET_break (0);
+ my_port = 0;
+ }
+ stats = GNUNET_STATISTICS_create ("C-UDP", cfg);
+ senders = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES);
+ receivers = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES);
+ senders_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
receivers_heap =
- GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN);
- key_cache = GNUNET_CONTAINER_multishortmap_create(1024, GNUNET_YES);
- GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL);
- is = GNUNET_NT_scanner_init();
- my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration(cfg);
+ GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
+ key_cache = GNUNET_CONTAINER_multishortmap_create (1024, GNUNET_YES);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
+ is = GNUNET_NT_scanner_init ();
+ my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
if (NULL == my_private_key)
- {
- GNUNET_log(
- GNUNET_ERROR_TYPE_ERROR,
- _(
- "Transport service is lacking key configuration settings. Exiting.\n"));
- GNUNET_SCHEDULER_shutdown();
- return;
- }
- GNUNET_CRYPTO_eddsa_key_get_public(my_private_key, &my_identity.public_key);
+ {
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ (
+ "Transport service is lacking key configuration settings. Exiting.\n"));
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key);
/* start reading */
- read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL,
- udp_sock,
- &sock_read,
- NULL);
- ch = GNUNET_TRANSPORT_communicator_connect(cfg,
- COMMUNICATOR_CONFIG_SECTION,
- COMMUNICATOR_ADDRESS_PREFIX,
- GNUNET_TRANSPORT_CC_UNRELIABLE,
- &mq_init,
- NULL,
- &enc_notify_cb,
+ read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ udp_sock,
+ &sock_read,
NULL);
+ ch = GNUNET_TRANSPORT_communicator_connect (cfg,
+ COMMUNICATOR_CONFIG_SECTION,
+ COMMUNICATOR_ADDRESS_PREFIX,
+ GNUNET_TRANSPORT_CC_UNRELIABLE,
+ &mq_init,
+ NULL,
+ &enc_notify_cb,
+ NULL);
if (NULL == ch)
- {
- GNUNET_break(0);
- GNUNET_SCHEDULER_shutdown();
- return;
- }
- ah = GNUNET_TRANSPORT_application_init(cfg);
+ {
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
+ ah = GNUNET_TRANSPORT_application_init (cfg);
if (NULL == ah)
- {
- GNUNET_break(0);
- GNUNET_SCHEDULER_shutdown();
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_shutdown ();
+ return;
+ }
/* start broadcasting */
if (GNUNET_YES !=
- GNUNET_CONFIGURATION_get_value_yesno(cfg,
- COMMUNICATOR_CONFIG_SECTION,
- "DISABLE_BROADCAST"))
- {
- broadcast_task = GNUNET_SCHEDULER_add_now(&do_broadcast, NULL);
- }
- nat = GNUNET_NAT_register(cfg,
- COMMUNICATOR_CONFIG_SECTION,
- IPPROTO_UDP,
- 1 /* one address */,
- (const struct sockaddr **)&in,
- &in_len,
- &nat_address_cb,
- NULL /* FIXME: support reversal: #5529 */,
- NULL /* closure */);
+ GNUNET_CONFIGURATION_get_value_yesno (cfg,
+ COMMUNICATOR_CONFIG_SECTION,
+ "DISABLE_BROADCAST"))
+ {
+ broadcast_task = GNUNET_SCHEDULER_add_now (&do_broadcast, NULL);
+ }
+ nat = GNUNET_NAT_register (cfg,
+ COMMUNICATOR_CONFIG_SECTION,
+ IPPROTO_UDP,
+ 1 /* one address */,
+ (const struct sockaddr **) &in,
+ &in_len,
+ &nat_address_cb,
+ NULL /* FIXME: support reversal: #5529 */,
+ NULL /* closure */);
}
@@ -2723,26 +2737,26 @@ run(void *cls,
* @return 0 ok, 1 on error
*/
int
-main(int argc, char *const *argv)
+main (int argc, char *const *argv)
{
static const struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_OPTION_END
};
int ret;
- if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
- ret = (GNUNET_OK == GNUNET_PROGRAM_run(argc,
- argv,
- "gnunet-communicator-udp",
- _("GNUnet UDP communicator"),
- options,
- &run,
- NULL))
+ ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-communicator-udp",
+ _ ("GNUnet UDP communicator"),
+ options,
+ &run,
+ NULL))
? 0
: 1;
- GNUNET_free((void *)argv);
+ GNUNET_free ((void *) argv);
return ret;
}
diff --git a/src/transport/gnunet-communicator-unix.c b/src/transport/gnunet-communicator-unix.c
index da610daa1..d8205addb 100644
--- a/src/transport/gnunet-communicator-unix.c
+++ b/src/transport/gnunet-communicator-unix.c
@@ -64,7 +64,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
/**
* UNIX Message-Packet header.
*/
-struct UNIXMessage {
+struct UNIXMessage
+{
/**
* Message header.
*/
@@ -82,7 +83,8 @@ GNUNET_NETWORK_STRUCT_END
/**
* Handle for a queue.
*/
-struct Queue {
+struct Queue
+{
/**
* Queues with pending messages (!) are kept in a DLL.
*/
@@ -205,37 +207,37 @@ static struct GNUNET_TRANSPORT_AddressIdentifier *ai;
* @param queue queue to close down
*/
static void
-queue_destroy(struct Queue *queue)
+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));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Disconnecting queue for peer `%s'\n",
+ GNUNET_i2s (&queue->target));
if (0 != queue->bytes_in_queue)
- {
- GNUNET_CONTAINER_DLL_remove(queue_head, queue_tail, queue);
- queue->bytes_in_queue = 0;
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (queue_head, queue_tail, queue);
+ queue->bytes_in_queue = 0;
+ }
if (NULL != (mq = queue->mq))
- {
- queue->mq = NULL;
- GNUNET_MQ_destroy(mq);
- }
- GNUNET_assert(
+ {
+ queue->mq = NULL;
+ GNUNET_MQ_destroy (mq);
+ }
+ GNUNET_assert (
GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove(queue_map, &queue->target, queue));
- GNUNET_STATISTICS_set(stats,
- "# queues active",
- GNUNET_CONTAINER_multipeermap_size(queue_map),
- GNUNET_NO);
+ GNUNET_CONTAINER_multipeermap_remove (queue_map, &queue->target, queue));
+ GNUNET_STATISTICS_set (stats,
+ "# queues active",
+ GNUNET_CONTAINER_multipeermap_size (queue_map),
+ GNUNET_NO);
if (NULL != queue->timeout_task)
- {
- GNUNET_SCHEDULER_cancel(queue->timeout_task);
- queue->timeout_task = NULL;
- }
- GNUNET_free(queue->address);
- GNUNET_free(queue);
+ {
+ GNUNET_SCHEDULER_cancel (queue->timeout_task);
+ queue->timeout_task = NULL;
+ }
+ GNUNET_free (queue->address);
+ GNUNET_free (queue);
}
@@ -245,28 +247,28 @@ queue_destroy(struct Queue *queue)
* @param cls the `struct Queue *` to disconnect
*/
static void
-queue_timeout(void *cls)
+queue_timeout (void *cls)
{
struct Queue *queue = cls;
struct GNUNET_TIME_Relative left;
queue->timeout_task = NULL;
- left = GNUNET_TIME_absolute_get_remaining(queue->timeout);
+ left = GNUNET_TIME_absolute_get_remaining (queue->timeout);
if (0 != left.rel_value_us)
- {
- /* not actually our turn yet, but let's at least update
- the monitor, it may think we're about to die ... */
- queue->timeout_task =
- GNUNET_SCHEDULER_add_delayed(left, &queue_timeout, 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_destroy(queue);
+ {
+ /* not actually our turn yet, but let's at least update
+ the monitor, it may think we're about to die ... */
+ queue->timeout_task =
+ GNUNET_SCHEDULER_add_delayed (left, &queue_timeout, 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_destroy (queue);
}
@@ -278,11 +280,11 @@ queue_timeout(void *cls)
* @param queue queue for which the timeout should be rescheduled
*/
static void
-reschedule_queue_timeout(struct Queue *queue)
+reschedule_queue_timeout (struct Queue *queue)
{
- GNUNET_assert(NULL != queue->timeout_task);
+ GNUNET_assert (NULL != queue->timeout_task);
queue->timeout =
- GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+ GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
}
@@ -295,22 +297,22 @@ reschedule_queue_timeout(struct Queue *queue)
* @return converted unix path
*/
static struct sockaddr_un *
-unix_address_to_sockaddr(const char *unixpath, socklen_t *sock_len)
+unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len)
{
struct sockaddr_un *un;
size_t slen;
- GNUNET_assert(0 < strlen(unixpath)); /* sanity check */
- un = GNUNET_new(struct sockaddr_un);
+ GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
+ un = GNUNET_new (struct sockaddr_un);
un->sun_family = AF_UNIX;
- slen = strlen(unixpath);
+ slen = strlen (unixpath);
if (slen >= sizeof(un->sun_path))
slen = sizeof(un->sun_path) - 1;
- GNUNET_memcpy(un->sun_path, unixpath, slen);
+ GNUNET_memcpy (un->sun_path, unixpath, slen);
un->sun_path[slen] = '\0';
slen = sizeof(struct sockaddr_un);
#if HAVE_SOCKADDR_UN_SUN_LEN
- un->sun_len = (u_char)slen;
+ un->sun_len = (u_char) slen;
#endif
(*sock_len) = slen;
if ('@' == un->sun_path[0])
@@ -322,7 +324,8 @@ unix_address_to_sockaddr(const char *unixpath, socklen_t *sock_len)
/**
* Closure to #lookup_queue_it().
*/
-struct LookupCtx {
+struct LookupCtx
+{
/**
* Location to store the queue, if found.
*/
@@ -349,17 +352,17 @@ struct LookupCtx {
* @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success
*/
static int
-lookup_queue_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
+lookup_queue_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
{
struct LookupCtx *lctx = cls;
struct Queue *queue = value;
if ((queue->address_len = lctx->un_len) &&
- (0 == memcmp(lctx->un, queue->address, queue->address_len)))
- {
- lctx->res = queue;
- return GNUNET_NO;
- }
+ (0 == memcmp (lctx->un, queue->address, queue->address_len)))
+ {
+ lctx->res = queue;
+ return GNUNET_NO;
+ }
return GNUNET_YES;
}
@@ -372,18 +375,18 @@ lookup_queue_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
* @return NULL if queue was not found
*/
static struct Queue *
-lookup_queue(const struct GNUNET_PeerIdentity *peer,
- const struct sockaddr_un *un,
- socklen_t un_len)
+lookup_queue (const struct GNUNET_PeerIdentity *peer,
+ const struct sockaddr_un *un,
+ socklen_t un_len)
{
struct LookupCtx lctx;
lctx.un = un;
lctx.un_len = un_len;
- GNUNET_CONTAINER_multipeermap_get_multiple(queue_map,
- peer,
- &lookup_queue_it,
- &lctx);
+ GNUNET_CONTAINER_multipeermap_get_multiple (queue_map,
+ peer,
+ &lookup_queue_it,
+ &lctx);
return lctx.res;
}
@@ -395,105 +398,105 @@ lookup_queue(const struct GNUNET_PeerIdentity *peer,
* @param cls NULL
*/
static void
-select_write_cb(void *cls)
+select_write_cb (void *cls)
{
struct Queue *queue = queue_tail;
const struct GNUNET_MessageHeader *msg = queue->msg;
- size_t msg_size = ntohs(msg->size);
+ size_t msg_size = ntohs (msg->size);
ssize_t sent;
/* take queue of the ready list */
write_task = NULL;
- GNUNET_CONTAINER_DLL_remove(queue_head, queue_tail, queue);
+ GNUNET_CONTAINER_DLL_remove (queue_head, queue_tail, queue);
if (NULL != queue_head)
- write_task = GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL,
- unix_sock,
- &select_write_cb,
- NULL);
+ write_task = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ unix_sock,
+ &select_write_cb,
+ NULL);
/* send 'msg' */
queue->msg = NULL;
- GNUNET_MQ_impl_send_continue(queue->mq);
+ GNUNET_MQ_impl_send_continue (queue->mq);
resend:
/* Send the data */
- sent = GNUNET_NETWORK_socket_sendto(unix_sock,
- msg,
- msg_size,
- (const struct sockaddr *)queue->address,
- queue->address_len);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "UNIX transmitted message to %s (%d/%u: %s)\n",
- GNUNET_i2s(&queue->target),
- (int)sent,
- (unsigned int)msg_size,
- (sent < 0) ? strerror(errno) : "ok");
+ sent = GNUNET_NETWORK_socket_sendto (unix_sock,
+ msg,
+ msg_size,
+ (const struct sockaddr *) queue->address,
+ queue->address_len);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "UNIX transmitted message to %s (%d/%u: %s)\n",
+ GNUNET_i2s (&queue->target),
+ (int) sent,
+ (unsigned int) msg_size,
+ (sent < 0) ? strerror (errno) : "ok");
if (-1 != sent)
- {
- GNUNET_STATISTICS_update(stats,
- "# bytes sent",
- (long long)sent,
- GNUNET_NO);
- reschedule_queue_timeout(queue);
- return; /* all good */
- }
- GNUNET_STATISTICS_update(stats,
- "# network transmission failures",
- 1,
- GNUNET_NO);
+ {
+ GNUNET_STATISTICS_update (stats,
+ "# bytes sent",
+ (long long) sent,
+ GNUNET_NO);
+ reschedule_queue_timeout (queue);
+ return; /* all good */
+ }
+ GNUNET_STATISTICS_update (stats,
+ "# network transmission failures",
+ 1,
+ GNUNET_NO);
switch (errno)
- {
- case EAGAIN:
- case ENOBUFS:
- /* We should retry later... */
- GNUNET_log_strerror(GNUNET_ERROR_TYPE_DEBUG, "send");
- return;
+ {
+ case EAGAIN:
+ case ENOBUFS:
+ /* We should retry later... */
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send");
+ return;
- case EMSGSIZE: {
+ case EMSGSIZE: {
socklen_t size = 0;
socklen_t len = sizeof(size);
- GNUNET_NETWORK_socket_getsockopt(unix_sock,
- SOL_SOCKET,
- SO_SNDBUF,
- &size,
- &len);
- if (size > ntohs(msg->size))
- {
- /* Buffer is bigger than message: error, no retry
- * This should never happen!*/
- GNUNET_break(0);
- return;
- }
- GNUNET_log(
+ GNUNET_NETWORK_socket_getsockopt (unix_sock,
+ SOL_SOCKET,
+ SO_SNDBUF,
+ &size,
+ &len);
+ if (size > ntohs (msg->size))
+ {
+ /* Buffer is bigger than message: error, no retry
+ * This should never happen!*/
+ GNUNET_break (0);
+ return;
+ }
+ GNUNET_log (
GNUNET_ERROR_TYPE_DEBUG,
"Trying to increase socket buffer size from %u to %u for message size %u\n",
- (unsigned int)size,
- (unsigned int)((msg_size / 1000) + 2) * 1000,
- (unsigned int)msg_size);
+ (unsigned int) size,
+ (unsigned int) ((msg_size / 1000) + 2) * 1000,
+ (unsigned int) msg_size);
size = ((msg_size / 1000) + 2) * 1000;
- if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt(unix_sock,
- SOL_SOCKET,
- SO_SNDBUF,
- &size,
- sizeof(size)))
+ if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt (unix_sock,
+ SOL_SOCKET,
+ SO_SNDBUF,
+ &size,
+ sizeof(size)))
goto resend; /* Increased buffer size, retry sending */
/* Ok, then just try very modest increase */
size = msg_size;
- if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt(unix_sock,
- SOL_SOCKET,
- SO_SNDBUF,
- &size,
- sizeof(size)))
+ if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt (unix_sock,
+ SOL_SOCKET,
+ SO_SNDBUF,
+ &size,
+ sizeof(size)))
goto resend; /* Increased buffer size, retry sending */
/* Could not increase buffer size: error, no retry */
- GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "setsockopt");
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt");
return;
}
- default:
- GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "send");
- return;
- }
+ default:
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "send");
+ return;
+ }
}
@@ -506,22 +509,22 @@ resend:
* @param impl_state our `struct Queue`
*/
static void
-mq_send(struct GNUNET_MQ_Handle *mq,
- const struct GNUNET_MessageHeader *msg,
- void *impl_state)
+mq_send (struct GNUNET_MQ_Handle *mq,
+ const struct GNUNET_MessageHeader *msg,
+ void *impl_state)
{
struct Queue *queue = impl_state;
- GNUNET_assert(mq == queue->mq);
- GNUNET_assert(NULL == queue->msg);
+ GNUNET_assert (mq == queue->mq);
+ GNUNET_assert (NULL == queue->msg);
queue->msg = msg;
- GNUNET_CONTAINER_DLL_insert(queue_head, queue_tail, queue);
- GNUNET_assert(NULL != unix_sock);
+ GNUNET_CONTAINER_DLL_insert (queue_head, queue_tail, queue);
+ GNUNET_assert (NULL != unix_sock);
if (NULL == write_task)
- write_task = GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL,
- unix_sock,
- &select_write_cb,
- NULL);
+ write_task = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ unix_sock,
+ &select_write_cb,
+ NULL);
}
@@ -534,15 +537,15 @@ mq_send(struct GNUNET_MQ_Handle *mq,
* @param impl_state our `struct Queue`
*/
static void
-mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
+mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
{
struct Queue *queue = impl_state;
if (mq == queue->mq)
- {
- queue->mq = NULL;
- queue_destroy(queue);
- }
+ {
+ queue->mq = NULL;
+ queue_destroy (queue);
+ }
}
@@ -553,19 +556,19 @@ mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
* @param impl_state our `struct Queue`
*/
static void
-mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
+mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
{
struct Queue *queue = impl_state;
- GNUNET_assert(NULL != queue->msg);
+ GNUNET_assert (NULL != queue->msg);
queue->msg = NULL;
- GNUNET_CONTAINER_DLL_remove(queue_head, queue_tail, queue);
- GNUNET_assert(NULL != write_task);
+ GNUNET_CONTAINER_DLL_remove (queue_head, queue_tail, queue);
+ GNUNET_assert (NULL != write_task);
if (NULL == queue_head)
- {
- GNUNET_SCHEDULER_cancel(write_task);
- write_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (write_task);
+ write_task = NULL;
+ }
}
@@ -579,15 +582,15 @@ mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
* @param error error code
*/
static void
-mq_error(void *cls, enum GNUNET_MQ_Error error)
+mq_error (void *cls, enum GNUNET_MQ_Error error)
{
struct Queue *queue = cls;
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "UNIX MQ error in queue to %s: %d\n",
- GNUNET_i2s(&queue->target),
- (int)error);
- queue_destroy(queue);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "UNIX MQ error in queue to %s: %d\n",
+ GNUNET_i2s (&queue->target),
+ (int) error);
+ queue_destroy (queue);
}
@@ -602,60 +605,60 @@ mq_error(void *cls, enum GNUNET_MQ_Error error)
* @return the queue or NULL of max connections exceeded
*/
static struct Queue *
-setup_queue(const struct GNUNET_PeerIdentity *target,
- enum GNUNET_TRANSPORT_ConnectionStatus cs,
- const struct sockaddr_un *un,
- socklen_t un_len)
+setup_queue (const struct GNUNET_PeerIdentity *target,
+ enum GNUNET_TRANSPORT_ConnectionStatus cs,
+ const struct sockaddr_un *un,
+ socklen_t un_len)
{
struct Queue *queue;
- queue = GNUNET_new(struct Queue);
+ queue = GNUNET_new (struct Queue);
queue->target = *target;
- queue->address = GNUNET_memdup(un, un_len);
+ queue->address = GNUNET_memdup (un, un_len);
queue->address_len = un_len;
- (void)GNUNET_CONTAINER_multipeermap_put(
+ (void) GNUNET_CONTAINER_multipeermap_put (
queue_map,
&queue->target,
queue,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
- GNUNET_STATISTICS_set(stats,
- "# queues active",
- GNUNET_CONTAINER_multipeermap_size(queue_map),
- GNUNET_NO);
+ GNUNET_STATISTICS_set (stats,
+ "# queues active",
+ GNUNET_CONTAINER_multipeermap_size (queue_map),
+ GNUNET_NO);
queue->timeout =
- GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_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->mq = GNUNET_MQ_queue_for_callbacks(&mq_send,
- &mq_destroy,
- &mq_cancel,
- queue,
- NULL,
- &mq_error,
- queue);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
+ &queue_timeout,
+ queue);
+ queue->mq = GNUNET_MQ_queue_for_callbacks (&mq_send,
+ &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]);
+ GNUNET_asprintf (&foreign_addr,
+ "%s-@%s",
+ COMMUNICATOR_ADDRESS_PREFIX,
+ &un->sun_path[1]);
else
- GNUNET_asprintf(&foreign_addr,
- "%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);
- GNUNET_free(foreign_addr);
+ GNUNET_asprintf (&foreign_addr,
+ "%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);
+ GNUNET_free (foreign_addr);
}
return queue;
}
@@ -669,7 +672,7 @@ setup_queue(const struct GNUNET_PeerIdentity *target,
* @param cls NULL
*/
static void
-select_read_cb(void *cls);
+select_read_cb (void *cls);
/**
@@ -680,21 +683,21 @@ select_read_cb(void *cls);
* @param success #GNUNET_OK on success
*/
static void
-receive_complete_cb(void *cls, int success)
+receive_complete_cb (void *cls, int success)
{
- (void)cls;
+ (void) cls;
delivering_messages--;
if (GNUNET_OK != success)
- GNUNET_STATISTICS_update(stats,
- "# transport transmission failures",
- 1,
- GNUNET_NO);
- GNUNET_assert(NULL != unix_sock);
+ GNUNET_STATISTICS_update (stats,
+ "# 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);
+ read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ unix_sock,
+ &select_read_cb,
+ NULL);
}
@@ -706,7 +709,7 @@ receive_complete_cb(void *cls, int success)
* @param cls NULL
*/
static void
-select_read_cb(void *cls)
+select_read_cb (void *cls)
{
char buf[65536] GNUNET_ALIGN;
struct Queue *queue;
@@ -716,93 +719,93 @@ select_read_cb(void *cls)
ssize_t ret;
uint16_t msize;
- GNUNET_assert(NULL != unix_sock);
- read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL,
- 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);
addrlen = sizeof(un);
- memset(&un, 0, sizeof(un));
- ret = GNUNET_NETWORK_socket_recvfrom(unix_sock,
- buf,
- sizeof(buf),
- (struct sockaddr *)&un,
- &addrlen);
+ memset (&un, 0, sizeof(un));
+ ret = GNUNET_NETWORK_socket_recvfrom (unix_sock,
+ buf,
+ sizeof(buf),
+ (struct sockaddr *) &un,
+ &addrlen);
if ((-1 == ret) && ((EAGAIN == errno) || (ENOBUFS == errno)))
return;
if (-1 == ret)
- {
- GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "recvfrom");
- return;
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "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);
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom");
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "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);
if ((msize < sizeof(struct UNIXMessage)) || (msize > ret))
- {
- GNUNET_break_op(0);
- return;
- }
- queue = lookup_queue(&msg->sender, &un, addrlen);
+ {
+ GNUNET_break_op (0);
+ return;
+ }
+ queue = lookup_queue (&msg->sender, &un, addrlen);
if (NULL == queue)
queue =
- setup_queue(&msg->sender, GNUNET_TRANSPORT_CS_INBOUND, &un, addrlen);
+ setup_queue (&msg->sender, GNUNET_TRANSPORT_CS_INBOUND, &un, addrlen);
else
- reschedule_queue_timeout(queue);
+ reschedule_queue_timeout (queue);
if (NULL == queue)
- {
- GNUNET_log(
- GNUNET_ERROR_TYPE_ERROR,
- _(
- "Maximum number of UNIX connections exceeded, dropping incoming message\n"));
- return;
- }
+ {
+ GNUNET_log (
+ GNUNET_ERROR_TYPE_ERROR,
+ _ (
+ "Maximum number of UNIX connections exceeded, dropping incoming message\n"));
+ return;
+ }
{
uint16_t offset = 0;
uint16_t tsize = msize - sizeof(struct UNIXMessage);
- const char *msgbuf = (const char *)&msg[1];
+ const char *msgbuf = (const char *) &msg[1];
while (offset + sizeof(struct GNUNET_MessageHeader) <= tsize)
+ {
+ const struct GNUNET_MessageHeader *currhdr;
+ struct GNUNET_MessageHeader al_hdr;
+ uint16_t csize;
+
+ currhdr = (const struct GNUNET_MessageHeader *) &msgbuf[offset];
+ /* ensure aligned access */
+ memcpy (&al_hdr, currhdr, sizeof(al_hdr));
+ csize = ntohs (al_hdr.size);
+ if ((csize < sizeof(struct GNUNET_MessageHeader)) ||
+ (csize > tsize - offset))
{
- const struct GNUNET_MessageHeader *currhdr;
- struct GNUNET_MessageHeader al_hdr;
- uint16_t csize;
-
- currhdr = (const struct GNUNET_MessageHeader *)&msgbuf[offset];
- /* ensure aligned access */
- memcpy(&al_hdr, currhdr, sizeof(al_hdr));
- csize = ntohs(al_hdr.size);
- if ((csize < sizeof(struct GNUNET_MessageHeader)) ||
- (csize > tsize - offset))
- {
- GNUNET_break_op(0);
- break;
- }
- ret = GNUNET_TRANSPORT_communicator_receive(ch,
- &msg->sender,
- currhdr,
- GNUNET_TIME_UNIT_FOREVER_REL,
- &receive_complete_cb,
- NULL);
- if (GNUNET_SYSERR == ret)
- return; /* transport not up */
- if (GNUNET_NO == ret)
- break;
- delivering_messages++;
- offset += csize;
+ GNUNET_break_op (0);
+ break;
}
+ ret = GNUNET_TRANSPORT_communicator_receive (ch,
+ &msg->sender,
+ currhdr,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ &receive_complete_cb,
+ NULL);
+ if (GNUNET_SYSERR == ret)
+ return; /* transport not up */
+ if (GNUNET_NO == ret)
+ break;
+ delivering_messages++;
+ offset += csize;
+ }
}
if (delivering_messages >= max_queue_length)
- {
- /* we should try to apply 'back pressure' */
- GNUNET_SCHEDULER_cancel(read_task);
- read_task = NULL;
- }
+ {
+ /* we should try to apply 'back pressure' */
+ GNUNET_SCHEDULER_cancel (read_task);
+ read_task = NULL;
+ }
}
@@ -824,43 +827,43 @@ select_read_cb(void *cls)
* @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is invalid
*/
static int
-mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
+mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
{
struct Queue *queue;
const char *path;
struct sockaddr_un *un;
socklen_t un_len;
- (void)cls;
- if (0 != strncmp(address,
- COMMUNICATOR_ADDRESS_PREFIX "-",
- strlen(COMMUNICATOR_ADDRESS_PREFIX "-")))
- {
- GNUNET_break_op(0);
- return GNUNET_SYSERR;
- }
- path = &address[strlen(COMMUNICATOR_ADDRESS_PREFIX "-")];
- un = unix_address_to_sockaddr(path, &un_len);
- queue = lookup_queue(peer, un, un_len);
+ (void) cls;
+ if (0 != strncmp (address,
+ COMMUNICATOR_ADDRESS_PREFIX "-",
+ strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
+ un = unix_address_to_sockaddr (path, &un_len);
+ queue = lookup_queue (peer, un, un_len);
if (NULL != queue)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Address `%s' for %s ignored, queue exists\n",
- path,
- GNUNET_i2s(peer));
- GNUNET_free(un);
- return GNUNET_OK;
- }
- queue = setup_queue(peer, GNUNET_TRANSPORT_CS_OUTBOUND, un, un_len);
- GNUNET_free(un);
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Address `%s' for %s ignored, queue exists\n",
+ path,
+ GNUNET_i2s (peer));
+ GNUNET_free (un);
+ return GNUNET_OK;
+ }
+ queue = setup_queue (peer, 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);
- return GNUNET_NO;
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Failed to setup queue to %s at `%s'\n",
+ GNUNET_i2s (peer),
+ path);
+ return GNUNET_NO;
+ }
return GNUNET_OK;
}
@@ -874,15 +877,15 @@ mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
* @return #GNUNET_OK to continue to iterate
*/
static int
-get_queue_delete_it(void *cls,
- const struct GNUNET_PeerIdentity *target,
- void *value)
+get_queue_delete_it (void *cls,
+ const struct GNUNET_PeerIdentity *target,
+ void *value)
{
struct Queue *queue = value;
- (void)cls;
- (void)target;
- queue_destroy(queue);
+ (void) cls;
+ (void) target;
+ queue_destroy (queue);
return GNUNET_OK;
}
@@ -893,40 +896,40 @@ get_queue_delete_it(void *cls,
* @param cls NULL (always)
*/
static void
-do_shutdown(void *cls)
+do_shutdown (void *cls)
{
if (NULL != read_task)
- {
- GNUNET_SCHEDULER_cancel(read_task);
- read_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (read_task);
+ read_task = NULL;
+ }
if (NULL != write_task)
- {
- GNUNET_SCHEDULER_cancel(write_task);
- write_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (write_task);
+ write_task = NULL;
+ }
if (NULL != unix_sock)
- {
- GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(unix_sock));
- unix_sock = NULL;
- }
- GNUNET_CONTAINER_multipeermap_iterate(queue_map, &get_queue_delete_it, NULL);
- GNUNET_CONTAINER_multipeermap_destroy(queue_map);
+ {
+ GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (unix_sock));
+ unix_sock = NULL;
+ }
+ GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL);
+ GNUNET_CONTAINER_multipeermap_destroy (queue_map);
if (NULL != ai)
- {
- GNUNET_TRANSPORT_communicator_address_remove(ai);
- ai = NULL;
- }
+ {
+ GNUNET_TRANSPORT_communicator_address_remove (ai);
+ ai = NULL;
+ }
if (NULL != ch)
- {
- GNUNET_TRANSPORT_communicator_disconnect(ch);
- ch = NULL;
- }
+ {
+ GNUNET_TRANSPORT_communicator_disconnect (ch);
+ ch = NULL;
+ }
if (NULL != stats)
- {
- GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
- stats = NULL;
- }
+ {
+ GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
+ stats = NULL;
+ }
}
@@ -942,14 +945,14 @@ do_shutdown(void *cls)
* @param msg payload
*/
static void
-enc_notify_cb(void *cls,
- const struct GNUNET_PeerIdentity *sender,
- const struct GNUNET_MessageHeader *msg)
+enc_notify_cb (void *cls,
+ const struct GNUNET_PeerIdentity *sender,
+ const struct GNUNET_MessageHeader *msg)
{
- (void)cls;
- (void)sender;
- (void)msg;
- GNUNET_break_op(0);
+ (void) cls;
+ (void) sender;
+ (void) msg;
+ GNUNET_break_op (0);
}
@@ -962,110 +965,110 @@ enc_notify_cb(void *cls,
* @param cfg configuration
*/
static void
-run(void *cls,
- char *const *args,
- const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
+run (void *cls,
+ char *const *args,
+ const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
char *unix_socket_path;
struct sockaddr_un *un;
socklen_t un_len;
char *my_addr;
- (void)cls;
+ (void) cls;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename(cfg,
- COMMUNICATOR_CONFIG_SECTION,
- "UNIXPATH",
- &unix_socket_path))
- {
- GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR,
- COMMUNICATOR_CONFIG_SECTION,
- "UNIXPATH");
- return;
- }
+ GNUNET_CONFIGURATION_get_value_filename (cfg,
+ COMMUNICATOR_CONFIG_SECTION,
+ "UNIXPATH",
+ &unix_socket_path))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ COMMUNICATOR_CONFIG_SECTION,
+ "UNIXPATH");
+ return;
+ }
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_number(cfg,
- COMMUNICATOR_CONFIG_SECTION,
- "MAX_QUEUE_LENGTH",
- &max_queue_length))
+ GNUNET_CONFIGURATION_get_value_number (cfg,
+ COMMUNICATOR_CONFIG_SECTION,
+ "MAX_QUEUE_LENGTH",
+ &max_queue_length))
max_queue_length = DEFAULT_MAX_QUEUE_LENGTH;
- un = unix_address_to_sockaddr(unix_socket_path, &un_len);
+ un = unix_address_to_sockaddr (unix_socket_path, &un_len);
if (NULL == un)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Failed to setup UNIX domain socket address with path `%s'\n",
- unix_socket_path);
- GNUNET_free(unix_socket_path);
- return;
- }
- unix_sock = GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_DGRAM, 0);
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to setup UNIX domain socket address with path `%s'\n",
+ unix_socket_path);
+ GNUNET_free (unix_socket_path);
+ return;
+ }
+ unix_sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0);
if (NULL == unix_sock)
- {
- GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket");
- GNUNET_free(un);
- GNUNET_free(unix_socket_path);
- return;
- }
+ {
+ GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
+ GNUNET_free (un);
+ GNUNET_free (unix_socket_path);
+ return;
+ }
if (('\0' != un->sun_path[0]) &&
- (GNUNET_OK != GNUNET_DISK_directory_create_for_file(un->sun_path)))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- _("Cannot create path to `%s'\n"),
- un->sun_path);
- GNUNET_NETWORK_socket_close(unix_sock);
- unix_sock = NULL;
- GNUNET_free(un);
- GNUNET_free(unix_socket_path);
- return;
- }
- if (GNUNET_OK != GNUNET_NETWORK_socket_bind(unix_sock,
- (const struct sockaddr *)un,
- un_len))
- {
- GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "bind", un->sun_path);
- GNUNET_NETWORK_socket_close(unix_sock);
- unix_sock = NULL;
- GNUNET_free(un);
- GNUNET_free(unix_socket_path);
- return;
- }
- GNUNET_free(un);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", unix_socket_path);
- stats = GNUNET_STATISTICS_create("C-UNIX", cfg);
- GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL);
- read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL,
- unix_sock,
- &select_read_cb,
- NULL);
- queue_map = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO);
- ch = GNUNET_TRANSPORT_communicator_connect(cfg,
- COMMUNICATOR_CONFIG_SECTION,
- COMMUNICATOR_ADDRESS_PREFIX,
- GNUNET_TRANSPORT_CC_RELIABLE,
- &mq_init,
- NULL,
- &enc_notify_cb,
+ (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Cannot create path to `%s'\n"),
+ un->sun_path);
+ GNUNET_NETWORK_socket_close (unix_sock);
+ unix_sock = NULL;
+ GNUNET_free (un);
+ GNUNET_free (unix_socket_path);
+ return;
+ }
+ if (GNUNET_OK != GNUNET_NETWORK_socket_bind (unix_sock,
+ (const struct sockaddr *) un,
+ un_len))
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", un->sun_path);
+ GNUNET_NETWORK_socket_close (unix_sock);
+ unix_sock = NULL;
+ GNUNET_free (un);
+ GNUNET_free (unix_socket_path);
+ return;
+ }
+ GNUNET_free (un);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", unix_socket_path);
+ stats = GNUNET_STATISTICS_create ("C-UNIX", cfg);
+ GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
+ read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
+ unix_sock,
+ &select_read_cb,
NULL);
+ queue_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
+ ch = GNUNET_TRANSPORT_communicator_connect (cfg,
+ COMMUNICATOR_CONFIG_SECTION,
+ COMMUNICATOR_ADDRESS_PREFIX,
+ GNUNET_TRANSPORT_CC_RELIABLE,
+ &mq_init,
+ NULL,
+ &enc_notify_cb,
+ NULL);
if (NULL == ch)
- {
- GNUNET_break(0);
- GNUNET_SCHEDULER_shutdown();
- GNUNET_free(unix_socket_path);
- return;
- }
- GNUNET_asprintf(&my_addr,
- "%s-%s",
- COMMUNICATOR_ADDRESS_PREFIX,
- unix_socket_path);
- GNUNET_free(unix_socket_path);
- ai = GNUNET_TRANSPORT_communicator_address_add(ch,
- my_addr,
- GNUNET_NT_LOOPBACK,
- GNUNET_TIME_UNIT_FOREVER_REL);
- GNUNET_free(my_addr);
+ {
+ GNUNET_break (0);
+ GNUNET_SCHEDULER_shutdown ();
+ GNUNET_free (unix_socket_path);
+ return;
+ }
+ GNUNET_asprintf (&my_addr,
+ "%s-%s",
+ COMMUNICATOR_ADDRESS_PREFIX,
+ unix_socket_path);
+ GNUNET_free (unix_socket_path);
+ ai = GNUNET_TRANSPORT_communicator_address_add (ch,
+ my_addr,
+ GNUNET_NT_LOOPBACK,
+ GNUNET_TIME_UNIT_FOREVER_REL);
+ GNUNET_free (my_addr);
}
@@ -1077,27 +1080,27 @@ run(void *cls,
* @return 0 ok, 1 on error
*/
int
-main(int argc, char *const *argv)
+main (int argc, char *const *argv)
{
static const struct GNUNET_GETOPT_CommandLineOption options[] = {
GNUNET_GETOPT_OPTION_END
};
int ret;
- if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
+ if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
ret = (GNUNET_OK ==
- GNUNET_PROGRAM_run(argc,
- argv,
- "gnunet-communicator-unix",
- _("GNUnet UNIX domain socket communicator"),
- options,
- &run,
- NULL))
+ GNUNET_PROGRAM_run (argc,
+ argv,
+ "gnunet-communicator-unix",
+ _ ("GNUnet UNIX domain socket communicator"),
+ options,
+ &run,
+ NULL))
? 0
: 1;
- GNUNET_free((void *)argv);
+ GNUNET_free ((void *) argv);
return ret;
}
@@ -1108,11 +1111,11 @@ main(int argc, char *const *argv)
/**
* MINIMIZE heap size (way below 128k) since this process doesn't need much.
*/
-void __attribute__ ((constructor)) GNUNET_ARM_memory_init()
+void __attribute__ ((constructor)) GNUNET_ARM_memory_init ()
{
- mallopt(M_TRIM_THRESHOLD, 4 * 1024);
- mallopt(M_TOP_PAD, 1 * 1024);
- malloc_trim(0);
+ mallopt (M_TRIM_THRESHOLD, 4 * 1024);
+ mallopt (M_TOP_PAD, 1 * 1024);
+ malloc_trim (0);
}
#endif
diff --git a/src/transport/gnunet-helper-transport-bluetooth.c b/src/transport/gnunet-helper-transport-bluetooth.c
index 4696f48f8..c0e0d9673 100644
--- a/src/transport/gnunet-helper-transport-bluetooth.c
+++ b/src/transport/gnunet-helper-transport-bluetooth.c
@@ -69,7 +69,8 @@
* struct for storing the information of the hardware. There is only
* one of these.
*/
-struct HardwareInfos {
+struct HardwareInfos
+{
/**
* Name of the interface, not necessarily 0-terminated (!).
*/
@@ -94,7 +95,8 @@ struct HardwareInfos {
/**
* IO buffer used for buffering data in transit (to wireless or to stdout).
*/
-struct SendBuffer {
+struct SendBuffer
+{
/**
* How many bytes of data are stored in 'buf' for transmission right now?
* Data always starts at offset 0 and extends to 'size'.
@@ -119,7 +121,8 @@ struct SendBuffer {
* Devices buffer used to keep a list with all the discoverable devices in
* order to send them HELLO messages one by one when it receive a broadcast message.
*/
-struct BroadcastMessages {
+struct BroadcastMessages
+{
/* List with the discoverable devices' addresses */
bdaddr_t devices[MAX_PORTS];
@@ -140,7 +143,10 @@ struct BroadcastMessages {
/**
* Address used to identify the broadcast messages.
*/
-static struct GNUNET_TRANSPORT_WLAN_MacAddress broadcast_address = { { 255, 255, 255, 255, 255, 255 } };
+static struct GNUNET_TRANSPORT_WLAN_MacAddress broadcast_address = { { 255, 255,
+ 255, 255,
+ 255,
+ 255 } };
/**
* Buffer with the discoverable devices.
@@ -190,7 +196,8 @@ typedef void (*MessageTokenizerCallback) (void *cls,
/**
* Handle to a message stream tokenizer.
*/
-struct MessageStreamTokenizer {
+struct MessageStreamTokenizer
+{
/**
* Function to call on completed messages.
*/
@@ -231,23 +238,23 @@ struct MessageStreamTokenizer {
* @return handle to tokenizer
*/
static struct MessageStreamTokenizer *
-mst_create(MessageTokenizerCallback cb,
- void *cb_cls)
+mst_create (MessageTokenizerCallback cb,
+ void *cb_cls)
{
struct MessageStreamTokenizer *ret;
- ret = malloc(sizeof(struct MessageStreamTokenizer));
+ ret = malloc (sizeof(struct MessageStreamTokenizer));
if (NULL == ret)
- {
- fprintf(stderr, "Failed to allocate buffer for tokenizer\n");
- exit(1);
- }
- ret->hdr = malloc(MIN_BUFFER_SIZE);
+ {
+ fprintf (stderr, "Failed to allocate buffer for tokenizer\n");
+ exit (1);
+ }
+ ret->hdr = malloc (MIN_BUFFER_SIZE);
if (NULL == ret->hdr)
- {
- fprintf(stderr, "Failed to allocate buffer for alignment\n");
- exit(1);
- }
+ {
+ fprintf (stderr, "Failed to allocate buffer for alignment\n");
+ exit (1);
+ }
ret->curr_buf = MIN_BUFFER_SIZE;
ret->cb = cb;
ret->cb_cls = cb_cls;
@@ -268,8 +275,8 @@ mst_create(MessageTokenizerCallback cb,
* GNUNET_SYSERR if the data stream is corrupt
*/
static int
-mst_receive(struct MessageStreamTokenizer *mst,
- const char *buf, size_t size)
+mst_receive (struct MessageStreamTokenizer *mst,
+ const char *buf, size_t size)
{
const struct GNUNET_MessageHeader *hdr;
size_t delta;
@@ -280,161 +287,162 @@ mst_receive(struct MessageStreamTokenizer *mst,
int ret;
ret = GNUNET_OK;
- ibuf = (char *)mst->hdr;
+ ibuf = (char *) mst->hdr;
while (mst->pos > 0)
- {
+ {
do_align:
- if (mst->pos < mst->off)
- {
- //fprintf (stderr, "We processed too many bytes!\n");
- return GNUNET_SYSERR;
- }
- if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) ||
- (0 != (mst->off % ALIGN_FACTOR)))
- {
- /* need to align or need more space */
- mst->pos -= mst->off;
- memmove(ibuf, &ibuf[mst->off], mst->pos);
- mst->off = 0;
- }
- if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
- {
- delta =
- GNUNET_MIN(sizeof(struct GNUNET_MessageHeader) -
- (mst->pos - mst->off), size);
- GNUNET_memcpy(&ibuf[mst->pos], buf, delta);
- mst->pos += delta;
- buf += delta;
- size -= delta;
- }
- if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
- {
- //FIXME should I reset ??
- // mst->off = 0;
- // mst->pos = 0;
- return GNUNET_OK;
- }
- hdr = (const struct GNUNET_MessageHeader *)&ibuf[mst->off];
- want = ntohs(hdr->size);
- if (want < sizeof(struct GNUNET_MessageHeader))
- {
- fprintf(stderr,
- "Received invalid message from stdin\n");
- return GNUNET_SYSERR;
- }
- if ((mst->curr_buf - mst->off < want) &&
- (mst->off > 0))
- {
- /* need more space */
- mst->pos -= mst->off;
- memmove(ibuf, &ibuf[mst->off], mst->pos);
- mst->off = 0;
- }
- if (want > mst->curr_buf)
- {
- if (mst->off != 0)
- {
- fprintf(stderr, "Error! We should proceeded 0 bytes\n");
- return GNUNET_SYSERR;
- }
- mst->hdr = realloc(mst->hdr, want);
- if (NULL == mst->hdr)
- {
- fprintf(stderr, "Failed to allocate buffer for alignment\n");
- exit(1);
- }
- ibuf = (char *)mst->hdr;
- mst->curr_buf = want;
- }
- hdr = (const struct GNUNET_MessageHeader *)&ibuf[mst->off];
- if (mst->pos - mst->off < want)
- {
- delta = GNUNET_MIN(want - (mst->pos - mst->off), size);
- if (mst->pos + delta > mst->curr_buf)
- {
- fprintf(stderr, "The size of the buffer will be exceeded!\n");
- return GNUNET_SYSERR;
- }
- GNUNET_memcpy(&ibuf[mst->pos], buf, delta);
- mst->pos += delta;
- buf += delta;
- size -= delta;
- }
- if (mst->pos - mst->off < want)
- {
- //FIXME should I use this?
- // mst->off = 0;
- // mst->pos = 0;
- return GNUNET_OK;
- }
- mst->cb(mst->cb_cls, hdr);
- mst->off += want;
- if (mst->off == mst->pos)
- {
- /* reset to beginning of buffer, it's free right now! */
- mst->off = 0;
- mst->pos = 0;
- }
+ if (mst->pos < mst->off)
+ {
+ // fprintf (stderr, "We processed too many bytes!\n");
+ return GNUNET_SYSERR;
}
- if (0 != mst->pos)
+ if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) ||
+ (0 != (mst->off % ALIGN_FACTOR)))
+ {
+ /* need to align or need more space */
+ mst->pos -= mst->off;
+ memmove (ibuf, &ibuf[mst->off], mst->pos);
+ mst->off = 0;
+ }
+ if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
+ {
+ delta =
+ GNUNET_MIN (sizeof(struct GNUNET_MessageHeader)
+ - (mst->pos - mst->off), size);
+ GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
+ mst->pos += delta;
+ buf += delta;
+ size -= delta;
+ }
+ if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
+ {
+ // FIXME should I reset ??
+ // mst->off = 0;
+ // mst->pos = 0;
+ return GNUNET_OK;
+ }
+ hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
+ want = ntohs (hdr->size);
+ if (want < sizeof(struct GNUNET_MessageHeader))
{
- fprintf(stderr, "There should some valid bytes in the buffer on this stage\n");
+ fprintf (stderr,
+ "Received invalid message from stdin\n");
return GNUNET_SYSERR;
}
+ if ((mst->curr_buf - mst->off < want) &&
+ (mst->off > 0))
+ {
+ /* need more space */
+ mst->pos -= mst->off;
+ memmove (ibuf, &ibuf[mst->off], mst->pos);
+ mst->off = 0;
+ }
+ if (want > mst->curr_buf)
+ {
+ if (mst->off != 0)
+ {
+ fprintf (stderr, "Error! We should proceeded 0 bytes\n");
+ return GNUNET_SYSERR;
+ }
+ mst->hdr = realloc (mst->hdr, want);
+ if (NULL == mst->hdr)
+ {
+ fprintf (stderr, "Failed to allocate buffer for alignment\n");
+ exit (1);
+ }
+ ibuf = (char *) mst->hdr;
+ mst->curr_buf = want;
+ }
+ hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
+ if (mst->pos - mst->off < want)
+ {
+ delta = GNUNET_MIN (want - (mst->pos - mst->off), size);
+ if (mst->pos + delta > mst->curr_buf)
+ {
+ fprintf (stderr, "The size of the buffer will be exceeded!\n");
+ return GNUNET_SYSERR;
+ }
+ GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
+ mst->pos += delta;
+ buf += delta;
+ size -= delta;
+ }
+ if (mst->pos - mst->off < want)
+ {
+ // FIXME should I use this?
+ // mst->off = 0;
+ // mst->pos = 0;
+ return GNUNET_OK;
+ }
+ mst->cb (mst->cb_cls, hdr);
+ mst->off += want;
+ if (mst->off == mst->pos)
+ {
+ /* reset to beginning of buffer, it's free right now! */
+ mst->off = 0;
+ mst->pos = 0;
+ }
+ }
+ if (0 != mst->pos)
+ {
+ fprintf (stderr,
+ "There should some valid bytes in the buffer on this stage\n");
+ return GNUNET_SYSERR;
+ }
while (size > 0)
+ {
+ if (size < sizeof(struct GNUNET_MessageHeader))
+ break;
+ offset = (unsigned long) buf;
+ need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO;
+ if (GNUNET_NO == need_align)
{
- if (size < sizeof(struct GNUNET_MessageHeader))
- break;
- offset = (unsigned long)buf;
- need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO;
- if (GNUNET_NO == need_align)
- {
- /* can try to do zero-copy and process directly from original buffer */
- hdr = (const struct GNUNET_MessageHeader *)buf;
- want = ntohs(hdr->size);
- if (want < sizeof(struct GNUNET_MessageHeader))
- {
- fprintf(stderr,
- "Received invalid message from stdin\n");
- //exit (1);
- mst->off = 0;
- return GNUNET_SYSERR;
- }
- if (size < want)
- break; /* or not, buffer incomplete, so copy to private buffer... */
- mst->cb(mst->cb_cls, hdr);
- buf += want;
- size -= want;
- }
- else
- {
- /* need to copy to private buffer to align;
- * yes, we go a bit more spagetti than usual here */
- goto do_align;
- }
+ /* can try to do zero-copy and process directly from original buffer */
+ hdr = (const struct GNUNET_MessageHeader *) buf;
+ want = ntohs (hdr->size);
+ if (want < sizeof(struct GNUNET_MessageHeader))
+ {
+ fprintf (stderr,
+ "Received invalid message from stdin\n");
+ // exit (1);
+ mst->off = 0;
+ return GNUNET_SYSERR;
+ }
+ if (size < want)
+ break; /* or not, buffer incomplete, so copy to private buffer... */
+ mst->cb (mst->cb_cls, hdr);
+ buf += want;
+ size -= want;
}
+ else
+ {
+ /* need to copy to private buffer to align;
+ * yes, we go a bit more spagetti than usual here */
+ goto do_align;
+ }
+ }
if (size > 0)
+ {
+ if (size + mst->pos > mst->curr_buf)
{
- if (size + mst->pos > mst->curr_buf)
- {
- mst->hdr = realloc(mst->hdr, size + mst->pos);
- if (NULL == mst->hdr)
- {
- fprintf(stderr, "Failed to allocate buffer for alignment\n");
- exit(1);
- }
- ibuf = (char *)mst->hdr;
- mst->curr_buf = size + mst->pos;
- }
- if (mst->pos + size > mst->curr_buf)
- {
- fprintf(stderr,
- "Assertion failed\n");
- exit(1);
- }
- GNUNET_memcpy(&ibuf[mst->pos], buf, size);
- mst->pos += size;
+ mst->hdr = realloc (mst->hdr, size + mst->pos);
+ if (NULL == mst->hdr)
+ {
+ fprintf (stderr, "Failed to allocate buffer for alignment\n");
+ exit (1);
+ }
+ ibuf = (char *) mst->hdr;
+ mst->curr_buf = size + mst->pos;
+ }
+ if (mst->pos + size > mst->curr_buf)
+ {
+ fprintf (stderr,
+ "Assertion failed\n");
+ exit (1);
}
+ GNUNET_memcpy (&ibuf[mst->pos], buf, size);
+ mst->pos += size;
+ }
return ret;
}
@@ -444,10 +452,10 @@ do_align:
* @param mst tokenizer to destroy
*/
static void
-mst_destroy(struct MessageStreamTokenizer *mst)
+mst_destroy (struct MessageStreamTokenizer *mst)
{
- free(mst->hdr);
- free(mst);
+ free (mst->hdr);
+ free (mst);
}
/**
@@ -458,7 +466,7 @@ mst_destroy(struct MessageStreamTokenizer *mst)
* @return crc sum
*/
static unsigned long
-calc_crc_osdep(const unsigned char *buf, size_t len)
+calc_crc_osdep (const unsigned char *buf, size_t len)
{
static const unsigned long int crc_tbl_osdep[256] = {
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F,
@@ -544,14 +552,14 @@ calc_crc_osdep(const unsigned char *buf, size_t len)
* @return 0 on success (checksum matches), 1 on error
*/
static int
-check_crc_buf_osdep(const unsigned char *buf, size_t len)
+check_crc_buf_osdep (const unsigned char *buf, size_t len)
{
unsigned long crc;
- crc = calc_crc_osdep(buf, len);
+ crc = calc_crc_osdep (buf, len);
buf += len;
- if (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] &&
- ((crc >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3])
+ if ((((crc) & 0xFF) == buf[0])&&(((crc >> 8) & 0xFF) == buf[1])&&
+ ( ((crc >> 16) & 0xFF) == buf[2]) &&( ((crc >> 24) & 0xFF) == buf[3]) )
return 0;
return 1;
}
@@ -568,19 +576,20 @@ check_crc_buf_osdep(const unsigned char *buf, size_t len)
* @return 0 on success
*/
static int
-bind_socket(int socket, struct sockaddr_rc *addr)
+bind_socket (int socket, struct sockaddr_rc *addr)
{
int port, status;
/* Bind every possible port (from 0 to 30) and stop when binding doesn't fail */
- //FIXME : it should start from port 1, but on my computer it doesn't work :)
+ // FIXME : it should start from port 1, but on my computer it doesn't work :)
for (port = 3; port <= 30; port++)
- {
- addr->rc_channel = port;
- status = bind(socket, (struct sockaddr *)addr, sizeof(struct sockaddr_rc));
- if (status == 0)
- return 0;
- }
+ {
+ addr->rc_channel = port;
+ status = bind (socket, (struct sockaddr *) addr, sizeof(struct
+ sockaddr_rc));
+ if (status == 0)
+ return 0;
+ }
return -1;
}
@@ -594,7 +603,7 @@ bind_socket(int socket, struct sockaddr_rc *addr)
* @return 0 on success
*/
static int
-register_service(struct HardwareInfos *dev, int rc_channel)
+register_service (struct HardwareInfos *dev, int rc_channel)
{
/**
* 1. initializations
@@ -606,8 +615,10 @@ register_service(struct HardwareInfos *dev, int rc_channel)
* 7. cleanup
*/
uint8_t svc_uuid_int[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- dev->pl_mac.mac[5], dev->pl_mac.mac[4], dev->pl_mac.mac[3],
- dev->pl_mac.mac[2], dev->pl_mac.mac[1], dev->pl_mac.mac[0] };
+ dev->pl_mac.mac[5], dev->pl_mac.mac[4],
+ dev->pl_mac.mac[3],
+ dev->pl_mac.mac[2], dev->pl_mac.mac[1],
+ dev->pl_mac.mac[0] };
const char *service_dsc = "Bluetooth plugin services";
const char *service_prov = "GNUnet provider";
uuid_t root_uuid, rfcomm_uuid, svc_uuid;
@@ -616,61 +627,63 @@ register_service(struct HardwareInfos *dev, int rc_channel)
sdp_record_t *record = 0;
sdp_data_t *channel = 0;
- record = sdp_record_alloc();
+ record = sdp_record_alloc ();
/* Set the general service ID */
- sdp_uuid128_create(&svc_uuid, &svc_uuid_int);
- svc_list = sdp_list_append(0, &svc_uuid);
- sdp_set_service_classes(record, svc_list);
- sdp_set_service_id(record, svc_uuid);
+ sdp_uuid128_create (&svc_uuid, &svc_uuid_int);
+ svc_list = sdp_list_append (0, &svc_uuid);
+ sdp_set_service_classes (record, svc_list);
+ sdp_set_service_id (record, svc_uuid);
/* Make the service record publicly browsable */
- sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP);
- root_list = sdp_list_append(0, &root_uuid);
- sdp_set_browse_groups(record, root_list);
+ sdp_uuid16_create (&root_uuid, PUBLIC_BROWSE_GROUP);
+ root_list = sdp_list_append (0, &root_uuid);
+ sdp_set_browse_groups (record, root_list);
/* Register the RFCOMM channel */
- sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID);
- channel = sdp_data_alloc(SDP_UINT8, &rc_channel);
- rfcomm_list = sdp_list_append(0, &rfcomm_uuid);
- sdp_list_append(rfcomm_list, channel);
- proto_list = sdp_list_append(0, rfcomm_list);
+ sdp_uuid16_create (&rfcomm_uuid, RFCOMM_UUID);
+ channel = sdp_data_alloc (SDP_UINT8, &rc_channel);
+ rfcomm_list = sdp_list_append (0, &rfcomm_uuid);
+ sdp_list_append (rfcomm_list, channel);
+ proto_list = sdp_list_append (0, rfcomm_list);
/* Set protocol information */
- access_proto_list = sdp_list_append(0, proto_list);
- sdp_set_access_protos(record, access_proto_list);
+ access_proto_list = sdp_list_append (0, proto_list);
+ sdp_set_access_protos (record, access_proto_list);
/* Set the name, provider, and description */
- sdp_set_info_attr(record, dev->iface, service_prov, service_dsc);
+ sdp_set_info_attr (record, dev->iface, service_prov, service_dsc);
/* Connect to the local SDP server */
- dev->session = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY);
+ dev->session = sdp_connect (BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY);
- if (!dev->session)
- {
- fprintf(stderr, "Failed to connect to the SDP server on interface `%.*s': %s\n",
- IFNAMSIZ, dev->iface, strerror(errno));
- //FIXME exit?
- return 1;
- }
+ if (! dev->session)
+ {
+ fprintf (stderr,
+ "Failed to connect to the SDP server on interface `%.*s': %s\n",
+ IFNAMSIZ, dev->iface, strerror (errno));
+ // FIXME exit?
+ return 1;
+ }
/* Register the service record */
- if (sdp_record_register(dev->session, record, 0) < 0)
- {
- fprintf(stderr, "Failed to register a service record on interface `%.*s': %s\n",
- IFNAMSIZ, dev->iface, strerror(errno));
- //FIXME exit?
- return 1;
- }
+ if (sdp_record_register (dev->session, record, 0) < 0)
+ {
+ fprintf (stderr,
+ "Failed to register a service record on interface `%.*s': %s\n",
+ IFNAMSIZ, dev->iface, strerror (errno));
+ // FIXME exit?
+ return 1;
+ }
/* Cleanup */
- sdp_data_free(channel);
- sdp_list_free(root_list, 0);
- sdp_list_free(rfcomm_list, 0);
- sdp_list_free(proto_list, 0);
- sdp_list_free(access_proto_list, 0);
- sdp_list_free(svc_list, 0);
- sdp_record_free(record);
+ sdp_data_free (channel);
+ sdp_list_free (root_list, 0);
+ sdp_list_free (rfcomm_list, 0);
+ sdp_list_free (proto_list, 0);
+ sdp_list_free (access_proto_list, 0);
+ sdp_list_free (svc_list, 0);
+ sdp_record_free (record);
return 0;
}
@@ -684,7 +697,7 @@ register_service(struct HardwareInfos *dev, int rc_channel)
* @return channel
*/
static int
-get_channel(struct HardwareInfos *dev, bdaddr_t dest)
+get_channel (struct HardwareInfos *dev, bdaddr_t dest)
{
/**
* 1. detect all nearby devices
@@ -704,46 +717,48 @@ get_channel(struct HardwareInfos *dev, bdaddr_t dest)
int channel = -1;
/* Connect to the local SDP server */
- session = sdp_connect(BDADDR_ANY, &dest, 0);
- if (!session)
- {
- fprintf(stderr, "Failed to connect to the SDP server on interface `%.*s': %s\n",
- IFNAMSIZ, dev->iface, strerror(errno));
- return -1;
- }
+ session = sdp_connect (BDADDR_ANY, &dest, 0);
+ if (! session)
+ {
+ fprintf (stderr,
+ "Failed to connect to the SDP server on interface `%.*s': %s\n",
+ IFNAMSIZ, dev->iface, strerror (errno));
+ return -1;
+ }
- sdp_uuid128_create(&svc_uuid, &svc_uuid_int);
- search_list = sdp_list_append(0, &svc_uuid);
- attrid_list = sdp_list_append(0, &range);
+ sdp_uuid128_create (&svc_uuid, &svc_uuid_int);
+ search_list = sdp_list_append (0, &svc_uuid);
+ attrid_list = sdp_list_append (0, &range);
- if (sdp_service_search_attr_req(session, search_list,
- SDP_ATTR_REQ_RANGE, attrid_list, &response_list) == 0)
+ if (sdp_service_search_attr_req (session, search_list,
+ SDP_ATTR_REQ_RANGE, attrid_list,
+ &response_list) == 0)
+ {
+ for (it = response_list; it; it = it->next)
{
- for (it = response_list; it; it = it->next)
- {
- sdp_record_t *record = (sdp_record_t*)it->data;
- sdp_list_t *proto_list = 0;
- if (sdp_get_access_protos(record, &proto_list) == 0)
- {
- channel = sdp_get_proto_port(proto_list, RFCOMM_UUID);
- sdp_list_free(proto_list, 0);
- }
- sdp_record_free(record);
- }
+ sdp_record_t *record = (sdp_record_t*) it->data;
+ sdp_list_t *proto_list = 0;
+ if (sdp_get_access_protos (record, &proto_list) == 0)
+ {
+ channel = sdp_get_proto_port (proto_list, RFCOMM_UUID);
+ sdp_list_free (proto_list, 0);
+ }
+ sdp_record_free (record);
}
+ }
- sdp_list_free(search_list, 0);
- sdp_list_free(attrid_list, 0);
- sdp_list_free(response_list, 0);
+ sdp_list_free (search_list, 0);
+ sdp_list_free (attrid_list, 0);
+ sdp_list_free (response_list, 0);
- sdp_close(session);
+ sdp_close (session);
if (-1 == channel)
- fprintf(stderr,
- "Failed to find the listening channel for interface `%.*s': %s\n",
- IFNAMSIZ,
- dev->iface,
- strerror(errno));
+ fprintf (stderr,
+ "Failed to find the listening channel for interface `%.*s': %s\n",
+ IFNAMSIZ,
+ dev->iface,
+ strerror (errno));
return channel;
}
@@ -759,48 +774,50 @@ get_channel(struct HardwareInfos *dev, bdaddr_t dest)
* @return number of bytes written to 'buf'
*/
static ssize_t
-read_from_the_socket(void *sock,
- unsigned char *buf, size_t buf_size,
- struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri)
+read_from_the_socket (void *sock,
+ unsigned char *buf, size_t buf_size,
+ struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri)
{
unsigned char tmpbuf[buf_size];
ssize_t count;
- count = read(*((int *)sock), tmpbuf, buf_size);
+ count = read (*((int *) sock), tmpbuf, buf_size);
if (0 > count)
- {
- if (EAGAIN == errno)
- return 0;
+ {
+ if (EAGAIN == errno)
+ return 0;
- fprintf(stderr, "Failed to read from the HCI socket: %s\n", strerror(errno));
+ fprintf (stderr, "Failed to read from the HCI socket: %s\n", strerror (
+ errno));
- return -1;
- }
+ return -1;
+ }
#ifdef LINUX
/* Get the channel used */
int len;
struct sockaddr_rc rc_addr = { 0 };
- memset(&rc_addr, 0, sizeof(rc_addr));
+ memset (&rc_addr, 0, sizeof(rc_addr));
len = sizeof(rc_addr);
- if (0 > getsockname(*((int *)sock), (struct sockaddr *)&rc_addr, (socklen_t *)&len))
- {
- fprintf(stderr, "getsockname() call failed : %s\n", strerror(errno));
- return -1;
- }
+ if (0 > getsockname (*((int *) sock), (struct sockaddr *) &rc_addr,
+ (socklen_t *) &len))
+ {
+ fprintf (stderr, "getsockname() call failed : %s\n", strerror (errno));
+ return -1;
+ }
- memset(ri, 0, sizeof(*ri));
+ memset (ri, 0, sizeof(*ri));
ri->ri_channel = rc_addr.rc_channel;
#endif
/* Detect CRC32 at the end */
- if (0 == check_crc_buf_osdep(tmpbuf, count - sizeof(uint32_t)))
- {
- count -= sizeof(uint32_t);
- }
+ if (0 == check_crc_buf_osdep (tmpbuf, count - sizeof(uint32_t)))
+ {
+ count -= sizeof(uint32_t);
+ }
- GNUNET_memcpy(buf, tmpbuf, count);
+ GNUNET_memcpy (buf, tmpbuf, count);
return count;
}
@@ -813,14 +830,15 @@ read_from_the_socket(void *sock,
* @return 0 on success, non-zero on error
*/
static int
-open_device(struct HardwareInfos *dev)
+open_device (struct HardwareInfos *dev)
{
int i, dev_id = -1, fd_hci;
- struct {
+ struct
+ {
struct hci_dev_list_req list;
struct hci_dev_req dev[HCI_MAX_DEV];
- } request; //used for detecting the local devices
- struct sockaddr_rc rc_addr = { 0 }; //used for binding
+ } request; // used for detecting the local devices
+ struct sockaddr_rc rc_addr = { 0 }; // used for binding
/* Initialize the neighbour structure */
neighbours.dev_id = -1;
@@ -828,147 +846,148 @@ open_device(struct HardwareInfos *dev)
neighbours.fds[i] = -1;
/* Open a HCI socket */
- fd_hci = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
+ fd_hci = socket (AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
if (fd_hci < 0)
- {
- fprintf(stderr,
- "Failed to create HCI socket: %s\n",
- strerror(errno));
- return -1;
- }
+ {
+ fprintf (stderr,
+ "Failed to create HCI socket: %s\n",
+ strerror (errno));
+ return -1;
+ }
- memset(&request, 0, sizeof(request));
+ memset (&request, 0, sizeof(request));
request.list.dev_num = HCI_MAX_DEV;
- if (ioctl(fd_hci, HCIGETDEVLIST, (void *)&request) < 0)
- {
- fprintf(stderr,
- "ioctl(HCIGETDEVLIST) on interface `%.*s' failed: %s\n",
- IFNAMSIZ,
- dev->iface,
- strerror(errno));
- (void)close(fd_hci);
- return 1;
- }
+ if (ioctl (fd_hci, HCIGETDEVLIST, (void *) &request) < 0)
+ {
+ fprintf (stderr,
+ "ioctl(HCIGETDEVLIST) on interface `%.*s' failed: %s\n",
+ IFNAMSIZ,
+ dev->iface,
+ strerror (errno));
+ (void) close (fd_hci);
+ return 1;
+ }
/* Search for a device with dev->iface name */
for (i = 0; i < request.list.dev_num; i++)
- {
- struct hci_dev_info dev_info;
+ {
+ struct hci_dev_info dev_info;
- memset(&dev_info, 0, sizeof(struct hci_dev_info));
- dev_info.dev_id = request.dev[i].dev_id;
- strncpy(dev_info.name, dev->iface, BLUEZ_DEVNAME_SIZE);
+ memset (&dev_info, 0, sizeof(struct hci_dev_info));
+ dev_info.dev_id = request.dev[i].dev_id;
+ strncpy (dev_info.name, dev->iface, BLUEZ_DEVNAME_SIZE);
- if (ioctl(fd_hci, HCIGETDEVINFO, (void *)&dev_info))
+ if (ioctl (fd_hci, HCIGETDEVINFO, (void *) &dev_info))
+ {
+ fprintf (stderr,
+ "ioctl(HCIGETDEVINFO) on interface `%.*s' failed: %s\n",
+ IFNAMSIZ,
+ dev->iface,
+ strerror (errno));
+ (void) close (fd_hci);
+ return 1;
+ }
+
+ if (strncmp (dev_info.name, dev->iface, BLUEZ_DEVNAME_SIZE) == 0)
+ {
+ dev_id = dev_info.dev_id; // the device was found
+ /**
+ * Copy the MAC address to the device structure
+ */
+ GNUNET_memcpy (&dev->pl_mac, &dev_info.bdaddr, sizeof(bdaddr_t));
+
+ /* Check if the interface is up */
+ if (hci_test_bit (HCI_UP, (void *) &dev_info.flags) == 0)
+ {
+ /* Bring the interface up */
+ if (ioctl (fd_hci, HCIDEVUP, dev_info.dev_id))
{
- fprintf(stderr,
- "ioctl(HCIGETDEVINFO) on interface `%.*s' failed: %s\n",
- IFNAMSIZ,
- dev->iface,
- strerror(errno));
- (void)close(fd_hci);
+ fprintf (stderr,
+ "ioctl(HCIDEVUP) on interface `%.*s' failed: %s\n",
+ IFNAMSIZ,
+ dev->iface,
+ strerror (errno));
+ (void) close (fd_hci);
return 1;
}
+ }
- if (strncmp(dev_info.name, dev->iface, BLUEZ_DEVNAME_SIZE) == 0)
- {
- dev_id = dev_info.dev_id; //the device was found
- /**
- * Copy the MAC address to the device structure
- */
- GNUNET_memcpy(&dev->pl_mac, &dev_info.bdaddr, sizeof(bdaddr_t));
-
- /* Check if the interface is up */
- if (hci_test_bit(HCI_UP, (void *)&dev_info.flags) == 0)
- {
- /* Bring the interface up */
- if (ioctl(fd_hci, HCIDEVUP, dev_info.dev_id))
- {
- fprintf(stderr,
- "ioctl(HCIDEVUP) on interface `%.*s' failed: %s\n",
- IFNAMSIZ,
- dev->iface,
- strerror(errno));
- (void)close(fd_hci);
- return 1;
- }
- }
-
- /* Check if the device is discoverable */
- if (hci_test_bit(HCI_PSCAN, (void *)&dev_info.flags) == 0 ||
- hci_test_bit(HCI_ISCAN, (void *)&dev_info.flags) == 0)
- {
- /* Set interface Page Scan and Inqury Scan ON */
- struct hci_dev_req dev_req;
+ /* Check if the device is discoverable */
+ if ((hci_test_bit (HCI_PSCAN, (void *) &dev_info.flags) == 0) ||
+ (hci_test_bit (HCI_ISCAN, (void *) &dev_info.flags) == 0) )
+ {
+ /* Set interface Page Scan and Inqury Scan ON */
+ struct hci_dev_req dev_req;
- memset(&dev_req, 0, sizeof(dev_req));
- dev_req.dev_id = dev_info.dev_id;
- dev_req.dev_opt = SCAN_PAGE | SCAN_INQUIRY;
+ memset (&dev_req, 0, sizeof(dev_req));
+ dev_req.dev_id = dev_info.dev_id;
+ dev_req.dev_opt = SCAN_PAGE | SCAN_INQUIRY;
- if (ioctl(fd_hci, HCISETSCAN, (unsigned long)&dev_req))
- {
- fprintf(stderr,
- "ioctl(HCISETSCAN) on interface `%.*s' failed: %s\n",
- IFNAMSIZ,
- dev->iface,
- strerror(errno));
- (void)close(fd_hci);
- return 1;
- }
- }
- break;
+ if (ioctl (fd_hci, HCISETSCAN, (unsigned long) &dev_req))
+ {
+ fprintf (stderr,
+ "ioctl(HCISETSCAN) on interface `%.*s' failed: %s\n",
+ IFNAMSIZ,
+ dev->iface,
+ strerror (errno));
+ (void) close (fd_hci);
+ return 1;
}
+ }
+ break;
}
+ }
/* Check if the interface was not found */
if (-1 == dev_id)
- {
- fprintf(stderr,
- "The interface %s was not found\n",
- dev->iface);
- (void)close(fd_hci);
- return 1;
- }
+ {
+ fprintf (stderr,
+ "The interface %s was not found\n",
+ dev->iface);
+ (void) close (fd_hci);
+ return 1;
+ }
/* Close the hci socket */
- (void)close(fd_hci);
+ (void) close (fd_hci);
/* Bind the rfcomm socket to the interface */
- memset(&rc_addr, 0, sizeof(rc_addr));
+ memset (&rc_addr, 0, sizeof(rc_addr));
rc_addr.rc_family = AF_BLUETOOTH;
rc_addr.rc_bdaddr = *BDADDR_ANY;
- if (bind_socket(dev->fd_rfcomm, &rc_addr) != 0)
- {
- fprintf(stderr,
- "Failed to bind interface `%.*s': %s\n",
- IFNAMSIZ,
- dev->iface,
- strerror(errno));
- return 1;
- }
+ if (bind_socket (dev->fd_rfcomm, &rc_addr) != 0)
+ {
+ fprintf (stderr,
+ "Failed to bind interface `%.*s': %s\n",
+ IFNAMSIZ,
+ dev->iface,
+ strerror (errno));
+ return 1;
+ }
/* Register a SDP service */
- if (register_service(dev, rc_addr.rc_channel) != 0)
- {
- fprintf(stderr,
- "Failed to register a service on interface `%.*s': %s\n",
- IFNAMSIZ,
- dev->iface, strerror(errno));
- return 1;
- }
+ if (register_service (dev, rc_addr.rc_channel) != 0)
+ {
+ fprintf (stderr,
+ "Failed to register a service on interface `%.*s': %s\n",
+ IFNAMSIZ,
+ dev->iface, strerror (errno));
+ return 1;
+ }
/* Switch socket in listening mode */
- if (listen(dev->fd_rfcomm, 5) == -1) //FIXME: probably we need a bigger number
- {
- fprintf(stderr, "Failed to listen on socket for interface `%.*s': %s\n", IFNAMSIZ,
- dev->iface, strerror(errno));
- return 1;
- }
+ if (listen (dev->fd_rfcomm, 5) == -1) // FIXME: probably we need a bigger number
+ {
+ fprintf (stderr, "Failed to listen on socket for interface `%.*s': %s\n",
+ IFNAMSIZ,
+ dev->iface, strerror (errno));
+ return 1;
+ }
return 0;
}
@@ -983,10 +1002,10 @@ open_device(struct HardwareInfos *dev)
**** copy from gnunet-helper-transport-wlan.c ****
*/
static void
-mac_set(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
- const struct HardwareInfos *dev)
+mac_set (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
+ const struct HardwareInfos *dev)
{
- taIeeeHeader->frame_control = htons(IEEE80211_FC0_TYPE_DATA);
+ taIeeeHeader->frame_control = htons (IEEE80211_FC0_TYPE_DATA);
taIeeeHeader->addr3 = mac_bssid_gnunet;
taIeeeHeader->addr2 = dev->pl_mac;
}
@@ -1001,22 +1020,22 @@ mac_set(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
**** similar with the one from gnunet-helper-transport-wlan.c ****
*/
static int
-test_bluetooth_interface(const char *iface)
+test_bluetooth_interface (const char *iface)
{
char strbuf[512];
struct stat sbuf;
int ret;
- ret = snprintf(strbuf, sizeof(strbuf),
- "/sys/class/bluetooth/%s/subsystem",
- iface);
- if ((ret < 0) || (ret >= sizeof(strbuf)) || (0 != stat(strbuf, &sbuf)))
- {
- fprintf(stderr,
- "Did not find 802.15.1 interface `%s'. Exiting.\n",
- iface);
- exit(1);
- }
+ ret = snprintf (strbuf, sizeof(strbuf),
+ "/sys/class/bluetooth/%s/subsystem",
+ iface);
+ if ((ret < 0) || (ret >= sizeof(strbuf)) || (0 != stat (strbuf, &sbuf)))
+ {
+ fprintf (stderr,
+ "Did not find 802.15.1 interface `%s'. Exiting.\n",
+ iface);
+ exit (1);
+ }
return 0;
}
#endif
@@ -1031,19 +1050,19 @@ test_bluetooth_interface(const char *iface)
**** same as the one from gnunet-helper-transport-wlan.c ****
*/
static int
-mac_test(const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
- const struct HardwareInfos *dev)
+mac_test (const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
+ const struct HardwareInfos *dev)
{
static struct GNUNET_TRANSPORT_WLAN_MacAddress all_zeros;
- if ((0 == memcmp(&taIeeeHeader->addr3, &all_zeros, MAC_ADDR_SIZE)) ||
- (0 == memcmp(&taIeeeHeader->addr1, &all_zeros, MAC_ADDR_SIZE)))
+ if ((0 == memcmp (&taIeeeHeader->addr3, &all_zeros, MAC_ADDR_SIZE)) ||
+ (0 == memcmp (&taIeeeHeader->addr1, &all_zeros, MAC_ADDR_SIZE)))
return 0; /* some drivers set no Macs, then assume it is all for us! */
- if (0 != memcmp(&taIeeeHeader->addr3, &mac_bssid_gnunet, MAC_ADDR_SIZE))
+ if (0 != memcmp (&taIeeeHeader->addr3, &mac_bssid_gnunet, MAC_ADDR_SIZE))
return 1; /* not a GNUnet ad-hoc package */
- if ((0 == memcmp(&taIeeeHeader->addr1, &dev->pl_mac, MAC_ADDR_SIZE)) ||
- (0 == memcmp(&taIeeeHeader->addr1, &bc_all_mac, MAC_ADDR_SIZE)))
+ if ((0 == memcmp (&taIeeeHeader->addr1, &dev->pl_mac, MAC_ADDR_SIZE)) ||
+ (0 == memcmp (&taIeeeHeader->addr1, &bc_all_mac, MAC_ADDR_SIZE)))
return 0; /* for us, or broadcast */
return 1; /* not for us */
}
@@ -1059,37 +1078,37 @@ mac_test(const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
**** same as the one from gnunet-helper-transport-wlan.c ****
*/
static void
-stdin_send_hw(void *cls, const struct GNUNET_MessageHeader *hdr)
+stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
{
struct HardwareInfos *dev = cls;
const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header;
struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *blueheader;
size_t sendsize;
- sendsize = ntohs(hdr->size);
+ sendsize = ntohs (hdr->size);
if ((sendsize <
sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)) ||
- (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs(hdr->type)))
- {
- fprintf(stderr, "Received malformed message\n");
- exit(1);
- }
- sendsize -= (sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) -
- sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame));
+ (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)))
+ {
+ fprintf (stderr, "Received malformed message\n");
+ exit (1);
+ }
+ sendsize -= (sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)
+ - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame));
if (MAXLINE < sendsize)
- {
- fprintf(stderr, "Packet too big for buffer\n");
- exit(1);
- }
- header = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)hdr;
- GNUNET_memcpy(&write_pout.buf, &header->frame, sendsize);
- blueheader = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *)&write_pout.buf;
+ {
+ fprintf (stderr, "Packet too big for buffer\n");
+ exit (1);
+ }
+ header = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr;
+ GNUNET_memcpy (&write_pout.buf, &header->frame, sendsize);
+ blueheader = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *) &write_pout.buf;
/* payload contains MAC address, but we don't trust it, so we'll
* overwrite it with OUR MAC address to prevent mischief */
- mac_set(blueheader, dev);
- GNUNET_memcpy(&blueheader->addr1, &header->frame.addr1,
- sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress));
+ mac_set (blueheader, dev);
+ GNUNET_memcpy (&blueheader->addr1, &header->frame.addr1,
+ sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress));
write_pout.size = sendsize;
}
@@ -1102,105 +1121,120 @@ stdin_send_hw(void *cls, const struct GNUNET_MessageHeader *hdr)
* @return 0 on success
*/
static int
-send_broadcast(struct HardwareInfos *dev, int *sendsocket)
+send_broadcast (struct HardwareInfos *dev, int *sendsocket)
{
int new_device = 0;
int loops = 0;
search_for_devices:
- if ((neighbours.size == neighbours.pos && new_device == 1) || neighbours.size == 0)
+ if (((neighbours.size == neighbours.pos)&&(new_device == 1)) ||
+ (neighbours.size == 0) )
+ {
+inquiry_devices: // skip the conditions and force a inquiry for new devices
{
-inquiry_devices: //skip the conditions and force a inquiry for new devices
+ /**
+ * It means that I sent HELLO messages to all the devices from the list and I should search
+ * for new ones or that this is the first time when I do a search.
+ */
+ inquiry_info *devices = NULL;
+ int i, responses, max_responses = MAX_PORTS;
+
+ /* sanity checks */
+ if (neighbours.size >= MAX_PORTS)
{
- /**
- * It means that I sent HELLO messages to all the devices from the list and I should search
- * for new ones or that this is the first time when I do a search.
- */
- inquiry_info *devices = NULL;
- int i, responses, max_responses = MAX_PORTS;
-
- /* sanity checks */
- if (neighbours.size >= MAX_PORTS)
- {
- fprintf(stderr, "%.*s reached the top limit for the discovarable devices\n", IFNAMSIZ, dev->iface);
- return 2;
- }
-
- /* Get the device id */
- if (neighbours.dev_id == -1)
- {
- char addr[19] = { 0 }; //the device MAC address
-
- ba2str((bdaddr_t *)&dev->pl_mac, addr);
- neighbours.dev_id = hci_devid(addr);
- if (neighbours.dev_id < 0)
- {
- fprintf(stderr, "Failed to get the device id for interface %.*s : %s\n", IFNAMSIZ,
- dev->iface, strerror(errno));
- return 1;
- }
- }
+ fprintf (stderr,
+ "%.*s reached the top limit for the discovarable devices\n",
+ IFNAMSIZ,
+ dev->iface);
+ return 2;
+ }
- devices = malloc(max_responses * sizeof(inquiry_info));
- if (devices == NULL)
- {
- fprintf(stderr, "Failed to allocate memory for inquiry info list on interface %.*s\n", IFNAMSIZ,
- dev->iface);
- return 1;
- }
+ /* Get the device id */
+ if (neighbours.dev_id == -1)
+ {
+ char addr[19] = { 0 }; // the device MAC address
- responses = hci_inquiry(neighbours.dev_id, 8, max_responses, NULL, &devices, IREQ_CACHE_FLUSH);
- if (responses < 0)
- {
- fprintf(stderr, "Failed to inquiry on interface %.*s\n", IFNAMSIZ, dev->iface);
- return 1;
- }
+ ba2str ((bdaddr_t *) &dev->pl_mac, addr);
+ neighbours.dev_id = hci_devid (addr);
+ if (neighbours.dev_id < 0)
+ {
+ fprintf (stderr,
+ "Failed to get the device id for interface %.*s : %s\n",
+ IFNAMSIZ,
+ dev->iface, strerror (errno));
+ return 1;
+ }
+ }
- fprintf(stderr, "LOG : Found %d devices\n", responses); //FIXME delete it after debugging stage
+ devices = malloc (max_responses * sizeof(inquiry_info));
+ if (devices == NULL)
+ {
+ fprintf (stderr,
+ "Failed to allocate memory for inquiry info list on interface %.*s\n",
+ IFNAMSIZ,
+ dev->iface);
+ return 1;
+ }
- if (responses == 0)
- {
- fprintf(stderr, "LOG : No devices discoverable\n");
- return 1;
- }
+ responses = hci_inquiry (neighbours.dev_id, 8, max_responses, NULL,
+ &devices, IREQ_CACHE_FLUSH);
+ if (responses < 0)
+ {
+ fprintf (stderr, "Failed to inquiry on interface %.*s\n", IFNAMSIZ,
+ dev->iface);
+ return 1;
+ }
- for (i = 0; i < responses; i++)
- {
- int j;
- int found = 0;
+ fprintf (stderr, "LOG : Found %d devices\n", responses); // FIXME delete it after debugging stage
- /* sanity check */
- if (i >= MAX_PORTS)
- {
- fprintf(stderr, "%.*s reached the top limit for the discoverable devices (after inquiry)\n", IFNAMSIZ,
- dev->iface);
- return 2;
- }
+ if (responses == 0)
+ {
+ fprintf (stderr, "LOG : No devices discoverable\n");
+ return 1;
+ }
- /* Search if the address already exists on the list */
- for (j = 0; j < neighbours.size; j++)
- {
- if (memcmp(&(devices + i)->bdaddr, &(neighbours.devices[j]), sizeof(bdaddr_t)) == 0)
- {
- found = 1;
- fprintf(stderr, "LOG : the device already exists on the list\n"); //FIXME debugging message
- break;
- }
- }
+ for (i = 0; i < responses; i++)
+ {
+ int j;
+ int found = 0;
- if (found == 0)
- {
- char addr[19] = { 0 };
+ /* sanity check */
+ if (i >= MAX_PORTS)
+ {
+ fprintf (stderr,
+ "%.*s reached the top limit for the discoverable devices (after inquiry)\n",
+ IFNAMSIZ,
+ dev->iface);
+ return 2;
+ }
- ba2str(&(devices + i)->bdaddr, addr);
- fprintf(stderr, "LOG : %s was added to the list\n", addr); //FIXME debugging message
- GNUNET_memcpy(&(neighbours.devices[neighbours.size++]), &(devices + i)->bdaddr, sizeof(bdaddr_t));
- }
+ /* Search if the address already exists on the list */
+ for (j = 0; j < neighbours.size; j++)
+ {
+ if (memcmp (&(devices + i)->bdaddr, &(neighbours.devices[j]),
+ sizeof(bdaddr_t)) == 0)
+ {
+ found = 1;
+ fprintf (stderr, "LOG : the device already exists on the list\n"); // FIXME debugging message
+ break;
}
+ }
+
+ if (found == 0)
+ {
+ char addr[19] = { 0 };
- free(devices);
+ ba2str (&(devices + i)->bdaddr, addr);
+ fprintf (stderr, "LOG : %s was added to the list\n", addr); // FIXME debugging message
+ GNUNET_memcpy (&(neighbours.devices[neighbours.size++]), &(devices
+ + i)->
+ bdaddr, sizeof(bdaddr_t));
+ }
}
+
+ free (devices);
}
+ }
int connection_successful = 0;
struct sockaddr_rc addr_rc = { 0 };
@@ -1209,115 +1243,120 @@ inquiry_devices: //skip the conditions and force a inquiry for new devices
/* Try to connect to a new device from the list */
while (neighbours.pos < neighbours.size)
+ {
+ /* Check if we are already connected to this device */
+ if (neighbours.fds[neighbours.pos] == -1)
{
- /* Check if we are already connected to this device */
- if (neighbours.fds[neighbours.pos] == -1)
- {
- memset(&addr_rc.rc_bdaddr, 0, sizeof(addr_rc.rc_bdaddr));
- GNUNET_memcpy(&addr_rc.rc_bdaddr, &(neighbours.devices[neighbours.pos]), sizeof(addr_rc.rc_bdaddr));
+ memset (&addr_rc.rc_bdaddr, 0, sizeof(addr_rc.rc_bdaddr));
+ GNUNET_memcpy (&addr_rc.rc_bdaddr, &(neighbours.devices[neighbours.pos]),
+ sizeof(addr_rc.rc_bdaddr));
- addr_rc.rc_channel = get_channel(dev, addr_rc.rc_bdaddr);
+ addr_rc.rc_channel = get_channel (dev, addr_rc.rc_bdaddr);
- *sendsocket = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
- if ((-1 < *sendsocket) &&
- (0 == connect(*sendsocket,
- (struct sockaddr *)&addr_rc,
- sizeof(addr_rc))))
- {
- neighbours.fds[neighbours.pos++] = *sendsocket;
- connection_successful = 1;
- char addr[19] = { 0 };
- ba2str(&(neighbours.devices[neighbours.pos - 1]), addr);
- fprintf(stderr, "LOG : Connected to %s\n", addr);
- break;
- }
- else
- {
- char addr[19] = { 0 };
- errno_copy = errno; //Save a copy for later
+ *sendsocket = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
+ if ((-1 < *sendsocket) &&
+ (0 == connect (*sendsocket,
+ (struct sockaddr *) &addr_rc,
+ sizeof(addr_rc))))
+ {
+ neighbours.fds[neighbours.pos++] = *sendsocket;
+ connection_successful = 1;
+ char addr[19] = { 0 };
+ ba2str (&(neighbours.devices[neighbours.pos - 1]), addr);
+ fprintf (stderr, "LOG : Connected to %s\n", addr);
+ break;
+ }
+ else
+ {
+ char addr[19] = { 0 };
+ errno_copy = errno; // Save a copy for later
- if (-1 != *sendsocket)
- {
- (void)close(*sendsocket);
- *sendsocket = -1;
- }
- ba2str(&(neighbours.devices[neighbours.pos]), addr);
- fprintf(stderr,
- "LOG : Couldn't connect on device %s, error : %s\n",
- addr,
- strerror(errno));
- if (errno != ECONNREFUSED) //FIXME be sure that this works
- {
- fprintf(stderr, "LOG : Removes %d device from the list\n", neighbours.pos);
- /* Remove the device from the list */
- GNUNET_memcpy(&neighbours.devices[neighbours.pos], &neighbours.devices[neighbours.size - 1], sizeof(bdaddr_t));
- memset(&neighbours.devices[neighbours.size - 1], 0, sizeof(bdaddr_t));
- neighbours.fds[neighbours.pos] = neighbours.fds[neighbours.size - 1];
- neighbours.fds[neighbours.size - 1] = -1;
- neighbours.size -= 1;
- }
+ if (-1 != *sendsocket)
+ {
+ (void) close (*sendsocket);
+ *sendsocket = -1;
+ }
+ ba2str (&(neighbours.devices[neighbours.pos]), addr);
+ fprintf (stderr,
+ "LOG : Couldn't connect on device %s, error : %s\n",
+ addr,
+ strerror (errno));
+ if (errno != ECONNREFUSED) // FIXME be sure that this works
+ {
+ fprintf (stderr, "LOG : Removes %d device from the list\n",
+ neighbours.pos);
+ /* Remove the device from the list */
+ GNUNET_memcpy (&neighbours.devices[neighbours.pos],
+ &neighbours.devices[neighbours.size - 1],
+ sizeof(bdaddr_t));
+ memset (&neighbours.devices[neighbours.size - 1], 0,
+ sizeof(bdaddr_t));
+ neighbours.fds[neighbours.pos] = neighbours.fds[neighbours.size - 1];
+ neighbours.fds[neighbours.size - 1] = -1;
+ neighbours.size -= 1;
+ }
- neighbours.pos += 1;
+ neighbours.pos += 1;
- if (neighbours.pos >= neighbours.size)
- neighbours.pos = 0;
+ if (neighbours.pos >= neighbours.size)
+ neighbours.pos = 0;
- loops += 1;
+ loops += 1;
- if (loops == MAX_LOOPS) //don't get stuck trying to connect to one device
- return 1;
- }
- }
- else
- {
- fprintf(stderr, "LOG : Search for a new device\n"); //FIXME debugging message
- neighbours.pos += 1;
- }
+ if (loops == MAX_LOOPS) // don't get stuck trying to connect to one device
+ return 1;
+ }
+ }
+ else
+ {
+ fprintf (stderr, "LOG : Search for a new device\n"); // FIXME debugging message
+ neighbours.pos += 1;
}
+ }
/* Cycle on the list */
if (neighbours.pos == neighbours.size)
- {
- neighbours.pos = 0;
- searching_devices_count += 1;
+ {
+ neighbours.pos = 0;
+ searching_devices_count += 1;
- if (searching_devices_count == MAX_LOOPS)
- {
- fprintf(stderr, "LOG : Force to inquiry for new devices\n");
- searching_devices_count = 0;
- goto inquiry_devices;
- }
+ if (searching_devices_count == MAX_LOOPS)
+ {
+ fprintf (stderr, "LOG : Force to inquiry for new devices\n");
+ searching_devices_count = 0;
+ goto inquiry_devices;
}
+ }
/* If a new device wasn't found, search an old one */
if (connection_successful == 0)
+ {
+ int loop_check = neighbours.pos;
+ while (neighbours.fds[neighbours.pos] == -1)
{
- int loop_check = neighbours.pos;
- while (neighbours.fds[neighbours.pos] == -1)
- {
- if (neighbours.pos == neighbours.size)
- neighbours.pos = 0;
-
- if (neighbours.pos == loop_check)
- {
- if (errno_copy == ECONNREFUSED)
- {
- fprintf(stderr, "LOG : No device found. Go back and search again\n"); //FIXME debugging message
- new_device = 1;
- loops += 1;
- goto search_for_devices;
- }
- else
- {
- return 1; // Skip the broadcast message
- }
- }
+ if (neighbours.pos == neighbours.size)
+ neighbours.pos = 0;
- neighbours.pos += 1;
+ if (neighbours.pos == loop_check)
+ {
+ if (errno_copy == ECONNREFUSED)
+ {
+ fprintf (stderr, "LOG : No device found. Go back and search again\n"); // FIXME debugging message
+ new_device = 1;
+ loops += 1;
+ goto search_for_devices;
}
+ else
+ {
+ return 1; // Skip the broadcast message
+ }
+ }
- *sendsocket = neighbours.fds[neighbours.pos++];
+ neighbours.pos += 1;
}
+ *sendsocket = neighbours.fds[neighbours.pos++];
+ }
+
return 0;
}
#endif
@@ -1334,7 +1373,7 @@ inquiry_devices: //skip the conditions and force a inquiry for new devices
**** similar to gnunet-helper-transport-wlan.c ****
*/
int
-main(int argc, char *argv[])
+main (int argc, char *argv[])
{
#ifdef LINUX
struct HardwareInfos dev;
@@ -1351,83 +1390,85 @@ main(int argc, char *argv[])
/* Assert privs so we can modify the firewall rules! */
{
#ifdef HAVE_SETRESUID
- uid_t uid = getuid();
+ uid_t uid = getuid ();
- if (0 != setresuid(uid, 0, 0))
- {
- fprintf(stderr,
- "Failed to setresuid to root: %s\n",
- strerror(errno));
- return 254;
- }
+ if (0 != setresuid (uid, 0, 0))
+ {
+ fprintf (stderr,
+ "Failed to setresuid to root: %s\n",
+ strerror (errno));
+ return 254;
+ }
#else
- if (0 != seteuid(0))
- {
- fprintf(stderr,
- "Failed to seteuid back to root: %s\n", strerror(errno));
- return 254;
- }
+ if (0 != seteuid (0))
+ {
+ fprintf (stderr,
+ "Failed to seteuid back to root: %s\n", strerror (errno));
+ return 254;
+ }
#endif
}
/* Make use of SGID capabilities on POSIX */
- memset(&dev, 0, sizeof(dev));
- dev.fd_rfcomm = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
+ memset (&dev, 0, sizeof(dev));
+ dev.fd_rfcomm = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
raw_eno = errno; /* remember for later */
/* Now that we've dropped root rights, we can do error checking */
if (2 != argc)
- {
- fprintf(stderr, "You must specify the name of the interface as the first \
+ {
+ fprintf (stderr,
+ "You must specify the name of the interface as the first \
and only argument to this program.\n");
- if (-1 != dev.fd_rfcomm)
- (void)close(dev.fd_rfcomm);
- return 1;
- }
+ if (-1 != dev.fd_rfcomm)
+ (void) close (dev.fd_rfcomm);
+ return 1;
+ }
if (-1 == dev.fd_rfcomm)
- {
- fprintf(stderr, "Failed to create a RFCOMM socket: %s\n", strerror(raw_eno));
- return 1;
- }
+ {
+ fprintf (stderr, "Failed to create a RFCOMM socket: %s\n", strerror (
+ raw_eno));
+ return 1;
+ }
if (dev.fd_rfcomm >= FD_SETSIZE)
+ {
+ fprintf (stderr, "File descriptor too large for select (%d > %d)\n",
+ dev.fd_rfcomm, FD_SETSIZE);
+ (void) close (dev.fd_rfcomm);
+ return 1;
+ }
+ if (0 != test_bluetooth_interface (argv[1]))
+ {
+ (void) close (dev.fd_rfcomm);
+ return 1;
+ }
+ strncpy (dev.iface, argv[1], IFNAMSIZ);
+ if (0 != open_device (&dev))
+ {
+ (void) close (dev.fd_rfcomm);
+ return 1;
+ }
+
+ /* Drop privs */
+ {
+ uid_t uid = getuid ();
+ #ifdef HAVE_SETRESUID
+ if (0 != setresuid (uid, uid, uid))
{
- fprintf(stderr, "File descriptor too large for select (%d > %d)\n",
- dev.fd_rfcomm, FD_SETSIZE);
- (void)close(dev.fd_rfcomm);
- return 1;
- }
- if (0 != test_bluetooth_interface(argv[1]))
- {
- (void)close(dev.fd_rfcomm);
+ fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno));
+ if (-1 != dev.fd_rfcomm)
+ (void) close (dev.fd_rfcomm);
return 1;
}
- strncpy(dev.iface, argv[1], IFNAMSIZ);
- if (0 != open_device(&dev))
+ #else
+ if (0 != (setuid (uid) | seteuid (uid)))
{
- (void)close(dev.fd_rfcomm);
+ fprintf (stderr, "Failed to setuid: %s\n", strerror (errno));
+ if (-1 != dev.fd_rfcomm)
+ (void) close (dev.fd_rfcomm);
return 1;
}
-
- /* Drop privs */
- {
- uid_t uid = getuid();
- #ifdef HAVE_SETRESUID
- if (0 != setresuid(uid, uid, uid))
- {
- fprintf(stderr, "Failed to setresuid: %s\n", strerror(errno));
- if (-1 != dev.fd_rfcomm)
- (void)close(dev.fd_rfcomm);
- return 1;
- }
- #else
- if (0 != (setuid(uid) | seteuid(uid)))
- {
- fprintf(stderr, "Failed to setuid: %s\n", strerror(errno));
- if (-1 != dev.fd_rfcomm)
- (void)close(dev.fd_rfcomm);
- return 1;
- }
#endif
}
@@ -1435,15 +1476,16 @@ main(int argc, char *argv[])
{
struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
- macmsg.hdr.size = htons(sizeof(macmsg));
- macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
- GNUNET_memcpy(&macmsg.mac, &dev.pl_mac, sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress));
- GNUNET_memcpy(write_std.buf, &macmsg, sizeof(macmsg));
+ macmsg.hdr.size = htons (sizeof(macmsg));
+ macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
+ GNUNET_memcpy (&macmsg.mac, &dev.pl_mac, sizeof(struct
+ GNUNET_TRANSPORT_WLAN_MacAddress));
+ GNUNET_memcpy (write_std.buf, &macmsg, sizeof(macmsg));
write_std.size = sizeof(macmsg);
}
- stdin_mst = mst_create(&stdin_send_hw, &dev);
+ stdin_mst = mst_create (&stdin_send_hw, &dev);
stdin_open = 1;
/**
@@ -1451,348 +1493,381 @@ main(int argc, char *argv[])
* from get_wlan_header (plugin_transport_bluetooth.c) is correct.
*/
while (1)
+ {
+ maxfd = -1;
+ broadcast = 0;
+ sendsocket = -1;
+
+ FD_ZERO (&rfds);
+ if ((0 == write_pout.size) && (1 == stdin_open))
+ {
+ FD_SET (STDIN_FILENO, &rfds);
+ maxfd = MAX (maxfd, STDIN_FILENO);
+ }
+ if (0 == write_std.size)
{
- maxfd = -1;
- broadcast = 0;
- sendsocket = -1;
+ FD_SET (dev.fd_rfcomm, &rfds);
+ maxfd = MAX (maxfd, dev.fd_rfcomm);
+ }
- FD_ZERO(&rfds);
- if ((0 == write_pout.size) && (1 == stdin_open))
- {
- FD_SET(STDIN_FILENO, &rfds);
- maxfd = MAX(maxfd, STDIN_FILENO);
- }
- if (0 == write_std.size)
+ for (i = 0; i < crt_rfds; i++) // it can receive messages from multiple devices
+ {
+ FD_SET (rfds_list[i], &rfds);
+ maxfd = MAX (maxfd, rfds_list[i]);
+ }
+ FD_ZERO (&wfds);
+ if (0 < write_std.size)
+ {
+ FD_SET (STDOUT_FILENO, &wfds);
+ maxfd = MAX (maxfd, STDOUT_FILENO);
+ }
+ if (0 < write_pout.size) // it can send messages only to one device per loop
+ {
+ struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *frame;
+ /* Get the destination address */
+ frame = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *) write_pout.buf;
+
+ if (memcmp (&frame->addr1, &dev.pl_mac,
+ sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0)
+ {
+ broadcast = 1;
+ memset (&write_pout, 0, sizeof(write_pout)); // clear the buffer
+ }
+ else if (memcmp (&frame->addr1, &broadcast_address,
+ sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0)
+ {
+ fprintf (stderr, "LOG : %s has a broadcast message (pos %d, size %d)\n",
+ dev.iface, neighbours.pos, neighbours.size); // FIXME: debugging message
+
+ if (send_broadcast (&dev, &sendsocket) != 0) // if the searching wasn't successful don't get stuck on the select stage
{
- FD_SET(dev.fd_rfcomm, &rfds);
- maxfd = MAX(maxfd, dev.fd_rfcomm);
+ broadcast = 1;
+ memset (&write_pout, 0, sizeof(write_pout)); // remove the message
+ fprintf (stderr,
+ "LOG : Skipping the broadcast message (pos %d, size %d)\n",
+ neighbours.pos, neighbours.size);
}
-
- for (i = 0; i < crt_rfds; i++) // it can receive messages from multiple devices
+ else
{
- FD_SET(rfds_list[i], &rfds);
- maxfd = MAX(maxfd, rfds_list[i]);
+ FD_SET (sendsocket, &wfds);
+ maxfd = MAX (maxfd, sendsocket);
}
- FD_ZERO(&wfds);
- if (0 < write_std.size)
+ }
+ else
+ {
+ int found = 0;
+ int pos = 0;
+ /* Search if the address already exists on the list */
+ for (i = 0; i < neighbours.size; i++)
{
- FD_SET(STDOUT_FILENO, &wfds);
- maxfd = MAX(maxfd, STDOUT_FILENO);
+ if (memcmp (&frame->addr1, &(neighbours.devices[i]),
+ sizeof(bdaddr_t)) == 0)
+ {
+ pos = i;
+ if (neighbours.fds[i] != -1)
+ {
+ found = 1; // save the position where it was found
+ FD_SET (neighbours.fds[i], &wfds);
+ maxfd = MAX (maxfd, neighbours.fds[i]);
+ sendsocket = neighbours.fds[i];
+ fprintf (stderr, "LOG: the address was found in the list\n");
+ break;
+ }
+ }
}
- if (0 < write_pout.size) //it can send messages only to one device per loop
+ if (found == 0)
{
- struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *frame;
- /* Get the destination address */
- frame = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *)write_pout.buf;
+ int status;
+ struct sockaddr_rc addr = { 0 };
- if (memcmp(&frame->addr1, &dev.pl_mac,
- sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0)
+ fprintf (stderr,
+ "LOG : %s has a new message for %.2X:%.2X:%.2X:%.2X:%.2X:%.2X which isn't on the broadcast list\n",
+ dev.iface,
+ frame->addr1.mac[5], frame->addr1.mac[4],
+ frame->addr1.mac[3],
+ frame->addr1.mac[2], frame->addr1.mac[1],
+ frame->addr1.mac[0]); // FIXME: debugging message
+
+ sendsocket = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
+
+ if (sendsocket < 0)
+ {
+ fprintf (stderr,
+ "Failed to create a RFCOMM socket (sending stage): %s\n",
+ strerror (errno));
+ return -1;
+ }
+
+ GNUNET_memcpy (&addr.rc_bdaddr, &frame->addr1, sizeof(bdaddr_t));
+ addr.rc_family = AF_BLUETOOTH;
+ addr.rc_channel = get_channel (&dev, addr.rc_bdaddr);
+
+ int tries = 0;
+connect_retry:
+ status = connect (sendsocket, (struct sockaddr *) &addr,
+ sizeof(addr));
+ if ((0 != status) &&(errno != EAGAIN) )
+ {
+ if ((errno == ECONNREFUSED) &&(tries < 2) )
+ {
+ fprintf (stderr, "LOG : %.*s failed to connect. Trying again!\n",
+ IFNAMSIZ, dev.iface);
+ tries++;
+ goto connect_retry;
+ }
+ else if (errno == EBADF)
{
+ fprintf (stderr, "LOG : %s failed to connect : %s. Skip it!\n",
+ dev.iface, strerror (errno));
+ memset (&write_pout, 0, sizeof(write_pout));
broadcast = 1;
- memset(&write_pout, 0, sizeof(write_pout)); //clear the buffer
}
- else if (memcmp(&frame->addr1, &broadcast_address,
- sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0)
+ else
{
- fprintf(stderr, "LOG : %s has a broadcast message (pos %d, size %d)\n", dev.iface, neighbours.pos, neighbours.size); //FIXME: debugging message
-
- if (send_broadcast(&dev, &sendsocket) != 0) //if the searching wasn't successful don't get stuck on the select stage
- {
- broadcast = 1;
- memset(&write_pout, 0, sizeof(write_pout)); //remove the message
- fprintf(stderr, "LOG : Skipping the broadcast message (pos %d, size %d)\n", neighbours.pos, neighbours.size);
- }
- else
- {
- FD_SET(sendsocket, &wfds);
- maxfd = MAX(maxfd, sendsocket);
- }
+ fprintf (stderr,
+ "LOG : %s failed to connect : %s. Try again later!\n",
+ dev.iface,
+ strerror (errno));
+ memset (&write_pout, 0, sizeof(write_pout));
+ broadcast = 1;
}
+ }
else
+ {
+ FD_SET (sendsocket, &wfds);
+ maxfd = MAX (maxfd, sendsocket);
+ fprintf (stderr, "LOG : Connection successful\n");
+ if (pos != 0) // save the socket
{
- int found = 0;
- int pos = 0;
- /* Search if the address already exists on the list */
- for (i = 0; i < neighbours.size; i++)
- {
- if (memcmp(&frame->addr1, &(neighbours.devices[i]), sizeof(bdaddr_t)) == 0)
- {
- pos = i;
- if (neighbours.fds[i] != -1)
- {
- found = 1; //save the position where it was found
- FD_SET(neighbours.fds[i], &wfds);
- maxfd = MAX(maxfd, neighbours.fds[i]);
- sendsocket = neighbours.fds[i];
- fprintf(stderr, "LOG: the address was found in the list\n");
- break;
- }
- }
- }
- if (found == 0)
- {
- int status;
- struct sockaddr_rc addr = { 0 };
-
- fprintf(stderr, "LOG : %s has a new message for %.2X:%.2X:%.2X:%.2X:%.2X:%.2X which isn't on the broadcast list\n", dev.iface,
- frame->addr1.mac[5], frame->addr1.mac[4], frame->addr1.mac[3],
- frame->addr1.mac[2], frame->addr1.mac[1], frame->addr1.mac[0]); //FIXME: debugging message
-
- sendsocket = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
-
- if (sendsocket < 0)
- {
- fprintf(stderr, "Failed to create a RFCOMM socket (sending stage): %s\n",
- strerror(errno));
- return -1;
- }
-
- GNUNET_memcpy(&addr.rc_bdaddr, &frame->addr1, sizeof(bdaddr_t));
- addr.rc_family = AF_BLUETOOTH;
- addr.rc_channel = get_channel(&dev, addr.rc_bdaddr);
-
- int tries = 0;
-connect_retry:
- status = connect(sendsocket, (struct sockaddr *)&addr, sizeof(addr));
- if (0 != status && errno != EAGAIN)
- {
- if (errno == ECONNREFUSED && tries < 2)
- {
- fprintf(stderr, "LOG : %.*s failed to connect. Trying again!\n", IFNAMSIZ, dev.iface);
- tries++;
- goto connect_retry;
- }
- else if (errno == EBADF)
- {
- fprintf(stderr, "LOG : %s failed to connect : %s. Skip it!\n", dev.iface, strerror(errno));
- memset(&write_pout, 0, sizeof(write_pout));
- broadcast = 1;
- }
- else
- {
- fprintf(stderr, "LOG : %s failed to connect : %s. Try again later!\n", dev.iface, strerror(errno));
- memset(&write_pout, 0, sizeof(write_pout));
- broadcast = 1;
- }
- }
- else
- {
- FD_SET(sendsocket, &wfds);
- maxfd = MAX(maxfd, sendsocket);
- fprintf(stderr, "LOG : Connection successful\n");
- if (pos != 0) // save the socket
- {
- neighbours.fds[pos] = sendsocket;
- }
- else
- {
- /* Add the new device to the discovered devices list */
- if (neighbours.size < MAX_PORTS)
- {
- neighbours.fds[neighbours.size] = sendsocket;
- GNUNET_memcpy(&(neighbours.devices[neighbours.size++]), &addr.rc_bdaddr, sizeof(bdaddr_t));
- }
- else
- {
- fprintf(stderr, "The top limit for the discovarable devices' list was reached\n");
- }
- }
- }
- }
+ neighbours.fds[pos] = sendsocket;
}
+ else
+ {
+ /* Add the new device to the discovered devices list */
+ if (neighbours.size < MAX_PORTS)
+ {
+ neighbours.fds[neighbours.size] = sendsocket;
+ GNUNET_memcpy (&(neighbours.devices[neighbours.size++]),
+ &addr.rc_bdaddr, sizeof(bdaddr_t));
+ }
+ else
+ {
+ fprintf (stderr,
+ "The top limit for the discovarable devices' list was reached\n");
+ }
+ }
+ }
}
+ }
+ }
- if (broadcast == 0)
+ if (broadcast == 0)
+ {
+ /* Select a fd which is ready for action :) */
+ {
+ int retval = select (maxfd + 1, &rfds, &wfds, NULL, NULL);
+ if ((-1 == retval) && (EINTR == errno))
+ continue;
+ if ((0 > retval) &&(errno != EBADF) ) // we handle BADF errors later
+ {
+ fprintf (stderr, "select failed: %s\n", strerror (errno));
+ break;
+ }
+ }
+ if (FD_ISSET (STDOUT_FILENO, &wfds))
+ {
+ ssize_t ret =
+ write (STDOUT_FILENO, write_std.buf + write_std.pos,
+ write_std.size - write_std.pos);
+ if (0 > ret)
+ {
+ fprintf (stderr, "Failed to write to STDOUT: %s\n", strerror (errno));
+ break;
+ }
+ write_std.pos += ret;
+ if (write_std.pos == write_std.size)
{
- /* Select a fd which is ready for action :) */
+ write_std.pos = 0;
+ write_std.size = 0;
+ }
+ fprintf (stderr, "LOG : %s sends a message to STDOUT\n", dev.iface); // FIXME: debugging message
+ }
+ if (-1 != sendsocket)
+ {
+ if (FD_ISSET (sendsocket, &wfds))
+ {
+ ssize_t ret = write (sendsocket,
+ write_pout.buf + write_std.pos,
+ write_pout.size - write_pout.pos);
+ if (0 > ret) // FIXME should I first check the error type?
{
- int retval = select(maxfd + 1, &rfds, &wfds, NULL, NULL);
- if ((-1 == retval) && (EINTR == errno))
- continue;
- if (0 > retval && errno != EBADF) // we handle BADF errors later
+ fprintf (stderr,
+ "Failed to write to bluetooth device: %s. Closing the socket!\n",
+ strerror (errno));
+ for (i = 0; i < neighbours.size; i++)
+ {
+ if (neighbours.fds[i] == sendsocket)
{
- fprintf(stderr, "select failed: %s\n", strerror(errno));
+ (void) close (sendsocket);
+ neighbours.fds[i] = -1;
break;
}
+ }
+ /* Remove the message */
+ memset (&write_pout.buf + write_std.pos, 0, (write_pout.size
+ - write_pout.pos));
+ write_pout.pos = 0;
+ write_pout.size = 0;
}
- if (FD_ISSET(STDOUT_FILENO, &wfds))
+ else
+ {
+ write_pout.pos += ret;
+ if ((write_pout.pos != write_pout.size) && (0 != ret))
{
- ssize_t ret =
- write(STDOUT_FILENO, write_std.buf + write_std.pos,
- write_std.size - write_std.pos);
- if (0 > ret)
- {
- fprintf(stderr, "Failed to write to STDOUT: %s\n", strerror(errno));
- break;
- }
- write_std.pos += ret;
- if (write_std.pos == write_std.size)
- {
- write_std.pos = 0;
- write_std.size = 0;
- }
- fprintf(stderr, "LOG : %s sends a message to STDOUT\n", dev.iface); //FIXME: debugging message
+ /* We should not get partial sends with packet-oriented devices... */
+ fprintf (stderr, "Write error, partial send: %u/%u\n",
+ (unsigned int) write_pout.pos,
+ (unsigned int) write_pout.size);
+ break;
}
- if (-1 != sendsocket)
+
+ if (write_pout.pos == write_pout.size)
{
- if (FD_ISSET(sendsocket, &wfds))
- {
- ssize_t ret = write(sendsocket,
- write_pout.buf + write_std.pos,
- write_pout.size - write_pout.pos);
- if (0 > ret) //FIXME should I first check the error type?
- {
- fprintf(stderr, "Failed to write to bluetooth device: %s. Closing the socket!\n",
- strerror(errno));
- for (i = 0; i < neighbours.size; i++)
- {
- if (neighbours.fds[i] == sendsocket)
- {
- (void)close(sendsocket);
- neighbours.fds[i] = -1;
- break;
- }
- }
- /* Remove the message */
- memset(&write_pout.buf + write_std.pos, 0, (write_pout.size - write_pout.pos));
- write_pout.pos = 0;
- write_pout.size = 0;
- }
- else
- {
- write_pout.pos += ret;
- if ((write_pout.pos != write_pout.size) && (0 != ret))
- {
- /* We should not get partial sends with packet-oriented devices... */
- fprintf(stderr, "Write error, partial send: %u/%u\n",
- (unsigned int)write_pout.pos,
- (unsigned int)write_pout.size);
- break;
- }
-
- if (write_pout.pos == write_pout.size)
- {
- write_pout.pos = 0;
- write_pout.size = 0;
- }
- fprintf(stderr, "LOG : %s sends a message to a DEVICE\n", dev.iface); //FIXME: debugging message
- }
- }
+ write_pout.pos = 0;
+ write_pout.size = 0;
+ }
+ fprintf (stderr, "LOG : %s sends a message to a DEVICE\n",
+ dev.iface); // FIXME: debugging message
+ }
+ }
+ }
+ for (i = 0; i <= maxfd; i++)
+ {
+ if (FD_ISSET (i, &rfds))
+ {
+ if (i == STDIN_FILENO)
+ {
+ ssize_t ret =
+ read (i, readbuf, sizeof(readbuf));
+ if (0 > ret)
+ {
+ fprintf (stderr,
+ "Read error from STDIN: %s\n",
+ strerror (errno));
+ break;
}
- for (i = 0; i <= maxfd; i++)
+ if (0 == ret)
{
- if (FD_ISSET(i, &rfds))
- {
- if (i == STDIN_FILENO)
- {
- ssize_t ret =
- read(i, readbuf, sizeof(readbuf));
- if (0 > ret)
- {
- fprintf(stderr,
- "Read error from STDIN: %s\n",
- strerror(errno));
- break;
- }
- if (0 == ret)
- {
- /* stop reading... */
- stdin_open = 0;
- }
- else
- {
- mst_receive(stdin_mst, readbuf, ret);
- fprintf(stderr, "LOG : %s receives a message from STDIN\n", dev.iface); //FIXME: debugging message
- }
- }
- else if (i == dev.fd_rfcomm)
- {
- int readsocket;
- struct sockaddr_rc addr = { 0 };
- unsigned int opt = sizeof(addr);
-
- readsocket = accept(dev.fd_rfcomm, (struct sockaddr *)&addr, &opt);
- fprintf(stderr, "LOG : %s accepts a message\n", dev.iface); //FIXME: debugging message
- if (readsocket == -1)
- {
- fprintf(stderr, "Failed to accept a connection on interface: %.*s\n", IFNAMSIZ,
- strerror(errno));
- break;
- }
- else
- {
- FD_SET(readsocket, &rfds);
- maxfd = MAX(maxfd, readsocket);
-
- if (crt_rfds < MAX_PORTS)
- rfds_list[crt_rfds++] = readsocket;
- else
- {
- fprintf(stderr, "The limit for the read file descriptors list was \
+ /* stop reading... */
+ stdin_open = 0;
+ }
+ else
+ {
+ mst_receive (stdin_mst, readbuf, ret);
+ fprintf (stderr, "LOG : %s receives a message from STDIN\n",
+ dev.iface); // FIXME: debugging message
+ }
+ }
+ else if (i == dev.fd_rfcomm)
+ {
+ int readsocket;
+ struct sockaddr_rc addr = { 0 };
+ unsigned int opt = sizeof(addr);
+
+ readsocket = accept (dev.fd_rfcomm, (struct sockaddr *) &addr,
+ &opt);
+ fprintf (stderr, "LOG : %s accepts a message\n", dev.iface); // FIXME: debugging message
+ if (readsocket == -1)
+ {
+ fprintf (stderr,
+ "Failed to accept a connection on interface: %.*s\n",
+ IFNAMSIZ,
+ strerror (errno));
+ break;
+ }
+ else
+ {
+ FD_SET (readsocket, &rfds);
+ maxfd = MAX (maxfd, readsocket);
+
+ if (crt_rfds < MAX_PORTS)
+ rfds_list[crt_rfds++] = readsocket;
+ else
+ {
+ fprintf (stderr,
+ "The limit for the read file descriptors list was \
reached\n");
- break;
- }
- }
- }
- else
- {
- struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm;
- ssize_t ret;
- fprintf(stderr, "LOG : %s reads something from the socket\n", dev.iface);//FIXME : debugging message
- rrm = (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *)write_std.buf;
- ret =
- read_from_the_socket((void *)&i, (unsigned char *)&rrm->frame,
- sizeof(write_std.buf)
- - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
- + sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
- rrm);
- if (0 >= ret)
- {
- int j;
- FD_CLR(i, &rfds);
- close(i);
- /* Remove the socket from the list */
- for (j = 0; j < crt_rfds; j++)
- {
- if (rfds_list[j] == i)
- {
- rfds_list[j] ^= rfds_list[crt_rfds - 1];
- rfds_list[crt_rfds - 1] ^= rfds_list[j];
- rfds_list[j] ^= rfds_list[crt_rfds - 1];
- crt_rfds -= 1;
- break;
- }
- }
-
- fprintf(stderr, "Read error from raw socket: %s\n", strerror(errno));
- break;
- }
- if ((0 < ret) && (0 == mac_test(&rrm->frame, &dev)))
- {
- write_std.size = ret
- + sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
- - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame);
- rrm->header.size = htons(write_std.size);
- rrm->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
- }
- }
+ break;
+ }
+ }
+ }
+ else
+ {
+ struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm;
+ ssize_t ret;
+ fprintf (stderr, "LOG : %s reads something from the socket\n",
+ dev.iface); // FIXME : debugging message
+ rrm = (struct
+ GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) write_std.buf;
+ ret =
+ read_from_the_socket ((void *) &i, (unsigned char *) &rrm->frame,
+ sizeof(write_std.buf)
+ - sizeof(struct
+ GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
+ + sizeof(struct
+ GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
+ rrm);
+ if (0 >= ret)
+ {
+ int j;
+ FD_CLR (i, &rfds);
+ close (i);
+ /* Remove the socket from the list */
+ for (j = 0; j < crt_rfds; j++)
+ {
+ if (rfds_list[j] == i)
+ {
+ rfds_list[j] ^= rfds_list[crt_rfds - 1];
+ rfds_list[crt_rfds - 1] ^= rfds_list[j];
+ rfds_list[j] ^= rfds_list[crt_rfds - 1];
+ crt_rfds -= 1;
+ break;
}
+ }
+
+ fprintf (stderr, "Read error from raw socket: %s\n", strerror (
+ errno));
+ break;
+ }
+ if ((0 < ret) && (0 == mac_test (&rrm->frame, &dev)))
+ {
+ write_std.size = ret
+ + sizeof(struct
+ GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
+ - sizeof(struct
+ GNUNET_TRANSPORT_WLAN_Ieee80211Frame);
+ rrm->header.size = htons (write_std.size);
+ rrm->header.type = htons (
+ GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
}
+ }
}
+ }
}
+ }
/* Error handling, try to clean up a bit at least */
- mst_destroy(stdin_mst);
+ mst_destroy (stdin_mst);
stdin_mst = NULL;
- sdp_close(dev.session);
- (void)close(dev.fd_rfcomm);
+ sdp_close (dev.session);
+ (void) close (dev.fd_rfcomm);
if (-1 != sendsocket)
- (void)close(sendsocket);
+ (void) close (sendsocket);
for (i = 0; i < crt_rfds; i++)
- (void)close(rfds_list[i]);
+ (void) close (rfds_list[i]);
for (i = 0; i < neighbours.size; i++)
- (void)close(neighbours.fds[i]);
+ (void) close (neighbours.fds[i]);
#else
struct HardwareInfos dev;
struct GNUNET_NETWORK_Handle *sendsocket;
@@ -1803,25 +1878,25 @@ connect_retry:
SOCKADDR_BTH acc_addr = { 0 };
int addr_len = sizeof(SOCKADDR_BTH);
int broadcast, i, stdin_open, crt_rfds = 0;
- HANDLE stdin_handle = GetStdHandle(STD_INPUT_HANDLE);
- HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
+ HANDLE stdin_handle = GetStdHandle (STD_INPUT_HANDLE);
+ HANDLE stdout_handle = GetStdHandle (STD_OUTPUT_HANDLE);
struct MessageStreamTokenizer *stdin_mst;
/* check the handles */
if (stdin_handle == INVALID_HANDLE_VALUE)
- {
- fprintf(stderr, "Failed to get the stdin handle\n");
- ExitProcess(2);
- }
+ {
+ fprintf (stderr, "Failed to get the stdin handle\n");
+ ExitProcess (2);
+ }
if (stdout_handle == INVALID_HANDLE_VALUE)
- {
- fprintf(stderr, "Failed to get the stdout handle\n");
- ExitProcess(2);
- }
+ {
+ fprintf (stderr, "Failed to get the stdout handle\n");
+ ExitProcess (2);
+ }
/* initialize windows sockets */
- initialize_windows_sockets();
+ initialize_windows_sockets ();
// /* test bluetooth socket family support */ --> it return false because the GNUNET_NETWORK_test_pf should also receive the type of socket (BTHPROTO_RFCOMM)
// if (GNUNET_NETWORK_test_pf (AF_BTH) != GNUNET_OK)
@@ -1831,347 +1906,373 @@ connect_retry:
// }
/* create the socket */
- dev.handle = GNUNET_NETWORK_socket_create(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
+ dev.handle = GNUNET_NETWORK_socket_create (AF_BTH, SOCK_STREAM,
+ BTHPROTO_RFCOMM);
if (dev.handle == NULL)
- {
- fprintf(stderr, "Failed to create RFCOMM socket: ");
- print_last_error();
- ExitProcess(2);
- }
+ {
+ fprintf (stderr, "Failed to create RFCOMM socket: ");
+ print_last_error ();
+ ExitProcess (2);
+ }
- if (open_device(&dev) == -1)
+ if (open_device (&dev) == -1)
+ {
+ fprintf (stderr, "Failed to open the device\n");
+ print_last_error ();
+ if (GNUNET_NETWORK_socket_close (dev.handle) != GNUNET_OK)
{
- fprintf(stderr, "Failed to open the device\n");
- print_last_error();
- if (GNUNET_NETWORK_socket_close(dev.handle) != GNUNET_OK)
- {
- fprintf(stderr, "Failed to close the socket!\n");
- print_last_error();
- }
- ExitProcess(2);
+ fprintf (stderr, "Failed to close the socket!\n");
+ print_last_error ();
}
+ ExitProcess (2);
+ }
- if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking(dev.handle, 1))
- {
- fprintf(stderr, "Failed to change the socket mode\n");
- ExitProcess(2);
- }
+ if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking (dev.handle, 1))
+ {
+ fprintf (stderr, "Failed to change the socket mode\n");
+ ExitProcess (2);
+ }
- memset(&write_std, 0, sizeof(write_std));
- memset(&write_pout, 0, sizeof(write_pout));
+ memset (&write_std, 0, sizeof(write_std));
+ memset (&write_pout, 0, sizeof(write_pout));
stdin_open = 1;
- rfds = GNUNET_NETWORK_fdset_create();
- wfds = GNUNET_NETWORK_fdset_create();
+ rfds = GNUNET_NETWORK_fdset_create ();
+ wfds = GNUNET_NETWORK_fdset_create ();
/* Send MAC address of the bluetooth interface to STDOUT first */
{
struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
- macmsg.hdr.size = htons(sizeof(macmsg));
- macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
- GNUNET_memcpy(&macmsg.mac, &dev.pl_mac, sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress_Copy));
- GNUNET_memcpy(write_std.buf, &macmsg, sizeof(macmsg));
+ macmsg.hdr.size = htons (sizeof(macmsg));
+ macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
+ GNUNET_memcpy (&macmsg.mac, &dev.pl_mac, sizeof(struct
+ GNUNET_TRANSPORT_WLAN_MacAddress_Copy));
+ GNUNET_memcpy (write_std.buf, &macmsg, sizeof(macmsg));
write_std.size = sizeof(macmsg);
}
- stdin_mst = mst_create(&stdin_send_hw, &dev);
+ stdin_mst = mst_create (&stdin_send_hw, &dev);
stdin_open = 1;
int pos = 0;
int stdin_pos = -1;
int stdout_pos = -1;
while (1)
+ {
+ broadcast = 0;
+ pos = 0;
+ stdin_pos = -1;
+ stdout_pos = -1;
+ sendsocket = NULL; // FIXME ???memleaks
+
+ GNUNET_NETWORK_fdset_zero (rfds);
+ if ((0 == write_pout.size) && (1 == stdin_open))
{
- broadcast = 0;
- pos = 0;
- stdin_pos = -1;
- stdout_pos = -1;
- sendsocket = NULL; //FIXME ???memleaks
-
- GNUNET_NETWORK_fdset_zero(rfds);
- if ((0 == write_pout.size) && (1 == stdin_open))
+ stdin_pos = pos;
+ pos += 1;
+ GNUNET_NETWORK_fdset_handle_set (rfds, (struct
+ GNUNET_DISK_FileHandle*) &
+ stdin_handle);
+ }
+
+ if (0 == write_std.size)
+ {
+ pos += 1;
+ GNUNET_NETWORK_fdset_set (rfds, dev.handle);
+ }
+
+ for (i = 0; i < crt_rfds; i++)
+ {
+ pos += 1;
+ GNUNET_NETWORK_fdset_set (rfds, rfds_list[i]);
+ }
+
+ GNUNET_NETWORK_fdset_zero (wfds);
+ if (0 < write_std.size)
+ {
+ stdout_pos = pos;
+ GNUNET_NETWORK_fdset_handle_set (wfds, (struct
+ GNUNET_DISK_FileHandle*) &
+ stdout_handle);
+ // printf ("%s\n", write_std.buf);
+ // memset (write_std.buf, 0, write_std.size);
+ // write_std.size = 0;
+ }
+
+ if (0 < write_pout.size)
+ {
+ if (strcmp (argv[1], "ff:ff:ff:ff:ff:ff") == 0)
+ {
+ fprintf (stderr, "LOG: BROADCAST! Skipping the message\n");
+ // skip the message
+ broadcast = 1;
+ memset (write_pout.buf, 0, write_pout.size);
+ write_pout.size = 0;
+ }
+ else
+ {
+ SOCKADDR_BTH addr;
+ fprintf (stderr, "LOG : has a new message for %s\n", argv[1]);
+ sendsocket = GNUNET_NETWORK_socket_create (AF_BTH, SOCK_STREAM,
+ BTHPROTO_RFCOMM);
+
+ if (sendsocket == NULL)
{
- stdin_pos = pos;
- pos += 1;
- GNUNET_NETWORK_fdset_handle_set(rfds, (struct GNUNET_DISK_FileHandle*)&stdin_handle);
+ fprintf (stderr, "Failed to create RFCOMM socket: \n");
+ print_last_error ();
+ ExitProcess (2);
}
- if (0 == write_std.size)
+ memset (&addr, 0, sizeof(addr));
+ // addr.addressFamily = AF_BTH;
+ if (SOCKET_ERROR ==
+ WSAStringToAddress (argv[1], AF_BTH, NULL, (LPSOCKADDR) &addr,
+ &addr_len))
+ {
+ fprintf (stderr, "Failed to translate the address: ");
+ print_last_error ();
+ ExitProcess (2);
+ }
+ addr.port = get_channel (argv[1]);
+ if (addr.port == -1)
+ {
+ fprintf (stderr,
+ "Couldn't find the sdp service for the address: %s\n",
+ argv[1]);
+ memset (write_pout.buf, 0, write_pout.size);
+ write_pout.size = 0;
+ broadcast = 1; // skipping the select part
+ }
+ else
{
- pos += 1;
- GNUNET_NETWORK_fdset_set(rfds, dev.handle);
+ if (GNUNET_OK != GNUNET_NETWORK_socket_connect (sendsocket,
+ (LPSOCKADDR) &addr,
+ addr_len))
+ {
+ fprintf (stderr, "Failed to connect: ");
+ print_last_error ();
+ ExitProcess (2);
+ }
+
+ if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking (sendsocket, 1))
+ {
+ fprintf (stderr, "Failed to change the socket mode\n");
+ ExitProcess (2);
+ }
+
+ GNUNET_NETWORK_fdset_set (wfds, sendsocket);
}
+ }
+ }
- for (i = 0; i < crt_rfds; i++)
+ if (broadcast == 0)
+ {
+ int retval = GNUNET_NETWORK_socket_select (rfds, wfds, NULL,
+ GNUNET_TIME_relative_get_forever_ ());
+ if (retval < 0)
+ {
+ fprintf (stderr, "Select error\n");
+ ExitProcess (2);
+ }
+ // if (GNUNET_NETWORK_fdset_isset (wfds, (struct GNUNET_NETWORK_Handle*)&stdout_handle))
+ if (retval == stdout_pos)
+ {
+ fprintf (stderr, "LOG : sends a message to STDOUT\n"); // FIXME: debugging message
+ // ssize_t ret;
+ // ret = GNUNET_NETWORK_socket_send ((struct GNUNET_NETWORK_Handle *)&stdout_handle, write_std.buf + write_std.pos, write_std.size - write_std.pos);
+ // ret = write (STDOUT_FILENO, write_std.buf + write_std.pos, write_std.size - write_std.pos);
+ DWORD ret;
+ if (FALSE == WriteFile (stdout_handle, write_std.buf + write_std.pos,
+ write_std.size - write_std.pos, &ret, NULL))
{
- pos += 1;
- GNUNET_NETWORK_fdset_set(rfds, rfds_list[i]);
+ fprintf (stderr, "Failed to write to STDOUT: ");
+ print_last_error ();
+ break;
}
- GNUNET_NETWORK_fdset_zero(wfds);
- if (0 < write_std.size)
+ if (ret <= 0)
{
- stdout_pos = pos;
- GNUNET_NETWORK_fdset_handle_set(wfds, (struct GNUNET_DISK_FileHandle*)&stdout_handle);
- // printf ("%s\n", write_std.buf);
- // memset (write_std.buf, 0, write_std.size);
- // write_std.size = 0;
+ fprintf (stderr, "Failed to write to STDOUT\n");
+ ExitProcess (2);
}
- if (0 < write_pout.size)
+ write_std.pos += ret;
+ if (write_std.pos == write_std.size)
+ {
+ write_std.pos = 0;
+ write_std.size = 0;
+ }
+ }
+ if (sendsocket != NULL)
+ {
+ if (GNUNET_NETWORK_fdset_isset (wfds, sendsocket))
{
- if (strcmp(argv[1], "ff:ff:ff:ff:ff:ff") == 0)
+ ssize_t ret;
+ ret = GNUNET_NETWORK_socket_send (sendsocket, write_pout.buf
+ + write_pout.pos,
+ write_pout.size - write_pout.pos);
+
+ if (GNUNET_SYSERR == ret)
+ {
+ fprintf (stderr,
+ "Failed to send to the socket. Closing the socket. Error: \n");
+ print_last_error ();
+ if (GNUNET_NETWORK_socket_close (sendsocket) != GNUNET_OK)
{
- fprintf(stderr, "LOG: BROADCAST! Skipping the message\n");
- // skip the message
- broadcast = 1;
- memset(write_pout.buf, 0, write_pout.size);
- write_pout.size = 0;
+ fprintf (stderr, "Failed to close the sendsocket!\n");
+ print_last_error ();
}
+ ExitProcess (2);
+ }
else
+ {
+ write_pout.pos += ret;
+ if ((write_pout.pos != write_pout.size) && (0 != ret))
{
- SOCKADDR_BTH addr;
- fprintf(stderr, "LOG : has a new message for %s\n", argv[1]);
- sendsocket = GNUNET_NETWORK_socket_create(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
-
- if (sendsocket == NULL)
- {
- fprintf(stderr, "Failed to create RFCOMM socket: \n");
- print_last_error();
- ExitProcess(2);
- }
-
- memset(&addr, 0, sizeof(addr));
- //addr.addressFamily = AF_BTH;
- if (SOCKET_ERROR ==
- WSAStringToAddress(argv[1], AF_BTH, NULL, (LPSOCKADDR)&addr, &addr_len))
- {
- fprintf(stderr, "Failed to translate the address: ");
- print_last_error();
- ExitProcess(2);
- }
- addr.port = get_channel(argv[1]);
- if (addr.port == -1)
- {
- fprintf(stderr, "Couldn't find the sdp service for the address: %s\n", argv[1]);
- memset(write_pout.buf, 0, write_pout.size);
- write_pout.size = 0;
- broadcast = 1; //skipping the select part
- }
- else
- {
- if (GNUNET_OK != GNUNET_NETWORK_socket_connect(sendsocket, (LPSOCKADDR)&addr, addr_len))
- {
- fprintf(stderr, "Failed to connect: ");
- print_last_error();
- ExitProcess(2);
- }
-
- if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking(sendsocket, 1))
- {
- fprintf(stderr, "Failed to change the socket mode\n");
- ExitProcess(2);
- }
-
- GNUNET_NETWORK_fdset_set(wfds, sendsocket);
- }
+ /* we should not get partial sends with packet-oriented devices... */
+ fprintf (stderr, "Write error, partial send: %u/%u\n",
+ (unsigned int) write_pout.pos,
+ (unsigned int) write_pout.size);
+ break;
}
- }
- if (broadcast == 0)
- {
- int retval = GNUNET_NETWORK_socket_select(rfds, wfds, NULL, GNUNET_TIME_relative_get_forever_());
- if (retval < 0)
+ if (write_pout.pos == write_pout.size)
{
- fprintf(stderr, "Select error\n");
- ExitProcess(2);
+ write_pout.pos = 0;
+ write_pout.size = 0;
}
- //if (GNUNET_NETWORK_fdset_isset (wfds, (struct GNUNET_NETWORK_Handle*)&stdout_handle))
- if (retval == stdout_pos)
- {
- fprintf(stderr, "LOG : sends a message to STDOUT\n"); //FIXME: debugging message
- //ssize_t ret;
- //ret = GNUNET_NETWORK_socket_send ((struct GNUNET_NETWORK_Handle *)&stdout_handle, write_std.buf + write_std.pos, write_std.size - write_std.pos);
- //ret = write (STDOUT_FILENO, write_std.buf + write_std.pos, write_std.size - write_std.pos);
- DWORD ret;
- if (FALSE == WriteFile(stdout_handle, write_std.buf + write_std.pos, write_std.size - write_std.pos, &ret, NULL))
- {
- fprintf(stderr, "Failed to write to STDOUT: ");
- print_last_error();
- break;
- }
+ fprintf (stderr, "LOG : sends a message to a DEVICE\n"); // FIXME: debugging message
+ }
+ }
+ }
- if (ret <= 0)
- {
- fprintf(stderr, "Failed to write to STDOUT\n");
- ExitProcess(2);
- }
+ // if (GNUNET_NETWORK_fdset_isset (rfds, (struct GNUNET_NETWORK_Handle*)&stdin_handle))
+ if (retval == stdin_pos)
+ {
+ // ssize_t ret;
+ // ret = GNUNET_NETWORK_socket_recv ((struct GNUNET_NETWORK_Handle *)&stdin_handle, readbuf, sizeof (write_pout.buf));
+ // ret = read (STDIN_FILENO, readbuf, sizeof (readbuf));
+ DWORD ret;
+ if (FALSE == ReadFile (stdin_handle, readbuf, sizeof(readbuf), &ret,
+ NULL)) /* do nothing asynchronous */
+ {
+ fprintf (stderr, "Read error from STDIN: ");
+ print_last_error ();
+ break;
+ }
+ if (0 == ret)
+ {
+ /* stop reading... */
+ stdin_open = 0;
+ }
+ else
+ {
+ mst_receive (stdin_mst, readbuf, ret);
+ fprintf (stderr, "LOG : receives a message from STDIN\n"); // FIXME: debugging message
+ }
+ }
+ else if (GNUNET_NETWORK_fdset_isset (rfds, dev.handle))
+ {
+ fprintf (stderr, "LOG: accepting connection\n");
+ struct GNUNET_NETWORK_Handle *readsocket;
+ readsocket = GNUNET_NETWORK_socket_accept (dev.handle,
+ (LPSOCKADDR) &acc_addr,
+ &addr_len);
+ if (readsocket == NULL)
+ {
+ fprintf (stderr, "Accept error %d: ", GetLastError ());
+ print_last_error ();
+ ExitProcess (2);
+ }
+ else
+ {
+ if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking (readsocket, 1))
+ {
+ fprintf (stderr, "Failed to change the socket mode\n");
+ ExitProcess (2);
+ }
+ GNUNET_NETWORK_fdset_set (rfds, readsocket);
- write_std.pos += ret;
- if (write_std.pos == write_std.size)
- {
- write_std.pos = 0;
- write_std.size = 0;
- }
- }
- if (sendsocket != NULL)
+ if (crt_rfds < MAX_PORTS)
+ rfds_list[crt_rfds++] = readsocket;
+ else
+ {
+ fprintf (stderr,
+ "The limit for the read file descriptors list was reached\n");
+ break;
+ }
+ }
+ }
+ else
+ for (i = 0; i < crt_rfds; i++)
+ {
+ if (GNUNET_NETWORK_fdset_isset (rfds, rfds_list[i]))
+ {
+ struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm;
+ ssize_t ret;
+ fprintf (stderr, "LOG: reading something from the socket\n"); // FIXME : debugging message
+ rrm = (struct
+ GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) write_std.buf;
+ ret = read_from_the_socket (rfds_list[i], (unsigned
+ char *) &rrm->frame,
+ sizeof(write_std.buf)
+ - sizeof(struct
+ GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
+ + sizeof(struct
+ GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
+ rrm);
+ if (0 >= ret)
{
- if (GNUNET_NETWORK_fdset_isset(wfds, sendsocket))
- {
- ssize_t ret;
- ret = GNUNET_NETWORK_socket_send(sendsocket, write_pout.buf + write_pout.pos,
- write_pout.size - write_pout.pos);
-
- if (GNUNET_SYSERR == ret)
- {
- fprintf(stderr, "Failed to send to the socket. Closing the socket. Error: \n");
- print_last_error();
- if (GNUNET_NETWORK_socket_close(sendsocket) != GNUNET_OK)
- {
- fprintf(stderr, "Failed to close the sendsocket!\n");
- print_last_error();
- }
- ExitProcess(2);
- }
- else
- {
- write_pout.pos += ret;
- if ((write_pout.pos != write_pout.size) && (0 != ret))
- {
- /* we should not get partial sends with packet-oriented devices... */
- fprintf(stderr, "Write error, partial send: %u/%u\n",
- (unsigned int)write_pout.pos,
- (unsigned int)write_pout.size);
- break;
- }
-
- if (write_pout.pos == write_pout.size)
- {
- write_pout.pos = 0;
- write_pout.size = 0;
- }
- fprintf(stderr, "LOG : sends a message to a DEVICE\n"); //FIXME: debugging message
- }
- }
- }
+ // TODO remove the socket from the list
+ if (GNUNET_NETWORK_socket_close (rfds_list[i]) != GNUNET_OK)
+ {
+ fprintf (stderr, "Failed to close the sendsocket!\n");
+ print_last_error ();
+ }
- //if (GNUNET_NETWORK_fdset_isset (rfds, (struct GNUNET_NETWORK_Handle*)&stdin_handle))
- if (retval == stdin_pos)
- {
- //ssize_t ret;
- //ret = GNUNET_NETWORK_socket_recv ((struct GNUNET_NETWORK_Handle *)&stdin_handle, readbuf, sizeof (write_pout.buf));
- //ret = read (STDIN_FILENO, readbuf, sizeof (readbuf));
- DWORD ret;
- if (FALSE == ReadFile(stdin_handle, readbuf, sizeof(readbuf), &ret, NULL)) /* do nothing asynchronous */
- {
- fprintf(stderr, "Read error from STDIN: ");
- print_last_error();
- break;
- }
- if (0 == ret)
- {
- /* stop reading... */
- stdin_open = 0;
- }
- else
- {
- mst_receive(stdin_mst, readbuf, ret);
- fprintf(stderr, "LOG : receives a message from STDIN\n"); //FIXME: debugging message
- }
+ fprintf (stderr, "Read error from raw socket: ");
+ print_last_error ();
+ break;
}
- else
- if (GNUNET_NETWORK_fdset_isset(rfds, dev.handle))
+ if ((0 < ret) && (0 == mac_test (&rrm->frame, &dev)))
{
- fprintf(stderr, "LOG: accepting connection\n");
- struct GNUNET_NETWORK_Handle *readsocket;
- readsocket = GNUNET_NETWORK_socket_accept(dev.handle, (LPSOCKADDR)&acc_addr, &addr_len);
- if (readsocket == NULL)
- {
- fprintf(stderr, "Accept error %d: ", GetLastError());
- print_last_error();
- ExitProcess(2);
- }
- else
- {
- if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking(readsocket, 1))
- {
- fprintf(stderr, "Failed to change the socket mode\n");
- ExitProcess(2);
- }
- GNUNET_NETWORK_fdset_set(rfds, readsocket);
-
- if (crt_rfds < MAX_PORTS)
- rfds_list[crt_rfds++] = readsocket;
- else
- {
- fprintf(stderr, "The limit for the read file descriptors list was reached\n");
- break;
- }
- }
+ write_std.size = ret
+ + sizeof(struct
+ GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
+ - sizeof(struct
+ GNUNET_TRANSPORT_WLAN_Ieee80211Frame);
+ rrm->header.size = htons (write_std.size);
+ rrm->header.type = htons (
+ GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
}
- else
- for (i = 0; i < crt_rfds; i++)
- {
- if (GNUNET_NETWORK_fdset_isset(rfds, rfds_list[i]))
- {
- struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm;
- ssize_t ret;
- fprintf(stderr, "LOG: reading something from the socket\n");//FIXME : debugging message
- rrm = (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *)write_std.buf;
- ret = read_from_the_socket(rfds_list[i], (unsigned char *)&rrm->frame,
- sizeof(write_std.buf)
- - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
- + sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
- rrm);
- if (0 >= ret)
- {
- //TODO remove the socket from the list
- if (GNUNET_NETWORK_socket_close(rfds_list[i]) != GNUNET_OK)
- {
- fprintf(stderr, "Failed to close the sendsocket!\n");
- print_last_error();
- }
-
- fprintf(stderr, "Read error from raw socket: ");
- print_last_error();
- break;
- }
- if ((0 < ret) && (0 == mac_test(&rrm->frame, &dev)))
- {
- write_std.size = ret
- + sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
- - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame);
- rrm->header.size = htons(write_std.size);
- rrm->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
- }
- break;
- }
- }
+ break;
+ }
}
}
+ }
- mst_destroy(stdin_mst);
+ mst_destroy (stdin_mst);
stdin_mst = NULL;
- if (GNUNET_NETWORK_socket_close(dev.handle) != GNUNET_OK)
- {
- fprintf(stderr, "Failed to close the socket!\n");
- print_last_error();
- }
+ if (GNUNET_NETWORK_socket_close (dev.handle) != GNUNET_OK)
+ {
+ fprintf (stderr, "Failed to close the socket!\n");
+ print_last_error ();
+ }
for (i = 0; i < crt_rfds; i++)
+ {
+ if (GNUNET_NETWORK_socket_close (rfds_list[i]) != GNUNET_OK)
{
- if (GNUNET_NETWORK_socket_close(rfds_list[i]) != GNUNET_OK)
- {
- fprintf(stderr, "Failed to close the socket!\n");
- print_last_error();
- }
+ fprintf (stderr, "Failed to close the socket!\n");
+ print_last_error ();
}
+ }
- WSACleanup();
+ WSACleanup ();
#endif
return 1; /* we never exit 'normally' */
}
diff --git a/src/transport/gnunet-helper-transport-wlan-dummy.c b/src/transport/gnunet-helper-transport-wlan-dummy.c
index 44a54b7f6..ab77f5c68 100644
--- a/src/transport/gnunet-helper-transport-wlan-dummy.c
+++ b/src/transport/gnunet-helper-transport-wlan-dummy.c
@@ -47,7 +47,8 @@
/**
* IO buffer used for buffering data in transit.
*/
-struct SendBuffer {
+struct SendBuffer
+{
/**
* How many bytes that were stored in 'buf' did we already write to the
* destination? Always smaller than 'size'.
@@ -80,11 +81,11 @@ static int closeprog;
* @param sig killing signal
*/
static void
-sigfunc(int sig)
+sigfunc (int sig)
{
closeprog = 1;
- (void)unlink(FIFO_FILE1);
- (void)unlink(FIFO_FILE2);
+ (void) unlink (FIFO_FILE1);
+ (void) unlink (FIFO_FILE2);
}
@@ -96,19 +97,19 @@ sigfunc(int sig)
* @return number of bytes written
*/
static int
-send_mac_to_plugin(char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac)
+send_mac_to_plugin (char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac)
{
struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
- GNUNET_memcpy(&macmsg.mac,
- (char *)mac,
- sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress));
+ GNUNET_memcpy (&macmsg.mac,
+ (char *) mac,
+ sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress));
macmsg.hdr.size =
- htons(sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
- macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
- GNUNET_memcpy(buffer,
- &macmsg,
- sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
+ htons (sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
+ macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
+ GNUNET_memcpy (buffer,
+ &macmsg,
+ sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
return sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage);
}
@@ -124,7 +125,7 @@ send_mac_to_plugin(char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac)
* #GNUNET_SYSERR to stop further processing with error
*/
static int
-stdin_send(void *cls, const struct GNUNET_MessageHeader *hdr)
+stdin_send (void *cls, const struct GNUNET_MessageHeader *hdr)
{
struct SendBuffer *write_pout = cls;
const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *in;
@@ -132,32 +133,32 @@ stdin_send(void *cls, const struct GNUNET_MessageHeader *hdr)
struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage newheader;
uint16_t sendsize;
- sendsize = ntohs(hdr->size);
- in = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)hdr;
- if ((GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs(hdr->type)) ||
+ sendsize = ntohs (hdr->size);
+ in = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr;
+ if ((GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) ||
(sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize))
- {
- fprintf(stderr, "%s", "Received malformed message\n");
- exit(1);
- }
+ {
+ fprintf (stderr, "%s", "Received malformed message\n");
+ exit (1);
+ }
payload_size =
sendsize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage);
- if ((payload_size +
- sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) +
- write_pout->size) > MAXLINE * 2)
- {
- fprintf(stderr, "%s", "Packet too big for buffer\n");
- exit(1);
- }
- memset(&newheader, 0, sizeof(newheader));
- newheader.header.size = htons(payload_size + sizeof(newheader));
- newheader.header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
+ if ((payload_size
+ + sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
+ + write_pout->size) > MAXLINE * 2)
+ {
+ fprintf (stderr, "%s", "Packet too big for buffer\n");
+ exit (1);
+ }
+ memset (&newheader, 0, sizeof(newheader));
+ newheader.header.size = htons (payload_size + sizeof(newheader));
+ newheader.header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
newheader.frame = in->frame;
- GNUNET_memcpy(write_pout->buf + write_pout->size,
- &newheader,
- sizeof(newheader));
+ GNUNET_memcpy (write_pout->buf + write_pout->size,
+ &newheader,
+ sizeof(newheader));
write_pout->size += sizeof(newheader);
- GNUNET_memcpy(write_pout->buf + write_pout->size, &in[1], payload_size);
+ GNUNET_memcpy (write_pout->buf + write_pout->size, &in[1], payload_size);
write_pout->size += payload_size;
return GNUNET_OK;
}
@@ -173,18 +174,18 @@ stdin_send(void *cls, const struct GNUNET_MessageHeader *hdr)
* #GNUNET_SYSERR to stop further processing with error
*/
static int
-file_in_send(void *cls, const struct GNUNET_MessageHeader *hdr)
+file_in_send (void *cls, const struct GNUNET_MessageHeader *hdr)
{
struct SendBuffer *write_std = cls;
uint16_t sendsize;
- sendsize = ntohs(hdr->size);
+ sendsize = ntohs (hdr->size);
if ((sendsize + write_std->size) > MAXLINE * 2)
- {
- fprintf(stderr, "%s", "Packet too big for buffer\n");
- exit(1);
- }
- GNUNET_memcpy(write_std->buf + write_std->size, hdr, sendsize);
+ {
+ fprintf (stderr, "%s", "Packet too big for buffer\n");
+ exit (1);
+ }
+ GNUNET_memcpy (write_std->buf + write_std->size, hdr, sendsize);
write_std->size += sendsize;
return GNUNET_OK;
}
@@ -198,7 +199,7 @@ file_in_send(void *cls, const struct GNUNET_MessageHeader *hdr)
* @return 1 on error, 0 if terminated normally via signal
*/
int
-main(int argc, char *argv[])
+main (int argc, char *argv[])
{
struct stat st;
int erg;
@@ -222,298 +223,298 @@ main(int argc, char *argv[])
int first;
if ((2 != argc) ||
- ((0 != strcmp(argv[1], "1")) && (0 != strcmp(argv[1], "2"))))
- {
- fprintf(
- stderr,
- "%s",
- "This program must be started with the operating mode (1 or 2) as the only argument.\n");
- return 1;
- }
+ ((0 != strcmp (argv[1], "1")) && (0 != strcmp (argv[1], "2"))))
+ {
+ fprintf (
+ stderr,
+ "%s",
+ "This program must be started with the operating mode (1 or 2) as the only argument.\n");
+ return 1;
+ }
/* make the fifos if needed */
- umask(0);
- if ((GNUNET_OK != GNUNET_DISK_directory_create_for_file(FIFO_FILE1)) ||
- (GNUNET_OK != GNUNET_DISK_directory_create_for_file(FIFO_FILE2)))
+ umask (0);
+ if ((GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE1)) ||
+ (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE2)))
+ {
+ fprintf (stderr, "Failed to create directory for file `%s'\n", FIFO_FILE1);
+ return 1;
+ }
+ if (0 == strcmp (argv[1], "1"))
+ {
+ if (0 != stat (FIFO_FILE1, &st))
{
- fprintf(stderr, "Failed to create directory for file `%s'\n", FIFO_FILE1);
- return 1;
- }
- if (0 == strcmp(argv[1], "1"))
- {
- if (0 != stat(FIFO_FILE1, &st))
- {
- erg = mkfifo(FIFO_FILE1, 0666);
- if ((0 != erg) && (EEXIST != errno))
- fprintf(stderr,
- "Error in mkfifo(%s): %s\n",
- FIFO_FILE1,
- strerror(errno));
- }
+ erg = mkfifo (FIFO_FILE1, 0666);
+ if ((0 != erg) && (EEXIST != errno))
+ fprintf (stderr,
+ "Error in mkfifo(%s): %s\n",
+ FIFO_FILE1,
+ strerror (errno));
}
+ }
else
+ {
+ if (0 != stat (FIFO_FILE2, &st))
{
- if (0 != stat(FIFO_FILE2, &st))
- {
- GNUNET_break(0 == (erg = mkfifo(FIFO_FILE2, 0666)));
- if ((0 != erg) && (EEXIST != errno))
- fprintf(stderr,
- "Error in mkfifo(%s): %s\n",
- FIFO_FILE2,
- strerror(errno));
- }
+ GNUNET_break (0 == (erg = mkfifo (FIFO_FILE2, 0666)));
+ if ((0 != erg) && (EEXIST != errno))
+ fprintf (stderr,
+ "Error in mkfifo(%s): %s\n",
+ FIFO_FILE2,
+ strerror (errno));
}
+ }
- if (0 == strcmp(argv[1], "1"))
+ if (0 == strcmp (argv[1], "1"))
+ {
+ first = 1;
+ fpin = fopen (FIFO_FILE1, "r");
+ if (NULL == fpin)
{
- first = 1;
- fpin = fopen(FIFO_FILE1, "r");
- if (NULL == fpin)
- {
- fprintf(stderr,
- "fopen of read FIFO_FILE1 failed: %s\n",
- strerror(errno));
- goto end;
- }
- if (NULL == (fpout = fopen(FIFO_FILE2, "w")))
- {
- GNUNET_break(0 == mkfifo(FIFO_FILE2, 0666));
- fpout = fopen(FIFO_FILE2, "w");
- }
- if (NULL == fpout)
- {
- fprintf(stderr,
- "fopen of write FIFO_FILE2 failed: %s\n",
- strerror(errno));
- goto end;
- }
+ fprintf (stderr,
+ "fopen of read FIFO_FILE1 failed: %s\n",
+ strerror (errno));
+ goto end;
+ }
+ if (NULL == (fpout = fopen (FIFO_FILE2, "w")))
+ {
+ GNUNET_break (0 == mkfifo (FIFO_FILE2, 0666));
+ fpout = fopen (FIFO_FILE2, "w");
}
+ if (NULL == fpout)
+ {
+ fprintf (stderr,
+ "fopen of write FIFO_FILE2 failed: %s\n",
+ strerror (errno));
+ goto end;
+ }
+ }
else
+ {
+ first = 0;
+ if (NULL == (fpout = fopen (FIFO_FILE1, "w")))
{
- first = 0;
- if (NULL == (fpout = fopen(FIFO_FILE1, "w")))
- {
- GNUNET_break(0 == mkfifo(FIFO_FILE1, 0666));
- fpout = fopen(FIFO_FILE1, "w");
- }
- if (NULL == fpout)
- {
- fprintf(stderr,
- "fopen of write FIFO_FILE1 failed: %s\n",
- strerror(errno));
- goto end;
- }
- fpin = fopen(FIFO_FILE2, "r");
- if (NULL == fpin)
- {
- fprintf(stderr,
- "fopen of read FIFO_FILE2 failed: %s\n",
- strerror(errno));
- goto end;
- }
+ GNUNET_break (0 == mkfifo (FIFO_FILE1, 0666));
+ fpout = fopen (FIFO_FILE1, "w");
}
-
- fdpin = fileno(fpin);
- GNUNET_assert(fpin >= 0);
- if (fdpin >= FD_SETSIZE)
+ if (NULL == fpout)
{
- fprintf(stderr,
- "File fdpin number too large (%d > %u)\n",
- fdpin,
- (unsigned int)FD_SETSIZE);
+ fprintf (stderr,
+ "fopen of write FIFO_FILE1 failed: %s\n",
+ strerror (errno));
goto end;
}
-
- fdpout = fileno(fpout);
- GNUNET_assert(fdpout >= 0);
-
- if (fdpout >= FD_SETSIZE)
+ fpin = fopen (FIFO_FILE2, "r");
+ if (NULL == fpin)
{
- fprintf(stderr,
- "File fdpout number too large (%d > %u)\n",
- fdpout,
- (unsigned int)FD_SETSIZE);
+ fprintf (stderr,
+ "fopen of read FIFO_FILE2 failed: %s\n",
+ strerror (errno));
goto end;
}
+ }
+
+ fdpin = fileno (fpin);
+ GNUNET_assert (fpin >= 0);
+ if (fdpin >= FD_SETSIZE)
+ {
+ fprintf (stderr,
+ "File fdpin number too large (%d > %u)\n",
+ fdpin,
+ (unsigned int) FD_SETSIZE);
+ goto end;
+ }
- signal(SIGINT, &sigfunc);
- signal(SIGTERM, &sigfunc);
- signal(GNUNET_TERM_SIG, &sigfunc);
+ fdpout = fileno (fpout);
+ GNUNET_assert (fdpout >= 0);
+
+ if (fdpout >= FD_SETSIZE)
+ {
+ fprintf (stderr,
+ "File fdpout number too large (%d > %u)\n",
+ fdpout,
+ (unsigned int) FD_SETSIZE);
+ goto end;
+ }
+
+ signal (SIGINT, &sigfunc);
+ signal (SIGTERM, &sigfunc);
+ signal (GNUNET_TERM_SIG, &sigfunc);
write_std.size = 0;
write_std.pos = 0;
write_pout.size = 0;
write_pout.pos = 0;
- stdin_mst = GNUNET_MST_create(&stdin_send, &write_pout);
- file_in_mst = GNUNET_MST_create(&file_in_send, &write_std);
+ stdin_mst = GNUNET_MST_create (&stdin_send, &write_pout);
+ file_in_mst = GNUNET_MST_create (&file_in_send, &write_std);
/* Send 'random' mac address */
macaddr.mac[0] = 0x13;
macaddr.mac[1] = 0x22;
macaddr.mac[2] = 0x33;
macaddr.mac[3] = 0x44;
- macaddr.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 256);
- macaddr.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 256);
- write_std.size = send_mac_to_plugin(write_std.buf, &macaddr);
+ macaddr.mac[4] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 256);
+ macaddr.mac[5] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 256);
+ write_std.size = send_mac_to_plugin (write_std.buf, &macaddr);
while (0 == closeprog)
+ {
+ maxfd = -1;
+ tv.tv_sec = 5;
+ tv.tv_usec = 0;
+
+ FD_ZERO (&rfds);
+ FD_ZERO (&wfds);
+ /* if output queue is empty, read */
+ if (0 == write_pout.size)
{
- maxfd = -1;
- tv.tv_sec = 5;
- tv.tv_usec = 0;
-
- FD_ZERO(&rfds);
- FD_ZERO(&wfds);
- /* if output queue is empty, read */
- if (0 == write_pout.size)
- {
- FD_SET(STDIN_FILENO, &rfds);
- maxfd = MAX(STDIN_FILENO, maxfd);
- }
- if (0 == write_std.size)
- {
- FD_SET(fdpin, &rfds);
- maxfd = MAX(fdpin, maxfd);
- }
+ FD_SET (STDIN_FILENO, &rfds);
+ maxfd = MAX (STDIN_FILENO, maxfd);
+ }
+ if (0 == write_std.size)
+ {
+ FD_SET (fdpin, &rfds);
+ maxfd = MAX (fdpin, maxfd);
+ }
- /* if there is something to write, try to write */
- if (0 < write_std.size)
- {
- FD_SET(STDOUT_FILENO, &wfds);
- maxfd = MAX(maxfd, STDOUT_FILENO);
- }
- if (0 < write_pout.size)
- {
- FD_SET(fdpout, &wfds);
- maxfd = MAX(maxfd, fdpout);
- }
+ /* if there is something to write, try to write */
+ if (0 < write_std.size)
+ {
+ FD_SET (STDOUT_FILENO, &wfds);
+ maxfd = MAX (maxfd, STDOUT_FILENO);
+ }
+ if (0 < write_pout.size)
+ {
+ FD_SET (fdpout, &wfds);
+ maxfd = MAX (maxfd, fdpout);
+ }
- retval = select(maxfd + 1, &rfds, &wfds, NULL, &tv);
- if ((-1 == retval) && (EINTR == errno))
- continue;
- if (0 > retval)
- {
- fprintf(stderr, "select failed: %s\n", strerror(errno));
- closeprog = 1;
- break;
- }
+ retval = select (maxfd + 1, &rfds, &wfds, NULL, &tv);
+ if ((-1 == retval) && (EINTR == errno))
+ continue;
+ if (0 > retval)
+ {
+ fprintf (stderr, "select failed: %s\n", strerror (errno));
+ closeprog = 1;
+ break;
+ }
- if (FD_ISSET(STDOUT_FILENO, &wfds))
+ if (FD_ISSET (STDOUT_FILENO, &wfds))
+ {
+ ret = write (STDOUT_FILENO,
+ write_std.buf + write_std.pos,
+ write_std.size - write_std.pos);
+ if (0 > ret)
+ {
+ closeprog = 1;
+ fprintf (stderr,
+ "Write ERROR to STDOUT_FILENO: %s\n",
+ strerror (errno));
+ break;
+ }
+ else
+ {
+ write_std.pos += ret;
+ /* check if finished writing */
+ if (write_std.pos == write_std.size)
{
- ret = write(STDOUT_FILENO,
- write_std.buf + write_std.pos,
- write_std.size - write_std.pos);
- if (0 > ret)
- {
- closeprog = 1;
- fprintf(stderr,
- "Write ERROR to STDOUT_FILENO: %s\n",
- strerror(errno));
- break;
- }
- else
- {
- write_std.pos += ret;
- /* check if finished writing */
- if (write_std.pos == write_std.size)
- {
- write_std.pos = 0;
- write_std.size = 0;
- }
- }
+ write_std.pos = 0;
+ write_std.size = 0;
}
+ }
+ }
- if (FD_ISSET(fdpout, &wfds))
+ if (FD_ISSET (fdpout, &wfds))
+ {
+ ret = write (fdpout,
+ write_pout.buf + write_pout.pos,
+ write_pout.size - write_pout.pos);
+
+ if (0 > ret)
+ {
+ closeprog = 1;
+ fprintf (stderr,
+ "Write ERROR to fdpout failed: %s\n",
+ strerror (errno));
+ }
+ else
+ {
+ write_pout.pos += ret;
+ /* check if finished writing */
+ if (write_pout.pos == write_pout.size)
{
- ret = write(fdpout,
- write_pout.buf + write_pout.pos,
- write_pout.size - write_pout.pos);
-
- if (0 > ret)
- {
- closeprog = 1;
- fprintf(stderr,
- "Write ERROR to fdpout failed: %s\n",
- strerror(errno));
- }
- else
- {
- write_pout.pos += ret;
- /* check if finished writing */
- if (write_pout.pos == write_pout.size)
- {
- write_pout.pos = 0;
- write_pout.size = 0;
- }
- }
+ write_pout.pos = 0;
+ write_pout.size = 0;
}
+ }
+ }
- if (FD_ISSET(STDIN_FILENO, &rfds))
- {
- readsize = read(STDIN_FILENO, readbuf, sizeof(readbuf));
-
- if (0 > readsize)
- {
- closeprog = 1;
- fprintf(stderr,
- "Error reading from STDIN_FILENO: %s\n",
- strerror(errno));
- }
- else if (0 < readsize)
- {
- GNUNET_MST_from_buffer(stdin_mst,
- readbuf,
- readsize,
- GNUNET_NO,
- GNUNET_NO);
- }
- else
- {
- /* eof */
- closeprog = 1;
- }
- }
+ if (FD_ISSET (STDIN_FILENO, &rfds))
+ {
+ readsize = read (STDIN_FILENO, readbuf, sizeof(readbuf));
+
+ if (0 > readsize)
+ {
+ closeprog = 1;
+ fprintf (stderr,
+ "Error reading from STDIN_FILENO: %s\n",
+ strerror (errno));
+ }
+ else if (0 < readsize)
+ {
+ GNUNET_MST_from_buffer (stdin_mst,
+ readbuf,
+ readsize,
+ GNUNET_NO,
+ GNUNET_NO);
+ }
+ else
+ {
+ /* eof */
+ closeprog = 1;
+ }
+ }
- if (FD_ISSET(fdpin, &rfds))
- {
- readsize = read(fdpin, readbuf, sizeof(readbuf));
- if (0 > readsize)
- {
- closeprog = 1;
- fprintf(stderr, "Error reading from fdpin: %s\n", strerror(errno));
- break;
- }
- else if (0 < readsize)
- {
- GNUNET_MST_from_buffer(file_in_mst,
- readbuf,
- readsize,
- GNUNET_NO,
- GNUNET_NO);
- }
- else
- {
- /* eof */
- closeprog = 1;
- }
- }
+ if (FD_ISSET (fdpin, &rfds))
+ {
+ readsize = read (fdpin, readbuf, sizeof(readbuf));
+ if (0 > readsize)
+ {
+ closeprog = 1;
+ fprintf (stderr, "Error reading from fdpin: %s\n", strerror (errno));
+ break;
+ }
+ else if (0 < readsize)
+ {
+ GNUNET_MST_from_buffer (file_in_mst,
+ readbuf,
+ readsize,
+ GNUNET_NO,
+ GNUNET_NO);
+ }
+ else
+ {
+ /* eof */
+ closeprog = 1;
+ }
}
+ }
end:
/* clean up */
if (NULL != stdin_mst)
- GNUNET_MST_destroy(stdin_mst);
+ GNUNET_MST_destroy (stdin_mst);
if (NULL != file_in_mst)
- GNUNET_MST_destroy(file_in_mst);
+ GNUNET_MST_destroy (file_in_mst);
if (NULL != fpout)
- fclose(fpout);
+ fclose (fpout);
if (NULL != fpin)
- fclose(fpin);
+ fclose (fpin);
if (1 == first)
- {
- (void)unlink(FIFO_FILE1);
- (void)unlink(FIFO_FILE2);
- }
+ {
+ (void) unlink (FIFO_FILE1);
+ (void) unlink (FIFO_FILE2);
+ }
return 0;
}
diff --git a/src/transport/gnunet-helper-transport-wlan.c b/src/transport/gnunet-helper-transport-wlan.c
index 885edb1b0..7ad6c5175 100644
--- a/src/transport/gnunet-helper-transport-wlan.c
+++ b/src/transport/gnunet-helper-transport-wlan.c
@@ -234,7 +234,8 @@
/**
* Values in the 'struct PrismHeader'. All in host byte order (!).
*/
-struct PrismValue {
+struct PrismValue
+{
/**
* This has a different ID for each parameter, see
* PRISM_DID_* constants.
@@ -263,7 +264,8 @@ struct PrismValue {
/**
* Prism header format ('struct p80211msg' in Linux). All in host byte order (!).
*/
-struct PrismHeader {
+struct PrismHeader
+{
/**
* We expect this to be a PRISM_MSGCODE_*.
*/
@@ -301,7 +303,8 @@ struct PrismHeader {
* reliable indicator of alignment requirement. See also
* 'man 9 ieee80211_radiotap'.
*/
-enum RadiotapType {
+enum RadiotapType
+{
/**
* IEEE80211_RADIOTAP_TSFT __le64 microseconds
*
@@ -576,7 +579,8 @@ enum RadiotapType {
* The radio capture header precedes the 802.11 header.
* All data in the header is little endian on all platforms.
*/
-struct Ieee80211RadiotapHeader {
+struct Ieee80211RadiotapHeader
+{
/**
* Version 0. Only increases for drastic changes, introduction of
* compatible new fields does not count.
@@ -607,7 +611,8 @@ struct Ieee80211RadiotapHeader {
* Format of the header we need to prepend to messages to be sent to the
* Kernel.
*/
-struct RadiotapTransmissionHeader {
+struct RadiotapTransmissionHeader
+{
/**
* First we begin with the 'generic' header we also get when receiving
* messages.
@@ -638,7 +643,12 @@ struct RadiotapTransmissionHeader {
* following value for 'header.it_present' based on the presence of
* the 'rate' and 'txflags' in the overall struct.
*/
-#define IEEE80211_RADIOTAP_OUR_TRANSMISSION_HEADER_MASK ((1 << IEEE80211_RADIOTAP_RATE) | (1 << IEEE80211_RADIOTAP_TX_FLAGS))
+#define IEEE80211_RADIOTAP_OUR_TRANSMISSION_HEADER_MASK ((1 \
+ << \
+ IEEE80211_RADIOTAP_RATE) \
+ | (1 \
+ << \
+ IEEE80211_RADIOTAP_TX_FLAGS))
@@ -646,7 +656,8 @@ struct RadiotapTransmissionHeader {
* struct Ieee80211RadiotapHeaderIterator - tracks walk through present radiotap arguments
* in the radiotap header. Used when we parse radiotap packets received from the kernel.
*/
-struct Ieee80211RadiotapHeaderIterator {
+struct Ieee80211RadiotapHeaderIterator
+{
/**
* pointer to the radiotap header we are walking through
*/
@@ -698,7 +709,8 @@ struct Ieee80211RadiotapHeaderIterator {
* struct for storing the information of the hardware. There is only
* one of these.
*/
-struct HardwareInfos {
+struct HardwareInfos
+{
/**
* file descriptor for the raw socket
*/
@@ -725,7 +737,8 @@ struct HardwareInfos {
/**
* IO buffer used for buffering data in transit (to wireless or to stdout).
*/
-struct SendBuffer {
+struct SendBuffer
+{
/**
* How many bytes of data are stored in 'buf' for transmission right now?
* Data always starts at offset 0 and extends to 'size'.
@@ -787,7 +800,8 @@ typedef void (*MessageTokenizerCallback) (void *cls,
/**
* Handle to a message stream tokenizer.
*/
-struct MessageStreamTokenizer {
+struct MessageStreamTokenizer
+{
/**
* Function to call on completed messages.
*/
@@ -828,23 +842,23 @@ struct MessageStreamTokenizer {
* @return handle to tokenizer
*/
static struct MessageStreamTokenizer *
-mst_create(MessageTokenizerCallback cb,
- void *cb_cls)
+mst_create (MessageTokenizerCallback cb,
+ void *cb_cls)
{
struct MessageStreamTokenizer *ret;
- ret = malloc(sizeof(struct MessageStreamTokenizer));
+ ret = malloc (sizeof(struct MessageStreamTokenizer));
if (NULL == ret)
- {
- fprintf(stderr, "Failed to allocate buffer for tokenizer\n");
- exit(1);
- }
- ret->hdr = malloc(MIN_BUFFER_SIZE);
+ {
+ fprintf (stderr, "Failed to allocate buffer for tokenizer\n");
+ exit (1);
+ }
+ ret->hdr = malloc (MIN_BUFFER_SIZE);
if (NULL == ret->hdr)
- {
- fprintf(stderr, "Failed to allocate buffer for alignment\n");
- exit(1);
- }
+ {
+ fprintf (stderr, "Failed to allocate buffer for alignment\n");
+ exit (1);
+ }
ret->curr_buf = MIN_BUFFER_SIZE;
ret->cb = cb;
ret->cb_cls = cb_cls;
@@ -863,8 +877,8 @@ mst_create(MessageTokenizerCallback cb,
* GNUNET_SYSERR if the data stream is corrupt
*/
static int
-mst_receive(struct MessageStreamTokenizer *mst,
- const char *buf, size_t size)
+mst_receive (struct MessageStreamTokenizer *mst,
+ const char *buf, size_t size)
{
const struct GNUNET_MessageHeader *hdr;
size_t delta;
@@ -875,132 +889,132 @@ mst_receive(struct MessageStreamTokenizer *mst,
int ret;
ret = GNUNET_OK;
- ibuf = (char *)mst->hdr;
+ ibuf = (char *) mst->hdr;
while (mst->pos > 0)
- {
+ {
do_align:
- if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) ||
- (0 != (mst->off % ALIGN_FACTOR)))
- {
- /* need to align or need more space */
- mst->pos -= mst->off;
- memmove(ibuf, &ibuf[mst->off], mst->pos);
- mst->off = 0;
- }
- if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
- {
- delta =
- GNUNET_MIN(sizeof(struct GNUNET_MessageHeader) -
- (mst->pos - mst->off), size);
- GNUNET_memcpy(&ibuf[mst->pos], buf, delta);
- mst->pos += delta;
- buf += delta;
- size -= delta;
- }
- if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
- {
- return GNUNET_OK;
- }
- hdr = (const struct GNUNET_MessageHeader *)&ibuf[mst->off];
- want = ntohs(hdr->size);
- if (want < sizeof(struct GNUNET_MessageHeader))
- {
- fprintf(stderr,
- "Received invalid message from stdin\n");
- exit(1);
- }
- if (mst->curr_buf - mst->off < want)
- {
- /* need more space */
- mst->pos -= mst->off;
- memmove(ibuf, &ibuf[mst->off], mst->pos);
- mst->off = 0;
- }
- if (want > mst->curr_buf)
- {
- mst->hdr = realloc(mst->hdr, want);
- if (NULL == mst->hdr)
- {
- fprintf(stderr, "Failed to allocate buffer for alignment\n");
- exit(1);
- }
- ibuf = (char *)mst->hdr;
- mst->curr_buf = want;
- }
- hdr = (const struct GNUNET_MessageHeader *)&ibuf[mst->off];
- if (mst->pos - mst->off < want)
- {
- delta = GNUNET_MIN(want - (mst->pos - mst->off), size);
- GNUNET_memcpy(&ibuf[mst->pos], buf, delta);
- mst->pos += delta;
- buf += delta;
- size -= delta;
- }
- if (mst->pos - mst->off < want)
- {
- return GNUNET_OK;
- }
- mst->cb(mst->cb_cls, hdr);
- mst->off += want;
- if (mst->off == mst->pos)
- {
- /* reset to beginning of buffer, it's free right now! */
- mst->off = 0;
- mst->pos = 0;
- }
+ if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) ||
+ (0 != (mst->off % ALIGN_FACTOR)))
+ {
+ /* need to align or need more space */
+ mst->pos -= mst->off;
+ memmove (ibuf, &ibuf[mst->off], mst->pos);
+ mst->off = 0;
+ }
+ if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
+ {
+ delta =
+ GNUNET_MIN (sizeof(struct GNUNET_MessageHeader)
+ - (mst->pos - mst->off), size);
+ GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
+ mst->pos += delta;
+ buf += delta;
+ size -= delta;
+ }
+ if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
+ {
+ return GNUNET_OK;
+ }
+ hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
+ want = ntohs (hdr->size);
+ if (want < sizeof(struct GNUNET_MessageHeader))
+ {
+ fprintf (stderr,
+ "Received invalid message from stdin\n");
+ exit (1);
+ }
+ if (mst->curr_buf - mst->off < want)
+ {
+ /* need more space */
+ mst->pos -= mst->off;
+ memmove (ibuf, &ibuf[mst->off], mst->pos);
+ mst->off = 0;
+ }
+ if (want > mst->curr_buf)
+ {
+ mst->hdr = realloc (mst->hdr, want);
+ if (NULL == mst->hdr)
+ {
+ fprintf (stderr, "Failed to allocate buffer for alignment\n");
+ exit (1);
+ }
+ ibuf = (char *) mst->hdr;
+ mst->curr_buf = want;
+ }
+ hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
+ if (mst->pos - mst->off < want)
+ {
+ delta = GNUNET_MIN (want - (mst->pos - mst->off), size);
+ GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
+ mst->pos += delta;
+ buf += delta;
+ size -= delta;
+ }
+ if (mst->pos - mst->off < want)
+ {
+ return GNUNET_OK;
}
+ mst->cb (mst->cb_cls, hdr);
+ mst->off += want;
+ if (mst->off == mst->pos)
+ {
+ /* reset to beginning of buffer, it's free right now! */
+ mst->off = 0;
+ mst->pos = 0;
+ }
+ }
while (size > 0)
+ {
+ if (size < sizeof(struct GNUNET_MessageHeader))
+ break;
+ offset = (unsigned long) buf;
+ need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO;
+ if (GNUNET_NO == need_align)
{
- if (size < sizeof(struct GNUNET_MessageHeader))
- break;
- offset = (unsigned long)buf;
- need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO;
- if (GNUNET_NO == need_align)
- {
- /* can try to do zero-copy and process directly from original buffer */
- hdr = (const struct GNUNET_MessageHeader *)buf;
- want = ntohs(hdr->size);
- if (want < sizeof(struct GNUNET_MessageHeader))
- {
- fprintf(stderr,
- "Received invalid message from stdin\n");
- exit(1);
- }
- if (size < want)
- break; /* or not, buffer incomplete, so copy to private buffer... */
- mst->cb(mst->cb_cls, hdr);
- buf += want;
- size -= want;
- }
- else
- {
- /* need to copy to private buffer to align;
- * yes, we go a bit more spagetti than usual here */
- goto do_align;
- }
+ /* can try to do zero-copy and process directly from original buffer */
+ hdr = (const struct GNUNET_MessageHeader *) buf;
+ want = ntohs (hdr->size);
+ if (want < sizeof(struct GNUNET_MessageHeader))
+ {
+ fprintf (stderr,
+ "Received invalid message from stdin\n");
+ exit (1);
+ }
+ if (size < want)
+ break; /* or not, buffer incomplete, so copy to private buffer... */
+ mst->cb (mst->cb_cls, hdr);
+ buf += want;
+ size -= want;
+ }
+ else
+ {
+ /* need to copy to private buffer to align;
+ * yes, we go a bit more spagetti than usual here */
+ goto do_align;
}
+ }
if (size > 0)
+ {
+ if (size + mst->pos > mst->curr_buf)
{
- if (size + mst->pos > mst->curr_buf)
- {
- mst->hdr = realloc(mst->hdr, size + mst->pos);
- if (NULL == mst->hdr)
- {
- fprintf(stderr, "Failed to allocate buffer for alignment\n");
- exit(1);
- }
- ibuf = (char *)mst->hdr;
- mst->curr_buf = size + mst->pos;
- }
- if (mst->pos + size > mst->curr_buf)
- {
- fprintf(stderr,
- "Assertion failed\n");
- exit(1);
- }
- GNUNET_memcpy(&ibuf[mst->pos], buf, size);
- mst->pos += size;
+ mst->hdr = realloc (mst->hdr, size + mst->pos);
+ if (NULL == mst->hdr)
+ {
+ fprintf (stderr, "Failed to allocate buffer for alignment\n");
+ exit (1);
+ }
+ ibuf = (char *) mst->hdr;
+ mst->curr_buf = size + mst->pos;
+ }
+ if (mst->pos + size > mst->curr_buf)
+ {
+ fprintf (stderr,
+ "Assertion failed\n");
+ exit (1);
}
+ GNUNET_memcpy (&ibuf[mst->pos], buf, size);
+ mst->pos += size;
+ }
return ret;
}
@@ -1011,10 +1025,10 @@ do_align:
* @param mst tokenizer to destroy
*/
static void
-mst_destroy(struct MessageStreamTokenizer *mst)
+mst_destroy (struct MessageStreamTokenizer *mst)
{
- free(mst->hdr);
- free(mst);
+ free (mst->hdr);
+ free (mst);
}
/* ***************** end of server_mst.c clone ***************** **/
@@ -1040,9 +1054,11 @@ mst_destroy(struct MessageStreamTokenizer *mst)
* @return 0 on success, -1 on error
*/
static int
-ieee80211_radiotap_iterator_init(struct Ieee80211RadiotapHeaderIterator *iterator,
- const struct Ieee80211RadiotapHeader *radiotap_header,
- size_t max_length)
+ieee80211_radiotap_iterator_init (struct
+ Ieee80211RadiotapHeaderIterator *iterator,
+ const struct
+ Ieee80211RadiotapHeader *radiotap_header,
+ size_t max_length)
{
if ((iterator == NULL) ||
(radiotap_header == NULL))
@@ -1054,36 +1070,39 @@ ieee80211_radiotap_iterator_init(struct Ieee80211RadiotapHeaderIterator *iterato
/* sanity check for allowed length and radiotap length field */
if ((max_length < sizeof(struct Ieee80211RadiotapHeader)) ||
- (max_length < (GNUNET_le16toh(radiotap_header->it_len))))
+ (max_length < (GNUNET_le16toh (radiotap_header->it_len))))
return -1;
- memset(iterator, 0, sizeof(struct Ieee80211RadiotapHeaderIterator));
+ memset (iterator, 0, sizeof(struct Ieee80211RadiotapHeaderIterator));
iterator->rtheader = radiotap_header;
- iterator->max_length = GNUNET_le16toh(radiotap_header->it_len);
- iterator->bitmap_shifter = GNUNET_le32toh(radiotap_header->it_present);
- iterator->arg = ((uint8_t *)radiotap_header) + sizeof(struct Ieee80211RadiotapHeader);
+ iterator->max_length = GNUNET_le16toh (radiotap_header->it_len);
+ iterator->bitmap_shifter = GNUNET_le32toh (radiotap_header->it_present);
+ iterator->arg = ((uint8_t *) radiotap_header) + sizeof(struct
+ Ieee80211RadiotapHeader);
/* find payload start allowing for extended bitmap(s) */
if (0 != (iterator->bitmap_shifter & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK))
+ {
+ while (GNUNET_le32toh (*((uint32_t *) iterator->arg))
+ & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)
{
- while (GNUNET_le32toh(*((uint32_t *)iterator->arg)) & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)
- {
- iterator->arg += sizeof(uint32_t);
- /*
- * check for insanity where the present bitmaps
- * keep claiming to extend up to or even beyond the
- * stated radiotap header length
- */
- if (iterator->arg - ((uint8_t*)iterator->rtheader) > iterator->max_length)
- return -1;
- }
iterator->arg += sizeof(uint32_t);
/*
- * no need to check again for blowing past stated radiotap
- * header length, becuase ieee80211_radiotap_iterator_next
- * checks it before it is dereferenced
+ * check for insanity where the present bitmaps
+ * keep claiming to extend up to or even beyond the
+ * stated radiotap header length
*/
+ if (iterator->arg - ((uint8_t*) iterator->rtheader) >
+ iterator->max_length)
+ return -1;
}
+ iterator->arg += sizeof(uint32_t);
+ /*
+ * no need to check again for blowing past stated radiotap
+ * header length, becuase ieee80211_radiotap_iterator_next
+ * checks it before it is dereferenced
+ */
+ }
/* we are all initialized happily */
return 0;
}
@@ -1102,7 +1121,8 @@ ieee80211_radiotap_iterator_init(struct Ieee80211RadiotapHeaderIterator *iterato
* @return next present arg index on success or -1 if no more or error
*/
static int
-ieee80211_radiotap_iterator_next(struct Ieee80211RadiotapHeaderIterator *iterator)
+ieee80211_radiotap_iterator_next (struct
+ Ieee80211RadiotapHeaderIterator *iterator)
{
/*
* small length lookup table for all radiotap types we heard of
@@ -1149,94 +1169,96 @@ ieee80211_radiotap_iterator_next(struct Ieee80211RadiotapHeaderIterator *iterato
* least skip (by knowing the length)...
*/
while (iterator->arg_index < sizeof(rt_sizes))
+ {
+ int hit = (0 != (iterator->bitmap_shifter & 1));
+
+ if (hit)
{
- int hit = (0 != (iterator->bitmap_shifter & 1));
+ unsigned int wanted_alignment;
+ unsigned int unalignment;
+ /*
+ * arg is present, account for alignment padding
+ * 8-bit args can be at any alignment
+ * 16-bit args must start on 16-bit boundary
+ * 32-bit args must start on 32-bit boundary
+ * 64-bit args must start on 64-bit boundary
+ *
+ * note that total arg size can differ from alignment of
+ * elements inside arg, so we use upper nybble of length table
+ * to base alignment on. First, 'wanted_alignment' is set to be
+ * 1 for 8-bit, 2 for 16-bit, 4 for 32-bit and 8 for 64-bit
+ * arguments. Then, we calculate the 'unalignment' (how many
+ * bytes we are over by taking the difference of 'arg' and the
+ * overall starting point modulo the desired alignment. As
+ * desired alignments are powers of two, we can do modulo with
+ * binary "&" (and also avoid the possibility of a division by
+ * zero if the 'rt_sizes' table contains bogus entries).
+ *
+ * also note: these alignments are relative to the start of the
+ * radiotap header. There is no guarantee that the radiotap
+ * header itself is aligned on any kind of boundary, thus we
+ * need to really look at the delta here.
+ */
+ wanted_alignment = rt_sizes[iterator->arg_index] >> 4;
+ unalignment = (((void *) iterator->arg) - ((void *) iterator->rtheader))
+ & (wanted_alignment - 1);
+ if (0 != unalignment)
+ {
+ /* need padding (by 'wanted_alignment - unalignment') */
+ iterator->arg_index += wanted_alignment - unalignment;
+ }
- if (hit)
- {
- unsigned int wanted_alignment;
- unsigned int unalignment;
- /*
- * arg is present, account for alignment padding
- * 8-bit args can be at any alignment
- * 16-bit args must start on 16-bit boundary
- * 32-bit args must start on 32-bit boundary
- * 64-bit args must start on 64-bit boundary
- *
- * note that total arg size can differ from alignment of
- * elements inside arg, so we use upper nybble of length table
- * to base alignment on. First, 'wanted_alignment' is set to be
- * 1 for 8-bit, 2 for 16-bit, 4 for 32-bit and 8 for 64-bit
- * arguments. Then, we calculate the 'unalignment' (how many
- * bytes we are over by taking the difference of 'arg' and the
- * overall starting point modulo the desired alignment. As
- * desired alignments are powers of two, we can do modulo with
- * binary "&" (and also avoid the possibility of a division by
- * zero if the 'rt_sizes' table contains bogus entries).
- *
- * also note: these alignments are relative to the start of the
- * radiotap header. There is no guarantee that the radiotap
- * header itself is aligned on any kind of boundary, thus we
- * need to really look at the delta here.
- */
- wanted_alignment = rt_sizes[iterator->arg_index] >> 4;
- unalignment = (((void *)iterator->arg) - ((void *)iterator->rtheader)) & (wanted_alignment - 1);
- if (0 != unalignment)
- {
- /* need padding (by 'wanted_alignment - unalignment') */
- iterator->arg_index += wanted_alignment - unalignment;
- }
+ /*
+ * this is what we will return to user, but we need to
+ * move on first so next call has something fresh to test
+ */
+ iterator->this_arg_index = iterator->arg_index;
+ iterator->this_arg = iterator->arg;
- /*
- * this is what we will return to user, but we need to
- * move on first so next call has something fresh to test
- */
- iterator->this_arg_index = iterator->arg_index;
- iterator->this_arg = iterator->arg;
-
- /* internally move on the size of this arg (using lower nybble from
- the table) */
- iterator->arg += rt_sizes[iterator->arg_index] & 0x0f;
-
- /*
- * check for insanity where we are given a bitmap that
- * claims to have more arg content than the length of the
- * radiotap section. We will normally end up equalling this
- * max_length on the last arg, never exceeding it.
- */
- if ((((void *)iterator->arg) - ((void *)iterator->rtheader)) > iterator->max_length)
- return -1;
- }
+ /* internally move on the size of this arg (using lower nybble from
+ the table) */
+ iterator->arg += rt_sizes[iterator->arg_index] & 0x0f;
- /* Now, move on to next bit / next entry */
- iterator->arg_index++;
+ /*
+ * check for insanity where we are given a bitmap that
+ * claims to have more arg content than the length of the
+ * radiotap section. We will normally end up equalling this
+ * max_length on the last arg, never exceeding it.
+ */
+ if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) >
+ iterator->max_length)
+ return -1;
+ }
- if (0 == (iterator->arg_index % 32))
- {
- /* completed current uint32_t bitmap */
- if (0 != (iterator->bitmap_shifter & 1))
- {
- /* bit 31 was set, there is more; move to next uint32_t bitmap */
- iterator->bitmap_shifter = GNUNET_le32toh(*iterator->next_bitmap);
- iterator->next_bitmap++;
- }
- else
- {
- /* no more bitmaps: end (by setting arg_index to high, unsupported value) */
- iterator->arg_index = sizeof(rt_sizes);
- }
- }
- else
- {
- /* just try the next bit (while loop will move on) */
- iterator->bitmap_shifter >>= 1;
- }
+ /* Now, move on to next bit / next entry */
+ iterator->arg_index++;
- /* if we found a valid arg earlier, return it now */
- if (hit)
- return iterator->this_arg_index;
+ if (0 == (iterator->arg_index % 32))
+ {
+ /* completed current uint32_t bitmap */
+ if (0 != (iterator->bitmap_shifter & 1))
+ {
+ /* bit 31 was set, there is more; move to next uint32_t bitmap */
+ iterator->bitmap_shifter = GNUNET_le32toh (*iterator->next_bitmap);
+ iterator->next_bitmap++;
+ }
+ else
+ {
+ /* no more bitmaps: end (by setting arg_index to high, unsupported value) */
+ iterator->arg_index = sizeof(rt_sizes);
+ }
+ }
+ else
+ {
+ /* just try the next bit (while loop will move on) */
+ iterator->bitmap_shifter >>= 1;
}
+ /* if we found a valid arg earlier, return it now */
+ if (hit)
+ return iterator->this_arg_index;
+ }
+
/* we don't know how to handle any more args (or there are no more),
so we're done (this is not an error) */
return -1;
@@ -1251,7 +1273,7 @@ ieee80211_radiotap_iterator_next(struct Ieee80211RadiotapHeaderIterator *iterato
* @return crc sum
*/
static unsigned long
-calc_crc_osdep(const unsigned char *buf, size_t len)
+calc_crc_osdep (const unsigned char *buf, size_t len)
{
static const unsigned long int crc_tbl_osdep[256] = {
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F,
@@ -1337,14 +1359,14 @@ calc_crc_osdep(const unsigned char *buf, size_t len)
* @return 0 on success (checksum matches), 1 on error
*/
static int
-check_crc_buf_osdep(const unsigned char *buf, size_t len)
+check_crc_buf_osdep (const unsigned char *buf, size_t len)
{
unsigned long crc;
- crc = calc_crc_osdep(buf, len);
+ crc = calc_crc_osdep (buf, len);
buf += len;
- if (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] &&
- ((crc >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3])
+ if ((((crc) & 0xFF) == buf[0])&&(((crc >> 8) & 0xFF) == buf[1])&&
+ ( ((crc >> 16) & 0xFF) == buf[2]) &&( ((crc >> 24) & 0xFF) == buf[3]) )
return 0;
return 1;
}
@@ -1362,13 +1384,13 @@ check_crc_buf_osdep(const unsigned char *buf, size_t len)
* @return number of the channel
*/
static int
-get_channel_from_frequency(int32_t frequency)
+get_channel_from_frequency (int32_t frequency)
{
- if (frequency >= 2412 && frequency <= 2472)
+ if ((frequency >= 2412)&&(frequency <= 2472))
return (frequency - 2407) / 5;
if (frequency == 2484)
return 14;
- if (frequency >= 5000 && frequency <= 6100)
+ if ((frequency >= 5000)&&(frequency <= 6100))
return (frequency - 5000) / 5;
return -1;
}
@@ -1381,14 +1403,14 @@ get_channel_from_frequency(int32_t frequency)
* @return channel number, -1 on error
*/
static int
-linux_get_channel(const struct HardwareInfos *dev)
+linux_get_channel (const struct HardwareInfos *dev)
{
struct iwreq wrq;
int32_t frequency;
- memset(&wrq, 0, sizeof(struct iwreq));
- strncpy(wrq.ifr_name, dev->iface, IFNAMSIZ);
- if (0 > ioctl(dev->fd_raw, SIOCGIWFREQ, &wrq))
+ memset (&wrq, 0, sizeof(struct iwreq));
+ strncpy (wrq.ifr_name, dev->iface, IFNAMSIZ);
+ if (0 > ioctl (dev->fd_raw, SIOCGIWFREQ, &wrq))
return -1;
frequency = wrq.u.freq.m; /* 'iw_freq' defines 'm' as '__s32', so we keep it signed */
if (100000000 < frequency)
@@ -1396,7 +1418,7 @@ linux_get_channel(const struct HardwareInfos *dev)
else if (1000000 < frequency)
frequency /= 1000;
if (1000 < frequency)
- return get_channel_from_frequency(frequency);
+ return get_channel_from_frequency (frequency);
return frequency;
}
@@ -1413,9 +1435,9 @@ linux_get_channel(const struct HardwareInfos *dev)
* @return number of bytes written to 'buf'
*/
static ssize_t
-linux_read(struct HardwareInfos *dev,
- unsigned char *buf, size_t buf_size,
- struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri)
+linux_read (struct HardwareInfos *dev,
+ unsigned char *buf, size_t buf_size,
+ struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri)
{
unsigned char tmpbuf[buf_size];
ssize_t caplen;
@@ -1425,207 +1447,210 @@ linux_read(struct HardwareInfos *dev,
int got_channel = 0;
int fcs_removed = 0;
- caplen = read(dev->fd_raw, tmpbuf, buf_size);
+ caplen = read (dev->fd_raw, tmpbuf, buf_size);
if (0 > caplen)
- {
- if (EAGAIN == errno)
- return 0;
- fprintf(stderr, "Failed to read from RAW socket: %s\n", strerror(errno));
- return -1;
- }
+ {
+ if (EAGAIN == errno)
+ return 0;
+ fprintf (stderr, "Failed to read from RAW socket: %s\n", strerror (errno));
+ return -1;
+ }
- memset(ri, 0, sizeof(*ri));
+ memset (ri, 0, sizeof(*ri));
switch (dev->arptype_in)
- {
- case ARPHRD_IEEE80211_PRISM:
+ {
+ case ARPHRD_IEEE80211_PRISM:
{
const struct PrismHeader *ph;
- ph = (const struct PrismHeader*)tmpbuf;
+ ph = (const struct PrismHeader*) tmpbuf;
n = ph->msglen;
if ((n < 8) || (n >= caplen))
return 0; /* invalid format */
if ((PRISM_MSGCODE_MONITOR == ph->msgcode) &&
(n >= sizeof(struct PrismHeader)))
+ {
+ const char *pos;
+ size_t left;
+ struct PrismValue pv;
+
+ left = n - sizeof(struct PrismHeader);
+ pos = (const char *) &ph[1];
+ while (left > sizeof(struct PrismValue))
{
- const char *pos;
- size_t left;
- struct PrismValue pv;
+ left -= sizeof(struct PrismValue);
+ GNUNET_memcpy (&pv, pos, sizeof(struct PrismValue));
+ pos += sizeof(struct PrismValue);
+
+ switch (pv.did)
+ {
+ case PRISM_DID_NOISE:
+ if (PRISM_STATUS_OK == pv.status)
+ {
+ ri->ri_noise = pv.data;
+ /* got_noise = 1; */
+ }
+ break;
+
+ case PRISM_DID_RATE:
+ if (PRISM_STATUS_OK == pv.status)
+ ri->ri_rate = pv.data * 500000;
+ break;
+
+ case PRISM_DID_CHANNEL:
+ if (PRISM_STATUS_OK == pv.status)
+ {
+ ri->ri_channel = pv.data;
+ got_channel = 1;
+ }
+ break;
+
+ case PRISM_DID_MACTIME:
+ if (PRISM_STATUS_OK == pv.status)
+ ri->ri_mactime = pv.data;
+ break;
- left = n - sizeof(struct PrismHeader);
- pos = (const char *)&ph[1];
- while (left > sizeof(struct PrismValue))
+ case PRISM_DID_SIGNAL:
+ if (PRISM_STATUS_OK == pv.status)
{
- left -= sizeof(struct PrismValue);
- GNUNET_memcpy(&pv, pos, sizeof(struct PrismValue));
- pos += sizeof(struct PrismValue);
-
- switch (pv.did)
- {
- case PRISM_DID_NOISE:
- if (PRISM_STATUS_OK == pv.status)
- {
- ri->ri_noise = pv.data;
- /* got_noise = 1; */
- }
- break;
-
- case PRISM_DID_RATE:
- if (PRISM_STATUS_OK == pv.status)
- ri->ri_rate = pv.data * 500000;
- break;
-
- case PRISM_DID_CHANNEL:
- if (PRISM_STATUS_OK == pv.status)
- {
- ri->ri_channel = pv.data;
- got_channel = 1;
- }
- break;
-
- case PRISM_DID_MACTIME:
- if (PRISM_STATUS_OK == pv.status)
- ri->ri_mactime = pv.data;
- break;
-
- case PRISM_DID_SIGNAL:
- if (PRISM_STATUS_OK == pv.status)
- {
- ri->ri_power = pv.data;
- /* got_signal = 1; */
- }
- break;
- }
+ ri->ri_power = pv.data;
+ /* got_signal = 1; */
}
+ break;
+ }
}
+ }
if ((n < 8) || (n >= caplen))
return 0; /* invalid format */
}
break;
- case ARPHRD_IEEE80211_FULL:
+ case ARPHRD_IEEE80211_FULL:
{
struct Ieee80211RadiotapHeaderIterator iterator;
struct Ieee80211RadiotapHeader *rthdr;
- memset(&iterator, 0, sizeof(iterator));
- rthdr = (struct Ieee80211RadiotapHeader *)tmpbuf;
- n = GNUNET_le16toh(rthdr->it_len);
+ memset (&iterator, 0, sizeof(iterator));
+ rthdr = (struct Ieee80211RadiotapHeader *) tmpbuf;
+ n = GNUNET_le16toh (rthdr->it_len);
if ((n < sizeof(struct Ieee80211RadiotapHeader)) || (n >= caplen))
return 0; /* invalid 'it_len' */
- if (0 != ieee80211_radiotap_iterator_init(&iterator, rthdr, caplen))
+ if (0 != ieee80211_radiotap_iterator_init (&iterator, rthdr, caplen))
return 0;
/* go through the radiotap arguments we have been given by the driver */
- while (0 <= ieee80211_radiotap_iterator_next(&iterator))
+ while (0 <= ieee80211_radiotap_iterator_next (&iterator))
+ {
+ switch (iterator.this_arg_index)
{
- switch (iterator.this_arg_index)
- {
- case IEEE80211_RADIOTAP_TSFT:
- ri->ri_mactime = GNUNET_le64toh(*((uint64_t *)iterator.this_arg));
- break;
-
- case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
- if (!got_signal)
- {
- ri->ri_power = *((int8_t*)iterator.this_arg);
- got_signal = 1;
- }
- break;
-
- case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
- if (!got_signal)
- {
- ri->ri_power = *((int8_t*)iterator.this_arg);
- got_signal = 1;
- }
- break;
-
- case IEEE80211_RADIOTAP_DBM_ANTNOISE:
- if (!got_noise)
- {
- ri->ri_noise = *((int8_t*)iterator.this_arg);
- got_noise = 1;
- }
- break;
-
- case IEEE80211_RADIOTAP_DB_ANTNOISE:
- if (!got_noise)
- {
- ri->ri_noise = *((int8_t*)iterator.this_arg);
- got_noise = 1;
- }
- break;
-
- case IEEE80211_RADIOTAP_ANTENNA:
- ri->ri_antenna = *iterator.this_arg;
- break;
-
- case IEEE80211_RADIOTAP_CHANNEL:
- ri->ri_channel = *iterator.this_arg;
- got_channel = 1;
- break;
+ case IEEE80211_RADIOTAP_TSFT:
+ ri->ri_mactime = GNUNET_le64toh (*((uint64_t *) iterator.this_arg));
+ break;
- case IEEE80211_RADIOTAP_RATE:
- ri->ri_rate = (*iterator.this_arg) * 500000;
- break;
+ case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
+ if (! got_signal)
+ {
+ ri->ri_power = *((int8_t*) iterator.this_arg);
+ got_signal = 1;
+ }
+ break;
- case IEEE80211_RADIOTAP_FLAGS:
- {
- uint8_t flags = *iterator.this_arg;
- /* is the CRC visible at the end? if so, remove */
- if (0 != (flags & IEEE80211_RADIOTAP_F_FCS))
- {
- fcs_removed = 1;
- caplen -= sizeof(uint32_t);
- }
- break;
- }
+ case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
+ if (! got_signal)
+ {
+ ri->ri_power = *((int8_t*) iterator.this_arg);
+ got_signal = 1;
+ }
+ break;
+
+ case IEEE80211_RADIOTAP_DBM_ANTNOISE:
+ if (! got_noise)
+ {
+ ri->ri_noise = *((int8_t*) iterator.this_arg);
+ got_noise = 1;
+ }
+ break;
+
+ case IEEE80211_RADIOTAP_DB_ANTNOISE:
+ if (! got_noise)
+ {
+ ri->ri_noise = *((int8_t*) iterator.this_arg);
+ got_noise = 1;
+ }
+ break;
- case IEEE80211_RADIOTAP_RX_FLAGS:
+ case IEEE80211_RADIOTAP_ANTENNA:
+ ri->ri_antenna = *iterator.this_arg;
+ break;
+
+ case IEEE80211_RADIOTAP_CHANNEL:
+ ri->ri_channel = *iterator.this_arg;
+ got_channel = 1;
+ break;
+
+ case IEEE80211_RADIOTAP_RATE:
+ ri->ri_rate = (*iterator.this_arg) * 500000;
+ break;
+
+ case IEEE80211_RADIOTAP_FLAGS:
+ {
+ uint8_t flags = *iterator.this_arg;
+ /* is the CRC visible at the end? if so, remove */
+ if (0 != (flags & IEEE80211_RADIOTAP_F_FCS))
{
- uint16_t flags = ntohs(*((uint16_t *)iterator.this_arg));
- if (0 != (flags & IEEE80211_RADIOTAP_F_RX_BADFCS))
- return 0;
+ fcs_removed = 1;
+ caplen -= sizeof(uint32_t);
}
break;
- } /* end of 'switch' */
- } /* end of the 'while' loop */
+ }
+
+ case IEEE80211_RADIOTAP_RX_FLAGS:
+ {
+ uint16_t flags = ntohs (*((uint16_t *) iterator.this_arg));
+ if (0 != (flags & IEEE80211_RADIOTAP_F_RX_BADFCS))
+ return 0;
+ }
+ break;
+ } /* end of 'switch' */
+ } /* end of the 'while' loop */
}
break;
- case ARPHRD_IEEE80211:
- n = 0; /* no header */
- break;
+ case ARPHRD_IEEE80211:
+ n = 0; /* no header */
+ break;
- case ARPHRD_ETHER:
+ case ARPHRD_ETHER:
{
if (sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) > caplen)
return 0; /* invalid */
- GNUNET_memcpy(&buf[sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)],
- tmpbuf + sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame),
- caplen - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) - 4 /* 4 byte FCS */);
+ GNUNET_memcpy (&buf[sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)],
+ tmpbuf + sizeof(struct
+ GNUNET_TRANSPORT_WLAN_Ieee8023Frame),
+ caplen - sizeof(struct
+ GNUNET_TRANSPORT_WLAN_Ieee8023Frame)
+ - 4 /* 4 byte FCS */);
return caplen - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) - 4;
}
- default:
- errno = ENOTSUP; /* unsupported format */
- return -1;
- }
+ default:
+ errno = ENOTSUP; /* unsupported format */
+ return -1;
+ }
caplen -= n;
- if (!got_channel)
- ri->ri_channel = linux_get_channel(dev);
+ if (! got_channel)
+ ri->ri_channel = linux_get_channel (dev);
/* detect CRC32 at the end, even if the flag wasn't set and remove it */
if ((0 == fcs_removed) &&
- (0 == check_crc_buf_osdep(tmpbuf + n, caplen - sizeof(uint32_t))))
- {
- /* NOTE: this heuristic can of course fail if there happens to
- be a matching checksum at the end. Would be good to have
- some data to see how often this heuristic actually works. */
- caplen -= sizeof(uint32_t);
- }
+ (0 == check_crc_buf_osdep (tmpbuf + n, caplen - sizeof(uint32_t))))
+ {
+ /* NOTE: this heuristic can of course fail if there happens to
+ be a matching checksum at the end. Would be good to have
+ some data to see how often this heuristic actually works. */
+ caplen -= sizeof(uint32_t);
+ }
/* copy payload to target buffer */
- GNUNET_memcpy(buf, tmpbuf + n, caplen);
+ GNUNET_memcpy (buf, tmpbuf + n, caplen);
return caplen;
}
@@ -1642,7 +1667,7 @@ linux_read(struct HardwareInfos *dev,
* @return 0 on success
*/
static int
-open_device_raw(struct HardwareInfos *dev)
+open_device_raw (struct HardwareInfos *dev)
{
struct ifreq ifr;
struct iwreq wrq;
@@ -1650,112 +1675,114 @@ open_device_raw(struct HardwareInfos *dev)
struct sockaddr_ll sll;
/* find the interface index */
- memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, dev->iface, IFNAMSIZ);
- if (-1 == ioctl(dev->fd_raw, SIOCGIFINDEX, &ifr))
- {
- fprintf(stderr, "ioctl(SIOCGIFINDEX) on interface `%.*s' failed: %s\n",
- IFNAMSIZ, dev->iface, strerror(errno));
- return 1;
- }
+ memset (&ifr, 0, sizeof(ifr));
+ strncpy (ifr.ifr_name, dev->iface, IFNAMSIZ);
+ if (-1 == ioctl (dev->fd_raw, SIOCGIFINDEX, &ifr))
+ {
+ fprintf (stderr, "ioctl(SIOCGIFINDEX) on interface `%.*s' failed: %s\n",
+ IFNAMSIZ, dev->iface, strerror (errno));
+ return 1;
+ }
/* lookup the hardware type */
- memset(&sll, 0, sizeof(sll));
+ memset (&sll, 0, sizeof(sll));
sll.sll_family = AF_PACKET;
sll.sll_ifindex = ifr.ifr_ifindex;
- sll.sll_protocol = htons(ETH_P_ALL);
- if (-1 == ioctl(dev->fd_raw, SIOCGIFHWADDR, &ifr))
- {
- fprintf(stderr, "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n",
- IFNAMSIZ, dev->iface, strerror(errno));
- return 1;
- }
+ sll.sll_protocol = htons (ETH_P_ALL);
+ if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr))
+ {
+ fprintf (stderr, "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n",
+ IFNAMSIZ, dev->iface, strerror (errno));
+ return 1;
+ }
if (((ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) &&
(ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) &&
(ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) &&
(ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL)))
- {
- fprintf(stderr, "Error: interface `%.*s' is not using a supported hardware address family (got %d)\n",
- IFNAMSIZ, dev->iface,
- ifr.ifr_hwaddr.sa_family);
- return 1;
- }
+ {
+ fprintf (stderr,
+ "Error: interface `%.*s' is not using a supported hardware address family (got %d)\n",
+ IFNAMSIZ, dev->iface,
+ ifr.ifr_hwaddr.sa_family);
+ return 1;
+ }
/* lookup iw mode */
- memset(&wrq, 0, sizeof(struct iwreq));
- strncpy(wrq.ifr_name, dev->iface, IFNAMSIZ);
- if (-1 == ioctl(dev->fd_raw, SIOCGIWMODE, &wrq))
- {
- /* most probably not supported (ie for rtap ipw interface) *
- * so just assume its correctly set... */
- wrq.u.mode = IW_MODE_MONITOR;
- }
+ memset (&wrq, 0, sizeof(struct iwreq));
+ strncpy (wrq.ifr_name, dev->iface, IFNAMSIZ);
+ if (-1 == ioctl (dev->fd_raw, SIOCGIWMODE, &wrq))
+ {
+ /* most probably not supported (ie for rtap ipw interface) *
+ * so just assume its correctly set... */
+ wrq.u.mode = IW_MODE_MONITOR;
+ }
if ((wrq.u.mode != IW_MODE_MONITOR) &&
(wrq.u.mode != IW_MODE_ADHOC))
- {
- fprintf(stderr, "Error: interface `%.*s' is not in monitor or ad-hoc mode (got %d)\n",
- IFNAMSIZ, dev->iface,
- wrq.u.mode);
- return 1;
- }
+ {
+ fprintf (stderr,
+ "Error: interface `%.*s' is not in monitor or ad-hoc mode (got %d)\n",
+ IFNAMSIZ, dev->iface,
+ wrq.u.mode);
+ return 1;
+ }
/* Is interface st to up, broadcast & running ? */
if ((ifr.ifr_flags | IFF_UP | IFF_BROADCAST | IFF_RUNNING) != ifr.ifr_flags)
- {
- /* Bring interface up */
- ifr.ifr_flags |= IFF_UP | IFF_BROADCAST | IFF_RUNNING;
-
- if (-1 == ioctl(dev->fd_raw, SIOCSIFFLAGS, &ifr))
- {
- fprintf(stderr, "ioctl(SIOCSIFFLAGS) on interface `%.*s' failed: %s\n",
- IFNAMSIZ, dev->iface, strerror(errno));
- return 1;
- }
- }
+ {
+ /* Bring interface up */
+ ifr.ifr_flags |= IFF_UP | IFF_BROADCAST | IFF_RUNNING;
- /* bind the raw socket to the interface */
- if (-1 == bind(dev->fd_raw, (struct sockaddr *)&sll, sizeof(sll)))
+ if (-1 == ioctl (dev->fd_raw, SIOCSIFFLAGS, &ifr))
{
- fprintf(stderr, "Failed to bind interface `%.*s': %s\n", IFNAMSIZ,
- dev->iface, strerror(errno));
+ fprintf (stderr, "ioctl(SIOCSIFFLAGS) on interface `%.*s' failed: %s\n",
+ IFNAMSIZ, dev->iface, strerror (errno));
return 1;
}
+ }
+
+ /* bind the raw socket to the interface */
+ if (-1 == bind (dev->fd_raw, (struct sockaddr *) &sll, sizeof(sll)))
+ {
+ fprintf (stderr, "Failed to bind interface `%.*s': %s\n", IFNAMSIZ,
+ dev->iface, strerror (errno));
+ return 1;
+ }
/* lookup the hardware type */
- if (-1 == ioctl(dev->fd_raw, SIOCGIFHWADDR, &ifr))
- {
- fprintf(stderr, "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n",
- IFNAMSIZ, dev->iface, strerror(errno));
- return 1;
- }
+ if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr))
+ {
+ fprintf (stderr, "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n",
+ IFNAMSIZ, dev->iface, strerror (errno));
+ return 1;
+ }
- GNUNET_memcpy(&dev->pl_mac, ifr.ifr_hwaddr.sa_data, MAC_ADDR_SIZE);
+ GNUNET_memcpy (&dev->pl_mac, ifr.ifr_hwaddr.sa_data, MAC_ADDR_SIZE);
dev->arptype_in = ifr.ifr_hwaddr.sa_family;
if ((ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) &&
(ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) &&
(ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) &&
(ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL))
- {
- fprintf(stderr, "Unsupported hardware link type %d on interface `%.*s'\n",
- ifr.ifr_hwaddr.sa_family, IFNAMSIZ, dev->iface);
- return 1;
- }
+ {
+ fprintf (stderr, "Unsupported hardware link type %d on interface `%.*s'\n",
+ ifr.ifr_hwaddr.sa_family, IFNAMSIZ, dev->iface);
+ return 1;
+ }
/* enable promiscuous mode */
- memset(&mr, 0, sizeof(mr));
+ memset (&mr, 0, sizeof(mr));
mr.mr_ifindex = sll.sll_ifindex;
mr.mr_type = PACKET_MR_PROMISC;
if (0 !=
- setsockopt(dev->fd_raw, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr,
- sizeof(mr)))
- {
- fprintf(stderr,
- "Failed to enable promiscuous mode on interface `%.*s'\n",
- IFNAMSIZ,
- dev->iface);
- return 1;
- }
+ setsockopt (dev->fd_raw, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr,
+ sizeof(mr)))
+ {
+ fprintf (stderr,
+ "Failed to enable promiscuous mode on interface `%.*s'\n",
+ IFNAMSIZ,
+ dev->iface);
+ return 1;
+ }
return 0;
}
@@ -1768,22 +1795,22 @@ open_device_raw(struct HardwareInfos *dev)
* @return 0 on success, 1 on error
*/
static int
-test_wlan_interface(const char *iface)
+test_wlan_interface (const char *iface)
{
char strbuf[512];
struct stat sbuf;
int ret;
- ret = snprintf(strbuf, sizeof(strbuf),
- "/sys/class/net/%s/phy80211/subsystem",
- iface);
- if ((ret < 0) || (ret >= sizeof(strbuf)) || (0 != stat(strbuf, &sbuf)))
- {
- fprintf(stderr,
- "Did not find 802.11 interface `%s'. Exiting.\n",
- iface);
- exit(1);
- }
+ ret = snprintf (strbuf, sizeof(strbuf),
+ "/sys/class/net/%s/phy80211/subsystem",
+ iface);
+ if ((ret < 0) || (ret >= sizeof(strbuf)) || (0 != stat (strbuf, &sbuf)))
+ {
+ fprintf (stderr,
+ "Did not find 802.11 interface `%s'. Exiting.\n",
+ iface);
+ exit (1);
+ }
return 0;
}
@@ -1796,19 +1823,19 @@ test_wlan_interface(const char *iface)
* @return 0 if mac belongs to us, 1 if mac is for another target
*/
static int
-mac_test(const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
- const struct HardwareInfos *dev)
+mac_test (const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
+ const struct HardwareInfos *dev)
{
static struct GNUNET_TRANSPORT_WLAN_MacAddress all_zeros;
- if ((0 == memcmp(&taIeeeHeader->addr3, &all_zeros, MAC_ADDR_SIZE)) ||
- (0 == memcmp(&taIeeeHeader->addr1, &all_zeros, MAC_ADDR_SIZE)))
+ if ((0 == memcmp (&taIeeeHeader->addr3, &all_zeros, MAC_ADDR_SIZE)) ||
+ (0 == memcmp (&taIeeeHeader->addr1, &all_zeros, MAC_ADDR_SIZE)))
return 0; /* some drivers set no Macs, then assume it is all for us! */
- if (0 != memcmp(&taIeeeHeader->addr3, &mac_bssid_gnunet, MAC_ADDR_SIZE))
+ if (0 != memcmp (&taIeeeHeader->addr3, &mac_bssid_gnunet, MAC_ADDR_SIZE))
return 1; /* not a GNUnet ad-hoc package */
- if ((0 == memcmp(&taIeeeHeader->addr1, &dev->pl_mac, MAC_ADDR_SIZE)) ||
- (0 == memcmp(&taIeeeHeader->addr1, &bc_all_mac, MAC_ADDR_SIZE)))
+ if ((0 == memcmp (&taIeeeHeader->addr1, &dev->pl_mac, MAC_ADDR_SIZE)) ||
+ (0 == memcmp (&taIeeeHeader->addr1, &bc_all_mac, MAC_ADDR_SIZE)))
return 0; /* for us, or broadcast */
return 1; /* not for us */
}
@@ -1821,10 +1848,10 @@ mac_test(const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
* @param dev pointer to the Hardware_Infos struct
*/
static void
-mac_set(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
- const struct HardwareInfos *dev)
+mac_set (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
+ const struct HardwareInfos *dev)
{
- taIeeeHeader->frame_control = htons(IEEE80211_FC0_TYPE_DATA);
+ taIeeeHeader->frame_control = htons (IEEE80211_FC0_TYPE_DATA);
taIeeeHeader->addr2 = dev->pl_mac;
taIeeeHeader->addr3 = mac_bssid_gnunet;
}
@@ -1839,7 +1866,7 @@ mac_set(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
* @param hdr pointer to the start of the packet
*/
static void
-stdin_send_hw(void *cls, const struct GNUNET_MessageHeader *hdr)
+stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
{
struct HardwareInfos *dev = cls;
const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header;
@@ -1848,58 +1875,67 @@ stdin_send_hw(void *cls, const struct GNUNET_MessageHeader *hdr)
struct RadiotapTransmissionHeader rtheader;
struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame etheader;
- sendsize = ntohs(hdr->size);
+ sendsize = ntohs (hdr->size);
if ((sendsize <
sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)) ||
- (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs(hdr->type)))
- {
- fprintf(stderr, "Received malformed message\n");
- exit(1);
- }
- sendsize -= (sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame));
+ (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)))
+ {
+ fprintf (stderr, "Received malformed message\n");
+ exit (1);
+ }
+ sendsize -= (sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)
+ - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame));
if (MAXLINE < sendsize)
- {
- fprintf(stderr, "Packet too big for buffer\n");
- exit(1);
- }
- header = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)hdr;
+ {
+ fprintf (stderr, "Packet too big for buffer\n");
+ exit (1);
+ }
+ header = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr;
switch (dev->arptype_in)
- {
- case ARPHRD_IEEE80211_PRISM:
- case ARPHRD_IEEE80211_FULL:
- case ARPHRD_IEEE80211:
- rtheader.header.it_version = 0;
- rtheader.header.it_pad = 0;
- rtheader.header.it_len = GNUNET_htole16(sizeof(rtheader));
- rtheader.header.it_present = GNUNET_htole16(IEEE80211_RADIOTAP_OUR_TRANSMISSION_HEADER_MASK);
- rtheader.rate = header->rate;
- rtheader.pad1 = 0;
- rtheader.txflags = GNUNET_htole16(IEEE80211_RADIOTAP_F_TX_NOACK | IEEE80211_RADIOTAP_F_TX_NOSEQ);
- GNUNET_memcpy(write_pout.buf, &rtheader, sizeof(rtheader));
- GNUNET_memcpy(&write_pout.buf[sizeof(rtheader)], &header->frame, sendsize);
- wlanheader = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *)&write_pout.buf[sizeof(rtheader)];
-
- /* payload contains MAC address, but we don't trust it, so we'll
- * overwrite it with OUR MAC address to prevent mischief */
- mac_set(wlanheader, dev);
- write_pout.size = sendsize + sizeof(rtheader);
- break;
+ {
+ case ARPHRD_IEEE80211_PRISM:
+ case ARPHRD_IEEE80211_FULL:
+ case ARPHRD_IEEE80211:
+ rtheader.header.it_version = 0;
+ rtheader.header.it_pad = 0;
+ rtheader.header.it_len = GNUNET_htole16 (sizeof(rtheader));
+ rtheader.header.it_present = GNUNET_htole16 (
+ IEEE80211_RADIOTAP_OUR_TRANSMISSION_HEADER_MASK);
+ rtheader.rate = header->rate;
+ rtheader.pad1 = 0;
+ rtheader.txflags = GNUNET_htole16 (IEEE80211_RADIOTAP_F_TX_NOACK
+ | IEEE80211_RADIOTAP_F_TX_NOSEQ);
+ GNUNET_memcpy (write_pout.buf, &rtheader, sizeof(rtheader));
+ GNUNET_memcpy (&write_pout.buf[sizeof(rtheader)], &header->frame, sendsize);
+ wlanheader = (struct
+ GNUNET_TRANSPORT_WLAN_Ieee80211Frame *) &write_pout.buf[sizeof(
+ rtheader)
+ ];
+
+ /* payload contains MAC address, but we don't trust it, so we'll
+ * overwrite it with OUR MAC address to prevent mischief */
+ mac_set (wlanheader, dev);
+ write_pout.size = sendsize + sizeof(rtheader);
+ break;
- case ARPHRD_ETHER:
- etheader.dst = header->frame.addr1;
- /* etheader.src = header->frame.addr2; --- untrusted input */
- etheader.src = dev->pl_mac;
- etheader.type = htons(ETH_P_IP);
- GNUNET_memcpy(write_pout.buf, &etheader, sizeof(etheader));
- GNUNET_memcpy(&write_pout.buf[sizeof(etheader)], &header[1], sendsize - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame));
- write_pout.size = sendsize - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame) + sizeof(etheader);
- break;
+ case ARPHRD_ETHER:
+ etheader.dst = header->frame.addr1;
+ /* etheader.src = header->frame.addr2; --- untrusted input */
+ etheader.src = dev->pl_mac;
+ etheader.type = htons (ETH_P_IP);
+ GNUNET_memcpy (write_pout.buf, &etheader, sizeof(etheader));
+ GNUNET_memcpy (&write_pout.buf[sizeof(etheader)], &header[1], sendsize
+ - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame));
+ write_pout.size = sendsize - sizeof(struct
+ GNUNET_TRANSPORT_WLAN_Ieee80211Frame)
+ + sizeof(etheader);
+ break;
- default:
- fprintf(stderr,
- "Unsupported ARPTYPE!\n");
- break;
- }
+ default:
+ fprintf (stderr,
+ "Unsupported ARPTYPE!\n");
+ break;
+ }
}
@@ -1914,7 +1950,7 @@ stdin_send_hw(void *cls, const struct GNUNET_MessageHeader *hdr)
* @return 0 on success (never happens, as we don't return unless aborted), 1 on error
*/
int
-main(int argc, char *argv[])
+main (int argc, char *argv[])
{
struct HardwareInfos dev;
char readbuf[MAXLINE];
@@ -1928,83 +1964,83 @@ main(int argc, char *argv[])
/* assert privs so we can modify the firewall rules! */
{
#ifdef HAVE_SETRESUID
- uid_t uid = getuid();
+ uid_t uid = getuid ();
- if (0 != setresuid(uid, 0, 0))
- {
- fprintf(stderr,
- "Failed to setresuid to root: %s\n",
- strerror(errno));
- return 254;
- }
+ if (0 != setresuid (uid, 0, 0))
+ {
+ fprintf (stderr,
+ "Failed to setresuid to root: %s\n",
+ strerror (errno));
+ return 254;
+ }
#else
- if (0 != seteuid(0))
- {
- fprintf(stderr,
- "Failed to seteuid back to root: %s\n", strerror(errno));
- return 254;
- }
+ if (0 != seteuid (0))
+ {
+ fprintf (stderr,
+ "Failed to seteuid back to root: %s\n", strerror (errno));
+ return 254;
+ }
#endif
}
/* make use of SGID capabilities on POSIX */
- memset(&dev, 0, sizeof(dev));
- dev.fd_raw = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
+ memset (&dev, 0, sizeof(dev));
+ dev.fd_raw = socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL));
raw_eno = errno; /* remember for later */
/* now that we've dropped root rights, we can do error checking */
if (2 != argc)
- {
- fprintf(stderr,
- "You must specify the name of the interface as the first and only argument to this program.\n");
- if (-1 != dev.fd_raw)
- (void)close(dev.fd_raw);
- return 1;
- }
+ {
+ fprintf (stderr,
+ "You must specify the name of the interface as the first and only argument to this program.\n");
+ if (-1 != dev.fd_raw)
+ (void) close (dev.fd_raw);
+ return 1;
+ }
if (-1 == dev.fd_raw)
- {
- fprintf(stderr, "Failed to create raw socket: %s\n", strerror(raw_eno));
- return 1;
- }
+ {
+ fprintf (stderr, "Failed to create raw socket: %s\n", strerror (raw_eno));
+ return 1;
+ }
if (dev.fd_raw >= FD_SETSIZE)
+ {
+ fprintf (stderr, "File descriptor too large for select (%d > %d)\n",
+ dev.fd_raw, FD_SETSIZE);
+ (void) close (dev.fd_raw);
+ return 1;
+ }
+ if (0 != test_wlan_interface (argv[1]))
+ {
+ (void) close (dev.fd_raw);
+ return 1;
+ }
+ strncpy (dev.iface, argv[1], IFNAMSIZ);
+ if (0 != open_device_raw (&dev))
+ {
+ (void) close (dev.fd_raw);
+ return 1;
+ }
+
+ /* drop privs */
+ {
+ uid_t uid = getuid ();
+#ifdef HAVE_SETRESUID
+ if (0 != setresuid (uid, uid, uid))
{
- fprintf(stderr, "File descriptor too large for select (%d > %d)\n",
- dev.fd_raw, FD_SETSIZE);
- (void)close(dev.fd_raw);
- return 1;
- }
- if (0 != test_wlan_interface(argv[1]))
- {
- (void)close(dev.fd_raw);
+ fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno));
+ if (-1 != dev.fd_raw)
+ (void) close (dev.fd_raw);
return 1;
}
- strncpy(dev.iface, argv[1], IFNAMSIZ);
- if (0 != open_device_raw(&dev))
+#else
+ if (0 != (setuid (uid) | seteuid (uid)))
{
- (void)close(dev.fd_raw);
+ fprintf (stderr, "Failed to setuid: %s\n", strerror (errno));
+ if (-1 != dev.fd_raw)
+ (void) close (dev.fd_raw);
return 1;
}
-
- /* drop privs */
- {
- uid_t uid = getuid();
-#ifdef HAVE_SETRESUID
- if (0 != setresuid(uid, uid, uid))
- {
- fprintf(stderr, "Failed to setresuid: %s\n", strerror(errno));
- if (-1 != dev.fd_raw)
- (void)close(dev.fd_raw);
- return 1;
- }
-#else
- if (0 != (setuid(uid) | seteuid(uid)))
- {
- fprintf(stderr, "Failed to setuid: %s\n", strerror(errno));
- if (-1 != dev.fd_raw)
- (void)close(dev.fd_raw);
- return 1;
- }
#endif
}
@@ -2013,141 +2049,145 @@ main(int argc, char *argv[])
{
struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
- macmsg.hdr.size = htons(sizeof(macmsg));
- macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
- GNUNET_memcpy(&macmsg.mac, &dev.pl_mac, sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress));
- GNUNET_memcpy(write_std.buf, &macmsg, sizeof(macmsg));
+ macmsg.hdr.size = htons (sizeof(macmsg));
+ macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
+ GNUNET_memcpy (&macmsg.mac, &dev.pl_mac, sizeof(struct
+ GNUNET_TRANSPORT_WLAN_MacAddress));
+ GNUNET_memcpy (write_std.buf, &macmsg, sizeof(macmsg));
write_std.size = sizeof(macmsg);
}
- stdin_mst = mst_create(&stdin_send_hw, &dev);
+ stdin_mst = mst_create (&stdin_send_hw, &dev);
stdin_open = 1;
while (1)
+ {
+ maxfd = -1;
+ FD_ZERO (&rfds);
+ if ((0 == write_pout.size) && (1 == stdin_open))
{
- maxfd = -1;
- FD_ZERO(&rfds);
- if ((0 == write_pout.size) && (1 == stdin_open))
- {
- FD_SET(STDIN_FILENO, &rfds);
- maxfd = MAX(maxfd, STDIN_FILENO);
- }
- if (0 == write_std.size)
- {
- FD_SET(dev.fd_raw, &rfds);
- maxfd = MAX(maxfd, dev.fd_raw);
- }
- FD_ZERO(&wfds);
- if (0 < write_std.size)
- {
- FD_SET(STDOUT_FILENO, &wfds);
- maxfd = MAX(maxfd, STDOUT_FILENO);
- }
- if (0 < write_pout.size)
- {
- FD_SET(dev.fd_raw, &wfds);
- maxfd = MAX(maxfd, dev.fd_raw);
- }
+ FD_SET (STDIN_FILENO, &rfds);
+ maxfd = MAX (maxfd, STDIN_FILENO);
+ }
+ if (0 == write_std.size)
+ {
+ FD_SET (dev.fd_raw, &rfds);
+ maxfd = MAX (maxfd, dev.fd_raw);
+ }
+ FD_ZERO (&wfds);
+ if (0 < write_std.size)
+ {
+ FD_SET (STDOUT_FILENO, &wfds);
+ maxfd = MAX (maxfd, STDOUT_FILENO);
+ }
+ if (0 < write_pout.size)
+ {
+ FD_SET (dev.fd_raw, &wfds);
+ maxfd = MAX (maxfd, dev.fd_raw);
+ }
+ {
+ int retval = select (maxfd + 1, &rfds, &wfds, NULL, NULL);
+ if ((-1 == retval) && (EINTR == errno))
+ continue;
+ if (0 > retval)
{
- int retval = select(maxfd + 1, &rfds, &wfds, NULL, NULL);
- if ((-1 == retval) && (EINTR == errno))
- continue;
- if (0 > retval)
- {
- fprintf(stderr, "select failed: %s\n", strerror(errno));
- break;
- }
+ fprintf (stderr, "select failed: %s\n", strerror (errno));
+ break;
}
- if (FD_ISSET(STDOUT_FILENO, &wfds))
- {
- ssize_t ret =
- write(STDOUT_FILENO, write_std.buf + write_std.pos,
- write_std.size - write_std.pos);
- if (0 > ret)
- {
- fprintf(stderr, "Failed to write to STDOUT: %s\n", strerror(errno));
- break;
- }
- write_std.pos += ret;
- if (write_std.pos == write_std.size)
- {
- write_std.pos = 0;
- write_std.size = 0;
- }
- }
- if (FD_ISSET(dev.fd_raw, &wfds))
- {
- ssize_t ret =
- write(dev.fd_raw, write_pout.buf + write_pout.pos,
- write_pout.size - write_pout.pos);
- if (0 > ret)
- {
- fprintf(stderr, "Failed to write to WLAN device: %s\n",
- strerror(errno));
- break;
- }
- write_pout.pos += ret;
- if ((write_pout.pos != write_pout.size) && (0 != ret))
- {
- /* we should not get partial sends with packet-oriented devices... */
- fprintf(stderr, "Write error, partial send: %u/%u\n",
- (unsigned int)write_pout.pos,
- (unsigned int)write_pout.size);
- break;
- }
- if (write_pout.pos == write_pout.size)
- {
- write_pout.pos = 0;
- write_pout.size = 0;
- }
- }
+ }
+ if (FD_ISSET (STDOUT_FILENO, &wfds))
+ {
+ ssize_t ret =
+ write (STDOUT_FILENO, write_std.buf + write_std.pos,
+ write_std.size - write_std.pos);
+ if (0 > ret)
+ {
+ fprintf (stderr, "Failed to write to STDOUT: %s\n", strerror (errno));
+ break;
+ }
+ write_std.pos += ret;
+ if (write_std.pos == write_std.size)
+ {
+ write_std.pos = 0;
+ write_std.size = 0;
+ }
+ }
+ if (FD_ISSET (dev.fd_raw, &wfds))
+ {
+ ssize_t ret =
+ write (dev.fd_raw, write_pout.buf + write_pout.pos,
+ write_pout.size - write_pout.pos);
+ if (0 > ret)
+ {
+ fprintf (stderr, "Failed to write to WLAN device: %s\n",
+ strerror (errno));
+ break;
+ }
+ write_pout.pos += ret;
+ if ((write_pout.pos != write_pout.size) && (0 != ret))
+ {
+ /* we should not get partial sends with packet-oriented devices... */
+ fprintf (stderr, "Write error, partial send: %u/%u\n",
+ (unsigned int) write_pout.pos,
+ (unsigned int) write_pout.size);
+ break;
+ }
+ if (write_pout.pos == write_pout.size)
+ {
+ write_pout.pos = 0;
+ write_pout.size = 0;
+ }
+ }
- if (FD_ISSET(STDIN_FILENO, &rfds))
- {
- ssize_t ret =
- read(STDIN_FILENO, readbuf, sizeof(readbuf));
- if (0 > ret)
- {
- fprintf(stderr, "Read error from STDIN: %s\n", strerror(errno));
- break;
- }
- if (0 == ret)
- {
- /* stop reading... */
- stdin_open = 0;
- }
- mst_receive(stdin_mst, readbuf, ret);
- }
+ if (FD_ISSET (STDIN_FILENO, &rfds))
+ {
+ ssize_t ret =
+ read (STDIN_FILENO, readbuf, sizeof(readbuf));
+ if (0 > ret)
+ {
+ fprintf (stderr, "Read error from STDIN: %s\n", strerror (errno));
+ break;
+ }
+ if (0 == ret)
+ {
+ /* stop reading... */
+ stdin_open = 0;
+ }
+ mst_receive (stdin_mst, readbuf, ret);
+ }
- if (FD_ISSET(dev.fd_raw, &rfds))
- {
- struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm;
- ssize_t ret;
-
- rrm = (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *)write_std.buf;
- ret =
- linux_read(&dev, (unsigned char *)&rrm->frame,
- sizeof(write_std.buf)
- - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
- + sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
- rrm);
- if (0 > ret)
- {
- fprintf(stderr, "Read error from raw socket: %s\n", strerror(errno));
- break;
- }
- if ((0 < ret) && (0 == mac_test(&rrm->frame, &dev)))
- {
- write_std.size = ret
- + sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
- - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame);
- rrm->header.size = htons(write_std.size);
- rrm->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
- }
- }
+ if (FD_ISSET (dev.fd_raw, &rfds))
+ {
+ struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm;
+ ssize_t ret;
+
+ rrm = (struct
+ GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) write_std.buf;
+ ret =
+ linux_read (&dev, (unsigned char *) &rrm->frame,
+ sizeof(write_std.buf)
+ - sizeof(struct
+ GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
+ + sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
+ rrm);
+ if (0 > ret)
+ {
+ fprintf (stderr, "Read error from raw socket: %s\n", strerror (errno));
+ break;
+ }
+ if ((0 < ret) && (0 == mac_test (&rrm->frame, &dev)))
+ {
+ write_std.size = ret
+ + sizeof(struct
+ GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
+ - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame);
+ rrm->header.size = htons (write_std.size);
+ rrm->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
+ }
}
+ }
/* Error handling, try to clean up a bit at least */
- mst_destroy(stdin_mst);
- (void)close(dev.fd_raw);
+ mst_destroy (stdin_mst);
+ (void) close (dev.fd_raw);
return 1; /* we never exit 'normally' */
}
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index 09e15655f..66a836b84 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -176,14 +176,14 @@
* the value chosen here might be too aggressively low!
*/
#define DELAY_WARN_THRESHOLD \
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5)
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
/**
* If a DVBox could not be forwarded after this number of
* seconds we drop it.
*/
#define DV_FORWARD_TIMEOUT \
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60)
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
/**
* We only consider queues as "quality" connections when
@@ -191,53 +191,53 @@
* the latency of the queue is below this threshold.
*/
#define DV_QUALITY_RTT_THRESHOLD \
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1)
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
/**
* How long do we consider a DV path valid if we see no
* further updates on it? Note: the value chosen here might be too low!
*/
#define DV_PATH_VALIDITY_TIMEOUT \
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
/**
* How long do we cache backchannel (struct Backtalker) information
* after a backchannel goes inactive?
*/
#define BACKCHANNEL_INACTIVITY_TIMEOUT \
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
/**
* How long before paths expire would we like to (re)discover DV paths? Should
* be below #DV_PATH_VALIDITY_TIMEOUT.
*/
#define DV_PATH_DISCOVERY_FREQUENCY \
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 4)
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4)
/**
* How long are ephemeral keys valid?
*/
#define EPHEMERAL_VALIDITY \
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4)
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
/**
* How long do we keep partially reassembled messages around before giving up?
*/
#define REASSEMBLY_EXPIRATION \
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 4)
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 4)
/**
* What is the fastest rate at which we send challenges *if* we keep learning
* an address (gossip, DHT, etc.)?
*/
#define FAST_VALIDATION_CHALLENGE_FREQ \
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1)
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1)
/**
* What is the slowest rate at which we send challenges?
*/
#define MAX_VALIDATION_CHALLENGE_FREQ \
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_DAYS, 1)
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_DAYS, 1)
/**
* How long until we forget about historic accumulators and thus
@@ -245,7 +245,7 @@
* active connection experiences without an ACK.
*/
#define ACK_CUMMULATOR_TIMEOUT \
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4)
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
/**
* What is the non-randomized base frequency at which we
@@ -263,13 +263,13 @@
* When do we forget an invalid address for sure?
*/
#define MAX_ADDRESS_VALID_UNTIL \
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MONTHS, 1)
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MONTHS, 1)
/**
* How long do we consider an address valid if we just checked?
*/
#define ADDRESS_VALIDATION_LIFETIME \
- GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4)
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
/**
* What is the maximum frequency at which we do address validation?
@@ -308,7 +308,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
/**
* Unique identifier we attach to a message.
*/
-struct MessageUUIDP {
+struct MessageUUIDP
+{
/**
* Unique value, generated by incrementing the
* `message_uuid_ctr` of `struct Neighbour`.
@@ -320,7 +321,8 @@ struct MessageUUIDP {
/**
* Unique identifier to map an acknowledgement to a transmission.
*/
-struct AcknowledgementUUIDP {
+struct AcknowledgementUUIDP
+{
/**
* The UUID value.
*/
@@ -331,7 +333,8 @@ struct AcknowledgementUUIDP {
/**
* Type of a nonce used for challenges.
*/
-struct ChallengeNonceP {
+struct ChallengeNonceP
+{
/**
* The value of the nonce. Note that this is NOT a hash.
*/
@@ -342,7 +345,8 @@ struct ChallengeNonceP {
/**
* Outer layer of an encapsulated backchannel message.
*/
-struct TransportBackchannelEncapsulationMessage {
+struct TransportBackchannelEncapsulationMessage
+{
/**
* Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION.
*/
@@ -358,7 +362,8 @@ struct TransportBackchannelEncapsulationMessage {
/**
* Body by which a peer confirms that it is using an ephemeral key.
*/
-struct EphemeralConfirmationPS {
+struct EphemeralConfirmationPS
+{
/**
* Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL
*/
@@ -397,7 +402,8 @@ struct EphemeralConfirmationPS {
* Plaintext of the variable-size payload that is encrypted
* within a `struct TransportBackchannelEncapsulationMessage`
*/
-struct TransportDVBoxPayloadP {
+struct TransportDVBoxPayloadP
+{
/**
* Sender's peer identity.
*/
@@ -430,7 +436,8 @@ struct TransportDVBoxPayloadP {
* Outer layer of an encapsulated unfragmented application message sent
* over an unreliable channel.
*/
-struct TransportReliabilityBoxMessage {
+struct TransportReliabilityBoxMessage
+{
/**
* Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX
*/
@@ -456,7 +463,8 @@ struct TransportReliabilityBoxMessage {
/**
* Acknowledgement payload.
*/
-struct TransportCummulativeAckPayloadP {
+struct TransportCummulativeAckPayloadP
+{
/**
* How long was the ACK delayed for generating cummulative ACKs?
* Used to calculate the correct network RTT by taking the receipt
@@ -479,7 +487,8 @@ struct TransportCummulativeAckPayloadP {
* so ACKs are identified by a combination of PID of sender and
* message UUID, without the queue playing any role!
*/
-struct TransportReliabilityAckMessage {
+struct TransportReliabilityAckMessage
+{
/**
* Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK
*/
@@ -499,7 +508,8 @@ struct TransportReliabilityAckMessage {
/**
* Outer layer of an encapsulated fragmented application message.
*/
-struct TransportFragmentBoxMessage {
+struct TransportFragmentBoxMessage
+{
/**
* Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT
*/
@@ -549,7 +559,8 @@ struct TransportFragmentBoxMessage {
* potential amplificator will check the @e monotonic_time and only respond
* (at most) once per message.
*/
-struct DvInitPS {
+struct DvInitPS
+{
/**
* Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR
*/
@@ -592,7 +603,8 @@ struct DvInitPS {
* replay old messages. Thus, passively learned paths should always be
* immediately marked as "potentially stale".
*/
-struct DvHopPS {
+struct DvHopPS
+{
/**
* Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP
*/
@@ -619,7 +631,8 @@ struct DvHopPS {
* An entry describing a peer on a path in a
* `struct TransportDVLearnMessage` message.
*/
-struct DVPathEntryP {
+struct DVPathEntryP
+{
/**
* Identity of a peer on the path.
*/
@@ -646,7 +659,8 @@ struct DVPathEntryP {
* zero, peers that can forward to the initator should always try to
* forward to the initiator.
*/
-struct TransportDVLearnMessage {
+struct TransportDVLearnMessage
+{
/**
* Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN
*/
@@ -733,7 +747,8 @@ struct TransportDVLearnMessage {
* the predecessor must be the origin (so this is not really useful
* for anonymization).
*/
-struct TransportDVBoxMessage {
+struct TransportDVBoxMessage
+{
/**
* Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX
*/
@@ -791,7 +806,8 @@ struct TransportDVBoxMessage {
* Message send to another peer to validate that it can indeed
* receive messages at a particular address.
*/
-struct TransportValidationChallengeMessage {
+struct TransportValidationChallengeMessage
+{
/**
* Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE
*/
@@ -819,7 +835,8 @@ struct TransportValidationChallengeMessage {
* Message signed by a peer to confirm that it can indeed
* receive messages at a particular address.
*/
-struct TransportValidationPS {
+struct TransportValidationPS
+{
/**
* Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE
*/
@@ -842,7 +859,8 @@ struct TransportValidationPS {
* Message send to a peer to respond to a
* #GNUNET_MESSAGE_TYPE_ADDRESS_VALIDATION_CHALLENGE
*/
-struct TransportValidationResponseMessage {
+struct TransportValidationResponseMessage
+{
/**
* Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE
*/
@@ -886,7 +904,8 @@ struct TransportValidationResponseMessage {
* send to us, and how much data we already received from the other
* peer.
*/
-struct TransportFlowControlMessage {
+struct TransportFlowControlMessage
+{
/**
* Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL
*/
@@ -942,7 +961,8 @@ GNUNET_NETWORK_STRUCT_END
/**
* What type of client is the `struct TransportClient` about?
*/
-enum ClientType {
+enum ClientType
+{
/**
* We do not know yet (client is fresh).
*/
@@ -974,7 +994,8 @@ enum ClientType {
* Which transmission options are allowable for transmission?
* Interpreted bit-wise!
*/
-enum RouteMessageOptions {
+enum RouteMessageOptions
+{
/**
* Only confirmed, non-DV direct neighbours.
*/
@@ -1007,7 +1028,8 @@ enum RouteMessageOptions {
/**
* When did we launch this DV learning activity?
*/
-struct LearnLaunchEntry {
+struct LearnLaunchEntry
+{
/**
* Kept (also) in a DLL sorted by launch time.
*/
@@ -1035,7 +1057,8 @@ struct LearnLaunchEntry {
* Information we keep per #GOODPUT_AGING_SLOTS about historic
* (or current) transmission performance.
*/
-struct TransmissionHistoryEntry {
+struct TransmissionHistoryEntry
+{
/**
* Number of bytes actually sent in the interval.
*/
@@ -1052,7 +1075,8 @@ struct TransmissionHistoryEntry {
/**
* Performance data for a transmission possibility.
*/
-struct PerformanceData {
+struct PerformanceData
+{
/**
* Weighted average for the RTT.
*/
@@ -1119,7 +1143,8 @@ struct VirtualLink;
* Context from #handle_incoming_msg(). Closure for many
* message handlers below.
*/
-struct CommunicatorMessageContext {
+struct CommunicatorMessageContext
+{
/**
* Kept in a DLL of `struct VirtualLink` if waiting for CORE
* flow control to unchoke.
@@ -1153,7 +1178,8 @@ struct CommunicatorMessageContext {
/**
* Closure for #core_env_sent_cb.
*/
-struct CoreSentContext {
+struct CoreSentContext
+{
/**
* Kept in a DLL to clear @e vl in case @e vl is lost.
*/
@@ -1192,7 +1218,8 @@ struct CoreSentContext {
* data that is per neighbour that is not specific to how the
* connectivity is established.
*/
-struct VirtualLink {
+struct VirtualLink
+{
/**
* Identity of the peer at the other end of the link.
*/
@@ -1390,7 +1417,8 @@ struct VirtualLink {
/**
* Data structure kept when we are waiting for an acknowledgement.
*/
-struct PendingAcknowledgement {
+struct PendingAcknowledgement
+{
/**
* If @e pm is non-NULL, this is the DLL in which this acknowledgement
* is kept in relation to its pending message.
@@ -1483,7 +1511,8 @@ struct PendingAcknowledgement {
/**
* One possible hop towards a DV target.
*/
-struct DistanceVectorHop {
+struct DistanceVectorHop
+{
/**
* Kept in a MDLL, sorted by @e timeout.
*/
@@ -1564,7 +1593,8 @@ struct DistanceVectorHop {
* Entry in our #dv_routes table, representing a (set of) distance
* vector routes to a particular peer.
*/
-struct DistanceVector {
+struct DistanceVector
+{
/**
* To which peer is this a route?
*/
@@ -1628,7 +1658,8 @@ struct DistanceVector {
* what the communicator can actually provide towards a particular
* peer/target).
*/
-struct QueueEntry {
+struct QueueEntry
+{
/**
* Kept as a DLL.
*/
@@ -1660,7 +1691,8 @@ struct QueueEntry {
* A queue is a message queue provided by a communicator
* via which we can reach a particular neighbour.
*/
-struct Queue {
+struct Queue
+{
/**
* Kept in a MDLL.
*/
@@ -1788,7 +1820,8 @@ struct Queue {
/**
* Information we keep for a message that we are reassembling.
*/
-struct ReassemblyContext {
+struct ReassemblyContext
+{
/**
* Original message ID for of the message that all the fragments
* belong to.
@@ -1846,7 +1879,8 @@ struct ReassemblyContext {
/**
* A neighbour that at least one communicator is connected to.
*/
-struct Neighbour {
+struct Neighbour
+{
/**
* Which peer is this about?
*/
@@ -1929,7 +1963,8 @@ struct Neighbour {
* Another peer attempted to talk to us, we should try to establish
* a connection in the other direction.
*/
-struct IncomingRequest {
+struct IncomingRequest
+{
/**
* Kept in a DLL.
*/
@@ -1955,7 +1990,8 @@ struct IncomingRequest {
/**
* A peer that an application (client) would like us to talk to directly.
*/
-struct PeerRequest {
+struct PeerRequest
+{
/**
* Which peer is this about?
*/
@@ -1988,7 +2024,8 @@ struct PeerRequest {
/**
* Types of different pending messages.
*/
-enum PendingMessageType {
+enum PendingMessageType
+{
/**
* Ordinary message received from the CORE service.
*/
@@ -2037,7 +2074,8 @@ enum PendingMessageType {
* is never again transmitted (even if it fits below the MTU), and
* only (remaining) fragments are sent.
*/
-struct PendingMessage {
+struct PendingMessage
+{
/**
* Kept in a MDLL of messages for this @a vl.
*/
@@ -2176,7 +2214,8 @@ struct PendingMessage {
/**
* Acknowledgement payload.
*/
-struct TransportCummulativeAckPayload {
+struct TransportCummulativeAckPayload
+{
/**
* When did we receive the message we are ACKing? Used to calculate
* the delay we introduced by cummulating ACKs.
@@ -2194,7 +2233,8 @@ struct TransportCummulativeAckPayload {
* Data structure in which we track acknowledgements still to
* be sent to the
*/
-struct AcknowledgementCummulator {
+struct AcknowledgementCummulator
+{
/**
* Target peer for which we are accumulating ACKs here.
*/
@@ -2234,7 +2274,8 @@ struct AcknowledgementCummulator {
/**
* One of the addresses of this peer.
*/
-struct AddressListEntry {
+struct AddressListEntry
+{
/**
* Kept in a DLL.
*/
@@ -2286,7 +2327,8 @@ struct AddressListEntry {
/**
* Client connected to the transport service.
*/
-struct TransportClient {
+struct TransportClient
+{
/**
* Kept in a DLL.
*/
@@ -2312,11 +2354,13 @@ struct TransportClient {
*/
enum ClientType type;
- union {
+ union
+ {
/**
* Information for @e type #CT_CORE.
*/
- struct {
+ struct
+ {
/**
* Head of list of messages pending for this client, sorted by
* transmission time ("next_attempt" + possibly internal prioritization).
@@ -2332,7 +2376,8 @@ struct TransportClient {
/**
* Information for @e type #CT_MONITOR.
*/
- struct {
+ struct
+ {
/**
* Peer identity to monitor the addresses of.
* Zero to monitor all neighbours. Valid if
@@ -2350,7 +2395,8 @@ struct TransportClient {
/**
* Information for @e type #CT_COMMUNICATOR.
*/
- struct {
+ struct
+ {
/**
* If @e type is #CT_COMMUNICATOR, this communicator
* supports communicating using these addresses.
@@ -2395,7 +2441,8 @@ struct TransportClient {
/**
* Information for @e type #CT_APPLICATION
*/
- struct {
+ struct
+ {
/**
* Map of requests for peers the given client application would like to
* see connections for. Maps from PIDs to `struct PeerRequest`.
@@ -2410,7 +2457,8 @@ struct TransportClient {
* State we keep for validation activities. Each of these
* is both in the #validation_heap and the #validation_map.
*/
-struct ValidationState {
+struct ValidationState
+{
/**
* For which peer is @a address to be validated (or possibly valid)?
* Serves as key in the #validation_map.
@@ -2520,7 +2568,8 @@ struct ValidationState {
* material (to avoid repeatedly checking signatures), and to synchronize
* monotonic time with the PEERSTORE.
*/
-struct Backtalker {
+struct Backtalker
+{
/**
* Peer this is about.
*/
@@ -2743,11 +2792,11 @@ static struct GNUNET_TIME_Absolute hello_mono_time;
* @return current age of the world
*/
static unsigned int
-get_age()
+get_age ()
{
struct GNUNET_TIME_Absolute now;
- now = GNUNET_TIME_absolute_get();
+ now = GNUNET_TIME_absolute_get ();
return now.abs_value_us / GNUNET_TIME_UNIT_MINUTES.rel_value_us / 15;
}
@@ -2758,13 +2807,13 @@ get_age()
* @param ir data structure to release
*/
static void
-free_incoming_request(struct IncomingRequest *ir)
+free_incoming_request (struct IncomingRequest *ir)
{
- GNUNET_CONTAINER_DLL_remove(ir_head, ir_tail, ir);
- GNUNET_assert(ir_total > 0);
+ GNUNET_CONTAINER_DLL_remove (ir_head, ir_tail, ir);
+ GNUNET_assert (ir_total > 0);
ir_total--;
- GNUNET_PEERSTORE_watch_cancel(ir->wc);
- GNUNET_free(ir);
+ GNUNET_PEERSTORE_watch_cancel (ir->wc);
+ GNUNET_free (ir);
}
@@ -2774,34 +2823,34 @@ free_incoming_request(struct IncomingRequest *ir)
* @param pa data structure to release
*/
static void
-free_pending_acknowledgement(struct PendingAcknowledgement *pa)
+free_pending_acknowledgement (struct PendingAcknowledgement *pa)
{
struct Queue *q = pa->queue;
struct PendingMessage *pm = pa->pm;
struct DistanceVectorHop *dvh = pa->dvh;
- GNUNET_CONTAINER_MDLL_remove(pa, pa_head, pa_tail, pa);
+ GNUNET_CONTAINER_MDLL_remove (pa, pa_head, pa_tail, pa);
pa_count--;
if (NULL != q)
- {
- GNUNET_CONTAINER_MDLL_remove(queue, q->pa_head, q->pa_tail, pa);
- pa->queue = NULL;
- }
+ {
+ GNUNET_CONTAINER_MDLL_remove (queue, q->pa_head, q->pa_tail, pa);
+ pa->queue = NULL;
+ }
if (NULL != pm)
- {
- GNUNET_CONTAINER_MDLL_remove(pm, pm->pa_head, pm->pa_tail, pa);
- pa->pm = NULL;
- }
+ {
+ GNUNET_CONTAINER_MDLL_remove (pm, pm->pa_head, pm->pa_tail, pa);
+ pa->pm = NULL;
+ }
if (NULL != dvh)
- {
- GNUNET_CONTAINER_MDLL_remove(dvh, dvh->pa_head, dvh->pa_tail, pa);
- pa->queue = NULL;
- }
- GNUNET_assert(GNUNET_YES ==
- GNUNET_CONTAINER_multiuuidmap_remove(pending_acks,
- &pa->ack_uuid.value,
- pa));
- GNUNET_free(pa);
+ {
+ GNUNET_CONTAINER_MDLL_remove (dvh, dvh->pa_head, dvh->pa_tail, pa);
+ pa->queue = NULL;
+ }
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multiuuidmap_remove (pending_acks,
+ &pa->ack_uuid.value,
+ pa));
+ GNUNET_free (pa);
}
@@ -2814,23 +2863,23 @@ free_pending_acknowledgement(struct PendingAcknowledgement *pa)
* @param root root of the tree to free
*/
static void
-free_fragment_tree(struct PendingMessage *root)
+free_fragment_tree (struct PendingMessage *root)
{
struct PendingMessage *frag;
while (NULL != (frag = root->head_frag))
- {
- struct PendingAcknowledgement *pa;
+ {
+ struct PendingAcknowledgement *pa;
- free_fragment_tree(frag);
- while (NULL != (pa = frag->pa_head))
- {
- GNUNET_CONTAINER_MDLL_remove(pm, frag->pa_head, frag->pa_tail, pa);
- pa->pm = NULL;
- }
- GNUNET_CONTAINER_MDLL_remove(frag, root->head_frag, root->tail_frag, frag);
- GNUNET_free(frag);
+ free_fragment_tree (frag);
+ while (NULL != (pa = frag->pa_head))
+ {
+ GNUNET_CONTAINER_MDLL_remove (pm, frag->pa_head, frag->pa_tail, pa);
+ pa->pm = NULL;
}
+ GNUNET_CONTAINER_MDLL_remove (frag, root->head_frag, root->tail_frag, frag);
+ GNUNET_free (frag);
+ }
}
@@ -2842,44 +2891,44 @@ free_fragment_tree(struct PendingMessage *root)
* @param pm the pending message to free
*/
static void
-free_pending_message(struct PendingMessage *pm)
+free_pending_message (struct PendingMessage *pm)
{
struct TransportClient *tc = pm->client;
struct VirtualLink *vl = pm->vl;
struct PendingAcknowledgement *pa;
if (NULL != tc)
- {
- GNUNET_CONTAINER_MDLL_remove(client,
- tc->details.core.pending_msg_head,
- tc->details.core.pending_msg_tail,
- pm);
- }
+ {
+ GNUNET_CONTAINER_MDLL_remove (client,
+ tc->details.core.pending_msg_head,
+ tc->details.core.pending_msg_tail,
+ pm);
+ }
if (NULL != vl)
- {
- GNUNET_CONTAINER_MDLL_remove(vl,
- vl->pending_msg_head,
- vl->pending_msg_tail,
- pm);
- }
+ {
+ GNUNET_CONTAINER_MDLL_remove (vl,
+ vl->pending_msg_head,
+ vl->pending_msg_tail,
+ pm);
+ }
while (NULL != (pa = pm->pa_head))
- {
- GNUNET_CONTAINER_MDLL_remove(pm, pm->pa_head, pm->pa_tail, pa);
- pa->pm = NULL;
- }
+ {
+ GNUNET_CONTAINER_MDLL_remove (pm, pm->pa_head, pm->pa_tail, pa);
+ pa->pm = NULL;
+ }
- free_fragment_tree(pm);
+ free_fragment_tree (pm);
if (NULL != pm->qe)
- {
- GNUNET_assert(pm == pm->qe->pm);
- pm->qe->pm = NULL;
- }
+ {
+ GNUNET_assert (pm == pm->qe->pm);
+ pm->qe->pm = NULL;
+ }
if (NULL != pm->bpm)
- {
- free_fragment_tree(pm->bpm);
- GNUNET_free(pm->bpm);
- }
- GNUNET_free(pm);
+ {
+ free_fragment_tree (pm->bpm);
+ GNUNET_free (pm->bpm);
+ }
+ GNUNET_free (pm);
}
@@ -2889,34 +2938,34 @@ free_pending_message(struct PendingMessage *pm)
* @param vl link data to free
*/
static void
-free_virtual_link(struct VirtualLink *vl)
+free_virtual_link (struct VirtualLink *vl)
{
struct PendingMessage *pm;
struct CoreSentContext *csc;
while (NULL != (pm = vl->pending_msg_head))
- free_pending_message(pm);
- GNUNET_assert(GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove(links, &vl->target, vl));
+ free_pending_message (pm);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_remove (links, &vl->target, vl));
if (NULL != vl->visibility_task)
- {
- GNUNET_SCHEDULER_cancel(vl->visibility_task);
- vl->visibility_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (vl->visibility_task);
+ vl->visibility_task = NULL;
+ }
if (NULL != vl->fc_retransmit_task)
- {
- GNUNET_SCHEDULER_cancel(vl->fc_retransmit_task);
- vl->fc_retransmit_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (vl->fc_retransmit_task);
+ vl->fc_retransmit_task = NULL;
+ }
while (NULL != (csc = vl->csc_head))
- {
- GNUNET_CONTAINER_DLL_remove(vl->csc_head, vl->csc_tail, csc);
- GNUNET_assert(vl == csc->vl);
- csc->vl = NULL;
- }
- GNUNET_break(NULL == vl->n);
- GNUNET_break(NULL == vl->dv);
- GNUNET_free(vl);
+ {
+ GNUNET_CONTAINER_DLL_remove (vl->csc_head, vl->csc_tail, csc);
+ GNUNET_assert (vl == csc->vl);
+ csc->vl = NULL;
+ }
+ GNUNET_break (NULL == vl->n);
+ GNUNET_break (NULL == vl->dv);
+ GNUNET_free (vl);
}
@@ -2926,20 +2975,20 @@ free_virtual_link(struct VirtualLink *vl)
* @param vs validation state to free
*/
static void
-free_validation_state(struct ValidationState *vs)
+free_validation_state (struct ValidationState *vs)
{
- GNUNET_assert(
+ GNUNET_assert (
GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove(validation_map, &vs->pid, vs));
- GNUNET_CONTAINER_heap_remove_node(vs->hn);
+ GNUNET_CONTAINER_multipeermap_remove (validation_map, &vs->pid, vs));
+ GNUNET_CONTAINER_heap_remove_node (vs->hn);
vs->hn = NULL;
if (NULL != vs->sc)
- {
- GNUNET_PEERSTORE_store_cancel(vs->sc);
- vs->sc = NULL;
- }
- GNUNET_free(vs->address);
- GNUNET_free(vs);
+ {
+ GNUNET_PEERSTORE_store_cancel (vs->sc);
+ vs->sc = NULL;
+ }
+ GNUNET_free (vs->address);
+ GNUNET_free (vs);
}
@@ -2950,9 +2999,9 @@ free_validation_state(struct ValidationState *vs)
* @return NULL if we do not have this peer as a neighbour
*/
static struct Neighbour *
-lookup_neighbour(const struct GNUNET_PeerIdentity *pid)
+lookup_neighbour (const struct GNUNET_PeerIdentity *pid)
{
- return GNUNET_CONTAINER_multipeermap_get(neighbours, pid);
+ return GNUNET_CONTAINER_multipeermap_get (neighbours, pid);
}
@@ -2963,16 +3012,17 @@ lookup_neighbour(const struct GNUNET_PeerIdentity *pid)
* @return NULL if we do not have this peer as a virtual link
*/
static struct VirtualLink *
-lookup_virtual_link(const struct GNUNET_PeerIdentity *pid)
+lookup_virtual_link (const struct GNUNET_PeerIdentity *pid)
{
- return GNUNET_CONTAINER_multipeermap_get(links, pid);
+ return GNUNET_CONTAINER_multipeermap_get (links, pid);
}
/**
* Details about what to notify monitors about.
*/
-struct MonitorEvent {
+struct MonitorEvent
+{
/**
* @deprecated To be discussed if we keep these...
*/
@@ -3011,20 +3061,20 @@ struct MonitorEvent {
* @param dvh hop to free
*/
static void
-free_distance_vector_hop(struct DistanceVectorHop *dvh)
+free_distance_vector_hop (struct DistanceVectorHop *dvh)
{
struct Neighbour *n = dvh->next_hop;
struct DistanceVector *dv = dvh->dv;
struct PendingAcknowledgement *pa;
while (NULL != (pa = dvh->pa_head))
- {
- GNUNET_CONTAINER_MDLL_remove(dvh, dvh->pa_head, dvh->pa_tail, pa);
- pa->dvh = NULL;
- }
- GNUNET_CONTAINER_MDLL_remove(neighbour, n->dv_head, n->dv_tail, dvh);
- GNUNET_CONTAINER_MDLL_remove(dv, dv->dv_head, dv->dv_tail, dvh);
- GNUNET_free(dvh);
+ {
+ GNUNET_CONTAINER_MDLL_remove (dvh, dvh->pa_head, dvh->pa_tail, pa);
+ pa->dvh = NULL;
+ }
+ GNUNET_CONTAINER_MDLL_remove (neighbour, n->dv_head, n->dv_tail, dvh);
+ GNUNET_CONTAINER_MDLL_remove (dv, dv->dv_head, dv->dv_tail, dvh);
+ GNUNET_free (dvh);
}
@@ -3035,7 +3085,7 @@ free_distance_vector_hop(struct DistanceVectorHop *dvh)
* @param cls a `struct VirtualLink`
*/
static void
-check_link_down(void *cls);
+check_link_down (void *cls);
/**
@@ -3044,22 +3094,22 @@ check_link_down(void *cls);
* @param pid peer the connection was for
*/
static void
-cores_send_disconnect_info(const struct GNUNET_PeerIdentity *pid)
+cores_send_disconnect_info (const struct GNUNET_PeerIdentity *pid)
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Informing CORE clients about disconnect from %s\n",
- GNUNET_i2s(pid));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Informing CORE clients about disconnect from %s\n",
+ GNUNET_i2s (pid));
for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
- {
- struct GNUNET_MQ_Envelope *env;
- struct DisconnectInfoMessage *dim;
-
- if (CT_CORE != tc->type)
- continue;
- env = GNUNET_MQ_msg(dim, GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
- dim->peer = *pid;
- GNUNET_MQ_send(tc->mq, env);
- }
+ {
+ struct GNUNET_MQ_Envelope *env;
+ struct DisconnectInfoMessage *dim;
+
+ if (CT_CORE != tc->type)
+ continue;
+ env = GNUNET_MQ_msg (dim, GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
+ dim->peer = *pid;
+ GNUNET_MQ_send (tc->mq, env);
+ }
}
@@ -3070,43 +3120,43 @@ cores_send_disconnect_info(const struct GNUNET_PeerIdentity *pid)
* @param dv route to free
*/
static void
-free_dv_route(struct DistanceVector *dv)
+free_dv_route (struct DistanceVector *dv)
{
struct DistanceVectorHop *dvh;
while (NULL != (dvh = dv->dv_head))
- free_distance_vector_hop(dvh);
+ free_distance_vector_hop (dvh);
if (NULL == dv->dv_head)
- {
- struct VirtualLink *vl;
+ {
+ struct VirtualLink *vl;
- GNUNET_assert(
- GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove(dv_routes, &dv->target, dv));
- if (NULL != (vl = dv->vl))
- {
- GNUNET_assert(dv == vl->dv);
- vl->dv = NULL;
- if (NULL == vl->n)
- {
- cores_send_disconnect_info(&dv->target);
- free_virtual_link(vl);
- }
- else
- {
- GNUNET_SCHEDULER_cancel(vl->visibility_task);
- vl->visibility_task = GNUNET_SCHEDULER_add_now(&check_link_down, vl);
- }
- dv->vl = NULL;
- }
+ GNUNET_assert (
+ GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_remove (dv_routes, &dv->target, dv));
+ if (NULL != (vl = dv->vl))
+ {
+ GNUNET_assert (dv == vl->dv);
+ vl->dv = NULL;
+ if (NULL == vl->n)
+ {
+ cores_send_disconnect_info (&dv->target);
+ free_virtual_link (vl);
+ }
+ else
+ {
+ GNUNET_SCHEDULER_cancel (vl->visibility_task);
+ vl->visibility_task = GNUNET_SCHEDULER_add_now (&check_link_down, vl);
+ }
+ dv->vl = NULL;
+ }
- if (NULL != dv->timeout_task)
- {
- GNUNET_SCHEDULER_cancel(dv->timeout_task);
- dv->timeout_task = NULL;
- }
- GNUNET_free(dv);
+ if (NULL != dv->timeout_task)
+ {
+ GNUNET_SCHEDULER_cancel (dv->timeout_task);
+ dv->timeout_task = NULL;
}
+ GNUNET_free (dv);
+ }
}
@@ -3124,30 +3174,30 @@ free_dv_route(struct DistanceVector *dv)
* @param me detailed information to transmit
*/
static void
-notify_monitor(struct TransportClient *tc,
- const struct GNUNET_PeerIdentity *peer,
- const char *address,
- enum GNUNET_NetworkType nt,
- const struct MonitorEvent *me)
+notify_monitor (struct TransportClient *tc,
+ const struct GNUNET_PeerIdentity *peer,
+ const char *address,
+ enum GNUNET_NetworkType nt,
+ const struct MonitorEvent *me)
{
struct GNUNET_MQ_Envelope *env;
struct GNUNET_TRANSPORT_MonitorData *md;
- size_t addr_len = strlen(address) + 1;
+ size_t addr_len = strlen (address) + 1;
- env = GNUNET_MQ_msg_extra(md,
- addr_len,
- GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA);
- md->nt = htonl((uint32_t)nt);
+ env = GNUNET_MQ_msg_extra (md,
+ addr_len,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA);
+ md->nt = htonl ((uint32_t) nt);
md->peer = *peer;
- md->last_validation = GNUNET_TIME_absolute_hton(me->last_validation);
- md->valid_until = GNUNET_TIME_absolute_hton(me->valid_until);
- md->next_validation = GNUNET_TIME_absolute_hton(me->next_validation);
- md->rtt = GNUNET_TIME_relative_hton(me->rtt);
- md->cs = htonl((uint32_t)me->cs);
- md->num_msg_pending = htonl(me->num_msg_pending);
- md->num_bytes_pending = htonl(me->num_bytes_pending);
- memcpy(&md[1], address, addr_len);
- GNUNET_MQ_send(tc->mq, env);
+ md->last_validation = GNUNET_TIME_absolute_hton (me->last_validation);
+ md->valid_until = GNUNET_TIME_absolute_hton (me->valid_until);
+ md->next_validation = GNUNET_TIME_absolute_hton (me->next_validation);
+ md->rtt = GNUNET_TIME_relative_hton (me->rtt);
+ md->cs = htonl ((uint32_t) me->cs);
+ md->num_msg_pending = htonl (me->num_msg_pending);
+ md->num_bytes_pending = htonl (me->num_bytes_pending);
+ memcpy (&md[1], address, addr_len);
+ GNUNET_MQ_send (tc->mq, env);
}
@@ -3161,22 +3211,22 @@ notify_monitor(struct TransportClient *tc,
* @param me detailed information to transmit
*/
static void
-notify_monitors(const struct GNUNET_PeerIdentity *peer,
- const char *address,
- enum GNUNET_NetworkType nt,
- const struct MonitorEvent *me)
+notify_monitors (const struct GNUNET_PeerIdentity *peer,
+ const char *address,
+ enum GNUNET_NetworkType nt,
+ const struct MonitorEvent *me)
{
for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
- {
- if (CT_MONITOR != tc->type)
- continue;
- if (tc->details.monitor.one_shot)
- continue;
- if ((0 != GNUNET_is_zero(&tc->details.monitor.peer)) &&
- (0 != GNUNET_memcmp(&tc->details.monitor.peer, peer)))
- continue;
- notify_monitor(tc, peer, address, nt, me);
- }
+ {
+ if (CT_MONITOR != tc->type)
+ continue;
+ if (tc->details.monitor.one_shot)
+ continue;
+ if ((0 != GNUNET_is_zero (&tc->details.monitor.peer)) &&
+ (0 != GNUNET_memcmp (&tc->details.monitor.peer, peer)))
+ continue;
+ notify_monitor (tc, peer, address, nt, me);
+ }
}
@@ -3190,18 +3240,18 @@ notify_monitors(const struct GNUNET_PeerIdentity *peer,
* @return our `struct TransportClient`
*/
static void *
-client_connect_cb(void *cls,
- struct GNUNET_SERVICE_Client *client,
- struct GNUNET_MQ_Handle *mq)
+client_connect_cb (void *cls,
+ struct GNUNET_SERVICE_Client *client,
+ struct GNUNET_MQ_Handle *mq)
{
struct TransportClient *tc;
- (void)cls;
- tc = GNUNET_new(struct TransportClient);
+ (void) cls;
+ tc = GNUNET_new (struct TransportClient);
tc->client = client;
tc->mq = mq;
- GNUNET_CONTAINER_DLL_insert(clients_head, clients_tail, tc);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc);
+ GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc);
return tc;
}
@@ -3212,16 +3262,16 @@ client_connect_cb(void *cls,
* @param rc data structure to free
*/
static void
-free_reassembly_context(struct ReassemblyContext *rc)
+free_reassembly_context (struct ReassemblyContext *rc)
{
struct Neighbour *n = rc->neighbour;
- GNUNET_assert(rc == GNUNET_CONTAINER_heap_remove_node(rc->hn));
- GNUNET_assert(GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap32_remove(n->reassembly_map,
- rc->msg_uuid.uuid,
- rc));
- GNUNET_free(rc);
+ GNUNET_assert (rc == GNUNET_CONTAINER_heap_remove_node (rc->hn));
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap32_remove (n->reassembly_map,
+ rc->msg_uuid.uuid,
+ rc));
+ GNUNET_free (rc);
}
@@ -3231,27 +3281,27 @@ free_reassembly_context(struct ReassemblyContext *rc)
* @param cls a `struct Neighbour`
*/
static void
-reassembly_cleanup_task(void *cls)
+reassembly_cleanup_task (void *cls)
{
struct Neighbour *n = cls;
struct ReassemblyContext *rc;
n->reassembly_timeout_task = NULL;
- while (NULL != (rc = GNUNET_CONTAINER_heap_peek(n->reassembly_heap)))
+ while (NULL != (rc = GNUNET_CONTAINER_heap_peek (n->reassembly_heap)))
+ {
+ if (0 == GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout)
+ .rel_value_us)
{
- if (0 == GNUNET_TIME_absolute_get_remaining(rc->reassembly_timeout)
- .rel_value_us)
- {
- free_reassembly_context(rc);
- continue;
- }
- GNUNET_assert(NULL == n->reassembly_timeout_task);
- n->reassembly_timeout_task =
- GNUNET_SCHEDULER_add_at(rc->reassembly_timeout,
- &reassembly_cleanup_task,
- n);
- return;
+ free_reassembly_context (rc);
+ continue;
}
+ GNUNET_assert (NULL == n->reassembly_timeout_task);
+ n->reassembly_timeout_task =
+ GNUNET_SCHEDULER_add_at (rc->reassembly_timeout,
+ &reassembly_cleanup_task,
+ n);
+ return;
+ }
}
@@ -3264,13 +3314,13 @@ reassembly_cleanup_task(void *cls)
* @return #GNUNET_OK (continue iteration)
*/
static int
-free_reassembly_cb(void *cls, uint32_t key, void *value)
+free_reassembly_cb (void *cls, uint32_t key, void *value)
{
struct ReassemblyContext *rc = value;
- (void)cls;
- (void)key;
- free_reassembly_context(rc);
+ (void) cls;
+ (void) key;
+ free_reassembly_context (rc);
return GNUNET_OK;
}
@@ -3281,66 +3331,66 @@ free_reassembly_cb(void *cls, uint32_t key, void *value)
* @param neighbour neighbour entry to free
*/
static void
-free_neighbour(struct Neighbour *neighbour)
+free_neighbour (struct Neighbour *neighbour)
{
struct DistanceVectorHop *dvh;
struct VirtualLink *vl;
- GNUNET_assert(NULL == neighbour->queue_head);
- GNUNET_assert(GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove(neighbours,
- &neighbour->pid,
- neighbour));
+ GNUNET_assert (NULL == neighbour->queue_head);
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_remove (neighbours,
+ &neighbour->pid,
+ neighbour));
if (NULL != neighbour->reassembly_map)
- {
- GNUNET_CONTAINER_multihashmap32_iterate(neighbour->reassembly_map,
- &free_reassembly_cb,
- NULL);
- GNUNET_CONTAINER_multihashmap32_destroy(neighbour->reassembly_map);
- neighbour->reassembly_map = NULL;
- GNUNET_CONTAINER_heap_destroy(neighbour->reassembly_heap);
- neighbour->reassembly_heap = NULL;
- }
+ {
+ GNUNET_CONTAINER_multihashmap32_iterate (neighbour->reassembly_map,
+ &free_reassembly_cb,
+ NULL);
+ GNUNET_CONTAINER_multihashmap32_destroy (neighbour->reassembly_map);
+ neighbour->reassembly_map = NULL;
+ GNUNET_CONTAINER_heap_destroy (neighbour->reassembly_heap);
+ neighbour->reassembly_heap = NULL;
+ }
while (NULL != (dvh = neighbour->dv_head))
- {
- struct DistanceVector *dv = dvh->dv;
+ {
+ struct DistanceVector *dv = dvh->dv;
- free_distance_vector_hop(dvh);
- if (NULL == dv->dv_head)
- free_dv_route(dv);
- }
+ free_distance_vector_hop (dvh);
+ if (NULL == dv->dv_head)
+ free_dv_route (dv);
+ }
if (NULL != neighbour->reassembly_timeout_task)
- {
- GNUNET_SCHEDULER_cancel(neighbour->reassembly_timeout_task);
- neighbour->reassembly_timeout_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (neighbour->reassembly_timeout_task);
+ neighbour->reassembly_timeout_task = NULL;
+ }
if (NULL != neighbour->get)
- {
- GNUNET_PEERSTORE_iterate_cancel(neighbour->get);
- neighbour->get = NULL;
- }
+ {
+ GNUNET_PEERSTORE_iterate_cancel (neighbour->get);
+ neighbour->get = NULL;
+ }
if (NULL != neighbour->sc)
+ {
+ GNUNET_PEERSTORE_store_cancel (neighbour->sc);
+ neighbour->sc = NULL;
+ }
+ if (NULL != (vl = neighbour->vl))
+ {
+ GNUNET_assert (neighbour == vl->n);
+ vl->n = NULL;
+ if (NULL == vl->dv)
{
- GNUNET_PEERSTORE_store_cancel(neighbour->sc);
- neighbour->sc = NULL;
+ cores_send_disconnect_info (&vl->target);
+ free_virtual_link (vl);
}
- if (NULL != (vl = neighbour->vl))
+ else
{
- GNUNET_assert(neighbour == vl->n);
- vl->n = NULL;
- if (NULL == vl->dv)
- {
- cores_send_disconnect_info(&vl->target);
- free_virtual_link(vl);
- }
- else
- {
- GNUNET_SCHEDULER_cancel(vl->visibility_task);
- vl->visibility_task = GNUNET_SCHEDULER_add_now(&check_link_down, vl);
- }
- neighbour->vl = NULL;
+ GNUNET_SCHEDULER_cancel (vl->visibility_task);
+ vl->visibility_task = GNUNET_SCHEDULER_add_now (&check_link_down, vl);
}
- GNUNET_free(neighbour);
+ neighbour->vl = NULL;
+ }
+ GNUNET_free (neighbour);
}
@@ -3351,16 +3401,16 @@ free_neighbour(struct Neighbour *neighbour)
* @param pid peer the connection is for
*/
static void
-core_send_connect_info(struct TransportClient *tc,
- const struct GNUNET_PeerIdentity *pid)
+core_send_connect_info (struct TransportClient *tc,
+ const struct GNUNET_PeerIdentity *pid)
{
struct GNUNET_MQ_Envelope *env;
struct ConnectInfoMessage *cim;
- GNUNET_assert(CT_CORE == tc->type);
- env = GNUNET_MQ_msg(cim, GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
+ GNUNET_assert (CT_CORE == tc->type);
+ env = GNUNET_MQ_msg (cim, GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
cim->id = *pid;
- GNUNET_MQ_send(tc->mq, env);
+ GNUNET_MQ_send (tc->mq, env);
}
@@ -3370,17 +3420,17 @@ core_send_connect_info(struct TransportClient *tc,
* @param pid peer the queue was for
*/
static void
-cores_send_connect_info(const struct GNUNET_PeerIdentity *pid)
+cores_send_connect_info (const struct GNUNET_PeerIdentity *pid)
{
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Informing CORE clients about connection to %s\n",
- GNUNET_i2s(pid));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Informing CORE clients about connection to %s\n",
+ GNUNET_i2s (pid));
for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
- {
- if (CT_CORE != tc->type)
- continue;
- core_send_connect_info(tc, pid);
- }
+ {
+ if (CT_CORE != tc->type)
+ continue;
+ core_send_connect_info (tc, pid);
+ }
}
@@ -3392,7 +3442,7 @@ cores_send_connect_info(const struct GNUNET_PeerIdentity *pid)
* @param cls the `struct Queue` to process transmissions for
*/
static void
-transmit_on_queue(void *cls);
+transmit_on_queue (void *cls);
/**
@@ -3403,38 +3453,38 @@ transmit_on_queue(void *cls);
* @param p task priority to use, if @a queue is scheduled
*/
static void
-schedule_transmit_on_queue(struct Queue *queue,
- enum GNUNET_SCHEDULER_Priority p)
+schedule_transmit_on_queue (struct Queue *queue,
+ enum GNUNET_SCHEDULER_Priority p)
{
if (queue->tc->details.communicator.total_queue_length >=
COMMUNICATOR_TOTAL_QUEUE_LIMIT)
- {
- GNUNET_STATISTICS_update(
- GST_stats,
- "# Transmission throttled due to communicator queue limit",
- 1,
- GNUNET_NO);
- queue->idle = GNUNET_NO;
- return;
- }
+ {
+ GNUNET_STATISTICS_update (
+ GST_stats,
+ "# Transmission throttled due to communicator queue limit",
+ 1,
+ GNUNET_NO);
+ queue->idle = GNUNET_NO;
+ return;
+ }
if (queue->queue_length >= QUEUE_LENGTH_LIMIT)
- {
- GNUNET_STATISTICS_update(GST_stats,
- "# Transmission throttled due to queue queue limit",
- 1,
- GNUNET_NO);
- queue->idle = GNUNET_NO;
- return;
- }
+ {
+ GNUNET_STATISTICS_update (GST_stats,
+ "# Transmission throttled due to queue queue limit",
+ 1,
+ GNUNET_NO);
+ queue->idle = GNUNET_NO;
+ return;
+ }
/* queue might indeed be ready, schedule it */
if (NULL != queue->transmit_task)
- GNUNET_SCHEDULER_cancel(queue->transmit_task);
+ GNUNET_SCHEDULER_cancel (queue->transmit_task);
queue->transmit_task =
- GNUNET_SCHEDULER_add_with_priority(p, &transmit_on_queue, queue);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Considering transmission on queue `%s' to %s\n",
- queue->address,
- GNUNET_i2s(&queue->neighbour->pid));
+ GNUNET_SCHEDULER_add_with_priority (p, &transmit_on_queue, queue);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Considering transmission on queue `%s' to %s\n",
+ queue->address,
+ GNUNET_i2s (&queue->neighbour->pid));
}
@@ -3445,7 +3495,7 @@ schedule_transmit_on_queue(struct Queue *queue,
* @param cls a `struct VirtualLink`
*/
static void
-check_link_down(void *cls)
+check_link_down (void *cls)
{
struct VirtualLink *vl = cls;
struct DistanceVector *dv = vl->dv;
@@ -3457,30 +3507,30 @@ check_link_down(void *cls)
dvh_timeout = GNUNET_TIME_UNIT_ZERO_ABS;
for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
pos = pos->next_dv)
- dvh_timeout = GNUNET_TIME_absolute_max(dvh_timeout, pos->path_valid_until);
- if (0 == GNUNET_TIME_absolute_get_remaining(dvh_timeout).rel_value_us)
- {
- vl->dv->vl = NULL;
- vl->dv = NULL;
- }
+ dvh_timeout = GNUNET_TIME_absolute_max (dvh_timeout, pos->path_valid_until);
+ if (0 == GNUNET_TIME_absolute_get_remaining (dvh_timeout).rel_value_us)
+ {
+ vl->dv->vl = NULL;
+ vl->dv = NULL;
+ }
q_timeout = GNUNET_TIME_UNIT_ZERO_ABS;
for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour)
- q_timeout = GNUNET_TIME_absolute_max(q_timeout, q->validated_until);
- if (0 == GNUNET_TIME_absolute_get_remaining(q_timeout).rel_value_us)
- {
- vl->n->vl = NULL;
- vl->n = NULL;
- }
+ q_timeout = GNUNET_TIME_absolute_max (q_timeout, q->validated_until);
+ if (0 == GNUNET_TIME_absolute_get_remaining (q_timeout).rel_value_us)
+ {
+ vl->n->vl = NULL;
+ vl->n = NULL;
+ }
if ((NULL == vl->n) && (NULL == vl->dv))
- {
- cores_send_disconnect_info(&vl->target);
- free_virtual_link(vl);
- return;
- }
+ {
+ cores_send_disconnect_info (&vl->target);
+ free_virtual_link (vl);
+ return;
+ }
vl->visibility_task =
- GNUNET_SCHEDULER_add_at(GNUNET_TIME_absolute_max(q_timeout, dvh_timeout),
- &check_link_down,
- vl);
+ GNUNET_SCHEDULER_add_at (GNUNET_TIME_absolute_max (q_timeout, dvh_timeout),
+ &check_link_down,
+ vl);
}
@@ -3490,7 +3540,7 @@ check_link_down(void *cls)
* @param queue the queue to free
*/
static void
-free_queue(struct Queue *queue)
+free_queue (struct Queue *queue)
{
struct Neighbour *neighbour = queue->neighbour;
struct TransportClient *tc = queue->tc;
@@ -3502,65 +3552,65 @@ free_queue(struct Queue *queue)
struct VirtualLink *vl;
if (NULL != queue->transmit_task)
- {
- GNUNET_SCHEDULER_cancel(queue->transmit_task);
- queue->transmit_task = NULL;
- }
+ {
+ GNUNET_SCHEDULER_cancel (queue->transmit_task);
+ queue->transmit_task = NULL;
+ }
while (NULL != (pa = queue->pa_head))
- {
- GNUNET_CONTAINER_MDLL_remove(queue, queue->pa_head, queue->pa_tail, pa);
- pa->queue = NULL;
- }
+ {
+ GNUNET_CONTAINER_MDLL_remove (queue, queue->pa_head, queue->pa_tail, pa);
+ pa->queue = NULL;
+ }
- GNUNET_CONTAINER_MDLL_remove(neighbour,
- neighbour->queue_head,
- neighbour->queue_tail,
- queue);
- GNUNET_CONTAINER_MDLL_remove(client,
- tc->details.communicator.queue_head,
- tc->details.communicator.queue_tail,
- queue);
+ GNUNET_CONTAINER_MDLL_remove (neighbour,
+ neighbour->queue_head,
+ neighbour->queue_tail,
+ queue);
+ GNUNET_CONTAINER_MDLL_remove (client,
+ tc->details.communicator.queue_head,
+ tc->details.communicator.queue_tail,
+ queue);
maxxed = (COMMUNICATOR_TOTAL_QUEUE_LIMIT >=
tc->details.communicator.total_queue_length);
while (NULL != (qe = queue->queue_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (queue->queue_head, queue->queue_tail, qe);
+ queue->queue_length--;
+ tc->details.communicator.total_queue_length--;
+ if (NULL != qe->pm)
{
- GNUNET_CONTAINER_DLL_remove(queue->queue_head, queue->queue_tail, qe);
- queue->queue_length--;
- tc->details.communicator.total_queue_length--;
- if (NULL != qe->pm)
- {
- GNUNET_assert(qe == qe->pm->qe);
- qe->pm->qe = NULL;
- }
- GNUNET_free(qe);
+ GNUNET_assert (qe == qe->pm->qe);
+ qe->pm->qe = NULL;
}
- GNUNET_assert(0 == queue->queue_length);
+ GNUNET_free (qe);
+ }
+ GNUNET_assert (0 == queue->queue_length);
if ((maxxed) && (COMMUNICATOR_TOTAL_QUEUE_LIMIT <
tc->details.communicator.total_queue_length))
- {
- /* Communicator dropped below threshold, resume all _other_ queues */
- GNUNET_STATISTICS_update(
- GST_stats,
- "# Transmission throttled due to communicator queue limit",
- -1,
- GNUNET_NO);
- for (struct Queue *s = tc->details.communicator.queue_head; NULL != s;
- s = s->next_client)
- schedule_transmit_on_queue(s, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
- }
- notify_monitors(&neighbour->pid, queue->address, queue->nt, &me);
- GNUNET_free(queue);
+ {
+ /* Communicator dropped below threshold, resume all _other_ queues */
+ GNUNET_STATISTICS_update (
+ GST_stats,
+ "# Transmission throttled due to communicator queue limit",
+ -1,
+ GNUNET_NO);
+ for (struct Queue *s = tc->details.communicator.queue_head; NULL != s;
+ s = s->next_client)
+ schedule_transmit_on_queue (s, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
+ }
+ notify_monitors (&neighbour->pid, queue->address, queue->nt, &me);
+ GNUNET_free (queue);
- vl = lookup_virtual_link(&neighbour->pid);
+ vl = lookup_virtual_link (&neighbour->pid);
if ((NULL != vl) && (neighbour == vl->n))
- {
- GNUNET_SCHEDULER_cancel(vl->visibility_task);
- check_link_down(vl);
- }
+ {
+ GNUNET_SCHEDULER_cancel (vl->visibility_task);
+ check_link_down (vl);
+ }
if (NULL == neighbour->queue_head)
- {
- free_neighbour(neighbour);
- }
+ {
+ free_neighbour (neighbour);
+ }
}
@@ -3570,24 +3620,24 @@ free_queue(struct Queue *queue)
* @param ale address list entry to free
*/
static void
-free_address_list_entry(struct AddressListEntry *ale)
+free_address_list_entry (struct AddressListEntry *ale)
{
struct TransportClient *tc = ale->tc;
- GNUNET_CONTAINER_DLL_remove(tc->details.communicator.addr_head,
- tc->details.communicator.addr_tail,
- ale);
+ GNUNET_CONTAINER_DLL_remove (tc->details.communicator.addr_head,
+ tc->details.communicator.addr_tail,
+ ale);
if (NULL != ale->sc)
- {
- GNUNET_PEERSTORE_store_cancel(ale->sc);
- ale->sc = NULL;
- }
+ {
+ GNUNET_PEERSTORE_store_cancel (ale->sc);
+ ale->sc = NULL;
+ }
if (NULL != ale->st)
- {
- GNUNET_SCHEDULER_cancel(ale->st);
- ale->st = NULL;
- }
- GNUNET_free(ale);
+ {
+ GNUNET_SCHEDULER_cancel (ale->st);
+ ale->st = NULL;
+ }
+ GNUNET_free (ale);
}
@@ -3600,20 +3650,20 @@ free_address_list_entry(struct AddressListEntry *ale)
* @return #GNUNET_YES (always)
*/
static int
-stop_peer_request(void *cls,
- const struct GNUNET_PeerIdentity *pid,
- void *value)
+stop_peer_request (void *cls,
+ const struct GNUNET_PeerIdentity *pid,
+ void *value)
{
struct TransportClient *tc = cls;
struct PeerRequest *pr = value;
- GNUNET_PEERSTORE_watch_cancel(pr->wc);
- GNUNET_assert(
+ GNUNET_PEERSTORE_watch_cancel (pr->wc);
+ GNUNET_assert (
GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove(tc->details.application.requests,
- pid,
- pr));
- GNUNET_free(pr);
+ GNUNET_CONTAINER_multipeermap_remove (tc->details.application.requests,
+ pid,
+ pr));
+ GNUNET_free (pr);
return GNUNET_OK;
}
@@ -3628,60 +3678,60 @@ stop_peer_request(void *cls,
* @param app_ctx our `struct TransportClient`
*/
static void
-client_disconnect_cb(void *cls,
- struct GNUNET_SERVICE_Client *client,
- void *app_ctx)
+client_disconnect_cb (void *cls,
+ struct GNUNET_SERVICE_Client *client,
+ void *app_ctx)
{
struct TransportClient *tc = app_ctx;
- (void)cls;
- (void)client;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Client %p disconnected, cleaning up.\n",
- tc);
- GNUNET_CONTAINER_DLL_remove(clients_head, clients_tail, tc);
+ (void) cls;
+ (void) client;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Client %p disconnected, cleaning up.\n",
+ tc);
+ GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc);
switch (tc->type)
- {
- case CT_NONE:
- break;
+ {
+ case CT_NONE:
+ break;
- case CT_CORE: {
+ case CT_CORE: {
struct PendingMessage *pm;
while (NULL != (pm = tc->details.core.pending_msg_head))
- {
- GNUNET_CONTAINER_MDLL_remove(client,
- tc->details.core.pending_msg_head,
- tc->details.core.pending_msg_tail,
- pm);
- pm->client = NULL;
- }
+ {
+ GNUNET_CONTAINER_MDLL_remove (client,
+ tc->details.core.pending_msg_head,
+ tc->details.core.pending_msg_tail,
+ pm);
+ pm->client = NULL;
+ }
}
break;
- case CT_MONITOR:
- break;
+ case CT_MONITOR:
+ break;
- case CT_COMMUNICATOR: {
+ case CT_COMMUNICATOR: {
struct Queue *q;
struct AddressListEntry *ale;
while (NULL != (q = tc->details.communicator.queue_head))
- free_queue(q);
+ free_queue (q);
while (NULL != (ale = tc->details.communicator.addr_head))
- free_address_list_entry(ale);
- GNUNET_free(tc->details.communicator.address_prefix);
+ free_address_list_entry (ale);
+ GNUNET_free (tc->details.communicator.address_prefix);
}
break;
- case CT_APPLICATION:
- GNUNET_CONTAINER_multipeermap_iterate(tc->details.application.requests,
- &stop_peer_request,
- tc);
- GNUNET_CONTAINER_multipeermap_destroy(tc->details.application.requests);
- break;
- }
- GNUNET_free(tc);
+ case CT_APPLICATION:
+ GNUNET_CONTAINER_multipeermap_iterate (tc->details.application.requests,
+ &stop_peer_request,
+ tc);
+ GNUNET_CONTAINER_multipeermap_destroy (tc->details.application.requests);
+ break;
+ }
+ GNUNET_free (tc);
}
@@ -3695,17 +3745,17 @@ client_disconnect_cb(void *cls,
* @return #GNUNET_OK (continue to iterate)
*/
static int
-notify_client_connect_info(void *cls,
- const struct GNUNET_PeerIdentity *pid,
- void *value)
+notify_client_connect_info (void *cls,
+ const struct GNUNET_PeerIdentity *pid,
+ void *value)
{
struct TransportClient *tc = cls;
- (void)value;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Telling new CORE client about existing connection to %s\n",
- GNUNET_i2s(pid));
- core_send_connect_info(tc, pid);
+ (void) value;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Telling new CORE client about existing connection to %s\n",
+ GNUNET_i2s (pid));
+ core_send_connect_info (tc, pid);
return GNUNET_OK;
}
@@ -3719,34 +3769,34 @@ notify_client_connect_info(void *cls,
* @param start the start message that was sent
*/
static void
-handle_client_start(void *cls, const struct StartMessage *start)
+handle_client_start (void *cls, const struct StartMessage *start)
{
struct TransportClient *tc = cls;
uint32_t options;
- options = ntohl(start->options);
+ options = ntohl (start->options);
if ((0 != (1 & options)) &&
- (0 != GNUNET_memcmp(&start->self, &GST_my_identity)))
- {
- /* client thinks this is a different peer, reject */
- GNUNET_break(0);
- GNUNET_SERVICE_client_drop(tc->client);
- return;
- }
+ (0 != GNUNET_memcmp (&start->self, &GST_my_identity)))
+ {
+ /* client thinks this is a different peer, reject */
+ GNUNET_break (0);
+ GNUNET_SERVICE_client_drop (tc->client);
+ return;
+ }
if (CT_NONE != tc->type)
- {
- GNUNET_break(0);
- GNUNET_SERVICE_client_drop(tc->client);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVICE_client_drop (tc->client);
+ return;
+ }
tc->type = CT_CORE;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "New CORE client with PID %s registered\n",
- GNUNET_i2s(&start->self));
- GNUNET_CONTAINER_multipeermap_iterate(neighbours,
- &notify_client_connect_info,
- tc);
- GNUNET_SERVICE_client_continue(tc->client);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "New CORE client with PID %s registered\n",
+ GNUNET_i2s (&start->self));
+ GNUNET_CONTAINER_multipeermap_iterate (neighbours,
+ &notify_client_connect_info,
+ tc);
+ GNUNET_SERVICE_client_continue (tc->client);
}
@@ -3757,29 +3807,29 @@ handle_client_start(void *cls, const struct StartMessage *start)
* @param obm the send message that was sent
*/
static int
-check_client_send(void *cls, const struct OutboundMessage *obm)
+check_client_send (void *cls, const struct OutboundMessage *obm)
{
struct TransportClient *tc = cls;
uint16_t size;
const struct GNUNET_MessageHeader *obmm;
if (CT_CORE != tc->type)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- size = ntohs(obm->header.size) - sizeof(struct OutboundMessage);
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ size = ntohs (obm->header.size) - sizeof(struct OutboundMessage);
if (size < sizeof(struct GNUNET_MessageHeader))
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- obmm = (const struct GNUNET_MessageHeader *)&obm[1];
- if (size != ntohs(obmm->size))
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ obmm = (const struct GNUNET_MessageHeader *) &obm[1];
+ if (size != ntohs (obmm->size))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -3792,25 +3842,25 @@ check_client_send(void *cls, const struct OutboundMessage *obm)
* @param pm handle to the original pending message
*/
static void
-client_send_response(struct PendingMessage *pm)
+client_send_response (struct PendingMessage *pm)
{
struct TransportClient *tc = pm->client;
struct VirtualLink *vl = pm->vl;
if (NULL != tc)
- {
- struct GNUNET_MQ_Envelope *env;
- struct SendOkMessage *som;
-
- env = GNUNET_MQ_msg(som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
- som->peer = vl->target;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Confirming transmission of <%llu> to %s\n",
- pm->logging_uuid,
- GNUNET_i2s(&vl->target));
- GNUNET_MQ_send(tc->mq, env);
- }
- free_pending_message(pm);
+ {
+ struct GNUNET_MQ_Envelope *env;
+ struct SendOkMessage *som;
+
+ env = GNUNET_MQ_msg (som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
+ som->peer = vl->target;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Confirming transmission of <%llu> to %s\n",
+ pm->logging_uuid,
+ GNUNET_i2s (&vl->target));
+ GNUNET_MQ_send (tc->mq, env);
+ }
+ free_pending_message (pm);
}
@@ -3824,10 +3874,10 @@ client_send_response(struct PendingMessage *pm)
* @return number of entries set in @a hops_array
*/
static unsigned int
-pick_random_dv_hops(const struct DistanceVector *dv,
- enum RouteMessageOptions options,
- struct DistanceVectorHop **hops_array,
- unsigned int hops_array_length)
+pick_random_dv_hops (const struct DistanceVector *dv,
+ enum RouteMessageOptions options,
+ struct DistanceVectorHop **hops_array,
+ unsigned int hops_array_length)
{
uint64_t choices[hops_array_length];
uint64_t num_dv;
@@ -3839,56 +3889,56 @@ pick_random_dv_hops(const struct DistanceVector *dv,
dv_count = 0;
for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
pos = pos->next_dv)
- {
- if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) &&
- (GNUNET_TIME_absolute_get_remaining(pos->path_valid_until)
- .rel_value_us == 0))
- continue; /* pos unconfirmed and confirmed required */
- num_dv += MAX_DV_HOPS_ALLOWED - pos->distance;
- dv_count++;
- }
+ {
+ if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) &&
+ (GNUNET_TIME_absolute_get_remaining (pos->path_valid_until)
+ .rel_value_us == 0))
+ continue; /* pos unconfirmed and confirmed required */
+ num_dv += MAX_DV_HOPS_ALLOWED - pos->distance;
+ dv_count++;
+ }
if (0 == dv_count)
return 0;
if (dv_count <= hops_array_length)
- {
- dv_count = 0;
- for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
- pos = pos->next_dv)
- hops_array[dv_count++] = pos;
- return dv_count;
- }
+ {
+ dv_count = 0;
+ for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
+ pos = pos->next_dv)
+ hops_array[dv_count++] = pos;
+ return dv_count;
+ }
for (unsigned int i = 0; i < hops_array_length; i++)
- {
- int ok = GNUNET_NO;
- while (GNUNET_NO == ok)
+ {
+ int ok = GNUNET_NO;
+ while (GNUNET_NO == ok)
+ {
+ choices[i] =
+ GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, num_dv);
+ ok = GNUNET_YES;
+ for (unsigned int j = 0; j < i; j++)
+ if (choices[i] == choices[j])
{
- choices[i] =
- GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, num_dv);
- ok = GNUNET_YES;
- for (unsigned int j = 0; j < i; j++)
- if (choices[i] == choices[j])
- {
- ok = GNUNET_NO;
- break;
- }
+ ok = GNUNET_NO;
+ break;
}
}
+ }
dv_count = 0;
num_dv = 0;
for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
pos = pos->next_dv)
- {
- uint32_t delta = MAX_DV_HOPS_ALLOWED - pos->distance;
-
- if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) &&
- (GNUNET_TIME_absolute_get_remaining(pos->path_valid_until)
- .rel_value_us == 0))
- continue; /* pos unconfirmed and confirmed required */
- for (unsigned int i = 0; i < hops_array_length; i++)
- if ((num_dv <= choices[i]) && (num_dv + delta > choices[i]))
- hops_array[dv_count++] = pos;
- num_dv += delta;
- }
+ {
+ uint32_t delta = MAX_DV_HOPS_ALLOWED - pos->distance;
+
+ if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) &&
+ (GNUNET_TIME_absolute_get_remaining (pos->path_valid_until)
+ .rel_value_us == 0))
+ continue; /* pos unconfirmed and confirmed required */
+ for (unsigned int i = 0; i < hops_array_length; i++)
+ if ((num_dv <= choices[i]) && (num_dv + delta > choices[i]))
+ hops_array[dv_count++] = pos;
+ num_dv += delta;
+ }
return dv_count;
}
@@ -3900,7 +3950,7 @@ pick_random_dv_hops(const struct DistanceVector *dv,
* @param cam the send message that was sent
*/
static int
-check_communicator_available(
+check_communicator_available (
void *cls,
const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam)
{
@@ -3908,15 +3958,15 @@ check_communicator_available(
uint16_t size;
if (CT_NONE != tc->type)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
tc->type = CT_COMMUNICATOR;
- size = ntohs(cam->header.size) - sizeof(*cam);
+ size = ntohs (cam->header.size) - sizeof(*cam);
if (0 == size)
return GNUNET_OK; /* receive-only communicator */
- GNUNET_MQ_check_zero_termination(cam);
+ GNUNET_MQ_check_zero_termination (cam);
return GNUNET_OK;
}
@@ -3927,22 +3977,22 @@ check_communicator_available(
* @param cmc context for which we are done handling the message
*/
static void
-finish_cmc_handling(struct CommunicatorMessageContext *cmc)
+finish_cmc_handling (struct CommunicatorMessageContext *cmc)
{
- if (0 != ntohl(cmc->im.fc_on))
- {
- /* send ACK when done to communicator for flow control! */
- struct GNUNET_MQ_Envelope *env;
- struct GNUNET_TRANSPORT_IncomingMessageAck *ack;
-
- env = GNUNET_MQ_msg(ack, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK);
- ack->reserved = htonl(0);
- ack->fc_id = cmc->im.fc_id;
- ack->sender = cmc->im.sender;
- GNUNET_MQ_send(cmc->tc->mq, env);
- }
- GNUNET_SERVICE_client_continue(cmc->tc->client);
- GNUNET_free(cmc);
+ if (0 != ntohl (cmc->im.fc_on))
+ {
+ /* send ACK when done to communicator for flow control! */
+ struct GNUNET_MQ_Envelope *env;
+ struct GNUNET_TRANSPORT_IncomingMessageAck *ack;
+
+ env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK);
+ ack->reserved = htonl (0);
+ ack->fc_id = cmc->im.fc_id;
+ ack->sender = cmc->im.sender;
+ GNUNET_MQ_send (cmc->tc->mq, env);
+ }
+ GNUNET_SERVICE_client_continue (cmc->tc->client);
+ GNUNET_free (cmc);
}
@@ -3956,7 +4006,7 @@ finish_cmc_handling(struct CommunicatorMessageContext *cmc)
* @param rom the message that was sent
*/
static void
-handle_client_recv_ok(void *cls, const struct RecvOkMessage *rom)
+handle_client_recv_ok (void *cls, const struct RecvOkMessage *rom)
{
struct TransportClient *tc = cls;
struct VirtualLink *vl;
@@ -3964,31 +4014,31 @@ handle_client_recv_ok(void *cls, const struct RecvOkMessage *rom)
struct CommunicatorMessageContext *cmc;
if (CT_CORE != tc->type)
- {
- GNUNET_break(0);
- GNUNET_SERVICE_client_drop(tc->client);
- return;
- }
- vl = lookup_virtual_link(&rom->peer);
+ {
+ GNUNET_break (0);
+ GNUNET_SERVICE_client_drop (tc->client);
+ return;
+ }
+ vl = lookup_virtual_link (&rom->peer);
if (NULL == vl)
- {
- GNUNET_STATISTICS_update(GST_stats,
- "# RECV_OK dropped: virtual link unknown",
- 1,
- GNUNET_NO);
- GNUNET_SERVICE_client_continue(tc->client);
- return;
- }
- delta = ntohl(rom->increase_window_delta);
+ {
+ GNUNET_STATISTICS_update (GST_stats,
+ "# RECV_OK dropped: virtual link unknown",
+ 1,
+ GNUNET_NO);
+ GNUNET_SERVICE_client_continue (tc->client);
+ return;
+ }
+ delta = ntohl (rom->increase_window_delta);
vl->core_recv_window += delta;
if (vl->core_recv_window <= 0)
return;
/* resume communicators */
while (NULL != (cmc = vl->cmc_tail))
- {
- GNUNET_CONTAINER_DLL_remove(vl->cmc_head, vl->cmc_tail, cmc);
- finish_cmc_handling(cmc);
- }
+ {
+ GNUNET_CONTAINER_DLL_remove (vl->cmc_head, vl->cmc_tail, cmc);
+ finish_cmc_handling (cmc);
+ }
}
@@ -3999,28 +4049,28 @@ handle_client_recv_ok(void *cls, const struct RecvOkMessage *rom)
* @param cam the send message that was sent
*/
static void
-handle_communicator_available(
+handle_communicator_available (
void *cls,
const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam)
{
struct TransportClient *tc = cls;
uint16_t size;
- size = ntohs(cam->header.size) - sizeof(*cam);
+ size = ntohs (cam->header.size) - sizeof(*cam);
if (0 == size)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Receive-only communicator connected\n");
- return; /* receive-only communicator */
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Receive-only communicator connected\n");
+ return; /* receive-only communicator */
+ }
tc->details.communicator.address_prefix =
- GNUNET_strdup((const char *)&cam[1]);
+ GNUNET_strdup ((const char *) &cam[1]);
tc->details.communicator.cc =
- (enum GNUNET_TRANSPORT_CommunicatorCharacteristics)ntohl(cam->cc);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Communicator with prefix `%s' connected\n",
- tc->details.communicator.address_prefix);
- GNUNET_SERVICE_client_continue(tc->client);
+ (enum GNUNET_TRANSPORT_CommunicatorCharacteristics) ntohl (cam->cc);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Communicator with prefix `%s' connected\n",
+ tc->details.communicator.address_prefix);
+ GNUNET_SERVICE_client_continue (tc->client);
}
@@ -4032,7 +4082,7 @@ handle_communicator_available(
* @return #GNUNET_OK if message is well-formed
*/
static int
-check_communicator_backchannel(
+check_communicator_backchannel (
void *cls,
const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb)
{
@@ -4041,24 +4091,24 @@ check_communicator_backchannel(
uint16_t msize;
uint16_t isize;
- (void)cls;
- msize = ntohs(cb->header.size) - sizeof(*cb);
- inbox = (const struct GNUNET_MessageHeader *)&cb[1];
- isize = ntohs(inbox->size);
+ (void) cls;
+ msize = ntohs (cb->header.size) - sizeof(*cb);
+ inbox = (const struct GNUNET_MessageHeader *) &cb[1];
+ isize = ntohs (inbox->size);
if (isize >= msize)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- is = (const char *)inbox;
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ is = (const char *) inbox;
is += isize;
msize -= isize;
- GNUNET_assert(0 < msize);
+ GNUNET_assert (0 < msize);
if ('\0' != is[msize - 1])
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -4070,26 +4120,26 @@ check_communicator_backchannel(
* @param dv[in,out] virtual link to update ephemeral for
*/
static void
-update_ephemeral(struct DistanceVector *dv)
+update_ephemeral (struct DistanceVector *dv)
{
struct EphemeralConfirmationPS ec;
if (0 !=
- GNUNET_TIME_absolute_get_remaining(dv->ephemeral_validity).rel_value_us)
+ GNUNET_TIME_absolute_get_remaining (dv->ephemeral_validity).rel_value_us)
return;
- dv->monotime = GNUNET_TIME_absolute_get_monotonic(GST_cfg);
+ dv->monotime = GNUNET_TIME_absolute_get_monotonic (GST_cfg);
dv->ephemeral_validity =
- GNUNET_TIME_absolute_add(dv->monotime, EPHEMERAL_VALIDITY);
- GNUNET_assert(GNUNET_OK ==
- GNUNET_CRYPTO_ecdhe_key_create2(&dv->private_key));
- GNUNET_CRYPTO_ecdhe_key_get_public(&dv->private_key, &dv->ephemeral_key);
- ec.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL);
- ec.purpose.size = htonl(sizeof(ec));
+ GNUNET_TIME_absolute_add (dv->monotime, EPHEMERAL_VALIDITY);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CRYPTO_ecdhe_key_create2 (&dv->private_key));
+ GNUNET_CRYPTO_ecdhe_key_get_public (&dv->private_key, &dv->ephemeral_key);
+ ec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL);
+ ec.purpose.size = htonl (sizeof(ec));
ec.target = dv->target;
ec.ephemeral_key = dv->ephemeral_key;
- GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(GST_my_private_key,
- &ec.purpose,
- &dv->sender_sig));
+ GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key,
+ &ec.purpose,
+ &dv->sender_sig));
}
@@ -4103,45 +4153,45 @@ update_ephemeral(struct DistanceVector *dv)
* @param payload_size number of bytes in @a payload
*/
static void
-queue_send_msg(struct Queue *queue,
- struct PendingMessage *pm,
- const void *payload,
- size_t payload_size)
+queue_send_msg (struct Queue *queue,
+ struct PendingMessage *pm,
+ const void *payload,
+ size_t payload_size)
{
struct Neighbour *n = queue->neighbour;
struct GNUNET_TRANSPORT_SendMessageTo *smt;
struct GNUNET_MQ_Envelope *env;
queue->idle = GNUNET_NO;
- GNUNET_log(
+ GNUNET_log (
GNUNET_ERROR_TYPE_DEBUG,
"Queueing %u bytes of payload for transmission <%llu> on queue %llu to %s\n",
- (unsigned int)payload_size,
+ (unsigned int) payload_size,
(NULL == pm) ? 0 : pm->logging_uuid,
- (unsigned long long)queue->qid,
- GNUNET_i2s(&queue->neighbour->pid));
- env = GNUNET_MQ_msg_extra(smt,
- payload_size,
- GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG);
+ (unsigned long long) queue->qid,
+ GNUNET_i2s (&queue->neighbour->pid));
+ env = GNUNET_MQ_msg_extra (smt,
+ payload_size,
+ GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG);
smt->qid = queue->qid;
smt->mid = queue->mid_gen;
smt->receiver = n->pid;
- memcpy(&smt[1], payload, payload_size);
+ memcpy (&smt[1], payload, payload_size);
{
/* Pass the env to the communicator of queue for transmission. */
struct QueueEntry *qe;
- qe = GNUNET_new(struct QueueEntry);
+ qe = GNUNET_new (struct QueueEntry);
qe->mid = queue->mid_gen++;
qe->queue = queue;
if (NULL != pm)
- {
- qe->pm = pm;
- GNUNET_assert(NULL == pm->qe);
- pm->qe = qe;
- }
- GNUNET_CONTAINER_DLL_insert(queue->queue_head, queue->queue_tail, qe);
- GNUNET_assert(CT_COMMUNICATOR == queue->tc->type);
+ {
+ qe->pm = pm;
+ GNUNET_assert (NULL == pm->qe);
+ pm->qe = qe;
+ }
+ GNUNET_CONTAINER_DLL_insert (queue->queue_head, queue->queue_tail, qe);
+ GNUNET_assert (CT_COMMUNICATOR == queue->tc->type);
queue->queue_length++;
queue->tc->details.communicator.total_queue_length++;
if (COMMUNICATOR_TOTAL_QUEUE_LIMIT ==
@@ -4149,7 +4199,7 @@ queue_send_msg(struct Queue *queue,
queue->idle = GNUNET_NO;
if (QUEUE_LENGTH_LIMIT == queue->queue_length)
queue->idle = GNUNET_NO;
- GNUNET_MQ_send(queue->tc->mq, env);
+ GNUNET_MQ_send (queue->tc->mq, env);
}
}
@@ -4165,9 +4215,9 @@ queue_send_msg(struct Queue *queue,
* @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed
*/
static struct GNUNET_TIME_Relative
-route_via_neighbour(const struct Neighbour *n,
- const struct GNUNET_MessageHeader *hdr,
- enum RouteMessageOptions options)
+route_via_neighbour (const struct Neighbour *n,
+ const struct GNUNET_MessageHeader *hdr,
+ enum RouteMessageOptions options)
{
struct GNUNET_TIME_Absolute now;
unsigned int candidates;
@@ -4176,7 +4226,7 @@ route_via_neighbour(const struct Neighbour *n,
struct GNUNET_TIME_Relative rtt;
/* Pick one or two 'random' queues from n (under constraints of options) */
- now = GNUNET_TIME_absolute_get();
+ now = GNUNET_TIME_absolute_get ();
/* FIXME-OPTIMIZE: give queues 'weights' and pick proportional to
weight in the future; weight could be assigned by observed
bandwidth (note: not sure if we should do this for this type
@@ -4184,53 +4234,53 @@ route_via_neighbour(const struct Neighbour *n,
candidates = 0;
for (struct Queue *pos = n->queue_head; NULL != pos;
pos = pos->next_neighbour)
- {
- if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) ||
- (pos->validated_until.abs_value_us > now.abs_value_us))
- candidates++;
- }
+ {
+ if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) ||
+ (pos->validated_until.abs_value_us > now.abs_value_us))
+ candidates++;
+ }
if (0 == candidates)
- {
- /* This can happen rarely if the last confirmed queue timed
- out just as we were beginning to process this message. */
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Could not route message of type %u to %s: no valid queue\n",
- ntohs(hdr->type),
- GNUNET_i2s(&n->pid));
- GNUNET_STATISTICS_update(GST_stats,
- "# route selection failed (all no valid queue)",
- 1,
- GNUNET_NO);
- return GNUNET_TIME_UNIT_FOREVER_REL;
- }
+ {
+ /* This can happen rarely if the last confirmed queue timed
+ out just as we were beginning to process this message. */
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Could not route message of type %u to %s: no valid queue\n",
+ ntohs (hdr->type),
+ GNUNET_i2s (&n->pid));
+ GNUNET_STATISTICS_update (GST_stats,
+ "# route selection failed (all no valid queue)",
+ 1,
+ GNUNET_NO);
+ return GNUNET_TIME_UNIT_FOREVER_REL;
+ }
rtt = GNUNET_TIME_UNIT_FOREVER_REL;
- sel1 = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, candidates);
+ sel1 = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, candidates);
if (0 == (options & RMO_REDUNDANT))
sel2 = candidates; /* picks none! */
else
- sel2 = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, candidates);
+ sel2 = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, candidates);
candidates = 0;
for (struct Queue *pos = n->queue_head; NULL != pos;
pos = pos->next_neighbour)
+ {
+ if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) ||
+ (pos->validated_until.abs_value_us > now.abs_value_us))
{
- if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) ||
- (pos->validated_until.abs_value_us > now.abs_value_us))
- {
- if ((sel1 == candidates) || (sel2 == candidates))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Routing message of type %u to %s using %s (#%u)\n",
- ntohs(hdr->type),
- GNUNET_i2s(&n->pid),
- pos->address,
- (sel1 == candidates) ? 1 : 2);
- rtt = GNUNET_TIME_relative_min(rtt, pos->pd.aged_rtt);
- queue_send_msg(pos, NULL, hdr, ntohs(hdr->size));
- }
- candidates++;
- }
+ if ((sel1 == candidates) || (sel2 == candidates))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Routing message of type %u to %s using %s (#%u)\n",
+ ntohs (hdr->type),
+ GNUNET_i2s (&n->pid),
+ pos->address,
+ (sel1 == candidates) ? 1 : 2);
+ rtt = GNUNET_TIME_relative_min (rtt, pos->pd.aged_rtt);
+ queue_send_msg (pos, NULL, hdr, ntohs (hdr->size));
+ }
+ candidates++;
}
+ }
return rtt;
}
@@ -4238,7 +4288,8 @@ route_via_neighbour(const struct Neighbour *n,
/**
* Structure of the key material used to encrypt backchannel messages.
*/
-struct DVKeyState {
+struct DVKeyState
+{
/**
* State of our block cipher.
*/
@@ -4247,7 +4298,8 @@ struct DVKeyState {
/**
* Actual key material.
*/
- struct {
+ struct
+ {
/**
* Key used for HMAC calculations (via #GNUNET_CRYPTO_hmac()).
*/
@@ -4275,34 +4327,34 @@ struct DVKeyState {
* @param key[out] symmetric cipher and HMAC state to generate
*/
static void
-dv_setup_key_state_from_km(const struct GNUNET_HashCode *km,
- const struct GNUNET_ShortHashCode *iv,
- struct DVKeyState *key)
+dv_setup_key_state_from_km (const struct GNUNET_HashCode *km,
+ const struct GNUNET_ShortHashCode *iv,
+ struct DVKeyState *key)
{
/* must match #dh_key_derive_eph_pub */
- GNUNET_assert(GNUNET_YES ==
- GNUNET_CRYPTO_kdf(&key->material,
- sizeof(key->material),
- "transport-backchannel-key",
- strlen("transport-backchannel-key"),
- &km,
- sizeof(km),
- iv,
- sizeof(*iv)));
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Deriving backchannel key based on KM %s and IV %s\n",
- GNUNET_h2s(km),
- GNUNET_sh2s(iv));
- gcry_cipher_open(&key->cipher,
- GCRY_CIPHER_AES256 /* low level: go for speed */,
- GCRY_CIPHER_MODE_CTR,
- 0 /* flags */);
- gcry_cipher_setkey(key->cipher,
- &key->material.aes_key,
- sizeof(key->material.aes_key));
- gcry_cipher_setctr(key->cipher,
- &key->material.aes_ctr,
- sizeof(key->material.aes_ctr));
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CRYPTO_kdf (&key->material,
+ sizeof(key->material),
+ "transport-backchannel-key",
+ strlen ("transport-backchannel-key"),
+ &km,
+ sizeof(km),
+ iv,
+ sizeof(*iv)));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Deriving backchannel key based on KM %s and IV %s\n",
+ GNUNET_h2s (km),
+ GNUNET_sh2s (iv));
+ gcry_cipher_open (&key->cipher,
+ GCRY_CIPHER_AES256 /* low level: go for speed */,
+ GCRY_CIPHER_MODE_CTR,
+ 0 /* flags */);
+ gcry_cipher_setkey (key->cipher,
+ &key->material.aes_key,
+ sizeof(key->material.aes_key));
+ gcry_cipher_setctr (key->cipher,
+ &key->material.aes_ctr,
+ sizeof(key->material.aes_ctr));
}
@@ -4316,7 +4368,7 @@ dv_setup_key_state_from_km(const struct GNUNET_HashCode *km,
* @param key[out] set to the key material
*/
static void
-dh_key_derive_eph_pid(
+dh_key_derive_eph_pid (
const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ephemeral,
const struct GNUNET_PeerIdentity *target,
const struct GNUNET_ShortHashCode *iv,
@@ -4324,10 +4376,10 @@ dh_key_derive_eph_pid(
{
struct GNUNET_HashCode km;
- GNUNET_assert(GNUNET_YES == GNUNET_CRYPTO_ecdh_eddsa(priv_ephemeral,
- &target->public_key,
- &km));
- dv_setup_key_state_from_km(&km, iv, key);
+ GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_ecdh_eddsa (priv_ephemeral,
+ &target->public_key,
+ &km));
+ dv_setup_key_state_from_km (&km, iv, key);
}
@@ -4341,16 +4393,16 @@ dh_key_derive_eph_pid(
* @param key[out] set to the key material
*/
static void
-dh_key_derive_eph_pub(const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral,
- const struct GNUNET_ShortHashCode *iv,
- struct DVKeyState *key)
+dh_key_derive_eph_pub (const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral,
+ const struct GNUNET_ShortHashCode *iv,
+ struct DVKeyState *key)
{
struct GNUNET_HashCode km;
- GNUNET_assert(GNUNET_YES == GNUNET_CRYPTO_eddsa_ecdh(GST_my_private_key,
- pub_ephemeral,
- &km));
- dv_setup_key_state_from_km(&km, iv, key);
+ GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_eddsa_ecdh (GST_my_private_key,
+ pub_ephemeral,
+ &km));
+ dv_setup_key_state_from_km (&km, iv, key);
}
@@ -4364,12 +4416,12 @@ dh_key_derive_eph_pub(const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral,
* @param data_size number of bytes in @a data
*/
static void
-dv_hmac(const struct DVKeyState *key,
- struct GNUNET_HashCode *hmac,
- const void *data,
- size_t data_size)
+dv_hmac (const struct DVKeyState *key,
+ struct GNUNET_HashCode *hmac,
+ const void *data,
+ size_t data_size)
{
- GNUNET_CRYPTO_hmac(&key->material.hmac_key, data, data_size, hmac);
+ GNUNET_CRYPTO_hmac (&key->material.hmac_key, data, data_size, hmac);
}
@@ -4383,10 +4435,10 @@ dv_hmac(const struct DVKeyState *key,
* @param in_size number of bytes of input in @a in and available at @a dst
*/
static void
-dv_encrypt(struct DVKeyState *key, const void *in, void *dst, size_t in_size)
+dv_encrypt (struct DVKeyState *key, const void *in, void *dst, size_t in_size)
{
- GNUNET_assert(0 ==
- gcry_cipher_encrypt(key->cipher, dst, in_size, in, in_size));
+ GNUNET_assert (0 ==
+ gcry_cipher_encrypt (key->cipher, dst, in_size, in, in_size));
}
@@ -4400,13 +4452,13 @@ dv_encrypt(struct DVKeyState *key, const void *in, void *dst, size_t in_size)
* @param out_size number of bytes of input in @a ciph and available in @a out
*/
static void
-dv_decrypt(struct DVKeyState *key,
- void *out,
- const void *ciph,
- size_t out_size)
+dv_decrypt (struct DVKeyState *key,
+ void *out,
+ const void *ciph,
+ size_t out_size)
{
- GNUNET_assert(
- 0 == gcry_cipher_decrypt(key->cipher, out, out_size, ciph, out_size));
+ GNUNET_assert (
+ 0 == gcry_cipher_decrypt (key->cipher, out, out_size, ciph, out_size));
}
@@ -4416,10 +4468,10 @@ dv_decrypt(struct DVKeyState *key,
* @param key key material to clean up (memory must not be free'd!)
*/
static void
-dv_key_clean(struct DVKeyState *key)
+dv_key_clean (struct DVKeyState *key)
{
- gcry_cipher_close(key->cipher);
- GNUNET_CRYPTO_zero_keys(&key->material, sizeof(key->material));
+ gcry_cipher_close (key->cipher);
+ GNUNET_CRYPTO_zero_keys (&key->material, sizeof(key->material));
}
@@ -4452,92 +4504,92 @@ typedef void (*DVMessageHandler) (void *cls,
* @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed
*/
static struct GNUNET_TIME_Relative
-encapsulate_for_dv(struct DistanceVector *dv,
- unsigned int num_dvhs,
- struct DistanceVectorHop **dvhs,
- const struct GNUNET_MessageHeader *hdr,
- DVMessageHandler use,
- void *use_cls,
- enum RouteMessageOptions options)
+encapsulate_for_dv (struct DistanceVector *dv,
+ unsigned int num_dvhs,
+ struct DistanceVectorHop **dvhs,
+ const struct GNUNET_MessageHeader *hdr,
+ DVMessageHandler use,
+ void *use_cls,
+ enum RouteMessageOptions options)
{
struct TransportDVBoxMessage box_hdr;
struct TransportDVBoxPayloadP payload_hdr;
- uint16_t enc_body_size = ntohs(hdr->size);
+ uint16_t enc_body_size = ntohs (hdr->size);
char enc[sizeof(struct TransportDVBoxPayloadP) + enc_body_size] GNUNET_ALIGN;
struct TransportDVBoxPayloadP *enc_payload_hdr =
- (struct TransportDVBoxPayloadP *)enc;
+ (struct TransportDVBoxPayloadP *) enc;
struct DVKeyState key;
struct GNUNET_TIME_Relative rtt;
/* Encrypt payload */
- box_hdr.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX);
- box_hdr.total_hops = htons(0);
- update_ephemeral(dv);
+ box_hdr.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX);
+ box_hdr.total_hops = htons (0);
+ update_ephemeral (dv);
box_hdr.ephemeral_key = dv->ephemeral_key;
payload_hdr.sender_sig = dv->sender_sig;
- GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE,
- &box_hdr.iv,
- sizeof(box_hdr.iv));
- dh_key_derive_eph_pid(&dv->private_key, &dv->target, &box_hdr.iv, &key);
+ GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE,
+ &box_hdr.iv,
+ sizeof(box_hdr.iv));
+ dh_key_derive_eph_pid (&dv->private_key, &dv->target, &box_hdr.iv, &key);
payload_hdr.sender = GST_my_identity;
- payload_hdr.monotonic_time = GNUNET_TIME_absolute_hton(dv->monotime);
- dv_encrypt(&key, &payload_hdr, enc_payload_hdr, sizeof(payload_hdr));
- dv_encrypt(&key,
- hdr,
- &enc[sizeof(struct TransportDVBoxPayloadP)],
- enc_body_size);
- dv_hmac(&key, &box_hdr.hmac, enc, sizeof(enc));
- dv_key_clean(&key);
+ payload_hdr.monotonic_time = GNUNET_TIME_absolute_hton (dv->monotime);
+ dv_encrypt (&key, &payload_hdr, enc_payload_hdr, sizeof(payload_hdr));
+ dv_encrypt (&key,
+ hdr,
+ &enc[sizeof(struct TransportDVBoxPayloadP)],
+ enc_body_size);
+ dv_hmac (&key, &box_hdr.hmac, enc, sizeof(enc));
+ dv_key_clean (&key);
rtt = GNUNET_TIME_UNIT_FOREVER_REL;
/* For each selected path, take the pre-computed header and body
and add the path in the middle of the message; then send it. */
for (unsigned int i = 0; i < num_dvhs; i++)
+ {
+ struct DistanceVectorHop *dvh = dvhs[i];
+ unsigned int num_hops = dvh->distance + 1;
+ char buf[sizeof(struct TransportDVBoxMessage)
+ + sizeof(struct GNUNET_PeerIdentity) * num_hops
+ + sizeof(struct TransportDVBoxPayloadP)
+ + enc_body_size] GNUNET_ALIGN;
+ struct GNUNET_PeerIdentity *dhops;
+
+ box_hdr.header.size = htons (sizeof(buf));
+ box_hdr.num_hops = htons (num_hops);
+ memcpy (buf, &box_hdr, sizeof(box_hdr));
+ dhops = (struct GNUNET_PeerIdentity *) &buf[sizeof(box_hdr)];
+ memcpy (dhops,
+ dvh->path,
+ dvh->distance * sizeof(struct GNUNET_PeerIdentity));
+ dhops[dvh->distance] = dv->target;
+ if (GNUNET_EXTRA_LOGGING > 0)
{
- struct DistanceVectorHop *dvh = dvhs[i];
- unsigned int num_hops = dvh->distance + 1;
- char buf[sizeof(struct TransportDVBoxMessage) +
- sizeof(struct GNUNET_PeerIdentity) * num_hops +
- sizeof(struct TransportDVBoxPayloadP) +
- enc_body_size] GNUNET_ALIGN;
- struct GNUNET_PeerIdentity *dhops;
-
- box_hdr.header.size = htons(sizeof(buf));
- box_hdr.num_hops = htons(num_hops);
- memcpy(buf, &box_hdr, sizeof(box_hdr));
- dhops = (struct GNUNET_PeerIdentity *)&buf[sizeof(box_hdr)];
- memcpy(dhops,
- dvh->path,
- dvh->distance * sizeof(struct GNUNET_PeerIdentity));
- dhops[dvh->distance] = dv->target;
- if (GNUNET_EXTRA_LOGGING > 0)
- {
- char *path;
-
- path = GNUNET_strdup(GNUNET_i2s(&GST_my_identity));
- for (unsigned int j = 0; j <= num_hops; j++)
- {
- char *tmp;
-
- GNUNET_asprintf(&tmp, "%s-%s", path, GNUNET_i2s(&dhops[j]));
- GNUNET_free(path);
- path = tmp;
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Routing message of type %u to %s using DV (#%u/%u) via %s\n",
- ntohs(hdr->type),
- GNUNET_i2s(&dv->target),
- i + 1,
- num_dvhs + 1,
- path);
- GNUNET_free(path);
- }
- rtt = GNUNET_TIME_relative_min(rtt, dvh->pd.aged_rtt);
- memcpy(&dhops[num_hops], enc, sizeof(enc));
- use(use_cls,
- dvh->next_hop,
- (const struct GNUNET_MessageHeader *)buf,
- options);
- }
+ char *path;
+
+ path = GNUNET_strdup (GNUNET_i2s (&GST_my_identity));
+ for (unsigned int j = 0; j <= num_hops; j++)
+ {
+ char *tmp;
+
+ GNUNET_asprintf (&tmp, "%s-%s", path, GNUNET_i2s (&dhops[j]));
+ GNUNET_free (path);
+ path = tmp;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Routing message of type %u to %s using DV (#%u/%u) via %s\n",
+ ntohs (hdr->type),
+ GNUNET_i2s (&dv->target),
+ i + 1,
+ num_dvhs + 1,
+ path);
+ GNUNET_free (path);
+ }
+ rtt = GNUNET_TIME_relative_min (rtt, dvh->pd.aged_rtt);
+ memcpy (&dhops[num_hops], enc, sizeof(enc));
+ use (use_cls,
+ dvh->next_hop,
+ (const struct GNUNET_MessageHeader *) buf,
+ options);
+ }
return rtt;
}
@@ -4552,13 +4604,13 @@ encapsulate_for_dv(struct DistanceVector *dv,
* @param options message options for queue selection
*/
static void
-send_dv_to_neighbour(void *cls,
- struct Neighbour *next_hop,
- const struct GNUNET_MessageHeader *hdr,
- enum RouteMessageOptions options)
+send_dv_to_neighbour (void *cls,
+ struct Neighbour *next_hop,
+ const struct GNUNET_MessageHeader *hdr,
+ enum RouteMessageOptions options)
{
- (void)cls;
- (void)route_via_neighbour(next_hop, hdr, options);
+ (void) cls;
+ (void) route_via_neighbour (next_hop, hdr, options);
}
@@ -4574,9 +4626,9 @@ send_dv_to_neighbour(void *cls,
* @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed
*/
static struct GNUNET_TIME_Relative
-route_control_message_without_fc(const struct GNUNET_PeerIdentity *target,
- const struct GNUNET_MessageHeader *hdr,
- enum RouteMessageOptions options)
+route_control_message_without_fc (const struct GNUNET_PeerIdentity *target,
+ const struct GNUNET_MessageHeader *hdr,
+ enum RouteMessageOptions options)
{
struct VirtualLink *vl;
struct Neighbour *n;
@@ -4584,78 +4636,78 @@ route_control_message_without_fc(const struct GNUNET_PeerIdentity *target,
struct GNUNET_TIME_Relative rtt1;
struct GNUNET_TIME_Relative rtt2;
- vl = lookup_virtual_link(target);
- GNUNET_assert(NULL != vl);
+ vl = lookup_virtual_link (target);
+ GNUNET_assert (NULL != vl);
n = vl->n;
dv = (0 != (options & RMO_DV_ALLOWED)) ? vl->dv : NULL;
if (0 == (options & RMO_UNCONFIRMED_ALLOWED))
- {
- /* if confirmed is required, and we do not have anything
- confirmed, drop respective options */
- if (NULL == n)
- n = lookup_neighbour(target);
- if ((NULL == dv) && (0 != (options & RMO_DV_ALLOWED)))
- dv = GNUNET_CONTAINER_multipeermap_get(dv_routes, target);
- }
+ {
+ /* if confirmed is required, and we do not have anything
+ confirmed, drop respective options */
+ if (NULL == n)
+ n = lookup_neighbour (target);
+ if ((NULL == dv) && (0 != (options & RMO_DV_ALLOWED)))
+ dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, target);
+ }
if ((NULL == n) && (NULL == dv))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Cannot route message of type %u to %s: no route\n",
- ntohs(hdr->type),
- GNUNET_i2s(target));
- GNUNET_STATISTICS_update(GST_stats,
- "# Messages dropped in routing: no acceptable method",
- 1,
- GNUNET_NO);
- return GNUNET_TIME_UNIT_FOREVER_REL;
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Routing message of type %u to %s with options %X\n",
- ntohs(hdr->type),
- GNUNET_i2s(target),
- (unsigned int)options);
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Cannot route message of type %u to %s: no route\n",
+ ntohs (hdr->type),
+ GNUNET_i2s (target));
+ GNUNET_STATISTICS_update (GST_stats,
+ "# Messages dropped in routing: no acceptable method",
+ 1,
+ GNUNET_NO);
+ return GNUNET_TIME_UNIT_FOREVER_REL;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Routing message of type %u to %s with options %X\n",
+ ntohs (hdr->type),
+ GNUNET_i2s (target),
+ (unsigned int) options);
/* If both dv and n are possible and we must choose:
flip a coin for the choice between the two; for now 50/50 */
if ((NULL != n) && (NULL != dv) && (0 == (options & RMO_REDUNDANT)))
- {
- if (0 == GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 2))
- n = NULL;
- else
- dv = NULL;
- }
+ {
+ if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2))
+ n = NULL;
+ else
+ dv = NULL;
+ }
if ((NULL != n) && (NULL != dv))
options &= ~RMO_REDUNDANT; /* We will do one DV and one direct, that's
enough for redunancy, so clear the flag. */
rtt1 = GNUNET_TIME_UNIT_FOREVER_REL;
rtt2 = GNUNET_TIME_UNIT_FOREVER_REL;
if (NULL != n)
- {
- rtt1 = route_via_neighbour(n, hdr, options);
- }
+ {
+ rtt1 = route_via_neighbour (n, hdr, options);
+ }
if (NULL != dv)
- {
- struct DistanceVectorHop *hops[2];
- unsigned int res;
-
- res = pick_random_dv_hops(dv,
- options,
- hops,
- (0 == (options & RMO_REDUNDANT)) ? 1 : 2);
- if (0 == res)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Failed to route message, could not determine DV path\n");
- return rtt1;
- }
- rtt2 = encapsulate_for_dv(dv,
- res,
- hops,
- hdr,
- &send_dv_to_neighbour,
- NULL,
- options & (~RMO_REDUNDANT));
- }
- return GNUNET_TIME_relative_min(rtt1, rtt2);
+ {
+ struct DistanceVectorHop *hops[2];
+ unsigned int res;
+
+ res = pick_random_dv_hops (dv,
+ options,
+ hops,
+ (0 == (options & RMO_REDUNDANT)) ? 1 : 2);
+ if (0 == res)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Failed to route message, could not determine DV path\n");
+ return rtt1;
+ }
+ rtt2 = encapsulate_for_dv (dv,
+ res,
+ hops,
+ hdr,
+ &send_dv_to_neighbour,
+ NULL,
+ options & (~RMO_REDUNDANT));
+ }
+ return GNUNET_TIME_relative_min (rtt1, rtt2);
}
@@ -4666,7 +4718,7 @@ route_control_message_without_fc(const struct GNUNET_PeerIdentity *target,
* @param cls a `struct VirtualLink` to work with
*/
static void
-consider_sending_fc(void *cls)
+consider_sending_fc (void *cls)
{
struct VirtualLink *vl = cls;
struct GNUNET_TIME_Absolute monotime;
@@ -4674,7 +4726,7 @@ consider_sending_fc(void *cls)
struct GNUNET_TIME_Relative duration;
struct GNUNET_TIME_Relative rtt;
- duration = GNUNET_TIME_absolute_get_duration(vl->last_fc_transmission);
+ duration = GNUNET_TIME_absolute_get_duration (vl->last_fc_transmission);
/* OPTIMIZE-FC-BDP: decide sane criteria on when to do this, instead of doing
it always! */
/* For example, we should probably ONLY do this if a bit more than
@@ -4683,41 +4735,41 @@ consider_sending_fc(void *cls)
need an estimate for the bandwidth-delay-product for the entire
VL, as that determines "significantly". We have the delay, but
the bandwidth statistics need to be added for the VL!*/
- (void)duration;
-
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Sending FC seq %u to %s with new window %llu\n",
- (unsigned int)vl->fc_seq_gen,
- GNUNET_i2s(&vl->target),
- (unsigned long long)vl->incoming_fc_window_size);
- monotime = GNUNET_TIME_absolute_get_monotonic(GST_cfg);
+ (void) duration;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending FC seq %u to %s with new window %llu\n",
+ (unsigned int) vl->fc_seq_gen,
+ GNUNET_i2s (&vl->target),
+ (unsigned long long) vl->incoming_fc_window_size);
+ monotime = GNUNET_TIME_absolute_get_monotonic (GST_cfg);
vl->last_fc_transmission = monotime;
- fc.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL);
- fc.header.size = htons(sizeof(fc));
- fc.seq = htonl(vl->fc_seq_gen++);
- fc.inbound_window_size = GNUNET_htonll(vl->incoming_fc_window_size);
- fc.outbound_sent = GNUNET_htonll(vl->outbound_fc_window_size_used);
- fc.outbound_window_size = GNUNET_htonll(vl->outbound_fc_window_size);
- fc.sender_time = GNUNET_TIME_absolute_hton(monotime);
- rtt = route_control_message_without_fc(&vl->target, &fc.header, RMO_NONE);
+ fc.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL);
+ fc.header.size = htons (sizeof(fc));
+ fc.seq = htonl (vl->fc_seq_gen++);
+ fc.inbound_window_size = GNUNET_htonll (vl->incoming_fc_window_size);
+ fc.outbound_sent = GNUNET_htonll (vl->outbound_fc_window_size_used);
+ fc.outbound_window_size = GNUNET_htonll (vl->outbound_fc_window_size);
+ fc.sender_time = GNUNET_TIME_absolute_hton (monotime);
+ rtt = route_control_message_without_fc (&vl->target, &fc.header, RMO_NONE);
if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == rtt.rel_value_us)
- {
- rtt = GNUNET_TIME_UNIT_SECONDS;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "FC retransmission to %s failed, will retry in %s\n",
- GNUNET_i2s(&vl->target),
- GNUNET_STRINGS_relative_time_to_string(rtt, GNUNET_YES));
- vl->last_fc_rtt = GNUNET_TIME_UNIT_ZERO;
- }
+ {
+ rtt = GNUNET_TIME_UNIT_SECONDS;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "FC retransmission to %s failed, will retry in %s\n",
+ GNUNET_i2s (&vl->target),
+ GNUNET_STRINGS_relative_time_to_string (rtt, GNUNET_YES));
+ vl->last_fc_rtt = GNUNET_TIME_UNIT_ZERO;
+ }
else
- {
- /* OPTIMIZE-FC-BDP: rtt is not ideal, we can do better! */
- vl->last_fc_rtt = rtt;
- }
+ {
+ /* OPTIMIZE-FC-BDP: rtt is not ideal, we can do better! */
+ vl->last_fc_rtt = rtt;
+ }
if (NULL != vl->fc_retransmit_task)
- GNUNET_SCHEDULER_cancel(vl->fc_retransmit_task);
+ GNUNET_SCHEDULER_cancel (vl->fc_retransmit_task);
vl->fc_retransmit_task =
- GNUNET_SCHEDULER_add_delayed(rtt, &consider_sending_fc, vl);
+ GNUNET_SCHEDULER_add_delayed (rtt, &consider_sending_fc, vl);
}
@@ -4738,7 +4790,7 @@ consider_sending_fc(void *cls)
* @param vl virtual link where we should check for transmission
*/
static void
-check_vl_transmission(struct VirtualLink *vl)
+check_vl_transmission (struct VirtualLink *vl)
{
struct Neighbour *n = vl->n;
struct DistanceVector *dv = vl->dv;
@@ -4750,57 +4802,57 @@ check_vl_transmission(struct VirtualLink *vl)
elig = GNUNET_NO;
for (struct PendingMessage *pm = vl->pending_msg_head; NULL != pm;
pm = pm->next_vl)
- {
- if (NULL != pm->qe)
- continue; /* not eligible, is in a queue! */
- if (pm->bytes_msg + vl->outbound_fc_window_size_used >
- vl->outbound_fc_window_size)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Stalled transmision on VL %s due to flow control: %llu < %llu\n",
- GNUNET_i2s(&vl->target),
- (unsigned long long)vl->outbound_fc_window_size,
- (unsigned long long)(pm->bytes_msg +
- vl->outbound_fc_window_size_used));
- consider_sending_fc(vl);
- return; /* We have a message, but flow control says "nope" */
- }
- elig = GNUNET_YES;
- break;
- }
+ {
+ if (NULL != pm->qe)
+ continue; /* not eligible, is in a queue! */
+ if (pm->bytes_msg + vl->outbound_fc_window_size_used >
+ vl->outbound_fc_window_size)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Stalled transmision on VL %s due to flow control: %llu < %llu\n",
+ GNUNET_i2s (&vl->target),
+ (unsigned long long) vl->outbound_fc_window_size,
+ (unsigned long long) (pm->bytes_msg
+ + vl->outbound_fc_window_size_used));
+ consider_sending_fc (vl);
+ return; /* We have a message, but flow control says "nope" */
+ }
+ elig = GNUNET_YES;
+ break;
+ }
if (GNUNET_NO == elig)
return;
/* Notify queues at direct neighbours that we are interested */
- now = GNUNET_TIME_absolute_get();
+ now = GNUNET_TIME_absolute_get ();
if (NULL != n)
+ {
+ for (struct Queue *queue = n->queue_head; NULL != queue;
+ queue = queue->next_neighbour)
+ if ((GNUNET_YES == queue->idle) &&
+ (queue->validated_until.abs_value_us > now.abs_value_us))
+ schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
+ }
+ /* Notify queues via DV that we are interested */
+ if (NULL != dv)
+ {
+ /* Do DV with lower scheduler priority, which effectively means that
+ IF a neighbour exists and is available, we prefer it. */
+ for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
+ pos = pos->next_dv)
{
- for (struct Queue *queue = n->queue_head; NULL != queue;
+ struct Neighbour *nh = pos->next_hop;
+
+ if (pos->path_valid_until.abs_value_us <= now.abs_value_us)
+ continue; /* skip this one: path not validated */
+ for (struct Queue *queue = nh->queue_head; NULL != queue;
queue = queue->next_neighbour)
if ((GNUNET_YES == queue->idle) &&
(queue->validated_until.abs_value_us > now.abs_value_us))
- schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
- }
- /* Notify queues via DV that we are interested */
- if (NULL != dv)
- {
- /* Do DV with lower scheduler priority, which effectively means that
- IF a neighbour exists and is available, we prefer it. */
- for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
- pos = pos->next_dv)
- {
- struct Neighbour *nh = pos->next_hop;
-
- if (pos->path_valid_until.abs_value_us <= now.abs_value_us)
- continue; /* skip this one: path not validated */
- for (struct Queue *queue = nh->queue_head; NULL != queue;
- queue = queue->next_neighbour)
- if ((GNUNET_YES == queue->idle) &&
- (queue->validated_until.abs_value_us > now.abs_value_us))
- schedule_transmit_on_queue(queue,
- GNUNET_SCHEDULER_PRIORITY_BACKGROUND);
- }
+ schedule_transmit_on_queue (queue,
+ GNUNET_SCHEDULER_PRIORITY_BACKGROUND);
}
+ }
}
@@ -4811,7 +4863,7 @@ check_vl_transmission(struct VirtualLink *vl)
* @param obm the send message that was sent
*/
static void
-handle_client_send(void *cls, const struct OutboundMessage *obm)
+handle_client_send (void *cls, const struct OutboundMessage *obm)
{
struct TransportClient *tc = cls;
struct PendingMessage *pm;
@@ -4820,46 +4872,46 @@ handle_client_send(void *cls, const struct OutboundMessage *obm)
struct VirtualLink *vl;
enum GNUNET_MQ_PriorityPreferences pp;
- GNUNET_assert(CT_CORE == tc->type);
- obmm = (const struct GNUNET_MessageHeader *)&obm[1];
- bytes_msg = ntohs(obmm->size);
- pp = (enum GNUNET_MQ_PriorityPreferences)ntohl(obm->priority);
- vl = lookup_virtual_link(&obm->peer);
+ GNUNET_assert (CT_CORE == tc->type);
+ obmm = (const struct GNUNET_MessageHeader *) &obm[1];
+ bytes_msg = ntohs (obmm->size);
+ pp = (enum GNUNET_MQ_PriorityPreferences) ntohl (obm->priority);
+ vl = lookup_virtual_link (&obm->peer);
if (NULL == vl)
- {
- /* Failure: don't have this peer as a neighbour (anymore).
- Might have gone down asynchronously, so this is NOT
- a protocol violation by CORE. Still count the event,
- as this should be rare. */
- GNUNET_SERVICE_client_continue(tc->client);
- GNUNET_STATISTICS_update(GST_stats,
- "# messages dropped (neighbour unknown)",
- 1,
- GNUNET_NO);
- return;
- }
+ {
+ /* Failure: don't have this peer as a neighbour (anymore).
+ Might have gone down asynchronously, so this is NOT
+ a protocol violation by CORE. Still count the event,
+ as this should be rare. */
+ GNUNET_SERVICE_client_continue (tc->client);
+ GNUNET_STATISTICS_update (GST_stats,
+ "# messages dropped (neighbour unknown)",
+ 1,
+ GNUNET_NO);
+ return;
+ }
- pm = GNUNET_malloc(sizeof(struct PendingMessage) + bytes_msg);
+ pm = GNUNET_malloc (sizeof(struct PendingMessage) + bytes_msg);
pm->logging_uuid = logging_uuid_gen++;
pm->prefs = pp;
pm->client = tc;
pm->vl = vl;
pm->bytes_msg = bytes_msg;
- memcpy(&pm[1], obmm, bytes_msg);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Sending %u bytes as <%llu> to %s\n",
- bytes_msg,
- pm->logging_uuid,
- GNUNET_i2s(&obm->peer));
- GNUNET_CONTAINER_MDLL_insert(client,
- tc->details.core.pending_msg_head,
- tc->details.core.pending_msg_tail,
- pm);
- GNUNET_CONTAINER_MDLL_insert(vl,
- vl->pending_msg_head,
- vl->pending_msg_tail,
- pm);
- check_vl_transmission(vl);
+ memcpy (&pm[1], obmm, bytes_msg);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending %u bytes as <%llu> to %s\n",
+ bytes_msg,
+ pm->logging_uuid,
+ GNUNET_i2s (&obm->peer));
+ GNUNET_CONTAINER_MDLL_insert (client,
+ tc->details.core.pending_msg_head,
+ tc->details.core.pending_msg_tail,
+ pm);
+ GNUNET_CONTAINER_MDLL_insert (vl,
+ vl->pending_msg_head,
+ vl->pending_msg_tail,
+ pm);
+ check_vl_transmission (vl);
}
@@ -4873,39 +4925,40 @@ handle_client_send(void *cls, const struct OutboundMessage *obm)
* @param cb the send message that was sent
*/
static void
-handle_communicator_backchannel(
+handle_communicator_backchannel (
void *cls,
const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb)
{
struct TransportClient *tc = cls;
const struct GNUNET_MessageHeader *inbox =
- (const struct GNUNET_MessageHeader *)&cb[1];
- uint16_t isize = ntohs(inbox->size);
- const char *is = ((const char *)&cb[1]) + isize;
+ (const struct GNUNET_MessageHeader *) &cb[1];
+ uint16_t isize = ntohs (inbox->size);
+ const char *is = ((const char *) &cb[1]) + isize;
char
- mbuf[isize +
- sizeof(struct TransportBackchannelEncapsulationMessage)] GNUNET_ALIGN;
+ mbuf[isize
+ + sizeof(struct
+ TransportBackchannelEncapsulationMessage)] GNUNET_ALIGN;
struct TransportBackchannelEncapsulationMessage *be =
- (struct TransportBackchannelEncapsulationMessage *)mbuf;
+ (struct TransportBackchannelEncapsulationMessage *) mbuf;
/* 0-termination of 'is' was checked already in
#check_communicator_backchannel() */
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Preparing backchannel transmission to %s:%s of type %u\n",
- GNUNET_i2s(&cb->pid),
- is,
- ntohs(inbox->size));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Preparing backchannel transmission to %s:%s of type %u\n",
+ GNUNET_i2s (&cb->pid),
+ is,
+ ntohs (inbox->size));
/* encapsulate and encrypt message */
be->header.type =
- htons(GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION);
- be->header.size = htons(sizeof(mbuf));
- memcpy(&be[1], inbox, isize);
- memcpy(&mbuf[sizeof(struct TransportBackchannelEncapsulationMessage) +
- isize],
- is,
- strlen(is) + 1);
- route_control_message_without_fc(&cb->pid, &be->header, RMO_DV_ALLOWED);
- GNUNET_SERVICE_client_continue(tc->client);
+ htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION);
+ be->header.size = htons (sizeof(mbuf));
+ memcpy (&be[1], inbox, isize);
+ memcpy (&mbuf[sizeof(struct TransportBackchannelEncapsulationMessage)
+ + isize],
+ is,
+ strlen (is) + 1);
+ route_control_message_without_fc (&cb->pid, &be->header, RMO_DV_ALLOWED);
+ GNUNET_SERVICE_client_continue (tc->client);
}
@@ -4917,17 +4970,17 @@ handle_communicator_backchannel(
* @return #GNUNET_OK if message is well-formed
*/
static int
-check_add_address(void *cls,
- const struct GNUNET_TRANSPORT_AddAddressMessage *aam)
+check_add_address (void *cls,
+ const struct GNUNET_TRANSPORT_AddAddressMessage *aam)
{
struct TransportClient *tc = cls;
if (CT_COMMUNICATOR != tc->type)
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
- GNUNET_MQ_check_zero_termination(aam);
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_MQ_check_zero_termination (aam);
return GNUNET_OK;
}
@@ -4938,7 +4991,7 @@ check_add_address(void *cls,
* @param cls an `struct AddressListEntry *`
*/
static void
-store_pi(void *cls);
+store_pi (void *cls);
/**
@@ -4948,26 +5001,26 @@ store_pi(void *cls);
* @param success #GNUNET_YES if peerstore was successful
*/
static void
-peerstore_store_own_cb(void *cls, int success)
+peerstore_store_own_cb (void *cls, int success)
{
struct AddressListEntry *ale = cls;
ale->sc = NULL;
if (GNUNET_YES != success)
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Failed to store our own address `%s' in peerstore!\n",
- ale->address);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to store our own address `%s' in peerstore!\n",
+ ale->address);
else
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Successfully stored our own address `%s' in peerstore!\n",
- ale->address);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Successfully stored our own address `%s' in peerstore!\n",
+ ale->address);
/* refresh period is 1/4 of expiration time, that should be plenty
without being excessive. */
ale->st =
- GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_divide(ale->expiration,
- 4ULL),
- &store_pi,
- ale);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (ale->expiration,
+ 4ULL),
+ &store_pi,
+ ale);
}
@@ -4977,7 +5030,7 @@ peerstore_store_own_cb(void *cls, int success)
* @param cls an `struct AddressListEntry *`
*/
static void
-store_pi(void *cls)
+store_pi (void *cls)
{
struct AddressListEntry *ale = cls;
void *addr;
@@ -4985,36 +5038,36 @@ store_pi(void *cls)
struct GNUNET_TIME_Absolute expiration;
ale->st = NULL;
- expiration = GNUNET_TIME_relative_to_absolute(ale->expiration);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Storing our address `%s' in peerstore until %s!\n",
- ale->address,
- GNUNET_STRINGS_absolute_time_to_string(expiration));
- GNUNET_HELLO_sign_address(ale->address,
- ale->nt,
- hello_mono_time,
- GST_my_private_key,
- &addr,
- &addr_len);
- ale->sc = GNUNET_PEERSTORE_store(peerstore,
- "transport",
- &GST_my_identity,
- GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY,
- addr,
- addr_len,
- expiration,
- GNUNET_PEERSTORE_STOREOPTION_MULTIPLE,
- &peerstore_store_own_cb,
- ale);
- GNUNET_free(addr);
+ expiration = GNUNET_TIME_relative_to_absolute (ale->expiration);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Storing our address `%s' in peerstore until %s!\n",
+ ale->address,
+ GNUNET_STRINGS_absolute_time_to_string (expiration));
+ GNUNET_HELLO_sign_address (ale->address,
+ ale->nt,
+ hello_mono_time,
+ GST_my_private_key,
+ &addr,
+ &addr_len);
+ ale->sc = GNUNET_PEERSTORE_store (peerstore,
+ "transport",
+ &GST_my_identity,
+ 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,
- "Failed to store our address `%s' with peerstore\n",
- ale->address);
- ale->st =
- GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &store_pi, ale);
- }
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Failed to store our address `%s' with peerstore\n",
+ ale->address);
+ ale->st =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &store_pi, ale);
+ }
}
@@ -5025,30 +5078,30 @@ store_pi(void *cls)
* @param aam the send message that was sent
*/
static void
-handle_add_address(void *cls,
- const struct GNUNET_TRANSPORT_AddAddressMessage *aam)
+handle_add_address (void *cls,
+ const struct GNUNET_TRANSPORT_AddAddressMessage *aam)
{
struct TransportClient *tc = cls;
struct AddressListEntry *ale;
size_t slen;
/* 0-termination of &aam[1] was checked in #check_add_address */
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Communicator added address `%s'!\n",
- (const char *)&aam[1]);
- slen = ntohs(aam->header.size) - sizeof(*aam);
- ale = GNUNET_malloc(sizeof(struct AddressListEntry) + slen);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Communicator added address `%s'!\n",
+ (const char *) &aam[1]);
+ slen = ntohs (aam->header.size) - sizeof(*aam);
+ ale = GNUNET_malloc (sizeof(struct AddressListEntry) + slen);
ale->tc = tc;
- ale->address = (const char *)&ale[1];
- ale->expiration = GNUNET_TIME_relative_ntoh(aam->expiration);
+ ale->address = (const char *) &ale[1];
+ ale->expiration = GNUNET_TIME_relative_ntoh (aam->expiration);
ale->aid = aam->aid;
- ale->nt = (enum GNUNET_NetworkType)ntohl(aam->nt);
- memcpy(&ale[1], &aam[1], slen);
- GNUNET_CONTAINER_DLL_insert(tc->details.communicator.addr_head,
- tc->details.communicator.addr_tail,
- ale);
- ale->st = GNUNET_SCHEDULER_add_now(&store_pi, ale);
- GNUNET_SERVICE_client_continue(tc->client);
+ ale->nt = (enum GNUNET_NetworkType) ntohl (aam->nt);
+ memcpy (&ale[1], &aam[1], slen);
+ GNUNET_CONTAINER_DLL_insert (tc->details.communicator.addr_head,
+ tc->details.communicator.addr_tail,
+ ale);
+ ale->st = GNUNET_SCHEDULER_add_now (&store_pi, ale);
+ GNUNET_SERVICE_client_continue (tc->client);
}
@@ -5059,34 +5112,34 @@ handle_add_address(void *cls,
* @param dam the send message that was sent
*/
static void
-handle_del_address(void *cls,
- const struct GNUNET_TRANSPORT_DelAddressMessage *dam)
+handle_del_address (void *cls,
+ const struct GNUNET_TRANSPORT_DelAddressMessage *dam)
{
struct TransportClient *tc = cls;
struct AddressListEntry *alen;
if (CT_COMMUNICATOR != tc->type)
- {
- GNUNET_break(0);
- GNUNET_SERVICE_client_drop(tc->client);
- return;
- }
+ {
+ GNUNET_break (0);
+ GNUNET_SERVICE_client_drop (tc->client);
+ return;
+ }
for (struct AddressListEntry *ale = tc->details.communicator.addr_head;
NULL != ale;
ale = alen)
- {
- alen = ale->next;
- if (dam->aid != ale->aid)
- continue;
- GNUNET_assert(ale->tc == tc);
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Communicator deleted address `%s'!\n",
- ale->address);
- free_address_list_entry(ale);
- GNUNET_SERVICE_client_continue(tc->client);
- }
- GNUNET_break(0);
- GNUNET_SERVICE_client_drop(tc->client);
+ {
+ alen = ale->next;
+ if (dam->aid != ale->aid)
+ continue;
+ GNUNET_assert (ale->tc == tc);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Communicator deleted address `%s'!\n",
+ ale->address);
+ free_address_list_entry (ale);
+ GNUNET_SERVICE_client_continue (tc->client);
+ }
+ GNUNET_break (0);
+ GNUNET_SERVICE_client_drop (tc->client);
}
@@ -5098,8 +5151,8 @@ handle_del_address(void *cls,
* @param msg message to demultiplex
*/
static void
-demultiplex_with_cmc(struct CommunicatorMessageContext *cmc,
- const struct GNUNET_MessageHeader *msg);
+demultiplex_with_cmc (struct CommunicatorMessageContext *cmc,
+ const struct GNUNET_MessageHeader *msg);
/**
@@ -5110,23 +5163,23 @@ demultiplex_with_cmc(struct CommunicatorMessageContext *cmc,
* @param cls a `struct CoreSentContext`
*/
static void
-core_env_sent_cb(void *cls)
+core_env_sent_cb (void *cls)
{
struct CoreSentContext *ctx = cls;
struct VirtualLink *vl = ctx->vl;
if (NULL == vl)
- {
- /* lost the link in the meantime, ignore */
- GNUNET_free(ctx);
- return;
- }
- GNUNET_CONTAINER_DLL_remove(vl->csc_head, vl->csc_tail, ctx);
- GNUNET_assert(vl->incoming_fc_window_size_ram >= ctx->size);
+ {
+ /* lost the link in the meantime, ignore */
+ GNUNET_free (ctx);
+ return;
+ }
+ GNUNET_CONTAINER_DLL_remove (vl->csc_head, vl->csc_tail, ctx);
+ GNUNET_assert (vl->incoming_fc_window_size_ram >= ctx->size);
vl->incoming_fc_window_size_ram -= ctx->size;
vl->incoming_fc_window_size_used += ctx->isize;
- consider_sending_fc(vl);
- GNUNET_free(ctx);
+ consider_sending_fc (vl);
+ GNUNET_free (ctx);
}
@@ -5139,109 +5192,109 @@ core_env_sent_cb(void *cls)
* @param mh the message that was received
*/
static void
-handle_raw_message(void *cls, const struct GNUNET_MessageHeader *mh)
+handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh)
{
struct CommunicatorMessageContext *cmc = cls;
struct VirtualLink *vl;
- uint16_t size = ntohs(mh->size);
+ uint16_t size = ntohs (mh->size);
int have_core;
if ((size > UINT16_MAX - sizeof(struct InboundMessage)) ||
(size < sizeof(struct GNUNET_MessageHeader)))
- {
- struct GNUNET_SERVICE_Client *client = cmc->tc->client;
+ {
+ struct GNUNET_SERVICE_Client *client = cmc->tc->client;
- GNUNET_break(0);
- finish_cmc_handling(cmc);
- GNUNET_SERVICE_client_drop(client);
- return;
- }
- vl = lookup_virtual_link(&cmc->im.sender);
+ GNUNET_break (0);
+ finish_cmc_handling (cmc);
+ GNUNET_SERVICE_client_drop (client);
+ return;
+ }
+ vl = lookup_virtual_link (&cmc->im.sender);
if (NULL == vl)
- {
- /* FIXME: sender is giving us messages for CORE but we don't have
- the link up yet! I *suspect* this can happen right now (i.e.
- sender has verified us, but we didn't verify sender), but if
- we pass this on, CORE would be confused (link down, messages
- arrive). We should investigate more if this happens often,
- or in a persistent manner, and possibly do "something" about
- it. Thus logging as error for now. */
- GNUNET_break_op(0);
- GNUNET_STATISTICS_update(GST_stats,
- "# CORE messages droped (virtual link still down)",
- 1,
- GNUNET_NO);
-
- finish_cmc_handling(cmc);
- return;
- }
+ {
+ /* FIXME: sender is giving us messages for CORE but we don't have
+ the link up yet! I *suspect* this can happen right now (i.e.
+ sender has verified us, but we didn't verify sender), but if
+ we pass this on, CORE would be confused (link down, messages
+ arrive). We should investigate more if this happens often,
+ or in a persistent manner, and possibly do "something" about
+ it. Thus logging as error for now. */
+ GNUNET_break_op (0);
+ GNUNET_STATISTICS_update (GST_stats,
+ "# CORE messages droped (virtual link still down)",
+ 1,
+ GNUNET_NO);
+
+ finish_cmc_handling (cmc);
+ return;
+ }
if (vl->incoming_fc_window_size_ram > UINT_MAX - size)
- {
- GNUNET_STATISTICS_update(GST_stats,
- "# CORE messages droped (FC arithmetic overflow)",
- 1,
- GNUNET_NO);
+ {
+ GNUNET_STATISTICS_update (GST_stats,
+ "# CORE messages droped (FC arithmetic overflow)",
+ 1,
+ GNUNET_NO);
- finish_cmc_handling(cmc);
- return;
- }
+ finish_cmc_handling (cmc);
+ return;
+ }
if (vl->incoming_fc_window_size_ram + size > vl->available_fc_window_size)
- {
- GNUNET_STATISTICS_update(GST_stats,
- "# CORE messages droped (FC window overflow)",
- 1,
- GNUNET_NO);
- finish_cmc_handling(cmc);
- return;
- }
+ {
+ GNUNET_STATISTICS_update (GST_stats,
+ "# CORE messages droped (FC window overflow)",
+ 1,
+ GNUNET_NO);
+ finish_cmc_handling (cmc);
+ return;
+ }
/* Forward to all CORE clients */
have_core = GNUNET_NO;
for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
- {
- struct GNUNET_MQ_Envelope *env;
- struct InboundMessage *im;
- struct CoreSentContext *ctx;
-
- if (CT_CORE != tc->type)
- continue;
- vl->incoming_fc_window_size_ram += size;
- env = GNUNET_MQ_msg_extra(im, size, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
- ctx = GNUNET_new(struct CoreSentContext);
- ctx->vl = vl;
- ctx->size = size;
- ctx->isize = (GNUNET_NO == have_core) ? size : 0;
- have_core = GNUNET_YES;
- GNUNET_CONTAINER_DLL_insert(vl->csc_head, vl->csc_tail, ctx);
- GNUNET_MQ_notify_sent(env, &core_env_sent_cb, ctx);
- im->peer = cmc->im.sender;
- memcpy(&im[1], mh, size);
- GNUNET_MQ_send(tc->mq, env);
- vl->core_recv_window--;
- }
+ {
+ struct GNUNET_MQ_Envelope *env;
+ struct InboundMessage *im;
+ struct CoreSentContext *ctx;
+
+ if (CT_CORE != tc->type)
+ continue;
+ vl->incoming_fc_window_size_ram += size;
+ env = GNUNET_MQ_msg_extra (im, size, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
+ ctx = GNUNET_new (struct CoreSentContext);
+ ctx->vl = vl;
+ ctx->size = size;
+ ctx->isize = (GNUNET_NO == have_core) ? size : 0;
+ have_core = GNUNET_YES;
+ GNUNET_CONTAINER_DLL_insert (vl->csc_head, vl->csc_tail, ctx);
+ GNUNET_MQ_notify_sent (env, &core_env_sent_cb, ctx);
+ im->peer = cmc->im.sender;
+ memcpy (&im[1], mh, size);
+ GNUNET_MQ_send (tc->mq, env);
+ vl->core_recv_window--;
+ }
if (GNUNET_NO == have_core)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "Dropped message to CORE: no CORE client connected!\n");
- /* Nevertheless, count window as used, as it is from the
- perspective of the other peer! */
- vl->incoming_fc_window_size_used += size;
- /* TODO-M1 */
- finish_cmc_handling(cmc);
- return;
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Delivered message from %s of type %u to CORE\n",
- GNUNET_i2s(&cmc->im.sender),
- ntohs(mh->type));
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Dropped message to CORE: no CORE client connected!\n");
+ /* Nevertheless, count window as used, as it is from the
+ perspective of the other peer! */
+ vl->incoming_fc_window_size_used += size;
+ /* TODO-M1 */
+ finish_cmc_handling (cmc);
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Delivered message from %s of type %u to CORE\n",
+ GNUNET_i2s (&cmc->im.sender),
+ ntohs (mh->type));
if (vl->core_recv_window > 0)
- {
- finish_cmc_handling(cmc);
- return;
- }
+ {
+ finish_cmc_handling (cmc);
+ return;
+ }
/* Wait with calling #finish_cmc_handling(cmc) until the message
was processed by CORE MQs (for CORE flow control)! */
- GNUNET_CONTAINER_DLL_insert(vl->cmc_head, vl->cmc_tail, cmc);
+ GNUNET_CONTAINER_DLL_insert (vl->cmc_head, vl->cmc_tail, cmc);
}
@@ -5253,27 +5306,27 @@ handle_raw_message(void *cls, const struct GNUNET_MessageHeader *mh)
* @return #GNUNET_YES if message is well-formed
*/
static int
-check_fragment_box(void *cls, const struct TransportFragmentBoxMessage *fb)
+check_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb)
{
- uint16_t size = ntohs(fb->header.size);
+ uint16_t size = ntohs (fb->header.size);
uint16_t bsize = size - sizeof(*fb);
- (void)cls;
+ (void) cls;
if (0 == bsize)
- {
- GNUNET_break_op(0);
- return GNUNET_SYSERR;
- }
- if (bsize + ntohs(fb->frag_off) > ntohs(fb->msg_size))
- {
- GNUNET_break_op(0);
- return GNUNET_SYSERR;
- }
- if (ntohs(fb->frag_off) >= ntohs(fb->msg_size))
- {
- GNUNET_break_op(0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (bsize + ntohs (fb->frag_off) > ntohs (fb->msg_size))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if (ntohs (fb->frag_off) >= ntohs (fb->msg_size))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
return GNUNET_YES;
}
@@ -5284,16 +5337,16 @@ check_fragment_box(void *cls, const struct TransportFragmentBoxMessage *fb)
* @param cls a `struct AcknowledgementCummulator *`
*/
static void
-destroy_ack_cummulator(void *cls)
+destroy_ack_cummulator (void *cls)
{
struct AcknowledgementCummulator *ac = cls;
ac->task = NULL;
- GNUNET_assert(0 == ac->num_acks);
- GNUNET_assert(
+ GNUNET_assert (0 == ac->num_acks);
+ GNUNET_assert (
GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_remove(ack_cummulators, &ac->target, ac));
- GNUNET_free(ac);
+ GNUNET_CONTAINER_multipeermap_remove (ack_cummulators, &ac->target, ac));
+ GNUNET_free (ac);
}
@@ -5303,39 +5356,39 @@ destroy_ack_cummulator(void *cls)
* @param cls a `struct AcknowledgementCummulator *`
*/
static void
-transmit_cummulative_ack_cb(void *cls)
+transmit_cummulative_ack_cb (void *cls)
{
struct AcknowledgementCummulator *ac = cls;
- char buf[sizeof(struct TransportReliabilityAckMessage) +
- ac->ack_counter *
- sizeof(struct TransportCummulativeAckPayloadP)] GNUNET_ALIGN;
+ char buf[sizeof(struct TransportReliabilityAckMessage)
+ + ac->ack_counter
+ * sizeof(struct TransportCummulativeAckPayloadP)] GNUNET_ALIGN;
struct TransportReliabilityAckMessage *ack =
- (struct TransportReliabilityAckMessage *)buf;
+ (struct TransportReliabilityAckMessage *) buf;
struct TransportCummulativeAckPayloadP *ap;
ac->task = NULL;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Sending ACK with %u components to %s\n",
- ac->ack_counter,
- GNUNET_i2s(&ac->target));
- GNUNET_assert(0 < ac->ack_counter);
- ack->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending ACK with %u components to %s\n",
+ ac->ack_counter,
+ GNUNET_i2s (&ac->target));
+ GNUNET_assert (0 < ac->ack_counter);
+ ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK);
ack->header.size =
- htons(sizeof(*ack) +
- ac->ack_counter * sizeof(struct TransportCummulativeAckPayloadP));
- ack->ack_counter = htonl(ac->ack_counter++);
- ap = (struct TransportCummulativeAckPayloadP *)&ack[1];
+ htons (sizeof(*ack)
+ + ac->ack_counter * sizeof(struct TransportCummulativeAckPayloadP));
+ ack->ack_counter = htonl (ac->ack_counter++);
+ ap = (struct TransportCummulativeAckPayloadP *) &ack[1];
for (unsigned int i = 0; i < ac->ack_counter; i++)
- {
- ap[i].ack_uuid = ac->ack_uuids[i].ack_uuid;
- ap[i].ack_delay = GNUNET_TIME_relative_hton(
- GNUNET_TIME_absolute_get_duration(ac->ack_uuids[i].receive_time));
- }
- route_control_message_without_fc(&ac->target, &ack->header, RMO_DV_ALLOWED);
+ {
+ ap[i].ack_uuid = ac->ack_uuids[i].ack_uuid;
+ ap[i].ack_delay = GNUNET_TIME_relative_hton (
+ GNUNET_TIME_absolute_get_duration (ac->ack_uuids[i].receive_time));
+ }
+ route_control_message_without_fc (&ac->target, &ack->header, RMO_DV_ALLOWED);
ac->num_acks = 0;
- ac->task = GNUNET_SCHEDULER_add_delayed(ACK_CUMMULATOR_TIMEOUT,
- &destroy_ack_cummulator,
- ac);
+ ac->task = GNUNET_SCHEDULER_add_delayed (ACK_CUMMULATOR_TIMEOUT,
+ &destroy_ack_cummulator,
+ ac);
}
@@ -5348,55 +5401,56 @@ transmit_cummulative_ack_cb(void *cls)
* @param max_delay how long can the ACK wait
*/
static void
-cummulative_ack(const struct GNUNET_PeerIdentity *pid,
- const struct AcknowledgementUUIDP *ack_uuid,
- struct GNUNET_TIME_Absolute max_delay)
+cummulative_ack (const struct GNUNET_PeerIdentity *pid,
+ const struct AcknowledgementUUIDP *ack_uuid,
+ struct GNUNET_TIME_Absolute max_delay)
{
struct AcknowledgementCummulator *ac;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Scheduling ACK %s for transmission to %s\n",
- GNUNET_uuid2s(&ack_uuid->value),
- GNUNET_i2s(pid));
- ac = GNUNET_CONTAINER_multipeermap_get(ack_cummulators, pid);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Scheduling ACK %s for transmission to %s\n",
+ GNUNET_uuid2s (&ack_uuid->value),
+ GNUNET_i2s (pid));
+ ac = GNUNET_CONTAINER_multipeermap_get (ack_cummulators, pid);
if (NULL == ac)
- {
- ac = GNUNET_new(struct AcknowledgementCummulator);
- ac->target = *pid;
- ac->min_transmission_time = max_delay;
- GNUNET_assert(GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_put(
- ack_cummulators,
- &ac->target,
- ac,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- }
+ {
+ ac = GNUNET_new (struct AcknowledgementCummulator);
+ ac->target = *pid;
+ ac->min_transmission_time = max_delay;
+ GNUNET_assert (GNUNET_YES ==
+ GNUNET_CONTAINER_multipeermap_put (
+ ack_cummulators,
+ &ac->target,
+ ac,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+ }
else
+ {
+ if (MAX_CUMMULATIVE_ACKS == ac->num_acks)
{
- if (MAX_CUMMULATIVE_ACKS == ac->num_acks)
- {
- /* must run immediately, ack buffer full! */
- GNUNET_SCHEDULER_cancel(ac->task);
- transmit_cummulative_ack_cb(ac);
- }
- GNUNET_SCHEDULER_cancel(ac->task);
- ac->min_transmission_time =
- GNUNET_TIME_absolute_min(ac->min_transmission_time, max_delay);
+ /* must run immediately, ack buffer full! */
+ GNUNET_SCHEDULER_cancel (ac->task);
+ transmit_cummulative_ack_cb (ac);
}
- GNUNET_assert(ac->num_acks < MAX_CUMMULATIVE_ACKS);
- ac->ack_uuids[ac->num_acks].receive_time = GNUNET_TIME_absolute_get();
+ GNUNET_SCHEDULER_cancel (ac->task);
+ ac->min_transmission_time =
+ GNUNET_TIME_absolute_min (ac->min_transmission_time, max_delay);
+ }
+ GNUNET_assert (ac->num_acks < MAX_CUMMULATIVE_ACKS);
+ ac->ack_uuids[ac->num_acks].receive_time = GNUNET_TIME_absolute_get ();
ac->ack_uuids[ac->num_acks].ack_uuid = *ack_uuid;
ac->num_acks++;
- ac->task = GNUNET_SCHEDULER_add_at(ac->min_transmission_time,
- &transmit_cummulative_ack_cb,
- ac);
+ ac->task = GNUNET_SCHEDULER_add_at (ac->min_transmission_time,
+ &transmit_cummulative_ack_cb,
+ ac);
}
/**
* Closure for #find_by_message_uuid.
*/
-struct FindByMessageUuidContext {
+struct FindByMessageUuidContext
+{
/**
* UUID to look for.
*/
@@ -5419,17 +5473,17 @@ struct FindByMessageUuidContext {
* @return #GNUNET_YES if not found, #GNUNET_NO if found
*/
static int
-find_by_message_uuid(void *cls, uint32_t key, void *value)
+find_by_message_uuid (void *cls, uint32_t key, void *value)
{
struct FindByMessageUuidContext *fc = cls;
struct ReassemblyContext *rc = value;
- (void)key;
- if (0 == GNUNET_memcmp(&fc->message_uuid, &rc->msg_uuid))
- {
- fc->rc = rc;
- return GNUNET_NO;
- }
+ (void) key;
+ if (0 == GNUNET_memcmp (&fc->message_uuid, &rc->msg_uuid))
+ {
+ fc->rc = rc;
+ return GNUNET_NO;
+ }
return GNUNET_YES;
}
@@ -5442,7 +5496,7 @@ find_by_message_uuid(void *cls, uint32_t key, void *value)
* @param fb the message that was received
*/
static void
-handle_fragment_box(void *cls, const struct TransportFragmentBoxMessage *fb)
+handle_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb)
{
struct CommunicatorMessageContext *cmc = cls;
struct Neighbour *n;
@@ -5455,142 +5509,142 @@ handle_fragment_box(void *cls, const struct TransportFragmentBoxMessage *fb)
struct GNUNET_TIME_Relative cdelay;
struct FindByMessageUuidContext fc;
- n = lookup_neighbour(&cmc->im.sender);
+ n = lookup_neighbour (&cmc->im.sender);
if (NULL == n)
- {
- struct GNUNET_SERVICE_Client *client = cmc->tc->client;
+ {
+ struct GNUNET_SERVICE_Client *client = cmc->tc->client;
- GNUNET_break(0);
- finish_cmc_handling(cmc);
- GNUNET_SERVICE_client_drop(client);
- return;
- }
+ GNUNET_break (0);
+ finish_cmc_handling (cmc);
+ GNUNET_SERVICE_client_drop (client);
+ return;
+ }
if (NULL == n->reassembly_map)
- {
- n->reassembly_map = GNUNET_CONTAINER_multihashmap32_create(8);
- n->reassembly_heap =
- GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN);
- n->reassembly_timeout_task =
- GNUNET_SCHEDULER_add_delayed(REASSEMBLY_EXPIRATION,
- &reassembly_cleanup_task,
- n);
- }
- msize = ntohs(fb->msg_size);
+ {
+ n->reassembly_map = GNUNET_CONTAINER_multihashmap32_create (8);
+ n->reassembly_heap =
+ GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
+ n->reassembly_timeout_task =
+ GNUNET_SCHEDULER_add_delayed (REASSEMBLY_EXPIRATION,
+ &reassembly_cleanup_task,
+ n);
+ }
+ msize = ntohs (fb->msg_size);
fc.message_uuid = fb->msg_uuid;
fc.rc = NULL;
- (void)GNUNET_CONTAINER_multihashmap32_get_multiple(n->reassembly_map,
- fb->msg_uuid.uuid,
- &find_by_message_uuid,
- &fc);
+ (void) GNUNET_CONTAINER_multihashmap32_get_multiple (n->reassembly_map,
+ fb->msg_uuid.uuid,
+ &find_by_message_uuid,
+ &fc);
if (NULL == (rc = fc.rc))
- {
- rc = GNUNET_malloc(sizeof(*rc) + msize + /* reassembly payload buffer */
- (msize + 7) / 8 * sizeof(uint8_t) /* bitfield */);
- rc->msg_uuid = fb->msg_uuid;
- rc->neighbour = n;
- rc->msg_size = msize;
- rc->reassembly_timeout =
- GNUNET_TIME_relative_to_absolute(REASSEMBLY_EXPIRATION);
- rc->last_frag = GNUNET_TIME_absolute_get();
- rc->hn = GNUNET_CONTAINER_heap_insert(n->reassembly_heap,
- rc,
- rc->reassembly_timeout.abs_value_us);
- GNUNET_assert(GNUNET_OK ==
- GNUNET_CONTAINER_multihashmap32_put(
- n->reassembly_map,
- rc->msg_uuid.uuid,
- rc,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
- target = (char *)&rc[1];
- rc->bitfield = (uint8_t *)(target + rc->msg_size);
- rc->msg_missing = rc->msg_size;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Received fragment at offset %u/%u from %s for NEW message %u\n",
- ntohs(fb->frag_off),
- msize,
- GNUNET_i2s(&cmc->im.sender),
- (unsigned int)fb->msg_uuid.uuid);
- }
+ {
+ rc = GNUNET_malloc (sizeof(*rc) + msize /* reassembly payload buffer */
+ + (msize + 7) / 8 * sizeof(uint8_t) /* bitfield */);
+ rc->msg_uuid = fb->msg_uuid;
+ rc->neighbour = n;
+ rc->msg_size = msize;
+ rc->reassembly_timeout =
+ GNUNET_TIME_relative_to_absolute (REASSEMBLY_EXPIRATION);
+ rc->last_frag = GNUNET_TIME_absolute_get ();
+ rc->hn = GNUNET_CONTAINER_heap_insert (n->reassembly_heap,
+ rc,
+ rc->reassembly_timeout.abs_value_us);
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONTAINER_multihashmap32_put (
+ n->reassembly_map,
+ rc->msg_uuid.uuid,
+ rc,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+ target = (char *) &rc[1];
+ rc->bitfield = (uint8_t *) (target + rc->msg_size);
+ rc->msg_missing = rc->msg_size;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received fragment at offset %u/%u from %s for NEW message %u\n",
+ ntohs (fb->frag_off),
+ msize,
+ GNUNET_i2s (&cmc->im.sender),
+ (unsigned int) fb->msg_uuid.uuid);
+ }
else
- {
- target = (char *)&rc[1];
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Received fragment at offset %u/%u from %s for message %u\n",
- ntohs(fb->frag_off),
- msize,
- GNUNET_i2s(&cmc->im.sender),
- (unsigned int)fb->msg_uuid.uuid);
- }
+ {
+ target = (char *) &rc[1];
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received fragment at offset %u/%u from %s for message %u\n",
+ ntohs (fb->frag_off),
+ msize,
+ GNUNET_i2s (&cmc->im.sender),
+ (unsigned int) fb->msg_uuid.uuid);
+ }
if (msize != rc->msg_size)
- {
- GNUNET_break(0);
- finish_cmc_handling(cmc);
- return;
- }
+ {
+ GNUNET_break (0);
+ finish_cmc_handling (cmc);
+ return;
+ }
/* reassemble */
- fsize = ntohs(fb->header.size) - sizeof(*fb);
+ fsize = ntohs (fb->header.size) - sizeof(*fb);
if (0 == fsize)
- {
- GNUNET_break(0);
- finish_cmc_handling(cmc);
- return;
- }
- frag_off = ntohs(fb->frag_off);
+ {
+ GNUNET_break (0);
+ finish_cmc_handling (cmc);
+ return;
+ }
+ frag_off = ntohs (fb->frag_off);
if (frag_off + fsize > msize)
- {
- /* Fragment (plus fragment size) exceeds message size! */
- GNUNET_break_op(0);
- finish_cmc_handling(cmc);
- return;
- }
- memcpy(&target[frag_off], &fb[1], fsize);
+ {
+ /* Fragment (plus fragment size) exceeds message size! */
+ GNUNET_break_op (0);
+ finish_cmc_handling (cmc);
+ return;
+ }
+ memcpy (&target[frag_off], &fb[1], fsize);
/* update bitfield and msg_missing */
for (unsigned int i = frag_off; i < frag_off + fsize; i++)
+ {
+ if (0 == (rc->bitfield[i / 8] & (1 << (i % 8))))
{
- if (0 == (rc->bitfield[i / 8] & (1 << (i % 8))))
- {
- rc->bitfield[i / 8] |= (1 << (i % 8));
- rc->msg_missing--;
- }
+ rc->bitfield[i / 8] |= (1 << (i % 8));
+ rc->msg_missing--;
}
+ }
/* Compute cummulative ACK */
- cdelay = GNUNET_TIME_absolute_get_duration(rc->last_frag);
- cdelay = GNUNET_TIME_relative_multiply(cdelay, rc->msg_missing / fsize);
+ cdelay = GNUNET_TIME_absolute_get_duration (rc->last_frag);
+ cdelay = GNUNET_TIME_relative_multiply (cdelay, rc->msg_missing / fsize);
if (0 == rc->msg_missing)
cdelay = GNUNET_TIME_UNIT_ZERO;
- cummulative_ack(&cmc->im.sender,
- &fb->ack_uuid,
- GNUNET_TIME_relative_to_absolute(cdelay));
- rc->last_frag = GNUNET_TIME_absolute_get();
+ cummulative_ack (&cmc->im.sender,
+ &fb->ack_uuid,
+ GNUNET_TIME_relative_to_absolute (cdelay));
+ rc->last_frag = GNUNET_TIME_absolute_get ();
/* is reassembly complete? */
if (0 != rc->msg_missing)
- {
- finish_cmc_handling(cmc);
- return;
- }
+ {
+ finish_cmc_handling (cmc);
+ return;
+ }
/* reassembly is complete, verify result */
- msg = (const struct GNUNET_MessageHeader *)&rc[1];
- if (ntohs(msg->size) != rc->msg_size)
- {
- GNUNET_break(0);
- free_reassembly_context(rc);
- finish_cmc_handling(cmc);
- return;
- }
+ msg = (const struct GNUNET_MessageHeader *) &rc[1];
+ if (ntohs (msg->size) != rc->msg_size)
+ {
+ GNUNET_break (0);
+ free_reassembly_context (rc);
+ finish_cmc_handling (cmc);
+ return;
+ }
/* successful reassembly */
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Fragment reassembly complete for message %u\n",
- (unsigned int)fb->msg_uuid.uuid);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Fragment reassembly complete for message %u\n",
+ (unsigned int) fb->msg_uuid.uuid);
/* FIXME: check that the resulting msg is NOT a
DV Box or Reliability Box, as that is NOT allowed! */
- demultiplex_with_cmc(cmc, msg);
+ demultiplex_with_cmc (cmc, msg);
/* FIXME-OPTIMIZE: really free here? Might be bad if fragments are still
en-route and we forget that we finished this reassembly immediately!
-> keep around until timeout?
-> shorten timeout based on ACK? */
- free_reassembly_context(rc);
+ free_reassembly_context (rc);
}
@@ -5602,11 +5656,11 @@ handle_fragment_box(void *cls, const struct TransportFragmentBoxMessage *fb)
* @return #GNUNET_YES if message is well-formed
*/
static int
-check_reliability_box(void *cls,
- const struct TransportReliabilityBoxMessage *rb)
+check_reliability_box (void *cls,
+ const struct TransportReliabilityBoxMessage *rb)
{
- (void)cls;
- GNUNET_MQ_check_boxed_message(rb);
+ (void) cls;
+ GNUNET_MQ_check_boxed_message (rb);
return GNUNET_YES;
}
@@ -5619,34 +5673,34 @@ check_reliability_box(void *cls,
* @param rb the message that was received
*/
static void
-handle_reliability_box(void *cls,
- const struct TransportReliabilityBoxMessage *rb)
+handle_reliability_box (void *cls,
+ const struct TransportReliabilityBoxMessage *rb)
{
struct CommunicatorMessageContext *cmc = cls;
const struct GNUNET_MessageHeader *inbox =
- (const struct GNUNET_MessageHeader *)&rb[1];
+ (const struct GNUNET_MessageHeader *) &rb[1];
struct GNUNET_TIME_Relative rtt;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Received reliability box from %s with UUID %s of type %u\n",
- GNUNET_i2s(&cmc->im.sender),
- GNUNET_uuid2s(&rb->ack_uuid.value),
- (unsigned int)ntohs(inbox->type));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received reliability box from %s with UUID %s of type %u\n",
+ GNUNET_i2s (&cmc->im.sender),
+ GNUNET_uuid2s (&rb->ack_uuid.value),
+ (unsigned int) ntohs (inbox->type));
rtt = GNUNET_TIME_UNIT_SECONDS; /* FIXME: should base this on "RTT", but we
do not really have an RTT for the
* incoming* queue (should we have
the sender add it to the rb message?) */
- cummulative_ack(
+ cummulative_ack (
&cmc->im.sender,
&rb->ack_uuid,
- (0 == ntohl(rb->ack_countdown))
+ (0 == ntohl (rb->ack_countdown))
? GNUNET_TIME_UNIT_ZERO_ABS
- : GNUNET_TIME_relative_to_absolute(
- GNUNET_TIME_relative_divide(rtt, 8 /* FIXME: magic constant */)));
+ : GNUNET_TIME_relative_to_absolute (
+ GNUNET_TIME_relative_divide (rtt, 8 /* FIXME: magic constant */)));
/* continue with inner message */
/* FIXME: check that inbox is NOT a DV Box, fragment or another
reliability box (not allowed!) */
- demultiplex_with_cmc(cmc, inbox);
+ demultiplex_with_cmc (cmc, inbox);
}
@@ -5659,20 +5713,20 @@ handle_reliability_box(void *cls,
* @param age current age
*/
static void
-update_pd_age(struct PerformanceData *pd, unsigned int age)
+update_pd_age (struct PerformanceData *pd, unsigned int age)
{
unsigned int sage;
if (age == pd->last_age)
return; /* nothing to do */
- sage = GNUNET_MAX(pd->last_age, age - 2 * GOODPUT_AGING_SLOTS);
+ sage = GNUNET_MAX (pd->last_age, age - 2 * GOODPUT_AGING_SLOTS);
for (unsigned int i = sage; i <= age - GOODPUT_AGING_SLOTS; i++)
- {
- struct TransmissionHistoryEntry *the = &pd->the[i % GOODPUT_AGING_SLOTS];
+ {
+ struct TransmissionHistoryEntry *the = &pd->the[i % GOODPUT_AGING_SLOTS];
- the->bytes_sent = 0;
- the->bytes_received = 0;
- }
+ the->bytes_sent = 0;
+ the->bytes_received = 0;
+ }
pd->last_age = age;
}
@@ -5686,20 +5740,20 @@ update_pd_age(struct PerformanceData *pd, unsigned int age)
* @param bytes_transmitted_ok number of bytes receiver confirmed as received
*/
static void
-update_performance_data(struct PerformanceData *pd,
- struct GNUNET_TIME_Relative rtt,
- uint16_t bytes_transmitted_ok)
+update_performance_data (struct PerformanceData *pd,
+ struct GNUNET_TIME_Relative rtt,
+ uint16_t bytes_transmitted_ok)
{
uint64_t nval = rtt.rel_value_us;
uint64_t oval = pd->aged_rtt.rel_value_us;
- unsigned int age = get_age();
+ unsigned int age = get_age ();
struct TransmissionHistoryEntry *the = &pd->the[age % GOODPUT_AGING_SLOTS];
if (oval == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
pd->aged_rtt = rtt;
else
pd->aged_rtt.rel_value_us = (nval + 7 * oval) / 8;
- update_pd_age(pd, age);
+ update_pd_age (pd, age);
the->bytes_received += bytes_transmitted_ok;
}
@@ -5712,11 +5766,11 @@ update_performance_data(struct PerformanceData *pd,
* @param bytes_transmitted_ok number of bytes successfully transmitted
*/
static void
-update_queue_performance(struct Queue *q,
- struct GNUNET_TIME_Relative rtt,
- uint16_t bytes_transmitted_ok)
+update_queue_performance (struct Queue *q,
+ struct GNUNET_TIME_Relative rtt,
+ uint16_t bytes_transmitted_ok)
{
- update_performance_data(&q->pd, rtt, bytes_transmitted_ok);
+ update_performance_data (&q->pd, rtt, bytes_transmitted_ok);
}
@@ -5728,11 +5782,11 @@ update_queue_performance(struct Queue *q,
* @param bytes_transmitted_ok number of bytes successfully transmitted
*/
static void
-update_dvh_performance(struct DistanceVectorHop *dvh,
- struct GNUNET_TIME_Relative rtt,
- uint16_t bytes_transmitted_ok)
+update_dvh_performance (struct DistanceVectorHop *dvh,
+ struct GNUNET_TIME_Relative rtt,
+ uint16_t bytes_transmitted_ok)
{
- update_performance_data(&dvh->pd, rtt, bytes_transmitted_ok);
+ update_performance_data (&dvh->pd, rtt, bytes_transmitted_ok);
}
@@ -5744,47 +5798,47 @@ update_dvh_performance(struct DistanceVectorHop *dvh,
* @param pm pending message that was transmitted
*/
static void
-completed_pending_message(struct PendingMessage *pm)
+completed_pending_message (struct PendingMessage *pm)
{
struct PendingMessage *pos;
switch (pm->pmt)
- {
- case PMT_CORE:
- case PMT_RELIABILITY_BOX:
- /* Full message sent, we are done */
- client_send_response(pm);
- return;
+ {
+ case PMT_CORE:
+ case PMT_RELIABILITY_BOX:
+ /* Full message sent, we are done */
+ client_send_response (pm);
+ return;
- case PMT_FRAGMENT_BOX:
- /* Fragment sent over reliabile channel */
- free_fragment_tree(pm);
+ case PMT_FRAGMENT_BOX:
+ /* Fragment sent over reliabile channel */
+ free_fragment_tree (pm);
+ pos = pm->frag_parent;
+ GNUNET_CONTAINER_MDLL_remove (frag, pos->head_frag, pos->tail_frag, pm);
+ GNUNET_free (pm);
+ /* check if subtree is done */
+ while ((NULL == pos->head_frag) && (pos->frag_off == pos->bytes_msg) &&
+ (pos != pm))
+ {
+ pm = pos;
pos = pm->frag_parent;
- GNUNET_CONTAINER_MDLL_remove(frag, pos->head_frag, pos->tail_frag, pm);
- GNUNET_free(pm);
- /* check if subtree is done */
- while ((NULL == pos->head_frag) && (pos->frag_off == pos->bytes_msg) &&
- (pos != pm))
- {
- pm = pos;
- pos = pm->frag_parent;
- GNUNET_CONTAINER_MDLL_remove(frag, pos->head_frag, pos->tail_frag, pm);
- GNUNET_free(pm);
- }
+ GNUNET_CONTAINER_MDLL_remove (frag, pos->head_frag, pos->tail_frag, pm);
+ GNUNET_free (pm);
+ }
- /* Was this the last applicable fragmment? */
- if ((NULL == pos->head_frag) && (NULL == pos->frag_parent) &&
- (pos->frag_off == pos->bytes_msg))
- client_send_response(pos);
- return;
+ /* Was this the last applicable fragmment? */
+ if ((NULL == pos->head_frag) && (NULL == pos->frag_parent) &&
+ (pos->frag_off == pos->bytes_msg))
+ client_send_response (pos);
+ return;
- case PMT_DV_BOX:
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Completed transmission of message %llu (DV Box)\n",
- pm->logging_uuid);
- free_pending_message(pm);
- return;
- }
+ case PMT_DV_BOX:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Completed transmission of message %llu (DV Box)\n",
+ pm->logging_uuid);
+ free_pending_message (pm);
+ return;
+ }
}
@@ -5796,23 +5850,23 @@ completed_pending_message(struct PendingMessage *pm)
* other peer
*/
static void
-handle_acknowledged(struct PendingAcknowledgement *pa,
- struct GNUNET_TIME_Relative ack_delay)
+handle_acknowledged (struct PendingAcknowledgement *pa,
+ struct GNUNET_TIME_Relative ack_delay)
{
struct GNUNET_TIME_Relative delay;
- delay = GNUNET_TIME_absolute_get_duration(pa->transmission_time);
+ delay = GNUNET_TIME_absolute_get_duration (pa->transmission_time);
if (delay.rel_value_us > ack_delay.rel_value_us)
delay = GNUNET_TIME_UNIT_ZERO;
else
- delay = GNUNET_TIME_relative_subtract(delay, ack_delay);
+ delay = GNUNET_TIME_relative_subtract (delay, ack_delay);
if (NULL != pa->queue)
- update_queue_performance(pa->queue, delay, pa->message_size);
+ update_queue_performance (pa->queue, delay, pa->message_size);
if (NULL != pa->dvh)
- update_dvh_performance(pa->dvh, delay, pa->message_size);
+ update_dvh_performance (pa->dvh, delay, pa->message_size);
if (NULL != pa->pm)
- completed_pending_message(pa->pm);
- free_pending_acknowledgement(pa);
+ completed_pending_message (pa->pm);
+ free_pending_acknowledgement (pa);
}
@@ -5824,25 +5878,25 @@ handle_acknowledged(struct PendingAcknowledgement *pa,
* @return #GNUNET_Ok if @a ra is well-formed
*/
static int
-check_reliability_ack(void *cls,
- const struct TransportReliabilityAckMessage *ra)
+check_reliability_ack (void *cls,
+ const struct TransportReliabilityAckMessage *ra)
{
unsigned int n_acks;
- (void)cls;
- n_acks = (ntohs(ra->header.size) - sizeof(*ra)) /
- sizeof(struct TransportCummulativeAckPayloadP);
+ (void) cls;
+ n_acks = (ntohs (ra->header.size) - sizeof(*ra))
+ / sizeof(struct TransportCummulativeAckPayloadP);
if (0 == n_acks)
- {
- GNUNET_break_op(0);
- return GNUNET_SYSERR;
- }
- if ((ntohs(ra->header.size) - sizeof(*ra)) !=
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ if ((ntohs (ra->header.size) - sizeof(*ra)) !=
n_acks * sizeof(struct TransportCummulativeAckPayloadP))
- {
- GNUNET_break_op(0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
return GNUNET_OK;
}
@@ -5855,46 +5909,46 @@ check_reliability_ack(void *cls,
* @param ra the message that was received
*/
static void
-handle_reliability_ack(void *cls,
- const struct TransportReliabilityAckMessage *ra)
+handle_reliability_ack (void *cls,
+ const struct TransportReliabilityAckMessage *ra)
{
struct CommunicatorMessageContext *cmc = cls;
const struct TransportCummulativeAckPayloadP *ack;
unsigned int n_acks;
uint32_t ack_counter;
- n_acks = (ntohs(ra->header.size) - sizeof(*ra)) /
- sizeof(struct TransportCummulativeAckPayloadP);
- ack = (const struct TransportCummulativeAckPayloadP *)&ra[1];
+ n_acks = (ntohs (ra->header.size) - sizeof(*ra))
+ / sizeof(struct TransportCummulativeAckPayloadP);
+ ack = (const struct TransportCummulativeAckPayloadP *) &ra[1];
for (unsigned int i = 0; i < n_acks; i++)
- {
- struct PendingAcknowledgement *pa =
- GNUNET_CONTAINER_multiuuidmap_get(pending_acks, &ack[i].ack_uuid.value);
- if (NULL == pa)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_INFO,
- "Received ACK from %s with UUID %s which is unknown to us!\n",
- GNUNET_i2s(&cmc->im.sender),
- GNUNET_uuid2s(&ack[i].ack_uuid.value));
- GNUNET_STATISTICS_update(
- GST_stats,
- "# FRAGMENT_ACKS dropped, no matching pending message",
- 1,
- GNUNET_NO);
- continue;
- }
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Received ACK from %s with UUID %s\n",
- GNUNET_i2s(&cmc->im.sender),
- GNUNET_uuid2s(&ack[i].ack_uuid.value));
- handle_acknowledged(pa, GNUNET_TIME_relative_ntoh(ack[i].ack_delay));
+ {
+ struct PendingAcknowledgement *pa =
+ GNUNET_CONTAINER_multiuuidmap_get (pending_acks, &ack[i].ack_uuid.value);
+ if (NULL == pa)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Received ACK from %s with UUID %s which is unknown to us!\n",
+ GNUNET_i2s (&cmc->im.sender),
+ GNUNET_uuid2s (&ack[i].ack_uuid.value));
+ GNUNET_STATISTICS_update (
+ GST_stats,
+ "# FRAGMENT_ACKS dropped, no matching pending message",
+ 1,
+ GNUNET_NO);
+ continue;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received ACK from %s with UUID %s\n",
+ GNUNET_i2s (&cmc->im.sender),
+ GNUNET_uuid2s (&ack[i].ack_uuid.value));
+ handle_acknowledged (pa, GNUNET_TIME_relative_ntoh (ack[i].ack_delay));
+ }
- ack_counter = htonl(ra->ack_counter);
- (void)ack_counter; /* silence compiler warning for now */
+ ack_counter = htonl (ra->ack_counter);
+ (void) ack_counter; /* silence compiler warning for now */
// FIXME-OPTIMIZE: track ACK losses based on ack_counter somewhere!
// (DV and/or Neighbour?)
- finish_cmc_handling(cmc);
+ finish_cmc_handling (cmc);
}
@@ -5906,30 +5960,30 @@ handle_reliability_ack(void *cls,
* @return #GNUNET_YES if message is well-formed
*/
static int
-check_backchannel_encapsulation(
+check_backchannel_encapsulation (
void *cls,
const struct TransportBackchannelEncapsulationMessage *be)
{
- uint16_t size = ntohs(be->header.size) - sizeof(*be);
+ uint16_t size = ntohs (be->header.size) - sizeof(*be);
const struct GNUNET_MessageHeader *inbox =
- (const struct GNUNET_MessageHeader *)&be[1];
+ (const struct GNUNET_MessageHeader *) &be[1];
const char *is;
uint16_t isize;
- (void)cls;
- if (ntohs(inbox->size) >= size)
- {
- GNUNET_break_op(0);
- return GNUNET_SYSERR;
- }
- isize = ntohs(inbox->size);
- is = ((const char *)inbox) + isize;
+ (void) cls;
+ if (ntohs (inbox->size) >= size)
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
+ isize = ntohs (inbox->size);
+ is = ((const char *) inbox) + isize;
size -= isize;
if ('\0' != is[size - 1])
- {
- GNUNET_break_op(0);
- return GNUNET_SYSERR;
- }
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
return GNUNET_YES;
}
@@ -5943,7 +5997,7 @@ check_backchannel_encapsulation(
* @para