diff options
Diffstat (limited to 'src/peerinfo/test_peerinfo_api_friend_only.c')
-rw-r--r-- | src/peerinfo/test_peerinfo_api_friend_only.c | 155 |
1 files changed, 77 insertions, 78 deletions
diff --git a/src/peerinfo/test_peerinfo_api_friend_only.c b/src/peerinfo/test_peerinfo_api_friend_only.c index d9d9200ac..a7bd69e6f 100644 --- a/src/peerinfo/test_peerinfo_api_friend_only.c +++ b/src/peerinfo/test_peerinfo_api_friend_only.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file peerinfo/test_peerinfo_api_friend_only.c | 22 | * @file peerinfo/test_peerinfo_api_friend_only.c |
@@ -46,9 +46,9 @@ static int global_ret; | |||
46 | 46 | ||
47 | 47 | ||
48 | static ssize_t | 48 | static ssize_t |
49 | address_generator (void *cls, | 49 | address_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,114 +56,113 @@ 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(GNUNET_TIME_UNIT_HOURS), |
67 | buf, | 67 | buf, |
68 | max); | 68 | max); |
69 | (*agc)--; | 69 | (*agc)--; |
70 | return ret; | 70 | return ret; |
71 | } | 71 | } |
72 | 72 | ||
73 | 73 | ||
74 | static void | 74 | static void |
75 | add_peer () | 75 | add_peer() |
76 | { | 76 | { |
77 | struct GNUNET_HELLO_Message *h2; | 77 | struct GNUNET_HELLO_Message *h2; |
78 | size_t agc; | 78 | size_t agc; |
79 | 79 | ||
80 | agc = 2; | 80 | agc = 2; |
81 | memset (&pid, 32, sizeof (pid)); | 81 | memset(&pid, 32, sizeof(pid)); |
82 | h2 = GNUNET_HELLO_create (&pid.public_key, | 82 | h2 = GNUNET_HELLO_create(&pid.public_key, |
83 | &address_generator, | 83 | &address_generator, |
84 | &agc, | 84 | &agc, |
85 | GNUNET_YES); | 85 | GNUNET_YES); |
86 | GNUNET_PEERINFO_add_peer (h, | 86 | GNUNET_PEERINFO_add_peer(h, |
87 | h2, | 87 | h2, |
88 | NULL, | 88 | NULL, |
89 | NULL); | 89 | NULL); |
90 | GNUNET_free (h2); | 90 | GNUNET_free(h2); |
91 | |||
92 | } | 91 | } |
93 | 92 | ||
94 | 93 | ||
95 | static void | 94 | static void |
96 | process (void *cls, | 95 | process(void *cls, |
97 | const struct GNUNET_PeerIdentity *peer, | 96 | const struct GNUNET_PeerIdentity *peer, |
98 | const struct GNUNET_HELLO_Message *hello, | 97 | const struct GNUNET_HELLO_Message *hello, |
99 | const char *err_msg) | 98 | const char *err_msg) |
100 | { | 99 | { |
101 | if (NULL != err_msg) | 100 | if (NULL != err_msg) |
102 | { | 101 | { |
103 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 102 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
104 | "Error in communication with PEERINFO service: %s\n", | 103 | "Error in communication with PEERINFO service: %s\n", |
105 | err_msg); | 104 | err_msg); |
106 | } | 105 | } |
107 | if (NULL == peer) | 106 | if (NULL == peer) |
108 | { | ||
109 | ic = NULL; | ||
110 | if ((3 == global_ret) && (retries < 50)) | ||
111 | { | 107 | { |
112 | /* try again */ | 108 | ic = NULL; |
113 | retries++; | 109 | if ((3 == global_ret) && (retries < 50)) |
114 | add_peer (); | 110 | { |
115 | ic = GNUNET_PEERINFO_iterate (h, | 111 | /* try again */ |
116 | GNUNET_NO, | 112 | retries++; |
117 | NULL, | 113 | add_peer(); |
118 | &process, | 114 | ic = GNUNET_PEERINFO_iterate(h, |
119 | cls); | 115 | GNUNET_NO, |
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; | ||
126 | } | ||
127 | |||
128 | if ((NULL != hello) && | ||
129 | (GNUNET_YES == GNUNET_HELLO_is_friend_only(hello))) | ||
130 | { | ||
131 | fprintf(stderr, | ||
132 | "Received friend-only HELLO\n"); | ||
133 | global_ret = 1; | ||
134 | GNUNET_PEERINFO_disconnect(h); | ||
135 | h = NULL; | ||
120 | return; | 136 | return; |
121 | } | 137 | } |
122 | GNUNET_assert (peer == NULL); | ||
123 | GNUNET_PEERINFO_disconnect (h); | ||
124 | h = NULL; | ||
125 | global_ret = 0; | ||
126 | return; | ||
127 | } | ||
128 | |||
129 | if ( (NULL != hello) && | ||
130 | (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ) | ||
131 | { | ||
132 | fprintf (stderr, | ||
133 | "Received friend-only HELLO\n"); | ||
134 | global_ret = 1; | ||
135 | GNUNET_PEERINFO_disconnect (h); | ||
136 | h = NULL; | ||
137 | return; | ||
138 | } | ||
139 | } | 138 | } |
140 | 139 | ||
141 | 140 | ||
142 | static void | 141 | static void |
143 | run (void *cls, | 142 | run(void *cls, |
144 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 143 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
145 | struct GNUNET_TESTING_Peer *peer) | 144 | struct GNUNET_TESTING_Peer *peer) |
146 | { | 145 | { |
147 | h = GNUNET_PEERINFO_connect (cfg); | 146 | h = GNUNET_PEERINFO_connect(cfg); |
148 | GNUNET_assert (NULL != h); | 147 | GNUNET_assert(NULL != h); |
149 | add_peer (); | 148 | add_peer(); |
150 | ic = GNUNET_PEERINFO_iterate (h, | 149 | ic = GNUNET_PEERINFO_iterate(h, |
151 | GNUNET_NO, | 150 | GNUNET_NO, |
152 | &pid, | 151 | &pid, |
153 | &process, | 152 | &process, |
154 | NULL); | 153 | NULL); |
155 | } | 154 | } |
156 | 155 | ||
157 | 156 | ||
158 | int | 157 | int |
159 | main (int argc, | 158 | main(int argc, |
160 | char *argv[]) | 159 | char *argv[]) |
161 | { | 160 | { |
162 | global_ret = 3; | 161 | global_ret = 3; |
163 | if (0 != GNUNET_TESTING_service_run ("test-peerinfo-api-friend-only", | 162 | if (0 != GNUNET_TESTING_service_run("test-peerinfo-api-friend-only", |
164 | "peerinfo", | 163 | "peerinfo", |
165 | "test_peerinfo_api_data.conf", | 164 | "test_peerinfo_api_data.conf", |
166 | &run, NULL)) | 165 | &run, NULL)) |
167 | return 1; | 166 | return 1; |
168 | return global_ret; | 167 | return global_ret; |
169 | } | 168 | } |