GNUnet 0.21.1
gnunet-communicator-unix.c File Reference

Transport plugin using unix domain sockets (!) Clearly, can only be used locally on Unix/Linux hosts... ONLY INTENDED FOR TESTING!!! More...

Include dependency graph for gnunet-communicator-unix.c:

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 Queuelookup_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 Queuesetup_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_Taskread_task
 ID of read task. More...
 
static struct GNUNET_SCHEDULER_Taskwrite_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_Handlestats
 For logging statistics. More...
 
static struct GNUNET_TRANSPORT_CommunicatorHandlech
 Our environment. More...
 
static struct GNUNET_CONTAINER_MultiPeerMapqueue_map
 Queues (map from peer identity to struct Queue) More...
 
static struct Queuequeue_head
 Head of queue of messages to transmit. More...
 
static struct Queuequeue_tail
 Tail of queue of messages to transmit. More...
 
static struct GNUNET_NETWORK_Handleunix_sock
 socket that we transmit all data with More...
 
static struct GNUNET_TRANSPORT_AddressIdentifierai
 Handle to the operation that publishes our address. More...
 

Detailed Description

Transport plugin using unix domain sockets (!) Clearly, can only be used locally on Unix/Linux hosts... ONLY INTENDED FOR TESTING!!!

Author
Christian Grothoff
Nathan Evans

Definition in file gnunet-communicator-unix.c.

Macro Definition Documentation

◆ DEFAULT_MAX_QUEUE_LENGTH

#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 44 of file gnunet-communicator-unix.c.

◆ COMMUNICATOR_ADDRESS_PREFIX

#define COMMUNICATOR_ADDRESS_PREFIX   "unix"

Address prefix used by the communicator.

Definition at line 49 of file gnunet-communicator-unix.c.

◆ COMMUNICATOR_CONFIG_SECTION

#define COMMUNICATOR_CONFIG_SECTION   "communicator-unix"

Configuration section used by the communicator.

Definition at line 54 of file gnunet-communicator-unix.c.

◆ UNIX_MTU

#define UNIX_MTU   UINT16_MAX

Our MTU.

Definition at line 60 of file gnunet-communicator-unix.c.

Function Documentation

◆ queue_destroy()

static void queue_destroy ( struct Queue queue)
static

Functions with this signature are called whenever we need to close a queue due to a disconnect or failure to establish a connection.

Parameters
queuequeue to close down

Definition at line 217 of file gnunet-communicator-unix.c.

218{
219 struct GNUNET_MQ_Handle *mq;
220
222 "Disconnecting queue for peer `%s'\n",
223 GNUNET_i2s (&queue->target));
224 if (0 != queue->bytes_in_queue)
225 {
227 queue->bytes_in_queue = 0;
228 }
229 if (NULL != (mq = queue->mq))
230 {
231 queue->mq = NULL;
233 }
235 GNUNET_YES ==
238 "# queues active",
240 GNUNET_NO);
241 if (NULL != queue->timeout_task)
242 {
243 GNUNET_SCHEDULER_cancel (queue->timeout_task);
244 queue->timeout_task = NULL;
245 }
246 GNUNET_free (queue->address);
248}
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
static struct GNUNET_CONTAINER_MultiPeerMap * queue_map
Queues (map from peer identity to struct Queue)
static struct Queue * queue_tail
Tail of queue of messages to transmit.
static struct GNUNET_STATISTICS_Handle * stats
For logging statistics.
static struct Queue * queue_head
Head of queue of messages to transmit.
static void queue(const char *hostname)
Add hostname to the list of requests to be made.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
#define GNUNET_log(kind,...)
@ GNUNET_YES
@ GNUNET_NO
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:683
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
Handle to a message queue.
Definition: mq.c:87

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ queue_timeout()

static void queue_timeout ( void *  cls)
static

Queue was idle for too long, so disconnect it.

Parameters
clsthe struct Queue * to disconnect

Definition at line 257 of file gnunet-communicator-unix.c.

258{
259 struct Queue *queue = cls;
260 struct GNUNET_TIME_Relative left;
261
262 queue->timeout_task = NULL;
264 if (0 != left.rel_value_us)
265 {
266 /* not actually our turn yet, but let's at least update
267 the monitor, it may think we're about to die ... */
268 queue->timeout_task =
270 return;
271 }
273 "Queue %p was idle for %s, disconnecting\n",
274 queue,
277 GNUNET_YES));
279}
static void queue_timeout(void *cls)
Queue was idle for too long, so disconnect it.
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 fai...
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don't receive messages from the peer?
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1278
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:405
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:570
Time for relative time used by GNUnet, in microseconds.
Handle for a queue.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reschedule_queue_timeout()

