GNUnet  0.11.x
Data Structures | Macros | Functions | Variables
gnunet-service-nse.c File Reference

network size estimation service More...

#include "platform.h"
#include <math.h>
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_protocols.h"
#include "gnunet_signatures.h"
#include "gnunet_statistics_service.h"
#include "gnunet_core_service.h"
#include "gnunet_nse_service.h"
#include "nse.h"
#include <gcrypt.h>
Include dependency graph for gnunet-service-nse.c:

Go to the source code of this file.

Data Structures

struct  NSEPeerEntry
 Per-peer information. More...
 
struct  GNUNET_NSE_FloodMessage
 Network size estimate reply; sent when "this" peer's timer has run out before receiving a valid reply from another peer. More...
 

Macros

#define USE_RANDOM_DELAYS   GNUNET_YES
 Should messages be delayed randomly? This option should be set to GNUNET_NO only for experiments, not in production. More...
 
#define DEBUG_NSE   GNUNET_NO
 Generate extensive debug-level log messages? More...
 
#define HISTORY_SIZE   64
 Over how many values do we calculate the weighted average? More...
 
#define NSE_PRIORITY
 Message priority to use. More...
 
#define WEST   1
 
#define ROUND_SIZE   10
 

Functions

static void setup_estimate_message (struct GNUNET_NSE_ClientMessage *em)
 Initialize a message to clients with the current network size estimate. More...
 
static void handle_start (void *cls, const struct GNUNET_MessageHeader *message)
 Handler for START message from client, triggers an immediate current network estimate notification. More...
 
static double get_matching_bits_delay (uint32_t matching_bits)
 How long should we delay a message to go the given number of matching bits? More...
 
static struct GNUNET_TIME_Relative get_delay_randomization (uint32_t matching_bits)
 What delay randomization should we apply for a given number of matching bits? More...
 
static void pow_hash (const void *buf, size_t buf_len, struct GNUNET_HashCode *result)
 Calculate the 'proof-of-work' hash (an expensive hash). More...
 
static uint32_t get_matching_bits (struct GNUNET_TIME_Absolute timestamp, const struct GNUNET_PeerIdentity *id)
 Get the number of matching bits that the given timestamp has to the given peer ID. More...
 
static struct GNUNET_TIME_Relative get_transmit_delay (int round_offset)
 Get the transmission delay that should be applied for a particular round. More...
 
static void transmit_task_cb (void *cls)
 Task that triggers a NSE P2P transmission. More...
 
static void update_network_size_estimate ()
 We've sent on our flood message or one that we received which was validated and closer than ours. More...
 
static void setup_flood_message (unsigned int slot, struct GNUNET_TIME_Absolute ts)
 Setup a flood message in our history array at the given slot offset for the given timestamp. More...
 
