#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_arm_service.h"
#include "gnunet_protocols.h"
#include "gnunet_transport_core_service.h"
#include "transport.h"
Go to the source code of this file.
Data Structures | |
struct | Neighbour |
A neighbour that at least one communicator is connected to. More... | |
struct | GNUNET_TRANSPORT_CoreHandle |
Handle for the transport service (includes all of the state for the transport service). More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "transport-api-core", __VA_ARGS__) |
#define | STARTING_NEIGHBOURS_SIZE 16 |
How large to start with for the hashmap of neighbours. More... | |
#define | SEND_WINDOW_SIZE 4 |
Window size. More... | |
Functions | |
static void | disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h) |
Function that will schedule the job that will try to connect us again to the client. More... | |
static struct Neighbour * | neighbour_find (struct GNUNET_TRANSPORT_CoreHandle *h, const struct GNUNET_PeerIdentity *peer) |
Get the neighbour list entry for the given peer. More... | |
static int | neighbour_delete (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
Iterator over hash map entries, for deleting state of a neighbour. More... | |
static void | mq_error_handler (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 void | notify_send_done (void *cls) |
A message from the handler's message queue to a neighbour was transmitted. More... | |
static void | do_send (struct Neighbour *n) |
We have an envelope waiting for transmission at n, and our transmission window is positive. More... | |
static void | mq_send_impl (struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state) |
Implement sending functionality of a message queue. More... | |
static void | mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) |
Handle destruction of a message queue. More... | |
static void | mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) |
Implementation function that cancels the currently sent message. More... | |
static void | peer_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
We had an error processing a message we forwarded from a peer to the CORE service. More... | |
static void | handle_connect (void *cls, const struct ConnectInfoMessage *cim) |
Function we use for handling incoming connect messages. More... | |
static void | handle_disconnect (void *cls, const struct DisconnectInfoMessage *dim) |
Function we use for handling incoming disconnect messages. More... | |
static void | handle_send_ok (void *cls, const struct SendOkMessage *okm) |
Function we use for handling incoming send-ok messages. More... | |
static int | check_recv (void *cls, const struct InboundMessage *im) |
Function we use for checking incoming "inbound" messages. More... | |
static void | handle_recv (void *cls, const struct InboundMessage *im) |
Function we use for handling incoming messages. More... | |
static void | reconnect (void *cls) |
Try again to connect to transport service. More... | |
static void | disconnect (struct GNUNET_TRANSPORT_CoreHandle *h) |
Disconnect from the transport service. More... | |
struct GNUNET_MQ_Handle * | GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle, const struct GNUNET_PeerIdentity *peer) |
Checks if a given peer is connected to us and get the message queue. More... | |
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "transport-api-core", __VA_ARGS__) |
Definition at line 34 of file transport_api2_core.c.
#define STARTING_NEIGHBOURS_SIZE 16 |
How large to start with for the hashmap of neighbours.
Definition at line 39 of file transport_api2_core.c.
#define SEND_WINDOW_SIZE 4 |
Window size.
How many messages to the same target do we pass to TRANSPORT without a SEND_OK in between? Small values limit throughput, large values will increase latency.
FIXME-OPTIMIZE: find out what good values are experimentally, maybe set adaptively (i.e. to observed available bandwidth).
Definition at line 49 of file transport_api2_core.c.
|
static |
Function that will schedule the job that will try to connect us again to the client.
h | transport service to reconnect |
Definition at line 677 of file transport_api2_core.c.
References disconnect(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_duration(), GNUNET_TIME_STD_BACKOFF, GNUNET_TIME_UNIT_MINUTES, GNUNET_TIME_UNIT_ZERO, GNUNET_YES, h, LOG, reconnect(), GNUNET_ARM_Handle::reconnect_task, and GNUNET_TIME_Relative::rel_value_us.
Referenced by handle_connect(), handle_disconnect(), handle_recv(), handle_send_ok(), and mq_error_handler().
|
static |
Get the neighbour list entry for the given peer.
h | our context |
peer | peer to look up |
Definition at line 193 of file transport_api2_core.c.
References GNUNET_CONTAINER_multipeermap_get(), and h.
Referenced by GNUNET_TRANSPORT_core_get_mq(), handle_connect(), handle_disconnect(), handle_recv(), and handle_send_ok().
|
static |
Iterator over hash map entries, for deleting state of a neighbour.
cls | the struct GNUNET_TRANSPORT_CoreHandle * |
key | peer identity |
value | value in the hash map, the neighbour entry to delete |
Definition at line 211 of file transport_api2_core.c.
References GNUNET_TRANSPORT_CoreHandle::cls, Neighbour::env, GNUNET_assert, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_MQ_destroy(), GNUNET_MQ_send_cancel(), GNUNET_YES, handle, Neighbour::handlers_cls, Neighbour::id, key, LOG, Neighbour::mq, and value.
Referenced by disconnect(), and handle_disconnect().
|
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 | closure with the struct GNUNET_TRANSPORT_CoreHandle * |
error | error code |
Definition at line 246 of file transport_api2_core.c.
References GNUNET_TRANSPORT_CoreHandle::cls, disconnect_and_schedule_reconnect(), GNUNET_ERROR_TYPE_DEBUG, h, and LOG.
Referenced by reconnect().
|
static |
A message from the handler's message queue to a neighbour was transmitted.
Now trigger (possibly delayed) notification of the neighbour's message queue that we are done and thus ready for the next message. Note that the MQ being ready is independent of the send window, as we may queue many messages and simply not pass them to TRANSPORT if the send window is insufficient.
cls | the struct Neighbour where the message was sent |
Definition at line 268 of file transport_api2_core.c.
References Neighbour::awaiting_done, Neighbour::env, GNUNET_MQ_impl_send_continue(), GNUNET_NO, Neighbour::mq, and Neighbour::ready_window.
Referenced by do_send().
|
static |
We have an envelope waiting for transmission at n, and our transmission window is positive.
Perform the transmission.
n | neighbour to perform transmission for |
Definition at line 286 of file transport_api2_core.c.
References Neighbour::awaiting_done, Neighbour::env, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_MQ_env_get_msg(), GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_YES, Neighbour::h, Neighbour::id, LOG, GNUNET_TRANSPORT_CoreHandle::mq, notify_send_done(), Neighbour::ready_window, and GNUNET_MessageHeader::type.
Referenced by handle_send_ok(), and mq_send_impl().
|
static |
Implement sending functionality of a message queue.
Called one message at a time. Should send the msg to the transport service and then notify the queue once we are ready for the next one.
mq | the message queue |
msg | the message to send |
impl_state | state of the implementation |
Definition at line 313 of file transport_api2_core.c.
References do_send(), env, Neighbour::env, Neighbour::env_size, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_MAX_MESSAGE_SIZE, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, GNUNET_MQ_env_get_options(), GNUNET_MQ_get_current_envelope(), GNUNET_MQ_impl_send_continue(), GNUNET_MQ_msg_nested_mh, Neighbour::id, LOG, mq, msg, OutboundMessage::peer, OutboundMessage::priority, Neighbour::ready_window, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.
Referenced by handle_connect().
|
static |
Handle 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 | state of the implementation |
Definition at line 364 of file transport_api2_core.c.
References GNUNET_assert, mq, and Neighbour::mq.
Referenced by handle_connect().
|
static |
Implementation function that cancels the currently sent message.
Should basically undo whatever mq_send_impl() did.
mq | message queue |
impl_state | state specific to the implementation |
Definition at line 381 of file transport_api2_core.c.
References Neighbour::awaiting_done, Neighbour::env, GNUNET_assert, GNUNET_MQ_send_cancel(), GNUNET_NO, GNUNET_YES, and Neighbour::ready_window.
Referenced by handle_connect().
|
static |
We had an error processing a message we forwarded from a peer to the CORE service.
We should just complain about it but otherwise continue processing.
cls | closure |
error | error code |
Definition at line 409 of file transport_api2_core.c.
References GNUNET_break_op, GNUNET_MQ_ERROR_MALFORMED, Neighbour::h, and Neighbour::id.
Referenced by handle_connect().
|
static |
Function we use for handling incoming connect messages.
cls | closure, a struct GNUNET_TRANSPORT_Handle * |
cim | message received |
Definition at line 428 of file transport_api2_core.c.
References GNUNET_TRANSPORT_CoreHandle::cls, disconnect_and_schedule_reconnect(), GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_put(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_MQ_queue_for_callbacks(), GNUNET_MQ_set_handlers_closure(), GNUNET_new, GNUNET_OK, h, Neighbour::h, Neighbour::handlers_cls, ConnectInfoMessage::id, Neighbour::id, LOG, Neighbour::mq, mq_cancel_impl(), mq_destroy_impl(), mq_send_impl(), neighbour_find(), peer_mq_error_handler(), Neighbour::ready_window, and SEND_WINDOW_SIZE.
|
static |
Function we use for handling incoming disconnect messages.
cls | closure, a struct GNUNET_TRANSPORT_CoreHandle * |
dim | message received |
Definition at line 476 of file transport_api2_core.c.
References GNUNET_TRANSPORT_CoreHandle::cls, dim, disconnect_and_schedule_reconnect(), GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_YES, h, LOG, neighbour_delete(), and neighbour_find().
|
static |
Function we use for handling incoming send-ok messages.
cls | closure, a struct GNUNET_TRANSPORT_CoreHandle * |
okm | message received |
Definition at line 503 of file transport_api2_core.c.
References Neighbour::awaiting_done, GNUNET_TRANSPORT_CoreHandle::cls, disconnect_and_schedule_reconnect(), do_send(), Neighbour::env, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_MQ_impl_send_continue(), GNUNET_NO, h, LOG, Neighbour::mq, neighbour_find(), SendOkMessage::peer, and Neighbour::ready_window.
|
static |
Function we use for checking incoming "inbound" messages.
cls | closure, a struct GNUNET_TRANSPORT_CoreHandle * |
im | message received |
Definition at line 549 of file transport_api2_core.c.
References GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, InboundMessage::header, GNUNET_MessageHeader::size, and size.
|
static |
Function we use for handling incoming messages.
cls | closure, a struct GNUNET_TRANSPORT_CoreHandle * |
im | message received |
Definition at line 579 of file transport_api2_core.c.
References GNUNET_TRANSPORT_CoreHandle::cls, disconnect_and_schedule_reconnect(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_MQ_inject_message(), h, LOG, Neighbour::mq, neighbour_find(), InboundMessage::peer, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.
|
static |
Try again to connect to transport service.
cls | the handle to the transport service |
Definition at line 608 of file transport_api2_core.c.
References GNUNET_ARM_Handle::cfg, GNUNET_TRANSPORT_CoreHandle::cls, disconnect(), env, GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK, GNUNET_MESSAGE_TYPE_TRANSPORT_START, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_TIME_absolute_get(), h, handlers, LOG, GNUNET_ARM_Handle::mq, mq_error_handler(), options, StartMessage::options, GNUNET_ARM_Handle::reconnect_task, and StartMessage::self.
Referenced by disconnect_and_schedule_reconnect().
|
static |
Disconnect from the transport service.
h | transport service to reconnect |
Definition at line 659 of file transport_api2_core.c.
References GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_MQ_destroy(), h, GNUNET_ARM_Handle::mq, and neighbour_delete().
Referenced by disconnect_and_schedule_reconnect(), and reconnect().
struct GNUNET_MQ_Handle * GNUNET_TRANSPORT_core_get_mq | ( | struct GNUNET_TRANSPORT_CoreHandle * | handle, |
const struct GNUNET_PeerIdentity * | peer | ||
) |
Checks if a given peer is connected to us and get the message queue.
handle | connection to transport service |
peer | the peer to check |
Definition at line 712 of file transport_api2_core.c.
References handle, Neighbour::mq, and neighbour_find().