aboutsummaryrefslogtreecommitdiff
path: root/src/hello/test_hello.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-11-08 23:20:42 +0000
committerChristian Grothoff <christian@grothoff.org>2011-11-08 23:20:42 +0000
commita983a0267109b1b6a8e16e476e2f2956a8771b94 (patch)
tree79bcae73cdb7b87b4f55d4396e79baea76ef53a6 /src/hello/test_hello.c
parenta3f8ef5b89dc44fc3acfb8f081a502f3409e4224 (diff)
downloadgnunet-a983a0267109b1b6a8e16e476e2f2956a8771b94.tar.gz
gnunet-a983a0267109b1b6a8e16e476e2f2956a8771b94.zip
refactoring how we handle peer addresses in peerinfo/ats/transport/hello subsystems -- use a struct instead of 3--4 arguments
Diffstat (limited to 'src/hello/test_hello.c')
-rw-r--r--src/hello/test_hello.c39
1 files changed, 21 insertions, 18 deletions
diff --git a/src/hello/test_hello.c b/src/hello/test_hello.c
index b6cdfcf66..ca69dfc18 100644
--- a/src/hello/test_hello.c
+++ b/src/hello/test_hello.c
@@ -35,55 +35,58 @@ my_addr_gen (void *cls, size_t max, void *buf)
35{ 35{
36 unsigned int *i = cls; 36 unsigned int *i = cls;
37 size_t ret; 37 size_t ret;
38 struct GNUNET_HELLO_Address address;
38 39
39#if DEBUG 40#if DEBUG
40 fprintf (stderr, "DEBUG: my_addr_gen called with i = %d\n", *i); 41 fprintf (stderr, "DEBUG: my_addr_gen called with i = %d\n", *i);
41#endif 42#endif
42 if (0 == *i) 43 if (0 == *i)
43 return 0; 44 return 0;
45 memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity));
46 address.address = "address_information";
47 address.transport_name = "test";
48 address.address_length = *i;
44 ret = 49 ret =
45 GNUNET_HELLO_add_address ("test", GNUNET_TIME_absolute_get (), 50 GNUNET_HELLO_add_address (&address, GNUNET_TIME_absolute_get (),
46 "address_information", *i, buf, max); 51 buf, max);
47 (*i)--; 52 (*i)--;
48 return ret; 53 return ret;
49} 54}
50 55
51 56
52static int 57static int
53check_addr (void *cls, const char *tname, 58check_addr (void *cls, const struct GNUNET_HELLO_Address *address,
54 struct GNUNET_TIME_Absolute expiration, const void *addr, 59 struct GNUNET_TIME_Absolute expiration)
55 uint16_t addrlen)
56{ 60{
57 unsigned int *i = cls; 61 unsigned int *i = cls;
58 62
59#if DEBUG 63#if DEBUG
60 fprintf (stderr, "DEBUG: check_addr called with i = %d and addrlen = %u\n", 64 fprintf (stderr, "DEBUG: check_addr called with i = %d and addrlen = %u\n",
61 *i, addrlen); 65 *i, address->address_length);
62#endif 66#endif
63 GNUNET_assert (addrlen > 0); 67 GNUNET_assert (address->address_length > 0);
64 GNUNET_assert (*i & (1 << (addrlen - 1))); 68 GNUNET_assert (*i & (1 << (address->address_length - 1)));
65 *i -= (1 << (addrlen - 1)); 69 *i -= (1 << (address->address_length - 1));
66 GNUNET_assert (0 == strncmp ("address_information", addr, addrlen)); 70 GNUNET_assert (0 == strncmp ("address_information", address->address, address->address_length));
67 GNUNET_assert (0 == strcmp ("test", tname)); 71 GNUNET_assert (0 == strcmp ("test", address->transport_name));
68 return GNUNET_OK; 72 return GNUNET_OK;
69} 73}
70 74
71 75
72static int 76static int
73remove_some (void *cls, const char *tname, 77remove_some (void *cls, const struct GNUNET_HELLO_Address *address,
74 struct GNUNET_TIME_Absolute expiration, const void *addr, 78 struct GNUNET_TIME_Absolute expiration)
75 uint16_t addrlen)
76{ 79{
77 unsigned int *i = cls; 80 unsigned int *i = cls;
78 81
79#if DEBUG 82#if DEBUG
80 fprintf (stderr, "DEBUG: remove_some called with i = %d and addrlen = %u\n", 83 fprintf (stderr, "DEBUG: remove_some called with i = %d and addrlen = %u\n",
81 *i, addrlen); 84 *i, address->address_length);
82#endif 85#endif
83 GNUNET_assert (addrlen > 0); 86 GNUNET_assert (address->address_length > 0);
84 if (*i & (1 << (addrlen - 1))) 87 if (*i & (1 << (address->address_length - 1)))
85 { 88 {
86 *i -= (1 << (addrlen - 1)); 89 *i -= (1 << (address->address_length - 1));
87 return GNUNET_NO; 90 return GNUNET_NO;
88 } 91 }
89 return GNUNET_OK; 92 return GNUNET_OK;