GNUnet 0.25.0
 
Loading...
Searching...
No Matches
gnunet-service-pils.c File Reference

peer identity lifecycle service More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_protocols.h"
#include "gnunet_signatures.h"
#include "gnunet_pils_service.h"
#include "pils.h"
Include dependency graph for gnunet-service-pils.c:

Go to the source code of this file.

Data Structures

struct  P_Client
 Data structure for each client connected to the CORE service. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "pils", __VA_ARGS__)
 

Functions

static void load_ikm ()
 Get the initial secret key for generating the peer id.
 
static void print_uri (void *cls, const struct GNUNET_PeerIdentity *pid, const char *uri)
 
static void do_generate_pid (const struct GNUNET_HELLO_Parser *parser)
 Generate the peer id from the addresses hash and the initial secret key.
 
static int check_feed_addresses (void *cls, const struct FeedAddressesMessage *msg)
 Checker for feed messages.
 
static void handle_feed_addresses (void *cls, const struct FeedAddressesMessage *message)
 Handler for feed addresses message from client.
 
static void handle_decaps (void *cls, const struct DecapsMessage *message)
 Handler for decaps request message from client.
 
static int check_sign (void *cls, const struct SignRequestMessage *msg)
 Handler for sign request message from client.
 
static void handle_sign (void *cls, const struct SignRequestMessage *message)
 Handler for sign request message from client.
 
static void shutdown_task (void *cls)
 Task run during shutdown.
 
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
 Set up the service.
 
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.
 
static void client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls)
 Callback called when a client disconnected from the service.
 
 GNUNET_SERVICE_MAIN (GNUNET_OS_project_data_gnunet(), "pils", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_var_size(feed_addresses, GNUNET_MESSAGE_TYPE_PILS_FEED_ADDRESSES, struct FeedAddressesMessage, NULL), GNUNET_MQ_hd_fixed_size(decaps, GNUNET_MESSAGE_TYPE_PILS_KEM_DECAPS, struct DecapsMessage, NULL), GNUNET_MQ_hd_var_size(sign, GNUNET_MESSAGE_TYPE_PILS_SIGN_REQUEST, struct SignRequestMessage, NULL), GNUNET_MQ_handler_end())
 Define "main" method using service macro.
 

Variables

static const struct GNUNET_CONFIGURATION_Handlecfg
 Handle to our current configuration.
 
static struct GNUNET_SCHEDULER_Taskgenerate_pid_task
 Task to schedule the generation of the peer id.
 
struct GNUNET_HashCode addresses_hash
 Hash of the canonicalized addresses.
 
struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key
 The current private key.
 
struct GNUNET_CRYPTO_EddsaPublicKey my_public_key
 The current public key.
 
static unsigned char ikm [256/8]
 The initial key material for the peer.
 
static struct P_Clientclients_head
 Head of the liked list of clients.
 
static struct P_Clientclients_tail
 Tail of the liked list of clients.
 
static int have_id
 Peer ID was calculated already at least once.
 
static struct GNUNET_MQ_Envelopesigned_hello
 Current signed HELLO.
 

Detailed Description

peer identity lifecycle service

Author
ch3
Martin Schanzenbach

This service maintains the peer identity. On address change it generates a new identity and informs subscribed components. It also signs data with the identity on request.

Definition in file gnunet-service-pils.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "pils", __VA_ARGS__)

Definition at line 41 of file gnunet-service-pils.c.

Function Documentation

◆ load_ikm()

static void load_ikm ( )
static

Get the initial secret key for generating the peer id.

This is supposed to be generated at random once in the lifetime of a peer, so all generated peer ids use the same initial secret key to obtain the same peer id per set of addresses.

First check whether there's already a initial secret key. If so: return it. If no initial secret key exists yet, generate at random and store it where it will be found.

Parameters
initialsecret key the memory the initial secret key can be written to.

Definition at line 140 of file gnunet-service-pils.c.

