diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-03-28 15:14:38 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-03-28 15:14:38 +0000 |
commit | b3883971cd31d198dbd768fffb15960dff0352a6 (patch) | |
tree | 1803032b911774f57158013eedfc26a3c0fb5462 /src/hello/hello.c | |
parent | 1fe395444d868f4fd66d44da83cb61a69acc6b66 (diff) | |
download | gnunet-b3883971cd31d198dbd768fffb15960dff0352a6.tar.gz gnunet-b3883971cd31d198dbd768fffb15960dff0352a6.zip |
new friend only HELLO type GNUNET_MESSAGE_TYPE_FRIEND_HELLO
Diffstat (limited to 'src/hello/hello.c')
-rw-r--r-- | src/hello/hello.c | 81 |
1 files changed, 69 insertions, 12 deletions
diff --git a/src/hello/hello.c b/src/hello/hello.c index a20e8992c..066c03d87 100644 --- a/src/hello/hello.c +++ b/src/hello/hello.c | |||
@@ -103,6 +103,23 @@ struct GNUNET_HELLO_ParseUriContext | |||
103 | GNUNET_HELLO_TransportPluginsFind plugins_find; | 103 | GNUNET_HELLO_TransportPluginsFind plugins_find; |
104 | }; | 104 | }; |
105 | 105 | ||
106 | /** | ||
107 | * Return HELLO type | ||
108 | * | ||
109 | * @param h HELLO Message to test | ||
110 | * @param GNUNET_MESSAGE_TYPE_HELLO or GNUNET_MESSAGE_TYPE_FRIEND_HELLO or 0 on error | ||
111 | */ | ||
112 | |||
113 | uint16_t | ||
114 | GNUNET_HELLO_get_type (const struct GNUNET_MessageHeader *h) | ||
115 | { | ||
116 | if (GNUNET_MESSAGE_TYPE_HELLO == ntohs(h->type)) | ||
117 | return GNUNET_MESSAGE_TYPE_HELLO; | ||
118 | if (GNUNET_MESSAGE_TYPE_FRIEND_HELLO == ntohs(h->type)) | ||
119 | return GNUNET_MESSAGE_TYPE_FRIEND_HELLO; | ||
120 | return 0; | ||
121 | } | ||
122 | |||
106 | 123 | ||
107 | /** | 124 | /** |
108 | * Copy the given address information into | 125 | * Copy the given address information into |
@@ -204,7 +221,8 @@ struct GNUNET_HELLO_Message * | |||
204 | GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded | 221 | GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded |
205 | *publicKey, | 222 | *publicKey, |
206 | GNUNET_HELLO_GenerateAddressListCallback addrgen, | 223 | GNUNET_HELLO_GenerateAddressListCallback addrgen, |
207 | void *addrgen_cls) | 224 | void *addrgen_cls, |
225 | int friend_only) | ||
208 | { | 226 | { |
209 | char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - 256 - | 227 | char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1 - 256 - |
210 | sizeof (struct GNUNET_HELLO_Message)]; | 228 | sizeof (struct GNUNET_HELLO_Message)]; |
@@ -224,7 +242,10 @@ GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded | |||
224 | } | 242 | } |
225 | } | 243 | } |
226 | hello = GNUNET_malloc (sizeof (struct GNUNET_HELLO_Message) + used); | 244 | hello = GNUNET_malloc (sizeof (struct GNUNET_HELLO_Message) + used); |
227 | hello->header.type = htons (GNUNET_MESSAGE_TYPE_HELLO); | 245 | if (GNUNET_NO == friend_only) |
246 | hello->header.type = htons (GNUNET_MESSAGE_TYPE_HELLO); | ||
247 | else | ||
248 | hello->header.type = htons (GNUNET_MESSAGE_TYPE_FRIEND_HELLO); | ||
228 | hello->header.size = htons (sizeof (struct GNUNET_HELLO_Message) + used); | 249 | hello->header.size = htons (sizeof (struct GNUNET_HELLO_Message) + used); |
229 | memcpy (&hello->publicKey, publicKey, | 250 | memcpy (&hello->publicKey, publicKey, |
230 | sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)); | 251 | sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)); |
@@ -261,7 +282,8 @@ GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg, | |||
261 | 282 | ||
262 | msize = GNUNET_HELLO_size (msg); | 283 | msize = GNUNET_HELLO_size (msg); |
263 | if ((msize < sizeof (struct GNUNET_HELLO_Message)) || | 284 | if ((msize < sizeof (struct GNUNET_HELLO_Message)) || |
264 | (ntohs (msg->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) | 285 | ((ntohs (msg->header.type) != GNUNET_MESSAGE_TYPE_HELLO) && |
286 | (ntohs (msg->header.type) != GNUNET_MESSAGE_TYPE_FRIEND_HELLO))) | ||
265 | return NULL; | 287 | return NULL; |
266 | ret = NULL; | 288 | ret = NULL; |
267 | if (return_modified) | 289 | if (return_modified) |
@@ -408,8 +430,24 @@ GNUNET_HELLO_merge (const struct GNUNET_HELLO_Message *h1, | |||
408 | const struct GNUNET_HELLO_Message *h2) | 430 | const struct GNUNET_HELLO_Message *h2) |
409 | { | 431 | { |
410 | struct MergeContext mc = { h1, h2, NULL, NULL, 0, 0, 0 }; | 432 | struct MergeContext mc = { h1, h2, NULL, NULL, 0, 0, 0 }; |
433 | int friend_only; | ||
434 | if (h1->header.type != h2->header.type) | ||
435 | { | ||
436 | /* Trying to merge different HELLO types */ | ||
437 | GNUNET_break (0); | ||
438 | return NULL; | ||
439 | } | ||
440 | if (GNUNET_MESSAGE_TYPE_HELLO == (ntohs(h1->header.type))) | ||
441 | friend_only = GNUNET_NO; | ||
442 | else if (GNUNET_MESSAGE_TYPE_FRIEND_HELLO == (ntohs(h1->header.type))) | ||
443 | friend_only = GNUNET_YES; | ||
444 | else | ||
445 | { | ||
446 | GNUNET_break (0); | ||
447 | return NULL; | ||
448 | } | ||
411 | 449 | ||
412 | return GNUNET_HELLO_create (&h1->publicKey, &merge_addr, &mc); | 450 | return GNUNET_HELLO_create (&h1->publicKey, &merge_addr, &mc, friend_only); |
413 | } | 451 | } |
414 | 452 | ||
415 | 453 | ||
@@ -488,7 +526,8 @@ GNUNET_HELLO_size (const struct GNUNET_HELLO_Message *hello) | |||
488 | uint16_t ret = ntohs (hello->header.size); | 526 | uint16_t ret = ntohs (hello->header.size); |
489 | 527 | ||
490 | if ((ret < sizeof (struct GNUNET_HELLO_Message)) || | 528 | if ((ret < sizeof (struct GNUNET_HELLO_Message)) || |
491 | (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) | 529 | ((ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO) && |
530 | (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_FRIEND_HELLO))) | ||
492 | return 0; | 531 | return 0; |
493 | return ret; | 532 | return ret; |
494 | } | 533 | } |
@@ -508,7 +547,8 @@ GNUNET_HELLO_get_key (const struct GNUNET_HELLO_Message *hello, | |||
508 | uint16_t ret = ntohs (hello->header.size); | 547 | uint16_t ret = ntohs (hello->header.size); |
509 | 548 | ||
510 | if ((ret < sizeof (struct GNUNET_HELLO_Message)) || | 549 | if ((ret < sizeof (struct GNUNET_HELLO_Message)) || |
511 | (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) | 550 | ((ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO) && |
551 | (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_FRIEND_HELLO))) | ||
512 | return GNUNET_SYSERR; | 552 | return GNUNET_SYSERR; |
513 | *publicKey = hello->publicKey; | 553 | *publicKey = hello->publicKey; |
514 | return GNUNET_OK; | 554 | return GNUNET_OK; |
@@ -529,7 +569,8 @@ GNUNET_HELLO_get_id (const struct GNUNET_HELLO_Message *hello, | |||
529 | uint16_t ret = ntohs (hello->header.size); | 569 | uint16_t ret = ntohs (hello->header.size); |
530 | 570 | ||
531 | if ((ret < sizeof (struct GNUNET_HELLO_Message)) || | 571 | if ((ret < sizeof (struct GNUNET_HELLO_Message)) || |
532 | (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) | 572 | ((ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO) && |
573 | (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_FRIEND_HELLO))) | ||
533 | return GNUNET_SYSERR; | 574 | return GNUNET_SYSERR; |
534 | GNUNET_CRYPTO_hash (&hello->publicKey, | 575 | GNUNET_CRYPTO_hash (&hello->publicKey, |
535 | sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), | 576 | sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded), |
@@ -552,7 +593,8 @@ GNUNET_HELLO_get_header (struct GNUNET_HELLO_Message *hello) | |||
552 | uint16_t ret = ntohs (hello->header.size); | 593 | uint16_t ret = ntohs (hello->header.size); |
553 | 594 | ||
554 | if ((ret < sizeof (struct GNUNET_HELLO_Message)) || | 595 | if ((ret < sizeof (struct GNUNET_HELLO_Message)) || |
555 | (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO)) | 596 | ((ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_HELLO) && |
597 | (ntohs (hello->header.type) != GNUNET_MESSAGE_TYPE_FRIEND_HELLO))) | ||
556 | return NULL; | 598 | return NULL; |
557 | 599 | ||
558 | return &hello->header; | 600 | return &hello->header; |
@@ -639,6 +681,9 @@ GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1, | |||
639 | { | 681 | { |
640 | struct EqualsContext ec; | 682 | struct EqualsContext ec; |
641 | 683 | ||
684 | if (h1->header.type != h2->header.type) | ||
685 | return GNUNET_TIME_UNIT_ZERO_ABS; | ||
686 | |||
642 | if (0 != | 687 | if (0 != |
643 | memcmp (&h1->publicKey, &h2->publicKey, | 688 | memcmp (&h1->publicKey, &h2->publicKey, |
644 | sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded))) | 689 | sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded))) |
@@ -1011,13 +1056,25 @@ GNUNET_HELLO_parse_uri (const char *uri, | |||
1011 | { | 1056 | { |
1012 | const char *pks; | 1057 | const char *pks; |
1013 | const char *exc; | 1058 | const char *exc; |
1059 | int friend_only; | ||
1014 | struct GNUNET_HELLO_ParseUriContext ctx; | 1060 | struct GNUNET_HELLO_ParseUriContext ctx; |
1015 | 1061 | ||
1016 | if (0 != strncmp (uri, | 1062 | if (0 == strncmp (uri, |
1017 | GNUNET_HELLO_URI_PREFIX, | 1063 | GNUNET_HELLO_URI_PREFIX, |
1018 | strlen (GNUNET_HELLO_URI_PREFIX))) | 1064 | strlen (GNUNET_HELLO_URI_PREFIX))) |
1019 | return GNUNET_SYSERR; | 1065 | { |
1020 | pks = &uri[strlen (GNUNET_HELLO_URI_PREFIX)]; | 1066 | pks = &uri[strlen (GNUNET_HELLO_URI_PREFIX)]; |
1067 | friend_only = GNUNET_NO; | ||
1068 | } | ||
1069 | else if (0 == strncmp (uri, | ||
1070 | GNUNET_FRIEND_HELLO_URI_PREFIX, | ||
1071 | strlen (GNUNET_FRIEND_HELLO_URI_PREFIX))) | ||
1072 | { | ||
1073 | pks = &uri[strlen (GNUNET_FRIEND_HELLO_URI_PREFIX)]; | ||
1074 | friend_only = GNUNET_YES; | ||
1075 | } | ||
1076 | else | ||
1077 | return GNUNET_SYSERR; | ||
1021 | exc = strstr (pks, "!"); | 1078 | exc = strstr (pks, "!"); |
1022 | 1079 | ||
1023 | if (GNUNET_OK != | 1080 | if (GNUNET_OK != |
@@ -1030,7 +1087,7 @@ GNUNET_HELLO_parse_uri (const char *uri, | |||
1030 | ctx.pos = exc; | 1087 | ctx.pos = exc; |
1031 | ctx.ret = GNUNET_OK; | 1088 | ctx.ret = GNUNET_OK; |
1032 | ctx.plugins_find = plugins_find; | 1089 | ctx.plugins_find = plugins_find; |
1033 | *hello = GNUNET_HELLO_create (pubkey, &add_address_to_hello, &ctx); | 1090 | *hello = GNUNET_HELLO_create (pubkey, &add_address_to_hello, &ctx, friend_only); |
1034 | 1091 | ||
1035 | return ctx.ret; | 1092 | return ctx.ret; |
1036 | } | 1093 | } |