static void reschedule_queue_timeout ( struct Queue queue)
static

Increment queue timeout due to activity.

We do not immediately notify the monitor here as that might generate excessive signalling.

Parameters
queuequeue for which the timeout should be rescheduled

Definition at line 290 of file gnunet-communicator-unix.c.

291{
292 GNUNET_assert (NULL != queue->timeout_task);
293 queue->timeout =
295}
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:316

References GNUNET_assert, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, GNUNET_TIME_relative_to_absolute(), and queue().

Referenced by select_read_cb(), and select_write_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unix_address_to_sockaddr()

static struct sockaddr_un * unix_address_to_sockaddr ( const char *  unixpath,
socklen_t *  sock_len 
)
static

Convert unix path to a struct sockaddr_un *

Parameters
unixpathpath to convert
[out]sock_lenset to the length of the address
is_abstractis this an abstract unixpath
Returns
converted unix path

Definition at line 307 of file gnunet-communicator-unix.c.

308{
309 struct sockaddr_un *un;
310 size_t slen;
311
312 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */
313 un = GNUNET_new (struct sockaddr_un);
314 un->sun_family = AF_UNIX;
315 slen = strlen (unixpath);
316 if (slen >= sizeof(un->sun_path))
317 slen = sizeof(un->sun_path) - 1;
318 GNUNET_memcpy (un->sun_path, unixpath, slen);
319 un->sun_path[slen] = '\0';
320 slen = sizeof(struct sockaddr_un);
321#if HAVE_SOCKADDR_UN_SUN_LEN
322 un->sun_len = (u_char) slen;
323#endif
324 (*sock_len) = slen;
325 if ('@' == un->sun_path[0])
326 un->sun_path[0] = '\0';
327 return un;
328}
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_new(type)
Allocate a struct or union of the given type.

References GNUNET_assert, GNUNET_memcpy, and GNUNET_new.

Referenced by mq_init(), and run().

Here is the caller graph for this function:

◆ lookup_queue_it()

static int lookup_queue_it ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Function called to find a queue by address.

Parameters
clsthe struct LookupCtx *
keypeer we are looking for (unused)
valuea queue
Returns
GNUNET_YES if not found (continue looking), GNUNET_NO on success

Definition at line 362 of file gnunet-communicator-unix.c.

363{
364 struct LookupCtx *lctx = cls;
365 struct Queue *queue = value;
366
367 if ((queue->address_len == lctx->un_len) &&
368 (0 == memcmp (lctx->un, queue->address, queue->address_len)))
369 {
370 lctx->res = queue;
371 return GNUNET_NO;
372 }
373 return GNUNET_YES;
374}
static char * value
Value of the record to add/remove.
Closure to lookup_queue_it().
socklen_t un_len
Number of bytes in un.
const struct sockaddr_un * un
Address we are looking for.
struct Queue * res
Location to store the queue, if found.

References GNUNET_NO, GNUNET_YES, queue(), LookupCtx::res, LookupCtx::un, LookupCtx::un_len, and value.

Referenced by lookup_queue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ lookup_queue()

static struct Queue * lookup_queue ( const struct GNUNET_PeerIdentity peer,
const struct sockaddr_un *  un,
socklen_t  un_len 
)
static

Find an existing queue by address.

Parameters
pluginthe plugin
addressthe address to find
Returns
NULL if queue was not found

Definition at line 385 of file gnunet-communicator-unix.c.

