GNUnet 0.28.1-dev.4-47-g3e168ca2d
 
Loading...
Searching...
No Matches
gnunet-service-dht_neighbours.h File Reference

GNUnet DHT routing code. More...

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.

Typedefs

typedef void(* GDS_PutOperationCallback) (void *cls, enum GNUNET_GenericReturnValue forwarded)
 

Functions

struct PeerInfoGDS_NEIGHBOURS_lookup_peer (const struct GNUNET_PeerIdentity *target)
 Lookup peer by peer's identity.
 
void GDS_NEIGHBOURS_handle_put (const struct GNUNET_DATACACHE_Block *bd, uint16_t desired_replication_level, uint16_t hop_count, struct GNUNET_CONTAINER_BloomFilter *bf, GDS_PutOperationCallback cb, void *cb_cls)
 Perform a PUT operation.
 
enum GNUNET_GenericReturnValue GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type, enum GNUNET_DHT_RouteOption options, uint16_t desired_replication_level, uint16_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.
 
void GDS_NEIGHBOURS_handle_reply (struct PeerInfo *pi, const struct GNUNET_DATACACHE_Block *bd, const struct GNUNET_HashCode *query_hash, unsigned int get_path_length, const struct GNUNET_DHT_PathElement *get_path, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
 Handle a reply (route to origin).
 
enum GNUNET_GenericReturnValue 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.
 
void GDS_try_connect (void *cls, const struct GNUNET_PeerIdentity *pid, const char *uri)
 Callback function used to extract URIs from a builder.
 
void GDS_u_connect (void *cls, struct GNUNET_DHTU_Target *target, const struct GNUNET_PeerIdentity *pid, void **ctx)
 Function to call when we connect to a peer and can henceforth transmit to that peer.
 
void GDS_u_disconnect (void *ctx)
 Function to call when we disconnected from a peer and can henceforth cannot transmit to that peer anymore.
 
void GDS_u_receive (void *cls, void **tctx, void **sctx, const void *message, size_t message_size)
 Function to call when we receive a message.
 
void GDS_NEIGHBOURS_broadcast (const struct GNUNET_MessageHeader *msg)
 Send msg to all peers in our buckets.
 
enum GNUNET_GenericReturnValue GDS_NEIGHBOURS_init (void)
 Initialize neighbours subsystem.
 
void GDS_NEIGHBOURS_done (void)
 Shutdown neighbours subsystem.
 
const struct GNUNET_PeerIdentityGDS_NEIGHBOURS_get_id (void)
 Get the ID of the local node.
 

Detailed Description

GNUnet DHT routing code.

Author
Christian Grothoff
Nathan Evans

Definition in file gnunet-service-dht_neighbours.h.

Typedef Documentation

◆ GDS_PutOperationCallback

typedef void(* GDS_PutOperationCallback) (void *cls, enum GNUNET_GenericReturnValue forwarded)

Definition at line 40 of file gnunet-service-dht_neighbours.h.

Function Documentation

◆ GDS_NEIGHBOURS_lookup_peer()

struct PeerInfo * GDS_NEIGHBOURS_lookup_peer ( const struct GNUNET_PeerIdentity target)

Lookup peer by peer's identity.

Parameters
targetpeer to look up
Returns
NULL if we are not connected to target

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

1593{
1595 target);
1596}
static struct GNUNET_CONTAINER_MultiPeerMap * all_connected_peers
Hash map of all CORE-connected peers, for easy removal from k_buckets on disconnect.
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.

References all_connected_peers, and GNUNET_CONTAINER_multipeermap_get().

Referenced by process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GDS_NEIGHBOURS_handle_put()

void GDS_NEIGHBOURS_handle_put ( const struct GNUNET_DATACACHE_Block bd,
uint16_t  desired_replication_level,
uint16_t  hop_count,
struct GNUNET_CONTAINER_BloomFilter bf,
GDS_PutOperationCallback  cb,
void *  cb_cls 
)

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
bddata about the block
desired_replication_leveldesired replication level
hop_counthow many hops has this message traversed so far
bfBloom filter of peers this PUT has already traversed
Returns
GNUNET_OK if the request was forwarded, GNUNET_NO if not

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