static int schedule_current_round (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Schedule transmission for the given peer for the current round based on what we know about the desired delay. More...
 
static void update_flood_message (void *cls)
 Update our flood message to be sent (and our timestamps). More...
 
static unsigned int count_leading_zeroes (const struct GNUNET_HashCode *hash)
 Count the leading zeroes in hash. More...
 
static int check_proof_of_work (const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, uint64_t val)
 Check whether the given public key and integer are a valid proof of work. More...
 
static void write_proof ()
 Write our current proof to disk. More...
 
static void find_proof (void *cls)
 Find our proof of work. More...
 
static int verify_message_crypto (const struct GNUNET_NSE_FloodMessage *incoming_flood)
 An incoming flood message has been received which claims to have more bits matching than any we know in this time period. More...
 
static int update_flood_times (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Update transmissions for the given peer for the current round based on updated proximity information. More...
 
static void handle_p2p_estimate (void *cls, const struct GNUNET_NSE_FloodMessage *incoming_flood)
 Core handler for size estimate flooding messages. More...
 
static void * handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
 Method called whenever a peer connects. More...
 
static void handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
 Method called whenever a peer disconnects. More...
 
static void shutdown_task (void *cls)
 Task run during shutdown. More...
 
static void core_init (void *cls, const struct GNUNET_PeerIdentity *identity)
 Called on core init/fail. More...
 
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
 Handle network size estimate clients. More...
 
static void * client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *c, struct GNUNET_MQ_Handle *mq)
 Callback called when a client connects to the service. More...
 
static void client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls)
 Callback called when a client disconnected from the service. More...
 
 GNUNET_SERVICE_MAIN ("nse", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_fixed_size(start, GNUNET_MESSAGE_TYPE_NSE_START, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_handler_end())
 Define "main" method using service macro. More...
 

Variables

static unsigned long long nse_work_required
 Amount of work required (W-bit collisions) for NSE proofs, in collision-bits. More...
 
static struct GNUNET_TIME_Relative gnunet_nse_interval
 Interval for sending network size estimation flood requests. More...
 
static struct GNUNET_TIME_Relative proof_find_delay
 Interval between proof find runs. More...
 
static GNUNET_NETWORK_STRUCT_END const struct GNUNET_CONFIGURATION_Handlecfg
 Handle to our current configuration. More...
 
static struct GNUNET_STATISTICS_Handlestats
 Handle to the statistics service. More...
 
static struct GNUNET_CORE_Handlecore_api
 Handle to the core service. More...
 
static struct GNUNET_CONTAINER_MultiPeerMappeers
 Map of all connected peers. More...
 
static double current_size_estimate
 The current network size estimate. More...
 
static double current_std_dev = NAN
 The standard deviation of the last HISTORY_SIZE network size estimates. More...
 
static uint32_t hop_count_max
 Current hop counter estimate (estimate for network diameter). More...
 
static struct GNUNET_NSE_FloodMessage next_message
 Message for the next round, if we got any. More...
 
static struct GNUNET_NSE_FloodMessage size_estimate_messages [64]
 Array of recent size estimate messages. More...
 
static unsigned int estimate_index
 Index of most recent estimate. More...
 
static unsigned int estimate_count
 Number of valid entries in the history. More...
 
static struct GNUNET_SCHEDULER_Taskflood_task
 Task scheduled to update our flood message for the next round. More...
 
static struct GNUNET_SCHEDULER_Taskproof_task
 Task scheduled to compute our proof. More...
 
static struct GNUNET_NotificationContextnc
 Notification context, simplifies client broadcasts. More...
 
static struct GNUNET_TIME_Absolute next_timestamp
 The next major time. More...
 
static struct GNUNET_TIME_Absolute current_timestamp
 The current major time. More...
 
static struct GNUNET_CRYPTO_EddsaPrivateKeymy_private_key
 The private key of this peer. More...
 
static struct GNUNET_PeerIdentity my_identity
 The peer identity of this peer. More...
 
static uint64_t my_proof
 Proof of work for this peer. More...
 

Detailed Description

network size estimation service

Author
Nathan Evans
Christian Grothoff

The purpose of this service is to estimate the size of the network. Given a specified interval, each peer hashes the most recent timestamp which is evenly divisible by that interval. This hash is compared in distance to the peer identity to choose an offset. The closer the peer identity to the hashed timestamp, the earlier the peer sends out a "nearest peer" message. The closest peer's message should thus be received before any others, which stops those peer from sending their messages at a later duration. So every peer should receive the same nearest peer message, and from this can calculate the expected number of peers in the network.

Definition in file gnunet-service-nse.c.

Macro Definition Documentation

◆ USE_RANDOM_DELAYS

#define USE_RANDOM_DELAYS   GNUNET_YES

Should messages be delayed randomly? This option should be set to GNUNET_NO only for experiments, not in production.

Definition at line 58 of file gnunet-service-nse.c.

◆ DEBUG_NSE

#define DEBUG_NSE   GNUNET_NO

Generate extensive debug-level log messages?

Definition at line 63 of file gnunet-service-nse.c.

◆ HISTORY_SIZE

#define HISTORY_SIZE   64

Over how many values do we calculate the weighted average?

Definition at line 68 of file gnunet-service-nse.c.

Referenced by core_init(), handle_p2p_estimate(), setup_estimate_message(), transmit_task_cb(), and update_flood_message().

◆ NSE_PRIORITY

#define NSE_PRIORITY
Value:
Lowest priority, i.e.
Flag to indicate that CORKing is acceptable.
Flag to indicate that unreliable delivery is acceptable.

Message priority to use.

No real rush, reliability not required. Corking OK.

Definition at line 74 of file gnunet-service-nse.c.

Referenced by handle_core_connect().

◆ WEST

#define WEST   1

◆ ROUND_SIZE

#define ROUND_SIZE   10

Referenced by find_proof().

Function Documentation

◆ setup_estimate_message()

static void setup_estimate_message ( struct GNUNET_NSE_ClientMessage em)
static

Initialize a message to clients with the current network size estimate.

Parameters
emmessage to fill in

Definition at line 322 of file gnunet-service-nse.c.

References current_size_estimate, current_std_dev, estimate_count, estimate_index, GNUNET_CONTAINER_multipeermap_size(), GNUNET_hton_double(), GNUNET_MAX, GNUNET_MESSAGE_TYPE_NSE_ESTIMATE, GNUNET_NO, GNUNET_STATISTICS_set(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_hton(), GNUNET_NSE_ClientMessage::header, HISTORY_SIZE, matching_bits, q, GNUNET_NSE_ClientMessage::reserved, GNUNET_MessageHeader::size, GNUNET_NSE_ClientMessage::size_estimate, size_estimate_messages, GNUNET_NSE_ClientMessage::std_deviation, GNUNET_NSE_ClientMessage::timestamp, and GNUNET_MessageHeader::type.

Referenced by handle_start(), and update_network_size_estimate().

323 {
324  double mean;
325  double sum;
326  double std_dev;
327  double variance;
328  double val;
329  double nsize;
330 
331 #define WEST 1
332  /* Weighted incremental algorithm for stddev according to West (1979) */
333 #if WEST
334  double sumweight;
335  double weight;
336  double q;
337  double r;
338  double temp;
339 
340  mean = 0.0;
341  sum = 0.0;
342  sumweight = 0.0;
343  variance = 0.0;
344  for (unsigned int i = 0; i < estimate_count; i++)
345  {
346  unsigned int j = (estimate_index - i + HISTORY_SIZE) % HISTORY_SIZE;
347 
348  val = htonl (size_estimate_messages[j].matching_bits);
349  weight = estimate_count + 1 - i;
350 
351  temp = weight + sumweight;
352  q = val - mean;
353  r = q * weight / temp;
354  mean += r;
355  sum += sumweight * q * r;
356  sumweight = temp;
357  }
358  if (estimate_count > 0)
359  variance = (sum / sumweight) * estimate_count / (estimate_count - 1.0);
360 #else
361  /* trivial version for debugging */
362  double vsq;
363 
364  /* non-weighted trivial version */
365  sum = 0.0;
366  vsq = 0.0;
367  variance = 0.0;
368  mean = 0.0;
369 
370  for (unsigned int i = 0; i < estimate_count; i++)
371  {
372  unsigned int j = (estimate_index - i + HISTORY_SIZE) % HISTORY_SIZE;
373 
374  val = htonl (size_estimate_messages[j].matching_bits);
375  sum += val;
376  vsq += val * val;
377  }
378  if (0 != estimate_count)
379  {
380  mean = sum / estimate_count;
381  variance = (vsq - mean * sum)
382  / (estimate_count - 1.0); // terrible for numerical stability...
383  }
384 #endif
385  if (variance >= 0)
386  std_dev = sqrt (variance);
387  else
388  std_dev = variance; /* must be infinity due to estimate_count == 0 */
389  current_std_dev = std_dev;
390  current_size_estimate = mean;
391 
392  em->header.size = htons (sizeof(struct GNUNET_NSE_ClientMessage));
394  em->reserved = htonl (0);
396  {
397  double se = mean - 0.332747;
398  unsigned int j = GNUNET_CONTAINER_multipeermap_size (peers);
399  if (0 == j)
400  j = 1; /* Avoid log2(0); can only happen if CORE didn't report
401  connection to self yet */
402  nsize = log2 (j);
403  em->size_estimate = GNUNET_hton_double (GNUNET_MAX (se, nsize));
404  em->std_deviation = GNUNET_hton_double (std_dev);
406  "# nodes in the network (estimate)",
407  (uint64_t) pow (2, GNUNET_MAX (se, nsize)),
408  GNUNET_NO);
409  }
410 }
struct GNUNET_TIME_AbsoluteNBO timestamp
Timestamp at which the server received the message.
Definition: nse.h:57
static struct GNUNET_CONTAINER_MultiPeerMap * peers
Map of all connected peers.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_NSE_ESTIMATE.
Definition: nse.h:47
Network size estimate sent from the service to clients.
Definition: nse.h:42
#define GNUNET_NO
Definition: gnunet_common.h:78
#define HISTORY_SIZE
Over how many values do we calculate the weighted average?
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_MESSAGE_TYPE_NSE_ESTIMATE
service->client message indicating
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
double std_deviation
The standard deviation (rounded down to the nearest integer) of size estimations. ...
Definition: nse.h:69
#define GNUNET_MAX(a, b)
Definition: gnunet_common.h:82
static unsigned int estimate_index
Index of most recent estimate.
static double current_size_estimate
The current network size estimate.
static struct GNUNET_NSE_FloodMessage size_estimate_messages[64]
Array of recent size estimate messages.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
static double current_std_dev
The standard deviation of the last HISTORY_SIZE network size estimates.
double size_estimate
The current estimated network size.
Definition: nse.h:62
static unsigned int estimate_count
Number of valid entries in the history.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
static unsigned long long matching_bits
Number of matching bits required for revocation.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
double GNUNET_hton_double(double d)
Convert double to network byte order.
Definition: common_endian.c:66
uint32_t reserved
For alignment.
Definition: nse.h:52
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_start()

static void handle_start ( void *  cls,
const struct GNUNET_MessageHeader message 
)
static

Handler for START message from client, triggers an immediate current network estimate notification.

Also, we remember the client for updates upon future estimate measurements.

Parameters
clsclient who sent the message
messagethe message received

Definition at line 423 of file gnunet-service-nse.c.

References env, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MQ_msg_copy(), GNUNET_MQ_send(), GNUNET_notification_context_add(), GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_get_mq(), GNUNET_NSE_ClientMessage::header, NSEPeerEntry::mq, and setup_estimate_message().

424 {
425  struct GNUNET_SERVICE_Client *client = cls;
426  struct GNUNET_MQ_Handle *mq;
427  struct GNUNET_NSE_ClientMessage em;
428  struct GNUNET_MQ_Envelope *env;
429 
430  (void) message;
431  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received START message from client\n");
432  mq = GNUNET_SERVICE_client_get_mq (client);
435  env = GNUNET_MQ_msg_copy (&em.header);
436  GNUNET_MQ_send (mq, env);
438 }
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_copy(const struct GNUNET_MessageHeader *hdr)
Create a new envelope by copying an existing message.
Definition: mq.c:653
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2437
Network size estimate sent from the service to clients.
Definition: nse.h:42
void GNUNET_notification_context_add(struct GNUNET_NotificationContext *nc, struct GNUNET_MQ_Handle *mq)
Add a subscriber to the notification context.
Definition: nc.c:160
Handle to a client that is connected to a service.
Definition: service.c:250
static struct GNUNET_NotificationContext * nc
Notification context, simplifies client broadcasts.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static void setup_estimate_message(struct GNUNET_NSE_ClientMessage *em)
Initialize a message to clients with the current network size estimate.
Handle to a message queue.
Definition: mq.c:85
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_log(kind,...)
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:353
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2243
Here is the call graph for this function:

◆ get_matching_bits_delay()

static double get_matching_bits_delay ( uint32_t  matching_bits)
static

How long should we delay a message to go the given number of matching bits?

Parameters
matching_bitsnumber of matching bits to consider

Definition at line 448 of file gnunet-service-nse.c.

References current_size_estimate, gnunet_nse_interval, and GNUNET_TIME_Relative::rel_value_us.

Referenced by get_delay_randomization(), and get_transmit_delay().

449 {
450  /* Calculated as: S + f/2 - (f / pi) * (atan(x - p')) */
451  // S is next_timestamp (ignored in return value)
452  // f is frequency (gnunet_nse_interval)
453  // x is matching_bits
454  // p' is current_size_estimate
455  return ((double) gnunet_nse_interval.rel_value_us / (double) 2.0)
458 }
uint64_t rel_value_us
The actual value.
static struct GNUNET_TIME_Relative gnunet_nse_interval
Interval for sending network size estimation flood requests.
static double current_size_estimate
The current network size estimate.
static unsigned long long matching_bits
Number of matching bits required for revocation.
Here is the caller graph for this function:

◆ get_delay_randomization()

static struct GNUNET_TIME_Relative get_delay_randomization ( uint32_t  matching_bits)
static

What delay randomization should we apply for a given number of matching bits?

Parameters
matching_bitsnumber of matching bits
Returns
random delay to apply

Definition at line 468 of file gnunet-service-nse.c.

References get_matching_bits_delay(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_UNIT_ZERO, GNUNET_YES, hop_count_max, matching_bits, GNUNET_TIME_Relative::rel_value_us, and ret.

Referenced by get_transmit_delay().

469 {
470 #if USE_RANDOM_DELAYS
471  struct GNUNET_TIME_Relative ret;
472  uint32_t i;
473  double d;
474 
476  i = (uint32_t) (d / (double) (hop_count_max + 1));
477  ret.rel_value_us = i;
479  "Randomizing flood using latencies up to %s\n",
481  ret.rel_value_us =
483  return ret;
484 #else
485  return GNUNET_TIME_UNIT_ZERO;
486 #endif
487 }
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static uint32_t hop_count_max
Current hop counter estimate (estimate for network diameter).
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:687
static double get_matching_bits_delay(uint32_t matching_bits)
How long should we delay a message to go the given number of matching bits?
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
static unsigned long long matching_bits
Number of matching bits required for revocation.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pow_hash()

static void pow_hash ( const void *  buf,
size_t  buf_len,
struct GNUNET_HashCode result 
)
static

Calculate the 'proof-of-work' hash (an expensive hash).

Parameters
bufdata to hash
buf_lennumber of bytes in buf
resultwhere to write the resulting hash

Definition at line 498 of file gnunet-service-nse.c.

References GNUNET_break.

Referenced by check_proof_of_work(), and find_proof().

499 {
500  GNUNET_break (
501  0 == gcry_kdf_derive (buf,
502  buf_len,
503  GCRY_KDF_SCRYPT,
504  1 /* subalgo */,
505  "gnunet-proof-of-work",
506  strlen ("gnunet-proof-of-work"),
507  2 /* iterations; keep cost of individual op small */,
508  sizeof(struct GNUNET_HashCode),
509  result));
510 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static char buf[2048]
A 512-bit hashcode.
Here is the caller graph for this function:

◆ get_matching_bits()

static uint32_t get_matching_bits ( struct GNUNET_TIME_Absolute  timestamp,
const struct GNUNET_PeerIdentity id 
)
static

Get the number of matching bits that the given timestamp has to the given peer ID.

Parameters
timestamptime to generate key
idpeer identity to compare with
Returns
number of matching bits

Definition at line 521 of file gnunet-service-nse.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_CRYPTO_hash(), and GNUNET_CRYPTO_hash_matching_bits().

Referenced by setup_flood_message(), and update_flood_message().

523 {
524  struct GNUNET_HashCode timestamp_hash;
525  struct GNUNET_HashCode pid_hash;
526 
527  GNUNET_CRYPTO_hash (&timestamp.abs_value_us,
528  sizeof(timestamp.abs_value_us),
529  &timestamp_hash);
530  GNUNET_CRYPTO_hash (id, sizeof(struct GNUNET_PeerIdentity), &pid_hash);
531  return GNUNET_CRYPTO_hash_matching_bits (&timestamp_hash, &pid_hash);
532 }
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:272
uint64_t abs_value_us
The actual value.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:48
A 512-bit hashcode.
The identity of the host (wraps the signing key of the peer).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_transmit_delay()

static struct GNUNET_TIME_Relative get_transmit_delay ( int  round_offset)
static

Get the transmission delay that should be applied for a particular round.

Parameters
round_offset-1 for the previous round (random delay between 0 and 50ms) 0 for the current round (based on our proximity to time key)
Returns
delay that should be applied

Definition at line 544 of file gnunet-service-nse.c.

References current_timestamp, estimate_index, get_delay_randomization(), get_matching_bits_delay(), GNUNET_break, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u64(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_STRINGS_absolute_time_to_string(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_add(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TIME_UNIT_ZERO, GNUNET_YES, matching_bits, GNUNET_TIME_Relative::rel_value_us, ret, and size_estimate_messages.

Referenced by handle_core_connect(), schedule_current_round(), transmit_task_cb(), and update_flood_times().

545 {
546  struct GNUNET_TIME_Relative ret;
547  struct GNUNET_TIME_Absolute tgt;
548  double dist_delay;
549  uint32_t matching_bits;
550 
551  switch (round_offset)
552  {
553  case -1:
554  /* previous round is randomized between 0 and 50 ms */
555 #if USE_RANDOM_DELAYS
556  ret.rel_value_us =
558 #else
560 #endif
562  "Transmitting previous round behind schedule in %s\n",
564  return ret;
565 
566  case 0:
567  /* current round is based on best-known matching_bits */
568  matching_bits =
569  ntohl (size_estimate_messages[estimate_index].matching_bits);
570  dist_delay = get_matching_bits_delay (matching_bits);
571  dist_delay += get_delay_randomization (matching_bits).rel_value_us;
572  ret.rel_value_us = (uint64_t) dist_delay;
574  "For round %s, delay for %u matching bits is %s\n",
576  (unsigned int) matching_bits,
578  /* now consider round start time and add delay to it */
581  }
582  GNUNET_break (0);
584 }
uint64_t rel_value_us
The actual value.
uint64_t GNUNET_CRYPTO_random_u64(enum GNUNET_CRYPTO_Quality mode, uint64_t max)
Random on unsigned 64-bit values.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition: time.c:395
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_TIME_Relative get_delay_randomization(uint32_t matching_bits)
What delay randomization should we apply for a given number of matching bits?
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:687
static unsigned int estimate_index
Index of most recent estimate.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static struct GNUNET_NSE_FloodMessage size_estimate_messages[64]
Array of recent size estimate messages.
static double get_matching_bits_delay(uint32_t matching_bits)
How long should we delay a message to go the given number of matching bits?
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
static struct GNUNET_TIME_Absolute current_timestamp
The current major time.
#define GNUNET_log(kind,...)
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:77
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:742
static unsigned long long matching_bits
Number of matching bits required for revocation.
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_task_cb()

static void transmit_task_cb ( void *  cls)
static

Task that triggers a NSE P2P transmission.

Parameters
clsthe struct NSEPeerEntry *

Definition at line 593 of file gnunet-service-nse.c.

References env, estimate_index, get_transmit_delay(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_MQ_msg_copy(), GNUNET_MQ_send(), GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_STATISTICS_update(), GNUNET_STRINGS_absolute_time_to_string(), GNUNET_TIME_absolute_ntoh(), GNUNET_YES, HISTORY_SIZE, NSEPeerEntry::id, matching_bits, NSEPeerEntry::mq, NSEPeerEntry::previous_round, size_estimate_messages, and NSEPeerEntry::transmit_task.

Referenced by handle_core_connect(), handle_p2p_estimate(), schedule_current_round(), and update_flood_times().

594 {
595  struct NSEPeerEntry *peer_entry = cls;
596  unsigned int idx;
597  struct GNUNET_MQ_Envelope *env;
598 
599  peer_entry->transmit_task = NULL;
600  idx = estimate_index;
601  if (GNUNET_NO == peer_entry->previous_round)
602  {
603  idx = (idx + HISTORY_SIZE - 1) % HISTORY_SIZE;
604  peer_entry->previous_round = GNUNET_YES;
605  peer_entry->transmit_task =
608  peer_entry);
609  }
610  if ((0 == ntohl (size_estimate_messages[idx].hop_count)) &&
611  (NULL != proof_task))
612  {
614  "# flood messages not generated (no proof yet)",
615  1,
616  GNUNET_NO);
617  return;
618  }
619  if (0 == ntohs (size_estimate_messages[idx].header.size))
620  {
622  "# flood messages not generated (lack of history)",
623  1,
624  GNUNET_NO);
625  return;
626  }
628  "In round %s, sending to `%s' estimate with %u bits\n",
631  size_estimate_messages[idx].timestamp)),
632  GNUNET_i2s (peer_entry->id),
633  (unsigned int) ntohl (size_estimate_messages[idx].matching_bits));
634  if (0 == ntohl (size_estimate_messages[idx].hop_count))
635  GNUNET_STATISTICS_update (stats, "# flood messages started", 1, GNUNET_NO);
637  "# flood messages transmitted",
638  1,
639  GNUNET_NO);
640 #if ENABLE_NSE_HISTOGRAM
641  peer_entry->transmitted_messages++;
642  peer_entry->last_transmitted_size =
644 #endif
645  env = GNUNET_MQ_msg_copy (&size_estimate_messages[idx].header);
646  GNUNET_MQ_send (peer_entry->mq, env);
647 }
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_copy(const struct GNUNET_MessageHeader *hdr)
Create a new envelope by copying an existing message.
Definition: mq.c:653
int previous_round
Did we receive or send a message about the previous round to this peer yet? GNUNET_YES if the previou...
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:673
static struct GNUNET_TIME_Relative get_transmit_delay(int round_offset)
Get the transmission delay that should be applied for a particular round.
const struct GNUNET_PeerIdentity * id
What is the identity of the peer?
static struct GNUNET_SCHEDULER_Task * proof_task
Task scheduled to compute our proof.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define HISTORY_SIZE
Over how many values do we calculate the weighted average?
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 void transmit_task_cb(void *cls)
Task that triggers a NSE P2P transmission.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1253
static unsigned int estimate_index
Index of most recent estimate.
static struct GNUNET_NSE_FloodMessage size_estimate_messages[64]
Array of recent size estimate messages.
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GNUNET_SCHEDULER_Task * transmit_task
Task scheduled to send message to this peer.
struct GNUNET_MQ_Handle * mq
Core handle for sending messages to this peer.
#define GNUNET_log(kind,...)
#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:353
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:742
static unsigned long long matching_bits
Number of matching bits required for revocation.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Per-peer information.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_network_size_estimate()

