X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fhello%2Fgnunet-hello.c;h=6fd5756ba96c6d82259431d53cab7cea8311457a;hb=5b32752cd7b02adcb8e6fec7798637638c6f63a0;hp=be7719e945bd9e0d52687b9bc01a229ab629a78a;hpb=1bf2b49b14f9058cd2d4223752c74ef59bbf3435;p=oweals%2Fgnunet.git diff --git a/src/hello/gnunet-hello.c b/src/hello/gnunet-hello.c index be7719e94..6fd5756ba 100644 --- a/src/hello/gnunet-hello.c +++ b/src/hello/gnunet-hello.c @@ -1,6 +1,6 @@ /* This file is part of GNUnet - (C) 2012 Christian Grothoff (and other contributing authors) + Copyright (C) 2012 GNUnet e.V. GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -14,8 +14,8 @@ You should have received a copy of the GNU General Public License along with GNUnet; see the file COPYING. If not, write to the - Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. */ /** * @file hello/gnunet-hello.c @@ -23,14 +23,11 @@ * @author Christian Grothoff */ #include "platform.h" +#include "gnunet_protocols.h" #include "gnunet_hello_lib.h" -#define DEBUG GNUNET_EXTRA_LOGGING - -#define VERBOSE GNUNET_NO - /** - * Closure for 'add_to_buf'. + * Closure for #add_to_buf(). */ struct AddContext { @@ -38,7 +35,7 @@ struct AddContext * Where to add. */ char *buf; - + /** * Maximum number of bytes left */ @@ -50,29 +47,33 @@ struct AddContext size_t ret; }; +static int address_count; + /** * Add the given address with infinit expiration to the buffer. * - * @param ac add context + * @param cls closure * @param address address to add * @param expiration old expiration - * @return GNUNET_OK keep iterating + * @return #GNUNET_OK keep iterating */ static int -add_to_buf (void *cls, const struct GNUNET_HELLO_Address *address, +add_to_buf (void *cls, + const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration) { struct AddContext *ac = cls; size_t ret; - ret = GNUNET_HELLO_add_address (address, + ret = GNUNET_HELLO_add_address (address, GNUNET_TIME_UNIT_FOREVER_ABS, ac->buf, ac->max); ac->buf += ret; ac->max -= ret; - ac->ret += ret; + ac->ret += ret; + address_count ++; return GNUNET_OK; } @@ -85,19 +86,21 @@ add_to_buf (void *cls, const struct GNUNET_HELLO_Address *address, * @param buf where to add the addresses * @return number of bytes added, 0 to terminate */ -static size_t -add_from_hello (void *cls, size_t max, void *buf) +static ssize_t +add_from_hello (void *cls, + size_t max, + void *buf) { struct GNUNET_HELLO_Message **orig = cls; struct AddContext ac; if (NULL == *orig) - return 0; /* already done */ + return GNUNET_SYSERR; /* already done */ ac.buf = buf; ac.max = max; ac.ret = 0; GNUNET_assert (NULL == - GNUNET_HELLO_iterate_addresses (*orig, + GNUNET_HELLO_iterate_addresses (*orig, GNUNET_NO, &add_to_buf, &ac)); *orig = NULL; @@ -111,8 +114,9 @@ main (int argc, char *argv[]) struct GNUNET_DISK_FileHandle *fh; struct GNUNET_HELLO_Message *orig; struct GNUNET_HELLO_Message *result; - struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pk; + struct GNUNET_PeerIdentity pid; uint64_t fsize; + address_count = 0; GNUNET_log_setup ("gnunet-hello", "INFO", NULL); if (argc != 2) @@ -122,7 +126,7 @@ main (int argc, char *argv[]) _("Call with name of HELLO file to modify.\n")); return 1; } - if (GNUNET_OK != GNUNET_DISK_file_size (argv[1], &fsize, GNUNET_YES)) + if (GNUNET_OK != GNUNET_DISK_file_size (argv[1], &fsize, GNUNET_YES, GNUNET_YES)) { FPRINTF (stderr, _("Error accessing file `%s': %s\n"), @@ -144,7 +148,7 @@ main (int argc, char *argv[]) argv[1]); return 1; } - fh = GNUNET_DISK_file_open (argv[1], + fh = GNUNET_DISK_file_open (argv[1], GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_USER_READ); if (NULL == fh) @@ -156,24 +160,37 @@ main (int argc, char *argv[]) return 1; } { - char buf[fsize]; - - GNUNET_assert (fsize == + char buf[fsize] GNUNET_ALIGN; + + GNUNET_assert (fsize == GNUNET_DISK_file_read (fh, buf, fsize)); GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); orig = (struct GNUNET_HELLO_Message *) buf; - if ( (fsize != GNUNET_HELLO_size (orig)) || - (GNUNET_OK != GNUNET_HELLO_get_key (orig, &pk)) ) + if ( (fsize < GNUNET_HELLO_size (orig)) || + (GNUNET_OK != GNUNET_HELLO_get_id (orig, + &pid)) ) { FPRINTF (stderr, _("Did not find well-formed HELLO in file `%s'\n"), argv[1]); return 1; } - result = GNUNET_HELLO_create (&pk, &add_from_hello, &orig); + { + char *pids; + + pids = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid.public_key); + fprintf (stdout, + "Processing HELLO for peer `%s'\n", + pids); + GNUNET_free (pids); + } + result = GNUNET_HELLO_create (&pid.public_key, + &add_from_hello, + &orig, + GNUNET_HELLO_is_friend_only (orig)); GNUNET_assert (NULL != result); - fh = GNUNET_DISK_file_open (argv[1], - GNUNET_DISK_OPEN_WRITE, + fh = GNUNET_DISK_file_open (argv[1], + GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE, GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); if (NULL == fh) { @@ -198,6 +215,10 @@ main (int argc, char *argv[]) } GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); } + FPRINTF (stderr, + _("Modified %u addresses, wrote %u bytes\n"), + address_count, + (unsigned int) fsize); return 0; }