aboutsummaryrefslogtreecommitdiff
path: root/src/hello
diff options
context:
space:
mode:
authorBertrand Marc <beberking@gmail.com>2012-06-06 20:47:48 +0200
committerBertrand Marc <beberking@gmail.com>2012-06-06 20:47:48 +0200
commit740b30688bd745a527f96f9116c19acb3480971a (patch)
tree2709a3f4dba11c174aa9e1ba3612e30c578e76a9 /src/hello
parent2b81464a43485fcc8ce079fafdee7b7a171835f4 (diff)
Imported Upstream version 0.9.3upstream/0.9.3
Diffstat (limited to 'src/hello')
-rw-r--r--src/hello/Makefile.am13
-rw-r--r--src/hello/Makefile.in65
-rw-r--r--src/hello/gnunet-hello.c204
-rw-r--r--src/hello/hello.c41
-rw-r--r--src/hello/test_hello.c2
5 files changed, 308 insertions, 17 deletions
diff --git a/src/hello/Makefile.am b/src/hello/Makefile.am
index 1788e8f..26aa6c7 100644
--- a/src/hello/Makefile.am
+++ b/src/hello/Makefile.am
@@ -19,6 +19,9 @@ libgnunethello_la_LDFLAGS = \
$(GN_LIB_LDFLAGS) \
-version-info 0:0:0
+noinst_PROGRAMS = \
+ gnunet-hello
+
check_PROGRAMS = \
test_hello
@@ -32,3 +35,13 @@ test_hello_LDADD = \
$(top_builddir)/src/hello/libgnunethello.la \
$(top_builddir)/src/util/libgnunetutil.la
+
+gnunet_hello_SOURCES = \
+ gnunet-hello.c
+gnunet_hello_LDADD = \
+ $(top_builddir)/src/hello/libgnunethello.la \
+ $(top_builddir)/src/util/libgnunetutil.la
+gnunet_hello_DEPENDENCIES = \
+ libgnunethello.la \
+ $(top_builddir)/src/util/libgnunetutil.la
+
diff --git a/src/hello/Makefile.in b/src/hello/Makefile.in
index 283d209..1887b27 100644
--- a/src/hello/Makefile.in
+++ b/src/hello/Makefile.in
@@ -15,6 +15,7 @@
@SET_MAKE@
+
VPATH = @srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
pkgincludedir = $(includedir)/@PACKAGE@
@@ -35,6 +36,7 @@ POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
target_triplet = @target@
+noinst_PROGRAMS = gnunet-hello$(EXEEXT)
check_PROGRAMS = test_hello$(EXEEXT)
subdir = src/hello
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
@@ -93,6 +95,9 @@ libgnunethello_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \
$(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \
$(AM_CFLAGS) $(CFLAGS) $(libgnunethello_la_LDFLAGS) $(LDFLAGS) \
-o $@
+PROGRAMS = $(noinst_PROGRAMS)
+am_gnunet_hello_OBJECTS = gnunet-hello.$(OBJEXT)
+gnunet_hello_OBJECTS = $(am_gnunet_hello_OBJECTS)
am_test_hello_OBJECTS = test_hello.$(OBJEXT)
test_hello_OBJECTS = $(am_test_hello_OBJECTS)
test_hello_DEPENDENCIES = $(top_builddir)/src/hello/libgnunethello.la \
@@ -123,8 +128,10 @@ am__v_CCLD_0 = @echo " CCLD " $@;
AM_V_GEN = $(am__v_GEN_$(V))
am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY))
am__v_GEN_0 = @echo " GEN " $@;
-SOURCES = $(libgnunethello_la_SOURCES) $(test_hello_SOURCES)
-DIST_SOURCES = $(libgnunethello_la_SOURCES) $(test_hello_SOURCES)
+SOURCES = $(libgnunethello_la_SOURCES) $(gnunet_hello_SOURCES) \
+ $(test_hello_SOURCES)
+DIST_SOURCES = $(libgnunethello_la_SOURCES) $(gnunet_hello_SOURCES) \
+ $(test_hello_SOURCES)
ETAGS = etags
CTAGS = ctags
am__tty_colors = \
@@ -185,6 +192,7 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
INTLLIBS = @INTLLIBS@
INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@
+JAVAPORT = @JAVAPORT@
LD = @LD@
LDFLAGS = @LDFLAGS@
LIBADD_DL = @LIBADD_DL@
@@ -218,6 +226,7 @@ LT_DLLOADERS = @LT_DLLOADERS@
LT_DLPREOPEN = @LT_DLPREOPEN@
MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
+MONKEYPREFIX = @MONKEYPREFIX@
MSGFMT = @MSGFMT@
MSGFMT_015 = @MSGFMT_015@
MSGMERGE = @MSGMERGE@
@@ -357,6 +366,17 @@ test_hello_LDADD = \
$(top_builddir)/src/hello/libgnunethello.la \
$(top_builddir)/src/util/libgnunetutil.la
+gnunet_hello_SOURCES = \
+ gnunet-hello.c
+
+gnunet_hello_LDADD = \
+ $(top_builddir)/src/hello/libgnunethello.la \
+ $(top_builddir)/src/util/libgnunetutil.la
+
+gnunet_hello_DEPENDENCIES = \
+ libgnunethello.la \
+ $(top_builddir)/src/util/libgnunetutil.la
+
all: all-am
.SUFFIXES:
@@ -433,6 +453,18 @@ clean-checkPROGRAMS:
list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
echo " rm -f" $$list; \
rm -f $$list
+
+clean-noinstPROGRAMS:
+ @list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \
+ echo " rm -f" $$list; \
+ rm -f $$list || exit $$?; \
+ test -n "$(EXEEXT)" || exit 0; \
+ list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+ echo " rm -f" $$list; \
+ rm -f $$list
+gnunet-hello$(EXEEXT): $(gnunet_hello_OBJECTS) $(gnunet_hello_DEPENDENCIES)
+ @rm -f gnunet-hello$(EXEEXT)
+ $(AM_V_CCLD)$(LINK) $(gnunet_hello_OBJECTS) $(gnunet_hello_LDADD) $(LIBS)
test_hello$(EXEEXT): $(test_hello_OBJECTS) $(test_hello_DEPENDENCIES)
@rm -f test_hello$(EXEEXT)
$(AM_V_CCLD)$(LINK) $(test_hello_OBJECTS) $(test_hello_LDADD) $(LIBS)
@@ -444,6 +476,7 @@ distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/address.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gnunet-hello.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hello.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_hello.Po@am__quote@
@@ -655,7 +688,7 @@ check-am: all-am
$(MAKE) $(AM_MAKEFLAGS) $(check_PROGRAMS)
$(MAKE) $(AM_MAKEFLAGS) check-TESTS
check: check-am
-all-am: Makefile $(LTLIBRARIES)
+all-am: Makefile $(LTLIBRARIES) $(PROGRAMS)
installdirs:
for dir in "$(DESTDIR)$(libdir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
@@ -688,7 +721,7 @@ maintainer-clean-generic:
clean: clean-am
clean-am: clean-checkPROGRAMS clean-generic clean-libLTLIBRARIES \
- clean-libtool mostlyclean-am
+ clean-libtool clean-noinstPROGRAMS mostlyclean-am
distclean: distclean-am
-rm -rf ./$(DEPDIR)
@@ -760,18 +793,18 @@ uninstall-am: uninstall-libLTLIBRARIES
.PHONY: CTAGS GTAGS all all-am check check-TESTS check-am clean \
clean-checkPROGRAMS clean-generic clean-libLTLIBRARIES \
- clean-libtool ctags distclean distclean-compile \
- distclean-generic distclean-libtool distclean-tags distdir dvi \
- dvi-am html html-am info info-am install install-am \
- install-data install-data-am install-dvi install-dvi-am \
- install-exec install-exec-am install-html install-html-am \
- install-info install-info-am install-libLTLIBRARIES \
- install-man install-pdf install-pdf-am install-ps \
- install-ps-am install-strip installcheck installcheck-am \
- installdirs maintainer-clean maintainer-clean-generic \
- mostlyclean mostlyclean-compile mostlyclean-generic \
- mostlyclean-libtool pdf pdf-am ps ps-am tags uninstall \
- uninstall-am uninstall-libLTLIBRARIES
+ clean-libtool clean-noinstPROGRAMS ctags distclean \
+ distclean-compile distclean-generic distclean-libtool \
+ distclean-tags distdir dvi dvi-am html html-am info info-am \
+ install install-am install-data install-data-am install-dvi \
+ install-dvi-am install-exec install-exec-am install-html \
+ install-html-am install-info install-info-am \
+ install-libLTLIBRARIES install-man install-pdf install-pdf-am \
+ install-ps install-ps-am install-strip installcheck \
+ installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags uninstall uninstall-am uninstall-libLTLIBRARIES
# Tell versions [3.59,3.63) of GNU make to not export all variables.
diff --git a/src/hello/gnunet-hello.c b/src/hello/gnunet-hello.c
new file mode 100644
index 0000000..bc35cdd
--- /dev/null
+++ b/src/hello/gnunet-hello.c
@@ -0,0 +1,204 @@
+/*
+ This file is part of GNUnet
+ (C) 2012 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/gnunet-hello.c
+ * @brief change HELLO files to never expire
+ * @author Christian Grothoff
+ */
+#include "platform.h"
+#include "gnunet_hello_lib.h"
+
+#define DEBUG GNUNET_EXTRA_LOGGING
+
+#define VERBOSE GNUNET_NO
+
+/**
+ * Closure for 'add_to_buf'.
+ */
+struct AddContext
+{
+ /**
+ * Where to add.
+ */
+ char *buf;
+
+ /**
+ * Maximum number of bytes left
+ */
+ size_t max;
+
+ /**
+ * Number of bytes added so far.
+ */
+ size_t ret;
+};
+
+
+/**
+ * Add the given address with infinit expiration to the buffer.
+ *
+ * @param cls closure
+ * @param address address to add
+ * @param expiration old expiration
+ * @return GNUNET_OK keep iterating
+ */
+static int
+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,
+ GNUNET_TIME_UNIT_FOREVER_ABS,
+ ac->buf,
+ ac->max);
+ ac->buf += ret;
+ ac->max -= ret;
+ ac->ret += ret;
+ return GNUNET_OK;
+}
+
+
+/**
+ * Add addresses from the address list to the HELLO.
+ *
+ * @param cls the HELLO with the addresses to add
+ * @param max maximum space available
+ * @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)
+{
+ struct GNUNET_HELLO_Message **orig = cls;
+ struct AddContext ac;
+
+ if (NULL == *orig)
+ return 0; /* already done */
+ ac.buf = buf;
+ ac.max = max;
+ ac.ret = 0;
+ GNUNET_assert (NULL ==
+ GNUNET_HELLO_iterate_addresses (*orig,
+ GNUNET_NO, &add_to_buf,
+ &ac));
+ *orig = NULL;
+ return ac.ret;
+}
+
+
+int
+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;
+ uint64_t fsize;
+
+ GNUNET_log_setup ("gnunet-hello", "INFO", NULL);
+ if (argc != 2)
+ {
+ FPRINTF (stderr,
+ "%s",
+ _("Call with name of HELLO file to modify.\n"));
+ return 1;
+ }
+ if (GNUNET_OK != GNUNET_DISK_file_size (argv[1], &fsize, GNUNET_YES, GNUNET_YES))
+ {
+ FPRINTF (stderr,
+ _("Error accessing file `%s': %s\n"),
+ argv[1],
+ STRERROR (errno));
+ return 1;
+ }
+ if (fsize > 65536)
+ {
+ FPRINTF (stderr,
+ _("File `%s' is too big to be a HELLO\n"),
+ argv[1]);
+ return 1;
+ }
+ if (fsize < sizeof (struct GNUNET_MessageHeader))
+ {
+ FPRINTF (stderr,
+ _("File `%s' is too small to be a HELLO\n"),
+ argv[1]);
+ return 1;
+ }
+ fh = GNUNET_DISK_file_open (argv[1],
+ GNUNET_DISK_OPEN_READ,
+ GNUNET_DISK_PERM_USER_READ);
+ if (NULL == fh)
+ {
+ FPRINTF (stderr,
+ _("Error opening file `%s': %s\n"),
+ argv[1],
+ STRERROR (errno));
+ return 1;
+ }
+ {
+ 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)) )
+ {
+ 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);
+ GNUNET_assert (NULL != result);
+ fh = GNUNET_DISK_file_open (argv[1],
+ GNUNET_DISK_OPEN_WRITE,
+ GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
+ if (NULL == fh)
+ {
+ FPRINTF (stderr,
+ _("Error opening file `%s': %s\n"),
+ argv[1],
+ STRERROR (errno));
+ GNUNET_free (result);
+ return 1;
+ }
+ fsize = GNUNET_HELLO_size (result);
+ if (fsize != GNUNET_DISK_file_write (fh,
+ result,
+ fsize))
+ {
+ FPRINTF (stderr,
+ _("Error writing HELLO to file `%s': %s\n"),
+ argv[1],
+ STRERROR (errno));
+ (void) GNUNET_DISK_file_close (fh);
+ return 1;
+ }
+ GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
+ }
+ return 0;
+}
+
+/* end of gnunet-hello.c */
diff --git a/src/hello/hello.c b/src/hello/hello.c
index 7aa9740..6529c93 100644
--- a/src/hello/hello.c
+++ b/src/hello/hello.c
@@ -641,5 +641,46 @@ GNUNET_HELLO_get_last_expiration (const struct GNUNET_HELLO_Message *msg)
return ret;
}
+/**
+ * GNUnet URIs are of the general form "gnunet://MODULE/IDENTIFIER".
+ * The specific structure of "IDENTIFIER" depends on the module and
+ * maybe differenciated into additional subcategories if applicable.
+ * This module only deals with hello identifiers (MODULE = "hello").
+ * <p>
+ *
+ * The concrete URI format is:
+ *
+ * "gnunet://hello/PEER[!YYYYMMDDHHNNSS!<TYPE>!<ADDRESS>]...".
+ * These URIs can be used to add a peer record to peerinfo service.
+ * PEER is the string representation of peer's public key.
+ * YYYYMMDDHHNNSS is the expiration date.
+ * TYPE is a transport type.
+ * ADDRESS is the address, its format depends upon the transport type.
+ * The concrete transport types and corresponding address formats are:
+ *
+ * <ul><li>
+ *
+ * <TCP|UDP>!IPADDRESS
+ * IPVDDRESS is either IPV4 .-delimited address in form of XXX.XXX.XXX.XXX:PPPPP
+ * or IPV6 :-delimited address, but with '(' and ')' instead of '[' and ']' (RFC2396 advises against using square brackets in URIs):
+ * (XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX:XXXX):PPPPP
+ * PPPPP is the port number. May be 0.
+ *
+ * </li><li>
+ *
+ * [add SMTP, HTTP and other addresses here]
+ *
+ * </li></ul>
+ *
+ * The encoding for hexadecimal values is defined in the crypto_hash.c
+ * module in the gnunetutil library and discussed there.
+ *
+ * Examples:
+ *
+ * gnunet://hello/0430205UC7D56PTQK8NV05776671CNN44FK4TL6D0GQ35OMF8MEN4RNMKA5UF6AL3DQO8B1SC5AQF50SQ2MABIRU4HC8H2HAJKJ59JL1JVRJAK308F9GASRFLMGUBB5TQ5AKR94AS5T3MDG8B9O1EMPRKB0HVCG7T6QPP4CDJ913LAEHVJ2DI1TOBB15Q1JIT5ARBOD12U4SIGRFDV3Q7T66G4TBVSJJ90UQF1BG29TGJJKLGEIMSPHHKO544D6EALQ4F2K0416311JC22GVAD48R616I7VK03K7MP7N0RS2MBV1TE9JV8CK1LSQMR7KCDRTLDA6917UGA67DHTGHERIACCGQ54TGSR48RMSGS9BA5HLMOKASFC1I6V4TT09TUGCU8GNDHQF0JF3H7LPV59UL5I38QID040G000!20120302010059!TCP!192.168.0.1:2086!TCP!64.23.8.174:0
+ * gnunet://hello/0430205UC7D56PTQK8NV05776671CNN44FK4TL6D0GQ35OMF8MEN4RNMKA5UF6AL3DQO8B1SC5AQF50SQ2MABIRU4HC8H2HAJKJ59JL1JVRJAK308F9GASRFLMGUBB5TQ5AKR94AS5T3MDG8B9O1EMPRKB0HVCG7T6QPP4CDJ913LAEHVJ2DI1TOBB15Q1JIT5ARBOD12U4SIGRFDV3Q7T66G4TBVSJJ90UQF1BG29TGJJKLGEIMSPHHKO544D6EALQ4F2K0416311JC22GVAD48R616I7VK03K7MP7N0RS2MBV1TE9JV8CK1LSQMR7KCDRTLDA6917UGA67DHTGHERIACCGQ54TGSR48RMSGS9BA5HLMOKASFC1I6V4TT09TUGCU8GNDHQF0JF3H7LPV59UL5I38QID040G000!20120302010059!TCP!(2001:db8:85a3:8d3:1319:8a2e:370:7348):2086
+ *
+ * <p>
+ */
/* end of hello.c */
diff --git a/src/hello/test_hello.c b/src/hello/test_hello.c
index 0efbdee..bdabc72 100644
--- a/src/hello/test_hello.c
+++ b/src/hello/test_hello.c
@@ -25,7 +25,7 @@
#include "platform.h"
#include "gnunet_hello_lib.h"
-#define DEBUG GNUNET_EXTRA_LOGGING
+#define DEBUG GNUNET_NO
#define VERBOSE GNUNET_NO