1355{
1356 const struct GNUNET_PeerIdentity *my_identity;
1357 const struct GNUNET_HashCode *my_identity_hash;
1358 struct GDS_RoutingPutCallbackData gds_routing;
1359 size_t msize;
1360 enum GNUNET_DHT_RouteOption ro = bd->ro;
1361 unsigned int put_path_length = bd->put_path_length;
1362 const struct GNUNET_DHT_PathElement *put_path = bd->put_path;
1363 bool truncated = (0 != (bd->ro & GNUNET_DHT_RO_TRUNCATED));
1364 const struct GNUNET_PeerIdentity *trunc_peer
1365 = truncated
1366 ? &bd->trunc_peer
1367 : NULL;
1368 struct GNUNET_PeerIdentity trunc_peer_out;
1370
1372 my_identity_hash = GNUNET_PILS_get_identity_hash (GDS_pils);
1373 GNUNET_assert (NULL != my_identity);
1374
1377 bd->ro, &ro,
1378 bd->expiration_time,
1379 bd->data, bd->data_size,
1380 put_path, put_path_length,
1381 &put_path_length,
1382 trunc_peer,
1383 &trunc_peer_out,
1384 &truncated);
1385 if (truncated)
1386 trunc_peer = &trunc_peer_out;
1387 /* Path may have been truncated by the call above */
1389 "Adding myself (%s) to PUT bloomfilter for %s with RO(%s/%s)\n",
1391 GNUNET_h2s (&bd->key),
1392 (bd->ro & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE) ? "x" : "-",
1393 (bd->ro & GNUNET_DHT_RO_RECORD_ROUTE) ? "R" : "-");
1394
1395 /* if we got a HELLO, consider it for our own routing table */
1396 hello_check (bd);
1397 GNUNET_assert ((NULL != bf) && (NULL != my_identity_hash));
1398 GNUNET_CONTAINER_bloomfilter_add (bf, my_identity_hash);
1400 "# PUT requests routed",
1401 1,
1402 GNUNET_NO);
1403 if (GNUNET_OK != ret)
1404 {
1405 if (cb)
1406 cb (cb_cls, ret);
1407 return;
1408 }
1409 gds_routing.target_count
1410 = get_target_peers (&bd->key,
1411 bf,
1412 hop_count,
1413 desired_replication_level,
1414 &(gds_routing.targets));
1415 if (0 == gds_routing.target_count)
1416 {
1418 "Routing PUT for %s terminates after %u hops at %s\n",
1419 GNUNET_h2s (&bd->key),
1420 (unsigned int) hop_count,
1422 if (cb)
1423 cb (cb_cls, GNUNET_NO);
1424 if (gds_routing.targets)
1425 GNUNET_free (gds_routing.targets);
1426 return;
1427 }
1428 GNUNET_memcpy (&(gds_routing.key), &(bd->key),
1429 sizeof (gds_routing.key));
1430 gds_routing.hop_count = hop_count;
1431 /* targets were added to @a bf by get_target_peers() */
1432
1433 gds_routing.queued = GNUNET_new (unsigned int);
1434 *(gds_routing.queued) = 0;
1435 gds_routing.sent = GNUNET_new (bool);
1436 *(gds_routing.sent) = false;
1437
1438 gds_routing.cb = cb;
1439 gds_routing.cb_cls = cb_cls;
1440
1441 for (unsigned int i = 0; i < gds_routing.target_count; i++)
1442 {
1443 struct PeerInfo *target = gds_routing.targets[i];
1444 struct PeerPutMessage *ppm;
1445 char buf[msize] GNUNET_ALIGN;
1446
1447 gds_routing.index = i;
1448
1449 ppm = (struct PeerPutMessage *) buf;
1450 GDS_helper_make_put_message (ppm, msize,
1452 &target->id,
1453 &target->phash,
1454 bf,
1455 &bd->key,
1456 ro,
1457 bd->type,
1458 bd->expiration_time,
1459 bd->data, bd->data_size,
1460 put_path, put_path_length,
1461 hop_count,
1463 trunc_peer,
1465 sizeof (gds_routing),
1466 &gds_routing);
1467 }
1468}
bool GDS_helper_make_put_message(struct PeerPutMessage *ppm, size_t msize, const struct GNUNET_CRYPTO_EddsaPrivateKey *sk, const struct GNUNET_PeerIdentity *target, const struct GNUNET_HashCode *target_hash, const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *block_key, enum GNUNET_DHT_RouteOption ro, enum GNUNET_BLOCK_Type block_type, struct GNUNET_TIME_Absolute block_expiration_time, const uint8_t *block_data, size_t block_data_len, const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_len, size_t hop_count, uint32_t desired_replication_level, const struct GNUNET_PeerIdentity *trunc_peer, GDS_HelperMsgCallback cb, size_t cb_data_size, void *cb_data)
Definition dht_helper.c:326
enum GNUNET_GenericReturnValue GDS_helper_put_message_get_size(size_t *msize_out, const struct GNUNET_PeerIdentity *my_identity, enum GNUNET_DHT_RouteOption ro_in, enum GNUNET_DHT_RouteOption *ro_out, struct GNUNET_TIME_Absolute block_expiration_time, const uint8_t *block_data, size_t block_data_len, const struct GNUNET_DHT_PathElement *put_path_in, unsigned int put_path_len_in, unsigned int *put_path_len_out, const struct GNUNET_PeerIdentity *trunc_peer, struct GNUNET_PeerIdentity *trunc_peer_out, bool *truncated)
Definition dht_helper.c:96
struct GNUNET_PILS_Handle * GDS_pils
Handle for the pils service.
static int ret
Final status code.
Definition gnunet-arm.c:93
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
struct GNUNET_STATISTICS_Handle * GDS_stats
Handle for the statistics service.
static bool cb_routing_put_message(void *cls, size_t msize, struct PeerPutMessage *ppm)
static unsigned int get_target_peers(const struct GNUNET_HashCode *key, struct GNUNET_CONTAINER_BloomFilter *bloom, uint16_t hop_count, uint16_t target_replication, struct PeerInfo ***targets)
Compute the set of peers that the given request should be forwarded to.
static void hello_check(const struct GNUNET_DATACACHE_Block *bd)
If we got a HELLO, consider it for our own routing table.
const struct GNUNET_HashCode * GNUNET_PILS_get_identity_hash(const struct GNUNET_PILS_Handle *handle)
Return the hash of the current peer identity from a given handle.
Definition pils_api.c:884
const struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_PILS_get_private_key(const struct GNUNET_PILS_Handle *handle)
Return the private key of the current peer identity.
Definition pils_api.c:943
const struct GNUNET_PeerIdentity * GNUNET_PILS_get_identity(const struct GNUNET_PILS_Handle *handle)
Return the current peer identity of a given handle.
Definition pils_api.c:875
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
GNUNET_DHT_RouteOption
Options for routing.
@ GNUNET_DHT_RO_TRUNCATED
Flag set if the path was truncated.
@ GNUNET_DHT_RO_RECORD_ROUTE
We should keep track of the route that the message took in the P2P network.
@ GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE
Each peer along the way should process the request (otherwise only peers locally closest to the key w...
#define GNUNET_log(kind,...)
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_NO
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
const struct GNUNET_DHT_PathElement * put_path
PUT path taken by the block, array of peer identities.
enum GNUNET_BLOCK_Type type
Type of the block.
const void * data
Actual block data.
enum GNUNET_DHT_RouteOption ro
Options for routing for the block.
struct GNUNET_PeerIdentity trunc_peer
If the path was truncated, this is the peer ID at which the path was truncated.
struct GNUNET_HashCode key
Key of the block.
size_t data_size
Number of bytes in data.
unsigned int put_path_length
Length of the put_path array.
struct GNUNET_TIME_Absolute expiration_time
When does the block expire?
A (signed) path tracking a block's flow through the DHT is represented by an array of path elements,...
A 512-bit hashcode.
The identity of the host (wraps the signing key of the peer).
Entry for a peer in a bucket.
struct GNUNET_PeerIdentity id
What is the identity of the peer?
struct GNUNET_HashCode phash
Hash of id.
P2P PUT message.
Definition dht.h:429
uint16_t desired_replication_level
Replication level for this message.
Definition dht.h:453
uint16_t hop_count
Hop count.
Definition dht.h:448
uint16_t put_path_length
Length of the PUT path that follows (if tracked).
Definition dht.h:458

References GDS_RoutingPutCallbackData::cb, GDS_RoutingPutCallbackData::cb_cls, cb_routing_put_message(), GNUNET_DATACACHE_Block::data, GNUNET_DATACACHE_Block::data_size, PeerPutMessage::desired_replication_level, GNUNET_DATACACHE_Block::expiration_time, GDS_helper_make_put_message(), GDS_helper_put_message_get_size(), GDS_pils, GDS_stats, get_target_peers(), GNUNET_ALIGN, GNUNET_assert, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_DHT_RO_TRUNCATED, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_memcpy, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_PILS_get_identity(), GNUNET_PILS_get_identity_hash(), GNUNET_PILS_get_private_key(), GNUNET_STATISTICS_update(), hello_check(), PeerPutMessage::hop_count, GDS_RoutingPutCallbackData::hop_count, PeerInfo::id, GDS_RoutingPutCallbackData::index, GNUNET_DATACACHE_Block::key, GDS_RoutingPutCallbackData::key, my_identity, PeerInfo::phash, GNUNET_DATACACHE_Block::put_path, GNUNET_DATACACHE_Block::put_path_length, PeerPutMessage::put_path_length, GDS_RoutingPutCallbackData::queued, ret, GNUNET_DATACACHE_Block::ro, GDS_RoutingPutCallbackData::sent, GDS_RoutingPutCallbackData::target_count, GDS_RoutingPutCallbackData::targets, GNUNET_DATACACHE_Block::trunc_peer, and GNUNET_DATACACHE_Block::type.

Referenced by handle_dht_p2p_put(), and route_pending_put().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GDS_NEIGHBOURS_handle_get()

enum GNUNET_GenericReturnValue GDS_NEIGHBOURS_handle_get ( enum GNUNET_BLOCK_Type  type,
enum GNUNET_DHT_RouteOption  options,
uint16_t  desired_replication_level,
uint16_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

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

1481{
1482 const struct GNUNET_PeerIdentity *my_identity;
1483 const struct GNUNET_HashCode *my_identity_hash;
1484 unsigned int target_count;
1485 struct PeerInfo **targets;
1486 size_t msize;
1487 size_t result_filter_size;
1488 void *result_filter;
1489 bool sent = false;
1490
1492 my_identity_hash = GNUNET_PILS_get_identity_hash (GDS_pils);
1493
1494 if (NULL == my_identity_hash)
1495 return GNUNET_NO;
1496
1497 GNUNET_assert (NULL != peer_bf);
1499 "# GET requests routed",
1500 1,
1501 GNUNET_NO);
1502 target_count = get_target_peers (key,
1503 peer_bf,
1504 hop_count,
1505 desired_replication_level,
1506 &targets);
1508 "Adding myself (%s) to GET bloomfilter for %s with RO(%s/%s)\n",
1510 GNUNET_h2s (key),
1512 (options & GNUNET_DHT_RO_RECORD_ROUTE) ? "R" : "-");
1513 GNUNET_assert (NULL != my_identity_hash);
1514 GNUNET_CONTAINER_bloomfilter_add (peer_bf, my_identity_hash);
1515 if (0 == target_count)
1516 {
1518 "Routing GET for %s terminates after %u hops at %s\n",
1519 GNUNET_h2s (key),
1520 (unsigned int) hop_count,
1522 return GNUNET_NO;
1523 }
1524 if (GNUNET_OK !=
1526 &result_filter,
1527 &result_filter_size))
1528 {
1529 result_filter = NULL;
1530 result_filter_size = 0;
1531 }
1532 msize = xquery_size + result_filter_size;
1533 if (msize + sizeof(struct PeerGetMessage) >= GNUNET_MAX_MESSAGE_SIZE)
1534 {
1535 GNUNET_break (0);
1536 GNUNET_free (result_filter);
1537 GNUNET_free (targets);
1538 return GNUNET_NO;
1539 }
1540 /* targets were added to @a peer_bf by get_target_peers() */
1541 /* forward request */
1542 for (unsigned int i = 0; i < target_count; i++)
1543 {
1544 struct PeerInfo *target = targets[i];
1545 struct PeerGetMessage *pgm;
1546 char buf[sizeof (*pgm) + msize] GNUNET_ALIGN;
1547 char *rf;
1548
1550 "Routing GET for %s after %u hops to %s\n",
1551 GNUNET_h2s (key),
1552 (unsigned int) hop_count,
1553 GNUNET_i2s (&target->id));
1554 pgm = (struct PeerGetMessage *) buf;
1556 pgm->header.size = htons (sizeof (buf));
1557 pgm->type = htonl (type);
1558 pgm->options = htons (options);
1559 pgm->hop_count = htons (hop_count + 1);
1561 pgm->result_filter_size = htons ((uint16_t) result_filter_size);
1564 pgm->bloomfilter,
1566 pgm->key = *key;
1567 rf = (char *) &pgm[1];
1568 GNUNET_memcpy (rf,
1569 result_filter,
1572 xquery,
1573 xquery_size);
1574 if (do_send (target,
1575 &pgm->header))
1576 sent = true;
1577 }
1579 "# GET messages queued for transmission",
1580 target_count,
1581 GNUNET_NO);
1582 GNUNET_free (targets);
1583 GNUNET_free (result_filter);
1584 /* Having picked a target is not the same as having sent to one: if
1585 every underlay dropped the message, the request was not routed and
1586 must go on the fast retry, not on the regular back-off. */
1587 return sent ? GNUNET_OK : GNUNET_NO;
1588}
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
#define DHT_BLOOM_SIZE
Size of the bloom filter the DHT uses to filter peers.
Definition dht.h:34
struct GNUNET_HashCode key
The key used in the DHT.
static uint32_t type
Type string converted to DNS type value.
static bool do_send(struct PeerInfo *pi, const struct GNUNET_MessageHeader *msg)
Send msg to pi.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
enum GNUNET_GenericReturnValue GNUNET_BLOCK_group_serialize(struct GNUNET_BLOCK_Group *bg, void **raw_data, size_t *raw_data_size)
Serialize state of a block group.
Definition block.c:177
enum GNUNET_GenericReturnValue 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.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_MESSAGE_TYPE_DHT_P2P_GET
Peer tries to find data in DHT.
uint16_t result_filter_size
Size of the result filter.
char bloomfilter[128]
Bloomfilter (for peer identities) to stop circular routes.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_DHT_P2P_GET.
uint16_t desired_replication_level
Desired replication level for this request.
uint16_t options
Processing options.
struct GNUNET_HashCode key
The key we are looking for.
uint32_t type
Desired content type.

