GNUnet  0.10.x
cadet_api.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2011, 2017 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_cadet_service.h"
30 #include "cadet.h"
31 #include "cadet_protocol.h"
32 
33 #define LOG(kind, ...) GNUNET_log_from(kind, "cadet-api", __VA_ARGS__)
34 
43 
48 
53 
58 
63 
68 
73 };
74 
75 
84 
89 
94 
99  void *ctx;
100 
105 
110 
117 
122 
127 
132 
136  unsigned int allow_send;
137 };
138 
139 
148 
153 
157  void *cls;
158 
163 
168 
173 
178 
183 };
184 
185 
193 static struct GNUNET_CADET_Port *
195  const struct GNUNET_HashCode *hash)
196 {
197  return GNUNET_CONTAINER_multihashmap_get(h->ports, hash);
198 }
199 
200 
208 static struct GNUNET_CADET_Channel *
211 {
213  ntohl(ccn.channel_of_client));
214 }
215 
216 
224 static struct GNUNET_CADET_Channel *
226  const struct GNUNET_CADET_ClientChannelNumber *ccnp)
227 {
228  struct GNUNET_CADET_Channel *ch;
230 
231  ch = GNUNET_new(struct GNUNET_CADET_Channel);
232  ch->cadet = h;
233  if (NULL == ccnp)
234  {
235  while (NULL != find_channel(h, h->next_ccn))
238  (1 + ntohl(h->next_ccn.channel_of_client)));
239  ccn = h->next_ccn;
240  }
241  else
242  {
243  ccn = *ccnp;
244  }
245  ch->ccn = ccn;
248  h->channels,
249  ntohl(ch->ccn.channel_of_client),
250  ch,
252  return ch;
253 }
254 
255 
266 static void
268 {
269  struct GNUNET_CADET_Handle *h = ch->cadet;
270 
272  "Destroying channel %X of %p\n",
273  htonl(ch->ccn.channel_of_client),
274  h);
276  GNUNET_YES ==
278  ntohl(ch->ccn.channel_of_client),
279  ch));
280  if (NULL != ch->mq_cont)
281  {
283  ch->mq_cont = NULL;
284  }
285  /* signal channel destruction */
286  if (NULL != ch->disconnects)
287  ch->disconnects(ch->ctx, ch);
288  if (NULL != ch->pending_env)
290  GNUNET_MQ_destroy(ch->mq);
291  GNUNET_free(ch);
292 }
293 
294 
301 static void
303 
304 
314 static int
315 open_port_cb(void *cls, const struct GNUNET_HashCode *id, void *value)
316 {
317  struct GNUNET_CADET_Handle *h = cls;
318  struct GNUNET_CADET_Port *port = value;
320  struct GNUNET_MQ_Envelope *env;
321 
322  (void)id;
324  msg->port = port->id;
325  GNUNET_MQ_send(h->mq, env);
326  return GNUNET_OK;
327 }
328 
329 
336 static void
337 reconnect_cbk(void *cls)
338 {
339  struct GNUNET_CADET_Handle *h = cls;
340 
341  h->reconnect_task = NULL;
343  reconnect(h);
345 }
346 
347 
353 static void
355 {
356  if (NULL != ch->window_changes)
357  ch->window_changes(ch->ctx,
358  ch, /* FIXME: remove 'ch'? */
359  ch->allow_send);
360 }
361 
362 
368 static void
370 {
371  struct GNUNET_CADET_Channel *ch = cls;
372  struct GNUNET_MQ_Envelope *env = ch->pending_env;
373 
374  ch->mq_cont = NULL;
375  if (0 == ch->allow_send)
376  {
377  /* how did we get here? */
378  GNUNET_break(0);
379  return;
380  }
381  if (NULL == env)
382  {
383  /* how did we get here? */
384  GNUNET_break(0);
385  return;
386  }
387  ch->allow_send--;
388  ch->pending_env = NULL;
390  "Sending message on channel %s to CADET, new window size is %u\n",
391  GNUNET_i2s(&ch->peer),
392  ch->allow_send);
393  GNUNET_MQ_send(ch->cadet->mq, env);
395 }
396 
397 
410 static void
412  const struct GNUNET_MessageHeader *msg,
413  void *impl_state)
414 {
415  struct GNUNET_CADET_Channel *ch = impl_state;
416  struct GNUNET_CADET_Handle *h = ch->cadet;
417  uint16_t msize;
418  struct GNUNET_MQ_Envelope *orig_env;
419  struct GNUNET_MQ_Envelope *env;
420  struct GNUNET_CADET_LocalData *cadet_msg;
422 
423  if (NULL == h->mq)
424  {
425  /* We're currently reconnecting, pretend this worked */
427  return;
428  }
429  orig_env = GNUNET_MQ_get_current_envelope(mq);
430  pp = GNUNET_MQ_env_get_options(orig_env);
431 
432  /* check message size for sanity */
433  msize = ntohs(msg->size);
435  {
436  GNUNET_break(0);
438  return;
439  }
440  env = GNUNET_MQ_msg_nested_mh(cadet_msg,
442  msg);
443  cadet_msg->ccn = ch->ccn;
444  cadet_msg->pp = htonl((uint32_t)pp);
445  GNUNET_assert(NULL == ch->pending_env);
446  ch->pending_env = env;
447  if (0 < ch->allow_send)
449 }
450 
451 
459 static void
460 cadet_mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
461 {
462  struct GNUNET_CADET_Channel *ch = impl_state;
463 
464  GNUNET_assert(mq == ch->mq);
465  ch->mq = NULL;
466 }
467 
468 
477 static void
479 {
480  struct GNUNET_CADET_Channel *ch = cls;
481 
482  if (GNUNET_MQ_ERROR_NO_MATCH == error)
483  {
484  /* Got a message we did not understand, still try to continue! */
485  GNUNET_break_op(0);
487  }
488  else
489  {
491  "MQ error in communication with CADET: %d\n",
492  error);
493  if (NULL != ch->disconnects)
494  ch->disconnects(ch->ctx, ch);
496  }
497 }
498 
499 
507 static void
508 cadet_mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
509 {
510  struct GNUNET_CADET_Channel *ch = impl_state;
511 
512  (void)mq;
513  GNUNET_assert(NULL != ch->pending_env);
515  ch->pending_env = NULL;
516  if (NULL != ch->mq_cont)
517  {
519  ch->mq_cont = NULL;
520  }
521 }
522 
523 
530 static void
532  void *cls,
534 {
535  struct GNUNET_CADET_Handle *h = cls;
536  struct GNUNET_CADET_Channel *ch;
537  struct GNUNET_CADET_Port *port;
538  const struct GNUNET_HashCode *port_number;
540 
541  ccn = msg->ccn;
542  port_number = &msg->port;
543  if (ntohl(ccn.channel_of_client) >= GNUNET_CADET_LOCAL_CHANNEL_ID_CLI)
544  {
545  GNUNET_break(0);
546  return;
547  }
548  port = find_port(h, port_number);
549  if (NULL == port)
550  {
551  /* We could have closed the port but the service didn't know about it yet
552  * This is not an error.
553  */
555  struct GNUNET_MQ_Envelope *env;
556 
558  "No handler for incoming channel %X (on port %s, recently closed?)\n",
559  ntohl(ccn.channel_of_client),
560  GNUNET_h2s(port_number));
561  env =
563  d_msg->ccn = msg->ccn;
564  GNUNET_MQ_send(h->mq, env);
565  return;
566  }
567 
568  ch = create_channel(h, &ccn);
569  ch->peer = msg->peer;
570  ch->incoming_port = port;
572  "Creating incoming channel %X [%s] %p\n",
573  ntohl(ccn.channel_of_client),
574  GNUNET_h2s(port_number),
575  ch);
576 
577  GNUNET_assert(NULL != port->connects);
578  ch->window_changes = port->window_changes;
579  ch->disconnects = port->disconnects;
583  ch,
584  port->handlers,
586  ch);
587  ch->ctx = port->connects(port->cls, ch, &msg->peer);
589 }
590 
591 
598 static void
600  void *cls,
602 {
603  struct GNUNET_CADET_Handle *h = cls;
604  struct GNUNET_CADET_Channel *ch;
605 
606  ch = find_channel(h, msg->ccn);
607  if (NULL == ch)
608  {
610  "Received channel destroy for unknown channel %X from CADET service (recently close?)\n",
611  ntohl(msg->ccn.channel_of_client));
612  return;
613  }
615  "Received channel destroy for channel %X from CADET service\n",
616  ntohl(msg->ccn.channel_of_client));
617  destroy_channel(ch);
618 }
619 
620 
629 static int
630 check_local_data(void *cls, const struct GNUNET_CADET_LocalData *message)
631 {
632  uint16_t size;
633 
634  (void)cls;
635  size = ntohs(message->header.size);
636  if (sizeof(*message) + sizeof(struct GNUNET_MessageHeader) > size)
637  {
638  GNUNET_break(0);
639  return GNUNET_SYSERR;
640  }
641  return GNUNET_OK;
642 }
643 
644 
651 static void
652 handle_local_data(void *cls, const struct GNUNET_CADET_LocalData *message)
653 {
654  struct GNUNET_CADET_Handle *h = cls;
655  const struct GNUNET_MessageHeader *payload;
656  struct GNUNET_CADET_Channel *ch;
657  uint16_t type;
658  int fwd;
659 
660  ch = find_channel(h, message->ccn);
661  if (NULL == ch)
662  {
664  "Unknown channel %X for incoming data (recently closed?)\n",
665  ntohl(message->ccn.channel_of_client));
666  return;
667  }
668 
669  payload = (const struct GNUNET_MessageHeader *)&message[1];
670  type = ntohs(payload->type);
673  "Got a %s data on channel %s [%X] of type %u\n",
674  fwd ? "FWD" : "BWD",
675  GNUNET_i2s(&ch->peer),
676  ntohl(message->ccn.channel_of_client),
677  type);
678  GNUNET_MQ_inject_message(ch->mq, payload);
679 }
680 
681 
689 static void
690 handle_local_ack(void *cls, const struct GNUNET_CADET_LocalAck *message)
691 {
692  struct GNUNET_CADET_Handle *h = cls;
693  struct GNUNET_CADET_Channel *ch;
694 
695  ch = find_channel(h, message->ccn);
696  if (NULL == ch)
697  {
699  "ACK on unknown channel %X\n",
700  ntohl(message->ccn.channel_of_client));
701  return;
702  }
703  ch->allow_send++;
705  "Got an ACK on mq channel %X (peer %s); new window size is %u!\n",
706  ntohl(ch->ccn.channel_of_client),
707  GNUNET_i2s(&ch->peer),
708  ch->allow_send);
709  if (NULL == ch->pending_env)
710  {
712  "Got an ACK on mq channel %X, allow send now %u!\n",
713  ntohl(ch->ccn.channel_of_client),
714  ch->allow_send);
715  notify_window_size(ch);
716  return;
717  }
718  if (NULL != ch->mq_cont)
719  return; /* already working on it! */
721 }
722 
723 
733 static int
734 destroy_channel_cb(void *cls, uint32_t cid, void *value)
735 {
736  /* struct GNUNET_CADET_Handle *handle = cls; */
737  struct GNUNET_CADET_Channel *ch = value;
738 
739  (void)cls;
740  (void)cid;
742  "Destroying channel due to GNUNET_CADET_disconnect()\n");
743  destroy_channel(ch);
744  return GNUNET_OK;
745 }
746 
747 
756 static void
757 handle_mq_error(void *cls, enum GNUNET_MQ_Error error)
758 {
759  struct GNUNET_CADET_Handle *h = cls;
760 
761  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MQ ERROR: %u\n", error);
763  GNUNET_MQ_destroy(h->mq);
764  h->mq = NULL;
765  GNUNET_assert(NULL == h->reconnect_task);
766  h->reconnect_task =
768 }
769 
770 
777 static void
779 {
780  struct GNUNET_MQ_MessageHandler handlers[] =
781  { GNUNET_MQ_hd_fixed_size(channel_created,
784  h),
788  h),
789  GNUNET_MQ_hd_var_size(local_data,
791  struct GNUNET_CADET_LocalData,
792  h),
793  GNUNET_MQ_hd_fixed_size(local_ack,
795  struct GNUNET_CADET_LocalAck,
796  h),
798 
799  GNUNET_assert(NULL == h->mq);
800  h->mq =
801  GNUNET_CLIENT_connect(h->cfg, "cadet", handlers, &handle_mq_error, h);
802 }
803 
804 
814 static int
815 destroy_port_cb(void *cls, const struct GNUNET_HashCode *id, void *value)
816 {
817  /* struct GNUNET_CADET_Handle *handle = cls; */
818  struct GNUNET_CADET_Port *port = value;
819 
820  (void)cls;
821  (void)id;
822  /* This is a warning, the app should have cleanly closed all open ports */
823  GNUNET_break(0);
825  return GNUNET_OK;
826 }
827 
828 
837 void
839 {
842  handle);
844  handle->ports = NULL;
847  handle);
849  handle->channels = NULL;
850  if (NULL != handle->mq)
851  {
852  GNUNET_MQ_destroy(handle->mq);
853  handle->mq = NULL;
854  }
855  if (NULL != handle->reconnect_task)
856  {
858  handle->reconnect_task = NULL;
859  }
860  GNUNET_free(handle);
861 }
862 
863 
870 void
872 {
874  GNUNET_YES ==
876  if (NULL != p->cadet->mq)
877  {
879  struct GNUNET_MQ_Envelope *env;
880 
882  msg->port = p->id;
883  GNUNET_MQ_send(p->cadet->mq, env);
884  }
886  GNUNET_free(p);
887 }
888 
889 
899 void
901 {
902  struct GNUNET_CADET_Handle *h = channel->cadet;
904  struct GNUNET_MQ_Envelope *env;
905 
906  if (NULL != h->mq)
907  {
909  msg->ccn = channel->ccn;
910  GNUNET_MQ_send(h->mq, env);
911  }
913  "Destroying channel due to GNUNET_CADET_channel_destroy()\n");
914  channel->disconnects = NULL;
915  destroy_channel(channel);
916 }
917 
918 
928 const union GNUNET_CADET_ChannelInfo *
931  ...)
932 {
933  switch (option)
934  {
936  return (const union GNUNET_CADET_ChannelInfo *)&channel->peer;
937 
938  default:
939  GNUNET_break(0);
940  return NULL;
941  }
942 }
943 
944 
950 void
952 {
953  struct GNUNET_CADET_LocalAck *msg;
954  struct GNUNET_MQ_Envelope *env;
955 
958  "Sending ACK on channel %X\n",
959  ntohl(channel->ccn.channel_of_client));
960  msg->ccn = channel->ccn;
961  GNUNET_MQ_send(channel->cadet->mq, env);
962 }
963 
964 
972 struct GNUNET_CADET_Handle *
974 {
975  struct GNUNET_CADET_Handle *h;
976 
977  LOG(GNUNET_ERROR_TYPE_DEBUG, "GNUNET_CADET_connect()\n");
978  h = GNUNET_new(struct GNUNET_CADET_Handle);
979  h->cfg = cfg;
982  reconnect(h);
983  if (NULL == h->mq)
984  {
985  GNUNET_break(0);
987  return NULL;
988  }
990  return h;
991 }
992 
993 
1006 struct GNUNET_CADET_Port *
1008  const struct GNUNET_HashCode *port,
1010  void *connects_cls,
1013  const struct GNUNET_MQ_MessageHandler *handlers)
1014 {
1015  struct GNUNET_CADET_Port *p;
1016 
1017  GNUNET_assert(NULL != connects);
1018  GNUNET_assert(NULL != disconnects);
1020  "Listening to CADET port %s\n",
1021  GNUNET_h2s(port));
1022 
1023  p = GNUNET_new(struct GNUNET_CADET_Port);
1024  p->cadet = h;
1025  p->id = *port;
1027  h->ports,
1028  &p->id,
1029  p,
1031  {
1032  GNUNET_free(p);
1033  return NULL;
1034  }
1035  p->connects = connects;
1036  p->cls = connects_cls;
1038  p->disconnects = disconnects;
1039  p->handlers = GNUNET_MQ_copy_handlers(handlers);
1040 
1041  GNUNET_assert(GNUNET_OK == open_port_cb(h, &p->id, p));
1042  return p;
1043 }
1044 
1045 
1064 struct GNUNET_CADET_Channel *
1066  void *channel_cls,
1067  const struct GNUNET_PeerIdentity *destination,
1068  const struct GNUNET_HashCode *port,
1071  const struct GNUNET_MQ_MessageHandler *handlers)
1072 {
1073  struct GNUNET_CADET_Channel *ch;
1075  struct GNUNET_MQ_Envelope *env;
1076 
1077  GNUNET_assert(NULL != disconnects);
1079  "Creating channel to peer %s at port %s\n",
1080  GNUNET_i2s(destination),
1081  GNUNET_h2s(port));
1082  ch = create_channel(h, NULL);
1083  ch->ctx = channel_cls;
1084  ch->peer = *destination;
1085  ch->window_changes = window_changes;
1086  ch->disconnects = disconnects;
1087 
1088  /* Create MQ for channel */
1092  ch,
1093  handlers,
1095  ch);
1096  GNUNET_MQ_set_handlers_closure(ch->mq, channel_cls);
1097 
1098  /* Request channel creation to service */
1100  msg->ccn = ch->ccn;
1101  msg->port = *port;
1102  msg->peer = *destination;
1103  GNUNET_MQ_send(h->mq, env);
1104  return ch;
1105 }
1106 
1107 
1115 struct GNUNET_MQ_Handle *
1117 {
1118  return channel->mq;
1119 }
1120 
1121 /* end of cadet_api.c */
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration given by the client, in case of reconnection.
Definition: cadet_api.c:62
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
GNUNET_CADET_DisconnectEventHandler disconnects
Handler called when an incoming channel is destroyed.
Definition: cadet_api.c:177
void GNUNET_CADET_disconnect(struct GNUNET_CADET_Handle *handle)
Disconnect from the cadet service.
Definition: cadet_api.c:838
struct GNUNET_CADET_ClientChannelNumber ccn
ID of a channel controlled by this client.
Definition: cadet.h:147
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
Message to allow the client send more data to the service (always service -> client).
Definition: cadet.h:212
static void channel_destroy(struct CadetChannel *ch)
Destroy the given channel.
GNUNET_CADET_DisconnectEventHandler disconnects
Disconnect handler.
Definition: cadet_api.c:126
uint32_t channel_of_client
Values for channel numbering.
Definition: cadet.h:110
Message for or to a client to destroy tunnel.
Definition: cadet.h:169
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_DESTROY
Tell client that a channel was destroyed.
GNUNET_CADET_WindowSizeEventHandler window_changes
Window size change handler.
Definition: cadet_api.c:172
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
Opaque handle to the service.
Definition: cadet_api.c:38
#define GNUNET_MQ_msg_nested_mh(mvar, type, mh)
Allocate a GNUNET_MQ_Envelope, and append a payload message after the given message struct...
void *(* GNUNET_CADET_ConnectEventHandler)(void *cls, struct GNUNET_CADET_Channel *channel, const struct GNUNET_PeerIdentity *source)
Method called whenever a peer connects to a port in MQ-based CADET.
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.
Definition: cadet_api.c:929
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. ...
Definition: cadet_api.c:315
static void reconnect_cbk(void *cls)
Reconnect callback: tries to reconnect again after a failer previous reconnecttion.
Definition: cadet_api.c:337
GNUNET_MQ_Error
Error codes for the queue.
static void handle_channel_destroy(void *cls, const struct GNUNET_CADET_LocalChannelDestroyMessage *msg)
Process the channel destroy notification and free associated resources.
Definition: cadet_api.c:599
We received a message for which we have no matching handler.
int GNUNET_CONTAINER_multihashmap32_iterate(struct GNUNET_CONTAINER_MultiHashMap32 *map, GNUNET_CONTAINER_MulitHashMapIterator32Callback it, void *it_cls)
Iterate over all entries in the map.
Message for a client to create and destroy channels.
Definition: cadet.h:117
void(* GNUNET_CADET_WindowSizeEventHandler)(void *cls, const struct GNUNET_CADET_Channel *channel, int window_size)
Function called whenever an MQ-channel&#39;s transmission window size changes.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_HashCode id
Port "number".
Definition: cadet_api.c:147
static void cadet_mq_send_now(void *cls)
Transmit the next message from our queue.
Definition: cadet_api.c:369
struct GNUNET_MQ_MessageHandler * GNUNET_MQ_copy_handlers(const struct GNUNET_MQ_MessageHandler *handlers)
Copy an array of handlers.
Definition: mq.c:1211
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
static void cadet_mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
Handle destruction of a message queue.
Definition: cadet_api.c:460
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
struct GNUNET_PeerIdentity peer
Other end of the channel.
Definition: cadet_api.c:83
Opaque handle to a channel.
Definition: cadet_api.c:79
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug 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.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
unsigned int allow_send
How many messages are we allowed to send to the service right now?
Definition: cadet_api.c:136
static void notify_window_size(struct GNUNET_CADET_Channel *ch)
Notify the application about a change in the window size (if needed).
Definition: cadet_api.c:354
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_CHANNEL_CREATE
Ask the cadet service to create a new channel.
GNUNET_CADET_ConnectEventHandler connects
Handler for incoming channels on this port.
Definition: cadet_api.c:162
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.
Definition: cadet_api.c:531
int GNUNET_CONTAINER_multihashmap32_put(struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct GNUNET_CADET_ClientChannelNumber next_ccn
child of the next channel to create (to avoid reusing IDs often)
Definition: cadet_api.c:57
Internal representation of the hash map.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
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 c...
Definition: cadet_api.c:757
struct GNUNET_CADET_Handle * GNUNET_CADET_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the MQ-based cadet service.
Definition: cadet_api.c:973
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
struct GNUNET_SCHEDULER_Task * mq_cont
Task to allow mq to send more traffic.
Definition: cadet_api.c:109
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
struct GNUNET_CADET_ClientChannelNumber ccn
Local ID of the channel, GNUNET_CADET_LOCAL_CHANNEL_ID_CLI bit is set if outbound.
Definition: cadet_api.c:131
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.
Definition: cadet_api.c:690
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
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_ACK
Local ACK for data.
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
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 incomming MQ-based channels.
Definition: cadet_api.c:1007
static struct GNUNET_OS_Process * p
Helper process we started.
Definition: gnunet-qr.c:59
int GNUNET_CONTAINER_multihashmap32_remove(struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, const void *value)
Remove the given key-value pair from the map.
void * cls
Closure for mv and cb.
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
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.
Definition: cadet_api.c:209
struct GNUNET_CONTAINER_MultiHashMap * ports
Ports open.
Definition: cadet_api.c:47
static char * value
Value of the record to add/remove.
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.
Definition: cadet_api.c:225
void * GNUNET_CONTAINER_multihashmap32_get(const struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key)
Given a key find a value in the map matching the key.
#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.
void * ctx
Any data the caller wants to put in here, used for the various callbacks (disconnects, window_changes, handlers).
Definition: cadet_api.c:99
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_MQ_Handle * mq
Message queue.
Definition: cadet_api.c:42
GNUNET_CADET_ChannelInfoOption
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1264
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_OPEN
Start listening on a port.
static char * option
Name of the option.
Definition: gnunet-config.c:38
int GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
Number uniquely identifying a channel of a client.
Definition: cadet.h:102
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
#define GNUNET_CADET_LOCAL_CHANNEL_ID_CLI
Minimum value for channel IDs of local clients.
Definition: cadet.h:71
#define LOG(kind,...)
Definition: cadet_api.c:33
Internal representation of the hash map.
static void reconnect(struct GNUNET_CADET_Handle *h)
Reconnect to the service, retransmit all infomation to try to restore the original state...
Definition: cadet_api.c:778
A 512-bit hashcode.
struct GNUNET_CADET_ClientChannelNumber ccn
ID of the channel.
Definition: cadet.h:194
Union to retrieve info about a channel.
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
#define GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE
Maximum message size that can be sent on CADET.
struct GNUNET_CONTAINER_MultiHashMap32 * GNUNET_CONTAINER_multihashmap32_create(unsigned int len)
Create a 32-bit key multi hash map.
struct GNUNET_TIME_Relative reconnect_time
Time to the next reconnect in case one reconnect fails.
Definition: cadet_api.c:72
void * cls
Closure for handler.
Definition: cadet_api.c:157
void GNUNET_CONTAINER_multihashmap32_destroy(struct GNUNET_CONTAINER_MultiHashMap32 *map)
Destroy a 32-bit key hash map.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:319
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.
Definition: cadet_api.c:411
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...
static void cadet_mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
Definition: cadet_api.c:508
struct GNUNET_HashCode port
Port to open/close.
Definition: cadet.h:129
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static void destroy_channel(struct GNUNET_CADET_Channel *ch)
Destroy the specified channel.
Definition: cadet_api.c:267
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:66
struct GNUNET_MQ_Handle * mq
Message Queue for the channel (which we are implementing).
Definition: cadet_api.c:104
Message for a client to create channels.
Definition: cadet.h:136
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...
Definition: cadet_api.c:734
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GNUNET_CADET_Handle * cadet
Handle to the CADET session this port belongs to.
Definition: cadet_api.c:152
struct GNUNET_CADET_ClientChannelNumber ccn
ID of the channel allowed to send more data.
Definition: cadet.h:221
struct GNUNET_CADET_Handle * cadet
Handle to the cadet this channel belongs to.
Definition: cadet_api.c:88
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
int GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
static unsigned long long payload
How much data are we currently storing in the database?
void * connects_cls
Closure for connects.
Definition: cadet_api.c:167
P2P messages used by CADET.
static void handle_local_data(void *cls, const struct GNUNET_CADET_LocalData *message)
Process the incoming data packets, call appropriate handlers.
Definition: cadet_api.c:652
Handle to a message queue.
Definition: mq.c:84
The identity of the host (wraps the signing key of the peer).
void GNUNET_CADET_receive_done(struct GNUNET_CADET_Channel *channel)
Send an ack on the channel to confirm the processing of a message.
Definition: cadet_api.c:951
struct GNUNET_CADET_ClientChannelNumber ccn
ID of a channel controlled by this client.
Definition: cadet.h:178
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.
Definition: cadet_api.c:1065
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...
Definition: cadet_api.c:815
static uint16_t port
Port number.
Definition: gnunet-bcd.c:81
struct GNUNET_MQ_Envelope * pending_env
Pending envelope with a message to be transmitted to the service as soon as we are allowed to...
Definition: cadet_api.c:116
configuration data
Definition: configuration.c:83
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_PORT_CLOSE
Stop listening on a port.
struct GNUNET_MQ_MessageHandler * handlers
Payload handlers for incoming channels.
Definition: cadet_api.c:182
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA
Payload client <-> service.
GNUNET_CADET_WindowSizeEventHandler window_changes
Window change handler.
Definition: cadet_api.c:121
struct GNUNET_CADET_Port * incoming_port
Channel&#39;s port, if incoming.
Definition: cadet_api.c:93
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
Definition: scheduler.c:131
Opaque handle to a port.
Definition: cadet_api.c:143
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
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.
Definition: cadet_api.c:194
static int check_local_data(void *cls, const struct GNUNET_CADET_LocalData *message)
Check that message received from CADET service is well-formed.
Definition: cadet_api.c:630
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
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
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA.
Definition: cadet.h:189
void GNUNET_CADET_close_port(struct GNUNET_CADET_Port *p)
Close a port opened with GNUNET_CADET_open_port().
Definition: cadet_api.c:871
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
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.
Definition: cadet_api.c:478
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
Message for cadet data traffic.
Definition: cadet.h:185
void(* GNUNET_CADET_DisconnectEventHandler)(void *cls, const struct GNUNET_CADET_Channel *channel)
Function called whenever an MQ-channel is destroyed, unless the destruction was requested by GNUNET_C...
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
uint32_t pp
Priority and preferences (an enum GNUNET_MQ_PriorityPreferences) of the message in NBO...
Definition: cadet.h:200
struct GNUNET_SCHEDULER_Task * reconnect_task
Task for trying to reconnect.
Definition: cadet_api.c:67
struct GNUNET_CONTAINER_MultiHashMap32 * channels
Channels open.
Definition: cadet_api.c:52
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
Channel&#39;s peer.
Definition: cadet.h:152
void GNUNET_CADET_channel_destroy(struct GNUNET_CADET_Channel *channel)
Destroy an existing channel.
Definition: cadet_api.c:900
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_HashCode port
Port of the channel.
Definition: cadet.h:157
#define GNUNET_free(ptr)
Wrapper around free.
Who is the peer at the other end of the channel.
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_MQ_Handle * GNUNET_CADET_get_mq(const struct GNUNET_CADET_Channel *channel)
Obtain the message queue for a connected peer.
Definition: cadet_api.c:1116
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956