library to access the transport service for message exchange More...
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_arm_service.h"
#include "gnunet_hello_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_transport_service.h"
#include "transport.h"
Go to the source code of this file.
Data Structures | |
struct | Neighbour |
A connected controller which is not our child. 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 | UNREADY_WARN_TIME GNUNET_TIME_UNIT_MINUTES |
If we could not send any payload to a peer for this amount of time, we print a warning. More... | |
#define | STARTING_NEIGHBOURS_SIZE 16 |
How large to start with for the hashmap of neighbours. 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 void | notify_excess_cb (void *cls) |
Function called by the bandwidth tracker if we have excess bandwidth. 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 int | check_hello (void *cls, const struct GNUNET_MessageHeader *msg) |
Function we use for checking incoming HELLO messages. More... | |
static void | handle_hello (void *cls, const struct GNUNET_MessageHeader *msg) |
Function we use for handling incoming HELLO messages. More... | |
static void | notify_send_done_fin (void *cls) |
A message from the handler's message queue to a neighbour was transmitted. More... | |
static void | notify_send_done (void *cls) |
A message from the handler's message queue to a neighbour was transmitted. 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 | outbound_bw_tracker_update (void *cls) |
The outbound quota has changed in a way that may require us to reset the timeout. 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 | handle_set_quota (void *cls, const struct QuotaSetMessage *qm) |
Function we use for handling incoming set quota messages. More... | |
static void | reconnect (void *cls) |
Try again to connect to 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... | |
struct GNUNET_TRANSPORT_CoreHandle * | GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *self, const struct GNUNET_MQ_MessageHandler *handlers, void *cls, GNUNET_TRANSPORT_NotifyConnect nc, GNUNET_TRANSPORT_NotifyDisconnect nd, GNUNET_TRANSPORT_NotifyExcessBandwidth neb) |
Connect to the transport service. More... | |
void | GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle) |
Disconnect from the transport service. More... | |
library to access the transport service for message exchange
Definition in file transport_api_core.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "transport-api-core", __VA_ARGS__) |
Definition at line 35 of file transport_api_core.c.
#define UNREADY_WARN_TIME GNUNET_TIME_UNIT_MINUTES |
If we could not send any payload to a peer for this amount of time, we print a warning.
Definition at line 41 of file transport_api_core.c.
#define STARTING_NEIGHBOURS_SIZE 16 |
How large to start with for the hashmap of neighbours.
Definition at line 46 of file transport_api_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 805 of file transport_api_core.c.
References GNUNET_assert, GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_STD_BACKOFF, GNUNET_YES, h, LOG, GNUNET_ARM_Handle::mq, neighbour_delete(), reconnect(), and GNUNET_ARM_Handle::reconnect_task.
Referenced by GNUNET_TRANSPORT_core_disconnect(), handle_connect(), handle_disconnect(), handle_recv(), handle_send_ok(), handle_set_quota(), 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 216 of file transport_api_core.c.
References GNUNET_CONTAINER_multipeermap_get(), h, and peer.
Referenced by GNUNET_TRANSPORT_core_get_mq(), handle_connect(), handle_disconnect(), handle_recv(), handle_send_ok(), and handle_set_quota().
|
static |
Function called by the bandwidth tracker if we have excess bandwidth.
cls | the struct Neighbour that has excess bandwidth |
Definition at line 230 of file transport_api_core.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), h, Neighbour::h, Neighbour::handlers_cls, Neighbour::id, and LOG.
Referenced by handle_connect().
|
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 255 of file transport_api_core.c.
References GNUNET_TRANSPORT_CoreHandle::cls, Neighbour::env, GNUNET_assert, GNUNET_BANDWIDTH_tracker_notification_stop(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_MQ_destroy(), GNUNET_MQ_send_cancel(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, handle, Neighbour::handlers_cls, Neighbour::id, key, LOG, Neighbour::mq, Neighbour::out_tracker, Neighbour::timeout_task, and value.
Referenced by disconnect_and_schedule_reconnect(), 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 296 of file transport_api_core.c.
References GNUNET_TRANSPORT_CoreHandle::cls, disconnect_and_schedule_reconnect(), GNUNET_ERROR_TYPE_ERROR, h, and LOG.
Referenced by reconnect().
|
static |
Function we use for checking incoming HELLO messages.
cls | closure, a struct GNUNET_TRANSPORT_CoreHandle * |
msg | message received |
Definition at line 315 of file transport_api_core.c.
References GNUNET_break, GNUNET_HELLO_get_id(), GNUNET_OK, GNUNET_SYSERR, me, and msg.
|
static |
Function we use for handling incoming HELLO messages.
cls | closure, a struct GNUNET_TRANSPORT_CoreHandle * |
msg | message received |
Definition at line 336 of file transport_api_core.c.
|
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.
cls | the struct Neighbour where the message was sent |
Definition at line 351 of file transport_api_core.c.
References GNUNET_MQ_impl_send_continue(), GNUNET_YES, Neighbour::is_ready, Neighbour::mq, and Neighbour::timeout_task.
Referenced by notify_send_done().
|
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.
cls | the struct Neighbour where the message was sent |
Definition at line 370 of file transport_api_core.c.
References delay, Neighbour::env, Neighbour::env_size, GNUNET_BANDWIDTH_tracker_consume(), GNUNET_BANDWIDTH_tracker_get_delay(), GNUNET_MQ_impl_send_continue(), GNUNET_MQ_impl_send_in_flight(), GNUNET_SCHEDULER_add_delayed(), GNUNET_YES, Neighbour::is_ready, Neighbour::mq, notify_send_done_fin(), Neighbour::out_tracker, GNUNET_TIME_Relative::rel_value_us, Neighbour::timeout_task, and Neighbour::traffic_overhead.
Referenced by mq_send_impl(), and outbound_bw_tracker_update().
|
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 409 of file transport_api_core.c.
References 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, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_NO, GNUNET_TIME_relative_hton(), GNUNET_TIME_UNIT_MINUTES, GNUNET_YES, h, Neighbour::h, Neighbour::id, Neighbour::is_ready, LOG, mq, GNUNET_ARM_Handle::mq, msg, notify_send_done(), OutboundMessage::peer, OutboundMessage::priority, GNUNET_MessageHeader::size, OutboundMessage::timeout, Neighbour::timeout_task, 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 458 of file transport_api_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 475 of file transport_api_core.c.
References Neighbour::env, GNUNET_assert, GNUNET_MQ_send_cancel(), GNUNET_NO, GNUNET_YES, and Neighbour::is_ready.
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 499 of file transport_api_core.c.
References GNUNET_break_op.
Referenced by handle_connect().
|
static |
The outbound quota has changed in a way that may require us to reset the timeout.
Update the timeout.
cls | the struct Neighbour for which the timeout changed |
Definition at line 514 of file transport_api_core.c.
References delay, GNUNET_BANDWIDTH_tracker_get_delay(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), notify_send_done(), Neighbour::out_tracker, and Neighbour::timeout_task.
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 534 of file transport_api_core.c.
References GNUNET_TRANSPORT_CoreHandle::cls, disconnect_and_schedule_reconnect(), GNUNET_assert, GNUNET_BANDWIDTH_tracker_init2(), GNUNET_BANDWIDTH_tracker_update_quota(), GNUNET_break, GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, 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, GNUNET_YES, h, Neighbour::h, Neighbour::handlers_cls, ConnectInfoMessage::id, Neighbour::id, Neighbour::is_ready, LOG, MAX_BANDWIDTH_CARRY_S, Neighbour::mq, mq_cancel_impl(), mq_destroy_impl(), mq_send_impl(), neighbour_find(), notify_excess_cb(), Neighbour::out_tracker, outbound_bw_tracker_update(), peer_mq_error_handler(), ConnectInfoMessage::quota_out, Neighbour::traffic_overhead, and GNUNET_BANDWIDTH_Value32NBO::value__.
|
static |
Function we use for handling incoming disconnect messages.
cls | closure, a struct GNUNET_TRANSPORT_CoreHandle * |
dim | message received |
Definition at line 592 of file transport_api_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 619 of file transport_api_core.c.
References SendOkMessage::bytes_msg, SendOkMessage::bytes_physical, GNUNET_TRANSPORT_CoreHandle::cls, disconnect_and_schedule_reconnect(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_OK, h, LOG, neighbour_find(), SendOkMessage::peer, SendOkMessage::success, and Neighbour::traffic_overhead.
|
static |
Function we use for checking incoming "inbound" messages.
cls | closure, a struct GNUNET_TRANSPORT_CoreHandle * |
im | message received |
Definition at line 660 of file transport_api_core.c.
References GNUNET_break, 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 688 of file transport_api_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 |
Function we use for handling incoming set quota messages.
cls | closure, a struct GNUNET_TRANSPORT_CoreHandle * |
qm | message received |
Definition at line 719 of file transport_api_core.c.
References GNUNET_TRANSPORT_CoreHandle::cls, disconnect_and_schedule_reconnect(), GNUNET_BANDWIDTH_tracker_update_quota(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), h, LOG, neighbour_find(), Neighbour::out_tracker, QuotaSetMessage::peer, QuotaSetMessage::quota, and GNUNET_BANDWIDTH_Value32NBO::value__.
|
static |
Try again to connect to transport service.
cls | the handle to the transport service |
Definition at line 746 of file transport_api_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_HELLO, 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_SET_QUOTA, 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(), 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(), and GNUNET_TRANSPORT_core_connect().