References PeerGetMessage::bloomfilter, PeerGetMessage::desired_replication_level, DHT_BLOOM_SIZE, do_send(), GDS_pils, GDS_stats, get_target_peers(), GNUNET_ALIGN, GNUNET_assert, GNUNET_BLOCK_group_serialize(), GNUNET_break, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_CONTAINER_bloomfilter_get_raw_data(), GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DHT_P2P_GET, GNUNET_NO, GNUNET_OK, GNUNET_PILS_get_identity(), GNUNET_PILS_get_identity_hash(), GNUNET_STATISTICS_update(), PeerGetMessage::header, PeerGetMessage::hop_count, PeerInfo::id, key, PeerGetMessage::key, my_identity, options, PeerGetMessage::options, PeerGetMessage::result_filter_size, GNUNET_MessageHeader::size, type, GNUNET_MessageHeader::type, and PeerGetMessage::type.

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

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 ( struct PeerInfo pi,
const struct GNUNET_DATACACHE_Block bd,
const struct GNUNET_HashCode query_hash,
unsigned int  get_path_length,
const struct GNUNET_DHT_PathElement get_path,
GNUNET_SCHEDULER_TaskCallback  cb,
void *  cb_cls 
)

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
pineighbour that should receive the block
bddetails about the reply
query_hashquery that was used for the request
get_path_lengthnumber of entries in put_path
get_pathpeers this reply has traversed so far (if tracked)
Returns
true on success

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