141{
142 char *keyfile;
144
145 if (GNUNET_OK !=
147 "PEER",
148 "PRIVATE_KEY",
149 &keyfile))
150 {
152 "PEER",
153 "PRIVATE_KEY");
155 return;
156 }
157 if (GNUNET_SYSERR ==
160 &key))
161 {
163 "Failed to setup peer's private key\n");
164 GNUNET_free (keyfile);
166 return;
167 }
168 GNUNET_free (keyfile);
169 GNUNET_assert (sizeof ikm == sizeof key.d);
170 memcpy (ikm, key.d, sizeof ikm);
171}
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned char ikm[256/8]
The initial key material for the peer.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Handle to our current configuration.
enum GNUNET_GenericReturnValue 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.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_key_from_file(const char *filename, int do_create, struct GNUNET_CRYPTO_EddsaPrivateKey *pkey)
Create a new private key by reading it from a file.
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition scheduler.c:567
Private ECC key encoded for transmission.

References cfg, GNUNET_assert, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CRYPTO_eddsa_key_from_file(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_log, GNUNET_log_config_missing(), GNUNET_OK, GNUNET_SCHEDULER_shutdown(), GNUNET_SYSERR, GNUNET_YES, ikm, and key.

Referenced by run().

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

◆ print_uri()

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

Definition at line 175 of file gnunet-service-pils.c.

178{
180 "%s\n", uri);
181}
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
#define LOG(kind,...)
@ GNUNET_ERROR_TYPE_DEBUG

References GNUNET_ERROR_TYPE_DEBUG, LOG, and uri.

Referenced by do_generate_pid().

Here is the caller graph for this function:

◆ do_generate_pid()

static void do_generate_pid ( const struct GNUNET_HELLO_Parser parser)
static

Generate the peer id from the addresses hash and the initial secret key.

Notify all subscribed clients with the new peer id.

Parameters
clsClosure - unused.

Definition at line 192 of file gnunet-service-pils.c.

