GNUnet  0.10.x
core_api.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2009-2016 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_constants.h"
29 #include "gnunet_core_service.h"
30 #include "core.h"
31 
32 #define LOG(kind, ...) GNUNET_log_from(kind, "core-api", __VA_ARGS__)
33 
34 
38 struct PeerRecord {
43 
48 
54 
59  void *client_cls;
60 
65 
69  uint16_t smr_id_gen;
70 };
71 
72 
81 
85  void *cls;
86 
91 
96 
101 
106 
111 
117 
122 
127 
131  struct GNUNET_TIME_Relative retry_backoff;
132 
136  unsigned int hcnt;
137 
142 };
143 
144 
151 static void
153 
154 
161 static void
162 reconnect_task(void *cls)
163 {
164  struct GNUNET_CORE_Handle *h = cls;
165 
166  h->reconnect_task = NULL;
167  LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to CORE service after delay\n");
168  reconnect(h);
169 }
170 
171 
181 static int
183  const struct GNUNET_PeerIdentity *key,
184  void *value)
185 {
186  struct GNUNET_CORE_Handle *h = cls;
187  struct PeerRecord *pr = value;
188 
189  GNUNET_assert(pr->h == h);
190  if (NULL != h->disconnects)
191  h->disconnects(h->cls, &pr->peer, pr->client_cls);
194  GNUNET_MQ_destroy(pr->mq);
195  GNUNET_assert(NULL == pr->mq);
196  if (NULL != pr->env)
197  {
198  GNUNET_MQ_discard(pr->env);
199  pr->env = NULL;
200  }
201  GNUNET_free(pr);
202  return GNUNET_YES;
203 }
204 
205 
212 static void
214 {
215  GNUNET_assert(NULL == h->reconnect_task);
216  if (NULL != h->mq)
217  {
218  GNUNET_MQ_destroy(h->mq);
219  h->mq = NULL;
220  }
221  GNUNET_assert(NULL == h->reconnect_task);
222  h->reconnect_task =
226  h);
228 }
229 
230 
238 static void
239 handle_mq_error(void *cls, enum GNUNET_MQ_Error error)
240 {
241  struct GNUNET_CORE_Handle *h = cls;
242 
243  LOG(GNUNET_ERROR_TYPE_DEBUG, "MQ ERROR: %d\n", error);
244  reconnect_later(h);
245 }
246 
247 
256 static void
258  const struct GNUNET_MessageHeader *msg,
259  void *impl_state)
260 {
261  struct PeerRecord *pr = impl_state;
262  struct GNUNET_CORE_Handle *h = pr->h;
263  struct SendMessageRequest *smr;
264  struct SendMessage *sm;
265  struct GNUNET_MQ_Envelope *env;
266  uint16_t msize;
268 
269  if (NULL == h->mq)
270  {
271  /* We're currently reconnecting, pretend this worked */
273  return;
274  }
275  GNUNET_assert(NULL == pr->env);
276  /* extract options from envelope */
278  flags = GNUNET_MQ_env_get_options(env);
279 
280  /* check message size for sanity */
281  msize = ntohs(msg->size);
282  if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct SendMessage))
283  {
284  GNUNET_break(0);
286  return;
287  }
288 
289  /* ask core for transmission */
291  "Asking core for transmission of %u bytes to `%s'\n",
292  (unsigned int)msize,
293  GNUNET_i2s(&pr->peer));
295  smr->priority = htonl((uint32_t)flags);
296  smr->peer = pr->peer;
297  smr->size = htons(msize);
298  smr->smr_id = htons(++pr->smr_id_gen);
299  GNUNET_MQ_send(h->mq, env);
300 
301  /* prepare message with actual transmission data */
303  sm->priority = htonl((uint32_t)flags);
304  sm->peer = pr->peer;
306  "Calling get_message with buffer of %u bytes\n",
307  (unsigned int)msize);
308 }
309 
310 
318 static void
319 core_mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
320 {
321  struct PeerRecord *pr = impl_state;
322 
323  GNUNET_assert(mq == pr->mq);
324  pr->mq = NULL;
325 }
326 
327 
335 static void
336 core_mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
337 {
338  struct PeerRecord *pr = impl_state;
339 
340  (void)mq;
341  GNUNET_assert(NULL != pr->env);
342  GNUNET_MQ_discard(pr->env);
343  pr->env = NULL;
344 }
345 
346 
355 static void
357 {
358  /* struct PeerRecord *pr = cls; */
359  (void)cls;
360  (void)error;
361  GNUNET_break_op(0);
362 }
363 
364 
373 static void
375  const struct GNUNET_PeerIdentity *peer)
376 {
377  struct PeerRecord *pr;
378 
379  pr = GNUNET_new(struct PeerRecord);
380  pr->peer = *peer;
381  pr->h = h;
384  h->peers,
385  &pr->peer,
386  pr,
391  pr,
392  h->handlers,
394  pr);
395  if (NULL != h->connects)
396  {
397  pr->client_cls = h->connects(h->cls, &pr->peer, pr->mq);
399  }
400 }
401 
402 
411 static void
412 handle_init_reply(void *cls, const struct InitReplyMessage *m)
413 {
414  struct GNUNET_CORE_Handle *h = cls;
416 
417  GNUNET_break(0 == ntohl(m->reserved));
419  if (NULL != (init = h->init))
420  {
421  /* mark so we don't call init on reconnect */
422  h->init = NULL;
423  h->me = m->my_identity;
425  "Connected to core service of peer `%s'.\n",
426  GNUNET_i2s(&h->me));
427  h->have_init = GNUNET_YES;
428  init(h->cls, &h->me);
429  }
430  else
431  {
433  "Successfully reconnected to core service.\n");
434  if (GNUNET_NO == h->have_init)
435  {
436  h->me = m->my_identity;
437  h->have_init = GNUNET_YES;
438  }
439  else
440  {
441  GNUNET_break(0 == memcmp(&h->me,
442  &m->my_identity,
443  sizeof(struct GNUNET_PeerIdentity)));
444  }
445  }
446  /* fake 'connect to self' */
447  connect_peer(h, &h->me);
448 }
449 
450 
458 static void
460 {
461  struct GNUNET_CORE_Handle *h = cls;
462  struct PeerRecord *pr;
463 
465  "Received notification about connection from `%s'.\n",
466  GNUNET_i2s(&cnm->peer));
467  if (0 == memcmp(&h->me, &cnm->peer, sizeof(struct GNUNET_PeerIdentity)))
468  {
469  /* connect to self!? */
470  GNUNET_break(0);
471  return;
472  }
474  if (NULL != pr)
475  {
476  GNUNET_break(0);
477  reconnect_later(h);
478  return;
479  }
480  connect_peer(h, &cnm->peer);
481 }
482 
483 
491 static void
493 {
494  struct GNUNET_CORE_Handle *h = cls;
495  struct PeerRecord *pr;
496 
497  if (0 == memcmp(&h->me, &dnm->peer, sizeof(struct GNUNET_PeerIdentity)))
498  {
499  /* disconnect from self!? */
500  GNUNET_break(0);
501  return;
502  }
503  GNUNET_break(0 == ntohl(dnm->reserved));
505  "Received notification about disconnect from `%s'.\n",
506  GNUNET_i2s(&dnm->peer));
508  if (NULL == pr)
509  {
510  GNUNET_break(0);
511  reconnect_later(h);
512  return;
513  }
515 }
516 
517 
525 static int
526 check_notify_inbound(void *cls, const struct NotifyTrafficMessage *ntm)
527 {
528  uint16_t msize;
529  const struct GNUNET_MessageHeader *em;
530 
531  (void)cls;
532  msize = ntohs(ntm->header.size) - sizeof(struct NotifyTrafficMessage);
533  if (msize < sizeof(struct GNUNET_MessageHeader))
534  {
535  GNUNET_break(0);
536  return GNUNET_SYSERR;
537  }
538  em = (const struct GNUNET_MessageHeader *)&ntm[1];
539  if (msize != ntohs(em->size))
540  {
541  GNUNET_break(0);
542  return GNUNET_SYSERR;
543  }
544  return GNUNET_OK;
545 }
546 
547 
555 static void
556 handle_notify_inbound(void *cls, const struct NotifyTrafficMessage *ntm)
557 {
558  struct GNUNET_CORE_Handle *h = cls;
559  const struct GNUNET_MessageHeader *em;
560  struct PeerRecord *pr;
561 
563  "Received inbound message from `%s'.\n",
564  GNUNET_i2s(&ntm->peer));
565  em = (const struct GNUNET_MessageHeader *)&ntm[1];
567  if (NULL == pr)
568  {
569  GNUNET_break(0);
570  reconnect_later(h);
571  return;
572  }
573  GNUNET_MQ_inject_message(pr->mq, em);
574 }
575 
576 
585 static void
586 handle_send_ready(void *cls, const struct SendMessageReady *smr)
587 {
588  struct GNUNET_CORE_Handle *h = cls;
589  struct PeerRecord *pr;
590 
592  if (NULL == pr)
593  {
594  GNUNET_break(0);
595  reconnect_later(h);
596  return;
597  }
599  "Received notification about transmission readiness to `%s'.\n",
600  GNUNET_i2s(&smr->peer));
601  if (NULL == pr->env)
602  {
603  /* request must have been cancelled between the original request
604  * and the response from CORE, ignore CORE's readiness */
605  return;
606  }
607  if (ntohs(smr->smr_id) != pr->smr_id_gen)
608  {
609  /* READY message is for expired or cancelled message,
610  * ignore! (we should have already sent another request) */
611  return;
612  }
613 
614  /* ok, all good, send message out! */
615  GNUNET_MQ_send(h->mq, pr->env);
616  pr->env = NULL;
618 }
619 
620 
627 static void
629 {
630  struct GNUNET_MQ_MessageHandler handlers[] =
631  { GNUNET_MQ_hd_fixed_size(init_reply,
633  struct InitReplyMessage,
634  h),
637  struct ConnectNotifyMessage,
638  h),
642  h),
643  GNUNET_MQ_hd_var_size(notify_inbound,
645  struct NotifyTrafficMessage,
646  h),
647  GNUNET_MQ_hd_fixed_size(send_ready,
649  struct SendMessageReady,
650  h),
652  struct InitMessage *init;
653  struct GNUNET_MQ_Envelope *env;
654  uint16_t *ts;
655 
656  GNUNET_assert(NULL == h->mq);
657  h->mq = GNUNET_CLIENT_connect(h->cfg, "core", handlers, &handle_mq_error, h);
658  if (NULL == h->mq)
659  {
660  reconnect_later(h);
661  return;
662  }
663  env = GNUNET_MQ_msg_extra(init,
664  sizeof(uint16_t) * h->hcnt,
666  LOG(GNUNET_ERROR_TYPE_INFO, "(Re)connecting to CORE service\n");
667  init->options = htonl(0);
668  ts = (uint16_t *)&init[1];
669  for (unsigned int hpos = 0; hpos < h->hcnt; hpos++)
670  ts[hpos] = htons(h->handlers[hpos].type);
671  GNUNET_MQ_send(h->mq, env);
672 }
673 
674 
689 struct GNUNET_CORE_Handle *
691  void *cls,
695  const struct GNUNET_MQ_MessageHandler *handlers)
696 {
697  struct GNUNET_CORE_Handle *h;
698 
699  h = GNUNET_new(struct GNUNET_CORE_Handle);
700  h->cfg = cfg;
701  h->cls = cls;
702  h->init = init;
703  h->connects = connects;
706  h->handlers = GNUNET_MQ_copy_handlers(handlers);
707  h->hcnt = GNUNET_MQ_count_handlers(handlers);
708  GNUNET_assert(h->hcnt <
709  (GNUNET_MAX_MESSAGE_SIZE - sizeof(struct InitMessage)) /
710  sizeof(uint16_t));
711  LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to CORE service\n");
712  reconnect(h);
713  if (NULL == h->mq)
714  {
716  return NULL;
717  }
718  return h;
719 }
720 
721 
727 void
729 {
730  LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from CORE service\n");
733  handle);
735  handle->peers = NULL;
736  if (NULL != handle->reconnect_task)
737  {
739  handle->reconnect_task = NULL;
740  }
741  if (NULL != handle->mq)
742  {
743  GNUNET_MQ_destroy(handle->mq);
744  handle->mq = NULL;
745  }
747  GNUNET_free(handle);
748 }
749 
750 
758 struct GNUNET_MQ_Handle *
760  const struct GNUNET_PeerIdentity *pid)
761 {
762  struct PeerRecord *pr;
763 
765  if (NULL == pr)
766  return NULL;
767  return pr->mq;
768 }
769 
770 
771 /* end of core_api.c */
struct GNUNET_MQ_Envelope * env
Message we are currently trying to pass to the CORE service for this peer (from mq).
Definition: core_api.c:53
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_MESSAGE_TYPE_CORE_SEND
Client with message to transmit (after SEND_READY confirmation was received).
Context for the core service connection.
Definition: core_api.c:76
Information we track for each peer.
Definition: core_api.c:38
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.
Definition: client.c:900
#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_PeerIdentity me
Identity of this peer.
Definition: core_api.c:121
uint32_t priority
How important is this message?
Definition: core.h:200
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...
Definition: core_api.c:374
GNUNET_MQ_Error
Error codes for the queue.
GNUNET_CORE_StartupCallback init
Function to call once we&#39;ve handshaked with the core service.
Definition: core_api.c:90
GNUNET_CORE_ConnectEventHandler connects
Function to call whenever we&#39;re notified about a peer connecting.
Definition: core_api.c:95
#define LOG(kind,...)
Definition: core_api.c:32
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void(* GNUNET_CORE_DisconnectEventHandler)(void *cls, const struct GNUNET_PeerIdentity *peer, void *peer_cls)
Method called whenever a peer disconnects.
struct GNUNET_MQ_MessageHandler * GNUNET_MQ_copy_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
Copy an array of handlers.
Definition: mq.c:1211
static void handle_disconnect_notify(void *cls, const struct DisconnectNotifyMessage *dnm)
Handle disconnect message received from CORE service.
Definition: core_api.c:492
static int check_notify_inbound(void *cls, const struct NotifyTrafficMessage *ntm)
Check that message received from CORE service is well-formed.
Definition: core_api.c:526
Message sent by the service to clients to notify them about a peer connecting.
Definition: core.h:122
struct GNUNET_MQ_Handle * mq
Message queue for the peer.
Definition: core_api.c:47
common internal definitions for core service
void * cls
Closure for the various callbacks.
Definition: core_api.c:85
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we&#39;re using.
Definition: core_api.c:80
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
int 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.
void(* GNUNET_CORE_StartupCallback)(void *cls, const struct GNUNET_PeerIdentity *my_identity)
Function called after GNUNET_CORE_connect has succeeded (or failed for good).
#define GNUNET_NO
Definition: gnunet_common.h:78
struct GNUNET_PeerIdentity peer
Peer the record is about.
Definition: core_api.c:64
#define GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND
Notify clients about incoming P2P messages.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
GNUNET_MQ_PriorityPreferences
Per envelope preferences and priorities.
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT
Notify clients about peer disconnecting.
uint32_t options
Options, see GNUNET_CORE_OPTION_ values.
Definition: core.h:92
struct GNUNET_PeerIdentity my_identity
Public key of the local peer.
Definition: core.h:114
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
static void core_mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
Definition: core_api.c:336
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).
struct GNUNET_PeerIdentity peer
Identity of the intended target.
Definition: core.h:211
Message transmitted core clients to gnunet-service-core to start the interaction. ...
Definition: core.h:83
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of reconnect task (if any).
Definition: core_api.c:126
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
int have_init
Did we ever get INIT?
Definition: core_api.c:141
struct GNUNET_CORE_Handle * h
Corresponding CORE handle.
Definition: core_api.c:42
void *(* GNUNET_CORE_ConnectEventHandler)(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Method called whenever a given peer connects.
Message transmitted by the gnunet-service-core process to its clients in response to an INIT message...
Definition: core.h:100
enum GNUNET_MQ_PriorityPreferences GNUNET_MQ_env_get_options(struct GNUNET_MQ_Envelope *env)
Get performance preferences set for this envelope.
Definition: mq.c:1017
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.
Definition: mq.c:581
#define GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST
Request from client to transmit message.
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:99
static void handle_init_reply(void *cls, const struct InitReplyMessage *m)
Handle init reply message received from CORE service.
Definition: core_api.c:412
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
#define GNUNET_MESSAGE_TYPE_CORE_INIT
Initial setup message from core client to core.
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.
Definition: scheduler.c:1237
uint16_t type
Type of the message this handler covers, in host byte order.
Core notifying client that it is allowed to now transmit a message to the given target (response to G...
Definition: core.h:235
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.
Definition: mq.c:550
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.
Definition: core_api.c:182
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
void * client_cls
Value the client returned when we connected, used as the closure in various places.
Definition: core_api.c:59
static char * value
Value of the record to add/remove.
struct GNUNET_TIME_Relative retry_backoff
Current delay we use for re-trying to connect to core.
Definition: core_api.c:131
uint16_t size
How large is the message?
Definition: core.h:221
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
uint16_t smr_id
Counter for this peer to match SMRs to replies.
Definition: core.h:226
static void reconnect_task(void *cls)
Task schedule to try to re-connect to core.
Definition: core_api.c:162
static void core_mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
Handle destruction of a message queue.
Definition: core_api.c:319
Client asking core to transmit a particular message to a particular target (response to GNUNET_MESSAG...
Definition: core.h:265
struct GNUNET_PeerIdentity peer
Identity of the intended receiver.
Definition: core.h:286
static void reconnect_later(struct GNUNET_CORE_Handle *h)
Close down any existing connection to the CORE service and try re-establishing it later...
Definition: core_api.c:213
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
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...
Definition: mq.c:200
Client notifying core about the maximum-priority message it has in the queue for a particular target...
Definition: core.h:191
struct GNUNET_MQ_Handle * mq
Our message queue for transmissions to the service.
Definition: core_api.c:110
struct GNUNET_PeerIdentity peer
Identity of the connecting peer.
Definition: core.h:136
Internal representation of the hash map.
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
Message handler for a specific message type.
void * connects(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Definition: 010.c:2
unsigned int GNUNET_MQ_count_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
Count the handlers in a handler array.
Definition: mq.c:1271
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:319
struct GNUNET_MessageHeader header
Header with type GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND or GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND...
Definition: core.h:176
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
void disconnects(void *cls, const struct GNUNET_PeerIdentity *peer)
Definition: 011.c:2
There must only be one value per key; storing a value should fail if a value under the same key alrea...
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_MESSAGE_TYPE_CORE_SEND_READY
Confirmation from core that message can now be sent.
static void handle_notify_inbound(void *cls, const struct NotifyTrafficMessage *ntm)
Handle inbound message received from CORE service.
Definition: core_api.c:556
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.
Definition: core_api.c:690
void GNUNET_CORE_disconnect(struct GNUNET_CORE_Handle *handle)
Disconnect from the core service.
Definition: core_api.c:728
struct GNUNET_MQ_MessageHandler * handlers
Function handlers for messages of particular type.
Definition: core_api.c:105
#define GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT
Notify clients about new peer-to-peer connections (triggered after key exchange). ...
static char * init
Set to the name of a service to start.
Definition: gnunet-arm.c:69
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
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.
Definition: core_api.c:257
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
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.
Definition: core_api.c:759
struct GNUNET_CONTAINER_MultiPeerMap * peers
Hash map listing all of the peers that we are currently connected to.
Definition: core_api.c:116
uint16_t smr_id
smr_id from the request.
Definition: core.h:252
Handle to a message queue.
Definition: mq.c:84
static void handle_connect_notify(void *cls, const struct ConnectNotifyMessage *cnm)
Handle connect message received from CORE service.
Definition: core_api.c:459
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.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
The identity of the host (wraps the signing key of the peer).
static void handle_mq_error(void *cls, enum GNUNET_MQ_Error error)
Error handler for the message queue to the CORE service.
Definition: core_api.c:239
uint32_t reserved
Always zero.
Definition: core.h:153
configuration data
Definition: configuration.c:83
uint32_t priority
How important is this message? Contains a enum GNUNET_MQ_PriorityPreferences in NBO.
Definition: core.h:275
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.
static void * connect_notify(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Method called whenever a peer connects.
Entry in list of pending tasks.
Definition: scheduler.c:131
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...
Definition: core_api.c:586
static void reconnect(struct GNUNET_CORE_Handle *h)
Our current client connection went down.
Definition: core_api.c:628
Message sent by the service to clients to notify them about a peer disconnecting. ...
Definition: core.h:144
Message sent by the service to clients to notify them about messages being received or transmitted...
Definition: core.h:171
struct GNUNET_PeerIdentity peer
Identity of the connecting peer.
Definition: core.h:158
Header for all communications.
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.
Definition: mq.c:971
unsigned int hcnt
Number of entries in the handlers array.
Definition: core_api.c:136
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:821
#define GNUNET_YES
Definition: gnunet_common.h:77
uint32_t reserved
Always zero.
Definition: core.h:109
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:351
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
uint16_t smr_id_gen
SendMessageRequest ID generator for this peer.
Definition: core_api.c:69
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition: mq.c:484
struct GNUNET_PeerIdentity peer
Identity of the intended target.
Definition: core.h:257
#define GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY
Response from core to core client to INIT message.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
struct GNUNET_PeerIdentity peer
Identity of the receiver or sender.
Definition: core.h:181
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.
Definition: core_api.c:356
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
static void disconnect_notify(void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
Method called whenever a peer disconnects.
GNUNET_CORE_DisconnectEventHandler disconnects
Function to call whenever we&#39;re notified about a peer disconnecting.
Definition: core_api.c:100
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956