388{
389 struct LookupCtx lctx;
390
391 lctx.un = un;
392 lctx.un_len = un_len;
393 lctx.res = NULL;
395 peer,
397 &lctx);
398 return lctx.res;
399}
static int lookup_queue_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Function called to find a queue by address.
int GNUNET_CONTAINER_multipeermap_get_multiple(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map that match a particular key.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ select_write_cb()

static void select_write_cb ( void *  cls)
static

We have been notified that our socket is ready to write.

Then reschedule this function to be called again once more is available.

Parameters
clsNULL

Definition at line 409 of file gnunet-communicator-unix.c.

410{
411 struct Queue *queue = queue_tail;
412 const struct GNUNET_MessageHeader *msg = &queue->msg->header;
413 size_t msg_size = ntohs (msg->size);
414 ssize_t sent;
415
416 /* take queue of the ready list */
417 write_task = NULL;
418resend:
419 /* Send the data */
421 msg,
422 msg_size,
423 (const struct sockaddr *) queue->address,
424 queue->address_len);
426 "UNIX transmitted message to %s (%d/%u: %s)\n",
427 GNUNET_i2s (&queue->target),
428 (int) sent,
429 (unsigned int) msg_size,
430 (sent < 0) ? strerror (errno) : "ok");
431 if (-1 != sent)
432 {
434 if (NULL != queue_head)
436 unix_sock,
438 NULL);
439
440 /* send 'msg' */
441 GNUNET_free (queue->msg);
442 queue->msg = NULL;
445 "# bytes sent",
446 (long long) sent,
447 GNUNET_NO);
449 return; /* all good */
450 }
452 "# network transmission failures",
453 1,
454 GNUNET_NO);
456 unix_sock,
458 NULL);
459 switch (errno)
460 {
461 case EAGAIN:
462 case ENOBUFS:
463 /* We should retry later... */
465 return;
466
467 case EMSGSIZE: {
468 socklen_t size = 0;
469 socklen_t len = sizeof(size);
470
472 SOL_SOCKET,
473 SO_SNDBUF,
474 &size,
475 &len);
476 if (size > ntohs (msg->size))
477 {
478 /* Buffer is bigger than message: error, no retry
479 * This should never happen!*/
480 GNUNET_break (0);
481 return;
482 }
483 GNUNET_log (
485 "Trying to increase socket buffer size from %u to %u for message size %u\n",
486 (unsigned int) size,
487 (unsigned int) ((msg_size / 1000) + 2) * 1000,
488 (unsigned int) msg_size);
489 size = ((msg_size / 1000) + 2) * 1000;
491 SOL_SOCKET,
492 SO_SNDBUF,
493 &size,
494 sizeof(size)))
495 goto resend; /* Increased buffer size, retry sending */
496 /* Ok, then just try very modest increase */
497 size = msg_size;
499 SOL_SOCKET,
500 SO_SNDBUF,
501 &size,
502 sizeof(size)))
503 goto resend; /* Increased buffer size, retry sending */
504 /* Could not increase buffer size: error, no retry */
506 return;
507 }
508
509 default:
511 return;
512 }
513}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
static struct GNUNET_SCHEDULER_Task * write_task
ID of write task.
static void reschedule_queue_timeout(struct Queue *queue)
Increment queue timeout due to activity.
static struct GNUNET_NETWORK_Handle * unix_sock
socket that we transmit all data with
static void select_write_cb(void *cls)
We have been notified that our socket is ready to write.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition: mq.c:421
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_getsockopt(const struct GNUNET_NETWORK_Handle *desc, int level, int optname, void *optval, socklen_t *optlen)
Get socket options.
Definition: network.c:626
int GNUNET_NETWORK_socket_setsockopt(struct GNUNET_NETWORK_Handle *fd, int level, int option_name, const void *option_value, socklen_t option_len)
Set socket option.
Definition: network.c:805
ssize_t GNUNET_NETWORK_socket_sendto(const struct GNUNET_NETWORK_Handle *desc, const void *message, size_t length, const struct sockaddr *dest_addr, socklen_t dest_len)
Send data to a particular destination (always non-blocking).
Definition: network.c:771
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_write_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1583
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static unsigned int size
Size of the "table".
Definition: peer.c:68
Header for all communications.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_send()

static void mq_send ( struct GNUNET_MQ_Handle mq,
const struct GNUNET_MessageHeader msg,
void *  impl_state 
)
static

Signature of functions implementing the sending functionality of a message queue.

Parameters
mqthe message queue
msgthe message to send
impl_stateour struct Queue

Definition at line 525 of file gnunet-communicator-unix.c.