193{
195 struct GNUNET_HashCode new_addresses_hash;
196 LOG (GNUNET_ERROR_TYPE_INFO, "Going to generate a new peer id\n");
197 generate_pid_task = NULL;
198
199 if (NULL == parser)
200 {
202 }
203 else
204 {
206 }
208 "Got new address list to derive PID:\n");
211 &new_addresses_hash);
212#if HELLO_DETERMINISTIC_PID_DERIVATION
213 if (0 == GNUNET_CRYPTO_hash_cmp (&new_addresses_hash,
215 {
217 "Address hash unchanged at %s, ignoring...\n",
220 return;
221 }
222#endif
223 addresses_hash = new_addresses_hash;
225 (uint8_t*) ikm,
231 "Successfully generated a new peer id %s - inform clients\n",
233
234 {
235 struct P_Client *client;
236 struct PeerIdUpdateMessage *msg;
238 struct GNUNET_TIME_Absolute et;
239 size_t block_bytes;
241
242 struct PilsHelloSignaturePurpose hsp = {
243 .purpose.size = htonl (sizeof (hsp)),
244 .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_HELLO),
245 .expiration_time = GNUNET_TIME_absolute_hton (et)
246 };
250 &hsp.purpose,
251 &sig));
253
255 block_bytes,
257 msg->hash = addresses_hash;
258 msg->block_len = htonl (block_bytes);
260 builder,
262 &sig,
263 et,
264 (char *) &msg[1]);
265 client = clients_head;
266 while (NULL != client)
267 {
269 client = client->next;
270 }
271 }
272}
struct GNUNET_MessageHeader * msg
Definition 005.c:2
static struct HostSet * builder
NULL if we are not currently iterating over peer information.
static struct GNUNET_MQ_Envelope * signed_hello
Current signed HELLO.
struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key
The current private key.
static struct GNUNET_SCHEDULER_Task * generate_pid_task
Task to schedule the generation of the peer id.
struct GNUNET_HashCode addresses_hash
Hash of the canonicalized addresses.
static void print_uri(void *cls, const struct GNUNET_PeerIdentity *pid, const char *uri)
struct GNUNET_CRYPTO_EddsaPublicKey my_public_key
The current public key.
static struct P_Client * clients_head
Head of the liked list of clients.
static int have_id
Peer ID was calculated already at least once.
void GNUNET_PILS_derive_pid(size_t seed_key_bytes, const uint8_t seed_key[seed_key_bytes], const struct GNUNET_HashCode *addrs_hash, struct GNUNET_CRYPTO_EddsaPrivateKey *outkey)
Generate the peer id from the addresses hash and the initial secret key.
Definition pils_api.c:507
#define GNUNET_SIGNATURE_PURPOSE_HELLO
Signature by which a peer affirms its address.
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
enum GNUNET_GenericReturnValue 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:625
int GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
void GNUNET_HELLO_builder_to_block(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_PeerIdentity *pid, const struct GNUNET_CRYPTO_EddsaSignature *sig, struct GNUNET_TIME_Absolute expiration_time, char *outbuf)
Generate DHT block from a builder.
Definition hello-uri.c:1244
void GNUNET_HELLO_builder_free(struct GNUNET_HELLO_Builder *builder)
Release resources of a builder.
Definition hello-uri.c:397
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_new()
Allocate builder.
Definition hello-uri.c:343
void GNUNET_HELLO_builder_iterate(const struct GNUNET_HELLO_Builder *builder, GNUNET_HELLO_UriCallback uc, void *uc_cls)
Iterate over URIs in a builder.
Definition hello-uri.c:956
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_from_parser(const struct GNUNET_HELLO_Parser *parser, struct GNUNET_PeerIdentity *pid)
Allocate builder from parser.
Definition hello-uri.c:360
size_t GNUNET_HELLO_get_builder_to_block_size(const struct GNUNET_HELLO_Builder *builder)
Get projected block size for builder.
Definition hello-uri.c:1312
#define GNUNET_HELLO_ADDRESS_EXPIRATION
For how long are HELLO signatures valid?
void GNUNET_HELLO_builder_hash_addresses(const struct GNUNET_HELLO_Builder *builder, struct GNUNET_HashCode *hash)
Compute hash over addresses in builder.
Definition hello-uri.c:1134
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
const char * GNUNET_p2s(const struct GNUNET_CRYPTO_EddsaPublicKey *p)
Convert a public key value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_INFO
void GNUNET_MQ_send_copy(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MQ_Envelope *ev)
Send a copy of a message with the given message queue.
Definition mq.c:384
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MESSAGE_TYPE_PILS_PEER_ID
Message passing the new peer id from the service to the client.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition time.c:316
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition time.c:640
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
an ECC signature using EdDSA.
Context for building (or parsing) HELLO URIs.
Definition hello-uri.c:184
A 512-bit hashcode.
The identity of the host (wraps the signing key of the peer).
Time for absolute times used by GNUnet, in microseconds.
Data structure for each client connected to the CORE service.
struct GNUNET_MQ_Handle * mq
Message queue to talk to client.
struct P_Client * next
Clients are kept in a linked list.
struct GNUNET_SERVICE_Client * client
Handle for the client with the server API.
Message containing the current peer id and the hash from which it was generated.
Definition pils.h:40
Message signed as part of a HELLO block/URL.
Definition hello-uri.c:50
struct GNUNET_HashCode h_addrs
Hash over all addresses.
Definition hello-uri.c:64
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Purpose must be GNUNET_SIGNATURE_PURPOSE_HELLO.
Definition hello-uri.c:54