1720{
1721 struct GNUNET_DHT_PathElement *paths;
1722 size_t msize;
1723 unsigned int ppl = bd->put_path_length;
1724 const struct GNUNET_DHT_PathElement *put_path = bd->put_path;
1725 enum GNUNET_DHT_RouteOption ro = bd->ro;
1726 bool truncated = (0 != (ro & GNUNET_DHT_RO_TRUNCATED));
1727 const struct GNUNET_PeerIdentity *trunc_peer
1728 = truncated
1729 ? &bd->trunc_peer
1730 : NULL;
1731 bool tracking = (0 != (ro & GNUNET_DHT_RO_RECORD_ROUTE));
1732#if SANITY_CHECKS > 1
1733 const struct GNUNET_PeerIdentity *my_identity;
1734 unsigned int failure_offset;
1735
1737 GNUNET_assert (NULL != my_identity);
1738
1739 failure_offset
1741 bd->data_size,
1742 bd->expiration_time,
1743 trunc_peer,
1744 put_path,
1745 ppl,
1746 get_path,
1747 get_path_length,
1748 my_identity);
1749 if (0 != failure_offset)
1750 {
1751 GNUNET_assert (failure_offset <= ppl + get_path_length);
1752 GNUNET_break_op (0);
1753 if (failure_offset < ppl)
1754 {
1755 trunc_peer = &put_path[failure_offset - 1].pred;
1756 put_path += failure_offset;
1757 ppl -= failure_offset;
1758 truncated = true;
1760 }
1761 else
1762 {
1763 failure_offset -= ppl;
1764 if (0 == failure_offset)
1765 trunc_peer = &put_path[ppl - 1].pred;
1766 else
1767 trunc_peer = &get_path[failure_offset - 1].pred;
1768 ppl = 0;
1769 put_path = NULL;
1770 truncated = true;
1772 get_path += failure_offset;
1773 get_path_length -= failure_offset;
1774 }
1775 }
1776#endif
1777 msize = bd->data_size + sizeof (struct PeerResultMessage);
1778 if (msize > GNUNET_MAX_MESSAGE_SIZE)
1779 {
1780 GNUNET_break_op (0);
1781 safe_neighbours_callback (cb_cls, cb, false);
1782 return;
1783 }
1784 if (truncated)
1785 msize += sizeof (struct GNUNET_PeerIdentity);
1786 if (tracking)
1787 msize += sizeof (struct GNUNET_CRYPTO_EddsaSignature);
1788 if (msize < bd->data_size)
1789 {
1790 GNUNET_break_op (0);
1791 safe_neighbours_callback (cb_cls, cb, false);
1792 return;
1793 }
1794 if ( (GNUNET_MAX_MESSAGE_SIZE - msize)
1795 / sizeof(struct GNUNET_DHT_PathElement)
1796 < (get_path_length + ppl) )
1797 {
1798 get_path_length = 0;
1799 ppl = 0;
1800 }
1801 if ( (get_path_length > UINT16_MAX) ||
1802 (ppl > UINT16_MAX) )
1803 {
1804 GNUNET_break (0);
1805 get_path_length = 0;
1806 ppl = 0;
1807 }
1808 msize += (get_path_length + ppl)
1809 * sizeof(struct GNUNET_DHT_PathElement);
1811 "Forwarding reply for key %s to peer %s\n",
1812 GNUNET_h2s (query_hash),
1813 GNUNET_i2s (&pi->id));
1815 "# RESULT messages queued for transmission",
1816 1,
1817 GNUNET_NO);
1818 {
1819 struct PeerResultMessage *prm;
1820 char buf[msize] GNUNET_ALIGN;
1821
1822 prm = (struct PeerResultMessage *) buf;
1824 prm->header.size = htons (sizeof (buf));
1825 prm->type = htonl ((uint32_t) bd->type);
1826 prm->reserved = htons (0);
1827 prm->options = htons ((uint16_t) ro);
1828 prm->put_path_length = htons ((uint16_t) ppl);
1829 prm->get_path_length = htons ((uint16_t) get_path_length);
1831 prm->key = *query_hash;
1832 if (truncated)
1833 {
1834 void *tgt = &prm[1];
1835
1836 GNUNET_memcpy (tgt,
1837 trunc_peer,
1838 sizeof (struct GNUNET_PeerIdentity));
1839 paths = (struct GNUNET_DHT_PathElement *)
1840 (tgt + sizeof (struct GNUNET_PeerIdentity));
1841 }
1842 else
1843 {
1844 paths = (struct GNUNET_DHT_PathElement *) &prm[1];
1845 }
1846 if (NULL != put_path)
1847 {
1848 GNUNET_memcpy (paths,
1849 put_path,
1850 ppl * sizeof(struct GNUNET_DHT_PathElement));
1851 }
1852 else
1853 {
1854 GNUNET_assert (0 == ppl);
1855 }
1856 if (NULL != get_path)
1857 {
1858 GNUNET_memcpy (&paths[ppl],
1859 get_path,
1860 get_path_length * sizeof(struct GNUNET_DHT_PathElement));
1861 }
1862 else
1863 {
1864 GNUNET_assert (0 == get_path_length);
1865 }
1866 if (tracking)
1867 {
1868 struct GDS_NeighboursReply reply;
1869 const struct GNUNET_PeerIdentity *pred;
1870
1871 reply.pi = pi;
1872 GNUNET_memcpy (&reply.bd, bd, sizeof (reply.bd));
1873 reply.block_data = GNUNET_memdup (bd->data, bd->data_size);
1874 reply.put_path = GNUNET_memdup (bd->put_path,
1875 sizeof (struct GNUNET_DHT_PathElement)
1876 * bd->put_path_length);
1877
1878 reply.bd.data = reply.block_data;
1879 reply.bd.put_path = reply.put_path;
1880
1881 reply.buf = GNUNET_memdup (buf, msize);
1882 reply.prm = (struct PeerResultMessage*) reply.buf;
1883 reply.paths = (struct GNUNET_DHT_PathElement*)
1884 (reply.buf + ((const char *) paths - buf));
1885
1886 if (trunc_peer)
1887 {
1888 reply.trunc_peer_is_null = false;
1889 GNUNET_memcpy (&reply.trunc_peer_id, trunc_peer,
1890 sizeof (reply.trunc_peer_id));
1891 }
1892 else
1893 {
1894 reply.trunc_peer_is_null = true;
1895 }
1896
1897 reply.cb = cb;
1898 reply.cb_cls = cb_cls;
1899
1900 if (ppl + get_path_length > 0)
1901 pred = &paths[ppl + get_path_length - 1].pred;
1902 else if (truncated)
1903 pred = trunc_peer;
1904 else
1905 pred = NULL; /* we are first! */
1906 /* Note that the last signature in 'paths' was not initialized before,
1907 so this is crucial to avoid sending garbage. */
1909 bd->data_size,
1911 bd->expiration_time,
1912 pred,
1913 &pi->id,
1915 sizeof (reply),
1916 &reply);
1917 }
1918 else
1919 {
1920 void *data;
1921 data = &prm[1];
1923 bd->data,
1924 bd->data_size);
1925 do_send (pi,
1926 &prm->header);
1927 safe_neighbours_callback (cb_cls, cb, true);
1928 return;
1929 }
1930 }
1931}
bool GDS_helper_sign_path(const void *data, size_t data_size, const struct GNUNET_CRYPTO_EddsaPrivateKey *sk, struct GNUNET_TIME_Absolute exp_time, const struct GNUNET_PeerIdentity *pred, const struct GNUNET_PeerIdentity *succ, GDS_HelperCallback cb, size_t cb_data_size, void *cb_data)
Sign that we are routing a message from pred to succ.
Definition dht_helper.c:226
static char * data
The data to insert into the dht.
static size_t data_size
Number of bytes in data.
static void safe_neighbours_callback(void *cls, GNUNET_SCHEDULER_TaskCallback cb, bool success)
static bool cb_path_signed(void *cls, const struct GNUNET_CRYPTO_EddsaSignature *sig)
unsigned int GNUNET_DHT_verify_path(const void *data, size_t data_size, struct GNUNET_TIME_Absolute exp_time, const struct GNUNET_PeerIdentity *trunc_peer, const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_len, const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_len, const struct GNUNET_PeerIdentity *me)
Verify signatures on a path consisting of put_path and get_path in reverse order (starting at the las...
Definition dht_api.c:1354
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_memdup(buf, size)
Allocate and initialize a block of memory.
#define GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT
Data is returned to peer from DHT.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition time.c:636
an ECC signature using EdDSA.
struct GNUNET_PeerIdentity pred
Previous peer on the path (matches "pred" in the signed field).
uint16_t get_path_length
Length of the GET path that follows (if tracked).
uint16_t options
Message options, actually an 'enum GNUNET_DHT_RouteOption' value in NBO.
struct GNUNET_HashCode key
The key of the corresponding GET request.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT.
uint16_t put_path_length
Length of the PUT path that follows (if tracked).
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the content expire?

References GDS_NeighboursReply::bd, GDS_NeighboursReply::block_data, GDS_NeighboursReply::buf, GDS_NeighboursReply::cb, GDS_NeighboursReply::cb_cls, cb_path_signed(), data, GNUNET_DATACACHE_Block::data, data_size, GNUNET_DATACACHE_Block::data_size, do_send(), GNUNET_DATACACHE_Block::expiration_time, PeerResultMessage::expiration_time, GDS_helper_sign_path(), GDS_pils, GDS_stats, PeerResultMessage::get_path_length, GNUNET_ALIGN, GNUNET_assert, GNUNET_break, GNUNET_break_op, GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_DHT_RO_TRUNCATED, GNUNET_DHT_verify_path(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_memdup, GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, GNUNET_NO, GNUNET_PILS_get_identity(), GNUNET_PILS_get_private_key(), GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_hton(), PeerResultMessage::header, PeerInfo::id, PeerResultMessage::key, my_identity, PeerResultMessage::options, GDS_NeighboursReply::paths, GDS_NeighboursReply::pi, GNUNET_DHT_PathElement::pred, GDS_NeighboursReply::prm, GNUNET_DATACACHE_Block::put_path, GDS_NeighboursReply::put_path, GNUNET_DATACACHE_Block::put_path_length, PeerResultMessage::put_path_length, PeerResultMessage::reserved, GNUNET_DATACACHE_Block::ro, safe_neighbours_callback(), GNUNET_MessageHeader::size, GNUNET_DATACACHE_Block::trunc_peer, GDS_NeighboursReply::trunc_peer_id, GDS_NeighboursReply::trunc_peer_is_null, GNUNET_MessageHeader::type, GNUNET_DATACACHE_Block::type, and PeerResultMessage::type.

Referenced by handle_find_local_hello(), handle_find_my_hello(), handle_local_result(), and process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GDS_am_closest_peer()

enum GNUNET_GenericReturnValue 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 885 of file gnunet-service-dht_neighbours.c.

887{
888 const struct GNUNET_HashCode *my_identity_hash;
889 int delta;
890 my_identity_hash = GNUNET_PILS_get_identity_hash (GDS_pils);
891 GNUNET_assert (NULL != my_identity_hash);
892 if (0 == GNUNET_memcmp (my_identity_hash, key))
893 return GNUNET_YES;
894 for (int bucket_num = find_bucket (key);
895 bucket_num < closest_bucket;
896 bucket_num++)
897 {
898 unsigned int count = 0;
899 GNUNET_assert (bucket_num >= 0);
900 for (struct PeerInfo *pos = k_buckets[bucket_num].head;
901 NULL != pos;
902 pos = pos->next)
903 {
904 if (count >= bucket_size)
905 break; /* we only consider first #bucket_size entries per bucket */
906 count++;
907 if ( (NULL != bloom) &&
908 (GNUNET_YES ==
910 &pos->phash)) )
911 continue; /* Ignore filtered peers */
912 /* All peers in this bucket must be closer than us, as
913 they mismatch with our PID on the pivotal bit. So
914 because an unfiltered peer exists, we are not the
915 closest. */
916 delta = GNUNET_CRYPTO_hash_xorcmp (&pos->phash,
917 my_identity_hash,
918 key);
919 switch (delta)
920 {
921 case -1: /* pos closer */
922 return GNUNET_NO;
923 case 0: /* identical, impossible! */
924 GNUNET_assert (0);
925 break;
926 case 1: /* I am closer */
927 break;
928 }
929 }
930 }
931 /* No closer (unfiltered) peers found; we must be the closest! */
932 return GNUNET_YES;
933}
static int find_bucket(const struct GNUNET_HashCode *hc)
Find the optimal bucket for this key.
static unsigned int bucket_size
Maximum size for each bucket.
static unsigned int closest_bucket
One past the deepest currently used bucket, initially 0 (no peers at all).
static struct PeerBucket k_buckets[sizeof(struct GNUNET_HashCode) *8]
The buckets.
bool GNUNET_CONTAINER_bloomfilter_test(const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Test if an element is in the filter.
int GNUNET_CRYPTO_hash_xorcmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2, const struct GNUNET_HashCode *target)
Find out which of the two GNUNET_CRYPTO_hash codes is closer to target in the XOR metric (Kademlia).
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
@ GNUNET_YES
static struct GNUNET_TIME_Relative delta
Definition speedup.c:36

References bucket_size, closest_bucket, delta, find_bucket(), GDS_pils, GNUNET_assert, GNUNET_CONTAINER_bloomfilter_test(), GNUNET_CRYPTO_hash_xorcmp(), GNUNET_memcmp, GNUNET_NO, GNUNET_PILS_get_identity_hash(), GNUNET_YES, k_buckets, and key.

Referenced by handle_dht_local_put(), handle_dht_p2p_get(), and handle_dht_p2p_put().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GDS_try_connect()

void GDS_try_connect ( void *  cls,
const struct GNUNET_PeerIdentity pid,
const char *  uri 
)

Callback function used to extract URIs from a builder.

Called when we should consider connecting to a peer.

Parameters
clsclosure
pidpointing to a struct GNUNET_PeerIdentity *
urione of the URIs

Called when we should consider connecting to a peer.

Parameters
clsclosure pointing to a struct GNUNET_PeerIdentity *
urione of the URIs

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

3101{
3102 const struct GNUNET_PeerIdentity *my_identity;
3103 struct GNUNET_HashCode phash;
3104 int peer_bucket;
3105 struct PeerBucket *bucket;
3106 (void) cls;
3107
3109 GNUNET_assert (NULL != my_identity);
3110
3111 if (0 == GNUNET_memcmp (my_identity, pid))
3112 {
3114 "Got a HELLO for my own PID, ignoring it\n");
3115 return; /* that's us! */
3116 }
3117 GNUNET_CRYPTO_hash (pid,
3118 sizeof(*pid),
3119 &phash);
3120 peer_bucket = find_bucket (&phash);
3121 GNUNET_assert ( (peer_bucket >= 0) &&
3122 ((unsigned int) peer_bucket < MAX_BUCKETS));
3123 bucket = &k_buckets[peer_bucket];
3124 for (struct PeerInfo *pi = bucket->head;
3125 NULL != pi;
3126 pi = pi->next)
3127 if (0 ==
3128 GNUNET_memcmp (&pi->id,
3129 pid))
3130 {
3131 /* already connected */
3132 GDS_u_try_connect (pid,
3133 uri);
3134 return;
3135 }
3136 if (bucket->peers_size >= bucket_size)
3137 return; /* do not care */
3139 "Discovered peer %s at %s suitable for bucket %d (%u/%u), trying to connect\n",
3140 GNUNET_i2s (pid),
3141 uri,
3142 peer_bucket,
3143 bucket->peers_size,
3144 bucket_size);
3145 /* new peer that we like! */
3146 GDS_u_try_connect (pid,
3147 uri);
3148}
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
void GDS_u_try_connect(const struct GNUNET_PeerIdentity *pid, const char *address)
Ask all underlays to connect to peer pid at address.
#define MAX_BUCKETS
How many buckets will we allow in total.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:40
@ GNUNET_ERROR_TYPE_INFO
Peers are grouped into buckets.
struct PeerInfo * head
Head of DLL.
unsigned int peers_size
Number of peers in the bucket.

