aboutsummaryrefslogtreecommitdiff
path: root/src/hello
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-04-04 09:43:10 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-04-04 09:43:10 +0000
commitc303b97bd731aef372ec24ebe8b47ee014ada23b (patch)
treeaa287d7443434a9147cfb08fe0caa12e9c8de9e4 /src/hello
parented18131bd038617c03e0b3b83e3eb56c31dc3e4a (diff)
downloadgnunet-c303b97bd731aef372ec24ebe8b47ee014ada23b.tar.gz
gnunet-c303b97bd731aef372ec24ebe8b47ee014ada23b.zip
changes for mantis 0002676
Diffstat (limited to 'src/hello')
-rw-r--r--src/hello/gnunet-hello.c9
-rw-r--r--src/hello/hello.c65
2 files changed, 27 insertions, 47 deletions
diff --git a/src/hello/gnunet-hello.c b/src/hello/gnunet-hello.c
index b20279c1d..816a89936 100644
--- a/src/hello/gnunet-hello.c
+++ b/src/hello/gnunet-hello.c
@@ -110,7 +110,6 @@ main (int argc, char *argv[])
110 struct GNUNET_HELLO_Message *result; 110 struct GNUNET_HELLO_Message *result;
111 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pk; 111 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pk;
112 uint64_t fsize; 112 uint64_t fsize;
113 int friend_only;
114 113
115 GNUNET_log_setup ("gnunet-hello", "INFO", NULL); 114 GNUNET_log_setup ("gnunet-hello", "INFO", NULL);
116 if (argc != 2) 115 if (argc != 2)
@@ -168,12 +167,8 @@ main (int argc, char *argv[])
168 argv[1]); 167 argv[1]);
169 return 1; 168 return 1;
170 } 169 }
171 friend_only = GNUNET_NO; 170 result = GNUNET_HELLO_create (&pk, &add_from_hello, &orig,
172 if (GNUNET_MESSAGE_TYPE_HELLO == GNUNET_HELLO_get_type (orig)) 171 GNUNET_HELLO_is_friend_only (orig));
173 friend_only = GNUNET_NO;
174 if (GNUNET_MESSAGE_TYPE_FRIEND_HELLO == GNUNET_HELLO_get_type (orig))
175 friend_only = GNUNET_YES;
176 result = GNUNET_HELLO_create (&pk, &add_from_hello, &orig, friend_only);
177 GNUNET_assert (NULL != result); 172 GNUNET_assert (NULL != result);
178 fh = GNUNET_DISK_file_open (argv[1], 173 fh = GNUNET_DISK_file_open (argv[1],
179 GNUNET_DISK_OPEN_WRITE, 174 GNUNET_DISK_OPEN_WRITE,
diff --git a/src/hello/hello.c b/src/hello/hello.c
index 382edf3d9..fc27e446b 100644
--- a/src/hello/hello.c
+++ b/src/hello/hello.c
@@ -52,9 +52,9 @@ struct GNUNET_HELLO_Message
52 struct GNUNET_MessageHeader header; 52 struct GNUNET_MessageHeader header;
53 53
54 /** 54 /**
55 * Always zero (for alignment). 55 * Use in F2F mode: Do not gossip this HELLO message
56 */ 56 */
57 uint32_t reserved GNUNET_PACKED; 57 uint32_t friend_only GNUNET_PACKED;
58 58
59 /** 59 /**
60 * The public key of the peer. 60 * The public key of the peer.
@@ -104,23 +104,21 @@ struct GNUNET_HELLO_ParseUriContext
104}; 104};
105 105
106 106
107/** 107/** Return HELLO type
108 * Return HELLO type
109 * 108 *
110 * @param h HELLO Message to test 109 * @param h HELLO Message to test
111 * @return GNUNET_MESSAGE_TYPE_HELLO or GNUNET_MESSAGE_TYPE_FRIEND_HELLO or 0 on error 110 * @return GNUNET_YES or GNUNET_NO
112 */ 111 */
113uint16_t 112int
114GNUNET_HELLO_get_type (const struct GNUNET_HELLO_Message *h) 113GNUNET_HELLO_is_friend_only (const struct GNUNET_HELLO_Message *h)
115{ 114{
116 if (GNUNET_MESSAGE_TYPE_HELLO == ntohs(h->header.type)) 115 if (GNUNET_YES == ntohl(h->friend_only))
117 return GNUNET_MESSAGE_TYPE_HELLO; 116 return GNUNET_YES;
118 if (GNUNET_MESSAGE_TYPE_FRIEND_HELLO == ntohs(h->header.type)) 117 return GNUNET_NO;
119 return GNUNET_MESSAGE_TYPE_FRIEND_HELLO;
120 return 0;
121} 118}
122 119
123 120
121
124/** 122/**
125 * Copy the given address information into 123 * Copy the given address information into
126 * the given buffer using the format of HELLOs. 124 * the given buffer using the format of HELLOs.
@@ -231,6 +229,9 @@ GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded
231 size_t ret; 229 size_t ret;
232 struct GNUNET_HELLO_Message *hello; 230 struct GNUNET_HELLO_Message *hello;
233 231
232 GNUNET_assert (NULL != publicKey);
233 GNUNET_assert ((GNUNET_YES == friend_only) || (GNUNET_NO == friend_only));
234
234 max = sizeof (buffer); 235 max = sizeof (buffer);
235 used = 0; 236 used = 0;
236 if (addrgen != NULL) 237 if (addrgen != NULL)
@@ -242,11 +243,10 @@ GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded
242 } 243 }
243 } 244 }
244 hello = GNUNET_malloc (sizeof (struct GNUNET_HELLO_Message) + used); 245 hello = GNUNET_malloc (sizeof (struct GNUNET_HELLO_Message) + used);
245 if (GNUNET_NO == friend_only) 246 hello->header.type = htons (GNUNET_MESSAGE_TYPE_HELLO);
246 hello->header.type = htons (GNUNET_MESSAGE_TYPE_HELLO);
247 else
248 hello->header.type = htons (GNUNET_MESSAGE_TYPE_FRIEND_HELLO);
249 hello->header.size = htons (sizeof (struct GNUNET_HELLO_Message) + used); 247 hello->header.size = htons (sizeof (struct GNUNET_HELLO_Message) + used);
248 hello->friend_only = htonl (friend_only);
249
250 memcpy (&hello->publicKey, publicKey, 250 memcpy (&hello->publicKey, publicKey,
251 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)); 251 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded));
252 memcpy (&hello[1], buffer, used); 252 memcpy (&hello[1], buffer, used);
@@ -282,8 +282,7 @@ GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg,
282 282
283 msize = GNUNET_HELLO_size (msg); 283 msize = GNUNET_HELLO_size (msg);
284 if ((msize < sizeof (struct GNUNET_HELLO_Message)) || 284 if ((msize < sizeof (struct GNUNET_HELLO_Message)) ||
285 ((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)))
287 return NULL; 286 return NULL;
288 ret = NULL; 287 ret = NULL;
289 if (return_modified) 288 if (return_modified)
@@ -431,21 +430,11 @@ GNUNET_HELLO_merge (const struct GNUNET_HELLO_Message *h1,
431{ 430{
432 struct MergeContext mc = { h1, h2, NULL, NULL, 0, 0, 0 }; 431 struct MergeContext mc = { h1, h2, NULL, NULL, 0, 0, 0 };
433 int friend_only; 432 int friend_only;
434 if (h1->header.type != h2->header.type) 433
435 { 434 if (h1->friend_only != h2->friend_only)
436 /* Trying to merge different HELLO types */ 435 friend_only = GNUNET_YES; /* One of the HELLOs is friend only */
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 436 else
445 { 437 friend_only = ntohl (h1->friend_only); /* Both HELLO's have the same type */
446 GNUNET_break (0);
447 return NULL;
448 }
449 438
450 return GNUNET_HELLO_create (&h1->publicKey, &merge_addr, &mc, friend_only); 439 return GNUNET_HELLO_create (&h1->publicKey, &merge_addr, &mc, friend_only);
451} 440}
@@ -526,8 +515,7 @@ GNUNET_HELLO_size (const struct GNUNET_HELLO_Message *hello)
526 uint16_t ret = ntohs (hello->header.size); 515 uint16_t ret = ntohs (hello->header.size);
527 516
528 if ((ret < sizeof (struct GNUNET_HELLO_Message)) || 517 if ((ret < sizeof (struct GNUNET_HELLO_Message)) ||
529 ((ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO) && 518 (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
530 (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_FRIEND_HELLO)))
531 return 0; 519 return 0;
532 return ret; 520 return ret;
533} 521}
@@ -547,8 +535,7 @@ GNUNET_HELLO_get_key (const struct GNUNET_HELLO_Message *hello,
547 uint16_t ret = ntohs (hello->header.size); 535 uint16_t ret = ntohs (hello->header.size);
548 536
549 if ((ret < sizeof (struct GNUNET_HELLO_Message)) || 537 if ((ret < sizeof (struct GNUNET_HELLO_Message)) ||
550 ((ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO) && 538 (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
551 (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_FRIEND_HELLO)))
552 return GNUNET_SYSERR; 539 return GNUNET_SYSERR;
553 *publicKey = hello->publicKey; 540 *publicKey = hello->publicKey;
554 return GNUNET_OK; 541 return GNUNET_OK;
@@ -569,8 +556,7 @@ GNUNET_HELLO_get_id (const struct GNUNET_HELLO_Message *hello,
569 uint16_t ret = ntohs (hello->header.size); 556 uint16_t ret = ntohs (hello->header.size);
570 557
571 if ((ret < sizeof (struct GNUNET_HELLO_Message)) || 558 if ((ret < sizeof (struct GNUNET_HELLO_Message)) ||
572 ((ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO) && 559 (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
573 (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_FRIEND_HELLO)))
574 return GNUNET_SYSERR; 560 return GNUNET_SYSERR;
575 GNUNET_CRYPTO_hash (&hello->publicKey, 561 GNUNET_CRYPTO_hash (&hello->publicKey,
576 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), 562 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
@@ -593,8 +579,7 @@ GNUNET_HELLO_get_header (struct GNUNET_HELLO_Message *hello)
593 uint16_t ret = ntohs (hello->header.size); 579 uint16_t ret = ntohs (hello->header.size);
594 580
595 if ((ret < sizeof (struct GNUNET_HELLO_Message)) || 581 if ((ret < sizeof (struct GNUNET_HELLO_Message)) ||
596 ((ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO) && 582 (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO))
597 (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_FRIEND_HELLO)))
598 return NULL; 583 return NULL;
599 584
600 return &hello->header; 585 return &hello->header;