static void update_network_size_estimate ( )
static

We've sent on our flood message or one that we received which was validated and closer than ours.

Update the global list of recent messages and the average. Also re-broadcast the message to any clients.

Definition at line 657 of file gnunet-service-nse.c.

References GNUNET_notification_context_broadcast(), GNUNET_YES, GNUNET_NSE_ClientMessage::header, and setup_estimate_message().

Referenced by handle_p2p_estimate().

658 {
659  struct GNUNET_NSE_ClientMessage em;
660 
663 }
Network size estimate sent from the service to clients.
Definition: nse.h:42
static struct GNUNET_NotificationContext * nc
Notification context, simplifies client broadcasts.
static void setup_estimate_message(struct GNUNET_NSE_ClientMessage *em)
Initialize a message to clients with the current network size estimate.
void GNUNET_notification_context_broadcast(struct GNUNET_NotificationContext *nc, const struct GNUNET_MessageHeader *msg, int can_drop)
Send a message to all subscribers of this context.
Definition: nc.c:189
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_flood_message()

static void setup_flood_message ( unsigned int  slot,
struct GNUNET_TIME_Absolute  ts 
)
static

Setup a flood message in our history array at the given slot offset for the given timestamp.

Parameters
slotindex to use
tstimestamp to use

Definition at line 674 of file gnunet-service-nse.c.

References get_matching_bits(), GNUNET_assert, GNUNET_CRYPTO_eddsa_sign(), GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD, GNUNET_OK, GNUNET_SIGNATURE_PURPOSE_NSE_SEND, GNUNET_TIME_absolute_hton(), GNUNET_NSE_FloodMessage::header, GNUNET_NSE_FloodMessage::hop_count, matching_bits, GNUNET_NSE_FloodMessage::matching_bits, my_identity, my_proof, nse_work_required, GNUNET_NSE_FloodMessage::origin, GNUNET_NSE_FloodMessage::proof_of_work, GNUNET_CRYPTO_EccSignaturePurpose::purpose, GNUNET_NSE_FloodMessage::purpose, GNUNET_NSE_FloodMessage::signature, GNUNET_CRYPTO_EccSignaturePurpose::size, GNUNET_MessageHeader::size, size_estimate_messages, GNUNET_NSE_FloodMessage::timestamp, and GNUNET_MessageHeader::type.

Referenced by core_init(), find_proof(), and update_flood_message().

675 {
676  struct GNUNET_NSE_FloodMessage *fm;
677  uint32_t matching_bits;
678 
679  matching_bits = get_matching_bits (ts, &my_identity);
680  fm = &size_estimate_messages[slot];
681  fm->header.size = htons (sizeof(struct GNUNET_NSE_FloodMessage));
683  fm->hop_count = htonl (0);
685  fm->purpose.size =
686  htonl (sizeof(struct GNUNET_NSE_FloodMessage)
687  - sizeof(struct GNUNET_MessageHeader) - sizeof(uint32_t)
688  - sizeof(struct GNUNET_CRYPTO_EddsaSignature));
689  fm->matching_bits = htonl (matching_bits);
691  fm->origin = my_identity;
692  fm->proof_of_work = my_proof;
693  if (nse_work_required > 0)
695  &fm->purpose,
696  &fm->signature));
697  else
698  memset (&fm->signature, 0, sizeof(fm->signature));
699 }
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD
P2P message sent from nearest peer.
uint32_t matching_bits
Number of matching bits between the hash of timestamp and the initiator&#39;s public key.
int GNUNET_CRYPTO_eddsa_sign(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
EdDSA sign a given block.
Definition: crypto_ecc.c:987
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
static struct GNUNET_PeerIdentity my_identity
The peer identity of this peer.
static unsigned long long nse_work_required
Amount of work required (W-bit collisions) for NSE proofs, in collision-bits.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
struct GNUNET_CRYPTO_EddsaSignature signature
Signature (over range specified in purpose).
Network size estimate reply; sent when "this" peer&#39;s timer has run out before receiving a valid reply...
static uint32_t get_matching_bits(struct GNUNET_TIME_Absolute timestamp, const struct GNUNET_PeerIdentity *id)
Get the number of matching bits that the given timestamp has to the given peer ID.
static struct GNUNET_NSE_FloodMessage size_estimate_messages[64]
Array of recent size estimate messages.
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!)...
struct GNUNET_PeerIdentity origin
Public key of the originator.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose.
uint64_t proof_of_work
Proof of work, causing leading zeros when hashed with pkey.
an ECC signature using EdDSA.
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD.
struct GNUNET_TIME_AbsoluteNBO timestamp
The current timestamp value (which all peers should agree on).
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
The private key of this peer.
static uint64_t my_proof
Proof of work for this peer.
uint32_t hop_count
Number of hops this message has taken so far.
#define GNUNET_SIGNATURE_PURPOSE_NSE_SEND
Signature of a network size estimate message.
Header for all communications.
static unsigned long long matching_bits
Number of matching bits required for revocation.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:657
Here is the call graph for this function:
Here is the caller graph for this function:

