GNUnet  0.10.x
Functions | Variables
gnunet-service-dht_neighbours.h File Reference

GNUnet DHT routing code. More...

#include "gnunet_util_lib.h"
#include "gnunet_block_lib.h"
#include "gnunet_dht_service.h"
Include dependency graph for gnunet-service-dht_neighbours.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type, enum GNUNET_DHT_RouteOption options, uint32_t desired_replication_level, struct GNUNET_TIME_Absolute expiration_time, uint32_t hop_count, struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *key, unsigned int put_path_length, struct GNUNET_PeerIdentity *put_path, const void *data, size_t data_size)
 Perform a PUT operation. More...
 
int GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, enum GNUNET_DHT_RouteOption options, uint32_t desired_replication_level, uint32_t hop_count, const struct GNUNET_HashCode *key, const void *xquery, size_t xquery_size, struct GNUNET_BLOCK_Group *bg, struct GNUNET_CONTAINER_BloomFilter *peer_bf)
 Perform a GET operation. More...
 
void GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute expiration_time, const struct GNUNET_HashCode *key, unsigned int put_path_length, const struct GNUNET_PeerIdentity *put_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *get_path, const void *data, size_t data_size)
 Handle a reply (route to origin). More...
 
int GDS_am_closest_peer (const struct GNUNET_HashCode *key, const struct GNUNET_CONTAINER_BloomFilter *bloom)
 Check whether my identity is closer than any known peers. More...
 
int GDS_NEIGHBOURS_init (void)
 Initialize neighbours subsystem. More...
 
void GDS_NEIGHBOURS_done (void)
 Shutdown neighbours subsystem. More...
 
struct GNUNET_PeerIdentityGDS_NEIGHBOURS_get_id (void)
 Get the ID of the local node. More...
 

Variables

struct GNUNET_HashCode my_identity_hash
 Hash of the identity of this peer. More...
 

Detailed Description

GNUnet DHT routing code.

Author
Christian Grothoff
Nathan Evans

Definition in file gnunet-service-dht_neighbours.h.

Function Documentation

◆ GDS_NEIGHBOURS_handle_put()

int GDS_NEIGHBOURS_handle_put ( enum GNUNET_BLOCK_Type  type,
enum GNUNET_DHT_RouteOption  options,
uint32_t  desired_replication_level,
struct GNUNET_TIME_Absolute  expiration_time,
uint32_t  hop_count,
struct GNUNET_CONTAINER_BloomFilter bf,
const struct GNUNET_HashCode key,
unsigned int  put_path_length,
struct GNUNET_PeerIdentity put_path,
const void *  data,
size_t  data_size 
)

Perform a PUT operation.

Forwards the given request to other peers. Does not store the data locally. Does not give the data to local clients. May do nothing if this is the only peer in the network (or if we are the closest peer in the network).

Parameters
typetype of the block
optionsrouting options
desired_replication_leveldesired replication level
expiration_timewhen does the content expire
hop_counthow many hops has this message traversed so far
bfBloom filter of peers this PUT has already traversed
keykey for the content
put_path_lengthnumber of entries in put_path
put_pathpeers this request has traversed so far (if tracked)
datapayload to store
data_sizenumber of bytes in data
Returns
GNUNET_OK if the request was forwarded, GNUNET_NO if not

Forwards the given request to other peers. Does not store the data locally. Does not give the data to local clients. May do nothing if this is the only peer in the network (or if we are the closest peer in the network).

Parameters
typetype of the block
optionsrouting options
desired_replication_leveldesired replication count
expiration_timewhen does the content expire
hop_counthow many hops has this message traversed so far
bfBloom filter of peers this PUT has already traversed
keykey for the content
put_path_lengthnumber of entries in put_path
put_pathpeers this request has traversed so far (if tracked)
datapayload to store
data_sizenumber of bytes in data
Returns
GNUNET_OK if the request was forwarded, GNUNET_NO if not

Definition at line 1239 of file gnunet-service-dht_neighbours.c.

