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 1228 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().

1239 {
1240  unsigned int target_count;
1241  unsigned int i;
1242  struct PeerInfo **targets;
1243  struct PeerInfo *target;
1244  size_t msize;
1245  struct GNUNET_MQ_Envelope *env;
1246  struct PeerPutMessage *ppm;
1247  struct GNUNET_PeerIdentity *pp;
1248  unsigned int skip_count;
1249 
1250  GNUNET_assert(NULL != bf);
1252  "Adding myself (%s) to PUT bloomfilter for %s\n",
1254  GNUNET_h2s(key));
1256  &my_identity_hash);
1258  gettext_noop("# PUT requests routed"),
1259  1,
1260  GNUNET_NO);
1261  target_count
1262  = get_target_peers(key,
1263  bf,
1264  hop_count,
1265  desired_replication_level,
1266  &targets);
1267  if (0 == target_count)
1268  {
1270  "Routing PUT for %s terminates after %u hops at %s\n",
1271  GNUNET_h2s(key),
1272  (unsigned int)hop_count,
1274  return GNUNET_NO;
1275  }
1276  msize = put_path_length * sizeof(struct GNUNET_PeerIdentity) + data_size;
1277  if (msize + sizeof(struct PeerPutMessage)
1279  {
1280  put_path_length = 0;
1281  msize = data_size;
1282  }
1283  if (msize + sizeof(struct PeerPutMessage)
1285  {
1286  GNUNET_break(0);
1287  GNUNET_free(targets);
1288  return GNUNET_NO;
1289  }
1291  gettext_noop("# PUT messages queued for transmission"),
1292  target_count,
1293  GNUNET_NO);
1294  skip_count = 0;
1295  for (i = 0; i < target_count; i++)
1296  {
1297  target = targets[i];
1299  {
1300  /* skip */
1302  gettext_noop("# P2P messages dropped due to full queue"),
1303  1,
1304  GNUNET_NO);
1305  skip_count++;
1306  continue;
1307  }
1309  "Routing PUT for %s after %u hops to %s\n",
1310  GNUNET_h2s(key),
1311  (unsigned int)hop_count,
1312  GNUNET_i2s(target->id));
1313  env = GNUNET_MQ_msg_extra(ppm,
1314  msize,
1316  ppm->options = htonl(options);
1317  ppm->type = htonl(type);
1318  ppm->hop_count = htonl(hop_count + 1);
1319  ppm->desired_replication_level = htonl(desired_replication_level);
1320  ppm->put_path_length = htonl(put_path_length);
1321  ppm->expiration_time = GNUNET_TIME_absolute_hton(expiration_time);
1324  &target->phash));
1327  ppm->bloomfilter,
1328  DHT_BLOOM_SIZE));
1329  ppm->key = *key;
1330  pp = (struct GNUNET_PeerIdentity *)&ppm[1];
1331  GNUNET_memcpy(pp,
1332  put_path,
1333  sizeof(struct GNUNET_PeerIdentity) * put_path_length);
1334  GNUNET_memcpy(&pp[put_path_length],
1335  data,
1336  data_size);
1337  GNUNET_MQ_send(target->mq,
1338  env);
1339  }
1340  GNUNET_free(targets);
1341  return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO;
1342 }
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_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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.
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:333
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:77
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_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:655
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 1363 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().

