aboutsummaryrefslogtreecommitdiff
path: root/src/hello
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/hello
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/hello')
-rw-r--r--src/hello/address.c66
-rw-r--r--src/hello/gnunet-hello.c179
-rw-r--r--src/hello/hello-ng.c141
-rw-r--r--src/hello/hello.c843
-rw-r--r--src/hello/test_friend_hello.c196
-rw-r--r--src/hello/test_hello.c284
6 files changed, 862 insertions, 847 deletions
diff --git a/src/hello/address.c b/src/hello/address.c
index 3936a0133..e22f3850f 100644
--- a/src/hello/address.c
+++ b/src/hello/address.c
@@ -36,8 +36,8 @@
36 * @return #GNUNET_YES or #GNUNET_NO 36 * @return #GNUNET_YES or #GNUNET_NO
37 */ 37 */
38int 38int
39GNUNET_HELLO_address_check_option(const struct GNUNET_HELLO_Address * address, 39GNUNET_HELLO_address_check_option (const struct GNUNET_HELLO_Address *address,
40 enum GNUNET_HELLO_AddressInfo option) 40 enum GNUNET_HELLO_AddressInfo option)
41{ 41{
42 if (option == (address->local_info & option)) 42 if (option == (address->local_info & option))
43 return GNUNET_YES; 43 return GNUNET_YES;
@@ -52,10 +52,10 @@ GNUNET_HELLO_address_check_option(const struct GNUNET_HELLO_Address * address,
52 * @return the size 52 * @return the size
53 */ 53 */
54size_t 54size_t
55GNUNET_HELLO_address_get_size(const struct GNUNET_HELLO_Address * address) 55GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address)
56{ 56{
57 return sizeof(struct GNUNET_HELLO_Address) + address->address_length + 57 return sizeof(struct GNUNET_HELLO_Address) + address->address_length
58 strlen(address->transport_name) + 1; 58 + strlen (address->transport_name) + 1;
59} 59}
60 60
61 61
@@ -70,31 +70,31 @@ GNUNET_HELLO_address_get_size(const struct GNUNET_HELLO_Address * address)
70 * @return the address struct 70 * @return the address struct
71 */ 71 */
72struct GNUNET_HELLO_Address * 72struct GNUNET_HELLO_Address *
73GNUNET_HELLO_address_allocate(const struct GNUNET_PeerIdentity *peer, 73GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer,
74 const char *transport_name, 74 const char *transport_name,
75 const void *address, 75 const void *address,
76 size_t address_length, 76 size_t address_length,
77 enum GNUNET_HELLO_AddressInfo local_info) 77 enum GNUNET_HELLO_AddressInfo local_info)
78{ 78{
79 struct GNUNET_HELLO_Address *addr; 79 struct GNUNET_HELLO_Address *addr;
80 size_t slen; 80 size_t slen;
81 char *end; 81 char *end;
82 82
83 slen = strlen(transport_name) + 1; 83 slen = strlen (transport_name) + 1;
84 addr = GNUNET_malloc(sizeof(struct GNUNET_HELLO_Address) + 84 addr = GNUNET_malloc (sizeof(struct GNUNET_HELLO_Address)
85 address_length + slen); 85 + address_length + slen);
86 addr->peer = *peer; 86 addr->peer = *peer;
87 addr->address = &addr[1]; 87 addr->address = &addr[1];
88 addr->address_length = address_length; 88 addr->address_length = address_length;
89 addr->local_info = local_info; 89 addr->local_info = local_info;
90 end = (char *)&addr[1]; 90 end = (char *) &addr[1];
91 addr->transport_name = &end[address_length]; 91 addr->transport_name = &end[address_length];
92 GNUNET_memcpy(end, 92 GNUNET_memcpy (end,
93 address, 93 address,
94 address_length); 94 address_length);
95 GNUNET_memcpy(&end[address_length], 95 GNUNET_memcpy (&end[address_length],
96 transport_name, 96 transport_name,
97 slen); 97 slen);
98 return addr; 98 return addr;
99} 99}
100 100
@@ -106,15 +106,15 @@ GNUNET_HELLO_address_allocate(const struct GNUNET_PeerIdentity *peer,
106 * @return a copy of the address struct 106 * @return a copy of the address struct
107 */ 107 */
108struct GNUNET_HELLO_Address * 108struct GNUNET_HELLO_Address *
109GNUNET_HELLO_address_copy(const struct GNUNET_HELLO_Address *address) 109GNUNET_HELLO_address_copy (const struct GNUNET_HELLO_Address *address)
110{ 110{
111 if (NULL == address) 111 if (NULL == address)
112 return NULL; 112 return NULL;
113 return GNUNET_HELLO_address_allocate(&address->peer, 113 return GNUNET_HELLO_address_allocate (&address->peer,
114 address->transport_name, 114 address->transport_name,
115 address->address, 115 address->address,
116 address->address_length, 116 address->address_length,
117 address->local_info); 117 address->local_info);
118} 118}
119 119
120 120
@@ -127,8 +127,8 @@ GNUNET_HELLO_address_copy(const struct GNUNET_HELLO_Address *address)
127 * @return 0 if the addresses are equal, -1 if a1<a2, 1 if a1>a2. 127 * @return 0 if the addresses are equal, -1 if a1<a2, 1 if a1>a2.
128 */ 128 */
129int 129int
130GNUNET_HELLO_address_cmp(const struct GNUNET_HELLO_Address *a1, 130GNUNET_HELLO_address_cmp (const struct GNUNET_HELLO_Address *a1,
131 const struct GNUNET_HELLO_Address *a2) 131 const struct GNUNET_HELLO_Address *a2)
132{ 132{
133 int ret; 133 int ret;
134 134
@@ -139,18 +139,18 @@ GNUNET_HELLO_address_cmp(const struct GNUNET_HELLO_Address *a1,
139 return 1; 139 return 1;
140 if (NULL == a2) 140 if (NULL == a2)
141 return -1; 141 return -1;
142 ret = strcmp(a1->transport_name, a2->transport_name); 142 ret = strcmp (a1->transport_name, a2->transport_name);
143 if (0 != ret) 143 if (0 != ret)
144 return ret; 144 return ret;
145 if (a1->local_info != a2->local_info) 145 if (a1->local_info != a2->local_info)
146 return (((int)a1->local_info) < ((int)a2->local_info)) ? -1 : 1; 146 return (((int) a1->local_info) < ((int) a2->local_info)) ? -1 : 1;
147 if (a1->address_length < a2->address_length) 147 if (a1->address_length < a2->address_length)
148 return -1; 148 return -1;
149 if (a1->address_length > a2->address_length) 149 if (a1->address_length > a2->address_length)
150 return 1; 150 return 1;
151 return memcmp(a1->address, 151 return memcmp (a1->address,
152 a2->address, 152 a2->address,
153 a1->address_length); 153 a1->address_length);
154} 154}
155 155
156 156
diff --git a/src/hello/gnunet-hello.c b/src/hello/gnunet-hello.c
index 1b572b904..9f277de4a 100644
--- a/src/hello/gnunet-hello.c
+++ b/src/hello/gnunet-hello.c
@@ -29,7 +29,8 @@
29/** 29/**
30 * Closure for #add_to_buf(). 30 * Closure for #add_to_buf().
31 */ 31 */
32struct AddContext { 32struct AddContext
33{
33 /** 34 /**
34 * Where to add. 35 * Where to add.
35 */ 36 */
@@ -58,17 +59,17 @@ static int address_count;
58 * @return #GNUNET_OK keep iterating 59 * @return #GNUNET_OK keep iterating
59 */ 60 */
60static int 61static int
61add_to_buf(void *cls, 62add_to_buf (void *cls,
62 const struct GNUNET_HELLO_Address *address, 63 const struct GNUNET_HELLO_Address *address,
63 struct GNUNET_TIME_Absolute expiration) 64 struct GNUNET_TIME_Absolute expiration)
64{ 65{
65 struct AddContext *ac = cls; 66 struct AddContext *ac = cls;
66 size_t ret; 67 size_t ret;
67 68
68 ret = GNUNET_HELLO_add_address(address, 69 ret = GNUNET_HELLO_add_address (address,
69 GNUNET_TIME_UNIT_FOREVER_ABS, 70 GNUNET_TIME_UNIT_FOREVER_ABS,
70 ac->buf, 71 ac->buf,
71 ac->max); 72 ac->max);
72 ac->buf += ret; 73 ac->buf += ret;
73 ac->max -= ret; 74 ac->max -= ret;
74 ac->ret += ret; 75 ac->ret += ret;
@@ -86,7 +87,7 @@ add_to_buf(void *cls,
86 * @return number of bytes added, 0 to terminate 87 * @return number of bytes added, 0 to terminate
87 */ 88 */
88static ssize_t 89static ssize_t
89add_from_hello(void *cls, size_t max, void *buf) 90add_from_hello (void *cls, size_t max, void *buf)
90{ 91{
91 struct GNUNET_HELLO_Message **orig = cls; 92 struct GNUNET_HELLO_Message **orig = cls;
92 struct AddContext ac; 93 struct AddContext ac;
@@ -96,16 +97,16 @@ add_from_hello(void *cls, size_t max, void *buf)
96 ac.buf = buf; 97 ac.buf = buf;
97 ac.max = max; 98 ac.max = max;
98 ac.ret = 0; 99 ac.ret = 0;
99 GNUNET_assert( 100 GNUNET_assert (
100 NULL == 101 NULL ==
101 GNUNET_HELLO_iterate_addresses(*orig, GNUNET_NO, &add_to_buf, &ac)); 102 GNUNET_HELLO_iterate_addresses (*orig, GNUNET_NO, &add_to_buf, &ac));
102 *orig = NULL; 103 *orig = NULL;
103 return ac.ret; 104 return ac.ret;
104} 105}
105 106
106 107
107int 108int
108main(int argc, char *argv[]) 109main (int argc, char *argv[])
109{ 110{
110 struct GNUNET_DISK_FileHandle *fh; 111 struct GNUNET_DISK_FileHandle *fh;
111 struct GNUNET_HELLO_Message *orig; 112 struct GNUNET_HELLO_Message *orig;
@@ -115,98 +116,98 @@ main(int argc, char *argv[])
115 116
116 address_count = 0; 117 address_count = 0;
117 118
118 GNUNET_log_setup("gnunet-hello", "INFO", NULL); 119 GNUNET_log_setup ("gnunet-hello", "INFO", NULL);
119 if (argc != 2) 120 if (argc != 2)
120 { 121 {
121 fprintf(stderr, "%s", _("Call with name of HELLO file to modify.\n")); 122 fprintf (stderr, "%s", _ ("Call with name of HELLO file to modify.\n"));
122 return 1; 123 return 1;
123 } 124 }
124 if (GNUNET_OK != 125 if (GNUNET_OK !=
125 GNUNET_DISK_file_size(argv[1], &fsize, GNUNET_YES, GNUNET_YES)) 126 GNUNET_DISK_file_size (argv[1], &fsize, GNUNET_YES, GNUNET_YES))
126 { 127 {
127 fprintf(stderr, 128 fprintf (stderr,
128 _("Error accessing file `%s': %s\n"), 129 _ ("Error accessing file `%s': %s\n"),
129 argv[1], 130 argv[1],
130 strerror(errno)); 131 strerror (errno));
131 return 1; 132 return 1;
132 } 133 }
133 if (fsize > 65536) 134 if (fsize > 65536)
134 { 135 {
135 fprintf(stderr, _("File `%s' is too big to be a HELLO\n"), argv[1]); 136 fprintf (stderr, _ ("File `%s' is too big to be a HELLO\n"), argv[1]);
136 return 1; 137 return 1;
137 } 138 }
138 if (fsize < sizeof(struct GNUNET_MessageHeader)) 139 if (fsize < sizeof(struct GNUNET_MessageHeader))
139 { 140 {
140 fprintf(stderr, _("File `%s' is too small to be a HELLO\n"), argv[1]); 141 fprintf (stderr, _ ("File `%s' is too small to be a HELLO\n"), argv[1]);
141 return 1; 142 return 1;
142 } 143 }
143 fh = GNUNET_DISK_file_open(argv[1], 144 fh = GNUNET_DISK_file_open (argv[1],
144 GNUNET_DISK_OPEN_READ, 145 GNUNET_DISK_OPEN_READ,
145 GNUNET_DISK_PERM_USER_READ); 146 GNUNET_DISK_PERM_USER_READ);
146 if (NULL == fh) 147 if (NULL == fh)
147 { 148 {
148 fprintf(stderr, 149 fprintf (stderr,
149 _("Error opening file `%s': %s\n"), 150 _ ("Error opening file `%s': %s\n"),
150 argv[1], 151 argv[1],
151 strerror(errno)); 152 strerror (errno));
152 return 1; 153 return 1;
153 } 154 }
154 { 155 {
155 char buf[fsize] GNUNET_ALIGN; 156 char buf[fsize] GNUNET_ALIGN;
156 157
157 GNUNET_assert(fsize == GNUNET_DISK_file_read(fh, buf, fsize)); 158 GNUNET_assert (fsize == GNUNET_DISK_file_read (fh, buf, fsize));
158 GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh)); 159 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
159 orig = (struct GNUNET_HELLO_Message *)buf; 160 orig = (struct GNUNET_HELLO_Message *) buf;
160 if ((fsize < GNUNET_HELLO_size(orig)) || 161 if ((fsize < GNUNET_HELLO_size (orig)) ||
161 (GNUNET_OK != GNUNET_HELLO_get_id(orig, &pid))) 162 (GNUNET_OK != GNUNET_HELLO_get_id (orig, &pid)))
162 { 163 {
163 fprintf(stderr, 164 fprintf (stderr,
164 _("Did not find well-formed HELLO in file `%s'\n"), 165 _ ("Did not find well-formed HELLO in file `%s'\n"),
165 argv[1]); 166 argv[1]);
166 return 1; 167 return 1;
167 } 168 }
168 { 169 {
169 char *pids; 170 char *pids;
170 171
171 pids = GNUNET_CRYPTO_eddsa_public_key_to_string(&pid.public_key); 172 pids = GNUNET_CRYPTO_eddsa_public_key_to_string (&pid.public_key);
172 fprintf(stdout, "Processing HELLO for peer `%s'\n", pids); 173 fprintf (stdout, "Processing HELLO for peer `%s'\n", pids);
173 GNUNET_free(pids); 174 GNUNET_free (pids);
174 } 175 }
175 result = GNUNET_HELLO_create(&pid.public_key, 176 result = GNUNET_HELLO_create (&pid.public_key,
176 &add_from_hello, 177 &add_from_hello,
177 &orig, 178 &orig,
178 GNUNET_HELLO_is_friend_only(orig)); 179 GNUNET_HELLO_is_friend_only (orig));
179 GNUNET_assert(NULL != result); 180 GNUNET_assert (NULL != result);
180 fh = 181 fh =
181 GNUNET_DISK_file_open(argv[1], 182 GNUNET_DISK_file_open (argv[1],
182 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE, 183 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE,
183 GNUNET_DISK_PERM_USER_READ | 184 GNUNET_DISK_PERM_USER_READ
184 GNUNET_DISK_PERM_USER_WRITE); 185 | GNUNET_DISK_PERM_USER_WRITE);
185 if (NULL == fh) 186 if (NULL == fh)
186 { 187 {
187 fprintf(stderr, 188 fprintf (stderr,
188 _("Error opening file `%s': %s\n"), 189 _ ("Error opening file `%s': %s\n"),
189 argv[1], 190 argv[1],
190 strerror(errno)); 191 strerror (errno));
191 GNUNET_free(result); 192 GNUNET_free (result);
192 return 1; 193 return 1;
193 } 194 }
194 fsize = GNUNET_HELLO_size(result); 195 fsize = GNUNET_HELLO_size (result);
195 if (fsize != GNUNET_DISK_file_write(fh, result, fsize)) 196 if (fsize != GNUNET_DISK_file_write (fh, result, fsize))
196 { 197 {
197 fprintf(stderr, 198 fprintf (stderr,
198 _("Error writing HELLO to file `%s': %s\n"), 199 _ ("Error writing HELLO to file `%s': %s\n"),
199 argv[1], 200 argv[1],
200 strerror(errno)); 201 strerror (errno));
201 (void)GNUNET_DISK_file_close(fh); 202 (void) GNUNET_DISK_file_close (fh);
202 return 1; 203 return 1;
203 } 204 }
204 GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh)); 205 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
205 } 206 }
206 fprintf(stderr, 207 fprintf (stderr,
207 _("Modified %u addresses, wrote %u bytes\n"), 208 _ ("Modified %u addresses, wrote %u bytes\n"),
208 address_count, 209 address_count,
209 (unsigned int)fsize); 210 (unsigned int) fsize);
210 return 0; 211 return 0;
211} 212}
212 213
diff --git a/src/hello/hello-ng.c b/src/hello/hello-ng.c
index f44fff032..8dea616b9 100644
--- a/src/hello/hello-ng.c
+++ b/src/hello/hello-ng.c
@@ -33,7 +33,8 @@
33/** 33/**
34 * Binary block we sign when we sign an address. 34 * Binary block we sign when we sign an address.
35 */ 35 */
36struct SignedAddress { 36struct SignedAddress
37{
37 /** 38 /**
38 * Purpose must be #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS 39 * Purpose must be #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS
39 */ 40 */
@@ -62,7 +63,7 @@ struct SignedAddress {
62 * @param result_size[out] set to size of @a result 63 * @param result_size[out] set to size of @a result
63 */ 64 */
64void 65void
65GNUNET_HELLO_sign_address( 66GNUNET_HELLO_sign_address (
66 const char *address, 67 const char *address,
67 enum GNUNET_NetworkType nt, 68 enum GNUNET_NetworkType nt,
68 struct GNUNET_TIME_Absolute mono_time, 69 struct GNUNET_TIME_Absolute mono_time,
@@ -74,22 +75,22 @@ GNUNET_HELLO_sign_address(
74 struct GNUNET_CRYPTO_EddsaSignature sig; 75 struct GNUNET_CRYPTO_EddsaSignature sig;
75 char *sig_str; 76 char *sig_str;
76 77
77 sa.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS); 78 sa.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS);
78 sa.purpose.size = htonl(sizeof(sa)); 79 sa.purpose.size = htonl (sizeof(sa));
79 sa.mono_time = GNUNET_TIME_absolute_hton(mono_time); 80 sa.mono_time = GNUNET_TIME_absolute_hton (mono_time);
80 GNUNET_CRYPTO_hash(address, strlen(address), &sa.h_addr); 81 GNUNET_CRYPTO_hash (address, strlen (address), &sa.h_addr);
81 GNUNET_assert(GNUNET_YES == 82 GNUNET_assert (GNUNET_YES ==
82 GNUNET_CRYPTO_eddsa_sign(private_key, &sa.purpose, &sig)); 83 GNUNET_CRYPTO_eddsa_sign (private_key, &sa.purpose, &sig));
83 sig_str = NULL; 84 sig_str = NULL;
84 (void)GNUNET_STRINGS_base64_encode(&sig, sizeof(sig), &sig_str); 85 (void) GNUNET_STRINGS_base64_encode (&sig, sizeof(sig), &sig_str);
85 *result_size = 86 *result_size =
86 1 + GNUNET_asprintf((char **)result, 87 1 + GNUNET_asprintf ((char **) result,
87 "%s;%llu;%u;%s", 88 "%s;%llu;%u;%s",
88 sig_str, 89 sig_str,
89 (unsigned long long)mono_time.abs_value_us, 90 (unsigned long long) mono_time.abs_value_us,
90 (unsigned int)nt, 91 (unsigned int) nt,
91 address); 92 address);
92 GNUNET_free(sig_str); 93 GNUNET_free (sig_str);
93} 94}
94 95
95 96
@@ -104,11 +105,11 @@ GNUNET_HELLO_sign_address(
104 * @return NULL on error, otherwise the address 105 * @return NULL on error, otherwise the address
105 */ 106 */
106char * 107char *
107GNUNET_HELLO_extract_address(const void *raw, 108GNUNET_HELLO_extract_address (const void *raw,
108 size_t raw_size, 109 size_t raw_size,
109 const struct GNUNET_PeerIdentity *pid, 110 const struct GNUNET_PeerIdentity *pid,
110 enum GNUNET_NetworkType *nt, 111 enum GNUNET_NetworkType *nt,
111 struct GNUNET_TIME_Absolute *mono_time) 112 struct GNUNET_TIME_Absolute *mono_time)
112{ 113{
113 const struct GNUNET_CRYPTO_EddsaPublicKey *public_key = &pid->public_key; 114 const struct GNUNET_CRYPTO_EddsaPublicKey *public_key = &pid->public_key;
114 const char *raws = raw; 115 const char *raws = raw;
@@ -123,59 +124,59 @@ GNUNET_HELLO_extract_address(const void *raw,
123 struct GNUNET_CRYPTO_EddsaSignature *sig; 124 struct GNUNET_CRYPTO_EddsaSignature *sig;
124 125
125 if ('\0' != raws[raw_size]) 126 if ('\0' != raws[raw_size])
126 { 127 {
127 GNUNET_break_op(0); 128 GNUNET_break_op (0);
128 return NULL; 129 return NULL;
129 } 130 }
130 if (NULL == (sc = strchr(raws, ';'))) 131 if (NULL == (sc = strchr (raws, ';')))
131 { 132 {
132 GNUNET_break_op(0); 133 GNUNET_break_op (0);
133 return NULL; 134 return NULL;
134 } 135 }
135 if (NULL == (sc2 = strchr(sc + 1, ';'))) 136 if (NULL == (sc2 = strchr (sc + 1, ';')))
136 { 137 {
137 GNUNET_break_op(0); 138 GNUNET_break_op (0);
138 return NULL; 139 return NULL;
139 } 140 }
140 if (NULL == (sc3 = strchr(sc2 + 1, ';'))) 141 if (NULL == (sc3 = strchr (sc2 + 1, ';')))
141 { 142 {
142 GNUNET_break_op(0); 143 GNUNET_break_op (0);
143 return NULL; 144 return NULL;
144 } 145 }
145 if (1 != sscanf(sc + 1, "%llu;%u;", &raw_us, &raw_nt)) 146 if (1 != sscanf (sc + 1, "%llu;%u;", &raw_us, &raw_nt))
146 { 147 {
147 GNUNET_break_op(0); 148 GNUNET_break_op (0);
148 return NULL; 149 return NULL;
149 } 150 }
150 raw_mono_time.abs_value_us = raw_us; 151 raw_mono_time.abs_value_us = raw_us;
151 sig = NULL; 152 sig = NULL;
152 if (sizeof(struct GNUNET_CRYPTO_EddsaSignature) != 153 if (sizeof(struct GNUNET_CRYPTO_EddsaSignature) !=
153 GNUNET_STRINGS_base64_decode(raws, sc - raws, (void **)&sig)) 154 GNUNET_STRINGS_base64_decode (raws, sc - raws, (void **) &sig))
154 { 155 {
155 GNUNET_break_op(0); 156 GNUNET_break_op (0);
156 GNUNET_free_non_null(sig); 157 GNUNET_free_non_null (sig);
157 return NULL; 158 return NULL;
158 } 159 }
159 raw_addr = sc3 + 1; 160 raw_addr = sc3 + 1;
160 161
161 sa.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS); 162 sa.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS);
162 sa.purpose.size = htonl(sizeof(sa)); 163 sa.purpose.size = htonl (sizeof(sa));
163 sa.mono_time = GNUNET_TIME_absolute_hton(raw_mono_time); 164 sa.mono_time = GNUNET_TIME_absolute_hton (raw_mono_time);
164 GNUNET_CRYPTO_hash(raw_addr, strlen(raw_addr), &sa.h_addr); 165 GNUNET_CRYPTO_hash (raw_addr, strlen (raw_addr), &sa.h_addr);
165 if (GNUNET_YES != 166 if (GNUNET_YES !=
166 GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS, 167 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_ADDRESS,
167 &sa.purpose, 168 &sa.purpose,
168 sig, 169 sig,
169 public_key)) 170 public_key))
170 { 171 {
171 GNUNET_break_op(0); 172 GNUNET_break_op (0);
172 GNUNET_free(sig); 173 GNUNET_free (sig);
173 return NULL; 174 return NULL;
174 } 175 }
175 GNUNET_free(sig); 176 GNUNET_free (sig);
176 *mono_time = raw_mono_time; 177 *mono_time = raw_mono_time;
177 *nt = (enum GNUNET_NetworkType)raw_nt; 178 *nt = (enum GNUNET_NetworkType) raw_nt;
178 return GNUNET_strdup(raw_addr); 179 return GNUNET_strdup (raw_addr);
179} 180}
180 181
181 182
@@ -187,12 +188,12 @@ GNUNET_HELLO_extract_address(const void *raw,
187 * @return NULL if the address is mal-formed, otherwise the prefix 188 * @return NULL if the address is mal-formed, otherwise the prefix
188 */ 189 */
189char * 190char *
190GNUNET_HELLO_address_to_prefix(const char *address) 191GNUNET_HELLO_address_to_prefix (const char *address)
191{ 192{
192 const char *dash; 193 const char *dash;
193 194
194 dash = strchr(address, '-'); 195 dash = strchr (address, '-');
195 if (NULL == dash) 196 if (NULL == dash)
196 return NULL; 197 return NULL;
197 return GNUNET_strndup(address, dash - address); 198 return GNUNET_strndup (address, dash - address);
198} 199}
diff --git a/src/hello/hello.c b/src/hello/hello.c
index 021451a08..e701e1f17 100644
--- a/src/hello/hello.c
+++ b/src/hello/hello.c
@@ -33,7 +33,8 @@
33/** 33/**
34 * Context used for building our own URI. 34 * Context used for building our own URI.
35 */ 35 */
36struct GNUNET_HELLO_ComposeUriContext { 36struct GNUNET_HELLO_ComposeUriContext
37{
37 /** 38 /**
38 * Final URI. 39 * Final URI.
39 */ 40 */
@@ -49,7 +50,8 @@ struct GNUNET_HELLO_ComposeUriContext {
49/** 50/**
50 * Context for #add_address_to_hello(). 51 * Context for #add_address_to_hello().
51 */ 52 */
52struct GNUNET_HELLO_ParseUriContext { 53struct GNUNET_HELLO_ParseUriContext
54{
53 /** 55 /**
54 * Position in the URI with the next address to parse. 56 * Position in the URI with the next address to parse.
55 */ 57 */
@@ -84,9 +86,9 @@ struct GNUNET_HELLO_ParseUriContext {
84 * @return #GNUNET_YES for friend-only or #GNUNET_NO otherwise 86 * @return #GNUNET_YES for friend-only or #GNUNET_NO otherwise
85 */ 87 */
86int 88int
87GNUNET_HELLO_is_friend_only(const struct GNUNET_HELLO_Message *h) 89GNUNET_HELLO_is_friend_only (const struct GNUNET_HELLO_Message *h)
88{ 90{
89 if (GNUNET_YES == ntohl(h->friend_only)) 91 if (GNUNET_YES == ntohl (h->friend_only))
90 return GNUNET_YES; 92 return GNUNET_YES;
91 return GNUNET_NO; 93 return GNUNET_NO;
92} 94}
@@ -104,27 +106,27 @@ GNUNET_HELLO_is_friend_only(const struct GNUNET_HELLO_Message *h)
104 * the target buffer was not big enough. 106 * the target buffer was not big enough.
105 */ 107 */
106size_t 108size_t
107GNUNET_HELLO_add_address(const struct GNUNET_HELLO_Address *address, 109GNUNET_HELLO_add_address (const struct GNUNET_HELLO_Address *address,
108 struct GNUNET_TIME_Absolute expiration, 110 struct GNUNET_TIME_Absolute expiration,
109 char *target, 111 char *target,
110 size_t max) 112 size_t max)
111{ 113{
112 uint16_t alen; 114 uint16_t alen;
113 size_t slen; 115 size_t slen;
114 struct GNUNET_TIME_AbsoluteNBO exp; 116 struct GNUNET_TIME_AbsoluteNBO exp;
115 117
116 slen = strlen(address->transport_name) + 1; 118 slen = strlen (address->transport_name) + 1;
117 if (slen + sizeof(uint16_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO) + 119 if (slen + sizeof(uint16_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO)
118 address->address_length > max) 120 + address->address_length > max)
119 return 0; 121 return 0;
120 exp = GNUNET_TIME_absolute_hton(expiration); 122 exp = GNUNET_TIME_absolute_hton (expiration);
121 alen = htons((uint16_t)address->address_length); 123 alen = htons ((uint16_t) address->address_length);
122 GNUNET_memcpy(target, address->transport_name, slen); 124 GNUNET_memcpy (target, address->transport_name, slen);
123 GNUNET_memcpy(&target[slen], &alen, sizeof(uint16_t)); 125 GNUNET_memcpy (&target[slen], &alen, sizeof(uint16_t));
124 slen += sizeof(uint16_t); 126 slen += sizeof(uint16_t);
125 GNUNET_memcpy(&target[slen], &exp, sizeof(struct GNUNET_TIME_AbsoluteNBO)); 127 GNUNET_memcpy (&target[slen], &exp, sizeof(struct GNUNET_TIME_AbsoluteNBO));
126 slen += sizeof(struct GNUNET_TIME_AbsoluteNBO); 128 slen += sizeof(struct GNUNET_TIME_AbsoluteNBO);
127 GNUNET_memcpy(&target[slen], address->address, address->address_length); 129 GNUNET_memcpy (&target[slen], address->address, address->address_length);
128 slen += address->address_length; 130 slen += address->address_length;
129 return slen; 131 return slen;
130} 132}
@@ -139,9 +141,9 @@ GNUNET_HELLO_add_address(const struct GNUNET_HELLO_Address *address,
139 * @return size of the entry, or 0 if @a max is not large enough 141 * @return size of the entry, or 0 if @a max is not large enough
140 */ 142 */
141static size_t 143static size_t
142get_hello_address_size(const char *buf, 144get_hello_address_size (const char *buf,
143 size_t max, 145 size_t max,
144 uint16_t *ralen) 146 uint16_t *ralen)
145{ 147{
146 const char *pos; 148 const char *pos;
147 uint16_t alen; 149 uint16_t alen;
@@ -152,34 +154,34 @@ get_hello_address_size(const char *buf,
152 pos = buf; 154 pos = buf;
153 slen = 1; 155 slen = 1;
154 while ((left > 0) && ('\0' != *pos)) 156 while ((left > 0) && ('\0' != *pos))
155 { 157 {
156 left--; 158 left--;
157 pos++; 159 pos++;
158 slen++; 160 slen++;
159 } 161 }
160 if (0 == left) 162 if (0 == left)
161 { 163 {
162 /* 0-termination not found */ 164 /* 0-termination not found */
163 GNUNET_break_op(0); 165 GNUNET_break_op (0);
164 return 0; 166 return 0;
165 } 167 }
166 pos++; 168 pos++;
167 if (left < sizeof(uint16_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO)) 169 if (left < sizeof(uint16_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO))
168 { 170 {
169 /* not enough space for addrlen */ 171 /* not enough space for addrlen */
170 GNUNET_break_op(0); 172 GNUNET_break_op (0);
171 return 0; 173 return 0;
172 } 174 }
173 GNUNET_memcpy(&alen, pos, sizeof(uint16_t)); 175 GNUNET_memcpy (&alen, pos, sizeof(uint16_t));
174 alen = ntohs(alen); 176 alen = ntohs (alen);
175 *ralen = alen; 177 *ralen = alen;
176 slen += alen + sizeof(uint16_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO); 178 slen += alen + sizeof(uint16_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO);
177 if (max < slen) 179 if (max < slen)
178 { 180 {
179 /* not enough space for addr */ 181 /* not enough space for addr */
180 GNUNET_break_op(0); 182 GNUNET_break_op (0);
181 return 0; 183 return 0;
182 } 184 }
183 return slen; 185 return slen;
184} 186}
185 187
@@ -199,41 +201,41 @@ get_hello_address_size(const char *buf,
199 * @return the hello message 201 * @return the hello message
200 */ 202 */
201struct GNUNET_HELLO_Message * 203struct GNUNET_HELLO_Message *
202GNUNET_HELLO_create(const struct GNUNET_CRYPTO_EddsaPublicKey *public_key, 204GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EddsaPublicKey *public_key,
203 GNUNET_HELLO_GenerateAddressListCallback addrgen, 205 GNUNET_HELLO_GenerateAddressListCallback addrgen,
204 void *addrgen_cls, 206 void *addrgen_cls,
205 int friend_only) 207 int friend_only)
206{ 208{
207 char buffer[GNUNET_MAX_MESSAGE_SIZE - 1 - 256 - 209 char buffer[GNUNET_MAX_MESSAGE_SIZE - 1 - 256
208 sizeof(struct GNUNET_HELLO_Message)]; 210 - sizeof(struct GNUNET_HELLO_Message)];
209 size_t max; 211 size_t max;
210 size_t used; 212 size_t used;
211 size_t ret; 213 size_t ret;
212 struct GNUNET_HELLO_Message *hello; 214 struct GNUNET_HELLO_Message *hello;
213 215
214 GNUNET_assert(NULL != public_key); 216 GNUNET_assert (NULL != public_key);
215 GNUNET_assert((GNUNET_YES == friend_only) || 217 GNUNET_assert ((GNUNET_YES == friend_only) ||
216 (GNUNET_NO == friend_only)); 218 (GNUNET_NO == friend_only));
217 max = sizeof(buffer); 219 max = sizeof(buffer);
218 used = 0; 220 used = 0;
219 if (NULL != addrgen) 221 if (NULL != addrgen)
222 {
223 while (GNUNET_SYSERR != (ret = addrgen (addrgen_cls,
224 max,
225 &buffer[used])))
220 { 226 {
221 while (GNUNET_SYSERR != (ret = addrgen(addrgen_cls, 227 max -= ret;
222 max, 228 used += ret;
223 &buffer[used])))
224 {
225 max -= ret;
226 used += ret;
227 }
228 } 229 }
229 hello = GNUNET_malloc(sizeof(struct GNUNET_HELLO_Message) + used); 230 }
230 hello->header.type = htons(GNUNET_MESSAGE_TYPE_HELLO); 231 hello = GNUNET_malloc (sizeof(struct GNUNET_HELLO_Message) + used);
231 hello->header.size = htons(sizeof(struct GNUNET_HELLO_Message) + used); 232 hello->header.type = htons (GNUNET_MESSAGE_TYPE_HELLO);
232 hello->friend_only = htonl(friend_only); 233 hello->header.size = htons (sizeof(struct GNUNET_HELLO_Message) + used);
234 hello->friend_only = htonl (friend_only);
233 hello->publicKey = *public_key; 235 hello->publicKey = *public_key;
234 GNUNET_memcpy(&hello[1], 236 GNUNET_memcpy (&hello[1],
235 buffer, 237 buffer,
236 used); 238 used);
237 return hello; 239 return hello;
238} 240}
239 241
@@ -249,10 +251,10 @@ GNUNET_HELLO_create(const struct GNUNET_CRYPTO_EddsaPublicKey *public_key,
249 * @return modified HELLO message 251 * @return modified HELLO message
250 */ 252 */
251struct GNUNET_HELLO_Message * 253struct GNUNET_HELLO_Message *
252GNUNET_HELLO_iterate_addresses(const struct GNUNET_HELLO_Message *msg, 254GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg,
253 int return_modified, 255 int return_modified,
254 GNUNET_HELLO_AddressIterator it, 256 GNUNET_HELLO_AddressIterator it,
255 void *it_cls) 257 void *it_cls)
256{ 258{
257 struct GNUNET_HELLO_Address address; 259 struct GNUNET_HELLO_Address address;
258 uint16_t msize; 260 uint16_t msize;
@@ -266,69 +268,70 @@ GNUNET_HELLO_iterate_addresses(const struct GNUNET_HELLO_Message *msg,
266 struct GNUNET_TIME_AbsoluteNBO expire; 268 struct GNUNET_TIME_AbsoluteNBO expire;
267 int iret; 269 int iret;
268 270
269 msize = GNUNET_HELLO_size(msg); 271 msize = GNUNET_HELLO_size (msg);
270 if ((msize < sizeof(struct GNUNET_HELLO_Message)) || 272 if ((msize < sizeof(struct GNUNET_HELLO_Message)) ||
271 (ntohs(msg->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) 273 (ntohs (msg->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
272 { 274 {
273 GNUNET_break_op(0); 275 GNUNET_break_op (0);
274 return NULL; 276 return NULL;
275 } 277 }
276 ret = NULL; 278 ret = NULL;
277 if (return_modified) 279 if (return_modified)
278 { 280 {
279 ret = GNUNET_malloc(msize); 281 ret = GNUNET_malloc (msize);
280 GNUNET_memcpy(ret, 282 GNUNET_memcpy (ret,
281 msg, 283 msg,
282 msize); 284 msize);
283 } 285 }
284 inptr = (const char *)&msg[1]; 286 inptr = (const char *) &msg[1];
285 insize = msize - sizeof(struct GNUNET_HELLO_Message); 287 insize = msize - sizeof(struct GNUNET_HELLO_Message);
286 wpos = 0; 288 wpos = 0;
287 woff = (NULL != ret) ? (char *)&ret[1] : NULL; 289 woff = (NULL != ret) ? (char *) &ret[1] : NULL;
288 address.peer.public_key = msg->publicKey; 290 address.peer.public_key = msg->publicKey;
289 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
290 "HELLO has %u bytes of address data\n", 292 "HELLO has %u bytes of address data\n",
291 (unsigned int)insize); 293 (unsigned int) insize);
292 294
293 while (insize > 0) 295 while (insize > 0)
296 {
297 esize = get_hello_address_size (inptr,
298 insize,
299 &alen);
300 if (0 == esize)
294 { 301 {
295 esize = get_hello_address_size(inptr, 302 GNUNET_break (0);
296 insize, 303 GNUNET_free_non_null (ret);
297 &alen); 304 return NULL;
298 if (0 == esize)
299 {
300 GNUNET_break(0);
301 GNUNET_free_non_null(ret);
302 return NULL;
303 }
304 /* need GNUNET_memcpy() due to possibility of misalignment */
305 GNUNET_memcpy(&expire,
306 &inptr[esize - alen - sizeof(struct GNUNET_TIME_AbsoluteNBO)],
307 sizeof(struct GNUNET_TIME_AbsoluteNBO));
308 address.address = &inptr[esize - alen];
309 address.address_length = alen;
310 address.transport_name = inptr;
311 address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE;
312 iret = it(it_cls,
313 &address,
314 GNUNET_TIME_absolute_ntoh(expire));
315 if (GNUNET_SYSERR == iret)
316 break;
317 if ((GNUNET_OK == iret) &&
318 (NULL != ret))
319 {
320 /* copy address over */
321 GNUNET_memcpy(woff,
322 inptr,
323 esize);
324 woff += esize;
325 wpos += esize;
326 }
327 insize -= esize;
328 inptr += esize;
329 } 305 }
306 /* need GNUNET_memcpy() due to possibility of misalignment */
307 GNUNET_memcpy (&expire,
308 &inptr[esize - alen - sizeof(struct
309 GNUNET_TIME_AbsoluteNBO)],
310 sizeof(struct GNUNET_TIME_AbsoluteNBO));
311 address.address = &inptr[esize - alen];
312 address.address_length = alen;
313 address.transport_name = inptr;
314 address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE;
315 iret = it (it_cls,
316 &address,
317 GNUNET_TIME_absolute_ntoh (expire));
318 if (GNUNET_SYSERR == iret)
319 break;
320 if ((GNUNET_OK == iret) &&
321 (NULL != ret))
322 {
323 /* copy address over */
324 GNUNET_memcpy (woff,
325 inptr,
326 esize);
327 woff += esize;
328 wpos += esize;
329 }
330 insize -= esize;
331 inptr += esize;
332 }
330 if (NULL != ret) 333 if (NULL != ret)
331 ret->header.size = ntohs(sizeof(struct GNUNET_HELLO_Message) + wpos); 334 ret->header.size = ntohs (sizeof(struct GNUNET_HELLO_Message) + wpos);
332 return ret; 335 return ret;
333} 336}
334 337
@@ -336,7 +339,8 @@ GNUNET_HELLO_iterate_addresses(const struct GNUNET_HELLO_Message *msg,
336/** 339/**
337 * Closure for #get_match_exp(). 340 * Closure for #get_match_exp().
338 */ 341 */
339struct ExpireContext { 342struct ExpireContext
343{
340 /** 344 /**
341 * Address we are looking for. 345 * Address we are looking for.
342 */ 346 */
@@ -363,14 +367,14 @@ struct ExpireContext {
363 * @return #GNUNET_SYSERR if we found a matching address, #GNUNET_OK otherwise 367 * @return #GNUNET_SYSERR if we found a matching address, #GNUNET_OK otherwise
364 */ 368 */
365static int 369static int
366get_match_exp(void *cls, 370get_match_exp (void *cls,
367 const struct GNUNET_HELLO_Address *address, 371 const struct GNUNET_HELLO_Address *address,
368 struct GNUNET_TIME_Absolute expiration) 372 struct GNUNET_TIME_Absolute expiration)
369{ 373{
370 struct ExpireContext *ec = cls; 374 struct ExpireContext *ec = cls;
371 375
372 if (0 != GNUNET_HELLO_address_cmp(address, 376 if (0 != GNUNET_HELLO_address_cmp (address,
373 ec->address)) 377 ec->address))
374 return GNUNET_OK; 378 return GNUNET_OK;
375 ec->found = GNUNET_YES; 379 ec->found = GNUNET_YES;
376 ec->expiration = expiration; 380 ec->expiration = expiration;
@@ -381,7 +385,8 @@ get_match_exp(void *cls,
381/** 385/**
382 * Context for a #GNUNET_HELLO_Merge operation. 386 * Context for a #GNUNET_HELLO_Merge operation.
383 */ 387 */
384struct MergeContext { 388struct MergeContext
389{
385 /** 390 /**
386 * First HELLO we are merging. 391 * First HELLO we are merging.
387 */ 392 */
@@ -434,9 +439,9 @@ struct MergeContext {
434 * @return always #GNUNET_OK 439 * @return always #GNUNET_OK
435 */ 440 */
436static int 441static int
437copy_latest(void *cls, 442copy_latest (void *cls,
438 const struct GNUNET_HELLO_Address *address, 443 const struct GNUNET_HELLO_Address *address,
439 struct GNUNET_TIME_Absolute expiration) 444 struct GNUNET_TIME_Absolute expiration)
440{ 445{
441 struct MergeContext *mc = cls; 446 struct MergeContext *mc = cls;
442 struct ExpireContext ec; 447 struct ExpireContext ec;
@@ -444,22 +449,22 @@ copy_latest(void *cls,
444 ec.address = address; 449 ec.address = address;
445 ec.found = GNUNET_NO; 450 ec.found = GNUNET_NO;
446 /* check if address exists in other */ 451 /* check if address exists in other */
447 GNUNET_HELLO_iterate_addresses(mc->other, 452 GNUNET_HELLO_iterate_addresses (mc->other,
448 GNUNET_NO, 453 GNUNET_NO,
449 &get_match_exp, 454 &get_match_exp,
450 &ec); 455 &ec);
451 if ((GNUNET_NO == ec.found) || 456 if ((GNUNET_NO == ec.found) ||
452 (ec.expiration.abs_value_us < expiration.abs_value_us) || 457 (ec.expiration.abs_value_us < expiration.abs_value_us) ||
453 ((ec.expiration.abs_value_us == expiration.abs_value_us) && 458 ((ec.expiration.abs_value_us == expiration.abs_value_us) &&
454 (GNUNET_YES == mc->take_equal))) 459 (GNUNET_YES == mc->take_equal)))
455 { 460 {
456 /* copy address to buffer */ 461 /* copy address to buffer */
457 mc->ret += 462 mc->ret +=
458 GNUNET_HELLO_add_address(address, 463 GNUNET_HELLO_add_address (address,
459 expiration, 464 expiration,
460 &mc->buf[mc->ret], 465 &mc->buf[mc->ret],
461 mc->max - mc->ret); 466 mc->max - mc->ret);
462 } 467 }
463 return GNUNET_OK; 468 return GNUNET_OK;
464} 469}
465 470
@@ -475,9 +480,9 @@ copy_latest(void *cls,
475 * @return #GNUNET_SYSERR to end iteration, otherwise number of bytes written to @a buf 480 * @return #GNUNET_SYSERR to end iteration, otherwise number of bytes written to @a buf
476 */ 481 */
477static ssize_t 482static ssize_t
478merge_addr(void *cls, 483merge_addr (void *cls,
479 size_t max, 484 size_t max,
480 void *buf) 485 void *buf)
481{ 486{
482 struct MergeContext *mc = cls; 487 struct MergeContext *mc = cls;
483 488
@@ -489,17 +494,17 @@ merge_addr(void *cls,
489 mc->take_equal = GNUNET_NO; 494 mc->take_equal = GNUNET_NO;
490 mc->other = mc->h2; 495 mc->other = mc->h2;
491 /* copy addresses from h1, if strictly larger expiration than h2 */ 496 /* copy addresses from h1, if strictly larger expiration than h2 */
492 GNUNET_HELLO_iterate_addresses(mc->h1, 497 GNUNET_HELLO_iterate_addresses (mc->h1,
493 GNUNET_NO, 498 GNUNET_NO,
494 &copy_latest, 499 &copy_latest,
495 mc); 500 mc);
496 mc->take_equal = GNUNET_YES; 501 mc->take_equal = GNUNET_YES;
497 mc->other = mc->h1; 502 mc->other = mc->h1;
498 /* copy addresses from h2, if larger or equal expiration than h1 */ 503 /* copy addresses from h2, if larger or equal expiration than h1 */
499 GNUNET_HELLO_iterate_addresses(mc->h2, 504 GNUNET_HELLO_iterate_addresses (mc->h2,
500 GNUNET_NO, 505 GNUNET_NO,
501 &copy_latest, 506 &copy_latest,
502 mc); 507 mc);
503 /* set marker to stop iteration */ 508 /* set marker to stop iteration */
504 mc->h1 = NULL; 509 mc->h1 = NULL;
505 return mc->ret; 510 return mc->ret;
@@ -516,8 +521,8 @@ merge_addr(void *cls,
516 * @return the combined HELLO message 521 * @return the combined HELLO message
517 */ 522 */
518struct GNUNET_HELLO_Message * 523struct GNUNET_HELLO_Message *
519GNUNET_HELLO_merge(const struct GNUNET_HELLO_Message *h1, 524GNUNET_HELLO_merge (const struct GNUNET_HELLO_Message *h1,
520 const struct GNUNET_HELLO_Message *h2) 525 const struct GNUNET_HELLO_Message *h2)
521{ 526{
522 struct MergeContext mc = { h1, h2, NULL, NULL, 0, 0, 0 }; 527 struct MergeContext mc = { h1, h2, NULL, NULL, 0, 0, 0 };
523 int friend_only; 528 int friend_only;
@@ -525,12 +530,12 @@ GNUNET_HELLO_merge(const struct GNUNET_HELLO_Message *h1,
525 if (h1->friend_only != h2->friend_only) 530 if (h1->friend_only != h2->friend_only)
526 friend_only = GNUNET_YES; /* One of the HELLOs is friend only */ 531 friend_only = GNUNET_YES; /* One of the HELLOs is friend only */
527 else 532 else
528 friend_only = ntohl(h1->friend_only); /* Both HELLO's have the same type */ 533 friend_only = ntohl (h1->friend_only); /* Both HELLO's have the same type */
529 534
530 return GNUNET_HELLO_create(&h1->publicKey, 535 return GNUNET_HELLO_create (&h1->publicKey,
531 &merge_addr, 536 &merge_addr,
532 &mc, 537 &mc,
533 friend_only); 538 friend_only);
534} 539}
535 540
536 541
@@ -538,7 +543,8 @@ GNUNET_HELLO_merge(const struct GNUNET_HELLO_Message *h1,
538 * Context used in #GNUNET_HELLO_iterate_new_addresses() to 543 * Context used in #GNUNET_HELLO_iterate_new_addresses() to
539 * figure out which addresses are in fact 'new'. 544 * figure out which addresses are in fact 'new'.
540 */ 545 */
541struct DeltaContext { 546struct DeltaContext
547{
542 /** 548 /**
543 * We should ignore addresses that expire before this time. 549 * We should ignore addresses that expire before this time.
544 */ 550 */
@@ -575,9 +581,9 @@ struct DeltaContext {
575 * whatever the iterator returned. 581 * whatever the iterator returned.
576 */ 582 */
577static int 583static int
578delta_match(void *cls, 584delta_match (void *cls,
579 const struct GNUNET_HELLO_Address *address, 585 const struct GNUNET_HELLO_Address *address,
580 struct GNUNET_TIME_Absolute expiration) 586 struct GNUNET_TIME_Absolute expiration)
581{ 587{
582 struct DeltaContext *dc = cls; 588 struct DeltaContext *dc = cls;
583 int ret; 589 int ret;
@@ -585,17 +591,17 @@ delta_match(void *cls,
585 591
586 ec.address = address; 592 ec.address = address;
587 ec.found = GNUNET_NO; 593 ec.found = GNUNET_NO;
588 GNUNET_HELLO_iterate_addresses(dc->old_hello, 594 GNUNET_HELLO_iterate_addresses (dc->old_hello,
589 GNUNET_NO, 595 GNUNET_NO,
590 &get_match_exp, 596 &get_match_exp,
591 &ec); 597 &ec);
592 if ((GNUNET_YES == ec.found) && 598 if ((GNUNET_YES == ec.found) &&
593 ((ec.expiration.abs_value_us > expiration.abs_value_us) || 599 ((ec.expiration.abs_value_us > expiration.abs_value_us) ||
594 (ec.expiration.abs_value_us >= dc->expiration_limit.abs_value_us))) 600 (ec.expiration.abs_value_us >= dc->expiration_limit.abs_value_us)))
595 return GNUNET_YES; /* skip: found and boring */ 601 return GNUNET_YES; /* skip: found and boring */
596 ret = dc->it(dc->it_cls, 602 ret = dc->it (dc->it_cls,
597 address, 603 address,
598 expiration); 604 expiration);
599 return ret; 605 return ret;
600} 606}
601 607
@@ -614,11 +620,14 @@ delta_match(void *cls,
614 * @param it_cls closure for @a it 620 * @param it_cls closure for @a it
615 */ 621 */
616void 622void
617GNUNET_HELLO_iterate_new_addresses(const struct GNUNET_HELLO_Message *new_hello, 623GNUNET_HELLO_iterate_new_addresses (const struct
618 const struct GNUNET_HELLO_Message *old_hello, 624 GNUNET_HELLO_Message *new_hello,
619 struct GNUNET_TIME_Absolute expiration_limit, 625 const struct
620 GNUNET_HELLO_AddressIterator it, 626 GNUNET_HELLO_Message *old_hello,
621 void *it_cls) 627 struct GNUNET_TIME_Absolute
628 expiration_limit,
629 GNUNET_HELLO_AddressIterator it,
630 void *it_cls)
622{ 631{
623 struct DeltaContext dc; 632 struct DeltaContext dc;
624 633
@@ -626,11 +635,11 @@ GNUNET_HELLO_iterate_new_addresses(const struct GNUNET_HELLO_Message *new_hello,
626 dc.it = it; 635 dc.it = it;
627 dc.it_cls = it_cls; 636 dc.it_cls = it_cls;
628 dc.old_hello = old_hello; 637 dc.old_hello = old_hello;
629 GNUNET_assert(NULL == 638 GNUNET_assert (NULL ==
630 GNUNET_HELLO_iterate_addresses(new_hello, 639 GNUNET_HELLO_iterate_addresses (new_hello,
631 GNUNET_NO, 640 GNUNET_NO,
632 &delta_match, 641 &delta_match,
633 &dc)); 642 &dc));
634} 643}
635 644
636 645
@@ -640,12 +649,12 @@ GNUNET_HELLO_iterate_new_addresses(const struct GNUNET_HELLO_Message *new_hello,
640 * @return the size, 0 if HELLO is invalid 649 * @return the size, 0 if HELLO is invalid
641 */ 650 */
642uint16_t 651uint16_t
643GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello) 652GNUNET_HELLO_size (const struct GNUNET_HELLO_Message *hello)
644{ 653{
645 uint16_t ret = ntohs(hello->header.size); 654 uint16_t ret = ntohs (hello->header.size);
646 655
647 if ((ret < sizeof(struct GNUNET_HELLO_Message)) || 656 if ((ret < sizeof(struct GNUNET_HELLO_Message)) ||
648 (ntohs(hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) 657 (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
649 return 0; 658 return 0;
650 return ret; 659 return ret;
651} 660}
@@ -659,13 +668,13 @@ GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
659 * @return #GNUNET_SYSERR if the HELLO was malformed 668 * @return #GNUNET_SYSERR if the HELLO was malformed
660 */ 669 */
661int 670int
662GNUNET_HELLO_get_id(const struct GNUNET_HELLO_Message *hello, 671GNUNET_HELLO_get_id (const struct GNUNET_HELLO_Message *hello,
663 struct GNUNET_PeerIdentity *peer) 672 struct GNUNET_PeerIdentity *peer)
664{ 673{
665 uint16_t ret = ntohs(hello->header.size); 674 uint16_t ret = ntohs (hello->header.size);
666 675
667 if ((ret < sizeof(struct GNUNET_HELLO_Message)) || 676 if ((ret < sizeof(struct GNUNET_HELLO_Message)) ||
668 (ntohs(hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) 677 (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
669 return GNUNET_SYSERR; 678 return GNUNET_SYSERR;
670 peer->public_key = hello->publicKey; 679 peer->public_key = hello->publicKey;
671 return GNUNET_OK; 680 return GNUNET_OK;
@@ -681,12 +690,12 @@ GNUNET_HELLO_get_id(const struct GNUNET_HELLO_Message *hello,
681 * @return header or NULL if the HELLO was malformed 690 * @return header or NULL if the HELLO was malformed
682 */ 691 */
683struct GNUNET_MessageHeader * 692struct GNUNET_MessageHeader *
684GNUNET_HELLO_get_header(struct GNUNET_HELLO_Message *hello) 693GNUNET_HELLO_get_header (struct GNUNET_HELLO_Message *hello)
685{ 694{
686 uint16_t ret = ntohs(hello->header.size); 695 uint16_t ret = ntohs (hello->header.size);
687 696
688 if ((ret < sizeof(struct GNUNET_HELLO_Message)) || 697 if ((ret < sizeof(struct GNUNET_HELLO_Message)) ||
689 (ntohs(hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) 698 (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
690 return NULL; 699 return NULL;
691 700
692 return &hello->header; 701 return &hello->header;
@@ -696,7 +705,8 @@ GNUNET_HELLO_get_header(struct GNUNET_HELLO_Message *hello)
696/** 705/**
697 * Context used for comparing HELLOs in #GNUNET_HELLO_equals(). 706 * Context used for comparing HELLOs in #GNUNET_HELLO_equals().
698 */ 707 */
699struct EqualsContext { 708struct EqualsContext
709{
700 /** 710 /**
701 * Addresses that expired before this date are ignored for 711 * Addresses that expired before this date are ignored for
702 * the comparisson. 712 * the comparisson.
@@ -746,22 +756,22 @@ struct EqualsContext {
746 * #GNUNET_SYSERR if the address does match. 756 * #GNUNET_SYSERR if the address does match.
747 */ 757 */
748static int 758static int
749find_other_matching(void *cls, 759find_other_matching (void *cls,
750 const struct GNUNET_HELLO_Address *address, 760 const struct GNUNET_HELLO_Address *address,
751 struct GNUNET_TIME_Absolute expiration) 761 struct GNUNET_TIME_Absolute expiration)
752{ 762{
753 struct EqualsContext *ec = cls; 763 struct EqualsContext *ec = cls;
754 764
755 if (expiration.abs_value_us < ec->expiration_limit.abs_value_us) 765 if (expiration.abs_value_us < ec->expiration_limit.abs_value_us)
756 return GNUNET_YES; 766 return GNUNET_YES;
757 if (0 == GNUNET_HELLO_address_cmp(address, ec->address)) 767 if (0 == GNUNET_HELLO_address_cmp (address, ec->address))
758 { 768 {
759 ec->found = GNUNET_YES; 769 ec->found = GNUNET_YES;
760 if (expiration.abs_value_us < ec->expiration.abs_value_us) 770 if (expiration.abs_value_us < ec->expiration.abs_value_us)
761 ec->result = GNUNET_TIME_absolute_min(expiration, 771 ec->result = GNUNET_TIME_absolute_min (expiration,
762 ec->result); 772 ec->result);
763 return GNUNET_SYSERR; 773 return GNUNET_SYSERR;
764 } 774 }
765 return GNUNET_YES; 775 return GNUNET_YES;
766} 776}
767 777
@@ -779,9 +789,9 @@ find_other_matching(void *cls,
779 * #GNUNET_SYSERR if it was not found 789 * #GNUNET_SYSERR if it was not found
780 */ 790 */
781static int 791static int
782find_matching(void *cls, 792find_matching (void *cls,
783 const struct GNUNET_HELLO_Address *address, 793 const struct GNUNET_HELLO_Address *address,
784 struct GNUNET_TIME_Absolute expiration) 794 struct GNUNET_TIME_Absolute expiration)
785{ 795{
786 struct EqualsContext *ec = cls; 796 struct EqualsContext *ec = cls;
787 797
@@ -790,16 +800,16 @@ find_matching(void *cls,
790 ec->address = address; 800 ec->address = address;
791 ec->expiration = expiration; 801 ec->expiration = expiration;
792 ec->found = GNUNET_NO; 802 ec->found = GNUNET_NO;
793 GNUNET_HELLO_iterate_addresses(ec->ref, 803 GNUNET_HELLO_iterate_addresses (ec->ref,
794 GNUNET_NO, 804 GNUNET_NO,
795 &find_other_matching, 805 &find_other_matching,
796 ec); 806 ec);
797 if (GNUNET_NO == ec->found) 807 if (GNUNET_NO == ec->found)
798 { 808 {
799 /* not found, we differ *now* */ 809 /* not found, we differ *now* */
800 ec->result = GNUNET_TIME_UNIT_ZERO_ABS; 810 ec->result = GNUNET_TIME_UNIT_ZERO_ABS;
801 return GNUNET_SYSERR; 811 return GNUNET_SYSERR;
802 } 812 }
803 return GNUNET_OK; 813 return GNUNET_OK;
804} 814}
805 815
@@ -821,32 +831,32 @@ find_matching(void *cls,
821 * do not match at all 831 * do not match at all
822 */ 832 */
823struct GNUNET_TIME_Absolute 833struct GNUNET_TIME_Absolute
824GNUNET_HELLO_equals(const struct GNUNET_HELLO_Message *h1, 834GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1,
825 const struct GNUNET_HELLO_Message *h2, 835 const struct GNUNET_HELLO_Message *h2,
826 struct GNUNET_TIME_Absolute now) 836 struct GNUNET_TIME_Absolute now)
827{ 837{
828 struct EqualsContext ec; 838 struct EqualsContext ec;
829 839
830 if (h1->header.type != h2->header.type) 840 if (h1->header.type != h2->header.type)
831 return GNUNET_TIME_UNIT_ZERO_ABS; 841 return GNUNET_TIME_UNIT_ZERO_ABS;
832 if (0 != 842 if (0 !=
833 GNUNET_memcmp(&h1->publicKey, 843 GNUNET_memcmp (&h1->publicKey,
834 &h2->publicKey)) 844 &h2->publicKey))
835 return GNUNET_TIME_UNIT_ZERO_ABS; 845 return GNUNET_TIME_UNIT_ZERO_ABS;
836 ec.expiration_limit = now; 846 ec.expiration_limit = now;
837 ec.result = GNUNET_TIME_UNIT_FOREVER_ABS; 847 ec.result = GNUNET_TIME_UNIT_FOREVER_ABS;
838 ec.ref = h2; 848 ec.ref = h2;
839 GNUNET_HELLO_iterate_addresses(h1, 849 GNUNET_HELLO_iterate_addresses (h1,
840 GNUNET_NO, 850 GNUNET_NO,
841 &find_matching, 851 &find_matching,
842 &ec); 852 &ec);
843 if (ec.result.abs_value_us == GNUNET_TIME_UNIT_ZERO.rel_value_us) 853 if (ec.result.abs_value_us == GNUNET_TIME_UNIT_ZERO.rel_value_us)
844 return ec.result; 854 return ec.result;
845 ec.ref = h1; 855 ec.ref = h1;
846 GNUNET_HELLO_iterate_addresses(h2, 856 GNUNET_HELLO_iterate_addresses (h2,
847 GNUNET_NO, 857 GNUNET_NO,
848 &find_matching, 858 &find_matching,
849 &ec); 859 &ec);
850 return ec.result; 860 return ec.result;
851} 861}
852 862
@@ -861,13 +871,13 @@ GNUNET_HELLO_equals(const struct GNUNET_HELLO_Message *h1,
861 * @return #GNUNET_OK (always) 871 * @return #GNUNET_OK (always)
862 */ 872 */
863static int 873static int
864find_max_expire(void *cls, 874find_max_expire (void *cls,
865 const struct GNUNET_HELLO_Address *address, 875 const struct GNUNET_HELLO_Address *address,
866 struct GNUNET_TIME_Absolute expiration) 876 struct GNUNET_TIME_Absolute expiration)
867{ 877{
868 struct GNUNET_TIME_Absolute *max = cls; 878 struct GNUNET_TIME_Absolute *max = cls;
869 879
870 *max = GNUNET_TIME_absolute_max(*max, expiration); 880 *max = GNUNET_TIME_absolute_max (*max, expiration);
871 return GNUNET_OK; 881 return GNUNET_OK;
872} 882}
873 883
@@ -879,15 +889,15 @@ find_max_expire(void *cls,
879 * @return time the last address expires, 0 if there are no addresses in the HELLO 889 * @return time the last address expires, 0 if there are no addresses in the HELLO
880 */ 890 */
881struct GNUNET_TIME_Absolute 891struct GNUNET_TIME_Absolute
882GNUNET_HELLO_get_last_expiration(const struct GNUNET_HELLO_Message *msg) 892GNUNET_HELLO_get_last_expiration (const struct GNUNET_HELLO_Message *msg)
883{ 893{
884 struct GNUNET_TIME_Absolute ret; 894 struct GNUNET_TIME_Absolute ret;
885 895
886 ret = GNUNET_TIME_UNIT_ZERO_ABS; 896 ret = GNUNET_TIME_UNIT_ZERO_ABS;
887 GNUNET_HELLO_iterate_addresses(msg, 897 GNUNET_HELLO_iterate_addresses (msg,
888 GNUNET_NO, 898 GNUNET_NO,
889 &find_max_expire, 899 &find_max_expire,
890 &ret); 900 &ret);
891 return ret; 901 return ret;
892} 902}
893 903
@@ -946,9 +956,9 @@ GNUNET_HELLO_get_last_expiration(const struct GNUNET_HELLO_Message *msg)
946 * @return #GNUNET_OK (continue iteration). 956 * @return #GNUNET_OK (continue iteration).
947 */ 957 */
948static int 958static int
949add_address_to_uri(void *cls, 959add_address_to_uri (void *cls,
950 const struct GNUNET_HELLO_Address *address, 960 const struct GNUNET_HELLO_Address *address,
951 struct GNUNET_TIME_Absolute expiration) 961 struct GNUNET_TIME_Absolute expiration)
952{ 962{
953 struct GNUNET_HELLO_ComposeUriContext *ctx = cls; 963 struct GNUNET_HELLO_ComposeUriContext *ctx = cls;
954 struct GNUNET_TRANSPORT_PluginFunctions *papi; 964 struct GNUNET_TRANSPORT_PluginFunctions *papi;
@@ -961,49 +971,49 @@ add_address_to_uri(void *cls,
961 struct tm *t; 971 struct tm *t;
962 time_t seconds; 972 time_t seconds;
963 973
964 papi = ctx->plugins_find(address->transport_name); 974 papi = ctx->plugins_find (address->transport_name);
965 if (NULL == papi) 975 if (NULL == papi)
966 { 976 {
967 /* Not an error - we might just not have the right plugin. */ 977 /* Not an error - we might just not have the right plugin. */
968 return GNUNET_OK; 978 return GNUNET_OK;
969 } 979 }
970 if (NULL == papi->address_to_string) 980 if (NULL == papi->address_to_string)
971 { 981 {
972 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 982 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
973 "URI conversion not implemented for plugin `%s'\n", 983 "URI conversion not implemented for plugin `%s'\n",
974 address->transport_name); 984 address->transport_name);
975 return GNUNET_OK; 985 return GNUNET_OK;
976 } 986 }
977 addr = papi->address_to_string(papi->cls, 987 addr = papi->address_to_string (papi->cls,
978 address->address, 988 address->address,
979 address->address_length); 989 address->address_length);
980 if ((NULL == addr) || 990 if ((NULL == addr) ||
981 (0 == strlen(addr))) 991 (0 == strlen (addr)))
982 return GNUNET_OK; 992 return GNUNET_OK;
983 993
984 addr_dup = GNUNET_strdup(addr); 994 addr_dup = GNUNET_strdup (addr);
985 if (NULL != (pos = strstr(addr_dup, "_server"))) 995 if (NULL != (pos = strstr (addr_dup, "_server")))
986 GNUNET_memcpy(pos, 996 GNUNET_memcpy (pos,
987 client_str, 997 client_str,
988 strlen(client_str)); /* Replace all server addresses with client addresses */ 998 strlen (client_str)); /* Replace all server addresses with client addresses */
989 999
990 seconds = expiration.abs_value_us / 1000LL / 1000LL; 1000 seconds = expiration.abs_value_us / 1000LL / 1000LL;
991 t = gmtime(&seconds); 1001 t = gmtime (&seconds);
992 1002
993 GNUNET_asprintf(&ret, 1003 GNUNET_asprintf (&ret,
994 "%s%c%s%c%s%c%s", 1004 "%s%c%s%c%s%c%s",
995 ctx->uri, 1005 ctx->uri,
996 GNUNET_HELLO_URI_SEP, 1006 GNUNET_HELLO_URI_SEP,
997 strftime(tbuf, 1007 strftime (tbuf,
998 sizeof(tbuf), 1008 sizeof(tbuf),
999 "%Y%m%d%H%M%S", 1009 "%Y%m%d%H%M%S",
1000 t) ? tbuf : "0", 1010 t) ? tbuf : "0",
1001 GNUNET_HELLO_URI_SEP, 1011 GNUNET_HELLO_URI_SEP,
1002 address->transport_name, 1012 address->transport_name,
1003 GNUNET_HELLO_URI_SEP, 1013 GNUNET_HELLO_URI_SEP,
1004 addr_dup); 1014 addr_dup);
1005 GNUNET_free(addr_dup); 1015 GNUNET_free (addr_dup);
1006 GNUNET_free(ctx->uri); 1016 GNUNET_free (ctx->uri);
1007 ctx->uri = ret; 1017 ctx->uri = ret;
1008 return GNUNET_OK; 1018 return GNUNET_OK;
1009} 1019}
@@ -1017,25 +1027,25 @@ add_address_to_uri(void *cls,
1017 * @return Hello URI string 1027 * @return Hello URI string
1018 */ 1028 */
1019char * 1029char *
1020GNUNET_HELLO_compose_uri(const struct GNUNET_HELLO_Message *hello, 1030GNUNET_HELLO_compose_uri (const struct GNUNET_HELLO_Message *hello,
1021 GNUNET_HELLO_TransportPluginsFind plugins_find) 1031 GNUNET_HELLO_TransportPluginsFind plugins_find)
1022{ 1032{
1023 struct GNUNET_HELLO_ComposeUriContext ctx; 1033 struct GNUNET_HELLO_ComposeUriContext ctx;
1024 char *pkey; 1034 char *pkey;
1025 1035
1026 ctx.plugins_find = plugins_find; 1036 ctx.plugins_find = plugins_find;
1027 pkey = GNUNET_CRYPTO_eddsa_public_key_to_string(&hello->publicKey); 1037 pkey = GNUNET_CRYPTO_eddsa_public_key_to_string (&hello->publicKey);
1028 GNUNET_asprintf(&ctx.uri, 1038 GNUNET_asprintf (&ctx.uri,
1029 "%s%s", 1039 "%s%s",
1030 (GNUNET_YES == GNUNET_HELLO_is_friend_only(hello)) 1040 (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello))
1031 ? GNUNET_FRIEND_HELLO_URI_PREFIX 1041 ? GNUNET_FRIEND_HELLO_URI_PREFIX
1032 : GNUNET_HELLO_URI_PREFIX, 1042 : GNUNET_HELLO_URI_PREFIX,
1033 pkey); 1043 pkey);
1034 GNUNET_free(pkey); 1044 GNUNET_free (pkey);
1035 GNUNET_HELLO_iterate_addresses(hello, 1045 GNUNET_HELLO_iterate_addresses (hello,
1036 GNUNET_NO, 1046 GNUNET_NO,
1037 &add_address_to_uri, 1047 &add_address_to_uri,
1038 &ctx); 1048 &ctx);
1039 return ctx.uri; 1049 return ctx.uri;
1040} 1050}
1041 1051
@@ -1053,9 +1063,9 @@ GNUNET_HELLO_compose_uri(const struct GNUNET_HELLO_Message *hello,
1053 * @return number of bytes added to buffer, #GNUNET_SYSERR on error 1063 * @return number of bytes added to buffer, #GNUNET_SYSERR on error
1054 */ 1064 */
1055static ssize_t 1065static ssize_t
1056add_address_to_hello(void *cls, 1066add_address_to_hello (void *cls,
1057 size_t max, 1067 size_t max,
1058 void *buffer) 1068 void *buffer)
1059{ 1069{
1060 struct GNUNET_HELLO_ParseUriContext *ctx = cls; 1070 struct GNUNET_HELLO_ParseUriContext *ctx = cls;
1061 const char *tname; 1071 const char *tname;
@@ -1075,119 +1085,122 @@ add_address_to_hello(void *cls,
1075 if (NULL == ctx->pos) 1085 if (NULL == ctx->pos)
1076 return GNUNET_SYSERR; 1086 return GNUNET_SYSERR;
1077 if (GNUNET_HELLO_URI_SEP != ctx->pos[0]) 1087 if (GNUNET_HELLO_URI_SEP != ctx->pos[0])
1078 { 1088 {
1079 ctx->ret = GNUNET_SYSERR; 1089 ctx->ret = GNUNET_SYSERR;
1080 GNUNET_break(0); 1090 GNUNET_break (0);
1081 return GNUNET_SYSERR; 1091 return GNUNET_SYSERR;
1082 } 1092 }
1083 ctx->pos++; 1093 ctx->pos++;
1084 1094
1085 if (('0' == ctx->pos[0]) && 1095 if (('0' == ctx->pos[0]) &&
1086 (GNUNET_HELLO_URI_SEP == ctx->pos[1])) 1096 (GNUNET_HELLO_URI_SEP == ctx->pos[1]))
1087 { 1097 {
1088 expire = GNUNET_TIME_UNIT_FOREVER_ABS; 1098 expire = GNUNET_TIME_UNIT_FOREVER_ABS;
1089 tname = ctx->pos + 1; 1099 tname = ctx->pos + 1;
1090 } 1100 }
1091 else 1101 else
1102 {
1103 memset (&expiration_time, 0, sizeof(expiration_time));
1104 tname = strptime (ctx->pos,
1105 "%Y%m%d%H%M%S",
1106 &expiration_time);
1107 if (NULL == tname)
1092 { 1108 {
1093 memset(&expiration_time, 0, sizeof(expiration_time));
1094 tname = strptime(ctx->pos,
1095 "%Y%m%d%H%M%S",
1096 &expiration_time);
1097 if (NULL == tname)
1098 {
1099 ctx->ret = GNUNET_SYSERR;
1100 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1101 _("Failed to parse HELLO message: missing expiration time\n"));
1102 GNUNET_break(0);
1103 return GNUNET_SYSERR;
1104 }
1105
1106 expiration_seconds = mktime(&expiration_time);
1107 if (expiration_seconds == (time_t)-1)
1108 {
1109 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1110 _("Failed to parse HELLO message: invalid expiration time\n"));
1111 ctx->ret = GNUNET_SYSERR;
1112 GNUNET_break(0);
1113 return GNUNET_SYSERR;
1114 }
1115 expire.abs_value_us = expiration_seconds * 1000LL * 1000LL;
1116 }
1117 if (GNUNET_HELLO_URI_SEP != tname[0])
1118 {
1119 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1120 _("Failed to parse HELLO message: malformed\n"));
1121 ctx->ret = GNUNET_SYSERR; 1109 ctx->ret = GNUNET_SYSERR;
1122 GNUNET_break(0); 1110 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1111 _ (
1112 "Failed to parse HELLO message: missing expiration time\n"));
1113 GNUNET_break (0);
1123 return GNUNET_SYSERR; 1114 return GNUNET_SYSERR;
1124 } 1115 }
1125 tname++; 1116
1126 address = strchr(tname, 1117 expiration_seconds = mktime (&expiration_time);
1127 (int)GNUNET_HELLO_URI_SEP); 1118 if (expiration_seconds == (time_t) -1)
1128 if (NULL == address)
1129 { 1119 {
1130 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1120 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1131 _("Failed to parse HELLO message: missing transport plugin\n")); 1121 _ (
1122 "Failed to parse HELLO message: invalid expiration time\n"));
1132 ctx->ret = GNUNET_SYSERR; 1123 ctx->ret = GNUNET_SYSERR;
1133 GNUNET_break(0); 1124 GNUNET_break (0);
1134 return GNUNET_SYSERR; 1125 return GNUNET_SYSERR;
1135 } 1126 }
1127 expire.abs_value_us = expiration_seconds * 1000LL * 1000LL;
1128 }
1129 if (GNUNET_HELLO_URI_SEP != tname[0])
1130 {
1131 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1132 _ ("Failed to parse HELLO message: malformed\n"));
1133 ctx->ret = GNUNET_SYSERR;
1134 GNUNET_break (0);
1135 return GNUNET_SYSERR;
1136 }
1137 tname++;
1138 address = strchr (tname,
1139 (int) GNUNET_HELLO_URI_SEP);
1140 if (NULL == address)
1141 {
1142 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1143 _ (
1144 "Failed to parse HELLO message: missing transport plugin\n"));
1145 ctx->ret = GNUNET_SYSERR;
1146 GNUNET_break (0);
1147 return GNUNET_SYSERR;
1148 }
1136 address++; 1149 address++;
1137 end = strchr(address, (int)GNUNET_HELLO_URI_SEP); 1150 end = strchr (address, (int) GNUNET_HELLO_URI_SEP);
1138 ctx->pos = end; 1151 ctx->pos = end;
1139 ctx->counter_total++; 1152 ctx->counter_total++;
1140 plugin_name = GNUNET_strndup(tname, address - (tname + 1)); 1153 plugin_name = GNUNET_strndup (tname, address - (tname + 1));
1141 papi = ctx->plugins_find(plugin_name); 1154 papi = ctx->plugins_find (plugin_name);
1142 if (NULL == papi) 1155 if (NULL == papi)
1143 { 1156 {
1144 /* Not an error - we might just not have the right plugin. 1157 /* Not an error - we might just not have the right plugin.
1145 * Skip this part, advance to the next one and recurse. 1158 * Skip this part, advance to the next one and recurse.
1146 * But only if this is not the end of string. 1159 * But only if this is not the end of string.
1147 */ 1160 */
1148 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1161 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1149 _("Plugin `%s' not found, skipping address\n"), 1162 _ ("Plugin `%s' not found, skipping address\n"),
1150 plugin_name); 1163 plugin_name);
1151 GNUNET_free(plugin_name); 1164 GNUNET_free (plugin_name);
1152 return 0; 1165 return 0;
1153 } 1166 }
1154 if (NULL == papi->string_to_address) 1167 if (NULL == papi->string_to_address)
1155 { 1168 {
1156 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1169 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1157 _("Plugin `%s' does not support URIs yet\n"), 1170 _ ("Plugin `%s' does not support URIs yet\n"),
1158 plugin_name); 1171 plugin_name);
1159 GNUNET_free(plugin_name); 1172 GNUNET_free (plugin_name);
1160 GNUNET_break(0); 1173 GNUNET_break (0);
1161 return 0; 1174 return 0;
1162 } 1175 }
1163 uri_address = GNUNET_strndup(address, end - address); 1176 uri_address = GNUNET_strndup (address, end - address);
1164 if (GNUNET_OK != 1177 if (GNUNET_OK !=
1165 papi->string_to_address(papi->cls, 1178 papi->string_to_address (papi->cls,
1166 uri_address, 1179 uri_address,
1167 strlen(uri_address) + 1, 1180 strlen (uri_address) + 1,
1168 &addr, 1181 &addr,
1169 &addr_len)) 1182 &addr_len))
1170 { 1183 {
1171 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1184 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1172 _("Failed to parse `%s' as an address for plugin `%s'\n"), 1185 _ ("Failed to parse `%s' as an address for plugin `%s'\n"),
1173 uri_address, 1186 uri_address,
1174 plugin_name); 1187 plugin_name);
1175 GNUNET_free(plugin_name); 1188 GNUNET_free (plugin_name);
1176 GNUNET_free(uri_address); 1189 GNUNET_free (uri_address);
1177 return 0; 1190 return 0;
1178 } 1191 }
1179 GNUNET_free(uri_address); 1192 GNUNET_free (uri_address);
1180 /* address.peer is unset - not used by add_address() */ 1193 /* address.peer is unset - not used by add_address() */
1181 haddr.address_length = addr_len; 1194 haddr.address_length = addr_len;
1182 haddr.address = addr; 1195 haddr.address = addr;
1183 haddr.transport_name = plugin_name; 1196 haddr.transport_name = plugin_name;
1184 ret = GNUNET_HELLO_add_address(&haddr, 1197 ret = GNUNET_HELLO_add_address (&haddr,
1185 expire, 1198 expire,
1186 buffer, 1199 buffer,
1187 max); 1200 max);
1188 ctx->counter_added++; 1201 ctx->counter_added++;
1189 GNUNET_free(addr); 1202 GNUNET_free (addr);
1190 GNUNET_free(plugin_name); 1203 GNUNET_free (plugin_name);
1191 return ret; 1204 return ret;
1192} 1205}
1193 1206
@@ -1202,39 +1215,39 @@ add_address_to_hello(void *cls,
1202 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the URI was invalid, #GNUNET_NO on other errors 1215 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the URI was invalid, #GNUNET_NO on other errors
1203 */ 1216 */
1204int 1217int
1205GNUNET_HELLO_parse_uri(const char *uri, 1218GNUNET_HELLO_parse_uri (const char *uri,
1206 struct GNUNET_CRYPTO_EddsaPublicKey *pubkey, 1219 struct GNUNET_CRYPTO_EddsaPublicKey *pubkey,
1207 struct GNUNET_HELLO_Message **hello, 1220 struct GNUNET_HELLO_Message **hello,
1208 GNUNET_HELLO_TransportPluginsFind plugins_find) 1221 GNUNET_HELLO_TransportPluginsFind plugins_find)
1209{ 1222{
1210 const char *pks; 1223 const char *pks;
1211 const char *exc; 1224 const char *exc;
1212 int friend_only; 1225 int friend_only;
1213 struct GNUNET_HELLO_ParseUriContext ctx; 1226 struct GNUNET_HELLO_ParseUriContext ctx;
1214 1227
1215 if (0 == strncmp(uri, 1228 if (0 == strncmp (uri,
1216 GNUNET_HELLO_URI_PREFIX, 1229 GNUNET_HELLO_URI_PREFIX,
1217 strlen(GNUNET_HELLO_URI_PREFIX))) 1230 strlen (GNUNET_HELLO_URI_PREFIX)))
1218 { 1231 {
1219 pks = &uri[strlen(GNUNET_HELLO_URI_PREFIX)]; 1232 pks = &uri[strlen (GNUNET_HELLO_URI_PREFIX)];
1220 friend_only = GNUNET_NO; 1233 friend_only = GNUNET_NO;
1221 } 1234 }
1222 else if (0 == strncmp(uri, 1235 else if (0 == strncmp (uri,
1223 GNUNET_FRIEND_HELLO_URI_PREFIX, 1236 GNUNET_FRIEND_HELLO_URI_PREFIX,
1224 strlen(GNUNET_FRIEND_HELLO_URI_PREFIX))) 1237 strlen (GNUNET_FRIEND_HELLO_URI_PREFIX)))
1225 { 1238 {
1226 pks = &uri[strlen(GNUNET_FRIEND_HELLO_URI_PREFIX)]; 1239 pks = &uri[strlen (GNUNET_FRIEND_HELLO_URI_PREFIX)];
1227 friend_only = GNUNET_YES; 1240 friend_only = GNUNET_YES;
1228 } 1241 }
1229 else 1242 else
1230 return GNUNET_SYSERR; 1243 return GNUNET_SYSERR;
1231 exc = strchr(pks, GNUNET_HELLO_URI_SEP); 1244 exc = strchr (pks, GNUNET_HELLO_URI_SEP);
1232 1245
1233 if (GNUNET_OK != 1246 if (GNUNET_OK !=
1234 GNUNET_STRINGS_string_to_data(pks, 1247 GNUNET_STRINGS_string_to_data (pks,
1235 (NULL == exc) ? strlen(pks) : (exc - pks), 1248 (NULL == exc) ? strlen (pks) : (exc - pks),
1236 (unsigned char *)pubkey, 1249 (unsigned char *) pubkey,
1237 sizeof(*pubkey))) 1250 sizeof(*pubkey)))
1238 return GNUNET_SYSERR; 1251 return GNUNET_SYSERR;
1239 1252
1240 ctx.pos = exc; 1253 ctx.pos = exc;
@@ -1242,15 +1255,15 @@ GNUNET_HELLO_parse_uri(const char *uri,
1242 ctx.counter_total = 0; 1255 ctx.counter_total = 0;
1243 ctx.counter_added = 0; 1256 ctx.counter_added = 0;
1244 ctx.plugins_find = plugins_find; 1257 ctx.plugins_find = plugins_find;
1245 *hello = GNUNET_HELLO_create(pubkey, 1258 *hello = GNUNET_HELLO_create (pubkey,
1246 &add_address_to_hello, 1259 &add_address_to_hello,
1247 &ctx, 1260 &ctx,
1248 friend_only); 1261 friend_only);
1249 1262
1250 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1251 "HELLO URI contained %u addresses, added %u addresses\n", 1264 "HELLO URI contained %u addresses, added %u addresses\n",
1252 ctx.counter_total, 1265 ctx.counter_total,
1253 ctx.counter_added); 1266 ctx.counter_added);
1254 1267
1255 return ctx.ret; 1268 return ctx.ret;
1256} 1269}
diff --git a/src/hello/test_friend_hello.c b/src/hello/test_friend_hello.c
index 7cbb019c6..1b092c0b8 100644
--- a/src/hello/test_friend_hello.c
+++ b/src/hello/test_friend_hello.c
@@ -27,73 +27,73 @@
27 27
28 28
29static ssize_t 29static ssize_t
30my_addr_gen(void *cls, 30my_addr_gen (void *cls,
31 size_t max, 31 size_t max,
32 void *buf) 32 void *buf)
33{ 33{
34 unsigned int *i = cls; 34 unsigned int *i = cls;
35 size_t ret; 35 size_t ret;
36 struct GNUNET_HELLO_Address address; 36 struct GNUNET_HELLO_Address address;
37 37
38 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 38 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
39 "DEBUG: my_addr_gen called with i = %d\n", *i); 39 "DEBUG: my_addr_gen called with i = %d\n", *i);
40 if (0 == *i) 40 if (0 == *i)
41 return GNUNET_SYSERR; /* Stop iteration */ 41 return GNUNET_SYSERR; /* Stop iteration */
42 memset(&address.peer, 0, sizeof(struct GNUNET_PeerIdentity)); 42 memset (&address.peer, 0, sizeof(struct GNUNET_PeerIdentity));
43 address.address = "address_information"; 43 address.address = "address_information";
44 address.transport_name = "test"; 44 address.transport_name = "test";
45 address.address_length = *i; 45 address.address_length = *i;
46 ret = 46 ret =
47 GNUNET_HELLO_add_address(&address, GNUNET_TIME_absolute_get(), buf, 47 GNUNET_HELLO_add_address (&address, GNUNET_TIME_absolute_get (), buf,
48 max); 48 max);
49 (*i)--; 49 (*i)--;
50 return ret; 50 return ret;
51} 51}
52 52
53 53
54static int 54static int
55check_addr(void *cls, 55check_addr (void *cls,
56 const struct GNUNET_HELLO_Address *address, 56 const struct GNUNET_HELLO_Address *address,
57 struct GNUNET_TIME_Absolute expiration) 57 struct GNUNET_TIME_Absolute expiration)
58{ 58{
59 unsigned int *i = cls; 59 unsigned int *i = cls;
60 60
61 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 61 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
62 "DEBUG: check_addr called with i = %d and addrlen = %u\n", 62 "DEBUG: check_addr called with i = %d and addrlen = %u\n",
63 *i, (unsigned int)address->address_length); 63 *i, (unsigned int) address->address_length);
64 GNUNET_assert(address->address_length > 0); 64 GNUNET_assert (address->address_length > 0);
65 GNUNET_assert(*i & (1 << (address->address_length - 1))); 65 GNUNET_assert (*i & (1 << (address->address_length - 1)));
66 *i -= (1 << (address->address_length - 1)); 66 *i -= (1 << (address->address_length - 1));
67 GNUNET_assert(0 == 67 GNUNET_assert (0 ==
68 strncmp("address_information", address->address, 68 strncmp ("address_information", address->address,
69 address->address_length)); 69 address->address_length));
70 GNUNET_assert(0 == strcmp("test", address->transport_name)); 70 GNUNET_assert (0 == strcmp ("test", address->transport_name));
71 return GNUNET_OK; 71 return GNUNET_OK;
72} 72}
73 73
74 74
75static int 75static int
76remove_some(void *cls, 76remove_some (void *cls,
77 const struct GNUNET_HELLO_Address *address, 77 const struct GNUNET_HELLO_Address *address,
78 struct GNUNET_TIME_Absolute expiration) 78 struct GNUNET_TIME_Absolute expiration)
79{ 79{
80 unsigned int *i = cls; 80 unsigned int *i = cls;
81 81
82 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
83 "DEBUG: remove_some called with i = %d and addrlen = %u\n", 83 "DEBUG: remove_some called with i = %d and addrlen = %u\n",
84 *i, (unsigned int)address->address_length); 84 *i, (unsigned int) address->address_length);
85 GNUNET_assert(address->address_length > 0); 85 GNUNET_assert (address->address_length > 0);
86 if (*i & (1 << (address->address_length - 1))) 86 if (*i & (1 << (address->address_length - 1)))
87 { 87 {
88 *i -= (1 << (address->address_length - 1)); 88 *i -= (1 << (address->address_length - 1));
89 return GNUNET_NO; 89 return GNUNET_NO;
90 } 90 }
91 return GNUNET_OK; 91 return GNUNET_OK;
92} 92}
93 93
94 94
95int 95int
96main(int argc, char *argv[]) 96main (int argc, char *argv[])
97{ 97{
98 struct GNUNET_HELLO_Message *msg1; 98 struct GNUNET_HELLO_Message *msg1;
99 struct GNUNET_HELLO_Message *msg2; 99 struct GNUNET_HELLO_Message *msg2;
@@ -102,84 +102,84 @@ main(int argc, char *argv[])
102 struct GNUNET_TIME_Absolute startup_time; 102 struct GNUNET_TIME_Absolute startup_time;
103 unsigned int i; 103 unsigned int i;
104 104
105 GNUNET_log_setup("test-hello", "DEBUG", NULL); 105 GNUNET_log_setup ("test-hello", "DEBUG", NULL);
106 startup_time = GNUNET_TIME_absolute_get(); 106 startup_time = GNUNET_TIME_absolute_get ();
107 memset(&publicKey, 42, sizeof(publicKey)); 107 memset (&publicKey, 42, sizeof(publicKey));
108 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
109 "Testing HELLO creation (without addresses)...\n"); 109 "Testing HELLO creation (without addresses)...\n");
110 i = 0; 110 i = 0;
111 msg1 = GNUNET_HELLO_create(&publicKey, &my_addr_gen, &i, GNUNET_YES); 111 msg1 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i, GNUNET_YES);
112 GNUNET_assert(msg1 != NULL); 112 GNUNET_assert (msg1 != NULL);
113 GNUNET_assert(0 < GNUNET_HELLO_size(msg1)); 113 GNUNET_assert (0 < GNUNET_HELLO_size (msg1));
114 114
115 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
116 "Testing address iteration (empty set)...\n"); 116 "Testing address iteration (empty set)...\n");
117 GNUNET_assert(NULL == 117 GNUNET_assert (NULL ==
118 GNUNET_HELLO_iterate_addresses(msg1, GNUNET_NO, &check_addr, 118 GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr,
119 &i)); 119 &i));
120 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
121 "Testing HELLO creation (with one address)...\n"); 121 "Testing HELLO creation (with one address)...\n");
122 i = 1; 122 i = 1;
123 msg2 = GNUNET_HELLO_create(&publicKey, &my_addr_gen, &i, GNUNET_YES); 123 msg2 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i, GNUNET_YES);
124 GNUNET_assert(msg2 != NULL); 124 GNUNET_assert (msg2 != NULL);
125 GNUNET_assert(GNUNET_HELLO_size(msg1) < GNUNET_HELLO_size(msg2)); 125 GNUNET_assert (GNUNET_HELLO_size (msg1) < GNUNET_HELLO_size (msg2));
126 126
127 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 127 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
128 "Testing address iteration (one address)...\n"); 128 "Testing address iteration (one address)...\n");
129 i = 1; 129 i = 1;
130 GNUNET_assert(NULL == 130 GNUNET_assert (NULL ==
131 GNUNET_HELLO_iterate_addresses(msg2, GNUNET_NO, &check_addr, 131 GNUNET_HELLO_iterate_addresses (msg2, GNUNET_NO, &check_addr,
132 &i)); 132 &i));
133 GNUNET_assert(i == 0); 133 GNUNET_assert (i == 0);
134 GNUNET_free(msg1); 134 GNUNET_free (msg1);
135 135
136 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 136 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
137 "Testing HELLO creation (with two addresses)...\n"); 137 "Testing HELLO creation (with two addresses)...\n");
138 i = 2; 138 i = 2;
139 msg3 = GNUNET_HELLO_create(&publicKey, &my_addr_gen, &i, GNUNET_YES); 139 msg3 = GNUNET_HELLO_create (&publicKey, &my_addr_gen, &i, GNUNET_YES);
140 GNUNET_assert(msg3 != NULL); 140 GNUNET_assert (msg3 != NULL);
141 GNUNET_assert(GNUNET_HELLO_size(msg2) < GNUNET_HELLO_size(msg3)); 141 GNUNET_assert (GNUNET_HELLO_size (msg2) < GNUNET_HELLO_size (msg3));
142 142
143 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
144 "Testing address iteration (two addresses)...\n"); 144 "Testing address iteration (two addresses)...\n");
145 i = 3; 145 i = 3;
146 GNUNET_assert(NULL == 146 GNUNET_assert (NULL ==
147 GNUNET_HELLO_iterate_addresses(msg3, GNUNET_NO, &check_addr, 147 GNUNET_HELLO_iterate_addresses (msg3, GNUNET_NO, &check_addr,
148 &i)); 148 &i));
149 GNUNET_assert(i == 0); 149 GNUNET_assert (i == 0);
150 150
151 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
152 "Testing HELLO merge...\n"); 152 "Testing HELLO merge...\n");
153 msg1 = GNUNET_HELLO_merge(msg2, msg3); 153 msg1 = GNUNET_HELLO_merge (msg2, msg3);
154 GNUNET_assert(GNUNET_HELLO_size(msg1) == GNUNET_HELLO_size(msg3)); 154 GNUNET_assert (GNUNET_HELLO_size (msg1) == GNUNET_HELLO_size (msg3));
155 155
156 i = 3; 156 i = 3;
157 GNUNET_assert(NULL == 157 GNUNET_assert (NULL ==
158 GNUNET_HELLO_iterate_addresses(msg1, GNUNET_NO, &check_addr, 158 GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr,
159 &i)); 159 &i));
160 GNUNET_assert(i == 0); 160 GNUNET_assert (i == 0);
161 GNUNET_free(msg1); 161 GNUNET_free (msg1);
162 162
163 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
164 "Testing address iteration to copy HELLO...\n"); 164 "Testing address iteration to copy HELLO...\n");
165 i = 2; 165 i = 2;
166 msg1 = GNUNET_HELLO_iterate_addresses(msg3, GNUNET_YES, &remove_some, &i); 166 msg1 = GNUNET_HELLO_iterate_addresses (msg3, GNUNET_YES, &remove_some, &i);
167 GNUNET_assert(msg1 != NULL); 167 GNUNET_assert (msg1 != NULL);
168 GNUNET_assert(i == 0); 168 GNUNET_assert (i == 0);
169 i = 1; 169 i = 1;
170 GNUNET_assert(NULL == 170 GNUNET_assert (NULL ==
171 GNUNET_HELLO_iterate_addresses(msg1, GNUNET_NO, &check_addr, 171 GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr,
172 &i)); 172 &i));
173 GNUNET_assert(i == 0); 173 GNUNET_assert (i == 0);
174 GNUNET_free(msg1); 174 GNUNET_free (msg1);
175 175
176 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
177 "Testing delta address iteration...\n"); 177 "Testing delta address iteration...\n");
178 i = 2; 178 i = 2;
179 GNUNET_HELLO_iterate_new_addresses(msg3, msg2, startup_time, &check_addr, 179 GNUNET_HELLO_iterate_new_addresses (msg3, msg2, startup_time, &check_addr,
180 &i); 180 &i);
181 GNUNET_assert(i == 0); 181 GNUNET_assert (i == 0);
182 GNUNET_free(msg2); 182 GNUNET_free (msg2);
183 GNUNET_free(msg3); 183 GNUNET_free (msg3);
184 return 0; /* testcase passed */ 184 return 0; /* testcase passed */
185} 185}
diff --git a/src/hello/test_hello.c b/src/hello/test_hello.c
index f3134a7ad..1580dcc55 100644
--- a/src/hello/test_hello.c
+++ b/src/hello/test_hello.c
@@ -35,27 +35,27 @@
35 * @return 35 * @return
36 */ 36 */
37static ssize_t 37static ssize_t
38my_addr_gen(void *cls, 38my_addr_gen (void *cls,
39 size_t max, 39 size_t max,
40 void *buf) 40 void *buf)
41{ 41{
42 unsigned int *i = cls; 42 unsigned int *i = cls;
43 size_t ret; 43 size_t ret;
44 struct GNUNET_HELLO_Address address; 44 struct GNUNET_HELLO_Address address;
45 45
46 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 46 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
47 "DEBUG: my_addr_gen called with i = %d\n", 47 "DEBUG: my_addr_gen called with i = %d\n",
48 *i); 48 *i);
49 if (0 == *i) 49 if (0 == *i)
50 return GNUNET_SYSERR; 50 return GNUNET_SYSERR;
51 memset(&address.peer, 0, sizeof(struct GNUNET_PeerIdentity)); 51 memset (&address.peer, 0, sizeof(struct GNUNET_PeerIdentity));
52 address.address = "address_information"; 52 address.address = "address_information";
53 address.transport_name = "test"; 53 address.transport_name = "test";
54 address.address_length = *i; 54 address.address_length = *i;
55 ret = GNUNET_HELLO_add_address(&address, 55 ret = GNUNET_HELLO_add_address (&address,
56 GNUNET_TIME_absolute_get(), 56 GNUNET_TIME_absolute_get (),
57 buf, 57 buf,
58 max); 58 max);
59 (*i)--; 59 (*i)--;
60 return ret; 60 return ret;
61} 61}
@@ -70,25 +70,25 @@ my_addr_gen(void *cls,
70 * @return 70 * @return
71 */ 71 */
72static int 72static int
73check_addr(void *cls, 73check_addr (void *cls,
74 const struct GNUNET_HELLO_Address *address, 74 const struct GNUNET_HELLO_Address *address,
75 struct GNUNET_TIME_Absolute expiration) 75 struct GNUNET_TIME_Absolute expiration)
76{ 76{
77 unsigned int *i = cls; 77 unsigned int *i = cls;
78 78
79 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 79 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
80 "DEBUG: check_addr called with i = %d and addrlen = %u\n", 80 "DEBUG: check_addr called with i = %d and addrlen = %u\n",
81 *i, 81 *i,
82 (unsigned int)address->address_length); 82 (unsigned int) address->address_length);
83 GNUNET_assert(address->address_length > 0); 83 GNUNET_assert (address->address_length > 0);
84 GNUNET_assert(*i & (1 << (address->address_length - 1))); 84 GNUNET_assert (*i & (1 << (address->address_length - 1)));
85 *i -= (1 << (address->address_length - 1)); 85 *i -= (1 << (address->address_length - 1));
86 GNUNET_assert(0 == 86 GNUNET_assert (0 ==
87 strncmp("address_information", 87 strncmp ("address_information",
88 address->address, 88 address->address,
89 address->address_length)); 89 address->address_length));
90 GNUNET_assert(0 == strcmp("test", 90 GNUNET_assert (0 == strcmp ("test",
91 address->transport_name)); 91 address->transport_name));
92 return GNUNET_OK; 92 return GNUNET_OK;
93} 93}
94 94
@@ -102,29 +102,29 @@ check_addr(void *cls,
102 * @return 102 * @return
103 */ 103 */
104static int 104static int
105remove_some(void *cls, 105remove_some (void *cls,
106 const struct GNUNET_HELLO_Address *address, 106 const struct GNUNET_HELLO_Address *address,
107 struct GNUNET_TIME_Absolute expiration) 107 struct GNUNET_TIME_Absolute expiration)
108{ 108{
109 unsigned int *i = cls; 109 unsigned int *i = cls;
110 110
111 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 111 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
112 "DEBUG: remove_some called with i = %d and addrlen = %u\n", 112 "DEBUG: remove_some called with i = %d and addrlen = %u\n",
113 *i, 113 *i,
114 (unsigned int)address->address_length); 114 (unsigned int) address->address_length);
115 GNUNET_assert(address->address_length > 0); 115 GNUNET_assert (address->address_length > 0);
116 if (*i & (1 << (address->address_length - 1))) 116 if (*i & (1 << (address->address_length - 1)))
117 { 117 {
118 *i -= (1 << (address->address_length - 1)); 118 *i -= (1 << (address->address_length - 1));
119 return GNUNET_NO; 119 return GNUNET_NO;
120 } 120 }
121 return GNUNET_OK; 121 return GNUNET_OK;
122} 122}
123 123
124 124
125int 125int
126main(int argc, 126main (int argc,
127 char *argv[]) 127 char *argv[])
128{ 128{
129 struct GNUNET_HELLO_Message *msg1; 129 struct GNUNET_HELLO_Message *msg1;
130 struct GNUNET_HELLO_Message *msg2; 130 struct GNUNET_HELLO_Message *msg2;
@@ -134,118 +134,118 @@ main(int argc,
134 struct GNUNET_TIME_Absolute startup_time; 134 struct GNUNET_TIME_Absolute startup_time;
135 unsigned int i; 135 unsigned int i;
136 136
137 GNUNET_log_setup("test-hello", 137 GNUNET_log_setup ("test-hello",
138 "DEBUG", 138 "DEBUG",
139 NULL); 139 NULL);
140 startup_time = GNUNET_TIME_absolute_get(); 140 startup_time = GNUNET_TIME_absolute_get ();
141 memset(&publicKey, 42, sizeof(publicKey)); 141 memset (&publicKey, 42, sizeof(publicKey));
142 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
143 "Testing HELLO creation (without addresses)...\n"); 143 "Testing HELLO creation (without addresses)...\n");
144 i = 0; 144 i = 0;
145 msg1 = GNUNET_HELLO_create(&publicKey, 145 msg1 = GNUNET_HELLO_create (&publicKey,
146 &my_addr_gen, 146 &my_addr_gen,
147 &i, 147 &i,
148 GNUNET_NO); 148 GNUNET_NO);
149 GNUNET_assert(msg1 != NULL); 149 GNUNET_assert (msg1 != NULL);
150 GNUNET_assert(0 < GNUNET_HELLO_size(msg1)); 150 GNUNET_assert (0 < GNUNET_HELLO_size (msg1));
151 151
152 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
153 "Testing address iteration (empty set)...\n"); 153 "Testing address iteration (empty set)...\n");
154 GNUNET_assert(NULL == 154 GNUNET_assert (NULL ==
155 GNUNET_HELLO_iterate_addresses(msg1, 155 GNUNET_HELLO_iterate_addresses (msg1,
156 GNUNET_NO, 156 GNUNET_NO,
157 &check_addr, 157 &check_addr,
158 &i)); 158 &i));
159 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
160 "Testing HELLO creation (with one address)...\n"); 160 "Testing HELLO creation (with one address)...\n");
161 i = 1; 161 i = 1;
162 msg2 = GNUNET_HELLO_create(&publicKey, 162 msg2 = GNUNET_HELLO_create (&publicKey,
163 &my_addr_gen, 163 &my_addr_gen,
164 &i, 164 &i,
165 GNUNET_NO); 165 GNUNET_NO);
166 GNUNET_assert(msg2 != NULL); 166 GNUNET_assert (msg2 != NULL);
167 GNUNET_assert(GNUNET_HELLO_size(msg1) < GNUNET_HELLO_size(msg2)); 167 GNUNET_assert (GNUNET_HELLO_size (msg1) < GNUNET_HELLO_size (msg2));
168 168
169 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
170 "Testing address iteration (one address)...\n"); 170 "Testing address iteration (one address)...\n");
171 i = 1; 171 i = 1;
172 GNUNET_assert(NULL == 172 GNUNET_assert (NULL ==
173 GNUNET_HELLO_iterate_addresses(msg2, 173 GNUNET_HELLO_iterate_addresses (msg2,
174 GNUNET_NO, 174 GNUNET_NO,
175 &check_addr, 175 &check_addr,
176 &i)); 176 &i));
177 GNUNET_assert(i == 0); 177 GNUNET_assert (i == 0);
178 178
179 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
180 "Testing get_key from HELLO...\n"); 180 "Testing get_key from HELLO...\n");
181 GNUNET_assert(GNUNET_OK == GNUNET_HELLO_get_id(msg2, &pid)); 181 GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (msg2, &pid));
182 GNUNET_assert(0 == GNUNET_memcmp(&publicKey, 182 GNUNET_assert (0 == GNUNET_memcmp (&publicKey,
183 &pid.public_key)); 183 &pid.public_key));
184 GNUNET_free(msg1); 184 GNUNET_free (msg1);
185 185
186 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
187 "Testing HELLO creation (with two addresses)...\n"); 187 "Testing HELLO creation (with two addresses)...\n");
188 i = 2; 188 i = 2;
189 msg3 = GNUNET_HELLO_create(&publicKey, 189 msg3 = GNUNET_HELLO_create (&publicKey,
190 &my_addr_gen, 190 &my_addr_gen,
191 &i, 191 &i,
192 GNUNET_NO); 192 GNUNET_NO);
193 GNUNET_assert(msg3 != NULL); 193 GNUNET_assert (msg3 != NULL);
194 GNUNET_assert(GNUNET_HELLO_size(msg2) < GNUNET_HELLO_size(msg3)); 194 GNUNET_assert (GNUNET_HELLO_size (msg2) < GNUNET_HELLO_size (msg3));
195 195
196 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
197 "Testing address iteration (two addresses)...\n"); 197 "Testing address iteration (two addresses)...\n");
198 i = 3; 198 i = 3;
199 GNUNET_assert(NULL == 199 GNUNET_assert (NULL ==
200 GNUNET_HELLO_iterate_addresses(msg3, 200 GNUNET_HELLO_iterate_addresses (msg3,
201 GNUNET_NO, 201 GNUNET_NO,
202 &check_addr, 202 &check_addr,
203 &i)); 203 &i));
204 GNUNET_assert(i == 0); 204 GNUNET_assert (i == 0);
205 205
206 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
207 "Testing HELLO merge...\n"); 207 "Testing HELLO merge...\n");
208 msg1 = GNUNET_HELLO_merge(msg2, msg3); 208 msg1 = GNUNET_HELLO_merge (msg2, msg3);
209 GNUNET_assert(GNUNET_HELLO_size(msg1) == GNUNET_HELLO_size(msg3)); 209 GNUNET_assert (GNUNET_HELLO_size (msg1) == GNUNET_HELLO_size (msg3));
210 210
211 i = 3; 211 i = 3;
212 GNUNET_assert(NULL == 212 GNUNET_assert (NULL ==
213 GNUNET_HELLO_iterate_addresses(msg1, 213 GNUNET_HELLO_iterate_addresses (msg1,
214 GNUNET_NO, 214 GNUNET_NO,
215 &check_addr, 215 &check_addr,
216 &i)); 216 &i));
217 GNUNET_assert(i == 0); 217 GNUNET_assert (i == 0);
218 GNUNET_free(msg1); 218 GNUNET_free (msg1);
219 219
220 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
221 "Testing address iteration to copy HELLO...\n"); 221 "Testing address iteration to copy HELLO...\n");
222 i = 2; 222 i = 2;
223 msg1 = GNUNET_HELLO_iterate_addresses(msg3, 223 msg1 = GNUNET_HELLO_iterate_addresses (msg3,
224 GNUNET_YES, 224 GNUNET_YES,
225 &remove_some, 225 &remove_some,
226 &i); 226 &i);
227 GNUNET_assert(msg1 != NULL); 227 GNUNET_assert (msg1 != NULL);
228 GNUNET_assert(i == 0); 228 GNUNET_assert (i == 0);
229 i = 1; 229 i = 1;
230 GNUNET_assert(NULL == 230 GNUNET_assert (NULL ==
231 GNUNET_HELLO_iterate_addresses(msg1, 231 GNUNET_HELLO_iterate_addresses (msg1,
232 GNUNET_NO, 232 GNUNET_NO,
233 &check_addr, 233 &check_addr,
234 &i)); 234 &i));
235 GNUNET_assert(i == 0); 235 GNUNET_assert (i == 0);
236 GNUNET_free(msg1); 236 GNUNET_free (msg1);
237 237
238 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
239 "Testing delta address iteration...\n"); 239 "Testing delta address iteration...\n");
240 i = 2; 240 i = 2;
241 GNUNET_HELLO_iterate_new_addresses(msg3, 241 GNUNET_HELLO_iterate_new_addresses (msg3,
242 msg2, 242 msg2,
243 startup_time, 243 startup_time,
244 &check_addr, 244 &check_addr,
245 &i); 245 &i);
246 GNUNET_assert(i == 0); 246 GNUNET_assert (i == 0);
247 GNUNET_free(msg2); 247 GNUNET_free (msg2);
248 GNUNET_free(msg3); 248 GNUNET_free (msg3);
249 return 0; /* testcase passed */ 249 return 0; /* testcase passed */
250} 250}
251 251