summaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/communicator.h8
-rw-r--r--src/transport/gnunet-communicator-tcp.c1840
-rw-r--r--src/transport/gnunet-communicator-udp.c2292
-rw-r--r--src/transport/gnunet-communicator-unix.c958
-rw-r--r--src/transport/gnunet-helper-transport-bluetooth.c3205
-rw-r--r--src/transport/gnunet-helper-transport-wlan-dummy.c595
-rw-r--r--src/transport/gnunet-helper-transport-wlan.c1607
-rw-r--r--src/transport/gnunet-service-tng.c7781
-rw-r--r--src/transport/gnunet-service-transport.c2390
-rw-r--r--src/transport/gnunet-service-transport.h64
-rw-r--r--src/transport/gnunet-service-transport_ats.c772
-rw-r--r--src/transport/gnunet-service-transport_ats.h56
-rw-r--r--src/transport/gnunet-service-transport_hello.c209
-rw-r--r--src/transport/gnunet-service-transport_hello.h24
-rw-r--r--src/transport/gnunet-service-transport_manipulation.c508
-rw-r--r--src/transport/gnunet-service-transport_manipulation.h38
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c4336
-rw-r--r--src/transport/gnunet-service-transport_neighbours.h86
-rw-r--r--src/transport/gnunet-service-transport_plugins.c486
-rw-r--r--src/transport/gnunet-service-transport_plugins.h24
-rw-r--r--src/transport/gnunet-service-transport_validation.c1702
-rw-r--r--src/transport/gnunet-service-transport_validation.h32
-rw-r--r--src/transport/gnunet-transport-profiler.c560
-rw-r--r--src/transport/gnunet-transport-wlan-receiver.c144
-rw-r--r--src/transport/gnunet-transport-wlan-sender.c280
-rw-r--r--src/transport/gnunet-transport.c1266
-rw-r--r--src/transport/ieee80211_radiotap.h60
-rw-r--r--src/transport/plugin_transport_http.h88
-rw-r--r--src/transport/plugin_transport_http_client.c2426
-rw-r--r--src/transport/plugin_transport_http_common.c961
-rw-r--r--src/transport/plugin_transport_http_common.h91
-rw-r--r--src/transport/plugin_transport_http_server.c3571
-rw-r--r--src/transport/plugin_transport_smtp.c642
-rw-r--r--src/transport/plugin_transport_tcp.c3631
-rw-r--r--src/transport/plugin_transport_template.c188
-rw-r--r--src/transport/plugin_transport_udp.c3988
-rw-r--r--src/transport/plugin_transport_udp.h46
-rw-r--r--src/transport/plugin_transport_udp_broadcasting.c643
-rw-r--r--src/transport/plugin_transport_unix.c1603
-rw-r--r--src/transport/plugin_transport_wlan.c2091
-rw-r--r--src/transport/plugin_transport_wlan.h53
-rw-r--r--src/transport/tcp_connection_legacy.c1315
-rw-r--r--src/transport/tcp_server_legacy.c1283
-rw-r--r--src/transport/tcp_server_mst_legacy.c329
-rw-r--r--src/transport/tcp_service_legacy.c1761
-rw-r--r--src/transport/test_communicator_unix.c222
-rw-r--r--src/transport/test_http_common.c227
-rw-r--r--src/transport/test_plugin_transport.c836
-rw-r--r--src/transport/test_quota_compliance.c326
-rw-r--r--src/transport/test_transport_address_switch.c406
-rw-r--r--src/transport/test_transport_api.c78
-rw-r--r--src/transport/test_transport_api_blacklisting.c178
-rw-r--r--src/transport/test_transport_api_disconnect.c96
-rw-r--r--src/transport/test_transport_api_limited_sockets.c78
-rw-r--r--src/transport/test_transport_api_manipulation_cfg.c175
-rw-r--r--src/transport/test_transport_api_manipulation_recv_tcp.c180
-rw-r--r--src/transport/test_transport_api_manipulation_send_tcp.c178
-rw-r--r--src/transport/test_transport_api_monitor_peers.c206
-rw-r--r--src/transport/test_transport_api_reliability.c218
-rw-r--r--src/transport/test_transport_api_restart_reconnect.c182
-rw-r--r--src/transport/test_transport_api_timeout.c128
-rw-r--r--src/transport/test_transport_blacklisting.c705
-rw-r--r--src/transport/test_transport_testing_restart.c133
-rw-r--r--src/transport/test_transport_testing_startstop.c117
-rw-r--r--src/transport/transport-testing-filenames.c124
-rw-r--r--src/transport/transport-testing-loggers.c44
-rw-r--r--src/transport/transport-testing-main.c460
-rw-r--r--src/transport/transport-testing-send.c206
-rw-r--r--src/transport/transport-testing.c1019
-rw-r--r--src/transport/transport-testing.h81
-rw-r--r--src/transport/transport-testing2.c456
-rw-r--r--src/transport/transport-testing2.h62
-rw-r--r--src/transport/transport.h155
-rw-r--r--src/transport/transport_api2_application.c189
-rw-r--r--src/transport/transport_api2_communication.c465
-rw-r--r--src/transport/transport_api2_core.c490
-rw-r--r--src/transport/transport_api2_monitor.c127
-rw-r--r--src/transport/transport_api_address_to_string.c222
-rw-r--r--src/transport/transport_api_blacklist.c91
-rw-r--r--src/transport/transport_api_core.c603
-rw-r--r--src/transport/transport_api_hello_get.c142
-rw-r--r--src/transport/transport_api_manipulation.c130
-rw-r--r--src/transport/transport_api_monitor_peers.c377
-rw-r--r--src/transport/transport_api_monitor_plugins.c294
-rw-r--r--src/transport/transport_api_offer_hello.c81
85 files changed, 33127 insertions, 33393 deletions
diff --git a/src/transport/communicator.h b/src/transport/communicator.h
index 07f316a68..04a9857e5 100644
--- a/src/transport/communicator.h
+++ b/src/transport/communicator.h
@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
/**
* @file transport/communicator.h
@@ -41,8 +41,7 @@ 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
*/
@@ -89,8 +88,7 @@ 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 c883166c6..a8d692940 100644
--- a/src/transport/gnunet-communicator-tcp.c
+++ b/src/transport/gnunet-communicator-tcp.c
@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
/**
* @file 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
@@ -63,7 +63,7 @@
* Size of our IO buffers for ciphertext data. Must be at
* least UINT_MAX + sizeof (struct TCPBox).
*/
-#define BUF_SIZE (2 * 64 * 1024 + sizeof (struct TCPBox))
+#define BUF_SIZE (2 * 64 * 1024 + sizeof(struct TCPBox))
/**
* How often do we rekey based on time (at least)
@@ -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,8 +107,7 @@ 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
*/
@@ -140,8 +139,7 @@ struct TcpHandshakeSignature
/**
* Encrypted continuation of TCP initial handshake.
*/
-struct TCPConfirmation
-{
+struct TCPConfirmation {
/**
* Sender's identity
*/
@@ -163,9 +161,7 @@ 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
@@ -193,9 +189,7 @@ 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.
*/
@@ -234,9 +228,7 @@ 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.
*/
@@ -260,9 +252,7 @@ GNUNET_NETWORK_STRUCT_END
/**
* Handle for a queue.
*/
-struct Queue
-{
-
+struct Queue {
/**
* To whom are we talking to.
*/
@@ -360,12 +350,12 @@ struct Queue
/**
* Plaintext buffer for decrypted plaintext.
*/
- char pread_buf[UINT16_MAX + 1 + sizeof (struct TCPBox)];
+ char pread_buf[UINT16_MAX + 1 + sizeof(struct TCPBox)];
/**
* Plaintext buffer for messages to be encrypted.
*/
- char pwrite_buf[UINT16_MAX + 1 + sizeof (struct TCPBox)];
+ char pwrite_buf[UINT16_MAX + 1 + sizeof(struct TCPBox)];
/**
* At which offset in the ciphertext read buffer should we
@@ -440,9 +430,7 @@ 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.
*/
@@ -565,7 +553,7 @@ static struct ProtoQueue *proto_tail;
* @param cls NULL
*/
static void
-listen_cb (void *cls);
+listen_cb(void *cls);
/**
@@ -576,53 +564,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);
}
@@ -635,24 +623,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);
}
@@ -663,23 +651,23 @@ 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));
- queue->pwrite_off = 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
more data, and that #queue_write() will call
- #queue_destroy() once the @c fin was fully written. */
+ #queue_destroy() once the @c fin was fully written. */
queue->finishing = GNUNET_YES;
}
@@ -692,10 +680,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);
}
@@ -705,7 +693,7 @@ reschedule_queue_timeout (struct Queue *queue)
* @param cls the `struct Queue *` to disconnect
*/
static void
-queue_read (void *cls);
+queue_read(void *cls);
/**
@@ -716,31 +704,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);
}
@@ -754,34 +742,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);
}
@@ -795,51 +783,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));
}
@@ -850,13 +838,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);
}
@@ -869,30 +857,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);
}
@@ -904,86 +892,89 @@ 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;
uint16_t type;
size_t size = 0; /* make compiler happy */
- if (sizeof (*hdr) > queue->pread_off)
+ 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)))
- {
- 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;
- 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);
+ 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;
+
+ 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;
+
+ default:
+ GNUNET_break_op(0);
+ queue_finish(queue);
return 0;
}
- /* handle FINISH by destroying queue */
- queue_destroy (queue);
- break;
- default:
- GNUNET_break_op (0);
- queue_finish (queue);
- return 0;
- }
- GNUNET_assert (0 != size);
+ GNUNET_assert(0 != size);
return size;
}
@@ -994,96 +985,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))
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv");
- queue_finish (queue);
+ 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);
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)) &&
+ 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;
+ 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;
}
- 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)
{
- /* continue reading */
- queue->read_task =
- GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
+ if (max_queue_length < queue->backpressure)
+ {
+ /* continue reading */
+ queue->read_task =
+ GNUNET_SCHEDULER_add_read_net(left, queue->sock, &queue_read, queue);
+ }
+ return;
}
- 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);
+ 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);
}
@@ -1095,7 +1086,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;
@@ -1103,88 +1094,88 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
char *colon;
char *cp;
- if (1 == sscanf (bindto, "%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);
- 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;
- }
- 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))
+ if (1 == sscanf(bindto, "%u%1s", &port, dummy))
{
/* interpreting value as just a PORT number */
if (port > UINT16_MAX)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "BINDTO specification `%s' invalid: value too large for port\n",
- bindto);
- GNUNET_free (cp);
- return NULL;
- }
+ {
+ GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
+ "BINDTO specification `%s' invalid: value too large for port\n",
+ bindto);
+ 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;
}
- else
+ cp = GNUNET_strdup(bindto);
+ colon = strrchr(cp, ':');
+ if (NULL != colon)
{
- GNUNET_log (
- GNUNET_ERROR_TYPE_ERROR,
- "BINDTO specification `%s' invalid: last ':' not followed by number\n",
- bindto);
- GNUNET_free (cp);
- return NULL;
+ /* 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;
+ }
}
- }
else
- {
- /* interpret missing port as 0, aka pick any free one */
- port = 0;
- }
+ {
+ /* 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 */
@@ -1192,22 +1183,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;
}
@@ -1219,17 +1210,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);
}
@@ -1240,32 +1231,32 @@ 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));
- queue->pwrite_off = 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);
}
@@ -1276,79 +1267,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;
+ 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);
+ }
}
- 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);
- }
- }
/* 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);
}
@@ -1361,32 +1352,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));
- queue->pread_off += sizeof (box);
- memcpy (&queue->pread_buf[queue->pread_off], msg, msize);
+ 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);
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);
}
@@ -1399,15 +1390,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);
+ }
}
@@ -1418,11 +1409,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;
}
@@ -1437,15 +1428,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);
}
@@ -1457,56 +1448,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);
}
}
@@ -1522,34 +1515,34 @@ 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));
- queue->cwrite_off = 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)));
- queue->cwrite_off += 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);
}
@@ -1561,15 +1554,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);
}
@@ -1585,31 +1578,31 @@ 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
+ /* 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);
}
@@ -1619,12 +1612,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);
}
@@ -1635,7 +1628,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;
@@ -1644,67 +1637,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))
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv");
- free_proto_queue (pq);
+ 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);
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;
- }
+ 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;
+ }
/* 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,
+ 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,
queue->sock,
- &queue_read,
+ &queue_write,
queue);
- 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);
+ GNUNET_CONTAINER_DLL_remove(proto_head, proto_tail, pq);
+ GNUNET_free(pq);
}
@@ -1716,7 +1709,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;
@@ -1724,35 +1717,35 @@ listen_cb (void *cls)
struct ProtoQueue *pq;
listen_task = NULL;
- GNUNET_assert (NULL != listen_sock);
- addrlen = sizeof (in);
- memset (&in, 0, sizeof (in));
- sock = GNUNET_NETWORK_socket_accept (listen_sock,
- (struct sockaddr *) &in,
- &addrlen);
+ GNUNET_assert(NULL != listen_sock);
+ addrlen = sizeof(in);
+ 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);
}
@@ -1764,7 +1757,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;
@@ -1772,65 +1765,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))
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv");
- queue_destroy (queue);
+ 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);
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);
}
@@ -1853,7 +1846,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;
@@ -1861,54 +1854,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,
+ 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,
queue->sock,
- &queue_read_kx,
+ &queue_write,
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;
}
@@ -1922,15 +1915,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;
}
@@ -1941,47 +1934,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;
+ }
}
@@ -1997,14 +1990,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);
}
@@ -2022,39 +2015,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;
+ }
}
@@ -2067,10 +2060,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;
@@ -2078,113 +2071,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;
+ 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;
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,
- 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,
+ 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);
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 */);
}
@@ -2196,25 +2189,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};
+ 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))
- ? 0
- : 1;
- GNUNET_free ((void *) argv);
+ ret = (GNUNET_OK == GNUNET_PROGRAM_run(argc,
+ argv,
+ "gnunet-communicator-tcp",
+ _("GNUnet TCP communicator"),
+ options,
+ &run,
+ NULL))
+ ? 0
+ : 1;
+ GNUNET_free((void *)argv);
return ret;
}
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c
index 2c8893d75..228540b81 100644
--- a/src/transport/gnunet-communicator-udp.c
+++ b/src/transport/gnunet-communicator-udp.c
@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
/**
* @file 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,8 +156,7 @@ 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
*/
@@ -190,9 +189,7 @@ struct UdpHandshakeSignature
* "Plaintext" header at beginning of KX message. Followed
* by encrypted `struct UDPConfirmation`.
*/
-struct InitialKX
-{
-
+struct InitialKX {
/**
* Ephemeral key for KX.
*/
@@ -210,8 +207,7 @@ struct InitialKX
* Encrypted continuation of UDP initial handshake, followed
* by message header with payload.
*/
-struct UDPConfirmation
-{
+struct UDPConfirmation {
/**
* Sender's identity
*/
@@ -238,9 +234,7 @@ 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.
*/
@@ -267,8 +261,7 @@ 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
*/
@@ -292,9 +285,7 @@ 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.
*/
@@ -312,9 +303,7 @@ 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
@@ -347,9 +336,7 @@ 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.
*/
@@ -396,8 +383,7 @@ struct ReceiverAddress;
/**
* Shared secret we generated for a particular sender or receiver.
*/
-struct SharedSecret
-{
+struct SharedSecret {
/**
* Kept in a DLL.
*/
@@ -462,9 +448,7 @@ 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.
*/
@@ -516,9 +500,7 @@ 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.
*/
@@ -596,9 +578,7 @@ struct ReceiverAddress
/**
* Interface we broadcast our presence on.
*/
-struct BroadcastInterface
-{
-
+struct BroadcastInterface {
/**
* Kept in a DLL.
*/
@@ -759,25 +739,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)))
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
+ /* 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_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);
}
@@ -787,35 +767,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);
}
@@ -825,16 +805,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);
}
@@ -846,24 +826,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);
}
@@ -874,26 +854,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);
}
@@ -903,31 +883,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);
}
@@ -938,18 +918,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);
}
@@ -962,28 +942,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);
}
@@ -993,11 +973,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);
}
@@ -1007,12 +987,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);
}
@@ -1022,7 +1002,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;
@@ -1030,27 +1010,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);
}
@@ -1060,20 +1040,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);
}
@@ -1086,36 +1066,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);
}
@@ -1128,20 +1108,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));
}
@@ -1158,29 +1138,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;
}
@@ -1192,12 +1172,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;
}
@@ -1210,20 +1190,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;
}
@@ -1236,7 +1216,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);
/**
@@ -1250,36 +1230,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)))
{
- 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)
+ if (0 == memcmp(&ack->cmac, &ss->cmac, sizeof(struct GNUNET_HashCode)))
{
- /* we just incremented from zero => MTU change! */
- setup_receiver_mq (receiver);
+ 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;
}
- 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;
}
@@ -1293,39 +1273,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)
+ 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);
+ }
}
@@ -1338,29 +1320,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);
+ }
}
@@ -1372,43 +1354,42 @@ 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);
+ 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);
}
/**
* Closure for #find_sender_by_address()
*/
-struct SearchContext
-{
+struct SearchContext {
/**
* Address we are looking for.
*/
@@ -1435,19 +1416,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;
}
@@ -1464,45 +1445,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);
+ struct SearchContext sc = { .address = address,
+ .address_len = address_len,
+ .sender = NULL };
+
+ 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;
}
@@ -1515,21 +1496,21 @@ 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);
}
@@ -1542,28 +1523,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;
}
@@ -1574,137 +1557,137 @@ 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);
+ 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;
-
- box = (const struct UDPBox *) buf;
- kce = GNUNET_CONTAINER_multishortmap_get (key_cache, &box->kid);
- if (NULL != kce)
+ if (rcvd > sizeof(struct UDPBox))
{
- decrypt_box (box, (size_t) rcvd, kce);
- return;
+ 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;
+ }
}
- }
/* 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))
+ if (sizeof(struct UDPBroadcast) == rcvd)
{
- 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;
+ 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... */
}
- /* 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;
- }
+ if (rcvd < sizeof(struct UDPConfirmation) + sizeof(struct InitialKX))
+ {
+ GNUNET_STATISTICS_update(stats,
+ "# messages dropped (no kid, too small for KX)",
+ 1,
+ GNUNET_NO);
+ return;
+ }
{
const struct InitialKX *kx;
struct SharedSecret *ss;
- char pbuf[rcvd - sizeof (struct InitialKX)];
+ char pbuf[rcvd - sizeof(struct InitialKX)];
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);
}
}
@@ -1717,7 +1700,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;
@@ -1725,88 +1708,88 @@ udp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
char *colon;
char *cp;
- if (1 == sscanf (bindto, "%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);
- return NULL;
- }
- if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
- (GNUNET_YES ==
- GNUNET_CONFIGURATION_get_value_yesno (cfg,
- COMMUNICATOR_CONFIG_SECTION,
- "DISABLE_V6")))
+ if (1 == sscanf(bindto, "%u%1s", &port, dummy))
{
- struct sockaddr_in *i4;
+ /* 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;
+ 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;
+ 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;
}
- return in;
- }
- cp = GNUNET_strdup (bindto);
- colon = strrchr (cp, ':');
+ 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))
{
- /* 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;
- }
+ /* 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;
+ }
}
- else
+ else
{
- GNUNET_log (
- GNUNET_ERROR_TYPE_ERROR,
- "BINDTO specification `%s' invalid: last ':' not followed by number\n",
- bindto);
- GNUNET_free (cp);
- return NULL;
+ /* interpret missing port as 0, aka pick any free one */
+ port = 0;
}
- }
- 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 */
@@ -1814,22 +1797,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;
}
@@ -1842,22 +1825,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));
- if (sizeof (pad) > sizeof (struct GNUNET_MessageHeader))
- {
- struct GNUNET_MessageHeader hdr =
- {.size = htons (sizeof (pad)),
- .type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_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) };
- 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)));
}
@@ -1870,123 +1853,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),
+ 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 */
+ 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 */
/* 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)
{
- 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;
+ 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;
+ }
}
- }
- GNUNET_assert (0);
+ GNUNET_assert(0);
}
@@ -1999,15 +1982,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);
+ }
}
@@ -2018,10 +2001,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);
}
@@ -2035,15 +2018,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);
}
@@ -2055,61 +2038,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);
}
@@ -2132,47 +2117,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;
}
@@ -2186,15 +2171,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;
}
@@ -2208,15 +2193,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;
}
@@ -2227,64 +2212,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;
+ }
}
@@ -2298,24 +2283,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);
}
@@ -2333,39 +2318,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;
+ }
}
@@ -2375,67 +2360,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: {
- 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 (-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");
- break;
- }
- case AF_INET6: {
- ssize_t sent;
- struct sockaddr_in6 dst;
-
- dst.sin6_family = AF_INET6;
- 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;
-
- 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");
- break;
- }
- default:
- GNUNET_break (0);
- break;
- }
+ {
+ 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 (-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");
+ break;
+ }
+
+ case AF_INET6: {
+ ssize_t sent;
+ struct sockaddr_in6 dst;
+
+ dst.sin6_family = AF_INET6;
+ 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;
+
+ 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");
+ break;
+ }
+
+ default:
+ GNUNET_break(0);
+ break;
+ }
}
@@ -2454,90 +2441,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)))
{
- bi->found = GNUNET_YES;
- return GNUNET_OK;
+ if ((bi->salen == addrlen) && (0 == memcmp(addr, bi->sa, addrlen)))
+ {
+ 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)))
{
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
+ /* 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");
+ }
}
- }
return GNUNET_OK;
}
@@ -2548,23 +2535,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);
}
@@ -2577,10 +2564,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;
@@ -2588,141 +2575,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;
+ 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;
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_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);
+ {
+ 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;
+
+ 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,
+ 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);
- 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 */);
}
@@ -2734,25 +2723,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};
+ 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))
- ? 0
- : 1;
- GNUNET_free ((void *) argv);
+ ret = (GNUNET_OK == GNUNET_PROGRAM_run(argc,
+ argv,
+ "gnunet-communicator-udp",
+ _("GNUnet UDP communicator"),
+ options,
+ &run,
+ NULL))
+ ? 0
+ : 1;
+ GNUNET_free((void *)argv);
return ret;
}
diff --git a/src/transport/gnunet-communicator-unix.c b/src/transport/gnunet-communicator-unix.c
index cb1fbc230..da610daa1 100644
--- a/src/transport/gnunet-communicator-unix.c
+++ b/src/transport/gnunet-communicator-unix.c
@@ -16,7 +16,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
/**
* @file transport/gnunet-communicator-unix.c
@@ -64,8 +64,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
/**
* UNIX Message-Packet header.
*/
-struct UNIXMessage
-{
+struct UNIXMessage {
/**
* Message header.
*/
@@ -83,9 +82,7 @@ GNUNET_NETWORK_STRUCT_END
/**
* Handle for a queue.
*/
-struct Queue
-{
-
+struct Queue {
/**
* Queues with pending messages (!) are kept in a DLL.
*/
@@ -208,37 +205,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);
}
@@ -248,28 +245,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);
}
@@ -281,11 +278,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);
}
@@ -298,22 +295,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);
- if (slen >= sizeof (un->sun_path))
- slen = sizeof (un->sun_path) - 1;
- GNUNET_memcpy (un->sun_path, unixpath, slen);
+ slen = strlen(unixpath);
+ if (slen >= sizeof(un->sun_path))
+ slen = sizeof(un->sun_path) - 1;
+ GNUNET_memcpy(un->sun_path, unixpath, slen);
un->sun_path[slen] = '\0';
- slen = sizeof (struct sockaddr_un);
+ 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])
@@ -325,8 +322,7 @@ 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.
*/
@@ -353,17 +349,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;
}
@@ -376,18 +372,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;
}
@@ -399,103 +395,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 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);
+ case EAGAIN:
+ case ENOBUFS:
+ /* We should retry later... */
+ GNUNET_log_strerror(GNUNET_ERROR_TYPE_DEBUG, "send");
+ return;
+
+ 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_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);
+ size = ((msg_size / 1000) + 2) * 1000;
+ 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)))
+ goto resend; /* Increased buffer size, retry sending */
+ /* Could not increase buffer size: error, no retry */
+ GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "setsockopt");
+ return;
+ }
+
+ default:
+ GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "send");
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);
- size = ((msg_size / 1000) + 2) * 1000;
- 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)))
- goto resend; /* Increased buffer size, retry sending */
- /* Could not increase buffer size: error, no retry */
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt");
- return;
- }
- default:
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "send");
- return;
- }
}
@@ -508,22 +506,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);
}
@@ -536,15 +534,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);
+ }
}
@@ -555,19 +553,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;
+ }
}
@@ -581,15 +579,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);
}
@@ -604,60 +602,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;
}
@@ -671,7 +669,7 @@ setup_queue (const struct GNUNET_PeerIdentity *target,
* @param cls NULL
*/
static void
-select_read_cb (void *cls);
+select_read_cb(void *cls);
/**
@@ -682,21 +680,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);
}
@@ -708,7 +706,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;
@@ -718,93 +716,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);
- addrlen = sizeof (un);
- memset (&un, 0, sizeof (un));
- ret = GNUNET_NETWORK_socket_recvfrom (unix_sock,
- buf,
- sizeof (buf),
- (struct sockaddr *) &un,
- &addrlen);
+ 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);
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);
- if ((msize < sizeof (struct UNIXMessage)) || (msize > ret))
- {
- GNUNET_break_op (0);
- return;
- }
- queue = lookup_queue (&msg->sender, &un, addrlen);
+ {
+ 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);
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];
+ uint16_t tsize = msize - sizeof(struct UNIXMessage);
+ 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))
+ while (offset + sizeof(struct GNUNET_MessageHeader) <= tsize)
{
- GNUNET_break_op (0);
- break;
+ 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;
}
- 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;
+ }
}
@@ -826,43 +824,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;
}
@@ -876,15 +874,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;
}
@@ -895,40 +893,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;
+ }
}
@@ -944,14 +942,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);
}
@@ -964,109 +962,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,
+ (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);
- 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);
}
@@ -1078,26 +1077,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};
+ 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))
- ? 0
- : 1;
- GNUNET_free ((void *) argv);
+ GNUNET_PROGRAM_run(argc,
+ argv,
+ "gnunet-communicator-unix",
+ _("GNUnet UNIX domain socket communicator"),
+ options,
+ &run,
+ NULL))
+ ? 0
+ : 1;
+ GNUNET_free((void *)argv);
return ret;
}
@@ -1108,11 +1108,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 217022190..2ac705996 100644
--- a/src/transport/gnunet-helper-transport-bluetooth.c
+++ b/src/transport/gnunet-helper-transport-bluetooth.c
@@ -13,12 +13,12 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
#include "gnunet_config.h"
#ifdef MINGW
@@ -68,32 +68,31 @@
#define MAX_LOOPS 5
#ifdef MINGW
- /* Maximum size of the interface's name */
+/* Maximum size of the interface's name */
#define IFNAMSIZ 16
#ifndef NS_BTH
#define NS_BTH 16
#endif
- /**
- * A copy of the MAC Address.
- */
- struct GNUNET_TRANSPORT_WLAN_MacAddress_Copy
- {
- UINT8 mac[MAC_ADDR_SIZE];
- };
+/**
+ * A copy of the MAC Address.
+ */
+struct GNUNET_TRANSPORT_WLAN_MacAddress_Copy {
+ UINT8 mac[MAC_ADDR_SIZE];
+};
- /**
- * The UUID used for the SDP service.
- * {31191E56-FA7E-4517-870E-71B86BBCC52F}
- */
+/**
+ * The UUID used for the SDP service.
+ * {31191E56-FA7E-4517-870E-71B86BBCC52F}
+ */
#define GNUNET_BLUETOOTH_SDP_UUID \
- { \
- 0x31, 0x19, 0x1E, 0x56, \
- 0xFA, 0x7E, \
- 0x45, 0x17, \
- 0x87, 0x0E, \
- 0x71, 0xB8, 0x6B, 0xBC, 0xC5, 0x2F \
- }
+ { \
+ 0x31, 0x19, 0x1E, 0x56, \
+ 0xFA, 0x7E, \
+ 0x45, 0x17, \
+ 0x87, 0x0E, \
+ 0x71, 0xB8, 0x6B, 0xBC, 0xC5, 0x2F \
+ }
#endif
/**
@@ -105,8 +104,7 @@
* 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 (!).
*/
@@ -136,15 +134,14 @@ struct HardwareInfos
/**
* SDP session
*/
- sdp_session_t *session ;
+ sdp_session_t *session;
#endif
};
/**
* 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'.
@@ -165,40 +162,39 @@ struct SendBuffer
};
#ifdef LINUX
- /**
- * 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
- {
- /* List with the discoverable devices' addresses */
- bdaddr_t devices[MAX_PORTS];
+/**
+ * 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 {
+ /* List with the discoverable devices' addresses */
+ bdaddr_t devices[MAX_PORTS];
- /* List with the open sockets */
- int fds[MAX_PORTS];
+ /* List with the open sockets */
+ int fds[MAX_PORTS];
- /* The number of the devices */
- int size;
+ /* The number of the devices */
+ int size;
- /* The current position */
- int pos;
+ /* The current position */
+ int pos;
- /* The device id */
- int dev_id;
- };
+ /* The device id */
+ int dev_id;
+};
- /**
- * Address used to identify the broadcast messages.
- */
- static struct GNUNET_TRANSPORT_WLAN_MacAddress broadcast_address = {{255, 255, 255, 255, 255, 255}};
+/**
+ * Address used to identify the broadcast messages.
+ */
+static struct GNUNET_TRANSPORT_WLAN_MacAddress broadcast_address = { { 255, 255, 255, 255, 255, 255 } };
- /**
- * Buffer with the discoverable devices.
- */
- static struct BroadcastMessages neighbours;
+/**
+ * Buffer with the discoverable devices.
+ */
+static struct BroadcastMessages neighbours;
- static int searching_devices_count = 0;
+static int searching_devices_count = 0;
#endif
/**
@@ -223,7 +219,7 @@ static struct SendBuffer write_std;
/**
* Smallest supported message.
*/
-#define MIN_BUFFER_SIZE sizeof (struct GNUNET_MessageHeader)
+#define MIN_BUFFER_SIZE sizeof(struct GNUNET_MessageHeader)
/**
@@ -234,16 +230,14 @@ static struct SendBuffer write_std;
* @param message the actual message
*/
typedef void (*MessageTokenizerCallback) (void *cls,
- const struct
- GNUNET_MessageHeader *
- message);
+ const struct
+ GNUNET_MessageHeader *
+ message);
/**
* Handle to a message stream tokenizer.
*/
-struct MessageStreamTokenizer
-{
-
+struct MessageStreamTokenizer {
/**
* Function to call on completed messages.
*/
@@ -273,7 +267,6 @@ struct MessageStreamTokenizer
* Beginning of the buffer. Typed like this to force alignment.
*/
struct GNUNET_MessageHeader *hdr;
-
};
@@ -285,23 +278,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;
@@ -322,8 +315,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;
@@ -334,161 +327,161 @@ 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;
+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;
+ }
}
- hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
- want = ntohs (hdr->size);
- if (want < sizeof (struct GNUNET_MessageHeader))
+ if (0 != mst->pos)
{
- fprintf (stderr,
- "Received invalid message from stdin\n");
+ fprintf(stderr, "There should some valid bytes in the buffer on this stage\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)
- {
- /* 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 < 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;
+ }
}
- }
if (size > 0)
- {
- 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);
+ 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;
}
- GNUNET_memcpy (&ibuf[mst->pos], buf, size);
- mst->pos += size;
- }
return ret;
}
@@ -498,10 +491,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);
}
/**
@@ -512,7 +505,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,
@@ -585,7 +578,7 @@ calc_crc_osdep (const unsigned char *buf, size_t len)
for (; len > 0; len--, buf++)
crc = crc_tbl_osdep[(crc ^ *buf) & 0xFF] ^ (crc >> 8);
- return (~crc);
+ return(~crc);
}
@@ -598,11 +591,11 @@ 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])
@@ -615,402 +608,409 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
/* ************** end of clone ***************** */
#ifdef MINGW
- /**
- * Function used to get the code of last error and to print the type of error.
- */
- static void
- print_last_error()
- {
- LPVOID lpMsgBuf = NULL;
+/**
+ * Function used to get the code of last error and to print the type of error.
+ */
+static void
+print_last_error()
+{
+ LPVOID lpMsgBuf = NULL;
- if (FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, GetLastError(), 0, (LPTSTR) &lpMsgBuf, 0, NULL))
- fprintf (stderr, "%s\n", (char *)lpMsgBuf);
- else
- fprintf (stderr, "Failed to format the message for the last error! Error number : %d\n", GetLastError());
- }
+ if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL, GetLastError(), 0, (LPTSTR)&lpMsgBuf, 0, NULL))
+ fprintf(stderr, "%s\n", (char *)lpMsgBuf);
+ else
+ fprintf(stderr, "Failed to format the message for the last error! Error number : %d\n", GetLastError());
+}
- /**
- * Function used to initialize the Windows Sockets
- */
- static void
- initialize_windows_sockets()
- {
- WSADATA wsaData ;
- WORD wVersionRequested = MAKEWORD (2, 0);
- if (WSAStartup (wVersionRequested, &wsaData) != NO_ERROR)
+/**
+ * Function used to initialize the Windows Sockets
+ */
+static void
+initialize_windows_sockets()
+{
+ WSADATA wsaData;
+ WORD wVersionRequested = MAKEWORD(2, 0);
+
+ if (WSAStartup(wVersionRequested, &wsaData) != NO_ERROR)
{
- fprintf (stderr , "Error initializing window sockets!\n");
+ fprintf(stderr, "Error initializing window sockets!\n");
print_last_error();
- ExitProcess (2) ;
+ ExitProcess(2);
}
- }
+}
- /**
- * Function used to convert the GUID.
- * @param bytes the GUID represented as a char array
- * @param uuid pointer to the GUID
- */
- static void
- convert_guid(char *bytes, GUID * uuid)
- {
- int i;
- uuid->Data1 = ((bytes[0] << 24) & 0xff000000) | ((bytes[1] << 16) & 0x00ff0000) | ((bytes[2] << 8) & 0x0000ff00) | (bytes[3] & 0x000000ff);
- uuid->Data2 = ((bytes[4] << 8) & 0xff00) | (bytes[5] & 0x00ff);
- uuid->Data3 = ((bytes[6] << 8) & 0xff00) | (bytes[7] & 0x00ff);
+/**
+ * Function used to convert the GUID.
+ * @param bytes the GUID represented as a char array
+ * @param uuid pointer to the GUID
+ */
+static void
+convert_guid(char *bytes, GUID * uuid)
+{
+ int i;
+
+ uuid->Data1 = ((bytes[0] << 24) & 0xff000000) | ((bytes[1] << 16) & 0x00ff0000) | ((bytes[2] << 8) & 0x0000ff00) | (bytes[3] & 0x000000ff);
+ uuid->Data2 = ((bytes[4] << 8) & 0xff00) | (bytes[5] & 0x00ff);
+ uuid->Data3 = ((bytes[6] << 8) & 0xff00) | (bytes[7] & 0x00ff);
- for (i = 0; i < 8; i++)
+ for (i = 0; i < 8; i++)
{
uuid->Data4[i] = bytes[i + 8];
}
- }
+}
#endif
#ifdef LINUX
- /**
- * Function for assigning a port number
- *
- * @param socket the socket used to bind
- * @param addr pointer to the rfcomm address
- * @return 0 on success
- */
- static int
- bind_socket (int socket, struct sockaddr_rc *addr)
- {
- int port, status;
+/**
+ * Function for assigning a port number
+ *
+ * @param socket the socket used to bind
+ * @param addr pointer to the rfcomm address
+ * @return 0 on success
+ */
+static int
+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 :)
- for (port = 3; port <= 30; port++)
+ /* 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 :)
+ for (port = 3; port <= 30; port++)
{
addr->rc_channel = port;
- status = bind (socket, (struct sockaddr *) addr, sizeof (struct sockaddr_rc));
+ status = bind(socket, (struct sockaddr *)addr, sizeof(struct sockaddr_rc));
if (status == 0)
return 0;
}
- return -1;
- }
+ return -1;
+}
#endif
#ifdef MINGW
- /**
- * Function used for creating the service record and registering it.
- *
- * @param dev pointer to the device struct
- * @return 0 on success
- */
- static int
- register_service (struct HardwareInfos *dev)
- {
- /* advertise the service */
- CSADDR_INFO addr_info;
- WSAQUERYSET wqs;
- GUID guid;
- unsigned char uuid[] = GNUNET_BLUETOOTH_SDP_UUID;
- SOCKADDR_BTH addr;
- int addr_len = sizeof (SOCKADDR_BTH);
- int fd;
- /* get the port on which we are listening on */
- memset (& addr, 0, sizeof (SOCKADDR_BTH));
- fd = GNUNET_NETWORK_get_fd (dev->handle);
- if (fd <= 0)
+/**
+ * Function used for creating the service record and registering it.
+ *
+ * @param dev pointer to the device struct
+ * @return 0 on success
+ */
+static int
+register_service(struct HardwareInfos *dev)
+{
+ /* advertise the service */
+ CSADDR_INFO addr_info;
+ WSAQUERYSET wqs;
+ GUID guid;
+ unsigned char uuid[] = GNUNET_BLUETOOTH_SDP_UUID;
+ SOCKADDR_BTH addr;
+ int addr_len = sizeof(SOCKADDR_BTH);
+ int fd;
+
+ /* get the port on which we are listening on */
+ memset(&addr, 0, sizeof(SOCKADDR_BTH));
+ fd = GNUNET_NETWORK_get_fd(dev->handle);
+ if (fd <= 0)
{
- fprintf (stderr, "Failed to get the file descriptor\n");
+ fprintf(stderr, "Failed to get the file descriptor\n");
return -1;
}
- if (SOCKET_ERROR == getsockname (fd, (SOCKADDR*)&addr, &addr_len))
+ if (SOCKET_ERROR == getsockname(fd, (SOCKADDR*)&addr, &addr_len))
{
- fprintf (stderr, "Failed to get the port on which we are listening on: \n");
+ fprintf(stderr, "Failed to get the port on which we are listening on: \n");
print_last_error();
return -1;
}
- /* save the device address */
- GNUNET_memcpy (&dev->pl_mac, &addr.btAddr, sizeof (BTH_ADDR));
-
- /* set the address information */
- memset (&addr_info, 0, sizeof (CSADDR_INFO));
- addr_info.iProtocol = BTHPROTO_RFCOMM;
- addr_info.iSocketType = SOCK_STREAM;
- addr_info.LocalAddr.lpSockaddr = (LPSOCKADDR)&addr;
- addr_info.LocalAddr.iSockaddrLength = sizeof (addr);
- addr_info.RemoteAddr.lpSockaddr = (LPSOCKADDR)&addr;
- addr_info.RemoteAddr.iSockaddrLength = sizeof (addr);
-
- convert_guid((char *) uuid, &guid);
-
- /* register the service */
- memset (&wqs, 0, sizeof (WSAQUERYSET));
- wqs.dwSize = sizeof (WSAQUERYSET);
- wqs.dwNameSpace = NS_BTH;
- wqs.lpszServiceInstanceName = "GNUnet Bluetooth Service";
- wqs.lpszComment = "This is the service used by the GNUnnet plugin transport";
- wqs.lpServiceClassId = &guid;
- wqs.dwNumberOfCsAddrs = 1;
- wqs.lpcsaBuffer = &addr_info ;
- wqs.lpBlob = 0;
-
- if (SOCKET_ERROR == WSASetService (&wqs , RNRSERVICE_REGISTER, 0))
+ /* save the device address */
+ GNUNET_memcpy(&dev->pl_mac, &addr.btAddr, sizeof(BTH_ADDR));
+
+ /* set the address information */
+ memset(&addr_info, 0, sizeof(CSADDR_INFO));
+ addr_info.iProtocol = BTHPROTO_RFCOMM;
+ addr_info.iSocketType = SOCK_STREAM;
+ addr_info.LocalAddr.lpSockaddr = (LPSOCKADDR)&addr;
+ addr_info.LocalAddr.iSockaddrLength = sizeof(addr);
+ addr_info.RemoteAddr.lpSockaddr = (LPSOCKADDR)&addr;
+ addr_info.RemoteAddr.iSockaddrLength = sizeof(addr);
+
+ convert_guid((char *)uuid, &guid);
+
+ /* register the service */
+ memset(&wqs, 0, sizeof(WSAQUERYSET));
+ wqs.dwSize = sizeof(WSAQUERYSET);
+ wqs.dwNameSpace = NS_BTH;
+ wqs.lpszServiceInstanceName = "GNUnet Bluetooth Service";
+ wqs.lpszComment = "This is the service used by the GNUnnet plugin transport";
+ wqs.lpServiceClassId = &guid;
+ wqs.dwNumberOfCsAddrs = 1;
+ wqs.lpcsaBuffer = &addr_info;
+ wqs.lpBlob = 0;
+
+ if (SOCKET_ERROR == WSASetService(&wqs, RNRSERVICE_REGISTER, 0))
{
- fprintf (stderr, "Failed to register the SDP service: ");
+ fprintf(stderr, "Failed to register the SDP service: ");
print_last_error();
return -1;
}
- else
+ else
{
- fprintf (stderr, "The SDP service was registered\n");
+ fprintf(stderr, "The SDP service was registered\n");
}
- return 0;
- }
+ return 0;
+}
#else
+/**
+ * Function used for creating the service record and registering it.
+ *
+ * @param dev pointer to the device struct
+ * @param rc_channel the rfcomm channel
+ * @return 0 on success
+ */
+static int
+register_service(struct HardwareInfos *dev, int rc_channel)
+{
/**
- * Function used for creating the service record and registering it.
- *
- * @param dev pointer to the device struct
- * @param rc_channel the rfcomm channel
- * @return 0 on success
+ * 1. initializations
+ * 2. set the service ID, class, profile information
+ * 3. make the service record publicly browsable
+ * 4. register the RFCOMM channel
+ * 5. set the name, provider and description
+ * 6. register the service record to the local SDP server
+ * 7. cleanup
*/
- static int
- register_service (struct HardwareInfos *dev, int rc_channel)
- {
- /**
- * 1. initializations
- * 2. set the service ID, class, profile information
- * 3. make the service record publicly browsable
- * 4. register the RFCOMM channel
- * 5. set the name, provider and description
- * 6. register the service record to the local SDP server
- * 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]};
- const char *service_dsc = "Bluetooth plugin services";
- const char *service_prov = "GNUnet provider";
- uuid_t root_uuid, rfcomm_uuid, svc_uuid;
- sdp_list_t *root_list = 0, *rfcomm_list = 0, *proto_list = 0,
- *access_proto_list = 0, *svc_list = 0;
- sdp_record_t *record = 0;
- sdp_data_t *channel = 0;
-
- 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);
-
- /* 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);
-
- /* 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);
-
- /* Set protocol information */
- 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);
-
- /* Connect to the local SDP server */
- dev->session = sdp_connect (BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY);
-
- if (!dev->session)
+ 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] };
+ const char *service_dsc = "Bluetooth plugin services";
+ const char *service_prov = "GNUnet provider";
+ uuid_t root_uuid, rfcomm_uuid, svc_uuid;
+ sdp_list_t *root_list = 0, *rfcomm_list = 0, *proto_list = 0,
+ *access_proto_list = 0, *svc_list = 0;
+ sdp_record_t *record = 0;
+ sdp_data_t *channel = 0;
+
+ 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);
+
+ /* 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);
+
+ /* 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);
+
+ /* Set protocol information */
+ 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);
+
+ /* Connect to the local SDP server */
+ 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));
+ 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)
+ /* 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));
+ 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);
+ /* 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);
- return 0;
- }
+ return 0;
+}
#endif
#ifdef MINGW
- /**
- * Function for searching and browsing for a service. This will return the
- * port number on which the service is running.
- *
- * @param dest target address
- * @return channel
- */
- static int
- get_channel(const char *dest)
- {
- HANDLE h;
- WSAQUERYSET *wqs;
- DWORD wqs_len = sizeof (WSAQUERYSET);
- int done = 0;
- int channel = -1;
- GUID guid;
- unsigned char uuid[] = GNUNET_BLUETOOTH_SDP_UUID;
- convert_guid ((char *) uuid, &guid);
-
- wqs = (WSAQUERYSET*)malloc (wqs_len);
- ZeroMemory (wqs, wqs_len);
-
- wqs->dwSize = sizeof (WSAQUERYSET) ;
- wqs->lpServiceClassId = &guid;
- wqs->dwNameSpace = NS_BTH;
- wqs->dwNumberOfCsAddrs = 0;
- wqs->lpszContext = (LPSTR)dest;
-
- if (SOCKET_ERROR == WSALookupServiceBegin (wqs, LUP_FLUSHCACHE | LUP_RETURN_ALL, &h))
+/**
+ * Function for searching and browsing for a service. This will return the
+ * port number on which the service is running.
+ *
+ * @param dest target address
+ * @return channel
+ */
+static int
+get_channel(const char *dest)
+{
+ HANDLE h;
+ WSAQUERYSET *wqs;
+ DWORD wqs_len = sizeof(WSAQUERYSET);
+ int done = 0;
+ int channel = -1;
+ GUID guid;
+ unsigned char uuid[] = GNUNET_BLUETOOTH_SDP_UUID;
+
+ convert_guid((char *)uuid, &guid);
+
+ wqs = (WSAQUERYSET*)malloc(wqs_len);
+ ZeroMemory(wqs, wqs_len);
+
+ wqs->dwSize = sizeof(WSAQUERYSET);
+ wqs->lpServiceClassId = &guid;
+ wqs->dwNameSpace = NS_BTH;
+ wqs->dwNumberOfCsAddrs = 0;
+ wqs->lpszContext = (LPSTR)dest;
+
+ if (SOCKET_ERROR == WSALookupServiceBegin(wqs, LUP_FLUSHCACHE | LUP_RETURN_ALL, &h))
{
if (GetLastError() == WSASERVICE_NOT_FOUND)
- {
- fprintf (stderr, "WARNING! The device with address %s wasn't found. Skipping the message!", dest);
- return -1;
- }
+ {
+ fprintf(stderr, "WARNING! The device with address %s wasn't found. Skipping the message!", dest);
+ return -1;
+ }
else
- {
- fprintf (stderr, "Failed to find the port number: ");
- print_last_error();
- ExitProcess (2);
- return -1;
- }
+ {
+ fprintf(stderr, "Failed to find the port number: ");
+ print_last_error();
+ ExitProcess(2);
+ return -1;
+ }
}
- /* search the sdp service */
- while (!done)
+ /* search the sdp service */
+ while (!done)
{
- if (SOCKET_ERROR == WSALookupServiceNext (h, LUP_FLUSHCACHE | LUP_RETURN_ALL, &wqs_len, wqs))
- {
- int error = WSAGetLastError();
-
- switch (error)
+ if (SOCKET_ERROR == WSALookupServiceNext(h, LUP_FLUSHCACHE | LUP_RETURN_ALL, &wqs_len, wqs))
{
- case WSAEFAULT:
- free (wqs);
- wqs = (WSAQUERYSET*)malloc (wqs_len);
- break;
- case WSANO_DATA:
- fprintf (stderr, "Failed! The address was valid but there was no data record of requested type\n");
- done = 1;
- break;
- case WSA_E_NO_MORE:
- done = 1;
- break;
- default:
- fprintf (stderr, "Failed to look over the services: ");
- print_last_error();
- WSALookupServiceEnd (h);
- ExitProcess (2);
+ int error = WSAGetLastError();
+
+ switch (error)
+ {
+ case WSAEFAULT:
+ free(wqs);
+ wqs = (WSAQUERYSET*)malloc(wqs_len);
+ break;
+
+ case WSANO_DATA:
+ fprintf(stderr, "Failed! The address was valid but there was no data record of requested type\n");
+ done = 1;
+ break;
+
+ case WSA_E_NO_MORE:
+ done = 1;
+ break;
+
+ default:
+ fprintf(stderr, "Failed to look over the services: ");
+ print_last_error();
+ WSALookupServiceEnd(h);
+ ExitProcess(2);
+ }
}
- }
else
- {
- channel = ((SOCKADDR_BTH*)wqs->lpcsaBuffer->RemoteAddr.lpSockaddr)->port;
- }
+ {
+ channel = ((SOCKADDR_BTH*)wqs->lpcsaBuffer->RemoteAddr.lpSockaddr)->port;
+ }
}
- free (wqs) ;
- WSALookupServiceEnd (h);
+ free(wqs);
+ WSALookupServiceEnd(h);
- return channel;
- }
+ return channel;
+}
#else
+/**
+ * Function used for searching and browsing for a service. This will return the
+ * port number on which the service is running.
+ *
+ * @param dev pointer to the device struct
+ * @param dest target address
+ * @return channel
+ */
+static int
+get_channel(struct HardwareInfos *dev, bdaddr_t dest)
+{
/**
- * Function used for searching and browsing for a service. This will return the
- * port number on which the service is running.
- *
- * @param dev pointer to the device struct
- * @param dest target address
- * @return channel
+ * 1. detect all nearby devices
+ * 2. for each device:
+ * 2.1. connect to the SDP server running
+ * 2.2. get a list of service records with the specific UUID
+ * 2.3. for each service record get a list of the protocol sequences and get
+ * the port number
*/
- static int
- get_channel(struct HardwareInfos *dev, bdaddr_t dest)
- {
- /**
- * 1. detect all nearby devices
- * 2. for each device:
- * 2.1. connect to the SDP server running
- * 2.2. get a list of service records with the specific UUID
- * 2.3. for each service record get a list of the protocol sequences and get
- * the port number
- */
- uint8_t svc_uuid_int[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ uint8_t svc_uuid_int[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
dest.b[5], dest.b[4], dest.b[3],
- dest.b[2], dest.b[1], dest.b[0]};
- sdp_session_t *session = 0;
- sdp_list_t *search_list = 0, *attrid_list = 0, *response_list = 0, *it = 0;
- uuid_t svc_uuid;
- uint32_t range = 0x0000ffff;
- int channel = -1;
-
- /* Connect to the local SDP server */
- session = sdp_connect (BDADDR_ANY, &dest, 0);
- if (!session)
+ dest.b[2], dest.b[1], dest.b[0] };
+ sdp_session_t *session = 0;
+ sdp_list_t *search_list = 0, *attrid_list = 0, *response_list = 0, *it = 0;
+ uuid_t svc_uuid;
+ uint32_t range = 0x0000ffff;
+ 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;
+ 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)
- {
- 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_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_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));
+ if (-1 == channel)
+ fprintf(stderr,
+ "Failed to find the listening channel for interface `%.*s': %s\n",
+ IFNAMSIZ,
+ dev->iface,
+ strerror(errno));
- return channel;
- }
+ return channel;
+}
#endif
/**
@@ -1024,56 +1024,56 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
* @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;
#ifdef MINGW
- count = GNUNET_NETWORK_socket_recv ((struct GNUNET_NETWORK_Handle *)sock, tmpbuf, buf_size);
+ count = GNUNET_NETWORK_socket_recv((struct GNUNET_NETWORK_Handle *)sock, tmpbuf, buf_size);
#else
- count = read (*((int *)sock), tmpbuf, buf_size);
+ count = read(*((int *)sock), tmpbuf, buf_size);
#endif
if (0 > count)
- {
- if (EAGAIN == errno)
- return 0;
+ {
+ if (EAGAIN == errno)
+ return 0;
#if MINGW
- print_last_error();
+ print_last_error();
#else
- 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));
#endif
- 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));
- 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;
- }
-
- memset (ri, 0, sizeof (*ri));
- ri->ri_channel = rc_addr.rc_channel;
+ /* Get the channel used */
+ int len;
+ struct sockaddr_rc rc_addr = { 0 };
+
+ 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;
+ }
+
+ 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;
}
@@ -1086,204 +1086,199 @@ 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)
{
#ifdef MINGW
- SOCKADDR_BTH addr;
+ SOCKADDR_BTH addr;
- /* bind the RFCOMM socket to the interface */
- addr.addressFamily = AF_BTH;
- addr.btAddr = 0;
- addr.port = BT_PORT_ANY;
+ /* bind the RFCOMM socket to the interface */
+ addr.addressFamily = AF_BTH;
+ addr.btAddr = 0;
+ addr.port = BT_PORT_ANY;
- if (GNUNET_OK !=
- GNUNET_NETWORK_socket_bind (dev->handle, (const SOCKADDR*)&addr, sizeof (SOCKADDR_BTH)))
+ if (GNUNET_OK !=
+ GNUNET_NETWORK_socket_bind(dev->handle, (const SOCKADDR*)&addr, sizeof(SOCKADDR_BTH)))
{
- fprintf (stderr, "Failed to bind the socket: ");
+ fprintf(stderr, "Failed to bind the socket: ");
if (GetLastError() == WSAENETDOWN)
- {
- fprintf (stderr, "Please make sure that your Bluetooth device is ON!\n");
- ExitProcess (2);
- }
+ {
+ fprintf(stderr, "Please make sure that your Bluetooth device is ON!\n");
+ ExitProcess(2);
+ }
print_last_error();
return -1;
}
- /* start listening on the socket */
- if (GNUNET_NETWORK_socket_listen (dev->handle, 4) != GNUNET_OK)
+ /* start listening on the socket */
+ if (GNUNET_NETWORK_socket_listen(dev->handle, 4) != GNUNET_OK)
{
- fprintf (stderr, "Failed to listen on the socket: ");
+ fprintf(stderr, "Failed to listen on the socket: ");
print_last_error();
return -1;
}
- /* register the sdp service */
- if (register_service(dev) != 0)
+ /* register the sdp service */
+ if (register_service(dev) != 0)
{
- fprintf (stderr, "Failed to register a service: ");
+ fprintf(stderr, "Failed to register a service: ");
print_last_error();
return 1;
}
#else
- int i, dev_id = -1, fd_hci;
- 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
-
- /* Initialize the neighbour structure */
- neighbours.dev_id = -1;
- for (i = 0; i < MAX_PORTS; i++)
- neighbours.fds[i] = -1;
-
- /* Open a HCI socket */
- fd_hci = socket (AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
-
- if (fd_hci < 0)
+ int i, dev_id = -1, fd_hci;
+ 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
+
+ /* Initialize the neighbour structure */
+ neighbours.dev_id = -1;
+ for (i = 0; i < MAX_PORTS; i++)
+ neighbours.fds[i] = -1;
+
+ /* Open a HCI socket */
+ fd_hci = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
+
+ if (fd_hci < 0)
{
- fprintf (stderr,
- "Failed to create HCI socket: %s\n",
- strerror (errno));
+ fprintf(stderr,
+ "Failed to create HCI socket: %s\n",
+ strerror(errno));
return -1;
}
- memset (&request, 0, sizeof(request));
- request.list.dev_num = HCI_MAX_DEV;
+ memset(&request, 0, sizeof(request));
+ request.list.dev_num = HCI_MAX_DEV;
- if (ioctl (fd_hci, HCIGETDEVLIST, (void *) &request) < 0)
+ 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);
+ 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++)
+ /* Search for a device with dev->iface name */
+ for (i = 0; i < request.list.dev_num; i++)
{
struct hci_dev_info dev_info;
- memset (&dev_info, 0, sizeof(struct hci_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);
-
- 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));
+ strncpy(dev_info.name, dev->iface, BLUEZ_DEVNAME_SIZE);
- /* Check if the interface is up */
- if (hci_test_bit (HCI_UP, (void *) &dev_info.flags) == 0)
+ if (ioctl(fd_hci, HCIGETDEVINFO, (void *)&dev_info))
{
- /* 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;
- }
+ fprintf(stderr,
+ "ioctl(HCIGETDEVINFO) 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)
+ if (strncmp(dev_info.name, dev->iface, BLUEZ_DEVNAME_SIZE) == 0)
{
- /* Set interface Page Scan and Inqury Scan ON */
- struct hci_dev_req dev_req;
+ 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;
+ }
+ }
- memset (&dev_req, 0, sizeof (dev_req));
- dev_req.dev_id = dev_info.dev_id;
- dev_req.dev_opt = SCAN_PAGE | SCAN_INQUIRY;
+ /* 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;
- 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;
- }
+ 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;
}
- break;
- }
-
}
- /* Check if the interface was not found */
- if (-1 == dev_id)
+ /* 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);
+ 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);
+ /* Close the hci socket */
+ (void)close(fd_hci);
- /* Bind the rfcomm socket to the interface */
- memset (&rc_addr, 0, sizeof (rc_addr));
- rc_addr.rc_family = AF_BLUETOOTH;
- rc_addr.rc_bdaddr = *BDADDR_ANY;
+ /* Bind the rfcomm socket to the interface */
+ 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)
+ if (bind_socket(dev->fd_rfcomm, &rc_addr) != 0)
{
- fprintf (stderr,
- "Failed to bind interface `%.*s': %s\n",
- IFNAMSIZ,
- dev->iface,
- strerror (errno));
+ 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)
+ /* 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));
+ 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
+ /* 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));
+ fprintf(stderr, "Failed to listen on socket for interface `%.*s': %s\n", IFNAMSIZ,
+ dev->iface, strerror(errno));
return 1;
}
-
#endif
return 0;
@@ -1299,47 +1294,47 @@ 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;
#ifdef MINGW
- GNUNET_memcpy (&taIeeeHeader->addr2, &dev->pl_mac, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress));
+ GNUNET_memcpy(&taIeeeHeader->addr2, &dev->pl_mac, sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress));
#else
- taIeeeHeader->addr2 = dev->pl_mac;
+ taIeeeHeader->addr2 = dev->pl_mac;
#endif
}
#ifdef LINUX
- /**
- * Test if the given interface name really corresponds to a bluetooth
- * device.
- *
- * @param iface name of the interface
- * @return 0 on success, 1 on error
- **** similar with the one from gnunet-helper-transport-wlan.c ****
- */
- static int
- 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)))
+/**
+ * Test if the given interface name really corresponds to a bluetooth
+ * device.
+ *
+ * @param iface name of the interface
+ * @return 0 on success, 1 on error
+ **** similar with the one from gnunet-helper-transport-wlan.c ****
+ */
+static int
+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);
+ fprintf(stderr,
+ "Did not find 802.15.1 interface `%s'. Exiting.\n",
+ iface);
+ exit(1);
}
- return 0;
- }
+ return 0;
+}
#endif
/**
@@ -1352,19 +1347,19 @@ mac_set (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
**** 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 */
}
@@ -1380,268 +1375,267 @@ 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);
- 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));
+ 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));
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));
+ * 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));
write_pout.size = sendsize;
}
#ifdef LINUX
- /**
- * Broadcast a HELLO message for peer discovery
- *
- * @param dev pointer to the device struct
- * @param dev pointer to the socket which was added to the set
- * @return 0 on success
- */
- static int
- send_broadcast (struct HardwareInfos *dev, int *sendsocket)
- {
- int new_device = 0;
- int loops = 0;
+/**
+ * Broadcast a HELLO message for peer discovery
+ *
+ * @param dev pointer to the device struct
+ * @param dev pointer to the socket which was added to the set
+ * @return 0 on success
+ */
+static int
+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)
+search_for_devices:
+ if ((neighbours.size == neighbours.pos && new_device == 1) || neighbours.size == 0)
{
- 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)
- {
- 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)
+inquiry_devices: //skip the conditions and force a inquiry for new devices
{
- 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;
- }
- }
+ /**
+ * 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;
- 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;
- }
+ /* sanity checks */
+ if (neighbours.size >= MAX_PORTS)
+ {
+ fprintf(stderr, "%.*s reached the top limit for the discovarable devices\n", IFNAMSIZ, dev->iface);
+ return 2;
+ }
- 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;
- }
+ /* Get the device id */
+ if (neighbours.dev_id == -1)
+ {
+ char addr[19] = { 0 }; //the device MAC address
- fprintf (stderr, "LOG : Found %d devices\n", responses); //FIXME delete it after debugging stage
+ 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;
+ }
+ }
- if (responses == 0)
- {
- fprintf (stderr, "LOG : No devices discoverable\n");
- return 1;
- }
+ 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;
+ }
- for (i = 0; i < responses; i++)
- {
- int j;
- int found = 0;
+ 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;
+ }
- /* 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;
- }
+ fprintf(stderr, "LOG : Found %d devices\n", responses); //FIXME delete it after debugging stage
- /* 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)
+ if (responses == 0)
{
- found = 1;
- fprintf (stderr, "LOG : the device already exists on the list\n"); //FIXME debugging message
- break;
+ fprintf(stderr, "LOG : No devices discoverable\n");
+ return 1;
}
- }
- if (found == 0)
- {
- char addr[19] = { 0 };
+ for (i = 0; i < responses; i++)
+ {
+ int j;
+ int found = 0;
- 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));
- }
- }
+ /* 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;
+ }
- free (devices);
+ /* 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 };
+
+ 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 };
- int errno_copy = 0;
- addr_rc.rc_family = AF_BLUETOOTH;
+ int connection_successful = 0;
+ struct sockaddr_rc addr_rc = { 0 };
+ int errno_copy = 0;
+ addr_rc.rc_family = AF_BLUETOOTH;
- /* Try to connect to a new device from the list */
- while (neighbours.pos < neighbours.size)
+ /* 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)
- {
-
- 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;
+ 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;
- }
+ {
+ fprintf(stderr, "LOG : Search for a new device\n"); //FIXME debugging message
+ neighbours.pos += 1;
+ }
}
- /* Cycle on the list */
- if (neighbours.pos == neighbours.size)
+ /* Cycle on the list */
+ if (neighbours.pos == neighbours.size)
{
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;
- }
+ {
+ 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)
+ /* 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)
- {
- 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
+ }
+ }
+
+ neighbours.pos += 1;
+ }
*sendsocket = neighbours.fds[neighbours.pos++];
}
- return 0;
- }
+ return 0;
+}
#endif
/**
@@ -1656,559 +1650,556 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
**** similar to gnunet-helper-transport-wlan.c ****
*/
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
#ifdef LINUX
- struct HardwareInfos dev;
- char readbuf[MAXLINE];
- int maxfd;
- fd_set rfds;
- fd_set wfds;
- int stdin_open;
- struct MessageStreamTokenizer *stdin_mst;
- int raw_eno, i;
- int crt_rfds = 0, rfds_list[MAX_PORTS];
- int broadcast, sendsocket;
-
- /* Assert privs so we can modify the firewall rules! */
- {
+ struct HardwareInfos dev;
+ char readbuf[MAXLINE];
+ int maxfd;
+ fd_set rfds;
+ fd_set wfds;
+ int stdin_open;
+ struct MessageStreamTokenizer *stdin_mst;
+ int raw_eno, i;
+ int crt_rfds = 0, rfds_list[MAX_PORTS];
+ int broadcast, sendsocket;
+
+ /* 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))
+ if (0 != setresuid(uid, 0, 0))
{
- fprintf (stderr,
- "Failed to setresuid to root: %s\n",
- strerror (errno));
- return 254;
+ fprintf(stderr,
+ "Failed to setresuid to root: %s\n",
+ strerror(errno));
+ return 254;
}
#else
- if (0 != seteuid (0))
+ if (0 != seteuid(0))
{
- fprintf (stderr,
- "Failed to seteuid back to root: %s\n", strerror (errno));
- return 254;
+ 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);
- raw_eno = errno; /* remember for later */
+ /* Make use of SGID capabilities on POSIX */
+ 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)
+ /* 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);
+ (void)close(dev.fd_rfcomm);
return 1;
}
- if (-1 == dev.fd_rfcomm)
+ if (-1 == dev.fd_rfcomm)
{
- fprintf (stderr, "Failed to create a RFCOMM socket: %s\n", strerror (raw_eno));
+ fprintf(stderr, "Failed to create a RFCOMM socket: %s\n", strerror(raw_eno));
return 1;
}
- if (dev.fd_rfcomm >= FD_SETSIZE)
+ 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);
+ 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]))
+ if (0 != test_bluetooth_interface(argv[1]))
{
- (void) close (dev.fd_rfcomm);
+ (void)close(dev.fd_rfcomm);
return 1;
}
- strncpy (dev.iface, argv[1], IFNAMSIZ);
- if (0 != open_device (&dev))
+ strncpy(dev.iface, argv[1], IFNAMSIZ);
+ if (0 != open_device(&dev))
{
- (void) close (dev.fd_rfcomm);
+ (void)close(dev.fd_rfcomm);
return 1;
}
- /* Drop privs */
- {
- uid_t uid = getuid ();
+ /* Drop privs */
+ {
+ uid_t uid = getuid();
#ifdef HAVE_SETRESUID
- if (0 != setresuid (uid, uid, uid))
+ if (0 != setresuid(uid, uid, uid))
{
- fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno));
+ fprintf(stderr, "Failed to setresuid: %s\n", strerror(errno));
if (-1 != dev.fd_rfcomm)
- (void) close (dev.fd_rfcomm);
+ (void)close(dev.fd_rfcomm);
return 1;
}
#else
- if (0 != (setuid (uid) | seteuid (uid)))
+ if (0 != (setuid(uid) | seteuid(uid)))
{
- fprintf (stderr, "Failed to setuid: %s\n", strerror (errno));
+ fprintf(stderr, "Failed to setuid: %s\n", strerror(errno));
if (-1 != dev.fd_rfcomm)
- (void) close (dev.fd_rfcomm);
+ (void)close(dev.fd_rfcomm);
return 1;
}
#endif
- }
+ }
- /* Send MAC address of the bluetooth interface to STDOUT first */
- {
- struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
+ /* 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));
- GNUNET_memcpy (write_std.buf, &macmsg, sizeof (macmsg));
- write_std.size = 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_open = 1;
+ stdin_mst = mst_create(&stdin_send_hw, &dev);
+ stdin_open = 1;
- /**
- * TODO : I should make the time out of a mac endpoint smaller and check if the rate
- * from get_wlan_header (plugin_transport_bluetooth.c) is correct.
- */
- while (1)
+ /**
+ * TODO : I should make the time out of a mac endpoint smaller and check if the rate
+ * from get_wlan_header (plugin_transport_bluetooth.c) is correct.
+ */
+ while (1)
{
maxfd = -1;
broadcast = 0;
sendsocket = -1;
- FD_ZERO (&rfds);
+ FD_ZERO(&rfds);
if ((0 == write_pout.size) && (1 == stdin_open))
- {
- FD_SET (STDIN_FILENO, &rfds);
- maxfd = MAX (maxfd, STDIN_FILENO);
- }
+ {
+ FD_SET(STDIN_FILENO, &rfds);
+ maxfd = MAX(maxfd, STDIN_FILENO);
+ }
if (0 == write_std.size)
- {
- FD_SET (dev.fd_rfcomm, &rfds);
- maxfd = MAX (maxfd, dev.fd_rfcomm);
- }
+ {
+ FD_SET(dev.fd_rfcomm, &rfds);
+ maxfd = MAX(maxfd, dev.fd_rfcomm);
+ }
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
+ FD_SET(rfds_list[i], &rfds);
+ maxfd = MAX(maxfd, rfds_list[i]);
}
- else if (memcmp (&frame->addr1, &broadcast_address,
- sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0)
+ FD_ZERO(&wfds);
+ if (0 < write_std.size)
{
- 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);
- }
+ FD_SET(STDOUT_FILENO, &wfds);
+ maxfd = MAX(maxfd, STDOUT_FILENO);
}
- else
+ if (0 < write_pout.size) //it can send messages only to one device per loop
{
- 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 };
+ struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *frame;
+ /* Get the destination address */
+ frame = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *)write_pout.buf;
- 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)
+ if (memcmp(&frame->addr1, &dev.pl_mac,
+ sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0)
{
- fprintf (stderr, "Failed to create a RFCOMM socket (sending stage): %s\n",
- strerror (errno));
- return -1;
+ broadcast = 1;
+ memset(&write_pout, 0, sizeof(write_pout)); //clear the buffer
}
-
- 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)
+ else if (memcmp(&frame->addr1, &broadcast_address,
+ sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0)
{
- 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;
- }
+ 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);
+ }
}
- else
+ 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)
+ int found = 0;
+ int pos = 0;
+ /* Search if the address already exists on the list */
+ for (i = 0; i < neighbours.size; i++)
{
- neighbours.fds[neighbours.size] = sendsocket;
- GNUNET_memcpy (&(neighbours.devices[neighbours.size++]), &addr.rc_bdaddr, sizeof (bdaddr_t));
+ 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;
+ }
+ }
}
- else
+ if (found == 0)
{
- fprintf (stderr, "The top limit for the discovarable devices' list was reached\n");
+ 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");
+ }
+ }
+ }
}
- }
}
- }
}
- }
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)
- {
- 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))
+ /* Select a fd which is ready for action :) */
{
- 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))
+ 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
{
- /* 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);
+ fprintf(stderr, "select failed: %s\n", strerror(errno));
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
- }
}
- }
- for (i = 0; i <= maxfd; i++)
- {
- if (FD_ISSET (i, &rfds))
- {
- if (i == STDIN_FILENO)
+ if (FD_ISSET(STDOUT_FILENO, &wfds))
{
ssize_t ret =
- read (i, readbuf, sizeof (readbuf));
+ write(STDOUT_FILENO, write_std.buf + write_std.pos,
+ write_std.size - write_std.pos);
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
- }
+ {
+ 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
}
- else if (i == dev.fd_rfcomm)
+ if (-1 != sendsocket)
{
- 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
+ if (FD_ISSET(sendsocket, &wfds))
{
- fprintf (stderr, "The limit for the read file descriptors list was \
- reached\n");
- break;
+ 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
+ }
}
- }
-
}
- else
+ for (i = 0; i <= maxfd; i++)
{
- 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 (FD_ISSET(i, &rfds))
{
- 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;
- }
+ 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 \
+ 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);
+ }
+ }
}
-
- 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);
- stdin_mst = NULL;
- sdp_close (dev.session);
- (void) close (dev.fd_rfcomm);
- if (-1 != sendsocket)
- (void) close (sendsocket);
-
- for (i = 0; i < crt_rfds; i++)
- (void) close (rfds_list[i]);
-
- for (i = 0; i < neighbours.size; i++)
- (void) close (neighbours.fds[i]);
+ /* Error handling, try to clean up a bit at least */
+ mst_destroy(stdin_mst);
+ stdin_mst = NULL;
+ sdp_close(dev.session);
+ (void)close(dev.fd_rfcomm);
+ if (-1 != sendsocket)
+ (void)close(sendsocket);
+
+ for (i = 0; i < crt_rfds; i++)
+ (void)close(rfds_list[i]);
+
+ for (i = 0; i < neighbours.size; i++)
+ (void)close(neighbours.fds[i]);
#else
- struct HardwareInfos dev;
- struct GNUNET_NETWORK_Handle *sendsocket;
- struct GNUNET_NETWORK_FDSet *rfds;
- struct GNUNET_NETWORK_FDSet *wfds;
- struct GNUNET_NETWORK_Handle *rfds_list[MAX_PORTS];
- char readbuf[MAXLINE] = { 0 };
- 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);
- struct MessageStreamTokenizer *stdin_mst;
-
- /* check the handles */
- if (stdin_handle == INVALID_HANDLE_VALUE)
+ struct HardwareInfos dev;
+ struct GNUNET_NETWORK_Handle *sendsocket;
+ struct GNUNET_NETWORK_FDSet *rfds;
+ struct GNUNET_NETWORK_FDSet *wfds;
+ struct GNUNET_NETWORK_Handle *rfds_list[MAX_PORTS];
+ char readbuf[MAXLINE] = { 0 };
+ 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);
+ 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)
+ 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 */
+ 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)
- // {
- // fprintf (stderr, "AF_BTH family is not supported\n");
- // ExitProcess (2);
- // }
+ // /* 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)
+ // {
+ // fprintf (stderr, "AF_BTH family is not supported\n");
+ // ExitProcess (2);
+ // }
- /* create the socket */
- dev.handle = GNUNET_NETWORK_socket_create (AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
- if (dev.handle == NULL)
+ /* create the socket */
+ dev.handle = GNUNET_NETWORK_socket_create(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
+ if (dev.handle == NULL)
{
- fprintf (stderr, "Failed to create RFCOMM socket: ");
+ fprintf(stderr, "Failed to create RFCOMM socket: ");
print_last_error();
- ExitProcess (2);
+ ExitProcess(2);
}
- if (open_device (&dev) == -1)
+ if (open_device(&dev) == -1)
{
- fprintf (stderr, "Failed to open the device\n");
+ 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);
+ if (GNUNET_NETWORK_socket_close(dev.handle) != GNUNET_OK)
+ {
+ fprintf(stderr, "Failed to close the socket!\n");
+ print_last_error();
+ }
+ ExitProcess(2);
}
- if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking (dev.handle, 1) )
+ if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking(dev.handle, 1))
{
- fprintf (stderr, "Failed to change the socket mode\n");
- ExitProcess (2);
+ 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));
- stdin_open = 1;
+ 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;
+ {
+ 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));
- write_std.size = 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_open = 1;
+ stdin_mst = mst_create(&stdin_send_hw, &dev);
+ stdin_open = 1;
- int pos = 0;
- int stdin_pos = -1;
- int stdout_pos = -1;
- while (1)
+ int pos = 0;
+ int stdin_pos = -1;
+ int stdout_pos = -1;
+ while (1)
{
broadcast = 0;
pos = 0;
@@ -2216,287 +2207,287 @@ main (int argc, char *argv[])
stdout_pos = -1;
sendsocket = NULL; //FIXME ???memleaks
- GNUNET_NETWORK_fdset_zero (rfds);
+ 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);
- }
+ {
+ 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);
- }
+ {
+ 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]);
- }
+ {
+ pos += 1;
+ GNUNET_NETWORK_fdset_set(rfds, rfds_list[i]);
+ }
- GNUNET_NETWORK_fdset_zero (wfds);
+ 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;
- }
+ {
+ 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)
- {
- 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))
+ if (strcmp(argv[1], "ff:ff:ff:ff:ff:ff") == 0)
{
- fprintf (stderr, "Failed to connect: ");
- print_last_error();
- ExitProcess (2);
+ 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;
}
-
- if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking (sendsocket, 1) )
+ else
{
- fprintf (stderr, "Failed to change the socket mode\n");
- ExitProcess (2);
- }
+ 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);
- GNUNET_NETWORK_fdset_set (wfds, sendsocket);
- }
- }
- }
+ if (sendsocket == NULL)
+ {
+ fprintf(stderr, "Failed to create RFCOMM socket: \n");
+ print_last_error();
+ ExitProcess(2);
+ }
- 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);
+ 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);
+ }
+ }
}
- //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;
- }
-
- if (ret <= 0)
- {
- fprintf (stderr, "Failed to write to STDOUT\n");
- ExitProcess (2);
- }
- write_std.pos += ret;
- if (write_std.pos == write_std.size)
- {
- write_std.pos = 0;
- write_std.size = 0;
- }
- }
- if (sendsocket != NULL)
+ if (broadcast == 0)
{
- 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)
+ int retval = GNUNET_NETWORK_socket_select(rfds, wfds, NULL, GNUNET_TIME_relative_get_forever_());
+ if (retval < 0)
{
- 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);
+ fprintf(stderr, "Select error\n");
+ ExitProcess(2);
}
- else
+ //if (GNUNET_NETWORK_fdset_isset (wfds, (struct GNUNET_NETWORK_Handle*)&stdout_handle))
+ if (retval == stdout_pos)
{
- 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;
- }
+ 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;
+ }
- if (write_pout.pos == write_pout.size)
- {
- write_pout.pos = 0;
- write_pout.size = 0;
+ if (ret <= 0)
+ {
+ fprintf(stderr, "Failed to write to STDOUT\n");
+ ExitProcess(2);
+ }
- }
- fprintf(stderr, "LOG : sends a message to a DEVICE\n"); //FIXME: debugging message
+ write_std.pos += ret;
+ if (write_std.pos == write_std.size)
+ {
+ write_std.pos = 0;
+ write_std.size = 0;
+ }
}
- }
- }
-
- //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) )
+ if (sendsocket != NULL)
{
- fprintf (stderr, "Failed to change the socket mode\n");
- ExitProcess (2);
+ 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
+ }
+ }
}
- GNUNET_NETWORK_fdset_set (rfds, readsocket);
- if (crt_rfds < MAX_PORTS)
- rfds_list[crt_rfds++] = readsocket;
- else
+ //if (GNUNET_NETWORK_fdset_isset (rfds, (struct GNUNET_NETWORK_Handle*)&stdin_handle))
+ if (retval == stdin_pos)
{
- fprintf (stderr, "The limit for the read file descriptors list was reached\n");
- break;
+ //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
- 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)
+ else
+ if (GNUNET_NETWORK_fdset_isset(rfds, dev.handle))
{
-
- //TODO remove the socket from the list
- if (GNUNET_NETWORK_socket_close (rfds_list[i]) != GNUNET_OK)
+ 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;
+ }
+ }
+ }
+ else
+ for (i = 0; i < crt_rfds; i++)
{
- fprintf (stderr, "Failed to close the sendsocket!\n");
- print_last_error();
+ 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;
+ }
}
-
- 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;
- }
}
- }
}
- mst_destroy (stdin_mst);
- stdin_mst = NULL;
+ mst_destroy(stdin_mst);
+ stdin_mst = NULL;
- if (GNUNET_NETWORK_socket_close (dev.handle) != GNUNET_OK)
+ if (GNUNET_NETWORK_socket_close(dev.handle) != GNUNET_OK)
{
- fprintf (stderr, "Failed to close the socket!\n");
+ fprintf(stderr, "Failed to close the socket!\n");
print_last_error();
}
- for (i = 0; i < crt_rfds; i++)
+ for (i = 0; i < crt_rfds; i++)
{
- if (GNUNET_NETWORK_socket_close (rfds_list[i]) != GNUNET_OK)
- {
- fprintf (stderr, "Failed to close the socket!\n");
- print_last_error();
- }
+ if (GNUNET_NETWORK_socket_close(rfds_list[i]) != GNUNET_OK)
+ {
+ 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 0adf8f6a5..44a54b7f6 100644
--- a/src/transport/gnunet-helper-transport-wlan-dummy.c
+++ b/src/transport/gnunet-helper-transport-wlan-dummy.c
@@ -1,19 +1,19 @@
/*
- This file is part of GNUnet.
- Copyright (C) 2010, 2012 GNUnet e.V.
+ This file is part of GNUnet.
+ Copyright (C) 2010, 2012 GNUnet e.V.
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
SPDX-License-Identifier: AGPL3.0-or-later
*/
@@ -47,9 +47,7 @@
/**
* 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'.
@@ -82,11 +80,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);
}
@@ -98,21 +96,20 @@ 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));
- return 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);
}
@@ -127,7 +124,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;
@@ -135,32 +132,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)) ||
- (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize))
- {
- fprintf (stderr, "%s", "Received malformed message\n");
- exit (1);
- }
+ 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);
+ }
payload_size =
- sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage);
+ sendsize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage);
if ((payload_size +
- sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) +
+ 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);
+ {
+ 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));
- 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,
+ &newheader,
+ sizeof(newheader));
+ write_pout->size += sizeof(newheader);
+ GNUNET_memcpy(write_pout->buf + write_pout->size, &in[1], payload_size);
write_pout->size += payload_size;
return GNUNET_OK;
}
@@ -176,18 +173,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;
}
@@ -201,7 +198,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;
@@ -225,298 +222,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;
- }
-
- /* 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)))
- {
- 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))
+ ((0 != strcmp(argv[1], "1")) && (0 != strcmp(argv[1], "2"))))
{
- erg = mkfifo (FIFO_FILE1, 0666);
- if ((0 != erg) && (EEXIST != errno))
- fprintf (stderr,
- "Error in mkfifo(%s): %s\n",
- FIFO_FILE1,
- strerror (errno));
+ fprintf(
+ stderr,
+ "%s",
+ "This program must be started with the operating mode (1 or 2) as the only argument.\n");
+ return 1;
}
- }
- else
- {
- if (0 != stat (FIFO_FILE2, &st))
+
+ /* 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)))
{
- 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));
+ fprintf(stderr, "Failed to create directory for file `%s'\n", FIFO_FILE1);
+ return 1;
}
- }
-
- if (0 == strcmp (argv[1], "1"))
- {
- first = 1;
- fpin = fopen (FIFO_FILE1, "r");
- if (NULL == fpin)
+ if (0 == strcmp(argv[1], "1"))
{
- fprintf (stderr,
- "fopen of read FIFO_FILE1 failed: %s\n",
- strerror (errno));
- goto end;
+ 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));
+ }
}
- if (NULL == (fpout = fopen (FIFO_FILE2, "w")))
+ else
{
- GNUNET_break (0 == mkfifo (FIFO_FILE2, 0666));
- fpout = fopen (FIFO_FILE2, "w");
+ 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));
+ }
}
- if (NULL == fpout)
+
+ if (0 == strcmp(argv[1], "1"))
{
- fprintf (stderr,
- "fopen of write FIFO_FILE2 failed: %s\n",
- strerror (errno));
- goto end;
+ 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;
+ }
}
- }
else
- {
- first = 0;
- if (NULL == (fpout = fopen (FIFO_FILE1, "w")))
{
- GNUNET_break (0 == mkfifo (FIFO_FILE1, 0666));
- 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;
+ }
}
- if (NULL == fpout)
+
+ fdpin = fileno(fpin);
+ GNUNET_assert(fpin >= 0);
+ if (fdpin >= FD_SETSIZE)
{
- fprintf (stderr,
- "fopen of write FIFO_FILE1 failed: %s\n",
- strerror (errno));
+ fprintf(stderr,
+ "File fdpin number too large (%d > %u)\n",
+ fdpin,
+ (unsigned int)FD_SETSIZE);
goto end;
}
- fpin = fopen (FIFO_FILE2, "r");
- if (NULL == fpin)
+
+ fdpout = fileno(fpout);
+ GNUNET_assert(fdpout >= 0);
+
+ if (fdpout >= FD_SETSIZE)
{
- fprintf (stderr,
- "fopen of read FIFO_FILE2 failed: %s\n",
- strerror (errno));
+ fprintf(stderr,
+ "File fdpout number too large (%d > %u)\n",
+ fdpout,
+ (unsigned int)FD_SETSIZE);
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;
- }
-
- 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);
+ 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)
- {
- FD_SET (STDIN_FILENO, &rfds);
- maxfd = MAX (STDIN_FILENO, maxfd);
- }
- if (0 == write_std.size)
{
- FD_SET (fdpin, &rfds);
- maxfd = MAX (fdpin, maxfd);
- }
+ 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);
+ }
- /* 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))
- {
- 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)
+ if (FD_ISSET(STDOUT_FILENO, &wfds))
{
- write_std.pos = 0;
- write_std.size = 0;
+ 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;
+ }
+ }
}
- }
- }
- 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)
+ if (FD_ISSET(fdpout, &wfds))
{
- write_pout.pos = 0;
- write_pout.size = 0;
+ 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;
+ }
+ }
}
- }
- }
- 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 6cd45ead8..885edb1b0 100644
--- a/src/transport/gnunet-helper-transport-wlan.c
+++ b/src/transport/gnunet-helper-transport-wlan.c
@@ -13,12 +13,12 @@
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Affero General Public License for more details.
-
+
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
SPDX-License-Identifier: AGPL3.0-or-later
-*/
+ */
/**
* @file src/transport/gnunet-helper-transport-wlan.c
* @brief mediator between the wlan interface and gnunet; must run as root (SUID will do)
@@ -234,8 +234,7 @@
/**
* 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.
@@ -258,15 +257,13 @@ struct PrismValue
* The data value
*/
uint32_t data;
-
} __attribute__ ((packed));
/**
* Prism header format ('struct p80211msg' in Linux). All in host byte order (!).
*/
-struct PrismHeader
-{
+struct PrismHeader {
/**
* We expect this to be a PRISM_MSGCODE_*.
*/
@@ -286,7 +283,6 @@ struct PrismHeader
are typically the hosttime, mactime, channel, rssi, sq, signal, noise,
rate, istx and frmlen values, but documentation is sparse. So we
will use the 'did' fields to find out what we actually got. */
-
} __attribute__ ((packed));
@@ -305,9 +301,7 @@ struct PrismHeader
* reliable indicator of alignment requirement. See also
* 'man 9 ieee80211_radiotap'.
*/
-enum RadiotapType
-{
-
+enum RadiotapType {
/**
* IEEE80211_RADIOTAP_TSFT __le64 microseconds
*
@@ -477,7 +471,7 @@ enum RadiotapType
*
* Frame was sent/received during CFP (Contention Free Period)
*/
-#define IEEE80211_RADIOTAP_F_CFP 0x01
+#define IEEE80211_RADIOTAP_F_CFP 0x01
/**
* Bit in IEEE80211_RADIOTAP_FLAGS (which we might get
@@ -487,7 +481,7 @@ enum RadiotapType
*
* Frame was sent/received with short preamble
*/
-#define IEEE80211_RADIOTAP_F_SHORTPRE 0x02
+#define IEEE80211_RADIOTAP_F_SHORTPRE 0x02
/**
* Bit in IEEE80211_RADIOTAP_FLAGS (which we might get
@@ -497,7 +491,7 @@ enum RadiotapType
*
* Frame was sent/received with WEP encryption
*/
-#define IEEE80211_RADIOTAP_F_WEP 0x04
+#define IEEE80211_RADIOTAP_F_WEP 0x04
/**
* Bit in IEEE80211_RADIOTAP_FLAGS (which we might get
@@ -507,7 +501,7 @@ enum RadiotapType
*
* Frame was sent/received with fragmentation
*/
-#define IEEE80211_RADIOTAP_F_FRAG 0x08
+#define IEEE80211_RADIOTAP_F_FRAG 0x08
/**
* Bit in IEEE80211_RADIOTAP_FLAGS (which we might get
@@ -517,7 +511,7 @@ enum RadiotapType
*
* Frame includes FCS (CRC at the end that needs to be removeD).
*/
-#define IEEE80211_RADIOTAP_F_FCS 0x10
+#define IEEE80211_RADIOTAP_F_FCS 0x10
/**
* Bit in IEEE80211_RADIOTAP_FLAGS (which we might get
@@ -528,44 +522,44 @@ enum RadiotapType
* Frame has padding between 802.11 header and payload
* (to 32-bit boundary)
*/
-#define IEEE80211_RADIOTAP_F_DATAPAD 0x20
+#define IEEE80211_RADIOTAP_F_DATAPAD 0x20
/**
* For IEEE80211_RADIOTAP_RX_FLAGS:
* frame failed crc check
*/
-#define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001
+#define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001
/**
* For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'):
* failed due to excessive retries
*/
-#define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001
+#define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001
/**
* For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'):
* used cts 'protection'
*/
-#define IEEE80211_RADIOTAP_F_TX_CTS 0x0002
+#define IEEE80211_RADIOTAP_F_TX_CTS 0x0002
/**
* For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'):
* used rts/cts handshake
*/
-#define IEEE80211_RADIOTAP_F_TX_RTS 0x0004
+#define IEEE80211_RADIOTAP_F_TX_RTS 0x0004
/**
* For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'):
* frame should not be ACKed
*/
-#define IEEE80211_RADIOTAP_F_TX_NOACK 0x0008
+#define IEEE80211_RADIOTAP_F_TX_NOACK 0x0008
/**
* For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'):
* sequence number handled by userspace
*/
-#define IEEE80211_RADIOTAP_F_TX_NOSEQ 0x0010
+#define IEEE80211_RADIOTAP_F_TX_NOSEQ 0x0010
/**
@@ -582,8 +576,7 @@ 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.
@@ -614,9 +607,7 @@ 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.
@@ -640,7 +631,6 @@ struct RadiotapTransmissionHeader
* Transmission flags from on the IEEE80211_RADIOTAP_F_TX_* constant family.
*/
uint16_t txflags;
-
};
/**
@@ -656,8 +646,7 @@ 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 +687,6 @@ struct Ieee80211RadiotapHeaderIterator
* internal next argument index
*/
unsigned int arg_index;
-
};
@@ -710,9 +698,7 @@ 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
*/
@@ -739,8 +725,7 @@ 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'.
@@ -784,7 +769,7 @@ static struct SendBuffer write_std;
/**
* Smallest supported message.
*/
-#define MIN_BUFFER_SIZE sizeof (struct GNUNET_MessageHeader)
+#define MIN_BUFFER_SIZE sizeof(struct GNUNET_MessageHeader)
/**
@@ -795,16 +780,14 @@ static struct SendBuffer write_std;
* @param message the actual message
*/
typedef void (*MessageTokenizerCallback) (void *cls,
- const struct
- GNUNET_MessageHeader *
- message);
+ const struct
+ GNUNET_MessageHeader *
+ message);
/**
* Handle to a message stream tokenizer.
*/
-struct MessageStreamTokenizer
-{
-
+struct MessageStreamTokenizer {
/**
* Function to call on completed messages.
*/
@@ -834,7 +817,6 @@ struct MessageStreamTokenizer
* Beginning of the buffer. Typed like this to force alignment.
*/
struct GNUNET_MessageHeader *hdr;
-
};
@@ -846,23 +828,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;
@@ -881,8 +863,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;
@@ -893,132 +875,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;
+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;
+ }
}
- }
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)
{
- /* 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 < 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;
+ }
}
- }
if (size > 0)
- {
- 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 (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;
}
- 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;
}
@@ -1029,10 +1011,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 ***************** **/
@@ -1058,12 +1040,12 @@ 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) )
+ if ((iterator == NULL) ||
+ (radiotap_header == NULL))
return -1;
/* Linux only supports version 0 radiotap format */
@@ -1071,37 +1053,37 @@ ieee80211_radiotap_iterator_init (struct Ieee80211RadiotapHeaderIterator *iterat
return -1;
/* sanity check for allowed length and radiotap length field */
- if ( (max_length < sizeof (struct Ieee80211RadiotapHeader)) ||
- (max_length < (GNUNET_le16toh (radiotap_header->it_len))) )
+ if ((max_length < sizeof(struct Ieee80211RadiotapHeader)) ||
+ (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)
{
- iterator->arg += sizeof (uint32_t);
+ 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);
/*
- * check for insanity where the present bitmaps
- * keep claiming to extend up to or even beyond the
- * stated radiotap header length
+ * no need to check again for blowing past stated radiotap
+ * header length, becuase ieee80211_radiotap_iterator_next
+ * checks it before it is dereferenced
*/
- 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;
}
@@ -1120,7 +1102,7 @@ ieee80211_radiotap_iterator_init (struct Ieee80211RadiotapHeaderIterator *iterat
* @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
@@ -1156,105 +1138,105 @@ ieee80211_radiotap_iterator_next (struct Ieee80211RadiotapHeaderIterator *iterat
[IEEE80211_RADIOTAP_RX_FLAGS] = 0x22,
[IEEE80211_RADIOTAP_RTS_RETRIES] = 0x11,
[IEEE80211_RADIOTAP_DATA_RETRIES] = 0x11
- /*
- * add more here as they are defined in
- * include/net/ieee80211_radiotap.h
- */
+ /*
+ * add more here as they are defined in
+ * include/net/ieee80211_radiotap.h
+ */
};
/*
* for every radiotap entry we can at
* least skip (by knowing the length)...
*/
- while (iterator->arg_index < sizeof (rt_sizes))
- {
- int hit = (0 != (iterator->bitmap_shifter & 1));
-
- if (hit)
+ while (iterator->arg_index < sizeof(rt_sizes))
{
- 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;
-
- /* 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;
- }
-
- /* Now, move on to next bit / next entry */
- iterator->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++;
- }
+ int hit = (0 != (iterator->bitmap_shifter & 1));
+
+ 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;
+
+ /* 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;
+ }
+
+ /* Now, move on to next bit / next entry */
+ iterator->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
- {
- /* 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;
+ {
+ /* 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;
}
- /* 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;
@@ -1269,7 +1251,7 @@ ieee80211_radiotap_iterator_next (struct Ieee80211RadiotapHeaderIterator *iterat
* @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,
@@ -1342,7 +1324,7 @@ calc_crc_osdep (const unsigned char *buf, size_t len)
for (; len > 0; len--, buf++)
crc = crc_tbl_osdep[(crc ^ *buf) & 0xFF] ^ (crc >> 8);
- return (~crc);
+ return(~crc);
}
@@ -1355,11 +1337,11 @@ 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])
@@ -1380,7 +1362,7 @@ 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)
return (frequency - 2407) / 5;
@@ -1399,14 +1381,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)
@@ -1414,7 +1396,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;
}
@@ -1431,9 +1413,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;
@@ -1443,190 +1425,207 @@ 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))
- {
- 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;
- }
- }
- }
- if ( (n < 8) || (n >= caplen) )
- return 0; /* invalid format */
+ 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))
+ {
+ 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;
+ }
+ }
+ }
+ 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);
- if ( (n < sizeof (struct Ieee80211RadiotapHeader)) || (n >= caplen))
- return 0; /* invalid 'it_len' */
- if (0 != ieee80211_radiotap_iterator_init (&iterator, rthdr, caplen))
- return 0;
+ 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))
+ return 0;
/* go through the radiotap arguments we have been given by the driver */
- while (0 <= ieee80211_radiotap_iterator_next (&iterator))
- {
- 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_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))
- {
- fcs_removed = 1;
- caplen -= sizeof (uint32_t);
- }
- break;
- }
- 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 */
+ while (0 <= ieee80211_radiotap_iterator_next(&iterator))
+ {
+ 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_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))
+ {
+ fcs_removed = 1;
+ caplen -= sizeof(uint32_t);
+ }
+ break;
+ }
+
+ 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_ETHER:
+
+ case ARPHRD_IEEE80211:
+ n = 0; /* no header */
+ break;
+
+ 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 */);
- return caplen - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) - 4;
- }
- default:
- errno = ENOTSUP; /* unsupported format */
- return -1;
- }
+ 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 */);
+ return caplen - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) - 4;
+ }
+
+ 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);
- }
+ 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);
+ }
/* copy payload to target buffer */
- GNUNET_memcpy (buf, tmpbuf + n, caplen);
+ GNUNET_memcpy(buf, tmpbuf + n, caplen);
return caplen;
}
@@ -1643,7 +1642,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;
@@ -1651,112 +1650,112 @@ 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;
- }
+ (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;
+ }
/* 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;
- }
+ 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;
+ }
/* 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;
+
+ 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;
+ }
}
- }
/* 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;
- }
+ 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;
}
@@ -1769,22 +1768,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;
}
@@ -1797,19 +1796,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 */
}
@@ -1822,10 +1821,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;
}
@@ -1840,7 +1839,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;
@@ -1849,56 +1848,58 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
struct RadiotapTransmissionHeader rtheader;
struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame etheader;
- 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));
+ 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));
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_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;
- }
+ {
+ 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;
+
+ default:
+ fprintf(stderr,
+ "Unsupported ARPTYPE!\n");
+ break;
+ }
}
@@ -1913,7 +1914,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];
@@ -1927,83 +1928,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, "Failed to setresuid: %s\n", strerror (errno));
- if (-1 != dev.fd_raw)
- (void) close (dev.fd_raw);
+ fprintf(stderr, "File descriptor too large for select (%d > %d)\n",
+ dev.fd_raw, FD_SETSIZE);
+ (void)close(dev.fd_raw);
return 1;
}
-#else
- if (0 != (setuid (uid) | seteuid (uid)))
+ if (0 != test_wlan_interface(argv[1]))
{
- fprintf (stderr, "Failed to setuid: %s\n", strerror (errno));
- if (-1 != dev.fd_raw)
- (void) close (dev.fd_raw);
+ (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, "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
}
@@ -2012,141 +2013,141 @@ 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));
- write_std.size = 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))
- {
- 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)
+ 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);
+ }
{
- fprintf (stderr, "select failed: %s\n", strerror (errno));
- break;
+ 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;
+ }
}
+ 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(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 (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 (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 bae187e7c..09e15655f 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -1,19 +1,19 @@
/*
- This file is part of GNUnet.
- Copyright (C) 2010-2016, 2018, 2019 GNUnet e.V.
+ This file is part of GNUnet.
+ Copyright (C) 2010-2016, 2018, 2019 GNUnet e.V.
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
+ GNUnet is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
SPDX-License-Identifier: AGPL3.0-or-later
*/
@@ -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,8 +308,7 @@ 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`.
@@ -321,8 +320,7 @@ struct MessageUUIDP
/**
* Unique identifier to map an acknowledgement to a transmission.
*/
-struct AcknowledgementUUIDP
-{
+struct AcknowledgementUUIDP {
/**
* The UUID value.
*/
@@ -333,8 +331,7 @@ 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.
*/
@@ -345,8 +342,7 @@ struct ChallengeNonceP
/**
* Outer layer of an encapsulated backchannel message.
*/
-struct TransportBackchannelEncapsulationMessage
-{
+struct TransportBackchannelEncapsulationMessage {
/**
* Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION.
*/
@@ -362,9 +358,7 @@ 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
*/
@@ -403,9 +397,7 @@ struct EphemeralConfirmationPS
* Plaintext of the variable-size payload that is encrypted
* within a `struct TransportBackchannelEncapsulationMessage`
*/
-struct TransportDVBoxPayloadP
-{
-
+struct TransportDVBoxPayloadP {
/**
* Sender's peer identity.
*/
@@ -438,8 +430,7 @@ 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
*/
@@ -465,8 +456,7 @@ 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
@@ -489,8 +479,7 @@ 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
*/
@@ -510,8 +499,7 @@ struct TransportReliabilityAckMessage
/**
* Outer layer of an encapsulated fragmented application message.
*/
-struct TransportFragmentBoxMessage
-{
+struct TransportFragmentBoxMessage {
/**
* Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT
*/
@@ -561,8 +549,7 @@ 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
*/
@@ -605,8 +592,7 @@ 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
*/
@@ -633,8 +619,7 @@ 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.
*/
@@ -661,8 +646,7 @@ 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
*/
@@ -749,8 +733,7 @@ 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
*/
@@ -808,9 +791,7 @@ 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
*/
@@ -838,9 +819,7 @@ 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
*/
@@ -863,9 +842,7 @@ 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
*/
@@ -909,8 +886,7 @@ 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
*/
@@ -966,8 +942,7 @@ 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).
*/
@@ -999,8 +974,7 @@ enum ClientType
* Which transmission options are allowable for transmission?
* Interpreted bit-wise!
*/
-enum RouteMessageOptions
-{
+enum RouteMessageOptions {
/**
* Only confirmed, non-DV direct neighbours.
*/
@@ -1033,9 +1007,7 @@ enum RouteMessageOptions
/**
* When did we launch this DV learning activity?
*/
-struct LearnLaunchEntry
-{
-
+struct LearnLaunchEntry {
/**
* Kept (also) in a DLL sorted by launch time.
*/
@@ -1063,8 +1035,7 @@ 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.
*/
@@ -1081,8 +1052,7 @@ struct TransmissionHistoryEntry
/**
* Performance data for a transmission possibility.
*/
-struct PerformanceData
-{
+struct PerformanceData {
/**
* Weighted average for the RTT.
*/
@@ -1149,9 +1119,7 @@ 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.
@@ -1185,9 +1153,7 @@ 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.
*/
@@ -1226,8 +1192,7 @@ 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.
*/
@@ -1425,9 +1390,7 @@ 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.
@@ -1520,9 +1483,7 @@ struct PendingAcknowledgement
/**
* One possible hop towards a DV target.
*/
-struct DistanceVectorHop
-{
-
+struct DistanceVectorHop {
/**
* Kept in a MDLL, sorted by @e timeout.
*/
@@ -1603,9 +1564,7 @@ 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?
*/
@@ -1669,9 +1628,7 @@ struct DistanceVector
* what the communicator can actually provide towards a particular
* peer/target).
*/
-struct QueueEntry
-{
-
+struct QueueEntry {
/**
* Kept as a DLL.
*/
@@ -1703,8 +1660,7 @@ 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.
*/
@@ -1832,9 +1788,7 @@ 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.
@@ -1892,9 +1846,7 @@ struct ReassemblyContext
/**
* A neighbour that at least one communicator is connected to.
*/
-struct Neighbour
-{
-
+struct Neighbour {
/**
* Which peer is this about?
*/
@@ -1977,9 +1929,7 @@ 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.
*/
@@ -2005,9 +1955,7 @@ struct IncomingRequest
/**
* A peer that an application (client) would like us to talk to directly.
*/
-struct PeerRequest
-{
-
+struct PeerRequest {
/**
* Which peer is this about?
*/
@@ -2040,9 +1988,7 @@ struct PeerRequest
/**
* Types of different pending messages.
*/
-enum PendingMessageType
-{
-
+enum PendingMessageType {
/**
* Ordinary message received from the CORE service.
*/
@@ -2062,7 +2008,6 @@ enum PendingMessageType
* Pending message created during #forward_dv_box().
*/
PMT_DV_BOX = 3
-
};
@@ -2092,8 +2037,7 @@ 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.
*/
@@ -2232,8 +2176,7 @@ 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.
@@ -2251,8 +2194,7 @@ 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.
*/
@@ -2292,9 +2234,7 @@ struct AcknowledgementCummulator
/**
* One of the addresses of this peer.
*/
-struct AddressListEntry
-{
-
+struct AddressListEntry {
/**
* Kept in a DLL.
*/
@@ -2346,9 +2286,7 @@ struct AddressListEntry
/**
* Client connected to the transport service.
*/
-struct TransportClient
-{
-
+struct TransportClient {
/**
* Kept in a DLL.
*/
@@ -2374,15 +2312,11 @@ 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).
@@ -2393,15 +2327,12 @@ struct TransportClient
* Tail of list of messages pending for this client.
*/
struct PendingMessage *pending_msg_tail;
-
} core;
/**
* Information for @e type #CT_MONITOR.
*/
- struct
- {
-
+ struct {
/**
* Peer identity to monitor the addresses of.
* Zero to monitor all neighbours. Valid if
@@ -2413,15 +2344,13 @@ struct TransportClient
* Is this a one-shot monitor?
*/
int one_shot;
-
} monitor;
/**
* Information for @e type #CT_COMMUNICATOR.
*/
- struct
- {
+ struct {
/**
* If @e type is #CT_COMMUNICATOR, this communicator
* supports communicating using these addresses.
@@ -2461,23 +2390,18 @@ struct TransportClient
* Characteristics of this communicator.
*/
enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc;
-
} communicator;
/**
* 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`.
*/
struct GNUNET_CONTAINER_MultiPeerMap *requests;
-
} application;
-
} details;
};
@@ -2486,9 +2410,7 @@ 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.
@@ -2598,8 +2520,7 @@ struct ValidationState
* material (to avoid repeatedly checking signatures), and to synchronize
* monotonic time with the PEERSTORE.
*/
-struct Backtalker
-{
+struct Backtalker {
/**
* Peer this is about.
*/
@@ -2822,11 +2743,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;
}
@@ -2837,13 +2758,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);
}
@@ -2853,34 +2774,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);
}
@@ -2893,23 +2814,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;
-
- 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;
+ 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);
}
- GNUNET_CONTAINER_MDLL_remove (frag, root->head_frag, root->tail_frag, frag);
- GNUNET_free (frag);
- }
}
@@ -2921,44 +2842,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);
}
@@ -2968,34 +2889,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);
}
@@ -3005,20 +2926,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);
}
@@ -3029,9 +2950,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);
}
@@ -3042,17 +2963,16 @@ 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...
*/
@@ -3091,20 +3011,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);
}
@@ -3115,7 +3035,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);
/**
@@ -3124,22 +3044,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);
+ }
}
@@ -3150,43 +3070,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;
-
- 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;
- }
+ struct VirtualLink *vl;
- if (NULL != dv->timeout_task)
- {
- GNUNET_SCHEDULER_cancel (dv->timeout_task);
- dv->timeout_task = 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);
}
- GNUNET_free (dv);
- }
}
@@ -3204,30 +3124,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);
}
@@ -3241,22 +3161,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);
+ }
}
@@ -3270,18 +3190,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;
}
@@ -3292,16 +3212,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);
}
@@ -3311,27 +3231,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)))
- {
- if (0 == GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout)
- .rel_value_us)
+ while (NULL != (rc = GNUNET_CONTAINER_heap_peek(n->reassembly_heap)))
{
- free_reassembly_context (rc);
- continue;
+ 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;
}
- GNUNET_assert (NULL == n->reassembly_timeout_task);
- n->reassembly_timeout_task =
- GNUNET_SCHEDULER_add_at (rc->reassembly_timeout,
- &reassembly_cleanup_task,
- n);
- return;
- }
}
@@ -3344,13 +3264,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;
}
@@ -3361,66 +3281,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)
{
- cores_send_disconnect_info (&vl->target);
- free_virtual_link (vl);
+ GNUNET_PEERSTORE_store_cancel(neighbour->sc);
+ neighbour->sc = NULL;
}
- else
+ if (NULL != (vl = neighbour->vl))
{
- GNUNET_SCHEDULER_cancel (vl->visibility_task);
- vl->visibility_task = GNUNET_SCHEDULER_add_now (&check_link_down, vl);
+ 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;
}
- neighbour->vl = NULL;
- }
- GNUNET_free (neighbour);
+ GNUNET_free(neighbour);
}
@@ -3431,16 +3351,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);
}
@@ -3450,17 +3370,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);
+ }
}
@@ -3472,7 +3392,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);
/**
@@ -3483,38 +3403,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));
}
@@ -3525,7 +3445,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;
@@ -3537,30 +3457,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);
}
@@ -3570,77 +3490,77 @@ 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;
- struct MonitorEvent me = {.cs = GNUNET_TRANSPORT_CS_DOWN,
- .rtt = GNUNET_TIME_UNIT_FOREVER_REL};
+ struct MonitorEvent me = { .cs = GNUNET_TRANSPORT_CS_DOWN,
+ .rtt = GNUNET_TIME_UNIT_FOREVER_REL };
struct QueueEntry *qe;
int maxxed;
struct PendingAcknowledgement *pa;
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_assert (qe == qe->pm->qe);
- qe->pm->qe = NULL;
+ 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_free (qe);
- }
- GNUNET_assert (0 == queue->queue_length);
+ 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);
+ }
}
@@ -3650,24 +3570,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);
}
@@ -3680,20 +3600,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;
}
@@ -3708,56 +3628,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_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;
+ case CT_NONE:
+ break;
+
+ 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;
+ }
}
- }
- break;
- case CT_MONITOR:
break;
- case CT_COMMUNICATOR: {
- struct Queue *q;
- struct AddressListEntry *ale;
-
- while (NULL != (q = tc->details.communicator.queue_head))
- free_queue (q);
- while (NULL != (ale = tc->details.communicator.addr_head))
- 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);
+
+ case CT_MONITOR:
+ break;
+
+ case CT_COMMUNICATOR: {
+ struct Queue *q;
+ struct AddressListEntry *ale;
+
+ while (NULL != (q = tc->details.communicator.queue_head))
+ free_queue(q);
+ while (NULL != (ale = tc->details.communicator.addr_head))
+ free_address_list_entry(ale);
+ GNUNET_free(tc->details.communicator.address_prefix);
+ }
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);
}
@@ -3771,17 +3695,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;
}
@@ -3795,34 +3719,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);
}
@@ -3833,29 +3757,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);
- 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;
+ }
+ 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;
+ }
return GNUNET_OK;
}
@@ -3868,25 +3792,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);
}
@@ -3900,10 +3824,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;
@@ -3915,56 +3839,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)
+ {
+ 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++;
- }
+ 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)
- {
- 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])
+ {
+ int ok = GNUNET_NO;
+ while (GNUNET_NO == ok)
{
- ok = GNUNET_NO;
- break;
+ 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;
+ }
}
}
- }
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;
+ {
+ uint32_t delta = MAX_DV_HOPS_ALLOWED - pos->distance;
- if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) &&
- (GNUNET_TIME_absolute_get_remaining (pos->path_valid_until)
+ 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;
- }
+ 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;
}
@@ -3976,7 +3900,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)
{
@@ -3984,15 +3908,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;
}
@@ -4003,22 +3927,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);
}
@@ -4032,7 +3956,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;
@@ -4040,31 +3964,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);
+ }
}
@@ -4075,28 +3999,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);
}
@@ -4108,7 +4032,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)
{
@@ -4117,24 +4041,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;
}
@@ -4146,26 +4070,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));
}
@@ -4179,45 +4103,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 ==
@@ -4225,7 +4149,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);
}
}
@@ -4241,9 +4165,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;
@@ -4252,7 +4176,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
@@ -4260,53 +4184,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 ((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 ((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++;
+ }
}
- }
return rtt;
}
@@ -4314,8 +4238,7 @@ 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.
*/
@@ -4324,9 +4247,7 @@ struct DVKeyState
/**
* Actual key material.
*/
- struct
- {
-
+ struct {
/**
* Key used for HMAC calculations (via #GNUNET_CRYPTO_hmac()).
*/
@@ -4341,7 +4262,6 @@ struct DVKeyState
* Counter value to use during setup.
*/
char aes_ctr[128 / 8];
-
} material;
};
@@ -4355,34 +4275,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));
}
@@ -4396,7 +4316,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,
@@ -4404,10 +4324,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);
}
@@ -4421,16 +4341,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);
}
@@ -4444,12 +4364,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);
}
@@ -4463,10 +4383,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));
}
@@ -4480,13 +4400,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));
}
@@ -4496,10 +4416,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));
}
@@ -4532,92 +4452,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);
- char enc[sizeof (struct TransportDVBoxPayloadP) + enc_body_size] GNUNET_ALIGN;
+ 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)
{
- 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);
- }
+ 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);
+ }
return rtt;
}
@@ -4632,13 +4552,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);
}
@@ -4654,9 +4574,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;
@@ -4664,78 +4584,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);
}
@@ -4746,7 +4666,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;
@@ -4754,7 +4674,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
@@ -4763,41 +4683,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);
}
@@ -4818,7 +4738,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;
@@ -4830,57 +4750,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)
{
- 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;
+ 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_BACKGROUND);
+ 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);
+ }
}
- }
}
@@ -4891,7 +4811,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;
@@ -4900,46 +4820,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);
}
@@ -4953,39 +4873,39 @@ 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;
+ 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));
+ #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));
/* 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);
}
@@ -4997,17 +4917,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;
}
@@ -5018,7 +4938,7 @@ check_add_address (void *cls,
* @param cls an `struct AddressListEntry *`
*/
static void
-store_pi (void *cls);
+store_pi(void *cls);
/**
@@ -5028,26 +4948,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);
}
@@ -5057,7 +4977,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;
@@ -5065,36 +4985,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);
+ }
}
@@ -5105,30 +5025,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);
}
@@ -5139,34 +5059,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);
}
@@ -5178,8 +5098,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);
/**
@@ -5190,23 +5110,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;