GNUnet  0.11.x
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2011 GNUnet e.V.
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.
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
13  Affero General Public License for more details.
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <>.
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
25 #include "platform.h"
27 #include "gnunet-service-ats.h"
28 #include "ats.h"
55 static struct GNUNET_TIME_Relative
57  int32_t amount)
58 {
59  struct GNUNET_BANDWIDTH_Tracker *tracker;
60  struct GNUNET_TIME_Relative ret;
62  tracker = GNUNET_CONTAINER_multipeermap_get (trackers,
63  peer);
64  if (NULL == tracker)
65  {
67  "Not connected, allowing reservation of %d bytes\n",
68  (int) amount);
69  return GNUNET_TIME_UNIT_ZERO; /* not connected, satisfy now */
70  }
71  if (amount >= 0)
72  {
73  ret = GNUNET_BANDWIDTH_tracker_get_delay (tracker, amount);
74  if (ret.rel_value_us > 0)
75  {
77  "Delay to satisfy reservation for %d bytes is %s\n",
78  (int) amount,
81  return ret;
82  }
83  }
84  (void) GNUNET_BANDWIDTH_tracker_consume (tracker, amount);
86  "Reserved %d bytes\n",
87  (int) amount);
89 }
100 void
102  struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
103 {
104  struct GNUNET_BANDWIDTH_Tracker *tracker;
106  tracker = GNUNET_CONTAINER_multipeermap_get (trackers, peer);
107  if (0 == ntohl (bandwidth_in.value__))
108  {
109  if (NULL == tracker)
110  return;
113  peer,
114  tracker));
115  GNUNET_free (tracker);
116  return;
117  }
118  if (NULL == tracker)
119  {
120  tracker = GNUNET_new (struct GNUNET_BANDWIDTH_Tracker);
122  NULL,
123  NULL,
124  bandwidth_in,
128  peer,
129  tracker,
131  return;
132  }
134  bandwidth_in);
135 }
144 void
146  const struct ReservationRequestMessage *msg)
147 {
148  struct GNUNET_MQ_Envelope *env;
150  int32_t amount;
151  struct GNUNET_TIME_Relative res_delay;
154  "Received RESERVATION_REQUEST message\n");
155  amount = (int32_t) ntohl (msg->amount);
156  res_delay = reservations_reserve (&msg->peer, amount);
157  if (res_delay.rel_value_us > 0)
158  amount = 0;
159  env = GNUNET_MQ_msg (result,
161  result->amount = htonl (amount);
162  result->peer = msg->peer;
163  result->res_delay = GNUNET_TIME_relative_hton (res_delay);
165  "# reservation requests processed",
166  1,
167  GNUNET_NO);
169  env);
170 }
176 void
178 {
179  trackers = GNUNET_CONTAINER_multipeermap_create (128,
180  GNUNET_NO);
181 }
192 static int
193 free_tracker (void *cls,
194  const struct GNUNET_PeerIdentity *key,
195  void *value)
196 {
197  struct GNUNET_BANDWIDTH_Tracker *tracker = value;
199  GNUNET_free (tracker);
200  return GNUNET_OK;
201 }
207 void
209 {
211  &free_tracker,
212  NULL);
214 }
217 /* end of gnunet-service-ats_reservations.c */
void GAS_handle_reservation_request(struct GNUNET_SERVICE_Client *client, const struct ReservationRequestMessage *msg)
Handle &#39;reservation request&#39; messages from clients.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
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
static struct GNUNET_CONTAINER_MultiPeerMap * trackers
Map of peer identities to struct GNUNET_BANDWIDTH_Tracker *s.
void GNUNET_BANDWIDTH_tracker_init(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)
Initialize bandwidth tracker.
Definition: bandwidth.c:302
uint64_t rel_value_us
The actual value.
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2434
void GAS_reservations_done()
Shutdown reservations subsystem.
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
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
Struct to track available bandwidth.
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.
#define GNUNET_NO
Definition: gnunet_common.h:86
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:83
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
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_STATISTICS_Handle * GSA_stats
Handle for statistics.
void GAS_reservations_init()
Initialize reservations subsystem.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
void GAS_reservations_set_bandwidth(const struct GNUNET_PeerIdentity *peer, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
Set the amount of bandwidth the other peer could currently transmit to us (as far as we know) to the ...
uint32_t value__
The actual value (bytes per second).
Handle to a client that is connected to a service.
Definition: service.c:250
struct GNUNET_PeerIdentity peer
Definition: ats.h:406
ats service, inbound bandwidth reservation management
static int free_tracker(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Free memory of bandwidth tracker.
static char * value
Value of the record to add/remove.
static struct GNUNET_TIME_Relative reservations_reserve(const struct GNUNET_PeerIdentity *peer, int32_t amount)
Reserve the given amount of incoming bandwidth (in bytes) from the given peer.
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:690
static int result
Global testing status.
Internal representation of the hash map.
Number of seconds that available bandwidth carries over (can accumulate).
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
There must only be one value per key; storing a value should fail if a value under the same key alrea...
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_HashCode key
The key used in the DHT.
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:625
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
32-bit bandwidth used for network exchange by GNUnet, in bytes per second.
Relative time zero.
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).
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.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:85
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:353
struct GNUNET_TIME_RelativeNBO res_delay
Definition: ats.h:411
Type of the &#39;struct ReservationResultMessage&#39; sent by ATS to clients in response to a reservation req...
struct GNUNET_PeerIdentity peer
Definition: ats.h:384
automatic transport selection messages
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.