◆ schedule_current_round()

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

Schedule transmission for the given peer for the current round based on what we know about the desired delay.

Parameters
clsunused
keyhash of peer identity
valuethe struct NSEPeerEntry
Returns
GNUNET_OK (continue to iterate)

Definition at line 712 of file gnunet-service-nse.c.

References get_transmit_delay(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_update(), NSEPeerEntry::previous_round, NSEPeerEntry::transmit_task, transmit_task_cb(), and value.

Referenced by update_flood_message().

715 {
716  struct NSEPeerEntry *peer_entry = value;
718 
719  (void) cls;
720  (void) key;
721  if (NULL != peer_entry->transmit_task)
722  {
724  peer_entry->previous_round = GNUNET_NO;
725  }
726 #if ENABLE_NSE_HISTOGRAM
727  if (peer_entry->received_messages > 1)
729  "# extra messages",
730  peer_entry->received_messages - 1,
731  GNUNET_NO);
732  peer_entry->transmitted_messages = 0;
733  peer_entry->last_transmitted_size = 0;
734  peer_entry->received_messages = 0;
735 #endif
736  delay =
737  get_transmit_delay ((GNUNET_NO == peer_entry->previous_round) ? -1 : 0);
738  peer_entry->transmit_task =
740  return GNUNET_OK;
741 }
int previous_round
Did we receive or send a message about the previous round to this peer yet? GNUNET_YES if the previou...
static struct GNUNET_TIME_Relative get_transmit_delay(int round_offset)
Get the transmission delay that should be applied for a particular round.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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 void transmit_task_cb(void *cls)
Task that triggers a NSE P2P transmission.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1253
static char * value
Value of the record to add/remove.
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
struct GNUNET_SCHEDULER_Task * transmit_task
Task scheduled to send message to this peer.
Time for relative time used by GNUnet, in microseconds.
Per-peer information.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_flood_message()

static void update_flood_message ( void *  cls)
static

Update our flood message to be sent (and our timestamps).

Parameters
clsunused

Definition at line 750 of file gnunet-service-nse.c.

References GNUNET_TIME_Absolute::abs_value_us, current_timestamp, estimate_count, estimate_index, get_matching_bits(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_MAX, gnunet_nse_interval, GNUNET_SCHEDULER_add_at(), GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_absolute_add(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_absolute_ntoh(), HISTORY_SIZE, GNUNET_NSE_FloodMessage::hop_count, hop_count_max, GNUNET_NSE_FloodMessage::matching_bits, my_identity, next_message, next_timestamp, GNUNET_TIME_Relative::rel_value_us, schedule_current_round(), setup_flood_message(), size_estimate_messages, and GNUNET_NSE_FloodMessage::timestamp.

Referenced by core_init().

751 {
752  struct GNUNET_TIME_Relative offset;
753 
754  (void) cls;
755  flood_task = NULL;
757  if (0 != offset.rel_value_us)
758  {
759  /* somehow run early, delay more */
760  flood_task =
762  return;
763  }
766  estimate_count++;
773  ntohl (next_message.matching_bits)))
774  {
775  /* we received a message for this round way early, use it! */
778  htonl (1 + ntohl (next_message.hop_count));
779  }
780  else
782  next_message.matching_bits = htonl (0); /* reset for 'next' round */
783  hop_count_max = 0;
784  for (unsigned int i = 0; i < HISTORY_SIZE; i++)
785  hop_count_max =
786  GNUNET_MAX (ntohl (size_estimate_messages[i].hop_count), hop_count_max);
788  flood_task =
790 }
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:673
static struct GNUNET_CONTAINER_MultiPeerMap * peers
Map of all connected peers.
static struct GNUNET_SCHEDULER_Task * flood_task
Task scheduled to update our flood message for the next round.
uint32_t matching_bits
Number of matching bits between the hash of timestamp and the initiator&#39;s public key.
static struct GNUNET_NSE_FloodMessage next_message
Message for the next round, if we got any.
static int schedule_current_round(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Schedule transmission for the given peer for the current round based on what we know about the desire...
#define HISTORY_SIZE
Over how many values do we calculate the weighted average?
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition: time.c:395
static struct GNUNET_PeerIdentity my_identity
The peer identity of this peer.
static struct GNUNET_TIME_Relative gnunet_nse_interval
Interval for sending network size estimation flood requests.
uint64_t abs_value_us
The actual value.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1253
static uint32_t hop_count_max
Current hop counter estimate (estimate for network diameter).
#define GNUNET_MAX(a, b)
Definition: gnunet_common.h:82
static uint32_t get_matching_bits(struct GNUNET_TIME_Absolute timestamp, const struct GNUNET_PeerIdentity *id)
Get the number of matching bits that the given timestamp has to the given peer ID.
static unsigned int estimate_index
Index of most recent estimate.
static struct GNUNET_NSE_FloodMessage size_estimate_messages[64]
Array of recent size estimate messages.
struct GNUNET_TIME_AbsoluteNBO timestamp
The current timestamp value (which all peers should agree on).
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 unsigned int estimate_count
Number of valid entries in the history.
static struct GNUNET_TIME_Absolute next_timestamp
The next major time.
static struct GNUNET_TIME_Absolute current_timestamp
The current major time.
uint32_t hop_count
Number of hops this message has taken so far.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_at(struct GNUNET_TIME_Absolute at, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run at the specified time.
Definition: scheduler.c:1230
static void update_flood_message(void *cls)
Update our flood message to be sent (and our timestamps).
static void setup_flood_message(unsigned int slot, struct GNUNET_TIME_Absolute ts)
Setup a flood message in our history array at the given slot offset for the given timestamp...
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ count_leading_zeroes()

static unsigned int count_leading_zeroes ( const struct GNUNET_HashCode hash)
static

Count the leading zeroes in hash.

Parameters
hashto count leading zeros in
Returns
the number of leading zero bits.

Definition at line 800 of file gnunet-service-nse.c.

References GNUNET_CRYPTO_hash_get_bit().

Referenced by check_proof_of_work(), and find_proof().

801 {
802  unsigned int hash_count;
803 
804  hash_count = 0;
805  while (0 == GNUNET_CRYPTO_hash_get_bit (hash, hash_count))
806  hash_count++;
807  return hash_count;
808 }
int GNUNET_CRYPTO_hash_get_bit(const struct GNUNET_HashCode *code, unsigned int bit)
Obtain a bit from a hashcode.
Definition: crypto_hash.c:251
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_proof_of_work()

static int check_proof_of_work ( const struct GNUNET_CRYPTO_EddsaPublicKey pkey,
uint64_t  val 
)
static

Check whether the given public key and integer are a valid proof of work.

Parameters
pkeythe public key
valthe integer
Returns
GNUNET_YES if valid, GNUNET_NO if not

Definition at line 820 of file gnunet-service-nse.c.

References buf, count_leading_zeroes(), GNUNET_memcpy, GNUNET_NO, GNUNET_YES, nse_work_required, and pow_hash().

Referenced by core_init(), and verify_message_crypto().

822 {
823  char buf[sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)
824  + sizeof(val)] GNUNET_ALIGN;
825  struct GNUNET_HashCode result;
826 
827  GNUNET_memcpy (buf, &val, sizeof(val));
828  GNUNET_memcpy (&buf[sizeof(val)],
829  pkey,
830  sizeof(struct GNUNET_CRYPTO_EddsaPublicKey));
831  pow_hash (buf, sizeof(buf), &result);
833  : GNUNET_NO;
834 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_NO
Definition: gnunet_common.h:78
static unsigned long long nse_work_required
Amount of work required (W-bit collisions) for NSE proofs, in collision-bits.
static char buf[2048]
static int result
Global testing status.
A 512-bit hashcode.
static void pow_hash(const void *buf, size_t buf_len, struct GNUNET_HashCode *result)
Calculate the &#39;proof-of-work&#39; hash (an expensive hash).
static unsigned int count_leading_zeroes(const struct GNUNET_HashCode *hash)
Count the leading zeroes in hash.
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to &#39;struct&#39;s...
#define GNUNET_YES
Definition: gnunet_common.h:77
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ write_proof()

static void write_proof ( )
static

Write our current proof to disk.

Definition at line 841 of file gnunet-service-nse.c.

References GNUNET_CONFIGURATION_get_value_filename(), GNUNET_DISK_fn_write(), GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log_strerror_file, GNUNET_OK, my_proof, and proof.

Referenced by find_proof(), and shutdown_task().

842 {
843  char *proof;
844 
845  if (GNUNET_OK !=
846  GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof))
847  return;
848  if (sizeof(my_proof) != GNUNET_DISK_fn_write (proof,
849  &my_proof,
850  sizeof(my_proof),
854  GNUNET_free (proof);
855 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
ssize_t GNUNET_DISK_fn_write(const char *fn, const void *buffer, size_t n, enum GNUNET_DISK_AccessPermissions mode)
Write a buffer to a file.
Definition: disk.c:880
static uint64_t proof
Definition: gnunet-scrypt.c:41
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level &#39;level&#39; that indicates a failure of the command &#39;cmd&#39; with the mess...
static uint64_t my_proof
Proof of work for this peer.
int GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
#define GNUNET_free(ptr)
Wrapper around free.
static GNUNET_NETWORK_STRUCT_END const struct GNUNET_CONFIGURATION_Handle * cfg
Handle to our current configuration.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_proof()

static void find_proof ( void *  cls)
static

Find our proof of work.

Parameters
clsclosure (unused)

Definition at line 864 of file gnunet-service-nse.c.

References buf, count_leading_zeroes(), current_timestamp, estimate_index, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_memcpy, GNUNET_ntohll(), GNUNET_SCHEDULER_add_delayed_with_priority(), GNUNET_SCHEDULER_PRIORITY_IDLE, my_identity, my_proof, nse_work_required, pow_hash(), proof_find_delay, ROUND_SIZE, setup_flood_message(), and write_proof().

Referenced by run().

865 {
866 #define ROUND_SIZE 10
867  uint64_t counter;
868  char buf[sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)
869  + sizeof(uint64_t)] GNUNET_ALIGN;
870  struct GNUNET_HashCode result;
871  unsigned int i;
872 
873  (void) cls;
874  proof_task = NULL;
875  GNUNET_memcpy (&buf[sizeof(uint64_t)],
876  &my_identity,
877  sizeof(struct GNUNET_PeerIdentity));
878  i = 0;
879  counter = my_proof;
880  while ((counter != UINT64_MAX) && (i < ROUND_SIZE))
881  {
882  GNUNET_memcpy (buf, &counter, sizeof(uint64_t));
883  pow_hash (buf, sizeof(buf), &result);
885  {
886  my_proof = counter;
888  "Proof of work found: %llu!\n",
889  (unsigned long long) GNUNET_ntohll (counter));
890  write_proof ();
892  return;
893  }
894  counter++;
895  i++;
896  }
897  if (my_proof / (100 * ROUND_SIZE) < counter / (100 * ROUND_SIZE))
898  {
900  "Testing proofs currently at %llu\n",
901  (unsigned long long) counter);
902  /* remember progress every 100 rounds */
903  my_proof = counter;
904  write_proof ();
905  }
906  else
907  {
908  my_proof = counter;
909  }
910  proof_task =
913  &find_proof,
914  NULL);
915 }
static struct GNUNET_TIME_Relative proof_find_delay
Interval between proof find runs.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed_with_priority(struct GNUNET_TIME_Relative delay, enum GNUNET_SCHEDULER_Priority priority, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1183
static struct GNUNET_SCHEDULER_Task * proof_task
Task scheduled to compute our proof.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static struct GNUNET_PeerIdentity my_identity
The peer identity of this peer.
static unsigned long long nse_work_required
Amount of work required (W-bit collisions) for NSE proofs, in collision-bits.
static void write_proof()
Write our current proof to disk.
static void find_proof(void *cls)
Find our proof of work.
static unsigned int estimate_index
Index of most recent estimate.
static char buf[2048]
static int result
Global testing status.
A 512-bit hashcode.
static void pow_hash(const void *buf, size_t buf_len, struct GNUNET_HashCode *result)
Calculate the &#39;proof-of-work&#39; hash (an expensive hash).
Run when otherwise idle.
static unsigned int count_leading_zeroes(const struct GNUNET_HashCode *hash)
Count the leading zeroes in hash.
#define ROUND_SIZE
The identity of the host (wraps the signing key of the peer).
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to &#39;struct&#39;s...
static uint64_t my_proof
Proof of work for this peer.
static struct GNUNET_TIME_Absolute current_timestamp
The current major time.
#define GNUNET_log(kind,...)
static void setup_flood_message(unsigned int slot, struct GNUNET_TIME_Absolute ts)
Setup a flood message in our history array at the given slot offset for the given timestamp...
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ verify_message_crypto()

static int verify_message_crypto ( const struct GNUNET_NSE_FloodMessage incoming_flood)
static

An incoming flood message has been received which claims to have more bits matching than any we know in this time period.

Verify the signature and/or proof of work.

Parameters
incoming_floodthe message to verify
Returns
GNUNET_YES if the message is verified GNUNET_NO if the key/signature don't verify

Definition at line 928 of file gnunet-service-nse.c.

References check_proof_of_work(), GNUNET_break_op, GNUNET_CRYPTO_eddsa_verify(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_ntohll(), GNUNET_OK, GNUNET_SIGNATURE_PURPOSE_NSE_SEND, GNUNET_YES, nse_work_required, GNUNET_NSE_FloodMessage::origin, GNUNET_NSE_FloodMessage::proof_of_work, GNUNET_PeerIdentity::public_key, GNUNET_NSE_FloodMessage::purpose, and GNUNET_NSE_FloodMessage::signature.

Referenced by handle_p2p_estimate().

929 {
930  if (GNUNET_YES != check_proof_of_work (&incoming_flood->origin.public_key,
931  incoming_flood->proof_of_work))
932  {
934  "Proof of work invalid: %llu!\n",
935  (unsigned long long) GNUNET_ntohll (
936  incoming_flood->proof_of_work));
937  GNUNET_break_op (0);
938  return GNUNET_NO;
939  }
940  if ((nse_work_required > 0) &&
941  (GNUNET_OK !=
943  &incoming_flood->purpose,
944  &incoming_flood->signature,
945  &incoming_flood->origin.public_key)))
946  {
947  GNUNET_break_op (0);
948  return GNUNET_NO;
949  }
950  return GNUNET_YES;
951 }
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static unsigned long long nse_work_required
Amount of work required (W-bit collisions) for NSE proofs, in collision-bits.
int GNUNET_CRYPTO_eddsa_verify(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Verify EdDSA signature.
Definition: crypto_ecc.c:1114
struct GNUNET_CRYPTO_EddsaSignature signature
Signature (over range specified in purpose).
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
struct GNUNET_PeerIdentity origin
Public key of the originator.
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose.
uint64_t proof_of_work
Proof of work, causing leading zeros when hashed with pkey.
static int check_proof_of_work(const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, uint64_t val)
Check whether the given public key and integer are a valid proof of work.
#define GNUNET_log(kind,...)
#define GNUNET_SIGNATURE_PURPOSE_NSE_SEND
Signature of a network size estimate message.
#define GNUNET_YES
Definition: gnunet_common.h:77
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_flood_times()

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

Update transmissions for the given peer for the current round based on updated proximity information.

Parameters
clspeer entry to exclude from updates
keyhash of peer identity
valuethe struct NSEPeerEntry * of a peer to transmit to
Returns
GNUNET_OK (continue to iterate)

Definition at line 964 of file gnunet-service-nse.c.

References get_transmit_delay(), GNUNET_break, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), NSEPeerEntry::previous_round, NSEPeerEntry::transmit_task, transmit_task_cb(), and value.