References addresses_hash, builder, P_Client::client, clients_head, generate_pid_task, GNUNET_assert, GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_CRYPTO_eddsa_sign_(), GNUNET_CRYPTO_hash_cmp(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_h2s(), GNUNET_HELLO_ADDRESS_EXPIRATION, GNUNET_HELLO_builder_free(), GNUNET_HELLO_builder_from_parser(), GNUNET_HELLO_builder_hash_addresses(), GNUNET_HELLO_builder_iterate(), GNUNET_HELLO_builder_new(), GNUNET_HELLO_builder_to_block(), GNUNET_HELLO_get_builder_to_block_size(), GNUNET_MESSAGE_TYPE_PILS_PEER_ID, GNUNET_MQ_msg_extra, GNUNET_MQ_send_copy(), GNUNET_OK, GNUNET_p2s(), GNUNET_PILS_derive_pid(), GNUNET_SIGNATURE_PURPOSE_HELLO, GNUNET_TIME_absolute_hton(), GNUNET_TIME_relative_to_absolute(), GNUNET_YES, PilsHelloSignaturePurpose::h_addrs, have_id, ikm, LOG, P_Client::mq, msg, my_private_key, my_public_key, P_Client::next, print_uri(), PilsHelloSignaturePurpose::purpose, signed_hello, and GNUNET_CRYPTO_EccSignaturePurpose::size.

Referenced by handle_feed_addresses(), and run().

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

◆ check_feed_addresses()

static int check_feed_addresses ( void *  cls,
const struct FeedAddressesMessage msg 
)
static

Checker for feed messages.

Parameters
clsclient who sent the message
messagethe message received

Definition at line 283 of file gnunet-service-pils.c.

285{
286 size_t msg_size;
287 uint32_t block_bytes;
288 (void) cls;
289
290 msg_size = ntohs (msg->header.size);
291 block_bytes = ntohl (msg->block_len);
292 if (msg_size != sizeof (*msg) + block_bytes)
293 {
295 "The msg_size (%lu) is not %lu (header) + %u (block)\n",
296 msg_size,
297 sizeof (*msg),
298 block_bytes);
299 return GNUNET_SYSERR;
300 }
301 return GNUNET_OK;
302}
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.

References GNUNET_ERROR_TYPE_ERROR, GNUNET_OK, GNUNET_SYSERR, LOG, msg, and GNUNET_MessageHeader::size.

◆ handle_feed_addresses()

static void handle_feed_addresses ( void *  cls,
const struct FeedAddressesMessage message 
)
static

Handler for feed addresses message from client.

A client (must be core) sent us the hash of the current set of addresses. This triggers the generation of the new peer id.

Parameters
clsclient who sent the message
messagethe message received

Definition at line 315 of file gnunet-service-pils.c.

317{
318 struct P_Client *client = cls;
320 uint32_t block_bytes;
321
323 "PILS received FEED_ADDRESSES message from client\n");
324
325 /* If there's a peer id generation scheduled, just kill it and generate an id
326 * on the more recent address */
327 block_bytes = ntohl (message->block_len);
329 block_bytes,
330 GNUNET_YES);
331 do_generate_pid (parser);
332
335}
static void do_generate_pid(const struct GNUNET_HELLO_Parser *parser)
Generate the peer id from the addresses hash and the initial secret key.
void GNUNET_HELLO_parser_free(struct GNUNET_HELLO_Parser *parser)
Release resources of a builder.
Definition hello-uri.c:379
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_block_(const void *block, size_t block_size, int noverify)
Parse block.
Definition hello-uri.c:533
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition service.c:2433
uint32_t block_len
For alignment.
Definition pils.h:132
Context for parsing HELLOs.
Definition hello-uri.c:232