528{
529 struct Queue *queue = impl_state;
530 size_t msize = ntohs (msg->size);
531
532 GNUNET_assert (mq == queue->mq);
533 GNUNET_assert (NULL == queue->msg);
534 // Convert to UNIXMessage
535 queue->msg = GNUNET_malloc (msize + sizeof (struct UNIXMessage));
536 queue->msg->header.size = htons (msize + sizeof (struct UNIXMessage));
537 queue->msg->sender = my_identity;
538 memcpy (&queue->msg[1], msg, msize);
540 GNUNET_assert (NULL != unix_sock);
541 if (NULL == write_task)
543 unix_sock,
545 NULL);
546}
static struct GNUNET_PeerIdentity my_identity
My Peer Identity.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_malloc(size)
Wrapper around malloc.
UNIX Message-Packet header.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_destroy()

static void mq_destroy ( struct GNUNET_MQ_Handle mq,
void *  impl_state 
)
static

Signature of functions implementing the destruction of a message queue.

Implementations must not free mq, but should take care of impl_state.

Parameters
mqthe message queue to destroy
impl_stateour struct Queue

Definition at line 558 of file gnunet-communicator-unix.c.

559{
560 struct Queue *queue = impl_state;
561
562 if (mq == queue->mq)
563 {
564 queue->mq = NULL;
566 }
567}

References mq, queue(), and queue_destroy().

Referenced by setup_queue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_cancel()

static void mq_cancel ( struct GNUNET_MQ_Handle mq,
void *  impl_state 
)
static

Implementation function that cancels the currently sent message.

Parameters
mqmessage queue
impl_stateour struct Queue

Definition at line 577 of file gnunet-communicator-unix.c.

578{
579 struct Queue *queue = impl_state;
580
581 GNUNET_assert (NULL != queue->msg);
582 queue->msg = NULL;
584 GNUNET_assert (NULL != write_task);
585 if (NULL == queue_head)
586 {
588 write_task = NULL;
589 }
590}

References GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_SCHEDULER_cancel(), queue(), queue_head, queue_tail, and write_task.

Referenced by setup_queue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_error()

static void mq_error ( void *  cls,
enum GNUNET_MQ_Error  error 
)
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.

Parameters
clsour struct Queue
errorerror code

Definition at line 603 of file gnunet-communicator-unix.c.

604{
605 struct Queue *queue = cls;
606
608 "UNIX MQ error in queue to %s: %d\n",
609 GNUNET_i2s (&queue->target),
610 (int) error);
612}

References GNUNET_ERROR_TYPE_ERROR, GNUNET_i2s(), GNUNET_log, queue(), and queue_destroy().

Referenced by setup_queue().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_queue()

static struct Queue * setup_queue ( const struct GNUNET_PeerIdentity target,
enum GNUNET_TRANSPORT_ConnectionStatus  cs,
const struct sockaddr_un *  un,
socklen_t  un_len 
)
static

Creates a new outbound queue the transport service will use to send data to another peer.

Parameters
peerthe target peer
csinbound or outbound queue
unthe address
un_lennumber of bytes in un
Returns
the queue or NULL of max connections exceeded

Definition at line 626 of file gnunet-communicator-unix.c.

630{
631 struct Queue *queue;
632
633 queue = GNUNET_new (struct Queue);
634 queue->target = *target;
635 queue->address = GNUNET_memdup (un, un_len);
636 queue->address_len = un_len;
638 queue_map,
639 &queue->target,
640 queue,
643 "# queues active",
645 GNUNET_NO);
646 queue->timeout =
648 queue->timeout_task =
651 queue);
653 &mq_destroy,
654 &mq_cancel,
655 queue,
656 NULL,
657 &mq_error,
658 queue);
659 {
660 char *foreign_addr;
661
662 if ('\0' == un->sun_path[0])
663 GNUNET_asprintf (&foreign_addr,
664 "%s-@%s",
666 &un->sun_path[1]);
667 else
668 GNUNET_asprintf (&foreign_addr,
669 "%s-%s",
671 un->sun_path);
673 &queue->target,
674 foreign_addr,
675 UNIX_MTU - sizeof (struct
678 0,
680 cs,
681 queue->mq);
682 GNUNET_free (foreign_addr);
683 }
684 return queue;
685}
#define UNIX_MTU
Our MTU.
#define COMMUNICATOR_ADDRESS_PREFIX
Address prefix used by the communicator.
static void mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
Signature of functions implementing the destruction of a message queue.
static struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Our environment.
static void mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
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 c...
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.
#define GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED
Queue length.
struct GNUNET_TRANSPORT_QueueHandle * GNUNET_TRANSPORT_communicator_mq_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_PeerIdentity *peer, const char *address, uint32_t mtu, uint64_t q_len, uint32_t priority, enum GNUNET_NetworkType nt, enum GNUNET_TRANSPORT_ConnectionStatus cs, struct GNUNET_MQ_Handle *mq)
Notify transport service that a MQ became available due to an "inbound" connection or because the com...
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
struct GNUNET_MQ_Handle * GNUNET_MQ_queue_for_callbacks(GNUNET_MQ_SendImpl send, GNUNET_MQ_DestroyImpl destroy, GNUNET_MQ_CancelImpl cancel, void *impl_state, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *cls)
Create a message queue for the specified handlers.
Definition: mq.c:465
@ GNUNET_NT_LOOPBACK
Loopback (same host).
Definition: gnunet_nt_lib.h:53
struct GNUNET_PeerIdentity target
To whom are we talking to.
enum GNUNET_TRANSPORT_ConnectionStatus cs
The connection status of this queue.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ select_read_cb()

