cadet api: client implementation of cadet service More...
#include "platform.h"#include "gnunet_util_lib.h"#include "gnunet_constants.h"#include "gnunet_cadet_service.h"#include "cadet.h"#include "cadet_protocol.h"Go to the source code of this file.
Data Structures | |
| struct | GNUNET_CADET_Handle |
| Opaque handle to the service. More... | |
| struct | GNUNET_CADET_Port |
| Opaque handle to a port. More... | |
Macros | |
| #define | LOG(kind, ...) GNUNET_log_from (kind, "cadet-api", __VA_ARGS__) |
Functions | |
| static struct GNUNET_CADET_Port * | find_port (const struct GNUNET_CADET_Handle *h, const struct GNUNET_HashCode *hash) |
| Find the Port struct for a hash. | |
| static struct GNUNET_CADET_Channel * | find_channel (struct GNUNET_CADET_Handle *h, struct GNUNET_CADET_ClientChannelNumber ccn) |
| Get the channel handler for the channel specified by id from the given handle. | |
| static struct GNUNET_CADET_Channel * | create_channel (struct GNUNET_CADET_Handle *h, const struct GNUNET_CADET_ClientChannelNumber *ccnp) |
| Create a new channel and insert it in the channel list of the cadet handle. | |
| static void | destroy_channel (struct GNUNET_CADET_Channel *ch) |
| Destroy the specified channel. | |
| static void | reconnect (struct GNUNET_CADET_Handle *h) |
| Reconnect to the service, retransmit all information to try to restore the original state. | |
| static int | open_port_cb (void *cls, const struct GNUNET_HashCode *id, void *value) |
| Function called during reconnect_cbk() to (re)open all ports that are still open. | |
| static void | reconnect_cbk (void *cls) |
| Reconnect callback: tries to reconnect again after a failed previous connection. | |
| static void | notify_window_size (struct GNUNET_CADET_Channel *ch) |
| Notify the application about a change in the window size (if needed). | |
| static void | cadet_mq_send_now (void *cls) |
| Transmit the next message from our queue. | |
| static void | cadet_mq_send_impl (struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state) |
| Implement sending functionality of a message queue for us sending messages to a peer. | |
| static void | cadet_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) |
| Handle destruction of a message queue. | |
| static void | cadet_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
| We had an error processing a message we forwarded from a peer to the CADET service. | |
| static void | cadet_mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) |
| Implementation function that cancels the currently sent message. | |
| static void | handle_channel_created (void *cls, const struct GNUNET_CADET_LocalChannelCreateMessage *msg) |
| Process the new channel notification and add it to the channels in the handle. | |
| static void | handle_channel_destroy (void *cls, const struct GNUNET_CADET_LocalChannelDestroyMessage *msg) |
| Process the channel destroy notification and free associated resources. | |
| static int | check_local_data (void *cls, const struct GNUNET_CADET_LocalData *message) |
| Check that message received from CADET service is well-formed. | |
| static void | handle_local_data (void *cls, const struct GNUNET_CADET_LocalData *message) |
| Process the incoming data packets, call appropriate handlers. | |
| static void | handle_local_ack (void *cls, const struct GNUNET_CADET_LocalAck *message) |
| Process a local ACK message, enabling the client to send more data to the service. | |
| static int | destroy_channel_cb (void *cls, uint32_t cid, void *value) |
| Function called during GNUNET_CADET_disconnect() to destroy all channels that are still open. | |
| static void | handle_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. | |
| static int | destroy_port_cb (void *cls, const struct GNUNET_HashCode *id, void *value) |
| Function called during GNUNET_CADET_disconnect() to destroy all ports that are still open. | |
| void | GNUNET_CADET_disconnect (struct GNUNET_CADET_Handle *handle) |
| Disconnect from the cadet service. | |
| void | GNUNET_CADET_close_port (struct GNUNET_CADET_Port *p) |
| Close a port opened with GNUNET_CADET_open_port. | |
| void | GNUNET_CADET_channel_destroy (struct GNUNET_CADET_Channel *channel) |
| Destroy an existing channel. | |
| const union GNUNET_CADET_ChannelInfo * | GNUNET_CADET_channel_get_info (struct GNUNET_CADET_Channel *channel, enum GNUNET_CADET_ChannelInfoOption option,...) |
| Get information about a channel. | |
| void | GNUNET_CADET_receive_done (struct GNUNET_CADET_Channel *channel) |
| Send an ack on the channel to confirm the processing of a message. | |
| struct GNUNET_CADET_Handle * | GNUNET_CADET_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) |
| Connect to the MQ-based cadet service. | |
| static void | return_agpl (void *cls, const struct GNUNET_MessageHeader *msg) |
| Function to return link to AGPL source upon request. | |
| struct GNUNET_CADET_Port * | GNUNET_CADET_open_port (struct GNUNET_CADET_Handle *h, const struct GNUNET_HashCode *port, GNUNET_CADET_ConnectEventHandler connects, void *connects_cls, GNUNET_CADET_WindowSizeEventHandler window_changes, GNUNET_CADET_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers) |
| Open a port to receive incoming MQ-based channels. | |
| struct GNUNET_CADET_Channel * | GNUNET_CADET_channel_create (struct GNUNET_CADET_Handle *h, void *channel_cls, const struct GNUNET_PeerIdentity *destination, const struct GNUNET_HashCode *port, GNUNET_CADET_WindowSizeEventHandler window_changes, GNUNET_CADET_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers) |
| Create a new channel towards a remote peer. | |
| struct GNUNET_MQ_Handle * | GNUNET_CADET_get_mq (const struct GNUNET_CADET_Channel *channel) |
| Obtain the message queue for a connected peer. | |
cadet api: client implementation of cadet service
Definition in file cadet_api.c.
| #define LOG | ( | kind, | |
| ... | |||
| ) | GNUNET_log_from (kind, "cadet-api", __VA_ARGS__) |
Definition at line 33 of file cadet_api.c.
|
static |
Find the Port struct for a hash.
| h | CADET handle. |
| hash | HashCode for the port number. |
Definition at line 131 of file cadet_api.c.
References GNUNET_CONTAINER_multihashmap_get(), and h.
Referenced by handle_channel_created().
|
static |
Get the channel handler for the channel specified by id from the given handle.
| h | Cadet handle |
| ccn | ID of the wanted channel |
Definition at line 146 of file cadet_api.c.
References GNUNET_CADET_Channel::ccn, GNUNET_CADET_ClientChannelNumber::channel_of_client, GNUNET_CONTAINER_multihashmap32_get(), and h.
Referenced by create_channel(), handle_channel_destroy(), handle_local_ack(), and handle_local_data().
|
static |
Create a new channel and insert it in the channel list of the cadet handle.
| h | Cadet handle |
| ccnp | pointer to desired ccn of the channel, NULL to assign one automatically. |
Definition at line 162 of file cadet_api.c.
References GNUNET_CADET_Channel::cadet, GNUNET_CADET_Channel::ccn, ch, GNUNET_CADET_ClientChannelNumber::channel_of_client, find_channel(), GNUNET_assert, GNUNET_CADET_LOCAL_CHANNEL_ID_CLI, GNUNET_CONTAINER_multihashmap32_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_new, GNUNET_OK, and h.
Referenced by GNUNET_CADET_channel_create(), and handle_channel_created().
|
static |
Destroy the specified channel.
| ch | Pointer to the channel. |
Definition at line 203 of file cadet_api.c.
References GNUNET_CADET_Channel::cadet, GNUNET_CADET_Channel::ccn, ch, GNUNET_CADET_ClientChannelNumber::channel_of_client, GNUNET_CADET_Channel::ctx, GNUNET_CADET_Channel::disconnects, GNUNET_assert, GNUNET_CONTAINER_multihashmap32_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_MQ_destroy(), GNUNET_MQ_discard(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, h, LOG, GNUNET_CADET_Channel::mq, GNUNET_CADET_Channel::mq_cont, and GNUNET_CADET_Channel::pending_env.
Referenced by destroy_channel_cb(), GNUNET_CADET_channel_destroy(), and handle_channel_destroy().
|
static |
Reconnect to the service, retransmit all information to try to restore the original state.
| h | handle to the cadet |
Definition at line 717 of file cadet_api.c.
References GNUNET_ARM_Handle::cfg, channel_destroy(), GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE, GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY, GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, h, handle_mq_error(), handlers, and GNUNET_ARM_Handle::mq.
|
static |
Function called during reconnect_cbk() to (re)open all ports that are still open.
| cls | the struct GNUNET_CADET_Handle |
| id | port ID |
| value | a struct GNUNET_CADET_Channel to open |
Definition at line 251 of file cadet_api.c.
References env, GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_OK, h, GNUNET_ARM_Handle::mq, msg, port, and value.
Referenced by GNUNET_CADET_open_port(), and reconnect_cbk().
|
static |
Reconnect callback: tries to reconnect again after a failed previous connection.
| cls | closure (cadet handle) |
Definition at line 273 of file cadet_api.c.
References GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_TIME_STD_BACKOFF, h, open_port_cb(), reconnect(), and GNUNET_ARM_Handle::reconnect_task.
Referenced by handle_mq_error().
|
static |
Notify the application about a change in the window size (if needed).
| ch | Channel to notify about. |
Definition at line 290 of file cadet_api.c.
References GNUNET_CADET_Channel::allow_send, ch, GNUNET_CADET_Channel::ctx, and GNUNET_CADET_Channel::window_changes.
Referenced by handle_local_ack().
|
static |
Transmit the next message from our queue.
| cls | Closure (channel whose mq to activate). |
Definition at line 305 of file cadet_api.c.
References GNUNET_CADET_Channel::allow_send, GNUNET_CADET_Channel::cadet, ch, env, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_MQ_impl_send_continue(), GNUNET_MQ_send(), GNUNET_CADET_Channel::mq, GNUNET_CADET_Handle::mq, GNUNET_CADET_Channel::mq_cont, GNUNET_CADET_Channel::peer, and GNUNET_CADET_Channel::pending_env.
Referenced by cadet_mq_send_impl(), and handle_local_ack().
|
static |
Implement sending functionality of a message queue for us sending messages to a peer.
Encapsulates the payload message in a GNUNET_CADET_LocalData message in order to label the message with the channel ID and send the encapsulated message to the service.
| mq | the message queue |
| msg | the message to send |
| impl_state | state of the implementation |
Definition at line 347 of file cadet_api.c.
References GNUNET_CADET_Channel::allow_send, GNUNET_CADET_Channel::cadet, cadet_mq_send_now(), GNUNET_CADET_Channel::ccn, GNUNET_CADET_LocalData::ccn, ch, env, GNUNET_assert, GNUNET_break, GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE, GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA, GNUNET_MQ_env_get_options(), GNUNET_MQ_get_current_envelope(), GNUNET_MQ_impl_send_continue(), GNUNET_MQ_msg_nested_mh, GNUNET_SCHEDULER_add_now(), h, mq, GNUNET_ARM_Handle::mq, GNUNET_CADET_Channel::mq_cont, msg, GNUNET_CADET_Channel::pending_env, GNUNET_CADET_LocalData::pp, and GNUNET_MessageHeader::size.
Referenced by GNUNET_CADET_channel_create(), and handle_channel_created().
|
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 396 of file cadet_api.c.
References ch, GNUNET_assert, mq, and GNUNET_CADET_Channel::mq.
Referenced by GNUNET_CADET_channel_create(), and handle_channel_created().
|
static |
We had an error processing a message we forwarded from a peer to the CADET service.
We should just complain about it but otherwise continue processing.
| cls | closure with our struct GNUNET_CADET_Channel |
| error | error code |
Definition at line 414 of file cadet_api.c.
References ch, GNUNET_CADET_Channel::ctx, GNUNET_CADET_Channel::disconnects, GNUNET_break_op, GNUNET_CADET_channel_destroy(), GNUNET_CADET_receive_done(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, and GNUNET_MQ_ERROR_NO_MATCH.
Referenced by GNUNET_CADET_channel_create(), and handle_channel_created().
|
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 444 of file cadet_api.c.
References ch, GNUNET_assert, GNUNET_MQ_discard(), GNUNET_SCHEDULER_cancel(), mq, GNUNET_CADET_Channel::mq_cont, and GNUNET_CADET_Channel::pending_env.
Referenced by GNUNET_CADET_channel_create(), and handle_channel_created().
|
static |
Process the new channel notification and add it to the channels in the handle.
| cls | The cadet handle |
| msg | A message with the details of the new incoming channel |
Definition at line 467 of file cadet_api.c.
References cadet_mq_cancel_impl(), cadet_mq_destroy_impl(), cadet_mq_error_handler(), cadet_mq_send_impl(), GNUNET_CADET_LocalChannelDestroyMessage::ccn, ch, GNUNET_CADET_ClientChannelNumber::channel_of_client, create_channel(), GNUNET_CADET_Channel::ctx, GNUNET_CADET_Channel::disconnects, env, find_port(), GNUNET_assert, GNUNET_break, GNUNET_CADET_LOCAL_CHANNEL_ID_CLI, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY, GNUNET_MQ_msg, GNUNET_MQ_queue_for_callbacks(), GNUNET_MQ_send(), GNUNET_MQ_set_handlers_closure(), h, GNUNET_CADET_Channel::incoming_port, LOG, GNUNET_ARM_Handle::mq, GNUNET_CADET_Channel::mq, msg, GNUNET_CADET_Channel::peer, port, and GNUNET_CADET_Channel::window_changes.
|
static |
Process the channel destroy notification and free associated resources.
| cls | The cadet handle |
| msg | A message with the details of the channel being destroyed |
Definition at line 535 of file cadet_api.c.
References ch, destroy_channel(), find_channel(), GNUNET_ERROR_TYPE_DEBUG, h, LOG, and msg.
|
static |
Check that message received from CADET service is well-formed.
| cls | the struct GNUNET_CADET_Handle |
| message | the message we got |
Definition at line 566 of file cadet_api.c.
References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, GNUNET_CADET_LocalData::header, GNUNET_MessageHeader::size, and size.
|
static |
Process the incoming data packets, call appropriate handlers.
| cls | The cadet handle |
| message | A message encapsulating the data |
Definition at line 589 of file cadet_api.c.
References GNUNET_CADET_Channel::ccn, GNUNET_CADET_LocalData::ccn, ch, GNUNET_CADET_ClientChannelNumber::channel_of_client, find_channel(), GNUNET_CADET_LOCAL_CHANNEL_ID_CLI, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_MQ_inject_message(), h, LOG, GNUNET_CADET_Channel::mq, payload, GNUNET_CADET_Channel::peer, and type.
|
static |
Process a local ACK message, enabling the client to send more data to the service.
| cls | Cadet handle. |
| message | Message itself. |
Definition at line 628 of file cadet_api.c.
References GNUNET_CADET_Channel::allow_send, cadet_mq_send_now(), GNUNET_CADET_Channel::ccn, GNUNET_CADET_LocalAck::ccn, ch, GNUNET_CADET_ClientChannelNumber::channel_of_client, find_channel(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_SCHEDULER_add_now(), h, LOG, GNUNET_CADET_Channel::mq_cont, notify_window_size(), GNUNET_CADET_Channel::peer, and GNUNET_CADET_Channel::pending_env.
|
static |
Function called during GNUNET_CADET_disconnect() to destroy all channels that are still open.
| cls | the struct GNUNET_CADET_Handle |
| cid | chanenl ID |
| value | a struct GNUNET_CADET_Channel to destroy |
Definition at line 673 of file cadet_api.c.
References ch, destroy_channel(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_OK, and value.
Referenced by GNUNET_CADET_disconnect(), and handle_mq_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.
| cls | closure, a struct GNUNET_CORE_Handle * |
| error | error code |
Definition at line 696 of file cadet_api.c.
References destroy_channel_cb(), GNUNET_assert, GNUNET_CONTAINER_multihashmap32_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), h, GNUNET_ARM_Handle::mq, reconnect_cbk(), and GNUNET_ARM_Handle::reconnect_task.
Referenced by reconnect().
|
static |
Function called during GNUNET_CADET_disconnect() to destroy all ports that are still open.
| cls | the struct GNUNET_CADET_Handle |
| id | port ID |
| value | a struct GNUNET_CADET_Channel to destroy |
Definition at line 754 of file cadet_api.c.
References GNUNET_CADET_Port::cls, GNUNET_break, GNUNET_CADET_close_port(), GNUNET_OK, port, and value.
Referenced by GNUNET_CADET_disconnect().
|
static |
Function to return link to AGPL source upon request.
| cls | closure with the identification of the client |
| msg | AGPL request |
Definition at line 925 of file cadet_api.c.
References GNUNET_OS_ProjectData::agpl_url, env, GNUNET_MESSAGE_TYPE_RESPONSE_AGPL, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_OS_project_data_gnunet(), GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_get_mq(), mq, msg, and res.
Referenced by GNUNET_CADET_open_port().