1372 {
1373  unsigned int target_count;
1374  struct PeerInfo **targets;
1375  struct PeerInfo *target;
1376  struct GNUNET_MQ_Envelope *env;
1377  size_t msize;
1378  struct PeerGetMessage *pgm;
1379  char *xq;
1380  size_t reply_bf_size;
1381  void *reply_bf;
1382  unsigned int skip_count;
1383  uint32_t bf_nonce;
1384 
1385  GNUNET_assert(NULL != peer_bf);
1387  gettext_noop("# GET requests routed"),
1388  1,
1389  GNUNET_NO);
1390  target_count = get_target_peers(key,
1391  peer_bf,
1392  hop_count,
1394  &targets);
1396  "Adding myself (%s) to GET bloomfilter for %s\n",
1398  GNUNET_h2s(key));
1400  &my_identity_hash);
1401  if (0 == target_count)
1402  {
1404  "Routing GET for %s terminates after %u hops at %s\n",
1405  GNUNET_h2s(key),
1406  (unsigned int)hop_count,
1408  return GNUNET_NO;
1409  }
1410  if (GNUNET_OK !=
1412  &bf_nonce,
1413  &reply_bf,
1414  &reply_bf_size))
1415  {
1416  reply_bf = NULL;
1417  reply_bf_size = 0;
1419  UINT32_MAX);
1420  }
1421  msize = xquery_size + reply_bf_size;
1422  if (msize + sizeof(struct PeerGetMessage) >= GNUNET_MAX_MESSAGE_SIZE)
1423  {
1424  GNUNET_break(0);
1425  GNUNET_free_non_null(reply_bf);
1426  GNUNET_free(targets);
1427  return GNUNET_NO;
1428  }
1430  gettext_noop("# GET messages queued for transmission"),
1431  target_count,
1432  GNUNET_NO);
1433  /* forward request */
1434  skip_count = 0;
1435  for (unsigned int i = 0; i < target_count; i++)
1436  {
1437  target = targets[i];
1439  {
1440  /* skip */
1442  gettext_noop("# P2P messages dropped due to full queue"),
1443  1, GNUNET_NO);
1444  skip_count++;
1445  continue;
1446  }
1448  "Routing GET for %s after %u hops to %s\n",
1449  GNUNET_h2s(key),
1450  (unsigned int)hop_count,
1451  GNUNET_i2s(target->id));
1452  env = GNUNET_MQ_msg_extra(pgm,
1453  msize,
1455  pgm->options = htonl(options);
1456  pgm->type = htonl(type);
1457  pgm->hop_count = htonl(hop_count + 1);
1459  pgm->xquery_size = htonl(xquery_size);
1460  pgm->bf_mutator = bf_nonce;
1463  &target->phash));
1466  pgm->bloomfilter,
1467  DHT_BLOOM_SIZE));
1468  pgm->key = *key;
1469  xq = (char *)&pgm[1];
1470  GNUNET_memcpy(xq,
1471  xquery,
1472  xquery_size);
1474  reply_bf,
1475  reply_bf_size);
1476  GNUNET_MQ_send(target->mq,
1477  env);
1478  }
1479  GNUNET_free(targets);
1480  GNUNET_free_non_null(reply_bf);
1481  return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO;
1482 }
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_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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
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:333
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:179
#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:77
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_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 1502 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().

1512 {
1513  struct PeerInfo *pi;
1514  struct GNUNET_MQ_Envelope *env;
1515  size_t msize;
1516  struct PeerResultMessage *prm;
1517  struct GNUNET_PeerIdentity *paths;
1518 
1519  msize = data_size + (get_path_length + put_path_length) *
1520  sizeof(struct GNUNET_PeerIdentity);
1521  if ((msize + sizeof(struct PeerResultMessage) >= GNUNET_MAX_MESSAGE_SIZE) ||
1522  (get_path_length >
1523  GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) ||
1524  (put_path_length >
1525  GNUNET_MAX_MESSAGE_SIZE / sizeof(struct GNUNET_PeerIdentity)) ||
1527  {
1528  GNUNET_break(0);
1529  return;
1530  }
1532  target);
1533  if (NULL == pi)
1534  {
1535  /* peer disconnected in the meantime, drop reply */
1537  "No matching peer for reply for key %s\n",
1538  GNUNET_h2s(key));
1539  return;
1540  }
1542  {
1543  /* skip */
1545  gettext_noop("# P2P messages dropped due to full queue"),
1546  1,
1547  GNUNET_NO);
1549  "Peer queue full, ignoring reply for key %s\n",
1550  GNUNET_h2s(key));
1551  return;
1552  }
1553 
1555  "Forwarding reply for key %s to peer %s\n",
1556  GNUNET_h2s(key),
1557  GNUNET_i2s(target));
1559  gettext_noop
1560  ("# RESULT messages queued for transmission"), 1,
1561  GNUNET_NO);
1562  env = GNUNET_MQ_msg_extra(prm,
1563  msize,
1565  prm->type = htonl(type);
1566  prm->put_path_length = htonl(put_path_length);
1567  prm->get_path_length = htonl(get_path_length);
1568  prm->expiration_time = GNUNET_TIME_absolute_hton(expiration_time);
1569  prm->key = *key;
1570  paths = (struct GNUNET_PeerIdentity *)&prm[1];
1571  GNUNET_memcpy(paths,
1572  put_path,
1573  put_path_length * sizeof(struct GNUNET_PeerIdentity));
1574  GNUNET_memcpy(&paths[put_path_length],
1575  get_path,
1576  get_path_length * sizeof(struct GNUNET_PeerIdentity));
1577  GNUNET_memcpy(&paths[put_path_length + get_path_length],
1578  data,
1579  data_size);
1580  GNUNET_MQ_send(pi->mq,
1581  env);
1582 }
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).
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint32_t get_path_length
Length of the GET path that follows (if tracked).
#define GNUNET_NO
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).
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
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
Definition: mq.c:333
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:351
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:655
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 942 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().