static void select_read_cb ( void *  cls)
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.

Parameters
clsNULL

Definition at line 733 of file gnunet-communicator-unix.c.

734{
735 char buf[65536] GNUNET_ALIGN;
736 struct Queue *queue;
737 const struct UNIXMessage *msg;
738 struct sockaddr_un un;
739 socklen_t addrlen;
740 ssize_t ret;
741 uint16_t msize;
742
743 GNUNET_assert (NULL != unix_sock);
745 unix_sock,
747 NULL);
748 addrlen = sizeof(un);
749 memset (&un, 0, sizeof(un));
751 buf,
752 sizeof(buf),
753 (struct sockaddr *) &un,
754 &addrlen);
755 if ((-1 == ret) && ((EAGAIN == errno) || (ENOBUFS == errno)))
756 return;
757 if (-1 == ret)
758 {
760 return;
761 }
763 "Read %d bytes from socket %s\n",
764 (int) ret,
765 un.sun_path);
766 GNUNET_assert (AF_UNIX == (un.sun_family));
767 msg = (struct UNIXMessage *) buf;
768 msize = ntohs (msg->header.size);
769 if ((msize < sizeof(struct UNIXMessage)) || (msize > ret))
770 {
772 "Wrong message size: %d bytes\n",
773 msize);
774 GNUNET_break_op (0);
775 return;
776 }
777 queue = lookup_queue (&msg->sender, &un, addrlen);
778 if (NULL == queue)
779 queue =
780 setup_queue (&msg->sender, GNUNET_TRANSPORT_CS_INBOUND, &un, addrlen);
781 else
783 if (NULL == queue)
784 {
785 GNUNET_log (
787 _ (
788 "Maximum number of UNIX connections exceeded, dropping incoming message\n"));
789 return;
790 }
791
792 {
793 uint16_t tsize = msize - sizeof(struct UNIXMessage);
794
795 const struct GNUNET_MessageHeader *currhdr;
796 struct GNUNET_MessageHeader al_hdr;
797
798 currhdr = (const struct GNUNET_MessageHeader *) &msg[1];
799 /* ensure aligned access */
800 memcpy (&al_hdr, currhdr, sizeof(al_hdr));
801 if ((tsize < sizeof(struct GNUNET_MessageHeader)) ||
802 (tsize != ntohs (al_hdr.size)))
803 {
804 GNUNET_break_op (0);
805 return;
806 }
808 &msg->sender,
809 currhdr,
812 NULL);
813 if (GNUNET_SYSERR == ret)
814 {
816 "Transport not up!\n");
817 return; /* transport not up */
818 }
819 if (GNUNET_NO == ret)
820 {
822 "Error sending message to transport\n");
823 return;
824 }
826 }
828 {
830 "Back pressure %llu\n", delivering_messages);
831
832 /* we should try to apply 'back pressure' */
834 read_task = NULL;
835 }
836}
static int ret
Final status code.
Definition: gnunet-arm.c:94
static void receive_complete_cb(void *cls, int success)
Function called when message was successfully passed to transport service.
static unsigned long long max_queue_length
Maximum queue length before we stop reading towards the transport service.
static struct GNUNET_SCHEDULER_Task * read_task
ID of read task.
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.
static unsigned long long delivering_messages
Number of messages we currently have in our queues towards the transport service.
static void select_read_cb(void *cls)
We have been notified that our socket has something to read.
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.
int GNUNET_TRANSPORT_communicator_receive(struct GNUNET_TRANSPORT_CommunicatorHandle *handle, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg, struct GNUNET_TIME_Relative expected_addr_validity, GNUNET_TRANSPORT_MessageCompletedCallback cb, void *cb_cls)
Notify transport service that the communicator has received a message.
@ GNUNET_TRANSPORT_CS_INBOUND
this is an inbound connection (communicator initiated)
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
ssize_t GNUNET_NETWORK_socket_recvfrom(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length, struct sockaddr *src_addr, socklen_t *addrlen)
Read data from a socket (always non-blocking).
Definition: network.c:687
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1512
#define _(String)
GNU gettext support macro.
Definition: platform.h:178

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ receive_complete_cb()

