Transport plugin using unix domain sockets (!) Clearly, can only be used locally on Unix/Linux hosts... ONLY INTENDED FOR TESTING!!! More...
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_statistics_service.h"
#include "gnunet_transport_communication_service.h"
Go to the source code of this file.
Data Structures | |
struct | UNIXMessage |
UNIX Message-Packet header. More... | |
struct | Queue |
Handle for a queue. More... | |
struct | LookupCtx |
Closure to lookup_queue_it(). More... | |
Macros | |
#define | DEFAULT_MAX_QUEUE_LENGTH 8000 |
How many messages do we keep at most in the queue to the transport service before we start to drop (default, can be changed via the configuration file). More... | |
#define | COMMUNICATOR_ADDRESS_PREFIX "unix" |
Address prefix used by the communicator. More... | |
#define | COMMUNICATOR_CONFIG_SECTION "communicator-unix" |
Configuration section used by the communicator. More... | |
#define | UNIX_MTU UINT16_MAX |
Our MTU. More... | |
Functions | |
static void | queue_destroy (struct Queue *queue) |
Functions with this signature are called whenever we need to close a queue due to a disconnect or failure to establish a connection. More... | |
static void | queue_timeout (void *cls) |
Queue was idle for too long, so disconnect it. More... | |
static void | reschedule_queue_timeout (struct Queue *queue) |
Increment queue timeout due to activity. More... | |
static struct sockaddr_un * | unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len) |
Convert unix path to a struct sockaddr_un * More... | |
static int | lookup_queue_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
Function called to find a queue by address. More... | |
static struct Queue * | lookup_queue (const struct GNUNET_PeerIdentity *peer, const struct sockaddr_un *un, socklen_t un_len) |
Find an existing queue by address. More... | |
static void | select_write_cb (void *cls) |
We have been notified that our socket is ready to write. More... | |
static void | mq_send (struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state) |
Signature of functions implementing the sending functionality of a message queue. More... | |
static void | mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state) |
Signature of functions implementing the destruction of a message queue. More... | |
static void | mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state) |
Implementation function that cancels the currently sent message. More... | |
static void | mq_error (void *cls, enum GNUNET_MQ_Error error) |
Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue. More... | |
static struct Queue * | setup_queue (const struct GNUNET_PeerIdentity *target, enum GNUNET_TRANSPORT_ConnectionStatus cs, const struct sockaddr_un *un, socklen_t un_len) |
Creates a new outbound queue the transport service will use to send data to another peer. More... | |
static void | select_read_cb (void *cls) |
We have been notified that our socket has something to read. More... | |
static void | receive_complete_cb (void *cls, int success) |
Function called when message was successfully passed to transport service. More... | |
static int | mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) |
Function called by the transport service to initialize a message queue given address information about another peer. More... | |
static int | get_queue_delete_it (void *cls, const struct GNUNET_PeerIdentity *target, void *value) |
Iterator over all message queues to clean up. More... | |
static void | do_shutdown (void *cls) |
Shutdown the UNIX communicator. More... | |
static void | enc_notify_cb (void *cls, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg) |
Function called when the transport service has received an acknowledgement for this communicator (!) via a different return path. More... | |
static void | run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
Setup communicator and launch network interactions. More... | |
int | main (int argc, char *const *argv) |
The main function for the UNIX communicator. More... | |
Variables | |
static struct GNUNET_PeerIdentity | my_identity |
My Peer Identity. More... | |
static struct GNUNET_SCHEDULER_Task * | read_task |
ID of read task. More... | |
static struct GNUNET_SCHEDULER_Task * | write_task |
ID of write task. More... | |
static unsigned long long | delivering_messages |
Number of messages we currently have in our queues towards the transport service. More... | |
static unsigned long long | max_queue_length |
Maximum queue length before we stop reading towards the transport service. More... | |
static struct GNUNET_STATISTICS_Handle * | stats |
For logging statistics. More... | |
static struct GNUNET_TRANSPORT_CommunicatorHandle * | ch |
Our environment. More... | |
static struct GNUNET_CONTAINER_MultiPeerMap * | queue_map |
Queues (map from peer identity to struct Queue ) More... | |
static struct Queue * | queue_head |
Head of queue of messages to transmit. More... | |
static struct Queue * | queue_tail |
Tail of queue of messages to transmit. More... | |
static struct GNUNET_NETWORK_Handle * | unix_sock |
socket that we transmit all data with More... | |
static struct GNUNET_TRANSPORT_AddressIdentifier * | ai |
Handle to the operation that publishes our address. More... | |
Transport plugin using unix domain sockets (!) Clearly, can only be used locally on Unix/Linux hosts... ONLY INTENDED FOR TESTING!!!
Definition in file gnunet-communicator-unix.c.
#define DEFAULT_MAX_QUEUE_LENGTH 8000 |
How many messages do we keep at most in the queue to the transport service before we start to drop (default, can be changed via the configuration file).
Should be below the level of the communicator API, as otherwise we may read messages just to have them dropped by the communicator API.
Definition at line 43 of file gnunet-communicator-unix.c.
#define COMMUNICATOR_ADDRESS_PREFIX "unix" |
Address prefix used by the communicator.
Definition at line 48 of file gnunet-communicator-unix.c.
#define COMMUNICATOR_CONFIG_SECTION "communicator-unix" |
Configuration section used by the communicator.
Definition at line 53 of file gnunet-communicator-unix.c.
#define UNIX_MTU UINT16_MAX |
Our MTU.
Definition at line 59 of file gnunet-communicator-unix.c.
|
static |
Functions with this signature are called whenever we need to close a queue due to a disconnect or failure to establish a connection.
queue | queue to close down |
Definition at line 216 of file gnunet-communicator-unix.c.
References GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_MQ_destroy(), GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_set(), GNUNET_YES, mq, queue(), queue_head, queue_map, queue_tail, and stats.
Referenced by get_queue_delete_it(), mq_destroy(), mq_error(), and queue_timeout().
|
static |
Queue was idle for too long, so disconnect it.
cls | the struct Queue * to disconnect |
Definition at line 256 of file gnunet-communicator-unix.c.
References GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_remaining(), GNUNET_YES, queue(), queue_destroy(), queue_timeout(), and GNUNET_TIME_Relative::rel_value_us.
Referenced by queue_timeout(), and setup_queue().
|
static |
Increment queue timeout due to activity.
We do not immediately notify the monitor here as that might generate excessive signalling.
queue | queue for which the timeout should be rescheduled |
Definition at line 289 of file gnunet-communicator-unix.c.
References GNUNET_assert, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_TIME_relative_to_absolute(), and queue().
Referenced by select_read_cb(), and select_write_cb().
|
static |
Convert unix path to a struct sockaddr_un *
unixpath | path to convert | |
[out] | sock_len | set to the length of the address |
is_abstract | is this an abstract unixpath |
Definition at line 306 of file gnunet-communicator-unix.c.
References GNUNET_assert, GNUNET_memcpy, and GNUNET_new.
Referenced by mq_init(), and run().
|
static |
Function called to find a queue by address.
cls | the struct LookupCtx * |
key | peer we are looking for (unused) |
value | a queue |
Definition at line 361 of file gnunet-communicator-unix.c.
References GNUNET_NO, GNUNET_YES, queue(), LookupCtx::res, LookupCtx::un, LookupCtx::un_len, and value.
Referenced by lookup_queue().
|
static |
Find an existing queue by address.
plugin | the plugin |
address | the address to find |
Definition at line 384 of file gnunet-communicator-unix.c.
References GNUNET_CONTAINER_multipeermap_get_multiple(), lookup_queue_it(), queue_map, LookupCtx::res, LookupCtx::un, and LookupCtx::un_len.
Referenced by mq_init(), and select_read_cb().
|
static |
We have been notified that our socket is ready to write.
Then reschedule this function to be called again once more is available.
cls | NULL |
Definition at line 408 of file gnunet-communicator-unix.c.
References GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_log_strerror, GNUNET_MQ_impl_send_continue(), GNUNET_NETWORK_socket_getsockopt(), GNUNET_NETWORK_socket_sendto(), GNUNET_NETWORK_socket_setsockopt(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_write_net(), GNUNET_STATISTICS_update(), GNUNET_TIME_UNIT_FOREVER_REL, msg, queue(), queue_head, queue_tail, reschedule_queue_timeout(), select_write_cb(), GNUNET_MessageHeader::size, size, stats, unix_sock, and write_task.
Referenced by mq_send(), and select_write_cb().
|
static |
Signature of functions implementing the sending functionality of a message queue.
mq | the message queue |
msg | the message to send |
impl_state | our struct Queue |
Definition at line 524 of file gnunet-communicator-unix.c.
References GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_malloc, GNUNET_SCHEDULER_add_write_net(), GNUNET_TIME_UNIT_FOREVER_REL, mq, msg, my_identity, queue(), queue_head, queue_tail, select_write_cb(), GNUNET_MessageHeader::size, unix_sock, and write_task.
Referenced by setup_queue().
|
static |
Signature of functions implementing the destruction of a message queue.
Implementations must not free mq, but should take care of impl_state.
mq | the message queue to destroy |
impl_state | our struct Queue |
Definition at line 557 of file gnunet-communicator-unix.c.
References mq, queue(), and queue_destroy().
Referenced by setup_queue().
|
static |
Implementation function that cancels the currently sent message.
mq | message queue |
impl_state | our struct Queue |
Definition at line 576 of file gnunet-communicator-unix.c.
References GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_SCHEDULER_cancel(), queue(), queue_head, queue_tail, and write_task.
Referenced by setup_queue().
|
static |
Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.
Not every message queue implementation supports an error handler.
cls | our struct Queue |
error | error code |
Definition at line 602 of file gnunet-communicator-unix.c.
References GNUNET_ERROR_TYPE_ERROR, GNUNET_i2s(), GNUNET_log, queue(), and queue_destroy().
Referenced by setup_queue().
|
static |
Creates a new outbound queue the transport service will use to send data to another peer.
peer | the target peer |
cs | inbound or outbound queue |
un | the address |
un_len | number of bytes in un |
Definition at line 625 of file gnunet-communicator-unix.c.
References ch, COMMUNICATOR_ADDRESS_PREFIX, Queue::cs, GNUNET_asprintf(), GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_free, GNUNET_memdup, GNUNET_MQ_queue_for_callbacks(), GNUNET_new, GNUNET_NO, GNUNET_NT_LOOPBACK, GNUNET_SCHEDULER_add_delayed(), GNUNET_STATISTICS_set(), GNUNET_TIME_relative_to_absolute(), GNUNET_TRANSPORT_communicator_mq_add(), GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED, mq_cancel(), mq_destroy(), mq_error(), mq_send(), queue(), queue_map, queue_timeout(), stats, Queue::target, and UNIX_MTU.
Referenced by mq_init(), and select_read_cb().
|
static |
We have been notified that our socket has something to read.
Do the read and reschedule this function to be called again once more is available.
cls | NULL |
Definition at line 732 of file gnunet-communicator-unix.c.
References _, ch, delivering_messages, GNUNET_ALIGN, GNUNET_assert, GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_log_strerror, GNUNET_NETWORK_socket_recvfrom(), GNUNET_NO, GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_communicator_receive(), GNUNET_TRANSPORT_CS_INBOUND, lookup_queue(), max_queue_length, msg, queue(), read_task, receive_complete_cb(), reschedule_queue_timeout(), ret, select_read_cb(), setup_queue(), GNUNET_MessageHeader::size, and unix_sock.
Referenced by receive_complete_cb(), run(), and select_read_cb().
|
static |
Function called when message was successfully passed to transport service.
Continue read activity.
cls | NULL |
success | GNUNET_OK on success |
Definition at line 706 of file gnunet-communicator-unix.c.
References delivering_messages, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_read_net(), GNUNET_STATISTICS_update(), GNUNET_TIME_UNIT_FOREVER_REL, max_queue_length, read_task, select_read_cb(), stats, and unix_sock.
Referenced by select_read_cb().
|
static |
Function called by the transport service to initialize a message queue given address information about another peer.
If and when the communication channel is established, the communicator must call GNUNET_TRANSPORT_communicator_mq_add() to notify the service that the channel is now up. It is the responsibility of the communicator to manage sane retries and timeouts for any peer/address combination provided by the transport service. Timeouts and retries do not need to be signalled to the transport service.
cls | closure |
peer | identity of the other peer |
address | where to send the message, human-readable communicator-specific format, 0-terminated, UTF-8 |
Definition at line 856 of file gnunet-communicator-unix.c.
References address, COMMUNICATOR_ADDRESS_PREFIX, GNUNET_break_op, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_TRANSPORT_CS_OUTBOUND, lookup_queue(), queue(), setup_queue(), and unix_address_to_sockaddr().
Referenced by run().
|
static |
Iterator over all message queues to clean up.
cls | NULL |
target | unused |
value | the queue to destroy |
Definition at line 906 of file gnunet-communicator-unix.c.
References GNUNET_OK, queue(), queue_destroy(), Queue::target, and value.
Referenced by do_shutdown().
|
static |
Shutdown the UNIX communicator.
cls | NULL (always) |
Definition at line 925 of file gnunet-communicator-unix.c.
References ai, ch, get_queue_delete_it(), GNUNET_break, GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_NETWORK_socket_close(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_destroy(), GNUNET_TRANSPORT_communicator_address_remove(), GNUNET_TRANSPORT_communicator_disconnect(), queue_map, read_task, stats, unix_sock, and write_task.
Referenced by run().
|
static |
Function called when the transport service has received an acknowledgement for this communicator (!) via a different return path.
Not applicable for UNIX.
cls | closure |
sender | which peer sent the notification |
msg | payload |
Definition at line 974 of file gnunet-communicator-unix.c.
References GNUNET_break_op, and msg.
Referenced by run().
|
static |
Setup communicator and launch network interactions.
cls | NULL (always) |
args | remaining command-line arguments |
cfgfile | name of the configuration file used (for saving, can be NULL!) |
cfg | configuration |
Definition at line 994 of file gnunet-communicator-unix.c.
References _, ai, cfg, ch, COMMUNICATOR_ADDRESS_PREFIX, COMMUNICATOR_CONFIG_SECTION, DEFAULT_MAX_QUEUE_LENGTH, delivering_messages, do_shutdown(), enc_notify_cb(), GNUNET_asprintf(), GNUNET_break, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONTAINER_multipeermap_create(), GNUNET_CRYPTO_eddsa_key_create_from_configuration(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_DISK_directory_create_for_file(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_log_config_missing(), GNUNET_log_strerror, GNUNET_log_strerror_file, GNUNET_NETWORK_socket_bind(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_create(), GNUNET_NO, GNUNET_NT_LOOPBACK, GNUNET_OK, GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_STATISTICS_create(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_CC_RELIABLE, GNUNET_TRANSPORT_communicator_address_add(), GNUNET_TRANSPORT_communicator_connect(), max_queue_length, mq_init(), my_identity, my_private_key, GNUNET_PeerIdentity::public_key, queue_map, read_task, select_read_cb(), stats, unix_address_to_sockaddr(), and unix_sock.
Referenced by main().
int main | ( | int | argc, |
char *const * | argv | ||
) |
The main function for the UNIX communicator.
argc | number of arguments from the command line |
argv | command line arguments |
Definition at line 1124 of file gnunet-communicator-unix.c.
References _, GNUNET_GETOPT_OPTION_END, GNUNET_OK, GNUNET_OS_project_data_gnunet(), GNUNET_PROGRAM_run(), options, ret, and run().
|
static |
My Peer Identity.
Definition at line 150 of file gnunet-communicator-unix.c.
|
static |
ID of read task.
Definition at line 155 of file gnunet-communicator-unix.c.
Referenced by do_shutdown(), receive_complete_cb(), run(), and select_read_cb().
|
static |
ID of write task.
Definition at line 160 of file gnunet-communicator-unix.c.
Referenced by do_shutdown(), mq_cancel(), mq_send(), and select_write_cb().
|
static |
Number of messages we currently have in our queues towards the transport service.
Definition at line 165 of file gnunet-communicator-unix.c.
Referenced by receive_complete_cb(), run(), and select_read_cb().
|
static |
Maximum queue length before we stop reading towards the transport service.
Definition at line 170 of file gnunet-communicator-unix.c.
Referenced by receive_complete_cb(), run(), and select_read_cb().
|
static |
For logging statistics.
Definition at line 175 of file gnunet-communicator-unix.c.
Referenced by do_shutdown(), queue_destroy(), receive_complete_cb(), run(), select_write_cb(), and setup_queue().
|
static |
Our environment.
Definition at line 180 of file gnunet-communicator-unix.c.
Referenced by do_shutdown(), run(), select_read_cb(), and setup_queue().
|
static |
Queues (map from peer identity to struct Queue
)
Definition at line 185 of file gnunet-communicator-unix.c.
Referenced by do_shutdown(), lookup_queue(), queue_destroy(), run(), and setup_queue().
|
static |
Head of queue of messages to transmit.
Definition at line 190 of file gnunet-communicator-unix.c.
Referenced by check_for_queue_with_higher_prio(), mq_cancel(), mq_send(), queue_destroy(), schedule_transmit_on_queue(), and select_write_cb().
|
static |
Tail of queue of messages to transmit.
Definition at line 195 of file gnunet-communicator-unix.c.
Referenced by mq_cancel(), mq_send(), queue_destroy(), and select_write_cb().
|
static |
socket that we transmit all data with
Definition at line 200 of file gnunet-communicator-unix.c.
Referenced by do_shutdown(), mq_send(), receive_complete_cb(), run(), select_read_cb(), and select_write_cb().
|
static |
Handle to the operation that publishes our address.
Definition at line 205 of file gnunet-communicator-unix.c.
Referenced by add_setter_action(), attr_iter_cb(), attr_iter_error(), attr_iter_finished(), cleanup_client(), cred_iter_cb(), cred_iter_error(), cred_iter_finished(), do_shutdown(), enc_notify_cb(), GNUNET_NETWORK_test_port_free(), GNUNET_RESOLVER_local_fqdn_get(), GNUNET_STATISTICS_get(), GNUNET_TESTBED_reserve_port(), GNUNET_TRANSPORT_communicator_address_add(), GNUNET_TRANSPORT_communicator_address_remove(), GNUNET_TRANSPORT_communicator_address_remove_all(), handle_ack_by_sender(), handle_credential_iteration_next(), handle_credential_iteration_start(), handle_credential_iteration_stop(), handle_iteration_next(), handle_iteration_start(), handle_iteration_stop(), nat_address_cb(), reconnect(), run(), schedule_watch_request(), send_add_address(), and send_del_address().