diff options
Diffstat (limited to 'src/hello')
-rw-r--r-- | src/hello/address.c | 40 | ||||
-rw-r--r-- | src/hello/hello.c | 28 | ||||
-rw-r--r-- | src/hello/test_hello.c | 8 |
3 files changed, 32 insertions, 44 deletions
diff --git a/src/hello/address.c b/src/hello/address.c index b511ca9df..618aa6e6a 100644 --- a/src/hello/address.c +++ b/src/hello/address.c | |||
@@ -39,21 +39,20 @@ | |||
39 | */ | 39 | */ |
40 | struct GNUNET_HELLO_Address * | 40 | struct GNUNET_HELLO_Address * |
41 | GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer, | 41 | GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer, |
42 | const char *transport_name, | 42 | const char *transport_name, const void *address, |
43 | const void *address, | 43 | size_t address_length) |
44 | size_t address_length) | ||
45 | { | 44 | { |
46 | struct GNUNET_HELLO_Address *addr; | 45 | struct GNUNET_HELLO_Address *addr; |
47 | size_t slen; | 46 | size_t slen; |
48 | char *end; | 47 | char *end; |
49 | 48 | ||
50 | slen = strlen (transport_name) + 1; | 49 | slen = strlen (transport_name) + 1; |
51 | addr = GNUNET_malloc (sizeof (struct GNUNET_HELLO_Address) + | 50 | addr = |
52 | address_length + | 51 | GNUNET_malloc (sizeof (struct GNUNET_HELLO_Address) + address_length + |
53 | slen); | 52 | slen); |
54 | addr->peer = *peer; | 53 | addr->peer = *peer; |
55 | addr->address = &addr[1]; | 54 | addr->address = &addr[1]; |
56 | end = (char*) &addr[1]; | 55 | end = (char *) &addr[1]; |
57 | memcpy (end, address, address_length); | 56 | memcpy (end, address, address_length); |
58 | addr->address_length = address_length; | 57 | addr->address_length = address_length; |
59 | addr->transport_name = &end[address_length]; | 58 | addr->transport_name = &end[address_length]; |
@@ -69,11 +68,10 @@ GNUNET_HELLO_address_allocate (const struct GNUNET_PeerIdentity *peer, | |||
69 | * @return the size | 68 | * @return the size |
70 | */ | 69 | */ |
71 | size_t | 70 | size_t |
72 | GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address) | 71 | GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address * address) |
73 | { | 72 | { |
74 | return sizeof (struct GNUNET_HELLO_Address) + | 73 | return sizeof (struct GNUNET_HELLO_Address) + address->address_length + |
75 | address->address_length + | 74 | strlen (address->transport_name) + 1; |
76 | strlen(address->transport_name) + 1; | ||
77 | } | 75 | } |
78 | 76 | ||
79 | 77 | ||
@@ -86,10 +84,9 @@ GNUNET_HELLO_address_get_size (const struct GNUNET_HELLO_Address *address) | |||
86 | struct GNUNET_HELLO_Address * | 84 | struct GNUNET_HELLO_Address * |
87 | GNUNET_HELLO_address_copy (const struct GNUNET_HELLO_Address *address) | 85 | GNUNET_HELLO_address_copy (const struct GNUNET_HELLO_Address *address) |
88 | { | 86 | { |
89 | return GNUNET_HELLO_address_allocate (&address->peer, | 87 | return GNUNET_HELLO_address_allocate (&address->peer, address->transport_name, |
90 | address->transport_name, | 88 | address->address, |
91 | address->address, | 89 | address->address_length); |
92 | address->address_length); | ||
93 | } | 90 | } |
94 | 91 | ||
95 | 92 | ||
@@ -103,21 +100,18 @@ GNUNET_HELLO_address_copy (const struct GNUNET_HELLO_Address *address) | |||
103 | */ | 100 | */ |
104 | int | 101 | int |
105 | GNUNET_HELLO_address_cmp (const struct GNUNET_HELLO_Address *a1, | 102 | GNUNET_HELLO_address_cmp (const struct GNUNET_HELLO_Address *a1, |
106 | const struct GNUNET_HELLO_Address *a2) | 103 | const struct GNUNET_HELLO_Address *a2) |
107 | { | 104 | { |
108 | int ret; | 105 | int ret; |
109 | 106 | ||
110 | ret = strcmp (a1->transport_name, | 107 | ret = strcmp (a1->transport_name, a2->transport_name); |
111 | a2->transport_name); | ||
112 | if (0 != ret) | 108 | if (0 != ret) |
113 | return ret; | 109 | return ret; |
114 | if (a1->address_length < a2->address_length) | 110 | if (a1->address_length < a2->address_length) |
115 | return -1; | 111 | return -1; |
116 | if (a1->address_length > a2->address_length) | 112 | if (a1->address_length > a2->address_length) |
117 | return 1; | 113 | return 1; |
118 | return memcmp (a1->address, | 114 | return memcmp (a1->address, a1->address, a1->address_length); |
119 | a1->address, | ||
120 | a1->address_length); | ||
121 | } | 115 | } |
122 | 116 | ||
123 | 117 | ||
diff --git a/src/hello/hello.c b/src/hello/hello.c index 9c0c3d4ac..f7d34233c 100644 --- a/src/hello/hello.c +++ b/src/hello/hello.c | |||
@@ -74,8 +74,7 @@ struct GNUNET_HELLO_Message | |||
74 | */ | 74 | */ |
75 | size_t | 75 | size_t |
76 | GNUNET_HELLO_add_address (const struct GNUNET_HELLO_Address *address, | 76 | GNUNET_HELLO_add_address (const struct GNUNET_HELLO_Address *address, |
77 | struct GNUNET_TIME_Absolute expiration, | 77 | struct GNUNET_TIME_Absolute expiration, char *target, |
78 | char *target, | ||
79 | size_t max) | 78 | size_t max) |
80 | { | 79 | { |
81 | uint16_t alen; | 80 | uint16_t alen; |
@@ -232,8 +231,8 @@ GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg, | |||
232 | wpos = 0; | 231 | wpos = 0; |
233 | woff = (ret != NULL) ? (char *) &ret[1] : NULL; | 232 | woff = (ret != NULL) ? (char *) &ret[1] : NULL; |
234 | GNUNET_CRYPTO_hash (&msg->publicKey, | 233 | GNUNET_CRYPTO_hash (&msg->publicKey, |
235 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), | 234 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), |
236 | &address.peer.hashPubKey); | 235 | &address.peer.hashPubKey); |
237 | while (insize > 0) | 236 | while (insize > 0) |
238 | { | 237 | { |
239 | esize = get_hello_address_size (inptr, insize, &alen); | 238 | esize = get_hello_address_size (inptr, insize, &alen); |
@@ -280,14 +279,12 @@ struct ExpireContext | |||
280 | 279 | ||
281 | 280 | ||
282 | static int | 281 | static int |
283 | get_match_exp (void *cls, | 282 | get_match_exp (void *cls, const struct GNUNET_HELLO_Address *address, |
284 | const struct GNUNET_HELLO_Address *address, | ||
285 | struct GNUNET_TIME_Absolute expiration) | 283 | struct GNUNET_TIME_Absolute expiration) |
286 | { | 284 | { |
287 | struct ExpireContext *ec = cls; | 285 | struct ExpireContext *ec = cls; |
288 | 286 | ||
289 | if (0 == GNUNET_HELLO_address_cmp (address, | 287 | if (0 == GNUNET_HELLO_address_cmp (address, ec->address)) |
290 | ec->address)) | ||
291 | { | 288 | { |
292 | ec->found = GNUNET_YES; | 289 | ec->found = GNUNET_YES; |
293 | ec->expiration = expiration; | 290 | ec->expiration = expiration; |
@@ -311,8 +308,7 @@ struct MergeContext | |||
311 | 308 | ||
312 | 309 | ||
313 | static int | 310 | static int |
314 | copy_latest (void *cls, | 311 | copy_latest (void *cls, const struct GNUNET_HELLO_Address *address, |
315 | const struct GNUNET_HELLO_Address *address, | ||
316 | struct GNUNET_TIME_Absolute expiration) | 312 | struct GNUNET_TIME_Absolute expiration) |
317 | { | 313 | { |
318 | struct MergeContext *mc = cls; | 314 | struct MergeContext *mc = cls; |
@@ -327,9 +323,8 @@ copy_latest (void *cls, | |||
327 | (mc->take_equal == GNUNET_YES))) | 323 | (mc->take_equal == GNUNET_YES))) |
328 | { | 324 | { |
329 | mc->ret += | 325 | mc->ret += |
330 | GNUNET_HELLO_add_address (address, | 326 | GNUNET_HELLO_add_address (address, expiration, &mc->buf[mc->ret], |
331 | expiration, | 327 | mc->max - mc->ret); |
332 | &mc->buf[mc->ret], mc->max - mc->ret); | ||
333 | } | 328 | } |
334 | return GNUNET_OK; | 329 | return GNUNET_OK; |
335 | } | 330 | } |
@@ -388,8 +383,7 @@ struct DeltaContext | |||
388 | 383 | ||
389 | 384 | ||
390 | static int | 385 | static int |
391 | delta_match (void *cls, | 386 | delta_match (void *cls, const struct GNUNET_HELLO_Address *address, |
392 | const struct GNUNET_HELLO_Address *address, | ||
393 | struct GNUNET_TIME_Absolute expiration) | 387 | struct GNUNET_TIME_Absolute expiration) |
394 | { | 388 | { |
395 | struct DeltaContext *dc = cls; | 389 | struct DeltaContext *dc = cls; |
@@ -547,9 +541,7 @@ find_other_matching (void *cls, const struct GNUNET_HELLO_Address *address, | |||
547 | 541 | ||
548 | if (expiration.abs_value < ec->expiration_limit.abs_value) | 542 | if (expiration.abs_value < ec->expiration_limit.abs_value) |
549 | return GNUNET_YES; | 543 | return GNUNET_YES; |
550 | if (0 == | 544 | if (0 == GNUNET_HELLO_address_cmp (address, ec->address)) |
551 | GNUNET_HELLO_address_cmp (address, | ||
552 | ec->address)) | ||
553 | { | 545 | { |
554 | ec->found = GNUNET_YES; | 546 | ec->found = GNUNET_YES; |
555 | if (expiration.abs_value < ec->expiration.abs_value) | 547 | if (expiration.abs_value < ec->expiration.abs_value) |
diff --git a/src/hello/test_hello.c b/src/hello/test_hello.c index ca69dfc18..eb15668f4 100644 --- a/src/hello/test_hello.c +++ b/src/hello/test_hello.c | |||
@@ -47,8 +47,8 @@ my_addr_gen (void *cls, size_t max, void *buf) | |||
47 | address.transport_name = "test"; | 47 | address.transport_name = "test"; |
48 | address.address_length = *i; | 48 | address.address_length = *i; |
49 | ret = | 49 | ret = |
50 | GNUNET_HELLO_add_address (&address, GNUNET_TIME_absolute_get (), | 50 | GNUNET_HELLO_add_address (&address, GNUNET_TIME_absolute_get (), buf, |
51 | buf, max); | 51 | max); |
52 | (*i)--; | 52 | (*i)--; |
53 | return ret; | 53 | return ret; |
54 | } | 54 | } |
@@ -67,7 +67,9 @@ check_addr (void *cls, const struct GNUNET_HELLO_Address *address, | |||
67 | GNUNET_assert (address->address_length > 0); | 67 | GNUNET_assert (address->address_length > 0); |
68 | GNUNET_assert (*i & (1 << (address->address_length - 1))); | 68 | GNUNET_assert (*i & (1 << (address->address_length - 1))); |
69 | *i -= (1 << (address->address_length - 1)); | 69 | *i -= (1 << (address->address_length - 1)); |
70 | GNUNET_assert (0 == strncmp ("address_information", address->address, address->address_length)); | 70 | GNUNET_assert (0 == |
71 | strncmp ("address_information", address->address, | ||
72 | address->address_length)); | ||
71 | GNUNET_assert (0 == strcmp ("test", address->transport_name)); | 73 | GNUNET_assert (0 == strcmp ("test", address->transport_name)); |
72 | return GNUNET_OK; | 74 | return GNUNET_OK; |
73 | } | 75 | } |