gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r18055 - in gnunet/src: hello include


From: gnunet
Subject: [GNUnet-SVN] r18055 - in gnunet/src: hello include
Date: Tue, 8 Nov 2011 20:37:32 +0100

Author: grothoff
Date: 2011-11-08 20:37:32 +0100 (Tue, 08 Nov 2011)
New Revision: 18055

Added:
   gnunet/src/hello/address.c
Modified:
   gnunet/src/hello/Makefile.am
   gnunet/src/include/gnunet_hello_lib.h
Log:
adding address abstraction

Modified: gnunet/src/hello/Makefile.am
===================================================================
--- gnunet/src/hello/Makefile.am        2011-11-08 17:32:06 UTC (rev 18054)
+++ gnunet/src/hello/Makefile.am        2011-11-08 19:37:32 UTC (rev 18055)
@@ -12,7 +12,7 @@
 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 = \

Added: gnunet/src/hello/address.c
===================================================================
--- gnunet/src/hello/address.c                          (rev 0)
+++ gnunet/src/hello/address.c  2011-11-08 19:37:32 UTC (rev 18055)
@@ -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 */

Modified: gnunet/src/include/gnunet_hello_lib.h
===================================================================
--- gnunet/src/include/gnunet_hello_lib.h       2011-11-08 17:32:06 UTC (rev 
18054)
+++ gnunet/src/include/gnunet_hello_lib.h       2011-11-08 19:37:32 UTC (rev 
18055)
@@ -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,7 +38,65 @@
 #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
  * to start with a "GNUNET_MessageHeader", everything else




reply via email to

[Prev in Thread] Current Thread [Next in Thread]