GNUnet 0.22.0
identity_api_lookup.c File Reference

api to lookup an ego More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_identity_service.h"
#include "identity.h"
Include dependency graph for identity_api_lookup.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_IDENTITY_EgoLookup
 Handle for ego lookup. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "identity-api", __VA_ARGS__)
 

Functions

static int check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm)
 We received a result code from the service. More...
 
static void handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm)
 We received a result code from the service. More...
 
static int check_identity_update (void *cls, const struct UpdateMessage *um)
 Check validity of identity update message. More...
 
static void handle_identity_update (void *cls, const struct UpdateMessage *um)
 Handle identity update message. More...
 
static void mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
 Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue. More...
 
struct GNUNET_IDENTITY_EgoLookupGNUNET_IDENTITY_ego_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *name, GNUNET_IDENTITY_EgoCallback cb, void *cb_cls)
 Lookup an ego by name. More...
 
void GNUNET_IDENTITY_ego_lookup_cancel (struct GNUNET_IDENTITY_EgoLookup *el)
 Abort ego lookup attempt. More...
 

Detailed Description

api to lookup an ego

Author
Christian Grothoff

Definition in file identity_api_lookup.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "identity-api", __VA_ARGS__)

Definition at line 31 of file identity_api_lookup.c.

Function Documentation

◆ check_identity_result_code()

static int check_identity_result_code ( void *  cls,
const struct ResultCodeMessage rcm 
)
static

We received a result code from the service.

Check the message is well-formed.

Parameters
clsclosure
rcmresult message received
Returns
GNUNET_OK if the message is well-formed

Definition at line 70 of file identity_api_lookup.c.

71{
72 if (sizeof(*rcm) != htons (rcm->header.size))
74 return GNUNET_OK;
75}
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE.
Definition: identity.h:85

References GNUNET_MQ_check_zero_termination, GNUNET_OK, ResultCodeMessage::header, and GNUNET_MessageHeader::size.

◆ handle_identity_result_code()

static void handle_identity_result_code ( void *  cls,
const struct ResultCodeMessage rcm 
)
static

We received a result code from the service.

Parameters
clsclosure
rcmresult message received

Definition at line 85 of file identity_api_lookup.c.

86{
87 struct GNUNET_IDENTITY_EgoLookup *el = cls;
88
89 el->cb (el->cb_cls, NULL);
91}
static struct GNUNET_IDENTITY_EgoLookup * el
Handle to identity lookup.
void GNUNET_IDENTITY_ego_lookup_cancel(struct GNUNET_IDENTITY_EgoLookup *el)
Abort ego lookup attempt.
Handle for ego lookup.
void * cb_cls
Closure for cb.
GNUNET_IDENTITY_EgoCallback cb
Function to call with the result.

References GNUNET_IDENTITY_EgoLookup::cb, GNUNET_IDENTITY_EgoLookup::cb_cls, el, and GNUNET_IDENTITY_ego_lookup_cancel().

Here is the call graph for this function:

◆ check_identity_update()

static int check_identity_update ( void *  cls,
const struct UpdateMessage um 
)
static

Check validity of identity update message.

Parameters
clsclosure
ummessage received
Returns
GNUNET_OK if the message is well-formed

Definition at line 102 of file identity_api_lookup.c.

103{
104 uint16_t size = ntohs (um->header.size);
105 uint16_t name_len = ntohs (um->name_len);
106 const char *str = (const char *) &um[1];
107
108 if ((size < name_len + sizeof(struct UpdateMessage)) ||
109 ((0 != name_len) && ('\0' != str[name_len - 1])))
110 {
111 GNUNET_break (0);
112 return GNUNET_SYSERR;
113 }
114 return GNUNET_OK;
115}
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
static unsigned int size
Size of the "table".
Definition: peer.c:68
Service informs client about status of a pseudonym.
Definition: identity.h:114
uint16_t name_len
Number of bytes in ego name string including 0-termination, in NBO; 0 if the ego was deleted.
Definition: identity.h:124
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE.
Definition: identity.h:118

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, UpdateMessage::header, UpdateMessage::name_len, GNUNET_MessageHeader::size, and size.

◆ handle_identity_update()

static void handle_identity_update ( void *  cls,
const struct UpdateMessage um 
)
static

Handle identity update message.

Parameters
clsclosure
ummessage received

Definition at line 125 of file identity_api_lookup.c.

126{
127 struct GNUNET_IDENTITY_EgoLookup *el = cls;
128 uint16_t name_len = ntohs (um->name_len);
129 const char *str;
130 size_t key_len;
131 size_t kb_read;
132 struct GNUNET_HashCode id;
133 struct GNUNET_IDENTITY_Ego ego;
134 struct GNUNET_CRYPTO_PrivateKey private_key;
135 const char *tmp;
136
137 memset (&ego, 0, sizeof (ego));
138
139 GNUNET_break (GNUNET_YES != ntohs (um->end_of_list));
140 tmp = (const char*) &um[1];
141 str = (0 == name_len) ? NULL : tmp;
142 memset (&private_key, 0, sizeof (private_key));
143 key_len = ntohs (um->header.size) - sizeof (*um) - name_len;
146 key_len,
147 &private_key,
148 &kb_read));
149 GNUNET_assert (key_len == kb_read);
150 GNUNET_CRYPTO_hash (&private_key, sizeof (private_key), &id);
151 ego.pk = private_key;
152 ego.name = (char *) str;
153 ego.id = id;
154 el->cb (el->cb_cls, &ego);
156}
static struct GNUNET_IDENTITY_Handle * id
Handle to IDENTITY.
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
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_read_private_key_from_buffer(const void *buffer, size_t len, struct GNUNET_CRYPTO_PrivateKey *key, size_t *read)
Reads a GNUNET_CRYPTO_PrivateKey from a compact buffer.
Definition: crypto_pkey.c:146
@ GNUNET_YES
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
A private key for an identity as per LSD0001.
A 512-bit hashcode.
Handle for an ego.
Definition: identity.h:37
uint16_t end_of_list
Usually GNUNET_NO, GNUNET_YES to signal end of list.
Definition: identity.h:129

References GNUNET_IDENTITY_EgoLookup::cb, GNUNET_IDENTITY_EgoLookup::cb_cls, el, UpdateMessage::end_of_list, GNUNET_assert, GNUNET_break, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_read_private_key_from_buffer(), GNUNET_IDENTITY_ego_lookup_cancel(), GNUNET_SYSERR, GNUNET_YES, UpdateMessage::header, id, GNUNET_IDENTITY_Ego::id, GNUNET_IDENTITY_Ego::name, UpdateMessage::name_len, GNUNET_IDENTITY_Ego::pk, and GNUNET_MessageHeader::size.

Here is the call graph for this function:

◆ mq_error_handler()

static void mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.

Not every message queue implementation supports an error handler.

Parameters
clsclosure with the struct GNUNET_IDENTITY_EgoLookup *
errorerror code

Definition at line 168 of file identity_api_lookup.c.

169{
170 struct GNUNET_IDENTITY_EgoLookup *el = cls;
171
172 el->cb (el->cb_cls, NULL);
173}

References GNUNET_IDENTITY_EgoLookup::cb, GNUNET_IDENTITY_EgoLookup::cb_cls, and el.

Referenced by GNUNET_IDENTITY_ego_lookup().

Here is the caller graph for this function: