aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo/test_peerinfo_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/peerinfo/test_peerinfo_api.c')
-rw-r--r--src/peerinfo/test_peerinfo_api.c123
1 files changed, 62 insertions, 61 deletions
diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c
index 4c2184904..b13b9dc57 100644
--- a/src/peerinfo/test_peerinfo_api.c
+++ b/src/peerinfo/test_peerinfo_api.c
@@ -43,25 +43,25 @@ static int global_ret;
43 43
44 44
45static int 45static int
46check_it(void *cls, const struct GNUNET_HELLO_Address *address, 46check_it (void *cls, const struct GNUNET_HELLO_Address *address,
47 struct GNUNET_TIME_Absolute expiration) 47 struct GNUNET_TIME_Absolute expiration)
48{ 48{
49 unsigned int *agc = cls; 49 unsigned int *agc = cls;
50 50
51 if (address != NULL) 51 if (address != NULL)
52 { 52 {
53 GNUNET_assert(0 == strcmp("peerinfotest", address->transport_name)); 53 GNUNET_assert (0 == strcmp ("peerinfotest", address->transport_name));
54 GNUNET_assert(0 == 54 GNUNET_assert (0 ==
55 strncmp("Address", address->address, 55 strncmp ("Address", address->address,
56 address->address_length)); 56 address->address_length));
57 (*agc) -= (1 << (address->address_length - 1)); 57 (*agc) -= (1 << (address->address_length - 1));
58 } 58 }
59 return GNUNET_OK; 59 return GNUNET_OK;
60} 60}
61 61
62 62
63static ssize_t 63static ssize_t
64address_generator(void *cls, size_t max, void *buf) 64address_generator (void *cls, size_t max, void *buf)
65{ 65{
66 size_t *agc = cls; 66 size_t *agc = cls;
67 ssize_t ret; 67 ssize_t ret;
@@ -69,14 +69,14 @@ address_generator(void *cls, size_t max, void *buf)
69 69
70 if (0 == *agc) 70 if (0 == *agc)
71 return GNUNET_SYSERR; /* Done */ 71 return GNUNET_SYSERR; /* Done */
72 memset(&address.peer, 0, sizeof(struct GNUNET_PeerIdentity)); 72 memset (&address.peer, 0, sizeof(struct GNUNET_PeerIdentity));
73 address.address = "Address"; 73 address.address = "Address";
74 address.transport_name = "peerinfotest"; 74 address.transport_name = "peerinfotest";
75 address.address_length = *agc; 75 address.address_length = *agc;
76 ret = 76 ret =
77 GNUNET_HELLO_add_address(&address, 77 GNUNET_HELLO_add_address (&address,
78 GNUNET_TIME_relative_to_absolute 78 GNUNET_TIME_relative_to_absolute
79 (GNUNET_TIME_UNIT_HOURS), buf, max); 79 (GNUNET_TIME_UNIT_HOURS), buf, max);
80 (*agc)--; 80 (*agc)--;
81 return ret; 81 return ret;
82} 82}
@@ -84,84 +84,85 @@ address_generator(void *cls, size_t max, void *buf)
84struct GNUNET_PeerIdentity pid; 84struct GNUNET_PeerIdentity pid;
85 85
86static void 86static void
87add_peer() 87add_peer ()
88{ 88{
89 struct GNUNET_HELLO_Message *h2; 89 struct GNUNET_HELLO_Message *h2;
90 size_t agc; 90 size_t agc;
91 91
92 agc = 2; 92 agc = 2;
93 memset(&pid, 32, sizeof(pid)); 93 memset (&pid, 32, sizeof(pid));
94 h2 = GNUNET_HELLO_create(&pid.public_key, &address_generator, &agc, GNUNET_NO); 94 h2 = GNUNET_HELLO_create (&pid.public_key, &address_generator, &agc,
95 GNUNET_PEERINFO_add_peer(h, h2, NULL, NULL); 95 GNUNET_NO);
96 GNUNET_free(h2); 96 GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL);
97 GNUNET_free (h2);
97} 98}
98 99
99 100
100static void 101static void
101process(void *cls, const struct GNUNET_PeerIdentity *peer, 102process (void *cls, const struct GNUNET_PeerIdentity *peer,
102 const struct GNUNET_HELLO_Message *hello, const char *err_msg) 103 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
103{ 104{
104 unsigned int agc; 105 unsigned int agc;
105 106
106 if (err_msg != NULL) 107 if (err_msg != NULL)
107 { 108 {
108 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 109 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
109 _("Error in communication with PEERINFO service\n")); 110 _ ("Error in communication with PEERINFO service\n"));
110 } 111 }
111 112
112 if (peer == NULL) 113 if (peer == NULL)
114 {
115 ic = NULL;
116 if ((3 == global_ret) && (retries < 50))
113 { 117 {
114 ic = NULL; 118 /* try again */
115 if ((3 == global_ret) && (retries < 50)) 119 retries++;
116 { 120 add_peer ();
117 /* try again */ 121 ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, NULL,
118 retries++; 122 &process,
119 add_peer(); 123 cls);
120 ic = GNUNET_PEERINFO_iterate(h, GNUNET_NO, NULL,
121 &process,
122 cls);
123 return;
124 }
125 GNUNET_assert(peer == NULL);
126 GNUNET_assert(2 == global_ret);
127 GNUNET_PEERINFO_disconnect(h);
128 h = NULL;
129 global_ret = 0;
130 return; 124 return;
131 } 125 }
126 GNUNET_assert (peer == NULL);
127 GNUNET_assert (2 == global_ret);
128 GNUNET_PEERINFO_disconnect (h);
129 h = NULL;
130 global_ret = 0;
131 return;
132 }
132 if (hello != NULL) 133 if (hello != NULL)
133 { 134 {
134 GNUNET_assert(3 == global_ret); 135 GNUNET_assert (3 == global_ret);
135 agc = 3; 136 agc = 3;
136 GNUNET_HELLO_iterate_addresses(hello, GNUNET_NO, 137 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO,
137 &check_it, &agc); 138 &check_it, &agc);
138 GNUNET_assert(agc == 0); 139 GNUNET_assert (agc == 0);
139 global_ret = 2; 140 global_ret = 2;
140 } 141 }
141} 142}
142 143
143 144
144static void 145static void
145run(void *cls, 146run (void *cls,
146 const struct GNUNET_CONFIGURATION_Handle *cfg, 147 const struct GNUNET_CONFIGURATION_Handle *cfg,
147 struct GNUNET_TESTING_Peer *peer) 148 struct GNUNET_TESTING_Peer *peer)
148{ 149{
149 h = GNUNET_PEERINFO_connect(cfg); 150 h = GNUNET_PEERINFO_connect (cfg);
150 GNUNET_assert(NULL != h); 151 GNUNET_assert (NULL != h);
151 add_peer(); 152 add_peer ();
152 ic = GNUNET_PEERINFO_iterate(h, GNUNET_NO, &pid, 153 ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, &pid,
153 &process, cls); 154 &process, cls);
154} 155}
155 156
156 157
157int 158int
158main(int argc, char *argv[]) 159main (int argc, char *argv[])
159{ 160{
160 global_ret = 3; 161 global_ret = 3;
161 if (0 != GNUNET_TESTING_service_run("test-gnunet-peerinfo", 162 if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerinfo",
162 "peerinfo", 163 "peerinfo",
163 "test_peerinfo_api_data.conf", 164 "test_peerinfo_api_data.conf",
164 &run, NULL)) 165 &run, NULL))
165 return 1; 166 return 1;
166 return global_ret; 167 return global_ret;
167} 168}