References PeerPutMessage::bloomfilter, data_size, PeerPutMessage::desired_replication_level, DHT_BLOOM_SIZE, env, PeerPutMessage::expiration_time, GDS_stats, get_target_peers(), gettext_noop, GNUNET_assert, GNUNET_break, GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_CONTAINER_bloomfilter_get_raw_data(), GNUNET_CONTAINER_bloomfilter_test(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, GNUNET_MQ_get_length(), GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_hton(), GNUNET_YES, PeerPutMessage::hop_count, PeerInfo::id, PeerPutMessage::key, MAXIMUM_PENDING_PER_PEER, PeerInfo::mq, my_identity, my_identity_hash, PeerPutMessage::options, PeerInfo::phash, PeerPutMessage::put_path_length, and PeerPutMessage::type.

Referenced by handle_dht_local_put(), and handle_dht_p2p_put().

1250 {
1251  unsigned int target_count;
1252  unsigned int i;
1253  struct PeerInfo **targets;
1254  struct PeerInfo *target;
1255  size_t msize;
1256  struct GNUNET_MQ_Envelope *env;
1257  struct PeerPutMessage *ppm;
1258  struct GNUNET_PeerIdentity *pp;
1259  unsigned int skip_count;
1260 
1261  GNUNET_assert (NULL != bf);
1263  "Adding myself (%s) to PUT bloomfilter for %s\n",
1265  GNUNET_h2s (key));
1267  &my_identity_hash);
1269  gettext_noop ("# PUT requests routed"),
1270  1,
1271  GNUNET_NO);
1272  target_count
1273  = get_target_peers (key,
1274  bf,
1275  hop_count,
1276  desired_replication_level,
1277  &targets);
1278  if (0 == target_count)
1279  {
1281  "Routing PUT for %s terminates after %u hops at %s\n",
1282  GNUNET_h2s (key),
1283  (unsigned int) hop_count,
1284  GNUNET_i2s (&my_identity));
1285  return GNUNET_NO;
1286  }
1287  msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size;
1288  if (msize + sizeof (struct PeerPutMessage)
1290  {
1291  put_path_length = 0;
1292  msize = data_size;
1293  }
1294  if (msize + sizeof (struct PeerPutMessage)
1296  {
1297  GNUNET_break (0);
1298  GNUNET_free (targets);
1299  return GNUNET_NO;
1300  }
1302  gettext_noop ("# PUT messages queued for transmission"),
1303  target_count,
1304  GNUNET_NO);
1305  skip_count = 0;
1306  for (i = 0; i < target_count; i++)
1307  {
1308  target = targets[i];
1310  {
1311  /* skip */
1313  gettext_noop ("# P2P messages dropped due to full queue"),
1314  1,
1315  GNUNET_NO);
1316  skip_count++;
1317  continue;
1318  }
1320  "Routing PUT for %s after %u hops to %s\n",
1321  GNUNET_h2s (key),
1322  (unsigned int) hop_count,
1323  GNUNET_i2s (target->id));
1324  env = GNUNET_MQ_msg_extra (ppm,
1325  msize,
1327  ppm->options = htonl (options);
1328  ppm->type = htonl (type);
1329  ppm->hop_count = htonl (hop_count + 1);
1330  ppm->desired_replication_level = htonl (desired_replication_level);
1331  ppm->put_path_length = htonl (put_path_length);
1332  ppm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time);
1335  &target->phash));
1338  ppm->bloomfilter,
1339  DHT_BLOOM_SIZE));
1340  ppm->key = *key;
1341  pp = (struct GNUNET_PeerIdentity *) &ppm[1];
1342  GNUNET_memcpy (pp,
1343  put_path,
1344  sizeof (struct GNUNET_PeerIdentity) * put_path_length);
1345  GNUNET_memcpy (&pp[put_path_length],
1346  data,
1347  data_size);
1348  GNUNET_MQ_send (target->mq,
1349  env);
1350  }
1351  GNUNET_free (targets);
1352  return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO;
1353 }
char bloomfilter[128]
Bloomfilter (for peer identities) to stop circular routes.
struct GNUNET_STATISTICS_Handle * GDS_stats
Handle for the statistics service.
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
uint32_t put_path_length
Length of the PUT path that follows (if tracked).
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define MAXIMUM_PENDING_PER_PEER
Maximum allowed number of pending messages per peer.
#define DHT_BLOOM_SIZE
Size of the bloom filter the DHT uses to filter peers.
Definition: dht.h:34
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
struct GNUNET_HashCode phash
Hash of id.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE
What is the maximum size for encrypted messages? Note that this number imposes a clear limit on the m...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_HashCode my_identity_hash
Hash of the identity of this peer.
#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
struct GNUNET_HashCode key
The key we are storing under.
#define GNUNET_memcpy(dst, src, n)
int GNUNET_CONTAINER_bloomfilter_test(const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Test if an element is in the filter.
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
Definition: mq.c:335
uint32_t hop_count
Hop count.
uint32_t desired_replication_level
Replication level for this message.
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the content expire?
struct GNUNET_HashCode key
The key used in the DHT.
Entry for a peer in a bucket.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
int GNUNET_CONTAINER_bloomfilter_get_raw_data(const struct GNUNET_CONTAINER_BloomFilter *bf, char *data, size_t size)
Copy the raw data of this Bloom filter into the given data array.
uint32_t options
Processing options.
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
The identity of the host (wraps the signing key of the peer).
uint32_t type
Content type.
const struct GNUNET_PeerIdentity * id
What is the identity of the peer?
#define GNUNET_log(kind,...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
#define GNUNET_YES
Definition: gnunet_common.h:80
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_MQ_Handle * mq
Handle for sending messages to this peer.
static unsigned int get_target_peers(const struct GNUNET_HashCode *key, struct GNUNET_CONTAINER_BloomFilter *bloom, uint32_t hop_count, uint32_t target_replication, struct PeerInfo ***targets)
Compute the set of peers that the given request should be forwarded to.
uint32_t data
The data value.
#define GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
Peer is storing data in DHT.
static size_t data_size
Number of bytes in data.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:654
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GDS_NEIGHBOURS_handle_get()

int GDS_NEIGHBOURS_handle_get ( enum GNUNET_BLOCK_Type  type,
enum GNUNET_DHT_RouteOption  options,
uint32_t  desired_replication_level,
uint32_t  hop_count,
const struct GNUNET_HashCode key,
const void *  xquery,
size_t  xquery_size,
struct GNUNET_BLOCK_Group bg,
struct GNUNET_CONTAINER_BloomFilter peer_bf 
)

Perform a GET operation.

Forwards the given request to other peers. Does not lookup the key locally. May do nothing if this is the only peer in the network (or if we are the closest peer in the network).

Parameters
typetype of the block
optionsrouting options
desired_replication_leveldesired replication count
hop_counthow many hops did this request traverse so far?
keykey for the content
xqueryextended query
xquery_sizenumber of bytes in xquery
bgblock group to filter replies
peer_bffilter for peers not to select (again, updated)
Returns
GNUNET_OK if the request was forwarded, GNUNET_NO if not

Forwards the given request to other peers. Does not lookup the key locally. May do nothing if this is the only peer in the network (or if we are the closest peer in the network).

Parameters
typetype of the block
optionsrouting options
desired_replication_leveldesired replication count
hop_counthow many hops did this request traverse so far?
keykey for the content
xqueryextended query
xquery_sizenumber of bytes in xquery
bggroup to use for filtering replies
peer_bffilter for peers not to select (again)
Returns
GNUNET_OK if the request was forwarded, GNUNET_NO if not

Definition at line 1374 of file gnunet-service-dht_neighbours.c.

References PeerGetMessage::bf_mutator, PeerGetMessage::bloomfilter, PeerGetMessage::desired_replication_level, DHT_BLOOM_SIZE, env, GDS_stats, get_target_peers(), gettext_noop, GNUNET_assert, GNUNET_BLOCK_group_serialize(), GNUNET_break, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_CONTAINER_bloomfilter_get_raw_data(), GNUNET_CONTAINER_bloomfilter_test(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_free_non_null, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DHT_P2P_GET, GNUNET_MQ_get_length(), GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_YES, PeerGetMessage::hop_count, PeerInfo::id, PeerPutMessage::key, PeerGetMessage::key, MAXIMUM_PENDING_PER_PEER, PeerInfo::mq, my_identity, my_identity_hash, PeerGetMessage::options, PeerInfo::phash, PeerGetMessage::type, and PeerGetMessage::xquery_size.

Referenced by handle_dht_p2p_get(), send_find_peer_message(), and transmit_request().

1383 {
1384  unsigned int target_count;
1385  struct PeerInfo **targets;
1386  struct PeerInfo *target;
1387  struct GNUNET_MQ_Envelope *env;
1388  size_t msize;
1389  struct PeerGetMessage *pgm;
1390  char *xq;
1391  size_t reply_bf_size;
1392  void *reply_bf;
1393  unsigned int skip_count;
1394  uint32_t bf_nonce;
1395 
1396  GNUNET_assert (NULL != peer_bf);
1398  gettext_noop ("# GET requests routed"),
1399  1,
1400  GNUNET_NO);
1401  target_count = get_target_peers (key,
1402  peer_bf,
1403  hop_count,
1405  &targets);
1407  "Adding myself (%s) to GET bloomfilter for %s\n",
1409  GNUNET_h2s (key));
1411  &my_identity_hash);
1412  if (0 == target_count)
1413  {
1415  "Routing GET for %s terminates after %u hops at %s\n",
1416  GNUNET_h2s (key),
1417  (unsigned int) hop_count,
1418  GNUNET_i2s (&my_identity));
1419  return GNUNET_NO;
1420  }
1421  if (GNUNET_OK !=
1423  &bf_nonce,
1424  &reply_bf,
1425  &reply_bf_size))
1426  {
1427  reply_bf = NULL;
1428  reply_bf_size = 0;
1430  UINT32_MAX);
1431  }
1432  msize = xquery_size + reply_bf_size;
1433  if (msize + sizeof (struct PeerGetMessage) >= GNUNET_MAX_MESSAGE_SIZE)
1434  {
1435  GNUNET_break (0);
1436  GNUNET_free_non_null (reply_bf);
1437  GNUNET_free (targets);
1438  return GNUNET_NO;
1439  }
1441  gettext_noop ("# GET messages queued for transmission"),
1442  target_count,
1443  GNUNET_NO);
1444  /* forward request */
1445  skip_count = 0;
1446  for (unsigned int i = 0; i < target_count; i++)
1447  {
1448  target = targets[i];
1450  {
1451  /* skip */
1453  gettext_noop ("# P2P messages dropped due to full queue"),
1454  1, GNUNET_NO);
1455  skip_count++;
1456  continue;
1457  }
1459  "Routing GET for %s after %u hops to %s\n",
1460  GNUNET_h2s (key),
1461  (unsigned int) hop_count,
1462  GNUNET_i2s (target->id));
1463  env = GNUNET_MQ_msg_extra (pgm,
1464  msize,
1466  pgm->options = htonl (options);
1467  pgm->type = htonl (type);
1468  pgm->hop_count = htonl (hop_count + 1);
1470  pgm->xquery_size = htonl (xquery_size);
1471  pgm->bf_mutator = bf_nonce;
1474  &target->phash));
1477  pgm->bloomfilter,
1478  DHT_BLOOM_SIZE));
1479  pgm->key = *key;
1480  xq = (char *) &pgm[1];
1481  GNUNET_memcpy (xq,
1482  xquery,
1483  xquery_size);
1484  GNUNET_memcpy (&xq[xquery_size],
1485  reply_bf,
1486  reply_bf_size);
1487  GNUNET_MQ_send (target->mq,
1488  env);
1489  }
1490  GNUNET_free (targets);
1491  GNUNET_free_non_null (reply_bf);
1492  return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO;
1493 }
uint32_t type
Desired content type.
struct GNUNET_STATISTICS_Handle * GDS_stats
Handle for the statistics service.
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
uint32_t hop_count
Hop count.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define MAXIMUM_PENDING_PER_PEER
Maximum allowed number of pending messages per peer.
#define DHT_BLOOM_SIZE
Size of the bloom filter the DHT uses to filter peers.
Definition: dht.h:34
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
struct GNUNET_HashCode phash
Hash of id.
uint32_t options
Processing options.
struct GNUNET_HashCode key
The key we are looking for.
char bloomfilter[128]
Bloomfilter (for peer identities) to stop circular routes.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_HashCode my_identity_hash
Hash of the identity of this peer.
uint32_t desired_replication_level
Desired replication level for this request.
#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_memcpy(dst, src, n)
int GNUNET_CONTAINER_bloomfilter_test(const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Test if an element is in the filter.
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
Definition: mq.c:335
int GNUNET_BLOCK_group_serialize(struct GNUNET_BLOCK_Group *bg, uint32_t *nonce, void **raw_data, size_t *raw_data_size)
Serialize state of a block group.
Definition: block.c:181
#define GNUNET_MESSAGE_TYPE_DHT_P2P_GET
Peer tries to find data in DHT.
uint32_t bf_mutator
Bloomfilter mutator.
struct GNUNET_HashCode key
The key used in the DHT.
Entry for a peer in a bucket.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
int GNUNET_CONTAINER_bloomfilter_get_raw_data(const struct GNUNET_CONTAINER_BloomFilter *bf, char *data, size_t size)
Copy the raw data of this Bloom filter into the given data array.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
uint32_t xquery_size
Size of the extended query.
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
const struct GNUNET_PeerIdentity * id
What is the identity of the peer?
#define GNUNET_log(kind,...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
#define GNUNET_YES
Definition: gnunet_common.h:80
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_MQ_Handle * mq
Handle for sending messages to this peer.
static unsigned int get_target_peers(const struct GNUNET_HashCode *key, struct GNUNET_CONTAINER_BloomFilter *bloom, uint32_t hop_count, uint32_t target_replication, struct PeerInfo ***targets)
Compute the set of peers that the given request should be forwarded to.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GDS_NEIGHBOURS_handle_reply()

void GDS_NEIGHBOURS_handle_reply ( const struct GNUNET_PeerIdentity target,
enum GNUNET_BLOCK_Type  type,
struct GNUNET_TIME_Absolute  expiration_time,
const struct GNUNET_HashCode key,
unsigned int  put_path_length,
const struct GNUNET_PeerIdentity put_path,
unsigned int  get_path_length,
const struct GNUNET_PeerIdentity get_path,
const void *  data,
size_t  data_size 
)

Handle a reply (route to origin).

Only forwards the reply back to other peers waiting for it. Does not do local caching or forwarding to local clients.

Parameters
targetneighbour that should receive the block (if still connected)
typetype of the block
expiration_timewhen does the content expire
keykey for the content
put_path_lengthnumber of entries in put_path
put_pathpeers the original PUT traversed (if tracked)
get_path_lengthnumber of entries in put_path
get_pathpeers this reply has traversed so far (if tracked)
datapayload of the reply
data_sizenumber of bytes in data

Only forwards the reply back to the given peer. Does not do local caching or forwarding to local clients.

Parameters
targetneighbour that should receive the block (if still connected)
typetype of the block
expiration_timewhen does the content expire
keykey for the content
put_path_lengthnumber of entries in put_path
put_pathpeers the original PUT traversed (if tracked)
get_path_lengthnumber of entries in get_path
get_pathpeers this reply has traversed so far (if tracked)
datapayload of the reply
data_sizenumber of bytes in data

Definition at line 1513 of file gnunet-service-dht_neighbours.c.

References env, PeerResultMessage::expiration_time, GDS_stats, PeerResultMessage::get_path_length, gettext_noop, GNUNET_break, GNUNET_CONTAINER_multipeermap_get(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, GNUNET_MQ_get_length(), GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_hton(), PeerPutMessage::key, PeerResultMessage::key, MAXIMUM_PENDING_PER_PEER, PeerInfo::mq, pi, PeerPutMessage::put_path_length, PeerResultMessage::put_path_length, and PeerResultMessage::type.

Referenced by handle_find_peer(), handle_local_result(), and process().

1523 {
1524  struct PeerInfo *pi;
1525  struct GNUNET_MQ_Envelope *env;
1526  size_t msize;
1527  struct PeerResultMessage *prm;
1528  struct GNUNET_PeerIdentity *paths;
1529 
1530  msize = data_size + (get_path_length + put_path_length) *
1531  sizeof (struct GNUNET_PeerIdentity);
1532  if ((msize + sizeof (struct PeerResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) ||
1533  (get_path_length >
1534  GNUNET_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ||
1535  (put_path_length >
1536  GNUNET_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_PeerIdentity)) ||
1538  {
1539  GNUNET_break (0);
1540  return;
1541  }
1543  target);
1544  if (NULL == pi)
1545  {
1546  /* peer disconnected in the meantime, drop reply */
1548  "No matching peer for reply for key %s\n",
1549  GNUNET_h2s (key));
1550  return;
1551  }
1553  {
1554  /* skip */
1556  gettext_noop ("# P2P messages dropped due to full queue"),
1557  1,
1558  GNUNET_NO);
1560  "Peer queue full, ignoring reply for key %s\n",
1561  GNUNET_h2s (key));
1562  return;
1563  }
1564 
1566  "Forwarding reply for key %s to peer %s\n",
1567  GNUNET_h2s (key),
1568  GNUNET_i2s (target));
1570  gettext_noop
1571  ("# RESULT messages queued for transmission"), 1,
1572  GNUNET_NO);
1573  env = GNUNET_MQ_msg_extra (prm,
1574  msize,
1576  prm->type = htonl (type);
1577  prm->put_path_length = htonl (put_path_length);
1578  prm->get_path_length = htonl (get_path_length);
1579  prm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time);
1580  prm->key = *key;
1581  paths = (struct GNUNET_PeerIdentity *) &prm[1];
1582  GNUNET_memcpy (paths,
1583  put_path,
1584  put_path_length * sizeof (struct GNUNET_PeerIdentity));
1585  GNUNET_memcpy (&paths[put_path_length],
1586  get_path,
1587  get_path_length * sizeof (struct GNUNET_PeerIdentity));
1588  GNUNET_memcpy (&paths[put_path_length + get_path_length],
1589  data,
1590  data_size);
1591  GNUNET_MQ_send (pi->mq,
1592  env);
1593 }
uint32_t type
Content type.
struct GNUNET_STATISTICS_Handle * GDS_stats
Handle for the statistics service.
#define MAXIMUM_PENDING_PER_PEER
Maximum allowed number of pending messages per peer.
uint32_t put_path_length
Length of the PUT path that follows (if tracked).
uint32_t get_path_length
Length of the GET path that follows (if tracked).
#define GNUNET_NO
Definition: gnunet_common.h:81
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_PEERINFO_Handle * pi
Handle to peerinfo service.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#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_memcpy(dst, src, n)
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
Definition: mq.c:335
struct GNUNET_HashCode key
The key used in the DHT.
Entry for a peer in a bucket.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_CONTAINER_MultiPeerMap * all_connected_peers
Hash map of all CORE-connected peers, for easy removal from k_buckets on disconnect.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the content expire?
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,...)
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
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_MQ_Handle * mq
Handle for sending messages to this peer.
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
struct GNUNET_HashCode key
The key of the corresponding GET request.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:654
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT
Data is returned to peer from DHT.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GDS_am_closest_peer()

