core service; this is the main API for encrypted P2P communications More...
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_core_service.h"
#include "core.h"
Go to the source code of this file.
Data Structures | |
struct | PeerRecord |
Information we track for each peer. More... | |
struct | GNUNET_CORE_Handle |
Context for the core service connection. More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "core-api", __VA_ARGS__) |
Functions | |
static void | reconnect (struct GNUNET_CORE_Handle *h) |
Our current client connection went down. More... | |
static void | reconnect_task (void *cls) |
Task schedule to try to re-connect to core. More... | |
static int | disconnect_and_free_peer_entry (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
Notify clients about disconnect and free the entry for connected peer. More... | |
static void | reconnect_later (struct GNUNET_CORE_Handle *h) |
Close down any existing connection to the CORE service and try re-establishing it later. More... | |
static void | handle_mq_error (void *cls, enum GNUNET_MQ_Error error) |
Error handler for the message queue to the CORE service. More... | |
static void | core_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. More... | |
static void | core_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) |
Handle destruction of a message queue. More... | |
static void | core_mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) |
Implementation function that cancels the currently sent message. More... | |
static void | core_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 | connect_peer (struct GNUNET_CORE_Handle *h, const struct GNUNET_PeerIdentity *peer) |
Add the given peer to the list of our connected peers and create the respective data structures and notify the application. More... | |
static void | handle_init_reply (void *cls, const struct InitReplyMessage *m) |
Handle init reply message received from CORE service. More... | |
static void | handle_connect_notify (void *cls, const struct ConnectNotifyMessage *cnm) |
Handle connect message received from CORE service. More... | |
static void | handle_disconnect_notify (void *cls, const struct DisconnectNotifyMessage *dnm) |
Handle disconnect message received from CORE service. More... | |
static int | check_notify_inbound (void *cls, const struct NotifyTrafficMessage *ntm) |
Check that message received from CORE service is well-formed. More... | |
static void | handle_notify_inbound (void *cls, const struct NotifyTrafficMessage *ntm) |
Handle inbound message received from CORE service. More... | |
static void | handle_send_ready (void *cls, const struct SendMessageReady *smr) |
Handle message received from CORE service notifying us that we are now allowed to send a message to a peer. More... | |
struct GNUNET_CORE_Handle * | GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, GNUNET_CORE_StartupCallback init, GNUNET_CORE_ConnectEventHandler connects, GNUNET_CORE_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers) |
Connect to the core service. More... | |
void | GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle) |
Disconnect from the core service. More... | |
struct GNUNET_MQ_Handle * | GNUNET_CORE_get_mq (const struct GNUNET_CORE_Handle *h, const struct GNUNET_PeerIdentity *pid) |
Obtain the message queue for a connected peer. More... | |
core service; this is the main API for encrypted P2P communications
Definition in file core_api.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "core-api", __VA_ARGS__) |
Definition at line 32 of file core_api.c.
|
static |
Our current client connection went down.
Clean it up and try to reconnect!
h | our handle to the core service |
Definition at line 629 of file core_api.c.
References GNUNET_ARM_Handle::cfg, connect_notify(), disconnect_notify(), env, GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_INFO, GNUNET_MESSAGE_TYPE_CORE_INIT, GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY, GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT, GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT, GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND, GNUNET_MESSAGE_TYPE_CORE_SEND_READY, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), h, handle_mq_error(), handlers, init, LOG, GNUNET_ARM_Handle::mq, and reconnect_later().
Referenced by GNUNET_CORE_connect(), and reconnect_task().
|
static |
Task schedule to try to re-connect to core.
cls | the struct GNUNET_CORE_Handle |
Definition at line 163 of file core_api.c.
References GNUNET_CORE_Handle::cls, GNUNET_ERROR_TYPE_DEBUG, h, LOG, reconnect(), and GNUNET_ARM_Handle::reconnect_task.
Referenced by reconnect_later().
|
static |
Notify clients about disconnect and free the entry for connected peer.
cls | the struct GNUNET_CORE_Handle * |
key | the peer identity (not used) |
value | the struct PeerRecord to free. |
Definition at line 183 of file core_api.c.
References PeerRecord::client_cls, GNUNET_CORE_Handle::cls, PeerRecord::env, GNUNET_assert, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_free, GNUNET_MQ_destroy(), GNUNET_MQ_discard(), GNUNET_YES, h, PeerRecord::h, key, PeerRecord::mq, PeerRecord::peer, and value.
Referenced by GNUNET_CORE_disconnect(), handle_disconnect_notify(), and reconnect_later().
|
static |
Close down any existing connection to the CORE service and try re-establishing it later.
h | our handle |
Definition at line 214 of file core_api.c.
References disconnect_and_free_peer_entry(), GNUNET_assert, GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_STD_BACKOFF, h, GNUNET_ARM_Handle::mq, GNUNET_ARM_Handle::reconnect_task, reconnect_task(), and GNUNET_ARM_Handle::retry_backoff.
Referenced by handle_connect_notify(), handle_disconnect_notify(), handle_mq_error(), handle_notify_inbound(), handle_send_ready(), and reconnect().
|
static |
Error handler for the message queue to the CORE service.
On errors, we reconnect.
cls | closure, a struct GNUNET_CORE_Handle * |
error | error code |
Definition at line 240 of file core_api.c.
References GNUNET_CORE_Handle::cls, GNUNET_ERROR_TYPE_DEBUG, h, LOG, and reconnect_later().
Referenced by reconnect().
|
static |
Implement sending functionality of a message queue for us sending messages to a peer.
mq | the message queue |
msg | the message to send |
impl_state | state of the implementation |
Definition at line 258 of file core_api.c.
References env, PeerRecord::env, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_MAX_MESSAGE_SIZE, GNUNET_MESSAGE_TYPE_CORE_SEND, GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST, GNUNET_MQ_env_get_options(), GNUNET_MQ_get_current_envelope(), GNUNET_MQ_impl_send_continue(), GNUNET_MQ_msg, GNUNET_MQ_msg_nested_mh, GNUNET_MQ_send(), h, PeerRecord::h, LOG, mq, GNUNET_ARM_Handle::mq, msg, SendMessageRequest::peer, SendMessage::peer, PeerRecord::peer, SendMessageRequest::priority, SendMessage::priority, GNUNET_MessageHeader::size, SendMessageRequest::size, SendMessageRequest::smr_id, and PeerRecord::smr_id_gen.
Referenced by connect_peer().
|
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 320 of file core_api.c.
References GNUNET_assert, mq, and PeerRecord::mq.
Referenced by connect_peer().
|
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 337 of file core_api.c.
References PeerRecord::env, GNUNET_assert, GNUNET_MQ_discard(), and mq.
Referenced by connect_peer().
|
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 357 of file core_api.c.
References GNUNET_break_op.
Referenced by connect_peer().
|
static |
Add the given peer to the list of our connected peers and create the respective data structures and notify the application.
h | the core handle |
peer | the peer that is connecting to us |
Definition at line 375 of file core_api.c.
References PeerRecord::client_cls, core_mq_cancel_impl(), core_mq_destroy_impl(), core_mq_error_handler(), core_mq_send_impl(), GNUNET_assert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_put(), GNUNET_MQ_queue_for_callbacks(), GNUNET_MQ_set_handlers_closure(), GNUNET_new, GNUNET_YES, h, PeerRecord::h, PeerRecord::mq, and PeerRecord::peer.
Referenced by handle_connect_notify(), and handle_init_reply().
|
static |
Handle init reply message received from CORE service.
Notify application that we are now connected to the CORE. Also fake loopback connection.
cls | the struct GNUNET_CORE_Handle |
m | the init reply |
Definition at line 413 of file core_api.c.
References GNUNET_CORE_Handle::cls, connect_peer(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_NO, GNUNET_TIME_UNIT_MILLISECONDS, GNUNET_YES, h, init, LOG, m, and GNUNET_ARM_Handle::retry_backoff.
|
static |
Handle connect message received from CORE service.
Notify the application about the new connection.
cls | the struct GNUNET_CORE_Handle |
cnm | the connect message |
Definition at line 460 of file core_api.c.
References GNUNET_CORE_Handle::cls, connect_peer(), GNUNET_break, GNUNET_CONTAINER_multipeermap_get(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), h, LOG, ConnectNotifyMessage::peer, and reconnect_later().
|
static |
Handle disconnect message received from CORE service.
Notify the application about the lost connection.
cls | the struct GNUNET_CORE_Handle |
dnm | message about the disconnect event |
Definition at line 493 of file core_api.c.
References GNUNET_CORE_Handle::cls, disconnect_and_free_peer_entry(), GNUNET_break, GNUNET_CONTAINER_multipeermap_get(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), h, LOG, DisconnectNotifyMessage::peer, PeerRecord::peer, reconnect_later(), and DisconnectNotifyMessage::reserved.
|
static |
Check that message received from CORE service is well-formed.
cls | the struct GNUNET_CORE_Handle |
ntm | the message we got |
Definition at line 527 of file core_api.c.
References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, NotifyTrafficMessage::header, and GNUNET_MessageHeader::size.
|
static |
Handle inbound message received from CORE service.
If applicable, notify the application.
cls | the struct GNUNET_CORE_Handle |
ntm | the message we got from CORE. |
Definition at line 557 of file core_api.c.
References GNUNET_CORE_Handle::cls, GNUNET_break, GNUNET_CONTAINER_multipeermap_get(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_MQ_inject_message(), h, LOG, PeerRecord::mq, NotifyTrafficMessage::peer, and reconnect_later().
|
static |
Handle message received from CORE service notifying us that we are now allowed to send a message to a peer.
If that message is still pending, put it into the queue to be transmitted.
cls | the struct GNUNET_CORE_Handle |
smr | the message we got |
Definition at line 587 of file core_api.c.
References GNUNET_CORE_Handle::cls, PeerRecord::env, GNUNET_break, GNUNET_CONTAINER_multipeermap_get(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_MQ_impl_send_continue(), GNUNET_MQ_send(), h, LOG, GNUNET_ARM_Handle::mq, PeerRecord::mq, SendMessageReady::peer, reconnect_later(), SendMessageReady::smr_id, and PeerRecord::smr_id_gen.