GNUnet 0.26.2-98-gb402d9955
 
Loading...
Searching...
No Matches
gnunet-dht-tvg.c File Reference
#include "gnunet_common.h"
#include "gnunet_constants.h"
#include "gnunet_dht_block_types.h"
#include "gnunet_dht_service.h"
#include "gnunet_pils_service.h"
#include "gnunet_time_lib.h"
#include "gnunet_util_lib.h"
#include "dht_helper.h"
#include <inttypes.h>
#include <string.h>
Include dependency graph for gnunet-dht-tvg.c:

Go to the source code of this file.

Data Structures

struct  TVG_CallbackData
 

Macros

#define NUM_PEERS   5
 

Functions

static void print_put_message (struct TVG_CallbackData *tvg)
 
static bool cb_print_put_message (void *cls, size_t msize, struct PeerPutMessage *ppm)
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Main function that will be run.
 
int main (int argc, char *const *argv)
 The main function of the test vector generation tool.
 

Variables

struct GNUNET_PILS_HandleGDS_pils
 Handle for the pils service.
 
static const char * peers_str [5]
 

Macro Definition Documentation

◆ NUM_PEERS

#define NUM_PEERS   5

Definition at line 42 of file gnunet-dht-tvg.c.

Function Documentation

◆ print_put_message()

static void print_put_message ( struct TVG_CallbackData tvg)
static

Definition at line 112 of file gnunet-dht-tvg.c.

113{
115 struct GNUNET_CRYPTO_EddsaPrivateKey *peers_sk;
116 struct GNUNET_HashCode *peers_hash;
117 struct GNUNET_DHT_PathElement *pp;
118 struct GNUNET_PeerIdentity trunc_peer_out;
119 bool truncated;
121 size_t msize;
122 int i;
123
124 peers = tvg->peers;
125 peers_sk = tvg->peers_sk;
126 peers_hash = tvg->peers_hash;
127 pp = tvg->pp;
128
129 i = tvg->index;
130 if (i >= NUM_PEERS - 1)
131 return;
132
134 &msize, &peers[i], tvg->ro, &tvg->ro, GNUNET_TIME_UNIT_FOREVER_ABS,
135 tvg->block_data, tvg->block_len, pp,
136 tvg->put_path_len, &tvg->put_path_len,
137 NULL, &trunc_peer_out, &truncated);
139 {
140 uint8_t buf[msize];
141 struct PeerPutMessage *ppm;
142 ppm = (struct PeerPutMessage*) buf;
144 &peers_hash[i]);
146 &peers_hash[i + 1]);
147 GDS_helper_make_put_message (ppm, msize,
148 &peers_sk[i], &peers[i + 1],
149 &peers_hash[i + 1],
150 tvg->peer_bf, &tvg->key, tvg->ro,
153 tvg->block_data,
154 tvg->block_len,
155 pp, tvg->put_path_len,
156 i, 7, NULL,
158 0,
159 tvg);
160 }
161}
bool GDS_helper_make_put_message(struct PeerPutMessage *ppm, size_t msize, const struct GNUNET_CRYPTO_EddsaPrivateKey *sk, const struct GNUNET_PeerIdentity *target, const struct GNUNET_HashCode *target_hash, const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *block_key, enum GNUNET_DHT_RouteOption ro, enum GNUNET_BLOCK_Type block_type, struct GNUNET_TIME_Absolute block_expiration_time, const uint8_t *block_data, size_t block_data_len, const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_len, size_t hop_count, uint32_t desired_replication_level, const struct GNUNET_PeerIdentity *trunc_peer, GDS_HelperMsgCallback cb, size_t cb_data_size, void *cb_data)
Definition dht_helper.c:326
enum GNUNET_GenericReturnValue GDS_helper_put_message_get_size(size_t *msize_out, const struct GNUNET_PeerIdentity *my_identity, enum GNUNET_DHT_RouteOption ro_in, enum GNUNET_DHT_RouteOption *ro_out, struct GNUNET_TIME_Absolute block_expiration_time, const uint8_t *block_data, size_t block_data_len, const struct GNUNET_DHT_PathElement *put_path_in, unsigned int put_path_len_in, unsigned int *put_path_len_out, const struct GNUNET_PeerIdentity *trunc_peer, struct GNUNET_PeerIdentity *trunc_peer_out, bool *truncated)
Definition dht_helper.c:96
static int ret
Final status code.
Definition gnunet-arm.c:93
#define NUM_PEERS
static bool cb_print_put_message(void *cls, size_t msize, struct PeerPutMessage *ppm)
struct GNUNET_CONTAINER_MultiPeerMap * peers
Map from PIDs to struct CadetPeer entries.
@ GNUNET_BLOCK_TYPE_TEST
Block for testing.
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
Private ECC key encoded for transmission.
A (signed) path tracking a block's flow through the DHT is represented by an array of path elements,...
A 512-bit hashcode.
The identity of the host (wraps the signing key of the peer).
P2P PUT message.
Definition dht.h:429
struct GNUNET_CRYPTO_EddsaPrivateKey peers_sk[5]
enum GNUNET_DHT_RouteOption ro
struct GNUNET_HashCode key
unsigned int put_path_len
struct GNUNET_DHT_PathElement pp[5+1]
struct GNUNET_CONTAINER_BloomFilter * peer_bf
struct GNUNET_PeerIdentity peers[5]
struct GNUNET_HashCode peers_hash[5]