int GDS_am_closest_peer ( const struct GNUNET_HashCode key,
const struct GNUNET_CONTAINER_BloomFilter bloom 
)

Check whether my identity is closer than any known peers.

If a non-null bloomfilter is given, check if this is the closest peer that hasn't already been routed to.

Parameters
keyhash code to check closeness to
bloombloomfilter, exclude these entries from the decision
Returns
GNUNET_YES if node location is closest, GNUNET_NO otherwise.

Definition at line 953 of file gnunet-service-dht_neighbours.c.

References GNUNET_HashCode::bits, find_bucket(), GNUNET_assert, GNUNET_CONTAINER_bloomfilter_test(), GNUNET_CRYPTO_hash_matching_bits(), GNUNET_memcmp, GNUNET_NO, GNUNET_YES, PeerBucket::head, k_buckets, my_identity_hash, PeerInfo::next, and PeerInfo::phash.

Referenced by handle_dht_p2p_get(), and handle_dht_p2p_put().

955 {
956  int bits;
957  int other_bits;
958  int bucket_num;
959  struct PeerInfo *pos;
960 
961  if (0 == GNUNET_memcmp (&my_identity_hash,
962  key))
963  return GNUNET_YES;
964  bucket_num = find_bucket (key);
965  GNUNET_assert (bucket_num >= 0);
967  key);
968  pos = k_buckets[bucket_num].head;
969  while (NULL != pos)
970  {
971  if ( (NULL != bloom) &&
972  (GNUNET_YES ==
974  &pos->phash)) )
975  {
976  pos = pos->next;
977  continue; /* Skip already checked entries */
978  }
979  other_bits = GNUNET_CRYPTO_hash_matching_bits (&pos->phash,
980  key);
981  if (other_bits > bits)
982  return GNUNET_NO;
983  if (other_bits == bits) /* We match the same number of bits */
984  return GNUNET_YES;
985  pos = pos->next;
986  }
987  /* No peers closer, we are the closest! */
988  return GNUNET_YES;
989 }
static struct PeerBucket k_buckets[sizeof(struct GNUNET_HashCode) *8]
The buckets.
struct PeerInfo * next
Next peer entry (DLL)
unsigned int GNUNET_CRYPTO_hash_matching_bits(const struct GNUNET_HashCode *first, const struct GNUNET_HashCode *second)
Determine how many low order bits match in two struct GNUNET_HashCodes.
Definition: crypto_hash.c:256
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct PeerInfo * head
Head of DLL.
static int find_bucket(const struct GNUNET_HashCode *hc)
Find the optimal bucket for this key.
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GNUNET_HashCode phash
Hash of id.
struct GNUNET_HashCode my_identity_hash
Hash of the identity of this peer.
int GNUNET_CONTAINER_bloomfilter_test(const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Test if an element is in the filter.
Entry for a peer in a bucket.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GDS_NEIGHBOURS_init()

int GDS_NEIGHBOURS_init ( void  )

Initialize neighbours subsystem.

Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 2474 of file gnunet-service-dht_neighbours.c.

References bucket_size, cache_results, core_init(), disable_try_connect, GDS_cfg, getenv(), GNUNET_ATS_connectivity_init(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONTAINER_multipeermap_create(), GNUNET_CORE_connect(), GNUNET_MESSAGE_TYPE_DHT_P2P_GET, GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, handle_core_connect(), handle_core_disconnect(), and log_route_details_stderr.

Referenced by run().

2475 {
2476  struct GNUNET_MQ_MessageHandler core_handlers[] = {
2477  GNUNET_MQ_hd_var_size (dht_p2p_get,
2479  struct PeerGetMessage,
2480  NULL),
2481  GNUNET_MQ_hd_var_size (dht_p2p_put,
2483  struct PeerPutMessage,
2484  NULL),
2485  GNUNET_MQ_hd_var_size (dht_p2p_result,
2487  struct PeerResultMessage,
2488  NULL),
2490  };
2491  unsigned long long temp_config_num;
2492 
2495  "DHT",
2496  "DISABLE_TRY_CONNECT");
2497  if (GNUNET_OK ==
2499  "DHT",
2500  "bucket_size",
2501  &temp_config_num))
2502  bucket_size = (unsigned int) temp_config_num;
2505  "DHT",
2506  "CACHE_RESULTS");
2507 
2509  (NULL != getenv("GNUNET_DHT_ROUTE_DEBUG")) ? GNUNET_YES : GNUNET_NO;
2512  NULL,
2513  &core_init,
2516  core_handlers);
2517  if (NULL == core_api)
2518  return GNUNET_SYSERR;
2520  GNUNET_YES);
2522  GNUNET_NO);
2523  return GNUNET_OK;
2524 }
int GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
static int cache_results
Do we cache all results that we are routing in the local datacache?
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static void core_init(void *cls, const struct GNUNET_PeerIdentity *identity)
To be called on core init/fail.
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).
static int disable_try_connect
Option for testing that disables the &#39;connect&#39; function of the DHT.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
Message handler for a specific message type.
#define GNUNET_MESSAGE_TYPE_DHT_P2P_GET
Peer tries to find data in DHT.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
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:694
char * getenv()
static struct GNUNET_CONTAINER_MultiPeerMap * all_connected_peers
Hash map of all CORE-connected peers, for easy removal from k_buckets on disconnect.
static struct GNUNET_CORE_Handle * core_api
Handle to CORE.
struct GNUNET_ATS_ConnectivityHandle * GNUNET_ATS_connectivity_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the ATS connectivity suggestion client handle.
static struct GNUNET_ATS_ConnectivityHandle * ats_ch
Handle to ATS connectivity.
static void handle_core_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
Method called whenever a peer disconnects.
static unsigned int bucket_size
Maximum size for each bucket.
static struct GNUNET_CONTAINER_MultiPeerMap * all_desired_peers
Hash map of all peers we would like to be connected to.
#define GNUNET_YES
Definition: gnunet_common.h:80
static int log_route_details_stderr
Should routing details be logged to stderr (for debugging)?
const struct GNUNET_CONFIGURATION_Handle * GDS_cfg
Configuration we use.
int GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
#define GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
Peer is storing data in DHT.
static void * handle_core_connect(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Method called whenever a peer connects.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT
Data is returned to peer from DHT.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GDS_NEIGHBOURS_done()

void GDS_NEIGHBOURS_done ( void  )

Shutdown neighbours subsystem.

Definition at line 2531 of file gnunet-service-dht_neighbours.c.

References free_connect_info(), GNUNET_assert, GNUNET_ATS_connectivity_done(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_CONTAINER_multipeermap_size(), and GNUNET_CORE_disconnect().

Referenced by shutdown_task().

2532 {
2533  if (NULL == core_api)
2534  return;
2536  core_api = NULL;
2537  GNUNET_assert (0 ==
2540  all_connected_peers = NULL;
2543  NULL);
2545  all_desired_peers = NULL;
2547  ats_ch = NULL;
2548  GNUNET_assert (NULL == find_peer_task);
2549 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_SCHEDULER_Task * find_peer_task
Task that sends FIND PEER requests.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
static int free_connect_info(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Function called for all entries in all_desired_peers to clean up.
void GNUNET_CORE_disconnect(struct GNUNET_CORE_Handle *handle)
Disconnect from the core service.
Definition: core_api.c:732
static struct GNUNET_CONTAINER_MultiPeerMap * all_connected_peers
Hash map of all CORE-connected peers, for easy removal from k_buckets on disconnect.
static struct GNUNET_CORE_Handle * core_api
Handle to CORE.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static struct GNUNET_ATS_ConnectivityHandle * ats_ch
Handle to ATS connectivity.
static struct GNUNET_CONTAINER_MultiPeerMap * all_desired_peers
Hash map of all peers we would like to be connected to.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
void GNUNET_ATS_connectivity_done(struct GNUNET_ATS_ConnectivityHandle *ch)
Client is done with ATS connectivity management, release resources.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GDS_NEIGHBOURS_get_id()

struct GNUNET_PeerIdentity* GDS_NEIGHBOURS_get_id ( void  )

Get the ID of the local node.

Returns
identity of the local node

Definition at line 2558 of file gnunet-service-dht_neighbours.c.

References my_identity.

Referenced by handle_dht_local_get(), and handle_dht_local_put().

2559 {
2560  return &my_identity;
2561 }
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
Here is the caller graph for this function:

Variable Documentation

◆ my_identity_hash

struct GNUNET_HashCode my_identity_hash