GNUnet  0.11.x
transport_api_core.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2009-2013, 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  */
20 
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_constants.h"
29 #include "gnunet_arm_service.h"
30 #include "gnunet_hello_lib.h"
31 #include "gnunet_protocols.h"
33 #include "transport.h"
34 
35 #define LOG(kind, ...) GNUNET_log_from (kind, "transport-api-core", __VA_ARGS__)
36 
41 #define UNREADY_WARN_TIME GNUNET_TIME_UNIT_MINUTES
42 
46 #define STARTING_NEIGHBOURS_SIZE 16
47 
48 
52 struct Neighbour
53 {
58 
62  struct GNUNET_MQ_Handle *mq;
63 
67  struct GNUNET_MQ_Envelope *env;
68 
72  void *handlers_cls;
73 
77  struct GNUNET_PeerIdentity id;
78 
83 
93 
99 
104  unsigned long long traffic_overhead;
105 
109  int is_ready;
110 
114  uint16_t env_size;
115 };
116 
117 
123 {
127  void *cls;
128 
134 
139 
144 
149 
153  struct GNUNET_MQ_Handle *mq;
154 
158  const struct GNUNET_CONFIGURATION_Handle *cfg;
159 
165 
169  struct GNUNET_PeerIdentity self;
170 
175 
180 
188  unsigned int rom_pending;
189 
194  int check_self;
195 };
196 
197 
204 static void
206 
207 
215 static struct Neighbour *
217  const struct GNUNET_PeerIdentity *peer)
218 {
219  return GNUNET_CONTAINER_multipeermap_get (h->neighbours, peer);
220 }
221 
222 
229 static void
230 notify_excess_cb (void *cls)
231 {
232  struct Neighbour *n = cls;
233  struct GNUNET_TRANSPORT_CoreHandle *h = n->h;
234 
236  "Notifying CORE that more bandwidth is available for %s\n",
237  GNUNET_i2s (&n->id));
238 
239  if (NULL != h->neb_cb)
240  h->neb_cb (h->cls, &n->id, n->handlers_cls);
241 }
242 
243 
254 static int
255 neighbour_delete (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
256 {
258  struct Neighbour *n = value;
259 
261  "Dropping entry for neighbour `%s'.\n",
262  GNUNET_i2s (key));
264  if (NULL != handle->nd_cb)
265  handle->nd_cb (handle->cls, &n->id, n->handlers_cls);
266  if (NULL != n->timeout_task)
267  {
269  n->timeout_task = NULL;
270  }
271  if (NULL != n->env)
272  {
274  n->env = NULL;
275  }
276  GNUNET_MQ_destroy (n->mq);
277  GNUNET_assert (NULL == n->mq);
278  GNUNET_assert (
279  GNUNET_YES ==
281  GNUNET_free (n);
282  return GNUNET_YES;
283 }
284 
285 
295 static void
296 mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
297 {
299 
301  "Error receiving from transport service (%d), disconnecting temporarily.\n",
302  error);
304 }
305 
306 
314 static int
315 check_hello (void *cls, const struct GNUNET_MessageHeader *msg)
316 {
317  struct GNUNET_PeerIdentity me;
318 
319  if (GNUNET_OK !=
320  GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg, &me))
321  {
322  GNUNET_break (0);
323  return GNUNET_SYSERR;
324  }
325  return GNUNET_OK;
326 }
327 
328 
335 static void
336 handle_hello (void *cls, const struct GNUNET_MessageHeader *msg)
337 {
338  /* we do not care => FIXME: signal in options to NEVER send HELLOs! */
339 }
340 
341 
350 static void
352 {
353  struct Neighbour *n = cls;
354 
355  n->timeout_task = NULL;
356  n->is_ready = GNUNET_YES;
358 }
359 
360 
369 static void
370 notify_send_done (void *cls)
371 {
372  struct Neighbour *n = cls;
374 
375  n->timeout_task = NULL;
376  if (NULL != n->env)
377  {
379  n->env_size + n->traffic_overhead);
380  n->env = NULL;
381  n->traffic_overhead = 0;
382  }
384  if (0 == delay.rel_value_us)
385  {
386  n->is_ready = GNUNET_YES;
388  return;
389  }
391  /* cannot send even a small message without violating
392  quota, wait a before allowing MQ to send next message */
393  n->timeout_task =
395 }
396 
397 
408 static void
410  const struct GNUNET_MessageHeader *msg,
411  void *impl_state)
412 {
413  struct Neighbour *n = impl_state;
414  struct GNUNET_TRANSPORT_CoreHandle *h = n->h;
415  struct OutboundMessage *obm;
416  uint16_t msize;
417 
419  msize = ntohs (msg->size);
420  if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*obm))
421  {
422  GNUNET_break (0);
424  return;
425  }
426  GNUNET_assert (NULL == n->env);
427  n->env =
429  {
430  struct GNUNET_MQ_Envelope *env;
431 
433  obm->priority = htonl ((uint32_t) GNUNET_MQ_env_get_options (env));
434  }
436  GNUNET_TIME_UNIT_MINUTES); /* FIXME: to be removed */
437  obm->peer = n->id;
438  GNUNET_assert (NULL == n->timeout_task);
439  n->is_ready = GNUNET_NO;
440  n->env_size = ntohs (msg->size);
442  GNUNET_MQ_send (h->mq, n->env);
444  "Queued message of type %u for neighbour `%s'.\n",
445  ntohs (msg->type),
446  GNUNET_i2s (&n->id));
447 }
448 
449 
457 static void
458 mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
459 {
460  struct Neighbour *n = impl_state;
461 
462  GNUNET_assert (mq == n->mq);
463  n->mq = NULL;
464 }
465 
466 
474 static void
475 mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
476 {
477  struct Neighbour *n = impl_state;
478 
480  if (NULL != n->env)
481  {
483  n->env = NULL;
484  }
485 
486  n->is_ready = GNUNET_YES;
487 }
488 
489 
498 static void
499 peer_mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
500 {
501  /* struct Neighbour *n = cls; */
502 
503  GNUNET_break_op (0);
504 }
505 
506 
513 static void
515 {
516  struct Neighbour *n = cls;
518 
519  if (NULL == n->timeout_task)
520  return;
524 }
525 
526 
533 static void
534 handle_connect (void *cls, const struct ConnectInfoMessage *cim)
535 {
537  struct Neighbour *n;
538 
540  "Receiving CONNECT message for `%s' with quota %u\n",
541  GNUNET_i2s (&cim->id),
542  ntohl (cim->quota_out.value__));
543  n = neighbour_find (h, &cim->id);
544  if (NULL != n)
545  {
546  GNUNET_break (0); /* FIXME: this assertion seems to fail sometimes!? */
548  return;
549  }
550  n = GNUNET_new (struct Neighbour);
551  n->id = cim->id;
552  n->h = h;
553  n->is_ready = GNUNET_YES;
554  n->traffic_overhead = 0;
557  n,
561  n);
564  h->neighbours,
565  &n->id,
566  n,
568 
573  n,
574  h->handlers,
576  n);
577  if (NULL != h->nc_cb)
578  {
579  n->handlers_cls = h->nc_cb (h->cls, &n->id, n->mq);
581  }
582 }
583 
584 
591 static void
592 handle_disconnect (void *cls, const struct DisconnectInfoMessage *dim)
593 {
595  struct Neighbour *n;
596 
597  GNUNET_break (ntohl (dim->reserved) == 0);
599  "Receiving DISCONNECT message for `%s'.\n",
600  GNUNET_i2s (&dim->peer));
601  n = neighbour_find (h, &dim->peer);
602  if (NULL == n)
603  {
604  GNUNET_break (0);
606  return;
607  }
609 }
610 
611 
618 static void
619 handle_send_ok (void *cls, const struct SendOkMessage *okm)
620 {
622  struct Neighbour *n;
623  uint32_t bytes_msg;
624  uint32_t bytes_physical;
625  uint16_t success = ntohs (okm->success);
626 
627  bytes_msg = ntohs (okm->bytes_msg);
628  bytes_physical = ntohl (okm->bytes_physical);
630  "Receiving SEND_OK message, transmission to %s %s.\n",
631  GNUNET_i2s (&okm->peer),
632  success == GNUNET_OK ? "succeeded" : "failed");
633  n = neighbour_find (h, &okm->peer);
634  if (NULL == n)
635  {
636  /* We should never get a 'SEND_OK' for a peer that we are not
637  connected to */
638  GNUNET_break (0);
640  return;
641  }
642  if (bytes_physical > bytes_msg)
643  {
645  "Overhead for %u byte message was %u\n",
646  bytes_msg,
647  bytes_physical - bytes_msg);
648  n->traffic_overhead += bytes_physical - bytes_msg;
649  }
650 }
651 
652 
659 static int
660 check_recv (void *cls, const struct InboundMessage *im)
661 {
662  const struct GNUNET_MessageHeader *imm;
663  uint16_t size;
664 
665  size = ntohs (im->header.size) - sizeof(*im);
666  if (size < sizeof(struct GNUNET_MessageHeader))
667  {
668  GNUNET_break (0);
669  return GNUNET_SYSERR;
670  }
671  imm = (const struct GNUNET_MessageHeader *) &im[1];
672  if (ntohs (imm->size) != size)
673  {
674  GNUNET_break (0);
675  return GNUNET_SYSERR;
676  }
677  return GNUNET_OK;
678 }
679 
680 
687 static void
688 handle_recv (void *cls, const struct InboundMessage *im)
689 {
691  const struct GNUNET_MessageHeader *imm =
692  (const struct GNUNET_MessageHeader *) &im[1];
693  struct Neighbour *n;
694 
696  "Received message of type %u with %u bytes from `%s'.\n",
697  (unsigned int) ntohs (imm->type),
698  (unsigned int) ntohs (imm->size),
699  GNUNET_i2s (&im->peer));
700  n = neighbour_find (h, &im->peer);
701  if (NULL == n)
702  {
703  GNUNET_break (0);
705  return;
706  }
707  h->rom_pending++;
708  GNUNET_MQ_inject_message (n->mq, imm);
709 }
710 
711 
718 static void
719 handle_set_quota (void *cls, const struct QuotaSetMessage *qm)
720 {
722  struct Neighbour *n;
723 
725  "Receiving SET_QUOTA message for `%s' with quota %u\n",
726  GNUNET_i2s (&qm->peer),
727  ntohl (qm->quota.value__));
728  n = neighbour_find (h, &qm->peer);
729  if (NULL == n)
730  {
731  GNUNET_break (
732  0); /* FIXME: julius reports this assertion fails sometimes? */
734  return;
735  }
737 }
738 
739 
745 static void
746 reconnect (void *cls)
747 {
750  { GNUNET_MQ_hd_var_size (hello,
752  struct GNUNET_MessageHeader,
753  h),
754  GNUNET_MQ_hd_fixed_size (connect,
756  struct ConnectInfoMessage,
757  h),
760  struct DisconnectInfoMessage,
761  h),
762  GNUNET_MQ_hd_fixed_size (send_ok,
764  struct SendOkMessage,
765  h),
766  GNUNET_MQ_hd_var_size (recv,
768  struct InboundMessage,
769  h),
770  GNUNET_MQ_hd_fixed_size (set_quota,
772  struct QuotaSetMessage,
773  h),
775  struct GNUNET_MQ_Envelope *env;
776  struct StartMessage *s;
777  uint32_t options;
778 
779  h->reconnect_task = NULL;
780  LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n");
781  GNUNET_assert (NULL == h->mq);
782  h->mq =
784  if (NULL == h->mq)
785  return;
787  options = 0;
788  if (h->check_self)
789  options |= 1;
790  if (NULL != h->handlers)
791  options |= 2;
792  s->options = htonl (options);
793  s->self = h->self;
794  GNUNET_MQ_send (h->mq, env);
795 }
796 
797 
804 static void
806 {
807  GNUNET_assert (NULL == h->reconnect_task);
808  /* Forget about all neighbours that we used to be connected to */
810  if (NULL != h->mq)
811  {
813  h->mq = NULL;
814  }
816  "Scheduling task to reconnect to transport service in %s.\n",
818  h->reconnect_task =
819  GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
820  h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay);
821 }
822 
823 
831 struct GNUNET_MQ_Handle *
833  const struct GNUNET_PeerIdentity *peer)
834 {
835  struct Neighbour *n;
836 
837  n = neighbour_find (handle, peer);
838  if (NULL == n)
839  return NULL;
840  return n->mq;
841 }
842 
843 
860  const struct GNUNET_PeerIdentity *self,
861  const struct GNUNET_MQ_MessageHandler *handlers,
862  void *cls,
866 {
868  unsigned int i;
869 
871  if (NULL != self)
872  {
873  h->self = *self;
874  h->check_self = GNUNET_YES;
875  }
876  h->cfg = cfg;
877  h->cls = cls;
878  h->nc_cb = nc;
879  h->nd_cb = nd;
880  h->neb_cb = neb;
881  h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
882  if (NULL != handlers)
883  {
884  for (i = 0; NULL != handlers[i].cb; i++)
885  ;
886  h->handlers = GNUNET_new_array (i + 1, struct GNUNET_MQ_MessageHandler);
887  GNUNET_memcpy (h->handlers,
888  handlers,
889  i * sizeof(struct GNUNET_MQ_MessageHandler));
890  }
891  LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n");
892  reconnect (h);
893  if (NULL == h->mq)
894  {
895  GNUNET_free (h->handlers);
896  GNUNET_free (h);
897  return NULL;
898  }
899  h->neighbours =
901  return h;
902 }
903 
904 
911 void
913 {
914  LOG (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n");
915  /* this disconnects all neighbours... */
916  if (NULL == handle->reconnect_task)
918  /* and now we stop trying to connect again... */
919  if (NULL != handle->reconnect_task)
920  {
922  handle->reconnect_task = NULL;
923  }
925  handle->neighbours = NULL;
926  GNUNET_free (handle->handlers);
927  handle->handlers = NULL;
929 }
930 
931 
952 void
953 GNUNET_TRANSPORT_core_receive_continue (struct GNUNET_TRANSPORT_CoreHandle *ch,
954  const struct GNUNET_PeerIdentity *pid)
955 {
956  struct RecvOkMessage *rom;
957  struct GNUNET_MQ_Envelope *env;
958 
959  GNUNET_assert (ch->rom_pending > 0);
960  ch->rom_pending--;
962  rom->increase_window_delta = htonl (1);
963  rom->peer = *pid;
964  GNUNET_MQ_send (ch->mq, env);
965 }
966 
967 
968 /* end of transport_api_core.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static char * value
Value of the record to add/remove.
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
#define MAX_BANDWIDTH_CARRY_S
Number of seconds that available bandwidth carries over (can accumulate).
static struct GNUNET_PEERINFO_NotifyContext * nc
Iterator context.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_YES
Definition: gnunet_common.h:97
@ GNUNET_NO
Definition: gnunet_common.h:94
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
void GNUNET_BANDWIDTH_tracker_notification_stop(struct GNUNET_BANDWIDTH_Tracker *av)
Stop notifying about tracker updates and excess notifications.
Definition: bandwidth.c:325
int GNUNET_BANDWIDTH_tracker_consume(struct GNUNET_BANDWIDTH_Tracker *av, ssize_t size)
Notify the tracker that a certain number of bytes of bandwidth have been consumed.
Definition: bandwidth.c:402
void GNUNET_BANDWIDTH_tracker_update_quota(struct GNUNET_BANDWIDTH_Tracker *av, struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit)
Update quota of bandwidth tracker.
Definition: bandwidth.c:526
void GNUNET_BANDWIDTH_tracker_init2(struct GNUNET_BANDWIDTH_Tracker *av, GNUNET_BANDWIDTH_TrackerUpdateCallback update_cb, void *update_cb_cls, struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit, uint32_t max_carry_s, GNUNET_BANDWIDTH_ExcessNotificationCallback excess_cb, void *excess_cb_cls)
Initialize bandwidth tracker.
Definition: bandwidth.c:259
struct GNUNET_TIME_Relative GNUNET_BANDWIDTH_tracker_get_delay(struct GNUNET_BANDWIDTH_Tracker *av, size_t size)
Compute how long we should wait until consuming size bytes of bandwidth in order to stay within the g...
Definition: bandwidth.c:458
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:1064
#define GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT
Bandwidth (in/out) to assume initially (before either peer has communicated any particular preference...
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_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_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.
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.
@ 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...
int GNUNET_HELLO_get_id(const struct GNUNET_HELLO_Message *hello, struct GNUNET_PeerIdentity *peer)
Get the peer identity from a HELLO message.
Definition: hello.c:671
#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_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_send_cancel(struct GNUNET_MQ_Envelope *ev)
Cancel sending the message.
Definition: mq.c:929
GNUNET_MQ_Error
Error codes for the queue.
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:355
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
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:565
#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_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition: mq.c:499
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
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:202
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore.
Definition: mq.c:787
enum GNUNET_MQ_PriorityPreferences GNUNET_MQ_env_get_options(struct GNUNET_MQ_Envelope *env)
Get performance preferences set for this envelope.
Definition: mq.c:1037
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_MQ_impl_send_in_flight(struct GNUNET_MQ_Handle *mq)
Call the send notification for the current message, but do not try to send the next message until #gn...
Definition: mq.c:532
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:596
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:991
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:837
#define GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT
Message from TRANSPORT notifying about a client that connected to us.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_START
Message from the core saying that the transport server should start giving it messages.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK
Message telling transport to limit its receive rate.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_RECV
Message from TRANSPORT notifying about a message that was received.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT
Message from TRANSPORT notifying about a client that disconnected from us.
#define GNUNET_MESSAGE_TYPE_HELLO
HELLO message with friend only flag used for communicating peer addresses.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SEND
Request to TRANSPORT to transmit a message.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK
Confirmation from TRANSPORT that message for transmission has been queued (and that the next message ...
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA
Message telling transport to limit its receive rate.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972
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:1269
#define GNUNET_TIME_UNIT_MINUTES
One minute.
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:444
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:557
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
struct GNUNET_MQ_Handle * GNUNET_TRANSPORT_core_get_mq(struct GNUNET_TRANSPORT_CoreHandle *handle, const struct GNUNET_PeerIdentity *peer)
Checks if a given peer is connected to us and get the message queue.
void *(* GNUNET_TRANSPORT_NotifyConnect)(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Function called to notify transport users that another peer connected to us.
void(* GNUNET_TRANSPORT_NotifyDisconnect)(void *cls, const struct GNUNET_PeerIdentity *peer, void *handler_cls)
Function called to notify transport users that another peer disconnected from us.
void(* GNUNET_TRANSPORT_NotifyExcessBandwidth)(void *cls, const struct GNUNET_PeerIdentity *neighbour, void *handlers_cls)
Function called if we have "excess" bandwidth to a peer.
struct GNUNET_TRANSPORT_CoreHandle * GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *self, const struct GNUNET_MQ_MessageHandler *handlers, void *cls, GNUNET_TRANSPORT_NotifyConnect nc, GNUNET_TRANSPORT_NotifyDisconnect nd, GNUNET_TRANSPORT_NotifyExcessBandwidth neb)
Connect to the transport service.
void GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle)
Disconnect from the transport service.
static unsigned int size
Size of the "table".
Definition: peer.c:67
static void disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the peerstore service.
Message from the transport service to the library informing about neighbors.
Definition: transport.h:118
struct GNUNET_PeerIdentity id
Identity of the new neighbour.
Definition: transport.h:141
struct GNUNET_BANDWIDTH_Value32NBO quota_out
Current outbound quota for this peer.
Definition: transport.h:135
Message from the transport service to the library informing about disconnects.
Definition: transport.h:150
uint32_t reserved
Reserved, always zero.
Definition: transport.h:159
struct GNUNET_PeerIdentity peer
Who got disconnected?
Definition: transport.h:164
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
Definition: arm_api.c:107
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition: arm_api.c:112
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
Definition: arm_api.c:147
Struct to track available bandwidth.
uint32_t value__
The actual value (bytes per second).
struct GNUNET_MQ_Handle * mq
Message Queue for the channel (which we are implementing).
Definition: cadet.h:143
Internal representation of the hash map.
struct GNUNET_SCHEDULER_Task * reconnect_task
Task to reconnect to the service.
Definition: dns_api.c:81
A HELLO message is used to exchange information about transports with other peers.
Handle to a message queue.
Definition: mq.c:86
Message handler for a specific message type.
Header for all communications.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Definition: scheduler.c:135
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Handle for the transport service (includes all of the state for the transport service).
int check_self
Should we check that self matches what the service thinks? (if GNUNET_NO, then self is all zeros!...
struct GNUNET_PeerIdentity self
Peer identity as assumed by this process, or all zeros.
const struct GNUNET_CONFIGURATION_Handle * cfg
My configuration.
struct GNUNET_CONTAINER_MultiPeerMap * neighbours
Hash map of the current connected neighbours of this peer.
void * cls
Closure for the callbacks.
GNUNET_TRANSPORT_NotifyDisconnect nd_cb
function to call on disconnect events
unsigned int rom_pending
Internal counter to check how many more receive OK messages this CORE service is allowed to send in t...
struct GNUNET_MQ_Handle * mq
My client connection to the transport service.
GNUNET_TRANSPORT_NotifyConnect nc_cb
function to call on connect events
struct GNUNET_TIME_Relative reconnect_delay
Delay until we try to reconnect.
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the task trying to reconnect to the service.
GNUNET_TRANSPORT_NotifyExcessBandwidth neb_cb
function to call on excess bandwidth events
struct GNUNET_MQ_MessageHandler * handlers
Functions to call for received data (template for new message queues).
Message used to notify the transport API about a message received from the network.
Definition: transport.h:199
struct GNUNET_MessageHeader header
Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_RECV.
Definition: transport.h:203
struct GNUNET_PeerIdentity peer
Which peer sent the message?
Definition: transport.h:208
A connected controller which is not our child.
void * handlers_cls
Closure for mq handlers.
uint16_t env_size
Size of the message in env.
struct GNUNET_TRANSPORT_CoreHandle * h
Overall transport handle.
struct GNUNET_MQ_Envelope * env
Envelope with the message we are currently transmitting (or NULL).
struct GNUNET_MQ_Handle * mq
Active message queue for the peer.
struct GNUNET_CONTAINER_HeapNode * hn
Entry in our readiness heap (which is sorted by next_ready value).
struct GNUNET_BANDWIDTH_Tracker out_tracker
Outbound bandwidh tracker.
struct GNUNET_PeerIdentity id
Identity of this neighbour.
int is_ready
Is this peer currently ready to receive a message?
struct GNUNET_SCHEDULER_Task * timeout_task
Task to trigger MQ when we have enough bandwidth for the next transmission.
unsigned long long traffic_overhead
Sending consumed more bytes on wire than payload was announced This overhead is added to the delay of...
Message used to notify the transport service about a message to be transmitted to another peer.
Definition: transport.h:285
uint32_t priority
An enum GNUNET_MQ_PriorityPreferences in NBO.
Definition: transport.h:294
struct GNUNET_PeerIdentity peer
Which peer should receive the message?
Definition: transport.h:308
struct GNUNET_TIME_RelativeNBO timeout
Allowed delay.
Definition: transport.h:302
Message used to set a particular bandwidth quota.
Definition: transport.h:176
struct GNUNET_BANDWIDTH_Value32NBO quota
Quota.
Definition: transport.h:185
struct GNUNET_PeerIdentity peer
About which peer are we talking here?
Definition: transport.h:190
Message used to notify the transport API that it can send another message to the transport service.
Definition: transport.h:261
struct GNUNET_PeerIdentity peer
Which peer can CORE handle more from now?
Definition: transport.h:276
uint32_t increase_window_delta
Number of messages by which to increase the window, greater or equal to one.
Definition: transport.h:271
Message used to notify the transport API that it can send another message to the transport service.
Definition: transport.h:217
uint16_t success
GNUNET_OK if the transmission succeeded, GNUNET_SYSERR if it failed (i.e.
Definition: transport.h:234
uint16_t bytes_msg
Size of message sent.
Definition: transport.h:239
uint32_t bytes_physical
Size of message sent over wire.
Definition: transport.h:245
struct GNUNET_PeerIdentity peer
Which peer can send more now?
Definition: transport.h:251
Message from the transport service to the library asking to check if both processes agree about this ...
Definition: transport.h:92
uint32_t options
0: no options 1: The self field should be checked 2: this client is interested in payload traffic
Definition: transport.h:103
struct GNUNET_PeerIdentity self
Identity we think we have.
Definition: transport.h:109
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
common internal definitions for transport service
static void handle_hello(void *cls, const struct GNUNET_MessageHeader *msg)
Function we use for handling incoming HELLO messages.
static int check_hello(void *cls, const struct GNUNET_MessageHeader *msg)
Function we use for checking incoming HELLO messages.
static int neighbour_delete(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Iterator over hash map entries, for deleting state of a neighbour.
static void handle_connect(void *cls, const struct ConnectInfoMessage *cim)
Function we use for handling incoming connect messages.
static void peer_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 void outbound_bw_tracker_update(void *cls)
The outbound quota has changed in a way that may require us to reset the timeout.
static void notify_send_done_fin(void *cls)
A message from the handler's message queue to a neighbour was transmitted.
static void handle_disconnect(void *cls, const struct DisconnectInfoMessage *dim)
Function we use for handling incoming disconnect messages.
static struct Neighbour * neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h, const struct GNUNET_PeerIdentity *peer)
Get the neighbour list entry for the given peer.
static void handle_send_ok(void *cls, const struct SendOkMessage *okm)
Function we use for handling incoming send-ok messages.
static int check_recv(void *cls, const struct InboundMessage *im)
Function we use for checking incoming "inbound" messages.
static void disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h)
Function that will schedule the job that will try to connect us again to the client.
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
static void reconnect(void *cls)
Try again to connect to transport service.
static void notify_send_done(void *cls)
A message from the handler's message queue to a neighbour was transmitted.
static void mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
Handle destruction of a message queue.
static void handle_set_quota(void *cls, const struct QuotaSetMessage *qm)
Function we use for handling incoming set quota messages.
#define STARTING_NEIGHBOURS_SIZE
How large to start with for the hashmap of neighbours.
static void mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
#define LOG(kind,...)
static void notify_excess_cb(void *cls)
Function called by the bandwidth tracker if we have excess bandwidth.
static void handle_recv(void *cls, const struct InboundMessage *im)
Function we use for handling incoming messages.
static void mq_send_impl(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
Implement sending functionality of a message queue.