References FeedAddressesMessage::block_len, P_Client::client, do_generate_pid(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_HELLO_parser_free(), GNUNET_HELLO_parser_from_block_(), GNUNET_SERVICE_client_continue(), GNUNET_YES, and LOG.

Here is the call graph for this function:

◆ handle_decaps()

static void handle_decaps ( void *  cls,
const struct DecapsMessage message 
)
static

Handler for decaps request message from client.

Parameters
clsclient who sent the message
messagethe message received

Definition at line 345 of file gnunet-service-pils.c.

347{
348 struct P_Client *client = cls;
349 struct DecapsResultMessage *rmsg;
350 struct GNUNET_MQ_Envelope *env;
352
354 "PILS received KEM_DECAPS message from client\n");
355
357 &message->c,
358 &rmsg->key))
359 {
361 "PILS failed to decapsulate encapsulation received from client\n");
362 memset (&rmsg->key, 0, sizeof (rmsg->key));
363 }
364
365 rmsg->rid = message->rid;
366 GNUNET_MQ_send (client->mq, env);
368}
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_kem_decaps(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_HpkeEncapsulation *c, struct GNUNET_ShortHashCode *prk)
Decapsulate a key for a private EdDSA key.
@ GNUNET_ERROR_TYPE_WARNING
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:305
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
#define GNUNET_MESSAGE_TYPE_PILS_DECAPS_RESULT
Decaps result.
uint32_t rid
Request ID.
Definition pils.h:157
struct GNUNET_CRYPTO_HpkeEncapsulation c
Encapsulation to decapsulate.
Definition pils.h:152
Message containing the decapsulated key.
Definition pils.h:164
uint32_t rid
Request ID.
Definition pils.h:178
struct GNUNET_ShortHashCode key
The decapsulated key.
Definition pils.h:173

References DecapsMessage::c, P_Client::client, env, GNUNET_CRYPTO_eddsa_kem_decaps(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_MESSAGE_TYPE_PILS_DECAPS_RESULT, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_OK, GNUNET_SERVICE_client_continue(), DecapsResultMessage::key, LOG, P_Client::mq, my_private_key, DecapsMessage::rid, and DecapsResultMessage::rid.

Here is the call graph for this function:

◆ check_sign()

static int check_sign ( void *  cls,
const struct SignRequestMessage msg 
)
static

Handler for sign request message from client.

Parameters
clsclient sending the message
er_msgmessage of type struct EditRecordSetMessage
Returns
GNUNET_OK if er_msg is well-formed

Definition at line 379 of file gnunet-service-pils.c.

380{
382 size_t msg_size;
383 (void) cls;
384
385 msg_size = ntohs (msg->header.size);
386 if (msg_size <= sizeof (*msg) + sizeof (struct
388 {
390 "The msg_size (%lu) is not big enough for msg (%lu) + purpose struct (%lu)\n",
391 msg_size,
392 sizeof (*msg),
393 sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose));
394 return GNUNET_SYSERR;
395 }
396 purp = (struct GNUNET_CRYPTO_EccSignaturePurpose*) &msg[1];
397 if (msg_size <= sizeof (*msg) + ntohs (purp->size))
398 {
400 "The msg_size (%lu) is not big enough for msg (%lu) + purpose (%u)\n",
401 msg_size,
402 sizeof (*msg),
403 ntohs (purp->size));
404 return GNUNET_SYSERR;
405 }
406 return GNUNET_OK;
407}
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...

References GNUNET_ERROR_TYPE_ERROR, GNUNET_OK, GNUNET_SYSERR, LOG, msg, GNUNET_MessageHeader::size, and GNUNET_CRYPTO_EccSignaturePurpose::size.

◆ handle_sign()

static void handle_sign ( void *  cls,
const struct SignRequestMessage message 
)
static

Handler for sign request message from client.

Parameters
clsclient who sent the message
messagethe message received

Definition at line 417 of file gnunet-service-pils.c.

419{
420 struct P_Client *client = cls;
421 struct SignResultMessage *rmsg;
422 struct GNUNET_MQ_Envelope *env;
425
427 "PILS received SIGN message from client\n");
428
429 purp = (struct GNUNET_CRYPTO_EccSignaturePurpose*) &message[1];
431 purp,
432 &rmsg->sig))
433 {
435 "PILS failed to sign message received from client\n");
436 memset (&rmsg->sig, 0, sizeof (rmsg->sig));
437 }
439 "PILS sent SIGN_RESULT message to client %p\n",
440 client->mq);
442 rmsg->rid = message->rid;
443 GNUNET_MQ_send (client->mq, env);
445}
#define GNUNET_MESSAGE_TYPE_PILS_SIGN_RESULT
The service sends the requested signature to the client.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
uint32_t rid
Request ID.
Definition pils.h:222
Message containing the signature.
Definition pils.h:185
uint32_t rid
Request ID.
Definition pils.h:204
struct GNUNET_PeerIdentity peer_id
The peer identity that produces the signature.
Definition pils.h:194
struct GNUNET_CRYPTO_EddsaSignature sig
The signature.
Definition pils.h:199

References P_Client::client, env, GNUNET_CRYPTO_eddsa_sign_(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_MESSAGE_TYPE_PILS_SIGN_RESULT, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_OK, GNUNET_SERVICE_client_continue(), LOG, P_Client::mq, my_private_key, my_public_key, SignResultMessage::peer_id, GNUNET_PeerIdentity::public_key, SignResultMessage::rid, SignRequestMessage::rid, and SignResultMessage::sig.

Here is the call graph for this function:

◆ shutdown_task()

static void shutdown_task ( void *  cls)
static

Task run during shutdown.

Parameters
clsunused

Definition at line 454 of file gnunet-service-pils.c.

455{
456 struct P_Client *c;
457 (void) cls;
458
460 "PILS shutting down\n");
461 c = clients_head;
462 while (NULL != c)
463 {
464 struct P_Client *c_delete = c;
465
466 c = c->next;
468 /* No need to remove from DLL or free here - #client_disconnect_cb(), which
469 * is called by GNUNET_SERVICE_client_drop(), takes care of this. */
470 }
471 if (NULL != signed_hello)
473 cfg = NULL;
474 if (NULL != generate_pid_task)
477}
void GNUNET_CRYPTO_eddsa_key_clear(struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
Clear memory that was used to store a private key.
Definition crypto_ecc.c:447
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:980
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition service.c:2462

References cfg, P_Client::client, clients_head, generate_pid_task, GNUNET_CRYPTO_eddsa_key_clear(), GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_SCHEDULER_cancel(), GNUNET_SERVICE_client_drop(), LOG, my_private_key, P_Client::next, and signed_hello.

Here is the call graph for this function:

◆ run()

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

Set up the service.

Parameters
clsclosure - unused
cconfiguration to use
servicethe initialized service - unused

Definition at line 488 of file gnunet-service-pils.c.

491{
492 cfg = c;
494 "PILS starting\n");
496 load_ikm ();
497 /* Generate an initial peer id from no addresses at all
498 * This is needed for scenarios in which we have only local addresses. */
499 do_generate_pid (NULL);
501}
struct GNUNET_SCHEDULER_Task * shutdown_task
static void load_ikm()
Get the initial secret key for generating the peer id.
@ GNUNET_NO
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,...
Definition scheduler.c:1339

References cfg, do_generate_pid(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_NO, GNUNET_SCHEDULER_add_shutdown(), have_id, load_ikm(), LOG, and shutdown_task.

Here is the call 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.

This stores the client in a DLL. If we have a peer id, send it immediately to the api/client.

Parameters
clsclosure for the service - unused
cthe new client that connected to the service
mqthe message queue used to send messages to the client
Returns
the P_Client as closure to handlers and disconnect

Definition at line 516 of file gnunet-service-pils.c.

519{
520 struct P_Client *client;
521 (void) cls;
522
523 LOG (GNUNET_ERROR_TYPE_DEBUG, "A client `%p' connected\n",
524 mq);
525 client = GNUNET_new (struct P_Client);
526 client->client = c;
527 client->mq = mq;
530 client);
531 if (GNUNET_YES == have_id)
532 {
534 }
535 return client;
536}
static struct P_Client * clients_tail
Tail of the liked list of clients.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_MQ_Handle * mq
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.
struct GNUNET_MQ_Handle * mq
Message queue for the client.
Definition service.c:273

References P_Client::client, clients_head, clients_tail, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MQ_send_copy(), GNUNET_new, GNUNET_YES, have_id, LOG, mq, GNUNET_SERVICE_Client::mq, and signed_hello.

Here is the call 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.