static void receive_complete_cb ( void *  cls,
int  success 
)
static

Function called when message was successfully passed to transport service.

Continue read activity.

Parameters
clsNULL
successGNUNET_OK on success

Definition at line 707 of file gnunet-communicator-unix.c.

708{
709 (void) cls;
711 if (GNUNET_OK != success)
713 "# transport transmission failures",
714 1,
715 GNUNET_NO);
716 if ((NULL == read_task) && (delivering_messages < max_queue_length) &&
717 (NULL != unix_sock))
719 unix_sock,
721 NULL);
722}

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_init()

static int mq_init ( void *  cls,
const struct GNUNET_PeerIdentity peer,
const char *  address 
)
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.

Parameters
clsclosure
peeridentity of the other peer
addresswhere to send the message, human-readable communicator-specific format, 0-terminated, UTF-8
Returns
GNUNET_OK on success, GNUNET_SYSERR if the provided address is invalid

Definition at line 857 of file gnunet-communicator-unix.c.

858{
859 struct Queue *queue;
860 const char *path;
861 struct sockaddr_un *un;
862 socklen_t un_len;
863
864 (void) cls;
865 if (0 != strncmp (address,
867 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
868 {
869 GNUNET_break_op (0);
870 return GNUNET_SYSERR;
871 }
872 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
873 un = unix_address_to_sockaddr (path, &un_len);
874 queue = lookup_queue (peer, un, un_len);
875 if (NULL != queue)
876 {
878 "Address `%s' for %s ignored, queue exists\n",
879 path,
880 GNUNET_i2s (peer));
881 GNUNET_free (un);
882 return GNUNET_OK;
883 }
884 queue = setup_queue (peer, GNUNET_TRANSPORT_CS_OUTBOUND, un, un_len);
885 GNUNET_free (un);
886 if (NULL == queue)
887 {
889 "Failed to setup queue to %s at `%s'\n",
890 GNUNET_i2s (peer),
891 path);
892 return GNUNET_NO;
893 }
894 return GNUNET_OK;
895}
static struct sockaddr_un * unix_address_to_sockaddr(const char *unixpath, socklen_t *sock_len)
Convert unix path to a struct sockaddr_un *
static char * address
GNS address for this phone.
@ GNUNET_TRANSPORT_CS_OUTBOUND
this is an outbound connection (transport initiated)
@ GNUNET_ERROR_TYPE_INFO

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_queue_delete_it()

static int get_queue_delete_it ( void *  cls,
const struct GNUNET_PeerIdentity target,
void *  value 
)
static

Iterator over all message queues to clean up.

Parameters
clsNULL
targetunused
valuethe queue to destroy
Returns
GNUNET_OK to continue to iterate

Definition at line 907 of file gnunet-communicator-unix.c.

910{
911 struct Queue *queue = value;
912
913 (void) cls;
914 (void) target;
916 return GNUNET_OK;
917}

References GNUNET_OK, queue(), queue_destroy(), Queue::target, and value.

Referenced by do_shutdown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Shutdown the UNIX communicator.

Parameters
clsNULL (always)

Definition at line 926 of file gnunet-communicator-unix.c.

927{
928 if (NULL != read_task)
929 {
931 read_task = NULL;
932 }
933 if (NULL != write_task)
934 {
936 write_task = NULL;
937 }
938 if (NULL != unix_sock)
939 {
941 unix_sock = NULL;
942 }
945 if (NULL != ai)
946 {
948 ai = NULL;
949 }
950 if (NULL != ch)
951 {
953 ch = NULL;
954 }
955 if (NULL != stats)
956 {
958 stats = NULL;
959 }
960}
static int get_queue_delete_it(void *cls, const struct GNUNET_PeerIdentity *target, void *value)
Iterator over all message queues to clean up.
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
void GNUNET_TRANSPORT_communicator_address_remove(struct GNUNET_TRANSPORT_AddressIdentifier *ai)
Notify transport service about an address that this communicator no longer provides for this peer.
void GNUNET_TRANSPORT_communicator_disconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Disconnect from the transport service.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:508
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ enc_notify_cb()

