GNUnet  0.10.x
Data Structures | Functions | Variables
gnunet-hello.c File Reference

change HELLO files to never expire More...

#include "platform.h"
#include "gnunet_protocols.h"
#include "gnunet_hello_lib.h"
Include dependency graph for gnunet-hello.c:

Go to the source code of this file.

Data Structures

struct  AddContext
 Closure for add_to_buf(). More...
 

Functions

static int add_to_buf (void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
 Add the given address with infinit expiration to the buffer. More...
 
static ssize_t add_from_hello (void *cls, size_t max, void *buf)
 Add addresses from the address list to the HELLO. More...
 
int main (int argc, char *argv[])
 

Variables

static int address_count
 

Detailed Description

change HELLO files to never expire

Author
Christian Grothoff

Definition in file gnunet-hello.c.

Function Documentation

◆ add_to_buf()

static int add_to_buf ( void *  cls,
const struct GNUNET_HELLO_Address address,
struct GNUNET_TIME_Absolute  expiration 
)
static

Add the given address with infinit expiration to the buffer.

Parameters
clsclosure
addressaddress to add
expirationold expiration
Returns
GNUNET_OK keep iterating

Definition at line 62 of file gnunet-hello.c.

References ac, address_count, AddContext::buf, GNUNET_HELLO_add_address(), GNUNET_OK, GNUNET_TIME_UNIT_FOREVER_ABS, AddContext::max, and AddContext::ret.

Referenced by add_from_hello().

65 {
66  struct AddContext *ac = cls;
67  size_t ret;
68 
69  ret = GNUNET_HELLO_add_address (address,
71  ac->buf,
72  ac->max);
73  ac->buf += ret;
74  ac->max -= ret;
75  ac->ret += ret;
76  address_count ++;
77  return GNUNET_OK;
78 }
char * buf
Where to add.
Definition: gnunet-hello.c:37
size_t max
Maximum number of bytes left.
Definition: gnunet-hello.c:42
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
static int address_count
Definition: gnunet-hello.c:50
size_t GNUNET_HELLO_add_address(const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration, char *target, size_t max)
Copy the given address information into the given buffer using the format of HELLOs.
Definition: hello.c:109
static struct GNUNET_MQ_Envelope * ac
Handle to current GNUNET_PEERINFO_add_peer() operation.
Closure for add_to_buf().
Definition: gnunet-hello.c:32
size_t ret
Number of bytes added so far.
Definition: gnunet-hello.c:47
Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_from_hello()

static ssize_t add_from_hello ( void *  cls,
size_t  max,
void *  buf 
)
static

Add addresses from the address list to the HELLO.

Parameters
clsthe HELLO with the addresses to add
maxmaximum space available
bufwhere to add the addresses
Returns
number of bytes added, 0 to terminate

Definition at line 90 of file gnunet-hello.c.

References add_to_buf(), AddContext::buf, GNUNET_assert, GNUNET_HELLO_iterate_addresses(), GNUNET_NO, GNUNET_SYSERR, AddContext::max, and AddContext::ret.

Referenced by main().

93 {
94  struct GNUNET_HELLO_Message **orig = cls;
95  struct AddContext ac;
96 
97  if (NULL == *orig)
98  return GNUNET_SYSERR; /* already done */
99  ac.buf = buf;
100  ac.max = max;
101  ac.ret = 0;
102  GNUNET_assert (NULL ==
105  &ac));
106  *orig = NULL;
107  return ac.ret;
108 }
A HELLO message is used to exchange information about transports with other peers.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
size_t max
Maximum number of bytes left.
Definition: gnunet-hello.c:42
#define GNUNET_NO
Definition: gnunet_common.h:81
static int add_to_buf(void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
Add the given address with infinit expiration to the buffer.
Definition: gnunet-hello.c:62
struct GNUNET_HELLO_Message * GNUNET_HELLO_iterate_addresses(const struct GNUNET_HELLO_Message *msg, int return_modified, GNUNET_HELLO_AddressIterator it, void *it_cls)
Iterate over all of the addresses in the HELLO.
Definition: hello.c:254
static char buf[2048]
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static struct GNUNET_MQ_Envelope * ac
Handle to current GNUNET_PEERINFO_add_peer() operation.
Closure for add_to_buf().
Definition: gnunet-hello.c:32
Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 112 of file gnunet-hello.c.

References _, add_from_hello(), address_count, AddContext::buf, fh, FPRINTF, GNUNET_ALIGN, GNUNET_assert, GNUNET_CRYPTO_eddsa_public_key_to_string(), GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_read(), GNUNET_DISK_file_size(), GNUNET_DISK_file_write(), GNUNET_DISK_OPEN_READ, GNUNET_DISK_OPEN_TRUNCATE, GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_free, GNUNET_HELLO_create(), GNUNET_HELLO_get_id(), GNUNET_HELLO_is_friend_only(), GNUNET_HELLO_size(), GNUNET_log_setup(), GNUNET_OK, GNUNET_YES, GNUNET_PeerIdentity::public_key, result, and STRERROR.

113 {
114  struct GNUNET_DISK_FileHandle *fh;
115  struct GNUNET_HELLO_Message *orig;
117  struct GNUNET_PeerIdentity pid;
118  uint64_t fsize;
119  address_count = 0;
120 
121  GNUNET_log_setup ("gnunet-hello", "INFO", NULL);
122  if (argc != 2)
123  {
124  FPRINTF (stderr,
125  "%s",
126  _("Call with name of HELLO file to modify.\n"));
127  return 1;
128  }
129  if (GNUNET_OK != GNUNET_DISK_file_size (argv[1], &fsize, GNUNET_YES, GNUNET_YES))
130  {
131  FPRINTF (stderr,
132  _("Error accessing file `%s': %s\n"),
133  argv[1],
134  STRERROR (errno));
135  return 1;
136  }
137  if (fsize > 65536)
138  {
139  FPRINTF (stderr,
140  _("File `%s' is too big to be a HELLO\n"),
141  argv[1]);
142  return 1;
143  }
144  if (fsize < sizeof (struct GNUNET_MessageHeader))
145  {
146  FPRINTF (stderr,
147  _("File `%s' is too small to be a HELLO\n"),
148  argv[1]);
149  return 1;
150  }
151  fh = GNUNET_DISK_file_open (argv[1],
154  if (NULL == fh)
155  {
156  FPRINTF (stderr,
157  _("Error opening file `%s': %s\n"),
158  argv[1],
159  STRERROR (errno));
160  return 1;
161  }
162  {
163  char buf[fsize] GNUNET_ALIGN;
164 
165  GNUNET_assert (fsize ==
166  GNUNET_DISK_file_read (fh, buf, fsize));
168  orig = (struct GNUNET_HELLO_Message *) buf;
169  if ( (fsize < GNUNET_HELLO_size (orig)) ||
170  (GNUNET_OK != GNUNET_HELLO_get_id (orig,
171  &pid)) )
172  {
173  FPRINTF (stderr,
174  _("Did not find well-formed HELLO in file `%s'\n"),
175  argv[1]);
176  return 1;
177  }
178  {
179  char *pids;
180 
182  fprintf (stdout,
183  "Processing HELLO for peer `%s'\n",
184  pids);
185  GNUNET_free (pids);
186  }
189  &orig,
191  GNUNET_assert (NULL != result);
192  fh = GNUNET_DISK_file_open (argv[1],
195  if (NULL == fh)
196  {
197  FPRINTF (stderr,
198  _("Error opening file `%s': %s\n"),
199  argv[1],
200  STRERROR (errno));
201  GNUNET_free (result);
202  return 1;
203  }
204  fsize = GNUNET_HELLO_size (result);
205  if (fsize != GNUNET_DISK_file_write (fh,
206  result,
207  fsize))
208  {
209  FPRINTF (stderr,
210  _("Error writing HELLO to file `%s': %s\n"),
211  argv[1],
212  STRERROR (errno));
213  (void) GNUNET_DISK_file_close (fh);
214  return 1;
215  }
217  }
218  FPRINTF (stderr,
219  _("Modified %u addresses, wrote %u bytes\n"),
221  (unsigned int) fsize);
222  return 0;
223 }
Open the file for reading.
int GNUNET_HELLO_get_id(const struct GNUNET_HELLO_Message *hello, struct GNUNET_PeerIdentity *peer)
Get the peer identity from a HELLO message.
Definition: hello.c:668
static ssize_t add_from_hello(void *cls, size_t max, void *buf)
Add addresses from the address list to the HELLO.
Definition: gnunet-hello.c:90
A HELLO message is used to exchange information about transports with other peers.
int GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1817
struct GNUNET_HELLO_Message * GNUNET_HELLO_create(const struct GNUNET_CRYPTO_EddsaPublicKey *public_key, GNUNET_HELLO_GenerateAddressListCallback addrgen, void *addrgen_cls, int friend_only)
Construct a HELLO message given the public key, expiration time and an iterator that spews the transp...
Definition: hello.c:204
#define FPRINTF
Definition: plibc.h:683
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:881
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define STRERROR(i)
Definition: plibc.h:676
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
Truncate file if it exists.
char * GNUNET_CRYPTO_eddsa_public_key_to_string(const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:367
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:1049
static char buf[2048]
static int result
Global testing status.
static int fh
Handle to the unique file.
static int address_count
Definition: gnunet-hello.c:50
Open the file for writing.
int GNUNET_HELLO_is_friend_only(const struct GNUNET_HELLO_Message *h)
Return HELLO type.
Definition: hello.c:89
int GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition: disk.c:289
The identity of the host (wraps the signing key of the peer).
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to &#39;struct&#39;s...
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
Definition: hello.c:649
Header for all communications.
#define GNUNET_YES
Definition: gnunet_common.h:80
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1673
Handle used to access files (and pipes).
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Here is the call graph for this function:

Variable Documentation

◆ address_count

int address_count
static

Definition at line 50 of file gnunet-hello.c.

Referenced by add_to_buf(), main(), and ril_network_is_not_full().