References bucket_size, find_bucket(), GDS_pils, GDS_u_try_connect(), GNUNET_assert, GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GNUNET_memcmp, GNUNET_PILS_get_identity(), PeerBucket::head, k_buckets, MAX_BUCKETS, my_identity, PeerBucket::peers_size, and uri.

Referenced by handle_dht_local_hello_offer(), and hello_check().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GDS_u_connect()

void GDS_u_connect ( void *  cls,
struct GNUNET_DHTU_Target target,
const struct GNUNET_PeerIdentity pid,
void **  ctx 
)

Function to call when we connect to a peer and can henceforth transmit to that peer.

Parameters
clsthe closure, must be a struct GDS_Underlay
targethandle to the target, pointer will remain valid until disconnect_cb is called
pidpeer identity, pointer will remain valid until disconnect_cb is called
[out]ctxstorage space for DHT to use in association with this target

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

666{
667 const struct GNUNET_PeerIdentity *my_identity;
668 struct GDS_Underlay *u = cls;
669 struct PeerInfo *pi;
670 struct PeerBucket *bucket;
671 bool do_hold = false;
672
674 GNUNET_assert (NULL != my_identity);
675
676 /* Check for connect to self message */
677 if (0 == GNUNET_memcmp (my_identity, pid))
678 return;
680 "Connected to peer %s\n",
681 GNUNET_i2s (pid));
683 pid);
684 if (NULL == pi)
685 {
687 "# peers connected",
688 1,
689 GNUNET_NO);
690 pi = GNUNET_new (struct PeerInfo);
691 pi->id = *pid;
693 sizeof(*pid),
694 &pi->phash);
695 pi->peer_bucket = find_bucket (&pi->phash);
696 GNUNET_assert ( (pi->peer_bucket >= 0) &&
697 ((unsigned int) pi->peer_bucket < MAX_BUCKETS));
698 bucket = &k_buckets[pi->peer_bucket];
700 bucket->tail,
701 pi);
702 bucket->peers_size++;
704 (unsigned int) pi->peer_bucket + 1);
707 &pi->id,
708 pi,
710 if (bucket->peers_size <= bucket_size)
711 {
713 do_hold = true;
714 }
717 {
718 /* got a first connection, good time to start with FIND PEER requests... */
721 NULL);
722 }
723 /* A pending GET that found no route is sitting on an exponential
724 back-off of up to 15 minutes; now that we have somewhere to send
725 it, do so immediately. A PUT that found no route was not sent at
726 all and nothing else will ever send it. */
729 }
730 {
731 struct Target *t;
732
733 t = GNUNET_new (struct Target);
734 t->u = u;
735 t->utarget = target;
736 t->pi = pi;
738 pi->t_tail,
739 t);
740 *ctx = t;
741
742 }
743 if (do_hold)
744 update_hold (bucket);
745}
static mp_limb_t u[(((256)+GMP_NUMB_BITS - 1)/GMP_NUMB_BITS)]
static struct GNUNET_FS_Handle * ctx
static struct GNUNET_SCHEDULER_Task * t
Main task.
void GDS_CLIENTS_retry_puts(void)
Our routing table gained a peer.
void GDS_CLIENTS_retry_requests(void)
Our routing table gained a peer.
static void send_find_peer_message(void *cls)
Task to send a find peer message for our own peer identifier so that we can find the closest peers in...
static int disable_try_connect
Option for testing that disables the 'connect' function of the DHT.
static unsigned int newly_found_peers
How many peers have we added since we sent out our last find peer request?
static struct GNUNET_SCHEDULER_Task * find_peer_task
Task that sends FIND PEER requests.
static void update_hold(struct PeerBucket *bucket)
The list of the first bucket_size peers of bucket changed.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
#define GNUNET_MAX(a, b)
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition scheduler.c:1310
Information we keep per underlay.
struct PeerInfo * tail
Tail of DLL.
struct Target * t_tail
Tail of DLL of targets for this peer.
int peer_bucket
Which bucket is this peer in?
struct Target * t_head
Head of DLL of targets for this peer.
List of targets that we can use to reach this peer.
struct PeerInfo * pi
Peer this is a target for.

