From: Christian Grothoff Date: Tue, 8 Nov 2011 19:37:32 +0000 (+0000) Subject: adding address abstraction X-Git-Tag: initial-import-from-subversion-38251~16003 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=ea3ff01740cdfd4505503bcff9f5d889ce1b4545;p=oweals%2Fgnunet.git adding address abstraction --- diff --git a/src/hello/Makefile.am b/src/hello/Makefile.am index 61c84e50e..0122a1918 100644 --- a/src/hello/Makefile.am +++ b/src/hello/Makefile.am @@ -12,7 +12,7 @@ endif lib_LTLIBRARIES = libgnunethello.la libgnunethello_la_SOURCES = \ - hello.c + hello.c address.c libgnunethello_la_LIBADD = \ $(top_builddir)/src/util/libgnunetutil.la $(XLIB) libgnunethello_la_LDFLAGS = \ diff --git a/src/hello/address.c b/src/hello/address.c new file mode 100644 index 000000000..51fb296c3 --- /dev/null +++ b/src/hello/address.c @@ -0,0 +1,64 @@ +/* + This file is part of GNUnet. + (C) 2009 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + 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. +*/ + +/** + * @file hello/address.c + * @brief helper functions for handling addresses + * @author Christian Grothoff + */ +#include "platform.h" +#include "gnunet_hello_lib.h" +#include "gnunet_util_lib.h" + + +/** + * Allocate an address struct. + * + * @param peer the peer + * @param transport_name plugin name + * @param address binary address + * @param address_length number of bytes in 'address' + * @return the address struct + */ +struct GNUNET_HELLO_Address * +GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer, + const char *transport_name, + const void *address, + size_t address_length) +{ + struct GNUNET_HELLO_Address *addr; + size_t slen; + char *end; + + slen = strlen (transport_name) + 1; + addr = GNUNET_malloc (sizeof (struct GNUNET_HELLO_Address) + + address_length + + slen); + addr->peer = *peer; + addr->address = &addr[1]; + end = (char*) &addr[1]; + memcpy (end, address, address_length); + addr->address_length = address_length; + addr->transport_name = &end[address_length]; + memcpy (&end[address_length], transport_name, slen); + return addr; +} + +/* end of address.c */ diff --git a/src/include/gnunet_hello_lib.h b/src/include/gnunet_hello_lib.h index 7f5e5fee0..4e8554b52 100644 --- a/src/include/gnunet_hello_lib.h +++ b/src/include/gnunet_hello_lib.h @@ -1,6 +1,6 @@ /* This file is part of GNUnet. - (C) 2001, 2002, 2003, 2004, 2005, 2006, 2010 Christian Grothoff (and other contributing authors) + (C) 2001, 2002, 2003, 2004, 2005, 2006, 2010, 2011 Christian Grothoff (and other contributing authors) GNUnet is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published @@ -38,6 +38,64 @@ extern "C" #include "gnunet_common.h" #include "gnunet_crypto_lib.h" + +/** + * An address for communicating with a peer. We frequently + * need this tuple and the components cannot really be + * separated. This is NOT the format that would be used + * on the wire. + */ +struct GNUNET_HELLO_Address +{ + + /** + * For which peer is this an address? + */ + struct GNUNET_PeerIdentity peer; + + /** + * Name of the transport plugin enabling the communication using + * this address. + */ + const char *transport_name; + + /** + * Binary representation of the address (plugin-specific). + */ + const void *address; + + /** + * Number of bytes in 'address'. + */ + size_t address_length; + +}; + + +/** + * Allocate an address struct. + * + * @param peer the peer + * @param transport_name plugin name + * @param address binary address + * @param address_length number of bytes in 'address' + * @return the address struct + */ +struct GNUNET_HELLO_Address * +GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer, + const char *transport_name, + const void *address, + size_t address_length); + + +/** + * Free an address. + * + * @param addr address to free + */ +#define GNUNET_HELLO_address_free(addr) GNUNET_free(addr) + + /** * A HELLO message is used to exchange information about * transports with other peers. This struct is guaranteed