References TVG_CallbackData::block_data, TVG_CallbackData::block_len, cb_print_put_message(), GDS_helper_make_put_message(), GDS_helper_put_message_get_size(), GNUNET_assert, GNUNET_BLOCK_TYPE_TEST, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_OK, GNUNET_TIME_UNIT_FOREVER_ABS, TVG_CallbackData::index, TVG_CallbackData::key, NUM_PEERS, TVG_CallbackData::peer_bf, peers, TVG_CallbackData::peers, TVG_CallbackData::peers_hash, TVG_CallbackData::peers_sk, TVG_CallbackData::pp, TVG_CallbackData::put_path_len, ret, and TVG_CallbackData::ro.

Referenced by cb_print_put_message(), and run().

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

◆ cb_print_put_message()

static bool cb_print_put_message ( void *  cls,
size_t  msize,
struct PeerPutMessage ppm 
)
static

Definition at line 73 of file gnunet-dht-tvg.c.

76{
77 struct TVG_CallbackData *tvg = cls;
79 struct GNUNET_DHT_PathElement *pp;
80
81 peers = tvg->peers;
82 pp = tvg->pp;
83
84 if (ppm)
85 {
86 size_t putlen;
87 struct GNUNET_DHT_PathElement *put_path;
88 struct GNUNET_CRYPTO_EddsaSignature *last_sig;
89
90 printf ("Peer %d sends to peer %d PUT Message:\n",
91 tvg->index, tvg->index + 1);
92 GNUNET_print_bytes (ppm, msize, 8, 0);
93 putlen = ntohs (ppm->put_path_length);
94 put_path = (struct GNUNET_DHT_PathElement*) &ppm[1];
95 last_sig = (struct GNUNET_CRYPTO_EddsaSignature*) &put_path[putlen];
96 memcpy (pp, put_path, putlen * sizeof (struct GNUNET_DHT_PathElement));
97 pp[putlen].pred = peers[tvg->index];
98 pp[putlen].sig = *last_sig;
99 tvg->put_path_len++;
100 printf ("\n");
101 // printf ("Put path (len = %u):\n", put_path_len);
102 // GNUNET_print_bytes (pp, put_path_len * sizeof (*pp), 8, 0);
103 }
104
105 tvg->index++;
106 print_put_message (tvg);
107 return false;
108}
static void print_put_message(struct TVG_CallbackData *tvg)
void GNUNET_print_bytes(const void *buf, size_t buf_len, int fold, int in_be)
Print a byte string in hexadecimal ascii notation.
an ECC signature using EdDSA.
struct GNUNET_PeerIdentity pred
Previous peer on the path (matches "pred" in the signed field).
struct GNUNET_CRYPTO_EddsaSignature sig
Signature affirming the hop of type GNUNET_SIGNATURE_PURPOSE_DHT_HOP.
uint16_t put_path_length
Length of the PUT path that follows (if tracked).
Definition dht.h:458

References GNUNET_print_bytes(), TVG_CallbackData::index, peers, TVG_CallbackData::peers, TVG_CallbackData::pp, GNUNET_DHT_PathElement::pred, print_put_message(), TVG_CallbackData::put_path_len, PeerPutMessage::put_path_length, and GNUNET_DHT_PathElement::sig.

Referenced by print_put_message().

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

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle cfg 
)
static

Main function that will be run.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cfgconfiguration

Definition at line 173 of file gnunet-dht-tvg.c.