References all_connected_peers, bucket_size, closest_bucket, ctx, disable_try_connect, find_bucket(), find_peer_task, GDS_CLIENTS_retry_puts(), GDS_CLIENTS_retry_requests(), GDS_pils, GDS_stats, GNUNET_assert, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_MAX, GNUNET_memcmp, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_PILS_get_identity(), GNUNET_SCHEDULER_add_now(), GNUNET_STATISTICS_update(), GNUNET_YES, PeerBucket::head, PeerInfo::id, k_buckets, MAX_BUCKETS, my_identity, newly_found_peers, PeerInfo::peer_bucket, PeerBucket::peers_size, PeerInfo::phash, Target::pi, send_find_peer_message(), t, PeerInfo::t_head, PeerInfo::t_tail, PeerBucket::tail, u, and update_hold().

Referenced by load_underlay().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GDS_u_disconnect()

void GDS_u_disconnect ( void *  ctx)

Function to call when we disconnected from a peer and can henceforth cannot transmit to that peer anymore.

Parameters
[in]ctxstorage space used by the DHT in association with this target

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

750{
751 struct Target *t = ctx;
752 struct PeerInfo *pi;
753 struct PeerBucket *bucket;
754 bool was_held = false;
755
756 /* Check for disconnect from self message (on shutdown) */
757 if (NULL == t)
758 return;
759 pi = t->pi;
761 pi->t_tail,
762 t);
763 if (NULL != t->ph)
764 {
765 GDS_u_drop (t->u,
766 t->ph);
767 t->ph = NULL;
768 was_held = true;
769 }
770 if (t->load > 0)
771 {
772 t->dropped = true;
773 t->pi = NULL;
774 }
775 else
776 {
777 GNUNET_free (t);
778 }
779 if (NULL != pi->t_head)
780 return; /* got other connections still */
782 "Disconnected from peer %s\n",
783 GNUNET_i2s (&pi->id));
785 "# peers connected",
786 -1,
787 GNUNET_NO);
790 &pi->id,
791 pi));
794 {
796 find_peer_task = NULL;
797 }
798 GNUNET_assert (pi->peer_bucket >= 0);
799 bucket = &k_buckets[pi->peer_bucket];
801 bucket->tail,
802 pi);
803 GNUNET_assert (bucket->peers_size > 0);
804 bucket->peers_size--;
805 if ( (was_held) &&
806 (bucket->peers_size >= bucket_size - 1) )
807 update_hold (bucket);
808 while ( (closest_bucket > 0) &&
811 GNUNET_free (pi->hello);
812 GNUNET_free (pi);
813}
void GDS_u_drop(struct GDS_Underlay *u, struct GNUNET_DHTU_PreferenceHandle *ph)
Drop a hold ph from underlay u.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
void * hello
Block with a HELLO of this peer.