static void enc_notify_cb ( void *  cls,
const struct GNUNET_PeerIdentity sender,
const struct GNUNET_MessageHeader msg 
)
static

Function called when the transport service has received an acknowledgement for this communicator (!) via a different return path.

Not applicable for UNIX.

Parameters
clsclosure
senderwhich peer sent the notification
msgpayload

Definition at line 975 of file gnunet-communicator-unix.c.

978{
979 (void) cls;
980 (void) sender;
981 (void) msg;
982 GNUNET_break_op (0);
983}

References GNUNET_break_op, and msg.

Referenced by run().

Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Setup communicator and launch network interactions.

Parameters
clsNULL (always)
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cfgconfiguration

Definition at line 995 of file gnunet-communicator-unix.c.

999{
1000 char *unix_socket_path;
1001 struct sockaddr_un *un;
1002 socklen_t un_len;
1003 char *my_addr;
1005
1006 (void) cls;
1008
1010 if (NULL == my_private_key)
1011 {
1012 GNUNET_log (
1014 _ (
1015 "UNIX communicator is lacking key configuration settings. Exiting.\n"));
1017 return;
1018 }
1020
1021 if (GNUNET_OK !=
1024 "UNIXPATH",
1025 &unix_socket_path))
1026 {
1029 "UNIXPATH");
1030 return;
1031 }
1032 if (GNUNET_OK !=
1035 "MAX_QUEUE_LENGTH",
1038
1039 un = unix_address_to_sockaddr (unix_socket_path, &un_len);
1040 if (NULL == un)
1041 {
1043 "Failed to setup UNIX domain socket address with path `%s'\n",
1044 unix_socket_path);
1045 GNUNET_free (unix_socket_path);
1046 return;
1047 }
1048 unix_sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0);
1049 if (NULL == unix_sock)
1050 {
1052 GNUNET_free (un);
1053 GNUNET_free (unix_socket_path);
1054 return;
1055 }
1056 if (('\0' != un->sun_path[0]) &&
1058 {
1060 _ ("Cannot create path to `%s'\n"),
1061 un->sun_path);
1063 unix_sock = NULL;
1064 GNUNET_free (un);
1065 GNUNET_free (unix_socket_path);
1066 return;
1067 }
1069 (const struct sockaddr *) un,
1070 un_len))
1071 {
1072 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", un->sun_path);
1074 unix_sock = NULL;
1075 GNUNET_free (un);
1076 GNUNET_free (unix_socket_path);
1077 return;
1078 }
1079 GNUNET_free (un);
1080 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", unix_socket_path);
1081 stats = GNUNET_STATISTICS_create ("C-UNIX", cfg);
1084 unix_sock,
1086 NULL);
1092 &mq_init,
1093 NULL,
1095 NULL);
1096 if (NULL == ch)
1097 {
1098 GNUNET_break (0);
1100 GNUNET_free (unix_socket_path);
1101 return;
1102 }
1103 GNUNET_asprintf (&my_addr,
1104 "%s-%s",
1106 unix_socket_path);
1107 GNUNET_free (unix_socket_path);
1109 my_addr,
1112 GNUNET_free (my_addr);
1113}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
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 (!...
static void do_shutdown(void *cls)
Shutdown the UNIX communicator.
#define COMMUNICATOR_CONFIG_SECTION
Configuration section used by the communicator.
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 abou...
#define DEFAULT_MAX_QUEUE_LENGTH
How many messages do we keep at most in the queue to the transport service before we start to drop (d...
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
Definition: gnunet-hello.c:96
struct GNUNET_TRANSPORT_CommunicatorHandle * GNUNET_TRANSPORT_communicator_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section_name, const char *addr_prefix, enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, GNUNET_TRANSPORT_CommunicatorMqInit mq_init, void *mq_init_cls, GNUNET_TRANSPORT_CommunicatorNotify notify_cb, void *notify_cb_cls)
Connect to the transport service.
struct GNUNET_TRANSPORT_AddressIdentifier * GNUNET_TRANSPORT_communicator_address_add(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const char *address, enum GNUNET_NetworkType nt, struct GNUNET_TIME_Relative expiration)
Notify transport service about an address that this communicator provides for this peer.
@ GNUNET_TRANSPORT_CC_RELIABLE
Transmission is reliabile (with ACKs), e.g.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:198
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_CRYPTO_eddsa_key_create_from_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new private key by reading our peer's key from the file specified in the configuration.
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_create_for_file(const char *filename)
Create the directory structure for storing a file.
Definition: disk.c:582
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:832
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Bind a socket to a particular address.
Definition: network.c:439
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:567
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1340
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
Private ECC key encoded for transmission.
struct GNUNET_CRYPTO_EddsaPublicKey public_key

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function for the UNIX communicator.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 1124 of file gnunet-communicator-unix.c.

1125{
1126 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1128 };
1129 int ret;
1130
1131 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1132 return 2;
1133
1134 ret = (GNUNET_OK ==
1135 GNUNET_PROGRAM_run (argc,
1136 argv,
1137 "gnunet-communicator-unix",
1138 _ ("GNUnet UNIX domain socket communicator"),
1139 options,
1140 &run,
1141 NULL))
1142 ? 0
1143 : 1;
1144 GNUNET_free_nz ((void *) argv);
1145 return ret;
1146}
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Setup communicator and launch network interactions.
#define GNUNET_free_nz(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:400
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1230
Definition of a command line option.