944 {
945  int bits;
946  int other_bits;
947  int bucket_num;
948  struct PeerInfo *pos;
949 
951  key))
952  return GNUNET_YES;
953  bucket_num = find_bucket(key);
954  GNUNET_assert(bucket_num >= 0);
956  key);
957  pos = k_buckets[bucket_num].head;
958  while (NULL != pos)
959  {
960  if ((NULL != bloom) &&
961  (GNUNET_YES ==
963  &pos->phash)))
964  {
965  pos = pos->next;
966  continue; /* Skip already checked entries */
967  }
968  other_bits = GNUNET_CRYPTO_hash_matching_bits(&pos->phash,
969  key);
970  if (other_bits > bits)
971  return GNUNET_NO;
972  if (other_bits == bits) /* We match the same number of bits */
973  return GNUNET_YES;
974  pos = pos->next;
975  }
976  /* No peers closer, we are the closest! */
977  return GNUNET_YES;
978 }
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:78
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:77
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 2466 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().

2467 {
2468  struct GNUNET_MQ_MessageHandler core_handlers[] = {
2469  GNUNET_MQ_hd_var_size(dht_p2p_get,
2471  struct PeerGetMessage,
2472  NULL),
2473  GNUNET_MQ_hd_var_size(dht_p2p_put,
2475  struct PeerPutMessage,
2476  NULL),
2477  GNUNET_MQ_hd_var_size(dht_p2p_result,
2479  struct PeerResultMessage,
2480  NULL),
2482  };
2483  unsigned long long temp_config_num;
2484 
2487  "DHT",
2488  "DISABLE_TRY_CONNECT");
2489  if (GNUNET_OK ==
2491  "DHT",
2492  "bucket_size",
2493  &temp_config_num))
2494  bucket_size = (unsigned int)temp_config_num;
2497  "DHT",
2498  "CACHE_RESULTS");
2499 
2501  (NULL != getenv("GNUNET_DHT_ROUTE_DEBUG")) ? GNUNET_YES : GNUNET_NO;
2504  NULL,
2505  &core_init,
2508  core_handlers);
2509  if (NULL == core_api)
2510  return GNUNET_SYSERR;
2512  GNUNET_YES);
2514  GNUNET_NO);
2515  return GNUNET_OK;
2516 }
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:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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:76
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:690
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:77
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 2523 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().

2524 {
2525  if (NULL == core_api)
2526  return;
2528  core_api = NULL;
2529  GNUNET_assert(0 ==
2532  all_connected_peers = NULL;
2535  NULL);
2537  all_desired_peers = NULL;
2539  ats_ch = NULL;
2540  GNUNET_assert(NULL == find_peer_task);
2541 }
#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:728
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 2550 of file gnunet-service-dht_neighbours.c.

References my_identity.

Referenced by handle_dht_local_get(), and handle_dht_local_put().

2551 {
2552  return &my_identity;
2553 }
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