References all_connected_peers, bucket_size, closest_bucket, ctx, disable_try_connect, find_peer_task, GDS_stats, GDS_u_drop(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_update(), GNUNET_YES, PeerBucket::head, PeerInfo::hello, PeerInfo::id, k_buckets, PeerInfo::peer_bucket, PeerBucket::peers_size, t, PeerInfo::t_head, PeerInfo::t_tail, PeerBucket::tail, and update_hold().

Referenced by load_underlay().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GDS_u_receive()

void GDS_u_receive ( void *  cls,
void **  tctx,
void **  sctx,
const void *  message,
size_t  message_size 
)

Function to call when we receive a message.

Parameters
clsthe closure
[in,out]tctxctx of target address where we received the message from
[in,out]sctxctx of our own source address at which we received the message
messagethe message we received
message_sizenumber of bytes in message

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

3034{
3035 struct Target *t = *tctx;
3036 struct GNUNET_MQ_MessageHandler core_handlers[] = {
3037 GNUNET_MQ_hd_var_size (dht_p2p_get,
3039 struct PeerGetMessage,
3040 t),
3041 GNUNET_MQ_hd_var_size (dht_p2p_put,
3043 struct PeerPutMessage,
3044 t),
3045 GNUNET_MQ_hd_var_size (dht_p2p_result,
3047 struct PeerResultMessage,
3048 t),
3049 GNUNET_MQ_hd_var_size (dht_p2p_hello,
3051 struct GNUNET_MessageHeader,
3052 t),
3054 };
3055 const struct GNUNET_MessageHeader *mh = message;
3056
3057 (void) cls; /* the 'struct GDS_Underlay' */
3058 (void) sctx; /* our receiver address */
3059 if (NULL == t)
3060 {
3061 /* Received message claiming to originate from myself?
3062 Ignore! */
3063 GNUNET_break_op (0);
3064 return;
3065 }
3066 if (message_size < sizeof (*mh))
3067 {
3068 GNUNET_break_op (0);
3069 return;
3070 }
3071 if (message_size != ntohs (mh->size))
3072 {
3073 GNUNET_break_op (0);
3074 return;
3075 }
3077 "Handling message of type %u from peer %s\n",
3078 ntohs (mh->type),
3079 GNUNET_i2s (&t->pi->id));
3080 if (GNUNET_OK !=
3081 GNUNET_MQ_handle_message (core_handlers,
3082 mh))
3083 {
3084 GNUNET_break_op (0);
3085 return;
3086 }
3087}
static struct GNUNET_CADET_Handle * mh
Cadet handle.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
enum GNUNET_GenericReturnValue GNUNET_MQ_handle_message(const struct GNUNET_MQ_MessageHandler *handlers, const struct GNUNET_MessageHeader *mh)
Call the message message handler that was registered for the type of the given message in the given h...
Definition mq.c:281
#define GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO
HELLO advertising a neighbours addresses.
#define GNUNET_MESSAGE_TYPE_DHT_P2P_PUT
Peer is storing data in DHT.
Message handler for a specific message type.
Header for all communications.

References GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_MESSAGE_TYPE_DHT_P2P_GET, GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO, GNUNET_MESSAGE_TYPE_DHT_P2P_PUT, GNUNET_MESSAGE_TYPE_DHT_P2P_RESULT, GNUNET_MQ_handle_message(), GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_OK, mh, and t.

Referenced by load_underlay().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GDS_NEIGHBOURS_broadcast()

void GDS_NEIGHBOURS_broadcast ( const struct GNUNET_MessageHeader msg)

Send msg to all peers in our buckets.

Parameters
msgmessage to broadcast

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

3158{
3159 for (unsigned int bc = 0; bc<closest_bucket; bc++)
3160 {
3161 struct PeerBucket *bucket = &k_buckets[bc];
3162 unsigned int count = 0;
3163
3164 for (struct PeerInfo *pos = bucket->head;
3165 NULL != pos;
3166 pos = pos->next)
3167 {
3168 if (count >= bucket_size)
3169 break; /* we only consider first #bucket_size entries per bucket */
3170 count++;
3171 do_send (pos,
3172 msg);
3173 }
3174 }
3175}
struct GNUNET_MessageHeader * msg
Definition 005.c:2

References bucket_size, closest_bucket, do_send(), PeerBucket::head, k_buckets, and msg.

Referenced by pid_change_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GDS_NEIGHBOURS_init()

enum GNUNET_GenericReturnValue GDS_NEIGHBOURS_init ( void  )

Initialize neighbours subsystem.

Returns
GNUNET_OK on success, GNUNET_SYSERR on error

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

3180{
3181
3182 unsigned long long temp_config_num;
3183
3186 "DHT",
3187 "DISABLE_TRY_CONNECT");
3188 if (GNUNET_OK ==
3190 "DHT",
3191 "bucket_size",
3192 &temp_config_num))
3193 bucket_size = (unsigned int) temp_config_num;
3196 "DHT",
3197 "CACHE_RESULTS");
3199 GNUNET_YES);
3200 return GNUNET_OK;
3201}
const struct GNUNET_CONFIGURATION_Handle * GDS_cfg
Configuration we use.
static int cache_results
Do we cache all results that we are routing in the local datacache?
enum GNUNET_GenericReturnValue 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.
enum GNUNET_GenericReturnValue 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".
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).

References all_connected_peers, bucket_size, cache_results, disable_try_connect, GDS_cfg, GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONTAINER_multipeermap_create(), GNUNET_OK, and GNUNET_YES.

Referenced by run().

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 3205 of file gnunet-service-dht_neighbours.c.

3206{
3207 if (NULL == all_connected_peers)
3208 return;
3209 GNUNET_assert (0 ==
3212 all_connected_peers = NULL;
3213 GNUNET_assert (NULL == find_peer_task);
3214}
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.

References all_connected_peers, find_peer_task, GNUNET_assert, GNUNET_CONTAINER_multipeermap_destroy(), and GNUNET_CONTAINER_multipeermap_size().

Referenced by shutdown_task().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GDS_NEIGHBOURS_get_id()

const struct GNUNET_PeerIdentity * GDS_NEIGHBOURS_get_id ( void  )

Get the ID of the local node.

Returns
identity of the local node

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

3219{
3221}

References GDS_pils, and GNUNET_PILS_get_identity().

Here is the call graph for this function: