aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo/test_peerinfo_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-01-18 09:45:40 +0000
committerChristian Grothoff <christian@grothoff.org>2010-01-18 09:45:40 +0000
commit260b2ebb0662c22d14f2482700c2211acb22b0d8 (patch)
tree94d4e3038d42cd9e8a0967407087c06ab6795811 /src/peerinfo/test_peerinfo_api.c
parent51ff626cb5d373cb7c066ad182af230f71c3ae01 (diff)
downloadgnunet-260b2ebb0662c22d14f2482700c2211acb22b0d8.tar.gz
gnunet-260b2ebb0662c22d14f2482700c2211acb22b0d8.zip
peerinfo fixes
Diffstat (limited to 'src/peerinfo/test_peerinfo_api.c')
-rw-r--r--src/peerinfo/test_peerinfo_api.c99
1 files changed, 68 insertions, 31 deletions
diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c
index 4cbbb7bf6..0b5230eb6 100644
--- a/src/peerinfo/test_peerinfo_api.c
+++ b/src/peerinfo/test_peerinfo_api.c
@@ -34,7 +34,13 @@
34#include "gnunet_peerinfo_service.h" 34#include "gnunet_peerinfo_service.h"
35#include "gnunet_program_lib.h" 35#include "gnunet_program_lib.h"
36#include "gnunet_time_lib.h" 36#include "gnunet_time_lib.h"
37#include "peerinfo.h"
37 38
39static struct GNUNET_SCHEDULER_Handle *sched;
40
41static const struct GNUNET_CONFIGURATION_Handle *cfg;
42
43static unsigned int retries;
38 44
39static int 45static int
40check_it (void *cls, 46check_it (void *cls,
@@ -54,6 +60,41 @@ check_it (void *cls,
54} 60}
55 61
56 62
63static size_t
64address_generator (void *cls, size_t max, void *buf)
65{
66 size_t *agc = cls;
67 size_t ret;
68
69 if (0 == *agc)
70 return 0;
71 ret = GNUNET_HELLO_add_address ("peerinfotest",
72 GNUNET_TIME_relative_to_absolute
73 (GNUNET_TIME_UNIT_HOURS), "Address", *agc,
74 buf, max);
75 (*agc)--;
76 return ret;
77}
78
79
80static void
81add_peer ()
82{
83 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
84 struct GNUNET_PeerIdentity pid;
85 struct GNUNET_HELLO_Message *h2;
86 size_t agc;
87
88 agc = 2;
89 memset (&pkey, 32, sizeof (pkey));
90 GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey);
91 h2 = GNUNET_HELLO_create (&pkey, &address_generator, &agc);
92 GNUNET_PEERINFO_add_peer (cfg, sched, &pid, h2);
93 GNUNET_free (h2);
94
95}
96
97
57static void 98static void
58process (void *cls, 99process (void *cls,
59 const struct GNUNET_PeerIdentity *peer, 100 const struct GNUNET_PeerIdentity *peer,
@@ -64,6 +105,21 @@ process (void *cls,
64 105
65 if (peer == NULL) 106 if (peer == NULL)
66 { 107 {
108 if ( (3 == *ok) &&
109 (retries < 5) )
110 {
111 /* try again */
112 retries++;
113 add_peer ();
114 GNUNET_PEERINFO_iterate (cfg,
115 sched,
116 NULL,
117 0,
118 GNUNET_TIME_relative_multiply
119 (GNUNET_TIME_UNIT_SECONDS, 15),
120 &process, cls);
121 return;
122 }
67 GNUNET_assert (peer == NULL); 123 GNUNET_assert (peer == NULL);
68 GNUNET_assert (2 == *ok); 124 GNUNET_assert (2 == *ok);
69 GNUNET_assert (trust == 0); 125 GNUNET_assert (trust == 0);
@@ -82,48 +138,22 @@ process (void *cls,
82} 138}
83 139
84 140
85static size_t
86address_generator (void *cls, size_t max, void *buf)
87{
88 size_t *agc = cls;
89 size_t ret;
90
91 if (0 == *agc)
92 return 0;
93 ret = GNUNET_HELLO_add_address ("peerinfotest",
94 GNUNET_TIME_relative_to_absolute
95 (GNUNET_TIME_UNIT_HOURS), "Address", *agc,
96 buf, max);
97 (*agc)--;
98 return ret;
99}
100
101
102static void 141static void
103run (void *cls, 142run (void *cls,
104 struct GNUNET_SCHEDULER_Handle *sched, 143 struct GNUNET_SCHEDULER_Handle *s,
105 char *const *args, 144 char *const *args,
106 const char *cfgfile, 145 const char *cfgfile,
107 const struct GNUNET_CONFIGURATION_Handle *cfg) 146 const struct GNUNET_CONFIGURATION_Handle *c)
108{ 147{
109 struct GNUNET_HELLO_Message *hello; 148 sched = s;
110 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; 149 cfg = c;
111 size_t agc; 150 add_peer ();
112 struct GNUNET_PeerIdentity pid;
113
114 memset (&pkey, 32, sizeof (pkey));
115 GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey);
116 agc = 2;
117 hello = GNUNET_HELLO_create (&pkey, &address_generator, &agc);
118 GNUNET_assert (hello != NULL);
119 GNUNET_PEERINFO_add_peer (cfg, sched, &pid, hello);
120 GNUNET_PEERINFO_iterate (cfg, 151 GNUNET_PEERINFO_iterate (cfg,
121 sched, 152 sched,
122 NULL, 153 NULL,
123 0, 154 0,
124 GNUNET_TIME_relative_multiply 155 GNUNET_TIME_relative_multiply
125 (GNUNET_TIME_UNIT_SECONDS, 15), &process, cls); 156 (GNUNET_TIME_UNIT_SECONDS, 15), &process, cls);
126 GNUNET_free (hello);
127} 157}
128 158
129 159
@@ -167,6 +197,13 @@ main (int argc, char *argv[])
167{ 197{
168 int ret = 0; 198 int ret = 0;
169 199
200 GNUNET_log_setup ("test_peerinfo_api",
201#if DEBUG_PEERINFO
202 "DEBUG",
203#else
204 "WARNING",
205#endif
206 NULL);
170 ret = check (); 207 ret = check ();
171 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-peerinfo"); 208 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-peerinfo");
172 return ret; 209 return ret;