Referenced by handle_p2p_estimate().

967 {
968  struct NSEPeerEntry *exclude = cls;
969  struct NSEPeerEntry *peer_entry = value;
971 
972  (void) key;
973  if (peer_entry == exclude)
974  return GNUNET_OK; /* trigger of the update */
975  if (GNUNET_NO == peer_entry->previous_round)
976  {
977  /* still stuck in previous round, no point to update, check that
978  * we are active here though... */
979  if (NULL == peer_entry->transmit_task)
980  {
981  GNUNET_break (0);
982  }
983  return GNUNET_OK;
984  }
985  if (NULL != peer_entry->transmit_task)
986  {
988  peer_entry->transmit_task = NULL;
989  }
991  peer_entry->transmit_task =
993  return GNUNET_OK;
994 }
int previous_round
Did we receive or send a message about the previous round to this peer yet? GNUNET_YES if the previou...
static struct GNUNET_TIME_Relative get_transmit_delay(int round_offset)
Get the transmission delay that should be applied for a particular round.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static void transmit_task_cb(void *cls)
Task that triggers a NSE P2P transmission.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1253
static char * value
Value of the record to add/remove.
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
struct GNUNET_SCHEDULER_Task * transmit_task
Task scheduled to send message to this peer.
Time for relative time used by GNUnet, in microseconds.
Per-peer information.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_p2p_estimate()

static void handle_p2p_estimate ( void *  cls,
const struct GNUNET_NSE_FloodMessage incoming_flood 
)
static

Core handler for size estimate flooding messages.

Parameters
clspeer this message is from
incoming_floodreceived message

Definition at line 1004 of file gnunet-service-nse.c.

