32#define LOG(kind, ...) GNUNET_log_from (kind, "core-api", __VA_ARGS__)
191 if (NULL !=
h->disconnects)
292 "Asking core for transmission of %u bytes to `%s'\n",
293 (
unsigned int) msize,
296 smr->
priority = htonl ((uint32_t) flags);
298 smr->
size = htons (msize);
304 sm->
priority = htonl ((uint32_t) flags);
307 "Calling get_message with buffer of %u bytes\n",
308 (
unsigned int) msize);
396 if (NULL !=
h->connects)
420 if (NULL != (
init =
h->init))
424 h->me =
m->my_identity;
426 "Connected to core service of peer `%s'.\n",
434 "Successfully reconnected to core service.\n");
437 h->me =
m->my_identity;
466 "Received notification about connection from `%s'.\n",
506 "Received notification about disconnect from `%s'.\n",
540 if (msize != ntohs (em->
size))
564 "Received inbound message from `%s'.\n",
600 "Received notification about transmission readiness to `%s'.\n",
665 sizeof(uint16_t) *
h->hcnt,
668 init->options = htonl (0);
669 ts = (uint16_t *) &
init[1];
670 for (
unsigned int hpos = 0; hpos <
h->hcnt; hpos++)
671 ts[hpos] = htons (
h->handlers[hpos].type);
737 if (NULL !=
handle->reconnect_task)
740 handle->reconnect_task = NULL;
struct GNUNET_MQ_MessageHandlers handlers[]
struct GNUNET_MQ_Handle * mq
struct GNUNET_MessageHeader * msg
struct GNUNET_MQ_Envelope * env
void * connects(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
void disconnects(void *cls, const struct GNUNET_PeerIdentity *peer)
common internal definitions for core service
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.
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...
static void reconnect_later(struct GNUNET_CORE_Handle *h)
Close down any existing connection to the CORE service and try re-establishing it later.
static int check_notify_inbound(void *cls, const struct NotifyTrafficMessage *ntm)
Check that message received from CORE service is well-formed.
static void handle_connect_notify(void *cls, const struct ConnectNotifyMessage *cnm)
Handle connect message received from CORE service.
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.
static void handle_disconnect_notify(void *cls, const struct DisconnectNotifyMessage *dnm)
Handle disconnect message received from CORE service.
static void reconnect(struct GNUNET_CORE_Handle *h)
Our current client connection went down.
static void handle_notify_inbound(void *cls, const struct NotifyTrafficMessage *ntm)
Handle inbound message received from CORE service.
static void handle_init_reply(void *cls, const struct InitReplyMessage *m)
Handle init reply message received from CORE service.
static void core_mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
static void core_mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
Handle destruction of a message queue.
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 n...
static void handle_mq_error(void *cls, enum GNUNET_MQ_Error error)
Error handler for the message queue to the CORE service.
static void reconnect_task(void *cls)
Task schedule to try to re-connect to core.
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.
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static char * init
Set to the name of a service to start.
static void disconnect_notify(void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
Method called whenever a peer disconnects.
static void * connect_notify(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Method called whenever a peer connects.
struct GNUNET_HashCode key
The key used in the DHT.
static char * value
Value of the record to add/remove.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Core service; the main API for encrypted P2P communications.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
void(* GNUNET_CORE_DisconnectEventHandler)(void *cls, const struct GNUNET_PeerIdentity *peer, void *peer_cls)
Method called whenever a peer disconnects.
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.
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.
void(* GNUNET_CORE_StartupCallback)(void *cls, const struct GNUNET_PeerIdentity *my_identity)
Function called after GNUNET_CORE_connect has succeeded (or failed for good).
void GNUNET_CORE_disconnect(struct GNUNET_CORE_Handle *handle)
Disconnect from the core service.
void *(* GNUNET_CORE_ConnectEventHandler)(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Method called whenever a given peer connects.
void * GNUNET_CONTAINER_multipeermap_get(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Given a key find a value in the map matching the key.
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.
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).
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.
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.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
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.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_MQ_Error
Error codes for the queue.
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.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_msg_nested_mh(mvar, type, mh)
Allocate a GNUNET_MQ_Envelope, and append a payload message after the given message struct.
struct GNUNET_MQ_MessageHandler * GNUNET_MQ_copy_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
Copy an array of handlers.
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
void GNUNET_MQ_inject_message(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *mh)
Call the message message handler that was registered for the type of the given message in the given m...
GNUNET_MQ_PriorityPreferences
Per envelope preferences and priorities.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
enum GNUNET_MQ_PriorityPreferences GNUNET_MQ_env_get_options(struct GNUNET_MQ_Envelope *env)
Get performance preferences set for this envelope.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_MQ_set_handlers_closure(struct GNUNET_MQ_Handle *mq, void *handlers_cls)
Change the closure argument in all of the handlers of the mq.
unsigned int GNUNET_MQ_count_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
Count the handlers in a handler array.
struct GNUNET_MQ_Envelope * GNUNET_MQ_get_current_envelope(struct GNUNET_MQ_Handle *mq)
Function to obtain the current envelope from within GNUNET_MQ_SendImpl implementations.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
#define GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST
Request from client to transmit message.
#define GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT
Notify clients about new peer-to-peer connections (triggered after key exchange).
#define GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT
Notify clients about peer disconnecting.
#define GNUNET_MESSAGE_TYPE_CORE_INIT
Initial setup message from core client to core.
#define GNUNET_MESSAGE_TYPE_CORE_SEND
Client with message to transmit (after SEND_READY confirmation was received).
#define GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND
Notify clients about incoming P2P messages.
#define GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY
Response from core to core client to INIT message.
#define GNUNET_MESSAGE_TYPE_CORE_SEND_READY
Confirmation from core that message can now be sent.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
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.
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
Message sent by the service to clients to notify them about a peer connecting.
struct GNUNET_PeerIdentity peer
Identity of the connecting peer.
Message sent by the service to clients to notify them about a peer disconnecting.
uint32_t reserved
Always zero.
struct GNUNET_PeerIdentity peer
Identity of the connecting peer.
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
struct GNUNET_TIME_Relative retry_backoff
Current delay we use for re-trying to connect to core.
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
Internal representation of the hash map.
Context for the core service connection.
void * cls
Closure for the various callbacks.
struct GNUNET_CONTAINER_MultiPeerMap * peers
Hash map listing all of the peers that we are currently connected to.
GNUNET_CORE_DisconnectEventHandler disconnects
Function to call whenever we're notified about a peer disconnecting.
GNUNET_CORE_ConnectEventHandler connects
Function to call whenever we're notified about a peer connecting.
struct GNUNET_MQ_Handle * mq
Our message queue for transmissions to the service.
struct GNUNET_MQ_MessageHandler * handlers
Function handlers for messages of particular type.
int have_init
Did we ever get INIT?
struct GNUNET_TIME_Relative retry_backoff
Current delay we use for re-trying to connect to core.
GNUNET_CORE_StartupCallback init
Function to call once we've handshaked with the core service.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we're using.
unsigned int hcnt
Number of entries in the handlers array.
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of reconnect task (if any).
struct GNUNET_PeerIdentity me
Identity of this peer.
Handle to a message queue.
Message handler for a specific message type.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_MQ_Handle * mq
Connection to VPN service.
Message transmitted core clients to gnunet-service-core to start the interaction.
Message transmitted by the gnunet-service-core process to its clients in response to an INIT message.
Message sent by the service to clients to notify them about messages being received or transmitted.
struct GNUNET_MessageHeader header
Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND or GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND.
struct GNUNET_PeerIdentity peer
Identity of the receiver or sender.
Information we track for each peer.
uint16_t smr_id_gen
SendMessageRequest ID generator for this peer.
struct GNUNET_CORE_Handle * h
Corresponding CORE handle.
void * client_cls
Value the client returned when we connected, used as the closure in various places.
struct GNUNET_PeerIdentity peer
Peer the record is about.
struct GNUNET_MQ_Handle * mq
Message queue for the peer.
struct GNUNET_MQ_Envelope * env
Message we are currently trying to pass to the CORE service for this peer (from mq).
Core notifying client that it is allowed to now transmit a message to the given target (response to G...
uint16_t smr_id
smr_id from the request.
struct GNUNET_PeerIdentity peer
Identity of the intended target.
Client notifying core about the maximum-priority message it has in the queue for a particular target.
uint32_t priority
How important is this message?
struct GNUNET_PeerIdentity peer
Identity of the intended target.
uint16_t size
How large is the message?
uint16_t smr_id
Counter for this peer to match SMRs to replies.
Client asking core to transmit a particular message to a particular target (response to GNUNET_MESSAG...
uint32_t priority
How important is this message? Contains a enum GNUNET_MQ_PriorityPreferences in NBO.
struct GNUNET_PeerIdentity peer
Identity of the intended receiver.