GNUnet 0.22.2
gnunet-dht-tvg.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2024 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
26#include "gnunet_common.h"
27#include "gnunet_constants.h"
28#include "gnunet_dht_block_types.h"
29#include "gnunet_dht_service.h"
30#include "gnunet_time_lib.h"
31#include "gnunet_util_lib.h"
32#include "dht_helper.h"
33#include <inttypes.h>
34
35static const char*peers_str[] = {
36 "a4bba7746dfd3432da2a11c57b248b2d6b14eafb3ad54401c44bd37f232d1ce5",
37 "02163d1dde228f9796c5327c781b4e5880ebf356204d3c4cceb9a77ae32157d7",
38 "859836011003dc5d0cd84418812e381f3989797fb994464a52e3b7ad954c2695",
39 "276881c5c18af46c2ad8ee5235c62c4d9d1df4bb2795d6f0ce190d51aa8b9ce0",
40 "56045fd5e9d91426c6a4ec9c8c230ea4ee56fb5c0ad3b77000d863142ceb3b9b"
41};
42
51static void
52run (void *cls,
53 char *const *args,
54 const char *cfgfile,
55 const struct GNUNET_CONFIGURATION_Handle *cfg)
56{
57 int NUM_PEERS = 5;
60 struct GNUNET_HashCode peers_hash[NUM_PEERS];
61 struct GNUNET_HashCode key; // FIXME set to key
63 size_t msize;
64 uint64_t data_num = 23;
65 uint8_t *block_data = (uint8_t*) &data_num;
66 size_t block_len = 8;
67 unsigned int put_path_len = 0;
68 size_t putlen;
69 struct GNUNET_CRYPTO_EddsaSignature *last_sig;
70 struct GNUNET_DHT_PathElement *put_path;
71 struct GNUNET_DHT_PathElement pp[NUM_PEERS + 1];
73 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
74 struct GNUNET_PeerIdentity trunc_peer_out;
75 bool truncated = false;
76 GNUNET_CRYPTO_hash ("testvector", strlen ("testvector"), &key);
77
78 for (int i = 0; i < NUM_PEERS; i++)
79 {
80 GNUNET_hex2b (peers_str[i], &peers_sk[i], sizeof peers_sk[i], 0);
82 &peers[i].public_key);
83 GNUNET_CRYPTO_hash (&peers[i], sizeof (struct GNUNET_PeerIdentity), &
84 peers_hash[i]);
85 printf ("Peer %d sk:\n", i);
86 GNUNET_print_bytes (&peers_sk[i], sizeof peers_sk[i], 8, 0);
87 printf ("\nPeer %d pk:\n", i);
88 GNUNET_print_bytes (&peers[i], sizeof peers[i], 8, 0);
89 printf ("\nPeer %d SHA512(pk):\n", i);
90 GNUNET_print_bytes (&peers_hash[i], sizeof peers_hash[i], 8, 0);
91 printf ("\n");
92 }
93
94 peer_bf
98 for (int i = 0; i < NUM_PEERS - 1; i++)
99 {
101 &msize, &peers[i], ro, &ro, GNUNET_TIME_UNIT_FOREVER_ABS,
102 block_data, block_len, pp, put_path_len, &put_path_len,
103 NULL, &trunc_peer_out, &truncated);
105 {
106
107 uint8_t buf[msize];
108 struct PeerPutMessage *ppm;
109 ppm = (struct PeerPutMessage*) buf;
111 &peers_hash[i]);
112 GNUNET_CONTAINER_bloomfilter_add (peer_bf, &peers_hash[i + 1]);
113 GDS_helper_make_put_message (ppm, msize,
114 &peers_sk[i], &peers[i + 1],
115 &peers_hash[i + 1],
116 peer_bf, &key, ro,
119 block_data, 10,
120 pp, put_path_len, i, 7, NULL);
121 printf ("Peer %d sends to peer %d PUT Message:\n", i, i + 1);
122 GNUNET_print_bytes (ppm, msize, 8, 0);
123 putlen = ntohs (ppm->put_path_length);
124 put_path = (struct GNUNET_DHT_PathElement*) &ppm[1];
125 last_sig = (struct GNUNET_CRYPTO_EddsaSignature*) &put_path[putlen];
126 memcpy (pp, put_path, putlen * sizeof (struct GNUNET_DHT_PathElement));
127 pp[putlen].pred = peers[i];
128 pp[putlen].sig = *last_sig;
129 put_path_len++;
130 printf ("\n");
131 // printf ("Put path (len = %u):\n", put_path_len);
132 // GNUNET_print_bytes (pp, put_path_len * sizeof (*pp), 8, 0);
133 }
134 }
135}
136
137
145int
146main (int argc,
147 char *const *argv)
148{
151 };
152
154 GNUNET_log_setup ("gnunet-dht-tvg",
155 "INFO",
156 NULL));
157 // gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u, 0);
158 // gcry_control (GCRYCTL_SET_VERBOSITY, 99);
159 if (GNUNET_OK !=
161 argc, argv,
162 "gnunet-dht-tvg",
163 "Generate test vectors for R5N",
164 options,
165 &run, NULL))
166 return 1;
167 return 0;
168}
169
170
171/* end of gnunet-gns-tvg.c */
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define DHT_BLOOM_SIZE
Size of the bloom filter the DHT uses to filter peers.
Definition: dht.h:34
void 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)
Definition: dht_helper.c:178
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:36
Helper functions for DHT.
static int ret
Final status code.
Definition: gnunet-arm.c:93
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
struct GNUNET_HashCode key
The key used in the DHT.
static const char * peers_str[]
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.
struct GNUNET_CONTAINER_MultiPeerMap * peers
Map from PIDs to struct CadetPeer entries.
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
API to the DHT service.
Functions related to time.
struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_init(const char *data, size_t size, unsigned int k)
Create a Bloom filter from raw bits.
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
#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_RouteOption
Options for routing.
@ 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
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
void GNUNET_print_bytes(const void *buf, size_t buf_len, int fold, int in_be)
Print a byte string in hexadecimal ascii notation.
size_t GNUNET_hex2b(const char *src, void *dst, size_t dstlen, int invert)
Parse an ascii-encoded hexadecimal string into the buffer.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
@ GNUNET_BLOCK_TYPE_TEST
Block for testing.
Private ECC key encoded for transmission.
an ECC signature using EdDSA.
A (signed) path tracking a block's flow through the DHT is represented by an array of path elements,...
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.
Definition of a command line option.
A 512-bit hashcode.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
P2P PUT message.
Definition: dht.h:429
uint16_t put_path_length
Length of the PUT path that follows (if tracked).
Definition: dht.h:458
#define NUM_PEERS
Definition: testbed_test.c:8