References _, GNUNET_free_nz, GNUNET_GETOPT_OPTION_END, GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), options, ret, and run().

Here is the call graph for this function:

Variable Documentation

◆ my_identity

struct GNUNET_PeerIdentity my_identity
static

My Peer Identity.

Definition at line 151 of file gnunet-communicator-unix.c.

Referenced by mq_send(), and run().

◆ read_task

struct GNUNET_SCHEDULER_Task* read_task
static

ID of read task.

Definition at line 156 of file gnunet-communicator-unix.c.

Referenced by do_shutdown(), receive_complete_cb(), run(), and select_read_cb().

◆ write_task

struct GNUNET_SCHEDULER_Task* write_task
static

ID of write task.

Definition at line 161 of file gnunet-communicator-unix.c.

Referenced by do_shutdown(), mq_cancel(), mq_send(), and select_write_cb().

◆ delivering_messages

unsigned long long delivering_messages
static

Number of messages we currently have in our queues towards the transport service.

Definition at line 166 of file gnunet-communicator-unix.c.

Referenced by receive_complete_cb(), run(), and select_read_cb().

◆ max_queue_length

unsigned long long max_queue_length
static

Maximum queue length before we stop reading towards the transport service.

Definition at line 171 of file gnunet-communicator-unix.c.

Referenced by receive_complete_cb(), run(), and select_read_cb().

◆ stats

struct GNUNET_STATISTICS_Handle* stats
static

For logging statistics.

Definition at line 176 of file gnunet-communicator-unix.c.

Referenced by do_shutdown(), queue_destroy(), receive_complete_cb(), run(), select_write_cb(), and setup_queue().

◆ ch

Our environment.

Definition at line 181 of file gnunet-communicator-unix.c.

Referenced by do_shutdown(), run(), select_read_cb(), and setup_queue().

◆ queue_map

struct GNUNET_CONTAINER_MultiPeerMap* queue_map
static

Queues (map from peer identity to struct Queue)

Definition at line 186 of file gnunet-communicator-unix.c.

Referenced by do_shutdown(), lookup_queue(), queue_destroy(), run(), and setup_queue().

◆ queue_head

struct Queue* queue_head
static

Head of queue of messages to transmit.

Definition at line 191 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().

◆ queue_tail

struct Queue* queue_tail
static

Tail of queue of messages to transmit.

Definition at line 196 of file gnunet-communicator-unix.c.

Referenced by mq_cancel(), mq_send(), queue_destroy(), and select_write_cb().

◆ unix_sock

struct GNUNET_NETWORK_Handle* unix_sock
static

socket that we transmit all data with

Definition at line 201 of file gnunet-communicator-unix.c.

Referenced by do_shutdown(), mq_send(), receive_complete_cb(), run(), select_read_cb(), and select_write_cb().

◆ ai