2 This file is part of GNUnet
3 (C) 2012 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file hello/gnunet-hello.c
22 * @brief change HELLO files to never expire
23 * @author Christian Grothoff
26 #include "gnunet_hello_lib.h"
29 * Closure for 'add_to_buf'.
39 * Maximum number of bytes left
44 * Number of bytes added so far.
51 * Add the given address with infinit expiration to the buffer.
54 * @param address address to add
55 * @param expiration old expiration
56 * @return GNUNET_OK keep iterating
59 add_to_buf (void *cls, const struct GNUNET_HELLO_Address *address,
60 struct GNUNET_TIME_Absolute expiration)
62 struct AddContext *ac = cls;
65 ret = GNUNET_HELLO_add_address (address,
66 GNUNET_TIME_UNIT_FOREVER_ABS,
77 * Add addresses from the address list to the HELLO.
79 * @param cls the HELLO with the addresses to add
80 * @param max maximum space available
81 * @param buf where to add the addresses
82 * @return number of bytes added, 0 to terminate
85 add_from_hello (void *cls, size_t max, void *buf)
87 struct GNUNET_HELLO_Message **orig = cls;
91 return 0; /* already done */
95 GNUNET_assert (NULL ==
96 GNUNET_HELLO_iterate_addresses (*orig,
97 GNUNET_NO, &add_to_buf,
105 main (int argc, char *argv[])
107 struct GNUNET_DISK_FileHandle *fh;
108 struct GNUNET_HELLO_Message *orig;
109 struct GNUNET_HELLO_Message *result;
110 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pk;
113 GNUNET_log_setup ("gnunet-hello", "INFO", NULL);
118 _("Call with name of HELLO file to modify.\n"));
121 if (GNUNET_OK != GNUNET_DISK_file_size (argv[1], &fsize, GNUNET_YES, GNUNET_YES))
124 _("Error accessing file `%s': %s\n"),
132 _("File `%s' is too big to be a HELLO\n"),
136 if (fsize < sizeof (struct GNUNET_MessageHeader))
139 _("File `%s' is too small to be a HELLO\n"),
143 fh = GNUNET_DISK_file_open (argv[1],
144 GNUNET_DISK_OPEN_READ,
145 GNUNET_DISK_PERM_USER_READ);
149 _("Error opening file `%s': %s\n"),
155 char buf[fsize] GNUNET_ALIGN;
157 GNUNET_assert (fsize ==
158 GNUNET_DISK_file_read (fh, buf, fsize));
159 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
160 orig = (struct GNUNET_HELLO_Message *) buf;
161 if ( (fsize != GNUNET_HELLO_size (orig)) ||
162 (GNUNET_OK != GNUNET_HELLO_get_key (orig, &pk)) )
165 _("Did not find well-formed HELLO in file `%s'\n"),
169 result = GNUNET_HELLO_create (&pk, &add_from_hello, &orig);
170 GNUNET_assert (NULL != result);
171 fh = GNUNET_DISK_file_open (argv[1],
172 GNUNET_DISK_OPEN_WRITE,
173 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
177 _("Error opening file `%s': %s\n"),
180 GNUNET_free (result);
183 fsize = GNUNET_HELLO_size (result);
184 if (fsize != GNUNET_DISK_file_write (fh,
189 _("Error writing HELLO to file `%s': %s\n"),
192 (void) GNUNET_DISK_file_close (fh);
195 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
200 /* end of gnunet-hello.c */