Remove the client from the DLL

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

Definition at line 549 of file gnunet-service-pils.c.

552{
553 struct P_Client *client_iter;
554 (void) cls;
555
556 client_iter = clients_head;
557 while (NULL != client_iter)
558 {
559 struct P_Client *client_next = client_iter->next;
560
561 if (client_iter->client == c)
562 {
565 client_iter);
566 GNUNET_free (client_iter);
567 }
568 client_iter = client_next;
569 }
570}
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.

References P_Client::client, clients_head, clients_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_free, and P_Client::next.

◆ GNUNET_SERVICE_MAIN()

GNUNET_SERVICE_MAIN ( GNUNET_OS_project_data_gnunet()  ,
"pils"  ,
GNUNET_SERVICE_OPTION_NONE  ,
run,
client_connect_cb,
client_disconnect_cb,
NULL  ,
GNUNET_MQ_hd_var_size(feed_addresses, GNUNET_MESSAGE_TYPE_PILS_FEED_ADDRESSES, struct FeedAddressesMessage, NULL)  ,
GNUNET_MQ_hd_fixed_size(decaps, GNUNET_MESSAGE_TYPE_PILS_KEM_DECAPS, struct DecapsMessage, NULL)  ,
GNUNET_MQ_hd_var_size(sign, GNUNET_MESSAGE_TYPE_PILS_SIGN_REQUEST, struct SignRequestMessage, NULL)  ,
GNUNET_MQ_handler_end()   
)

Define "main" method using service macro.

Variable Documentation

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Handle to our current configuration.

Definition at line 46 of file gnunet-service-pils.c.

Referenced by load_ikm(), run(), and shutdown_task().

◆ generate_pid_task

struct GNUNET_SCHEDULER_Task* generate_pid_task
static

Task to schedule the generation of the peer id.

Definition at line 52 of file gnunet-service-pils.c.

Referenced by do_generate_pid(), and shutdown_task().

◆ addresses_hash

struct GNUNET_HashCode addresses_hash

Hash of the canonicalized addresses.

This is computed by the api, passed to the service as representation of the addresses. From it the service generates the peer id. It is also passed back to the api alongside the peer id to connect the peer id to the addresses it was based upon.

Definition at line 61 of file gnunet-service-pils.c.

Referenced by do_generate_pid().

◆ my_private_key

struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key

The current private key.

Own private key.

Definition at line 67 of file gnunet-service-pils.c.

Referenced by do_generate_pid(), handle_decaps(), handle_sign(), and shutdown_task().

◆ my_public_key

struct GNUNET_CRYPTO_EddsaPublicKey my_public_key

The current public key.

Definition at line 73 of file gnunet-service-pils.c.

Referenced by do_generate_pid(), GNUNET_FS_uri_loc_create(), and handle_sign().

◆ ikm

unsigned char ikm[256/8]
static

The initial key material for the peer.

Definition at line 78 of file gnunet-service-pils.c.

Referenced by checkvec(), do_generate_pid(), labeled_extract(), load_ikm(), load_ikm(), output_vectors(), and pid_change_cb().

◆ clients_head

struct P_Client* clients_head
static

Head of the liked list of clients.

Definition at line 110 of file gnunet-service-pils.c.

Referenced by client_connect_cb(), client_disconnect_cb(), do_generate_pid(), and shutdown_task().

◆ clients_tail

struct P_Client* clients_tail
static

Tail of the liked list of clients.

Definition at line 116 of file gnunet-service-pils.c.

Referenced by client_connect_cb(), and client_disconnect_cb().

◆ have_id

int have_id
static

Peer ID was calculated already at least once.

Definition at line 122 of file gnunet-service-pils.c.

Referenced by client_connect_cb(), do_generate_pid(), and run().

◆ signed_hello

struct GNUNET_MQ_Envelope* signed_hello
static

Current signed HELLO.

Definition at line 127 of file gnunet-service-pils.c.

Referenced by client_connect_cb(), do_generate_pid(), and shutdown_task().