GNUnet  0.10.x
Macros | Functions | Variables
gnunet-service-ats_reservations.c File Reference

ats service, inbound bandwidth reservation management More...

#include "platform.h"
#include "gnunet-service-ats_reservations.h"
#include "gnunet-service-ats.h"
#include "ats.h"
Include dependency graph for gnunet-service-ats_reservations.c:

Go to the source code of this file.

Macros

#define MAX_BANDWIDTH_CARRY_S   5
 Number of seconds that available bandwidth carries over (can accumulate). More...
 

Functions

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. More...
 
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 given value. More...
 
void GAS_handle_reservation_request (struct GNUNET_SERVICE_Client *client, const struct ReservationRequestMessage *msg)
 Handle 'reservation request' messages from clients. More...
 
void GAS_reservations_init ()
 Initialize reservations subsystem. More...
 
static int free_tracker (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Free memory of bandwidth tracker. More...
 
void GAS_reservations_done ()
 Shutdown reservations subsystem. More...
 

Variables

static struct GNUNET_CONTAINER_MultiPeerMaptrackers
 Map of peer identities to struct GNUNET_BANDWIDTH_Tracker *s. More...
 

Detailed Description

ats service, inbound bandwidth reservation management

Author
Christian Grothoff

Definition in file gnunet-service-ats_reservations.c.

Macro Definition Documentation

◆ MAX_BANDWIDTH_CARRY_S

#define MAX_BANDWIDTH_CARRY_S   5

Number of seconds that available bandwidth carries over (can accumulate).

Note that the test_ats_reservation_api test depends on this value!

Definition at line 35 of file gnunet-service-ats_reservations.c.

Referenced by GAS_reservations_set_bandwidth(), handle_connect(), and setup_neighbour().

Function Documentation

◆ reservations_reserve()

static struct GNUNET_TIME_Relative reservations_reserve ( const struct GNUNET_PeerIdentity peer,
int32_t  amount 
)
static

Reserve the given amount of incoming bandwidth (in bytes) from the given peer.

If a reservation is not possible right now, return how long the client should wait before trying again.

Parameters
peerpeer to reserve bandwidth from
amountnumber of bytes to reserve
Returns
0 if the reservation was successful, FOREVER if the peer is not connected, otherwise the time to wait until the reservation might succeed

Definition at line 56 of file gnunet-service-ats_reservations.c.

References GNUNET_BANDWIDTH_tracker_consume(), GNUNET_BANDWIDTH_tracker_get_delay(), GNUNET_CONTAINER_multipeermap_get(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_UNIT_ZERO, GNUNET_YES, GNUNET_TIME_Relative::rel_value_us, and ret.

Referenced by GAS_handle_reservation_request().

58 {
59  struct GNUNET_BANDWIDTH_Tracker *tracker;
61 
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,
80  GNUNET_YES));
81  return ret;
82  }
83  }
84  (void)GNUNET_BANDWIDTH_tracker_consume(tracker, amount);
86  "Reserved %d bytes\n",
87  (int)amount);
88  return GNUNET_TIME_UNIT_ZERO;
89 }
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.
Struct to track available bandwidth.
static int ret
Final status code.
Definition: gnunet-arm.c:89
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:686
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
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
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:77
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_reservations_set_bandwidth()

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 given value.

Parameters
peeridentity of the peer
bandwidth_incurrently available bandwidth from that peer to this peer (estimate)

Definition at line 101 of file gnunet-service-ats_reservations.c.