177{
178 struct TVG_CallbackData tvg;
180 struct GNUNET_CRYPTO_EddsaPrivateKey *peers_sk;
181 struct GNUNET_HashCode *peers_hash;
182 uint64_t data_num = 23;
183
184 GDS_pils = NULL;
185
186 GNUNET_CRYPTO_hash ("testvector", strlen ("testvector"), &tvg.key);
187
188 memset (&tvg, 0, sizeof (tvg));
190 tvg.put_path_len = 0;
191 tvg.block_data = (uint8_t*) &data_num;
192 tvg.block_len = sizeof (data_num);
193
194 peers = tvg.peers;
195 peers_sk = tvg.peers_sk;
196 peers_hash = tvg.peers_hash;
197
198 for (int i = 0; i < NUM_PEERS; i++)
199 {
200 GNUNET_hex2b (peers_str[i], &peers_sk[i], sizeof peers_sk[i], 0);
202 &peers[i].public_key);
203 GNUNET_CRYPTO_hash (&peers[i], sizeof (struct GNUNET_PeerIdentity), &
204 peers_hash[i]);
205 printf ("Peer %d sk:\n", i);
206 GNUNET_print_bytes (&peers_sk[i], sizeof peers_sk[i], 8, 0);
207 printf ("\nPeer %d pk:\n", i);
208 GNUNET_print_bytes (&peers[i], sizeof peers[i], 8, 0);
209 printf ("\nPeer %d SHA512(pk):\n", i);
210 GNUNET_print_bytes (&peers_hash[i], sizeof peers_hash[i], 8, 0);
211 printf ("\n");
212 }
213
214 tvg.peer_bf
218 tvg.index = 0;
219 print_put_message (&tvg);
220
222 GDS_pils = NULL;
223}
#define DHT_BLOOM_SIZE
Size of the bloom filter the DHT uses to filter peers.
Definition dht.h:34
void GDS_helper_cleanup_operations(void)
Definition dht_helper.c:81
struct GNUNET_PILS_Handle * GDS_pils
Handle for the pils service.
static const char * peers_str[5]
struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_init(const char *data, size_t size, unsigned int k)
Create a Bloom filter from raw bits.
#define GNUNET_CONSTANTS_BLOOMFILTER_K
K-value that must be used for the bloom filters in 'GET' queries.
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:201
@ GNUNET_DHT_RO_RECORD_ROUTE
We should keep track of the route that the message took in the P2P network.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:41
size_t GNUNET_hex2b(const char *src, void *dst, size_t dstlen, int invert)
Parse an ascii-encoded hexadecimal string into the buffer.

References TVG_CallbackData::block_data, TVG_CallbackData::block_len, DHT_BLOOM_SIZE, GDS_helper_cleanup_operations(), GDS_pils, GNUNET_CONSTANTS_BLOOMFILTER_K, GNUNET_CONTAINER_bloomfilter_init(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_CRYPTO_hash(), GNUNET_DHT_RO_RECORD_ROUTE, GNUNET_hex2b(), GNUNET_print_bytes(), TVG_CallbackData::index, TVG_CallbackData::key, NUM_PEERS, TVG_CallbackData::peer_bf, peers, TVG_CallbackData::peers, TVG_CallbackData::peers_hash, TVG_CallbackData::peers_sk, peers_str, print_put_message(), TVG_CallbackData::put_path_len, and TVG_CallbackData::ro.

Referenced by main().

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

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function of the test vector generation tool.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 234 of file gnunet-dht-tvg.c.

236{
239 };
240
242 GNUNET_log_setup ("gnunet-dht-tvg",
243 "INFO",
244 NULL));
245 // gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0);
246 // gcry_control (GCRYCTL_SET_VERBOSITY, 99);
247 if (GNUNET_OK !=
249 argc, argv,
250 "gnunet-dht-tvg",
251 "Generate test vectors for R5N",
252 options,
253 &run, NULL))
254 return 1;
255 return 0;
256}
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition program.c:407
Definition of a command line option.

References GNUNET_assert, GNUNET_GETOPT_OPTION_END, GNUNET_log_setup(), GNUNET_OK, GNUNET_OS_project_data_gnunet(), GNUNET_PROGRAM_run(), options, and run().

Here is the call graph for this function:

Variable Documentation

◆ GDS_pils

struct GNUNET_PILS_Handle* GDS_pils

Handle for the pils service.

(may be NULL but needed for linking)

Definition at line 40 of file gnunet-dht-tvg.c.

Referenced by run().

◆ peers_str

const char* peers_str[5]
static
Initial value:
= {
"a4bba7746dfd3432da2a11c57b248b2d6b14eafb3ad54401c44bd37f232d1ce5",
"02163d1dde228f9796c5327c781b4e5880ebf356204d3c4cceb9a77ae32157d7",
"859836011003dc5d0cd84418812e381f3989797fb994464a52e3b7ad954c2695",
"276881c5c18af46c2ad8ee5235c62c4d9d1df4bb2795d6f0ce190d51aa8b9ce0",
"56045fd5e9d91426c6a4ec9c8c230ea4ee56fb5c0ad3b77000d863142ceb3b9b"
}

Definition at line 44 of file gnunet-dht-tvg.c.

44 {
45 "a4bba7746dfd3432da2a11c57b248b2d6b14eafb3ad54401c44bd37f232d1ce5",
46 "02163d1dde228f9796c5327c781b4e5880ebf356204d3c4cceb9a77ae32157d7",
47 "859836011003dc5d0cd84418812e381f3989797fb994464a52e3b7ad954c2695",
48 "276881c5c18af46c2ad8ee5235c62c4d9d1df4bb2795d6f0ce190d51aa8b9ce0",
49 "56045fd5e9d91426c6a4ec9c8c230ea4ee56fb5c0ad3b77000d863142ceb3b9b"
50};

Referenced by run().