References GNUNET_TIME_Absolute::abs_value_us, current_timestamp, estimate_index, GNUNET_assert, GNUNET_BIO_write_int64(), GNUNET_break_op, GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_i2s(), GNUNET_log, GNUNET_MAX, GNUNET_memcmp, GNUNET_NO, gnunet_nse_interval, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_snprintf(), GNUNET_STATISTICS_set(), GNUNET_STATISTICS_update(), GNUNET_STRINGS_absolute_time_to_string(), GNUNET_TESTBED_LOGGER_write(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_ntoh(), GNUNET_YES, HISTORY_SIZE, GNUNET_NSE_FloodMessage::hop_count, hop_count_max, NSEPeerEntry::id, matching_bits, GNUNET_NSE_FloodMessage::matching_bits, my_identity, next_message, next_timestamp, GNUNET_NSE_FloodMessage::origin, NSEPeerEntry::previous_round, GNUNET_TIME_Relative::rel_value_us, size_estimate_messages, t, GNUNET_NSE_FloodMessage::timestamp, NSEPeerEntry::transmit_task, transmit_task_cb(), update_flood_times(), update_network_size_estimate(), and verify_message_crypto().

1006 {
1007  struct NSEPeerEntry *peer_entry = cls;
1008  struct GNUNET_TIME_Absolute ts;
1009  uint32_t matching_bits;
1010  unsigned int idx;
1011 
1012 #if ENABLE_NSE_HISTOGRAM
1013  {
1014  uint64_t t;
1015 
1017  if (NULL != lh)
1018  GNUNET_TESTBED_LOGGER_write (lh, &t, sizeof(uint64_t));
1019  if (NULL != histogram)
1020  GNUNET_BIO_write_int64 (histogram, t);
1021  }
1022 #endif
1023  GNUNET_STATISTICS_update (stats, "# flood messages received", 1, GNUNET_NO);
1024  matching_bits = ntohl (incoming_flood->matching_bits);
1025 #if DEBUG_NSE
1026  {
1027  char origin[5];
1028  char pred[5];
1029  struct GNUNET_PeerIdentity os;
1030 
1031  GNUNET_snprintf (origin,
1032  sizeof(origin),
1033  "%s",
1034  GNUNET_i2s (&incoming_flood->origin));
1035  GNUNET_snprintf (pred, sizeof(pred), "%s", GNUNET_i2s (peer_entry->id));
1037  "Flood at %s from `%s' via `%s' at `%s' with bits %u\n",
1039  GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp)),
1040  origin,
1041  pred,
1043  (unsigned int) matching_bits);
1044  }
1045 #endif
1046 
1047 #if ENABLE_NSE_HISTOGRAM
1048  peer_entry->received_messages++;
1049  if ((peer_entry->transmitted_messages > 0) &&
1050  (peer_entry->last_transmitted_size >= matching_bits) )
1051  GNUNET_STATISTICS_update (stats, "# cross messages", 1, GNUNET_NO);
1052 #endif
1053 
1054  ts = GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp);
1055  if (ts.abs_value_us == current_timestamp.abs_value_us)
1056  idx = estimate_index;
1057  else if (ts.abs_value_us ==
1059  idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE;
1060  else if (ts.abs_value_us == next_timestamp.abs_value_us)
1061  {
1062  if (matching_bits <= ntohl (next_message.matching_bits))
1063  return; /* ignore, simply too early/late */
1064  if (GNUNET_YES != verify_message_crypto (incoming_flood))
1065  {
1067  "Peer %s is likely ill-configured!\n",
1068  GNUNET_i2s (peer_entry->id));
1069  GNUNET_break_op (0);
1070  return;
1071  }
1072  next_message = *incoming_flood;
1073  return;
1074  }
1075  else
1076  {
1078  "# flood messages discarded (clock skew too large)",
1079  1,
1080  GNUNET_NO);
1081  return;
1082  }
1083  if (0 == (GNUNET_memcmp (peer_entry->id, &my_identity)))
1084  {
1085  /* send to self, update our own estimate IF this also comes from us! */
1086  if (0 == GNUNET_memcmp (&incoming_flood->origin, &my_identity))
1088  return;
1089  }
1090  if (matching_bits == ntohl (size_estimate_messages[idx].matching_bits))
1091  {
1092  /* Cancel transmission in the other direction, as this peer clearly has
1093  up-to-date information already. Even if we didn't talk to this peer in
1094  the previous round, we should no longer send it stale information as it
1095  told us about the current round! */
1096  peer_entry->previous_round = GNUNET_YES;
1097  if (idx != estimate_index)
1098  {
1099  /* do not transmit information for the previous round to this peer
1100  anymore (but allow current round) */
1101  return;
1102  }
1103  /* got up-to-date information for current round, cancel transmission to
1104  * this peer altogether */
1105  if (NULL != peer_entry->transmit_task)
1106  {
1107  GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
1108  peer_entry->transmit_task = NULL;
1109  }
1110  return;
1111  }
1112  if (matching_bits < ntohl (size_estimate_messages[idx].matching_bits))
1113  {
1114  if ((idx < estimate_index) && (peer_entry->previous_round == GNUNET_YES))
1115  {
1116  peer_entry->previous_round = GNUNET_NO;
1117  }
1118  /* push back our result now, that peer is spreading bad information... */
1119  if (NULL != peer_entry->transmit_task)
1120  GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
1121  peer_entry->transmit_task =
1123  /* Not closer than our most recent message, no need to do work here */
1125  "# flood messages ignored (had closer already)",
1126  1,
1127  GNUNET_NO);
1128  return;
1129  }
1130  if (GNUNET_YES != verify_message_crypto (incoming_flood))
1131  {
1132  GNUNET_break_op (0);
1133  return;
1134  }
1135  GNUNET_assert (matching_bits >
1136  ntohl (size_estimate_messages[idx].matching_bits));
1137  /* Cancel transmission in the other direction, as this peer clearly has
1138  * up-to-date information already.
1139  */
1140  peer_entry->previous_round = GNUNET_YES;
1141  if (idx == estimate_index)
1142  {
1143  /* cancel any activity for current round */
1144  if (NULL != peer_entry->transmit_task)
1145  {
1146  GNUNET_SCHEDULER_cancel (peer_entry->transmit_task);
1147  peer_entry->transmit_task = NULL;
1148  }
1149  }
1150  size_estimate_messages[idx] = *incoming_flood;
1152  htonl (ntohl (incoming_flood->hop_count) + 1);
1153  hop_count_max =
1154  GNUNET_MAX (ntohl (incoming_flood->hop_count) + 1, hop_count_max);
1156  "# estimated network diameter",
1157  hop_count_max,
1158  GNUNET_NO);
1159 
1160  /* have a new, better size estimate, inform clients */
1162 
1163  /* flood to rest */
1166  peer_entry);
1167 }
int previous_round
Did we receive or send a message about the previous round to this peer yet? GNUNET_YES if the previou...
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:673
uint64_t rel_value_us
The actual value.
static int update_flood_times(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Update transmissions for the given peer for the current round based on updated proximity information...
const struct GNUNET_PeerIdentity * id
What is the identity of the peer?
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
static struct GNUNET_CONTAINER_MultiPeerMap * peers
Map of all connected peers.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int GNUNET_BIO_write_int64(struct GNUNET_BIO_WriteHandle *h, int64_t i)
Write an (u)int64_t.
Definition: bio.c:599
uint32_t matching_bits
Number of matching bits between the hash of timestamp and the initiator&#39;s public key.
static struct GNUNET_NSE_FloodMessage next_message
Message for the next round, if we got any.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define HISTORY_SIZE
Over how many values do we calculate the weighted average?
static struct GNUNET_SCHEDULER_Task * t
Main task.
static struct GNUNET_PeerIdentity my_identity
The peer identity of this peer.
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_TIME_Relative gnunet_nse_interval
Interval for sending network size estimation flood requests.
uint64_t abs_value_us
The actual value.
static void transmit_task_cb(void *cls)
Task that triggers a NSE P2P transmission.
static uint32_t hop_count_max
Current hop counter estimate (estimate for network diameter).
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_MAX(a, b)
Definition: gnunet_common.h:82
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:1280
static unsigned int estimate_index
Index of most recent estimate.
static struct GNUNET_NSE_FloodMessage size_estimate_messages[64]
Array of recent size estimate messages.
struct GNUNET_PeerIdentity origin
Public key of the originator.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
struct GNUNET_SCHEDULER_Task * transmit_task
Task scheduled to send message to this peer.
static void update_network_size_estimate()
We&#39;ve sent on our flood message or one that we received which was validated and closer than ours...
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
struct GNUNET_TIME_AbsoluteNBO timestamp
The current timestamp value (which all peers should agree on).
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
The identity of the host (wraps the signing key of the peer).
static struct GNUNET_TIME_Absolute next_timestamp
The next major time.
static struct GNUNET_TIME_Absolute current_timestamp
The current major time.
#define GNUNET_log(kind,...)
uint32_t hop_count
Number of hops this message has taken so far.
void GNUNET_TESTBED_LOGGER_write(struct GNUNET_TESTBED_LOGGER_Handle *h, const void *data, size_t size)
Send data to be logged to the logger service.
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:77
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:742
static unsigned long long matching_bits
Number of matching bits required for revocation.
static ogg_stream_state os
Ogg stream state.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
static int verify_message_crypto(const struct GNUNET_NSE_FloodMessage *incoming_flood)
An incoming flood message has been received which claims to have more bits matching than any we know ...
Per-peer information.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:

◆ handle_core_connect()

static void* handle_core_connect ( void *  cls,
const struct GNUNET_PeerIdentity peer,
struct GNUNET_MQ_Handle mq 
)
static

Method called whenever a peer connects.

Sets up the PeerEntry and schedules the initial size info transmission to this peer.

Parameters
clsclosure
peerpeer identity this notification is about

Definition at line 1178 of file gnunet-service-nse.c.

References get_transmit_delay(), GNUNET_assert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_put(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_MQ_set_options(), GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_STATISTICS_update(), NSEPeerEntry::id, NSEPeerEntry::mq, NSE_PRIORITY, peer, NSEPeerEntry::transmit_task, and transmit_task_cb().

Referenced by run().

1181 {
1182  struct NSEPeerEntry *peer_entry;
1183 
1184  (void) cls;
1186  "Peer `%s' connected to us\n",
1187  GNUNET_i2s (peer));
1188  /* set our default transmission options */
1190  /* create our peer entry for this peer */
1191  peer_entry = GNUNET_new (struct NSEPeerEntry);
1192  peer_entry->id = peer;
1193  peer_entry->mq = mq;
1196  peers,
1197  peer_entry->id,
1198  peer_entry,
1200  peer_entry->transmit_task =
1203  peer_entry);
1204  GNUNET_STATISTICS_update (stats, "# peers connected", 1, GNUNET_NO);
1205  return peer_entry;
1206 }
static struct GNUNET_TIME_Relative get_transmit_delay(int round_offset)
Get the transmission delay that should be applied for a particular round.
const struct GNUNET_PeerIdentity * id
What is the identity of the peer?
static struct GNUNET_CONTAINER_MultiPeerMap * peers
Map of all connected peers.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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 void transmit_task_cb(void *cls)
Task that triggers a NSE P2P transmission.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1253
#define NSE_PRIORITY
Message priority to use.
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_SCHEDULER_Task * transmit_task
Task scheduled to send message to this peer.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
void GNUNET_MQ_set_options(struct GNUNET_MQ_Handle *mq, enum GNUNET_MQ_PriorityPreferences pp)
Set application-specific options for this queue.
Definition: mq.c:1066
struct GNUNET_MQ_Handle * mq
Core handle for sending messages to this peer.
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_log(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Per-peer information.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_core_disconnect()

static void handle_core_disconnect ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  internal_cls 
)
static

Method called whenever a peer disconnects.

Deletes the PeerEntry and cancels any pending transmission requests to that peer.

Parameters
clsclosure
peerpeer identity this notification is about internal_cls the struct NSEPeerEntry for the peer

Definition at line 1218 of file gnunet-service-nse.c.

References GNUNET_assert, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_update(), GNUNET_TESTBED_LOGGER_disconnect(), GNUNET_YES, size, and NSEPeerEntry::transmit_task.

Referenced by run().

1221 {
1222  struct NSEPeerEntry *pos = internal_cls;
1223 
1224  (void) cls;
1226  "Peer `%s' disconnected from us\n",
1227  GNUNET_i2s (peer));
1230  if (NULL != pos->transmit_task)
1231  {
1233  pos->transmit_task = NULL;
1234  }
1235  GNUNET_free (pos);
1236  GNUNET_STATISTICS_update (stats, "# peers connected", -1, GNUNET_NO);
1237 }
static struct GNUNET_CONTAINER_MultiPeerMap * peers
Map of all connected peers.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
struct GNUNET_SCHEDULER_Task * transmit_task
Task scheduled to send message to this peer.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
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.
Per-peer information.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ shutdown_task()

static void shutdown_task ( void *  cls)
static

Task run during shutdown.

Parameters
clsunused

Definition at line 1267 of file gnunet-service-nse.c.

References GNUNET_BIO_write_close(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CORE_disconnect(), GNUNET_free, GNUNET_NO, GNUNET_notification_context_destroy(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_destroy(), GNUNET_TESTBED_LOGGER_flush(), and write_proof().

Referenced by run().

1268 {
1269  (void) cls;
1270  if (NULL != flood_task)
1271  {
1273  flood_task = NULL;
1274  }
1275  if (NULL != proof_task)
1276  {
1278  proof_task = NULL;
1279  write_proof (); /* remember progress */
1280  }
1281  if (NULL != nc)
1282  {
1284  nc = NULL;
1285  }
1286  if (NULL != core_api)
1287  {
1289  core_api = NULL;
1290  }
1291  if (NULL != stats)
1292  {
1294  stats = NULL;
1295  }
1296  if (NULL != peers)
1297  {
1299  peers = NULL;
1300  }
1301  if (NULL != my_private_key)
1302  {
1304  my_private_key = NULL;
1305  }
1306 #if ENABLE_NSE_HISTOGRAM
1307  if (NULL != logger_test)
1308  {
1309  GNUNET_CLIENT_service_test_cancel (logger_test);
1310  logger_test = NULL;
1311  }
1312  if (NULL != lh)
1313  {
1314  GNUNET_TESTBED_LOGGER_flush (lh, &flush_comp_cb, NULL);
1315  }
1316  if (NULL != histogram)
1317  {
1318  GNUNET_BIO_write_close (histogram);
1319  histogram = NULL;
1320  }
1321 #endif
1322 }
static struct GNUNET_CONTAINER_MultiPeerMap * peers
Map of all connected peers.
static struct GNUNET_SCHEDULER_Task * proof_task
Task scheduled to compute our proof.
static struct GNUNET_SCHEDULER_Task * flood_task
Task scheduled to update our flood message for the next round.
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
static void write_proof()
Write our current proof to disk.
static struct GNUNET_NotificationContext * nc
Notification context, simplifies client broadcasts.
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
void GNUNET_CORE_disconnect(struct GNUNET_CORE_Handle *handle)
Disconnect from the core service.
Definition: core_api.c:730
int GNUNET_BIO_write_close(struct GNUNET_BIO_WriteHandle *h)
Close an open file for writing.
Definition: bio.c:438
static struct GNUNET_CORE_Handle * core_api
Handle to the core service.
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
The private key of this peer.
void GNUNET_notification_context_destroy(struct GNUNET_NotificationContext *nc)
Destroy the context, force disconnect for all subscribers.
Definition: nc.c:137
void GNUNET_TESTBED_LOGGER_flush(struct GNUNET_TESTBED_LOGGER_Handle *h, GNUNET_TESTBED_LOGGER_FlushCompletion cb, void *cb_cls)
Flush the buffered data to the logger service.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
Here is the call graph for this function:
Here is the caller graph for this function:

◆ core_init()

static void core_init ( void *  cls,
const struct GNUNET_PeerIdentity identity 
)
static

Called on core init/fail.

Parameters
clsservice closure
identitythe public identity of this peer

Definition at line 1332 of file gnunet-service-nse.c.

References GNUNET_TIME_Absolute::abs_value_us, check_proof_of_work(), current_timestamp, estimate_count, estimate_index, GNUNET_assert, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_memcmp, gnunet_nse_interval, GNUNET_SCHEDULER_add_at(), GNUNET_SCHEDULER_shutdown(), GNUNET_TESTBED_LOGGER_connect(), GNUNET_TIME_absolute_add(), GNUNET_TIME_absolute_get(), GNUNET_YES, HISTORY_SIZE, my_identity, my_proof, next_timestamp, GNUNET_PeerIdentity::public_key, GNUNET_TIME_Relative::rel_value_us, setup_flood_message(), status, and update_flood_message().

Referenced by run().

1333 {
1334  struct GNUNET_TIME_Absolute now;
1335  struct GNUNET_TIME_Absolute prev_time;
1336 
1337  (void) cls;
1338  if (NULL == identity)
1339  {
1340  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to core FAILED!\n");
1342  return;
1343  }
1344  GNUNET_assert (0 == GNUNET_memcmp (&my_identity, identity));
1345  now = GNUNET_TIME_absolute_get ();
1347  (now.abs_value_us / gnunet_nse_interval.rel_value_us)
1349  next_timestamp =
1352  estimate_count = 0;
1354  {
1355  int idx = (estimate_index + HISTORY_SIZE - 1) % HISTORY_SIZE;
1356  prev_time.abs_value_us =
1358  setup_flood_message (idx, prev_time);
1360  estimate_count++;
1361  }
1362  flood_task =
1364 }
uint64_t rel_value_us
The actual value.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_SCHEDULER_Task * flood_task
Task scheduled to update our flood message for the next round.
#define HISTORY_SIZE
Over how many values do we calculate the weighted average?
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition: time.c:395
static struct GNUNET_PeerIdentity my_identity
The peer identity of this peer.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:526
static struct GNUNET_TIME_Relative gnunet_nse_interval
Interval for sending network size estimation flood requests.
uint64_t abs_value_us
The actual value.
static unsigned int estimate_index
Index of most recent estimate.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
static unsigned int estimate_count
Number of valid entries in the history.
static struct GNUNET_TIME_Absolute next_timestamp
The next major time.
static int check_proof_of_work(const struct GNUNET_CRYPTO_EddsaPublicKey *pkey, uint64_t val)
Check whether the given public key and integer are a valid proof of work.
static uint64_t my_proof
Proof of work for this peer.
static struct GNUNET_TIME_Absolute current_timestamp
The current major time.
#define GNUNET_log(kind,...)
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_at(struct GNUNET_TIME_Absolute at, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run at the specified time.
Definition: scheduler.c:1230
static void update_flood_message(void *cls)
Update our flood message to be sent (and our timestamps).
static void setup_flood_message(unsigned int slot, struct GNUNET_TIME_Absolute ts)
Setup a flood message in our history array at the given slot offset for the given timestamp...
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
const struct GNUNET_CONFIGURATION_Handle c,
struct GNUNET_SERVICE_Handle service 
)
static

Handle network size estimate clients.

Parameters
clsclosure
cconfiguration to use
servicethe initialized service

Definition at line 1406 of file gnunet-service-nse.c.

References _, core_init(), find_proof(), GNUNET_asprintf(), GNUNET_assert, GNUNET_BIO_write_open(), GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_time(), GNUNET_CONTAINER_multipeermap_create(), GNUNET_CORE_connect(), GNUNET_CRYPTO_eddsa_key_create_from_configuration(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_DISK_file_test(), GNUNET_DISK_fn_read(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_log_config_invalid(), GNUNET_log_config_missing(), GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_notification_context_create(), gnunet_nse_interval, GNUNET_OK, GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_add_with_priority(), GNUNET_SCHEDULER_PRIORITY_IDLE, GNUNET_SCHEDULER_shutdown(), GNUNET_STATISTICS_create(), GNUNET_TIME_UNIT_SECONDS, GNUNET_YES, handle_core_connect(), handle_core_disconnect(), my_identity, my_proof, nse_work_required, pk, proof, proof_find_delay, GNUNET_PeerIdentity::public_key, and shutdown_task().

Referenced by client_disconnect_cb().

1409 {
1410  struct GNUNET_MQ_MessageHandler core_handlers[] =
1411  { GNUNET_MQ_hd_fixed_size (p2p_estimate,
1413  struct GNUNET_NSE_FloodMessage,
1414  NULL),
1415  GNUNET_MQ_handler_end () };
1416  char *proof;
1418 
1419  (void) cls;
1420  (void) service;
1421  cfg = c;
1423  "NSE",
1424  "INTERVAL",
1426  {
1429  return;
1430  }
1432  "NSE",
1433  "WORKDELAY",
1434  &proof_find_delay))
1435  {
1436  GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "WORKDELAY");
1438  return;
1439  }
1441  "NSE",
1442  "WORKBITS",
1444  {
1447  return;
1448  }
1449  if (nse_work_required >= sizeof(struct GNUNET_HashCode) * 8)
1450  {
1452  "NSE",
1453  "WORKBITS",
1454  _ ("Value is too large.\n"));
1456  return;
1457  }
1458 
1459 #if ENABLE_NSE_HISTOGRAM
1460  {
1461  char *histogram_dir;
1462  char *histogram_fn;
1463 
1465  "NSE",
1466  "HISTOGRAM_DIR",
1467  &histogram_dir))
1468  {
1469  GNUNET_assert (
1470  0 < GNUNET_asprintf (&histogram_fn, "%s/timestamps", histogram_dir));
1471  GNUNET_free (histogram_dir);
1472  histogram = GNUNET_BIO_write_open (histogram_fn);
1473  if (NULL == histogram)
1475  "Unable to open histogram file `%s'\n",
1476  histogram_fn);
1477  GNUNET_free (histogram_fn);
1478  }
1479  logger_test = GNUNET_CLIENT_service_test ("testbed-logger",
1480  cfg,
1482  &status_cb,
1483  NULL);
1484  }
1485 #endif
1486 
1489  GNUNET_assert (NULL != pk);
1490  my_private_key = pk;
1492  if (GNUNET_OK !=
1493  GNUNET_CONFIGURATION_get_value_filename (cfg, "NSE", "PROOFFILE", &proof))
1494  {
1495  GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "NSE", "PROOFFILE");
1497  my_private_key = NULL;
1499  return;
1500  }
1501  if ((GNUNET_YES != GNUNET_DISK_file_test (proof)) ||
1502  (sizeof(my_proof) !=
1503  GNUNET_DISK_fn_read (proof, &my_proof, sizeof(my_proof))))
1504  my_proof = 0;
1505  GNUNET_free (proof);
1506  proof_task =
1508  &find_proof,
1509  NULL);
1510 
1513  /* Connect to core service and register core handlers */
1514  core_api =
1515  GNUNET_CORE_connect (cfg, /* Main configuration */
1516  NULL, /* Closure passed to functions */
1517  &core_init, /* Call core_init once connected */
1518  &handle_core_connect, /* Handle connects */
1519  &handle_core_disconnect, /* Handle disconnects */
1520  core_handlers); /* Register these handlers */
1521  if (NULL == core_api)
1522  {
1524  return;
1525  }
1526  stats = GNUNET_STATISTICS_create ("nse", cfg);
1527 }
int GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory)...
Definition: disk.c:544
static struct GNUNET_CRYPTO_EddsaPrivateKey * pk
Private key of this peer.
int GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
static void shutdown_task(void *cls)
Task run during shutdown.
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 struct GNUNET_TIME_Relative proof_find_delay
Interval between proof find runs.
static void handle_core_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
Method called whenever a peer disconnects.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1300
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
static struct GNUNET_CONTAINER_MultiPeerMap * peers
Map of all connected peers.
static struct GNUNET_SCHEDULER_Task * proof_task
Task scheduled to compute our proof.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_MESSAGE_TYPE_NSE_P2P_FLOOD
P2P message sent from nearest peer.
#define GNUNET_TIME_UNIT_SECONDS
One second.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, const char *section, const char *option, const char *required)
Log error message about invalid configuration option value.
static struct GNUNET_PeerIdentity my_identity
The peer identity of this peer.
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:526
static struct GNUNET_TIME_Relative gnunet_nse_interval
Interval for sending network size estimation flood requests.
static unsigned long long nse_work_required
Amount of work required (W-bit collisions) for NSE proofs, in collision-bits.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_with_priority(enum GNUNET_SCHEDULER_Priority prio, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified priority.
Definition: scheduler.c:1207
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
static uint64_t proof
Definition: gnunet-scrypt.c:41
Network size estimate reply; sent when "this" peer&#39;s timer has run out before receiving a valid reply...
static void find_proof(void *cls)
Find our proof of work.
static struct GNUNET_NotificationContext * nc
Notification context, simplifies client broadcasts.
A 512-bit hashcode.
Message handler for a specific message type.
Run when otherwise idle.
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
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:692
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:270
static struct GNUNET_CORE_Handle * core_api
Handle to the core service.
struct GNUNET_NotificationContext * GNUNET_notification_context_create(unsigned int queue_length)
Create a new notification context.
Definition: nc.c:121
static void * handle_core_connect(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Method called whenever a peer connects.
Private ECC key encoded for transmission.
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
The private key of this peer.
struct GNUNET_BIO_WriteHandle * GNUNET_BIO_write_open(const char *fn)
Open a file for writing.
Definition: bio.c:410
static uint64_t my_proof
Proof of work for this peer.
#define GNUNET_log(kind,...)
int GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_CRYPTO_eddsa_key_create_from_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new private key by reading our peer&#39;s key from the file specified in the configuration...
static void core_init(void *cls, const struct GNUNET_PeerIdentity *identity)
Called on core init/fail.
#define GNUNET_YES
Definition: gnunet_common.h:77
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
ssize_t GNUNET_DISK_fn_read(const char *fn, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:794
#define GNUNET_free(ptr)
Wrapper around free.
static GNUNET_NETWORK_STRUCT_END const struct GNUNET_CONFIGURATION_Handle * cfg
Handle to our current configuration.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_connect_cb()

static void* client_connect_cb ( void *  cls,
struct GNUNET_SERVICE_Client c,
struct GNUNET_MQ_Handle mq 
)
static

Callback called when a client connects to the service.

Parameters
clsclosure for the service
cthe new client that connected to the service
mqthe message queue used to send messages to the client
Returns
c

Definition at line 1539 of file gnunet-service-nse.c.

Referenced by client_disconnect_cb().

1542 {
1543  (void) cls;
1544  (void) mq;
1545  return c;
1546 }
Here is the caller graph for this function:

◆ client_disconnect_cb()

static void client_disconnect_cb ( void *  cls,
struct GNUNET_SERVICE_Client c,
void *  internal_cls 
)
static

Callback called when a client disconnected from the service.

Parameters
clsclosure for the service
cthe client that disconnected
internal_clsshould be equal to c

Definition at line 1557 of file gnunet-service-nse.c.

References __attribute__, client_connect_cb(), GNUNET_assert, GNUNET_MESSAGE_TYPE_NSE_START, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_SERVICE_MAIN(), GNUNET_SERVICE_OPTION_NONE, run(), and start.

1560 {
1561  (void) cls;
1562  GNUNET_assert (c == internal_cls);
1563 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Here is the call graph for this function:

◆ GNUNET_SERVICE_MAIN()

GNUNET_SERVICE_MAIN ( "nse"  ,
GNUNET_SERVICE_OPTION_NONE  ,
run,
client_connect_cb,
client_disconnect_cb,
NULL  ,
GNUNET_MQ_hd_fixed_size(start, GNUNET_MESSAGE_TYPE_NSE_START, struct GNUNET_MessageHeader, NULL)  ,
GNUNET_MQ_handler_end()   
)

Define "main" method using service macro.

Referenced by client_disconnect_cb().

Here is the caller graph for this function:

Variable Documentation

◆ nse_work_required

unsigned long long nse_work_required
static

Amount of work required (W-bit collisions) for NSE proofs, in collision-bits.

Definition at line 85 of file gnunet-service-nse.c.

Referenced by check_proof_of_work(), find_proof(), run(), setup_flood_message(), and verify_message_crypto().

◆ gnunet_nse_interval

struct GNUNET_TIME_Relative gnunet_nse_interval
static

Interval for sending network size estimation flood requests.

Definition at line 90 of file gnunet-service-nse.c.

Referenced by core_init(), get_matching_bits_delay(), handle_p2p_estimate(), run(), and update_flood_message().

◆ proof_find_delay

struct GNUNET_TIME_Relative proof_find_delay
static

Interval between proof find runs.

Definition at line 95 of file gnunet-service-nse.c.

Referenced by find_proof(), and run().

◆ cfg

Handle to our current configuration.

Definition at line 220 of file gnunet-service-nse.c.

◆ stats

struct GNUNET_STATISTICS_Handle* stats
static

Handle to the statistics service.

Definition at line 225 of file gnunet-service-nse.c.

◆ core_api

struct GNUNET_CORE_Handle* core_api
static

Handle to the core service.

Definition at line 230 of file gnunet-service-nse.c.

◆ peers

struct GNUNET_CONTAINER_MultiPeerMap* peers
static

Map of all connected peers.

Definition at line 235 of file gnunet-service-nse.c.

◆ current_size_estimate

double current_size_estimate
static

The current network size estimate.

Number of bits matching on average thus far.

Definition at line 241 of file gnunet-service-nse.c.

Referenced by get_matching_bits_delay(), and setup_estimate_message().

◆ current_std_dev

double current_std_dev = NAN
static

The standard deviation of the last HISTORY_SIZE network size estimates.

Definition at line 247 of file gnunet-service-nse.c.

Referenced by setup_estimate_message().

◆ hop_count_max

uint32_t hop_count_max
static

Current hop counter estimate (estimate for network diameter).

Definition at line 252 of file gnunet-service-nse.c.

Referenced by get_delay_randomization(), handle_p2p_estimate(), and update_flood_message().

◆ next_message

struct GNUNET_NSE_FloodMessage next_message
static

Message for the next round, if we got any.

Definition at line 257 of file gnunet-service-nse.c.

Referenced by handle_p2p_estimate(), and update_flood_message().

◆ size_estimate_messages

struct GNUNET_NSE_FloodMessage size_estimate_messages[64]
static

Array of recent size estimate messages.

Definition at line 262 of file gnunet-service-nse.c.

Referenced by get_transmit_delay(), handle_p2p_estimate(), setup_estimate_message(), setup_flood_message(), transmit_task_cb(), and update_flood_message().

◆ estimate_index

unsigned int estimate_index
static

◆ estimate_count

unsigned int estimate_count
static

Number of valid entries in the history.

Definition at line 272 of file gnunet-service-nse.c.

Referenced by core_init(), setup_estimate_message(), and update_flood_message().

◆ flood_task

struct GNUNET_SCHEDULER_Task* flood_task
static

Task scheduled to update our flood message for the next round.

Definition at line 277 of file gnunet-service-nse.c.

◆ proof_task

struct GNUNET_SCHEDULER_Task* proof_task
static

Task scheduled to compute our proof.

Definition at line 282 of file gnunet-service-nse.c.

◆ nc

struct GNUNET_NotificationContext* nc
static

Notification context, simplifies client broadcasts.

Definition at line 287 of file gnunet-service-nse.c.

◆ next_timestamp

struct GNUNET_TIME_Absolute next_timestamp
static

The next major time.

Definition at line 292 of file gnunet-service-nse.c.

Referenced by core_init(), handle_p2p_estimate(), and update_flood_message().

◆ current_timestamp

struct GNUNET_TIME_Absolute current_timestamp
static

The current major time.

Definition at line 297 of file gnunet-service-nse.c.

Referenced by core_init(), find_proof(), get_transmit_delay(), handle_p2p_estimate(), and update_flood_message().

◆ my_private_key

struct GNUNET_CRYPTO_EddsaPrivateKey* my_private_key
static

The private key of this peer.

Definition at line 302 of file gnunet-service-nse.c.

◆ my_identity

struct GNUNET_PeerIdentity my_identity
static

The peer identity of this peer.

Definition at line 307 of file gnunet-service-nse.c.

Referenced by core_init(), find_proof(), handle_p2p_estimate(), run(), setup_flood_message(), and update_flood_message().

◆ my_proof

uint64_t my_proof
static

Proof of work for this peer.

Definition at line 312 of file gnunet-service-nse.c.

Referenced by core_init(), find_proof(), run(), setup_flood_message(), and write_proof().