References GNUNET_assert, GNUNET_BANDWIDTH_tracker_init(), GNUNET_BANDWIDTH_tracker_update_quota(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_free, GNUNET_new, GNUNET_OK, GNUNET_YES, MAX_BANDWIDTH_CARRY_S, and GNUNET_BANDWIDTH_Value32NBO::value__.

Referenced by bandwidth_changed_cb().

103 {
104  struct GNUNET_BANDWIDTH_Tracker *tracker;
105 
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 }
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
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.
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_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
uint32_t value__
The actual value (bytes per second).
#define MAX_BANDWIDTH_CARRY_S
Number of seconds that available bandwidth carries over (can accumulate).
There must only be one value per key; storing a value should fail if a value under the same key alrea...
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.
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_YES
Definition: gnunet_common.h:77
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_handle_reservation_request()

void GAS_handle_reservation_request ( struct GNUNET_SERVICE_Client client,
const struct ReservationRequestMessage msg 
)

Handle 'reservation request' messages from clients.

Parameters
clientclient that sent the request
msgthe request message

Definition at line 145 of file gnunet-service-ats_reservations.c.

References ReservationRequestMessage::amount, ReservationResultMessage::amount, env, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_NO, GNUNET_SERVICE_client_get_mq(), GNUNET_STATISTICS_update(), GNUNET_TIME_relative_hton(), GSA_stats, ReservationRequestMessage::peer, ReservationResultMessage::peer, GNUNET_TIME_Relative::rel_value_us, ReservationResultMessage::res_delay, reservations_reserve(), and result.

Referenced by handle_reservation_request().

147 {
148  struct GNUNET_MQ_Envelope *env;
150  int32_t amount;
151  struct GNUNET_TIME_Relative res_delay;
152 
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 }
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2424
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_NO
Definition: gnunet_common.h:78
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_STATISTICS_Handle * GSA_stats
Handle for statistics.
struct GNUNET_PeerIdentity peer
Definition: ats.h:395
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.
static int result
Global testing status.
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:623
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_log(kind,...)
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
struct GNUNET_TIME_RelativeNBO res_delay
Definition: ats.h:400
#define GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT
Type of the 'struct ReservationResultMessage' sent by ATS to clients in response to a reservation req...
struct GNUNET_PeerIdentity peer
Definition: ats.h:374
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GAS_reservations_init()

void GAS_reservations_init ( void  )

Initialize reservations subsystem.

Parameters
serverhandle to our server

Definition at line 177 of file gnunet-service-ats_reservations.c.

References GNUNET_CONTAINER_multipeermap_create(), and GNUNET_NO.

Referenced by run().

178 {
180  GNUNET_NO);
181 }
static struct GNUNET_CONTAINER_MultiPeerMap * trackers
Map of peer identities to struct GNUNET_BANDWIDTH_Tracker *s.
#define GNUNET_NO
Definition: gnunet_common.h:78
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).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_tracker()

static int free_tracker ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Free memory of bandwidth tracker.

Parameters
clsNULL
keypeer identity (unused)
valuethe struct GNUNET_BANDWIDTH_Tracker to free
Returns
GNUNET_OK (continue to iterate)

Definition at line 193 of file gnunet-service-ats_reservations.c.

References GNUNET_free, GNUNET_OK, and value.

Referenced by GAS_reservations_done().

196 {
197  struct GNUNET_BANDWIDTH_Tracker *tracker = value;
198 
199  GNUNET_free(tracker);
200  return GNUNET_OK;
201 }
Struct to track available bandwidth.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static char * value
Value of the record to add/remove.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ GAS_reservations_done()

void GAS_reservations_done ( void  )

Shutdown reservations subsystem.

Definition at line 208 of file gnunet-service-ats_reservations.c.

References free_tracker(), GNUNET_CONTAINER_multipeermap_destroy(), and GNUNET_CONTAINER_multipeermap_iterate().

Referenced by cleanup_task(), and run().

209 {
211  &free_tracker,
212  NULL);
214 }
static struct GNUNET_CONTAINER_MultiPeerMap * trackers
Map of peer identities to struct GNUNET_BANDWIDTH_Tracker *s.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
static int free_tracker(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Free memory of bandwidth tracker.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ trackers

struct GNUNET_CONTAINER_MultiPeerMap* trackers
static

Map of peer identities to struct GNUNET_BANDWIDTH_Tracker *s.

Definition at line 41 of file gnunet-service-ats_reservations.c.