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