aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-03-28 15:14:38 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-03-28 15:14:38 +0000
commitb3883971cd31d198dbd768fffb15960dff0352a6 (patch)
tree1803032b911774f57158013eedfc26a3c0fb5462
parent1fe395444d868f4fd66d44da83cb61a69acc6b66 (diff)
downloadgnunet-b3883971cd31d198dbd768fffb15960dff0352a6.tar.gz
gnunet-b3883971cd31d198dbd768fffb15960dff0352a6.zip
new friend only HELLO type GNUNET_MESSAGE_TYPE_FRIEND_HELLO
-rw-r--r--src/hello/Makefile.am8
-rw-r--r--src/hello/gnunet-hello.c9
-rw-r--r--src/hello/hello.c81
-rw-r--r--src/hello/test_friend_hello.c186
-rw-r--r--src/hello/test_hello.c6
-rw-r--r--src/include/gnunet_hello_lib.h19
-rw-r--r--src/include/gnunet_protocols.h6
-rwxr-xr-xsrc/peerinfo/perf_peerinfo_api.c2
-rw-r--r--src/peerinfo/test_peerinfo_api.c2
-rw-r--r--src/transport/gnunet-service-transport_hello.c4
-rw-r--r--src/transport/gnunet-service-transport_validation.c4
-rw-r--r--src/transport/test_plugin_transport.c2
12 files changed, 304 insertions, 25 deletions
diff --git a/src/hello/Makefile.am b/src/hello/Makefile.am
index fd5a41bea..ef23e8a6e 100644
--- a/src/hello/Makefile.am
+++ b/src/hello/Makefile.am
@@ -24,7 +24,8 @@ noinst_PROGRAMS = \
24 gnunet-hello 24 gnunet-hello
25 25
26check_PROGRAMS = \ 26check_PROGRAMS = \
27 test_hello 27 test_hello \
28 test_friend_hello
28 29
29if ENABLE_TEST_RUN 30if ENABLE_TEST_RUN
30TESTS = $(check_PROGRAMS) 31TESTS = $(check_PROGRAMS)
@@ -36,6 +37,11 @@ test_hello_LDADD = \
36 $(top_builddir)/src/hello/libgnunethello.la \ 37 $(top_builddir)/src/hello/libgnunethello.la \
37 $(top_builddir)/src/util/libgnunetutil.la 38 $(top_builddir)/src/util/libgnunetutil.la
38 39
40test_friend_hello_SOURCES = \
41 test_friend_hello.c
42test_friend_hello_LDADD = \
43 $(top_builddir)/src/hello/libgnunethello.la \
44 $(top_builddir)/src/util/libgnunetutil.la
39 45
40gnunet_hello_SOURCES = \ 46gnunet_hello_SOURCES = \
41 gnunet-hello.c 47 gnunet-hello.c
diff --git a/src/hello/gnunet-hello.c b/src/hello/gnunet-hello.c
index fa250d7a1..7df8b7b83 100644
--- a/src/hello/gnunet-hello.c
+++ b/src/hello/gnunet-hello.c
@@ -23,6 +23,7 @@
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 */ 24 */
25#include "platform.h" 25#include "platform.h"
26#include "gnunet_protocols.h"
26#include "gnunet_hello_lib.h" 27#include "gnunet_hello_lib.h"
27 28
28/** 29/**
@@ -109,6 +110,7 @@ main (int argc, char *argv[])
109 struct GNUNET_HELLO_Message *result; 110 struct GNUNET_HELLO_Message *result;
110 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pk; 111 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pk;
111 uint64_t fsize; 112 uint64_t fsize;
113 int friend_only;
112 114
113 GNUNET_log_setup ("gnunet-hello", "INFO", NULL); 115 GNUNET_log_setup ("gnunet-hello", "INFO", NULL);
114 if (argc != 2) 116 if (argc != 2)
@@ -166,7 +168,12 @@ main (int argc, char *argv[])
166 argv[1]); 168 argv[1]);
167 return 1; 169 return 1;
168 } 170 }
169 result = GNUNET_HELLO_create (&pk, &add_from_hello, &orig); 171 friend_only = GNUNET_NO;
172 if (GNUNET_MESSAGE_TYPE_HELLO == GNUNET_HELLO_get_type ((struct GNUNET_MessageHeader *) orig))
173 friend_only = GNUNET_NO;
174 if (GNUNET_MESSAGE_TYPE_FRIEND_HELLO == GNUNET_HELLO_get_type ((struct GNUNET_MessageHeader *) orig))
175 friend_only = GNUNET_YES;
176 result = GNUNET_HELLO_create (&pk, &add_from_hello, &orig, friend_only);
170 GNUNET_assert (NULL != result); 177 GNUNET_assert (NULL != result);
171 fh = GNUNET_DISK_file_open (argv[1], 178 fh = GNUNET_DISK_file_open (argv[1],
172 GNUNET_DISK_OPEN_WRITE, 179 GNUNET_DISK_OPEN_WRITE,
diff --git a/src/hello/hello.c b/src/hello/hello.c
index a20e8992c..066c03d87 100644
--- a/src/hello/hello.c
+++ b/src/hello/hello.c
@@ -103,6 +103,23 @@ struct GNUNET_HELLO_ParseUriContext
103 GNUNET_HELLO_TransportPluginsFind plugins_find; 103 GNUNET_HELLO_TransportPluginsFind plugins_find;
104}; 104};
105 105
106/**
107 * Return HELLO type
108 *
109 * @param h HELLO Message to test
110 * @param GNUNET_MESSAGE_TYPE_HELLO or GNUNET_MESSAGE_TYPE_FRIEND_HELLO or 0 on error
111 */
112
113uint16_t
114GNUNET_HELLO_get_type (const struct GNUNET_MessageHeader *h)
115{
116 if (GNUNET_MESSAGE_TYPE_HELLO == ntohs(h->type))
117 return GNUNET_MESSAGE_TYPE_HELLO;
118 if (GNUNET_MESSAGE_TYPE_FRIEND_HELLO == ntohs(h->type))
119 return GNUNET_MESSAGE_TYPE_FRIEND_HELLO;
120 return 0;
121}
122
106 123
107/** 124/**
108 * Copy the given address information into 125 * Copy the given address information into
@@ -204,7 +221,8 @@ struct GNUNET_HELLO_Message *
204GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded 221GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded
205 *publicKey, 222 *publicKey,
206 GNUNET_HELLO_GenerateAddressListCallback addrgen, 223 GNUNET_HELLO_GenerateAddressListCallback addrgen,
207 void *addrgen_cls) 224 void *addrgen_cls,
225 int friend_only)
208{ 226{
209 char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - 256 - 227 char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - 256 -
210 sizeof (struct GNUNET_HELLO_Message)]; 228 sizeof (struct GNUNET_HELLO_Message)];
@@ -224,7 +242,10 @@ GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded
224 } 242 }
225 } 243 }
226 hello = GNUNET_malloc (sizeof (struct GNUNET_HELLO_Message) + used); 244 hello = GNUNET_malloc (sizeof (struct GNUNET_HELLO_Message) + used);
227 hello->header.type = htons (GNUNET_MESSAGE_TYPE_HELLO); 245 if (GNUNET_NO == friend_only)
246 hello->header.type = htons (GNUNET_MESSAGE_TYPE_HELLO);
247 else
248 hello->header.type = htons (GNUNET_MESSAGE_TYPE_FRIEND_HELLO);
228 hello->header.size = htons (sizeof (struct GNUNET_HELLO_Message) + used); 249 hello->header.size = htons (sizeof (struct GNUNET_HELLO_Message) + used);
229 memcpy (&hello->publicKey, publicKey, 250 memcpy (&hello->publicKey, publicKey,
230 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)); 251 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded));
@@ -261,7 +282,8 @@ GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg,
261 282
262 msize = GNUNET_HELLO_size (msg); 283 msize = GNUNET_HELLO_size (msg);
263 if ((msize < sizeof (struct GNUNET_HELLO_Message)) || 284 if ((msize < sizeof (struct GNUNET_HELLO_Message)) ||
264 (ntohs (msg->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) 285 ((ntohs (msg->header.type) != GNUNET_MESSAGE_TYPE_HELLO) &&
286 (ntohs (msg->header.type) != GNUNET_MESSAGE_TYPE_FRIEND_HELLO)))
265 return NULL; 287 return NULL;
266 ret = NULL; 288 ret = NULL;
267 if (return_modified) 289 if (return_modified)
@@ -408,8 +430,24 @@ GNUNET_HELLO_merge (const struct GNUNET_HELLO_Message *h1,
408 const struct GNUNET_HELLO_Message *h2) 430 const struct GNUNET_HELLO_Message *h2)
409{ 431{
410 struct MergeContext mc = { h1, h2, NULL, NULL, 0, 0, 0 }; 432 struct MergeContext mc = { h1, h2, NULL, NULL, 0, 0, 0 };
433 int friend_only;
434 if (h1->header.type != h2->header.type)
435 {
436 /* Trying to merge different HELLO types */
437 GNUNET_break (0);
438 return NULL;
439 }
440 if (GNUNET_MESSAGE_TYPE_HELLO == (ntohs(h1->header.type)))
441 friend_only = GNUNET_NO;
442 else if (GNUNET_MESSAGE_TYPE_FRIEND_HELLO == (ntohs(h1->header.type)))
443 friend_only = GNUNET_YES;
444 else
445 {
446 GNUNET_break (0);
447 return NULL;
448 }
411 449
412 return GNUNET_HELLO_create (&h1->publicKey, &merge_addr, &mc); 450 return GNUNET_HELLO_create (&h1->publicKey, &merge_addr, &mc, friend_only);
413} 451}
414 452
415 453
@@ -488,7 +526,8 @@ GNUNET_HELLO_size (const struct GNUNET_HELLO_Message *hello)
488 uint16_t ret = ntohs (hello->header.size); 526 uint16_t ret = ntohs (hello->header.size);
489 527
490 if ((ret < sizeof (struct GNUNET_HELLO_Message)) || 528 if ((ret < sizeof (struct GNUNET_HELLO_Message)) ||
491 (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) 529 ((ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO) &&
530 (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_FRIEND_HELLO)))
492 return 0; 531 return 0;
493 return ret; 532 return ret;
494} 533}
@@ -508,7 +547,8 @@ GNUNET_HELLO_get_key (const struct GNUNET_HELLO_Message *hello,
508 uint16_t ret = ntohs (hello->header.size); 547 uint16_t ret = ntohs (hello->header.size);
509 548
510 if ((ret < sizeof (struct GNUNET_HELLO_Message)) || 549 if ((ret < sizeof (struct GNUNET_HELLO_Message)) ||
511 (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) 550 ((ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO) &&
551 (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_FRIEND_HELLO)))
512 return GNUNET_SYSERR; 552 return GNUNET_SYSERR;
513 *publicKey = hello->publicKey; 553 *publicKey = hello->publicKey;
514 return GNUNET_OK; 554 return GNUNET_OK;
@@ -529,7 +569,8 @@ GNUNET_HELLO_get_id (const struct GNUNET_HELLO_Message *hello,
529 uint16_t ret = ntohs (hello->header.size); 569 uint16_t ret = ntohs (hello->header.size);
530 570
531 if ((ret < sizeof (struct GNUNET_HELLO_Message)) || 571 if ((ret < sizeof (struct GNUNET_HELLO_Message)) ||
532 (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) 572 ((ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO) &&
573 (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_FRIEND_HELLO)))
533 return GNUNET_SYSERR; 574 return GNUNET_SYSERR;
534 GNUNET_CRYPTO_hash (&hello->publicKey, 575 GNUNET_CRYPTO_hash (&hello->publicKey,
535 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), 576 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
@@ -552,7 +593,8 @@ GNUNET_HELLO_get_header (struct GNUNET_HELLO_Message *hello)
552 uint16_t ret = ntohs (hello->header.size); 593 uint16_t ret = ntohs (hello->header.size);
553 594
554 if ((ret < sizeof (struct GNUNET_HELLO_Message)) || 595 if ((ret < sizeof (struct GNUNET_HELLO_Message)) ||
555 (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) 596 ((ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO) &&
597 (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_FRIEND_HELLO)))
556 return NULL; 598 return NULL;
557 599
558 return &hello->header; 600 return &hello->header;
@@ -639,6 +681,9 @@ GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1,
639{ 681{
640 struct EqualsContext ec; 682 struct EqualsContext ec;
641 683
684 if (h1->header.type != h2->header.type)
685 return GNUNET_TIME_UNIT_ZERO_ABS;
686
642 if (0 != 687 if (0 !=
643 memcmp (&h1->publicKey, &h2->publicKey, 688 memcmp (&h1->publicKey, &h2->publicKey,
644 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded))) 689 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)))
@@ -1011,13 +1056,25 @@ GNUNET_HELLO_parse_uri (const char *uri,
1011{ 1056{
1012 const char *pks; 1057 const char *pks;
1013 const char *exc; 1058 const char *exc;
1059 int friend_only;
1014 struct GNUNET_HELLO_ParseUriContext ctx; 1060 struct GNUNET_HELLO_ParseUriContext ctx;
1015 1061
1016 if (0 != strncmp (uri, 1062 if (0 == strncmp (uri,
1017 GNUNET_HELLO_URI_PREFIX, 1063 GNUNET_HELLO_URI_PREFIX,
1018 strlen (GNUNET_HELLO_URI_PREFIX))) 1064 strlen (GNUNET_HELLO_URI_PREFIX)))
1019 return GNUNET_SYSERR; 1065 {
1020 pks = &uri[strlen (GNUNET_HELLO_URI_PREFIX)]; 1066 pks = &uri[strlen (GNUNET_HELLO_URI_PREFIX)];
1067 friend_only = GNUNET_NO;
1068 }
1069 else if (0 == strncmp (uri,
1070 GNUNET_FRIEND_HELLO_URI_PREFIX,
1071 strlen (GNUNET_FRIEND_HELLO_URI_PREFIX)))
1072 {
1073 pks = &uri[strlen (GNUNET_FRIEND_HELLO_URI_PREFIX)];
1074 friend_only = GNUNET_YES;
1075 }
1076 else
1077 return GNUNET_SYSERR;
1021 exc = strstr (pks, "!"); 1078 exc = strstr (pks, "!");
1022 1079
1023 if (GNUNET_OK != 1080 if (GNUNET_OK !=
@@ -1030,7 +1087,7 @@ GNUNET_HELLO_parse_uri (const char *uri,
1030 ctx.pos = exc; 1087 ctx.pos = exc;
1031 ctx.ret = GNUNET_OK; 1088 ctx.ret = GNUNET_OK;
1032 ctx.plugins_find = plugins_find; 1089 ctx.plugins_find = plugins_find;
1033 *hello = GNUNET_HELLO_create (pubkey, &add_address_to_hello, &ctx); 1090 *hello = GNUNET_HELLO_create (pubkey, &add_address_to_hello, &ctx, friend_only);
1034 1091
1035 return ctx.ret; 1092 return ctx.ret;
1036} 1093}
diff --git a/src/hello/test_friend_hello.c b/src/hello/test_friend_hello.c
new file mode 100644
index 000000000..fb14817c7
--- /dev/null
+++ b/src/hello/test_friend_hello.c
@@ -0,0 +1,186 @@
1/*
2 This file is part of GNUnet
3 (C) 2009 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19*/
20/**
21 * @file hello/test_hello.c
22 * @brief test for hello.c
23 * @author Christian Grothoff
24 */
25#include "platform.h"
26#include "gnunet_hello_lib.h"
27
28static size_t
29my_addr_gen (void *cls, size_t max, void *buf)
30{
31 unsigned int *i = cls;
32 size_t ret;
33 struct GNUNET_HELLO_Address address;
34
35 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
36 "DEBUG: my_addr_gen called with i = %d\n", *i);
37 if (0 == *i)
38 return 0;
39 memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity));
40 address.address = "address_information";
41 address.transport_name = "test";
42 address.address_length = *i;
43 ret =
44 GNUNET_HELLO_add_address (&address, GNUNET_TIME_absolute_get (), buf,
45 max);
46 (*i)--;
47 return ret;
48}
49
50
51static int
52check_addr (void *cls, const struct GNUNET_HELLO_Address *address,
53 struct GNUNET_TIME_Absolute expiration)
54{
55 unsigned int *i = cls;
56
57 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
58 "DEBUG: check_addr called with i = %d and addrlen = %u\n",
59 *i, (unsigned int) address->address_length);
60 GNUNET_assert (address->address_length > 0);
61 GNUNET_assert (*i & (1 << (address->address_length - 1)));
62 *i -= (1 << (address->address_length - 1));
63 GNUNET_assert (0 ==
64 strncmp ("address_information", address->address,
65 address->address_length));
66 GNUNET_assert (0 == strcmp ("test", address->transport_name));
67 return GNUNET_OK;
68}
69
70
71static int
72remove_some (void *cls, const struct GNUNET_HELLO_Address *address,
73 struct GNUNET_TIME_Absolute expiration)
74{
75 unsigned int *i = cls;
76
77 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
78 "DEBUG: remove_some called with i = %d and addrlen = %u\n",
79 *i, (unsigned int) address->address_length);
80 GNUNET_assert (address->address_length > 0);
81 if (*i & (1 << (address->address_length - 1)))
82 {
83 *i -= (1 << (address->address_length - 1));
84 return GNUNET_NO;
85 }
86 return GNUNET_OK;
87}
88
89
90int
91main (int argc, char *argv[])
92{
93 struct GNUNET_HELLO_Message *msg1;
94 struct GNUNET_HELLO_Message *msg2;
95 struct GNUNET_HELLO_Message *msg3;
96 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded publicKey;
97 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pk;
98 struct GNUNET_TIME_Absolute startup_time;
99 unsigned int i;
100
101 GNUNET_log_setup ("test-hello", "DEBUG", NULL);
102 startup_time = GNUNET_TIME_absolute_get ();
103 memset (&publicKey, 42, sizeof (publicKey));
104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
105 "Testing HELLO creation (without addresses)...\n");
106 i = 0;
107 msg1 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i, GNUNET_YES);
108 GNUNET_assert (msg1 != NULL);
109 GNUNET_assert (0 < GNUNET_HELLO_size (msg1));
110
111 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
112 "Testing address iteration (empty set)...\n");
113 GNUNET_assert (NULL ==
114 GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr,
115 &i));
116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
117 "Testing HELLO creation (with one address)...\n");
118 i = 1;
119 msg2 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i, GNUNET_YES);
120 GNUNET_assert (msg2 != NULL);
121 GNUNET_assert (GNUNET_HELLO_size (msg1) < GNUNET_HELLO_size (msg2));
122
123 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
124 "Testing address iteration (one address)...\n");
125 i = 1;
126 GNUNET_assert (NULL ==
127 GNUNET_HELLO_iterate_addresses (msg2, GNUNET_NO, &check_addr,
128 &i));
129 GNUNET_assert (i == 0);
130
131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
132 "Testing get_key from HELLO...\n");
133 GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_key (msg2, &pk));
134 GNUNET_assert (0 == memcmp (&publicKey, &pk, sizeof (pk)));
135 GNUNET_free (msg1);
136
137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
138 "Testing HELLO creation (with two addresses)...\n");
139 i = 2;
140 msg3 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i, GNUNET_YES);
141 GNUNET_assert (msg3 != NULL);
142 GNUNET_assert (GNUNET_HELLO_size (msg2) < GNUNET_HELLO_size (msg3));
143
144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
145 "Testing address iteration (two addresses)...\n");
146 i = 3;
147 GNUNET_assert (NULL ==
148 GNUNET_HELLO_iterate_addresses (msg3, GNUNET_NO, &check_addr,
149 &i));
150 GNUNET_assert (i == 0);
151
152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
153 "Testing HELLO merge...\n");
154 msg1 = GNUNET_HELLO_merge (msg2, msg3);
155 GNUNET_assert (GNUNET_HELLO_size (msg1) == GNUNET_HELLO_size (msg3));
156
157 i = 3;
158 GNUNET_assert (NULL ==
159 GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr,
160 &i));
161 GNUNET_assert (i == 0);
162 GNUNET_free (msg1);
163
164 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
165 "Testing address iteration to copy HELLO...\n");
166 i = 2;
167 msg1 = GNUNET_HELLO_iterate_addresses (msg3, GNUNET_YES, &remove_some, &i);
168 GNUNET_assert (msg1 != NULL);
169 GNUNET_assert (i == 0);
170 i = 1;
171 GNUNET_assert (NULL ==
172 GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr,
173 &i));
174 GNUNET_assert (i == 0);
175 GNUNET_free (msg1);
176
177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
178 "Testing delta address iteration...\n");
179 i = 2;
180 GNUNET_HELLO_iterate_new_addresses (msg3, msg2, startup_time, &check_addr,
181 &i);
182 GNUNET_assert (i == 0);
183 GNUNET_free (msg2);
184 GNUNET_free (msg3);
185 return 0; /* testcase passed */
186}
diff --git a/src/hello/test_hello.c b/src/hello/test_hello.c
index 67335ab95..64abec5e4 100644
--- a/src/hello/test_hello.c
+++ b/src/hello/test_hello.c
@@ -104,7 +104,7 @@ main (int argc, char *argv[])
104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
105 "Testing HELLO creation (without addresses)...\n"); 105 "Testing HELLO creation (without addresses)...\n");
106 i = 0; 106 i = 0;
107 msg1 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i); 107 msg1 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i, GNUNET_NO);
108 GNUNET_assert (msg1 != NULL); 108 GNUNET_assert (msg1 != NULL);
109 GNUNET_assert (0 < GNUNET_HELLO_size (msg1)); 109 GNUNET_assert (0 < GNUNET_HELLO_size (msg1));
110 110
@@ -116,7 +116,7 @@ main (int argc, char *argv[])
116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
117 "Testing HELLO creation (with one address)...\n"); 117 "Testing HELLO creation (with one address)...\n");
118 i = 1; 118 i = 1;
119 msg2 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i); 119 msg2 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i, GNUNET_NO);
120 GNUNET_assert (msg2 != NULL); 120 GNUNET_assert (msg2 != NULL);
121 GNUNET_assert (GNUNET_HELLO_size (msg1) < GNUNET_HELLO_size (msg2)); 121 GNUNET_assert (GNUNET_HELLO_size (msg1) < GNUNET_HELLO_size (msg2));
122 122
@@ -137,7 +137,7 @@ main (int argc, char *argv[])
137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
138 "Testing HELLO creation (with two addresses)...\n"); 138 "Testing HELLO creation (with two addresses)...\n");
139 i = 2; 139 i = 2;
140 msg3 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i); 140 msg3 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i, GNUNET_NO);
141 GNUNET_assert (msg3 != NULL); 141 GNUNET_assert (msg3 != NULL);
142 GNUNET_assert (GNUNET_HELLO_size (msg2) < GNUNET_HELLO_size (msg3)); 142 GNUNET_assert (GNUNET_HELLO_size (msg2) < GNUNET_HELLO_size (msg3));
143 143
diff --git a/src/include/gnunet_hello_lib.h b/src/include/gnunet_hello_lib.h
index 867ff686d..897b84274 100644
--- a/src/include/gnunet_hello_lib.h
+++ b/src/include/gnunet_hello_lib.h
@@ -44,6 +44,10 @@ extern "C"
44 */ 44 */
45#define GNUNET_HELLO_URI_PREFIX "gnunet://hello/" 45#define GNUNET_HELLO_URI_PREFIX "gnunet://hello/"
46 46
47/**
48 * Prefix that every FRIEND HELLO URI must start with.
49 */
50#define GNUNET_FRIEND_HELLO_URI_PREFIX "gnunet://friend-hello/"
47 51
48/** 52/**
49 * An address for communicating with a peer. We frequently 53 * An address for communicating with a peer. We frequently
@@ -79,6 +83,15 @@ struct GNUNET_HELLO_Address
79 83
80 84
81/** 85/**
86 * Return HELLO type
87 *
88 * @param h HELLO Message to test
89 * @param GNUNET_MESSAGE_TYPE_HELLO or GNUNET_MESSAGE_TYPE_FRIEND_HELLO or 0 on error
90 */
91uint16_t
92GNUNET_HELLO_get_type (const struct GNUNET_MessageHeader *h);
93
94/**
82 * Allocate an address struct. 95 * Allocate an address struct.
83 * 96 *
84 * @param peer the peer 97 * @param peer the peer
@@ -180,13 +193,17 @@ typedef size_t (*GNUNET_HELLO_GenerateAddressListCallback) (void *cls,
180 * expiration time and an iterator that spews the 193 * expiration time and an iterator that spews the
181 * transport addresses. 194 * transport addresses.
182 * 195 *
196 * If friend only is set to GNUNET_YES we create a FRIEND_HELLO which will
197 * not be gossiped to other peers
198 *
183 * @return the hello message 199 * @return the hello message
184 */ 200 */
185struct GNUNET_HELLO_Message * 201struct GNUNET_HELLO_Message *
186GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded 202GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded
187 *publicKey, 203 *publicKey,
188 GNUNET_HELLO_GenerateAddressListCallback addrgen, 204 GNUNET_HELLO_GenerateAddressListCallback addrgen,
189 void *addrgen_cls); 205 void *addrgen_cls,
206 int friend_only);
190 207
191 208
192/** 209/**
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 7f8d02be9..5c7357d13 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -112,6 +112,12 @@ extern "C"
112 */ 112 */
113#define GNUNET_MESSAGE_TYPE_HELLO 16 113#define GNUNET_MESSAGE_TYPE_HELLO 16
114 114
115/**
116 * HELLO message used for communicating peer addresses with friends only.
117 */
118
119#define GNUNET_MESSAGE_TYPE_FRIEND_HELLO 17
120
115/******************************************************************************* 121/*******************************************************************************
116 * FRAGMENTATION message types 122 * FRAGMENTATION message types
117 ******************************************************************************/ 123 ******************************************************************************/
diff --git a/src/peerinfo/perf_peerinfo_api.c b/src/peerinfo/perf_peerinfo_api.c
index 991773cad..41533bd3f 100755
--- a/src/peerinfo/perf_peerinfo_api.c
+++ b/src/peerinfo/perf_peerinfo_api.c
@@ -87,7 +87,7 @@ add_peer (size_t i)
87 87
88 memset (&pkey, i, sizeof (pkey)); 88 memset (&pkey, i, sizeof (pkey));
89 GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey); 89 GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey);
90 h2 = GNUNET_HELLO_create (&pkey, &address_generator, &i); 90 h2 = GNUNET_HELLO_create (&pkey, &address_generator, &i, GNUNET_NO);
91 GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL); 91 GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL);
92 GNUNET_free (h2); 92 GNUNET_free (h2);
93} 93}
diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c
index 6fdfdc5ca..59ea0ac8a 100644
--- a/src/peerinfo/test_peerinfo_api.c
+++ b/src/peerinfo/test_peerinfo_api.c
@@ -93,7 +93,7 @@ add_peer ()
93 agc = 2; 93 agc = 2;
94 memset (&pkey, 32, sizeof (pkey)); 94 memset (&pkey, 32, sizeof (pkey));
95 GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey); 95 GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey);
96 h2 = GNUNET_HELLO_create (&pkey, &address_generator, &agc); 96 h2 = GNUNET_HELLO_create (&pkey, &address_generator, &agc, GNUNET_NO);
97 GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL); 97 GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL);
98 GNUNET_free (h2); 98 GNUNET_free (h2);
99 99
diff --git a/src/transport/gnunet-service-transport_hello.c b/src/transport/gnunet-service-transport_hello.c
index c04d2e1dd..78968ae77 100644
--- a/src/transport/gnunet-service-transport_hello.c
+++ b/src/transport/gnunet-service-transport_hello.c
@@ -167,7 +167,7 @@ refresh_hello_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
167 gc.expiration = GNUNET_TIME_relative_to_absolute (hello_expiration); 167 gc.expiration = GNUNET_TIME_relative_to_absolute (hello_expiration);
168 168
169 GNUNET_free (our_hello); 169 GNUNET_free (our_hello);
170 our_hello = GNUNET_HELLO_create (&GST_my_public_key, &address_generator, &gc); 170 our_hello = GNUNET_HELLO_create (&GST_my_public_key, &address_generator, &gc, GNUNET_NO);
171 GNUNET_assert (NULL != our_hello); 171 GNUNET_assert (NULL != our_hello);
172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
173 "Refreshed my `%s', new size is %d\n", "HELLO", 173 "Refreshed my `%s', new size is %d\n", "HELLO",
@@ -208,7 +208,7 @@ GST_hello_start (GST_HelloCallback cb, void *cb_cls)
208{ 208{
209 hello_cb = cb; 209 hello_cb = cb;
210 hello_cb_cls = cb_cls; 210 hello_cb_cls = cb_cls;
211 our_hello = GNUNET_HELLO_create (&GST_my_public_key, NULL, NULL); 211 our_hello = GNUNET_HELLO_create (&GST_my_public_key, NULL, NULL, GNUNET_NO);
212 GNUNET_assert (NULL != our_hello); 212 GNUNET_assert (NULL != our_hello);
213 refresh_hello (); 213 refresh_hello ();
214} 214}
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index 4bb782bf4..f5c57d864 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -1264,7 +1264,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1264 1264
1265 /* build HELLO to store in PEERINFO */ 1265 /* build HELLO to store in PEERINFO */
1266 ve->copied = GNUNET_NO; 1266 ve->copied = GNUNET_NO;
1267 hello = GNUNET_HELLO_create (&ve->public_key, &add_valid_peer_address, ve); 1267 hello = GNUNET_HELLO_create (&ve->public_key, &add_valid_peer_address, ve, GNUNET_NO);
1268 GNUNET_PEERINFO_add_peer (GST_peerinfo, hello, NULL, NULL); 1268 GNUNET_PEERINFO_add_peer (GST_peerinfo, hello, NULL, NULL);
1269 GNUNET_free (hello); 1269 GNUNET_free (hello);
1270} 1270}
@@ -1295,7 +1295,7 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
1295 memcmp (&GST_my_identity, &vac.pid, sizeof (struct GNUNET_PeerIdentity))) 1295 memcmp (&GST_my_identity, &vac.pid, sizeof (struct GNUNET_PeerIdentity)))
1296 return; 1296 return;
1297 /* Add peer identity without addresses to peerinfo service */ 1297 /* Add peer identity without addresses to peerinfo service */
1298 h = GNUNET_HELLO_create (&vac.public_key, NULL, NULL); 1298 h = GNUNET_HELLO_create (&vac.public_key, NULL, NULL, GNUNET_NO);
1299 GNUNET_PEERINFO_add_peer (GST_peerinfo, h, NULL, NULL); 1299 GNUNET_PEERINFO_add_peer (GST_peerinfo, h, NULL, NULL);
1300 1300
1301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c
index 583e78467..58fd07c78 100644
--- a/src/transport/test_plugin_transport.c
+++ b/src/transport/test_plugin_transport.c
@@ -601,7 +601,7 @@ run (void *cls, char *const *args, const char *cfgfile,
601 &my_identity.hashPubKey); 601 &my_identity.hashPubKey);
602 602
603 603
604 hello = GNUNET_HELLO_create(&my_public_key, NULL, NULL); 604 hello = GNUNET_HELLO_create(&my_public_key, NULL, NULL, GNUNET_NO);
605 605
606 /* load plugins... */ 606 /* load plugins... */
607 setup_plugin_environment (); 607 setup_plugin_environment ();