GNUnet  0.20.0
transport_api_address_to_string.c File Reference

enable clients to convert addresses to human readable strings More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_arm_service.h"
#include "gnunet_hello_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_transport_service.h"
#include "transport.h"
Include dependency graph for transport_api_address_to_string.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_TRANSPORT_AddressToStringContext
 Context for the address lookup. More...
 

Functions

static int check_reply (void *cls, const struct AddressToStringResultMessage *atsm)
 Function called with responses from the service. More...
 
static void handle_reply (void *cls, const struct AddressToStringResultMessage *atsm)
 Function called with responses from the service. 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_TRANSPORT_AddressToStringContextGNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_HELLO_Address *address, int numeric, struct GNUNET_TIME_Relative timeout, GNUNET_TRANSPORT_AddressToStringCallback aluc, void *aluc_cls)
 Convert a binary address into a human readable address. More...
 
void GNUNET_TRANSPORT_address_to_string_cancel (struct GNUNET_TRANSPORT_AddressToStringContext *alc)
 Cancel request for address conversion. More...
 

Detailed Description

enable clients to convert addresses to human readable strings

Author
Christian Grothoff

Definition in file transport_api_address_to_string.c.

Function Documentation

◆ check_reply()

static int check_reply ( void *  cls,
const struct AddressToStringResultMessage atsm 
)
static

Function called with responses from the service.

Parameters
clsour struct GNUNET_TRANSPORT_AddressToStringContext *
atsmmessage with the human-readable address
Returns
GNUNET_OK if message is well-formed

Definition at line 63 of file transport_api_address_to_string.c.

65 {
66  uint16_t size = ntohs (atsm->header.size) - sizeof(*atsm);
67  const char *address;
68  int result;
69  uint32_t addr_len;
70 
71  result = (int) ntohl (atsm->res);
72  addr_len = ntohl (atsm->addr_len);
73  if (GNUNET_SYSERR == result)
74  return GNUNET_OK;
75  if (0 == size)
76  {
77  if (GNUNET_OK != result)
78  {
79  GNUNET_break (0);
80  return GNUNET_SYSERR;
81  }
82  return GNUNET_OK;
83  }
84  address = (const char *) &atsm[1];
85  if ((addr_len > size) ||
86  (address[addr_len - 1] != '\0'))
87  {
88  /* invalid reply */
89  GNUNET_break (0);
90  return GNUNET_SYSERR;
91  }
92  return GNUNET_OK;
93 }
static char * address
GNS address for this phone.
static int result
Global testing status.
@ GNUNET_OK
@ 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
uint32_t addr_len
Length of the following string, zero if is GNUNET_SYSERR.
Definition: transport.h:339
struct GNUNET_MessageHeader header
Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY.
Definition: transport.h:328
uint32_t res
GNUNET_OK if the conversion succeeded, GNUNET_SYSERR if it failed
Definition: transport.h:334
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.

References AddressToStringResultMessage::addr_len, address, GNUNET_break, GNUNET_OK, GNUNET_SYSERR, AddressToStringResultMessage::header, consensus-simulation::int, AddressToStringResultMessage::res, result, GNUNET_MessageHeader::size, and size.

◆ handle_reply()

static void handle_reply ( void *  cls,
const struct AddressToStringResultMessage atsm 
)
static

Function called with responses from the service.

Parameters
clsour struct GNUNET_TRANSPORT_AddressToStringContext *
atsmmessage with the human-readable address

Definition at line 103 of file transport_api_address_to_string.c.

105 {
106  struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls;
107  uint16_t size = ntohs (atsm->header.size) - sizeof(*atsm);
108  const char *address;
109  int result;
110 
111  result = (int) ntohl (atsm->res);
112  if (GNUNET_SYSERR == result)
113  {
114  /* expect more replies; as this is not the last
115  call, we must pass the empty string for the address */
117  "Address resolution failed\n");
118  alucb->cb (alucb->cb_cls,
119  "",
120  GNUNET_NO);
121  return;
122  }
123  if (0 == size)
124  {
125  /* we are done (successfully, without communication errors) */
126  alucb->cb (alucb->cb_cls,
127  NULL,
128  GNUNET_OK);
130  return;
131  }
132  address = (const char *) &atsm[1];
133  /* return normal reply to caller, also expect more replies */
134  alucb->cb (alucb->cb_cls,
135  address,
136  GNUNET_OK);
137 }
#define GNUNET_log(kind,...)
@ GNUNET_NO
@ GNUNET_ERROR_TYPE_DEBUG
void GNUNET_TRANSPORT_address_to_string_cancel(struct GNUNET_TRANSPORT_AddressToStringContext *alc)
Cancel request for address conversion.
GNUNET_TRANSPORT_AddressToStringCallback cb
Function to call with the human-readable address.

References address, GNUNET_TRANSPORT_AddressToStringContext::cb, GNUNET_TRANSPORT_AddressToStringContext::cb_cls, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_TRANSPORT_address_to_string_cancel(), AddressToStringResultMessage::header, consensus-simulation::int, AddressToStringResultMessage::res, result, GNUNET_MessageHeader::size, and 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
clsthe struct GNUNET_TRANSPORT_AddressToStringContext *
errorerror code

Definition at line 150 of file transport_api_address_to_string.c.

152 {
153  struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls;
154 
156  "Disconnected from transport, address resolution failed\n");
157  alucb->cb (alucb->cb_cls,
158  NULL,
159  GNUNET_SYSERR);
161 }

References GNUNET_TRANSPORT_AddressToStringContext::cb, GNUNET_TRANSPORT_AddressToStringContext::cb_cls, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_SYSERR, and GNUNET_TRANSPORT_address_to_string_cancel().

Referenced by GNUNET_TRANSPORT_address_to_string().

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