diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-15 21:46:35 +0000 |
commit | 502af2167f7c218366666ca4944bd7cc54b5b19a (patch) | |
tree | a91fec5cc9769d260640bd91c6633cb9cf395524 /src/peerinfo-tool | |
parent | 03af5a603b7cc53432249d5854cd412aa90dde0d (diff) | |
download | gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip |
indentation
Diffstat (limited to 'src/peerinfo-tool')
-rw-r--r-- | src/peerinfo-tool/gnunet-peerinfo.c | 186 |
1 files changed, 88 insertions, 98 deletions
diff --git a/src/peerinfo-tool/gnunet-peerinfo.c b/src/peerinfo-tool/gnunet-peerinfo.c index 48cbb6038..951eecce8 100644 --- a/src/peerinfo-tool/gnunet-peerinfo.c +++ b/src/peerinfo-tool/gnunet-peerinfo.c | |||
@@ -57,18 +57,14 @@ dump_pc (struct PrintContext *pc) | |||
57 | unsigned int i; | 57 | unsigned int i; |
58 | 58 | ||
59 | GNUNET_CRYPTO_hash_to_enc (&pc->peer.hashPubKey, &enc); | 59 | GNUNET_CRYPTO_hash_to_enc (&pc->peer.hashPubKey, &enc); |
60 | printf (_("Peer `%s'\n"), | 60 | printf (_("Peer `%s'\n"), (const char *) &enc); |
61 | (const char *) &enc); | 61 | for (i = 0; i < pc->num_addresses; i++) |
62 | for (i=0;i<pc->num_addresses;i++) | 62 | { |
63 | { | 63 | printf ("\t%s\n", pc->address_list[i]); |
64 | printf ("\t%s\n", | 64 | GNUNET_free (pc->address_list[i]); |
65 | pc->address_list[i]); | 65 | } |
66 | GNUNET_free (pc->address_list[i]); | ||
67 | } | ||
68 | printf ("\n"); | 66 | printf ("\n"); |
69 | GNUNET_array_grow (pc->address_list, | 67 | GNUNET_array_grow (pc->address_list, pc->num_addresses, 0); |
70 | pc->num_addresses, | ||
71 | 0); | ||
72 | GNUNET_free (pc); | 68 | GNUNET_free (pc); |
73 | } | 69 | } |
74 | 70 | ||
@@ -80,21 +76,19 @@ dump_pc (struct PrintContext *pc) | |||
80 | * @param address NULL on error, otherwise 0-terminated printable UTF-8 string | 76 | * @param address NULL on error, otherwise 0-terminated printable UTF-8 string |
81 | */ | 77 | */ |
82 | static void | 78 | static void |
83 | process_resolved_address (void *cls, | 79 | process_resolved_address (void *cls, const char *address) |
84 | const char *address) | ||
85 | { | 80 | { |
86 | struct PrintContext *pc = cls; | 81 | struct PrintContext *pc = cls; |
87 | 82 | ||
88 | if (address == NULL) | 83 | if (address == NULL) |
89 | { | 84 | { |
90 | pc->off--; | 85 | pc->off--; |
91 | if (pc->off == 0) | 86 | if (pc->off == 0) |
92 | dump_pc (pc); | 87 | dump_pc (pc); |
93 | return; | 88 | return; |
94 | } | 89 | } |
95 | GNUNET_array_append (pc->address_list, | 90 | GNUNET_array_append (pc->address_list, |
96 | pc->num_addresses, | 91 | pc->num_addresses, GNUNET_strdup (address)); |
97 | GNUNET_strdup (address)); | ||
98 | } | 92 | } |
99 | 93 | ||
100 | 94 | ||
@@ -110,11 +104,12 @@ process_resolved_address (void *cls, | |||
110 | */ | 104 | */ |
111 | static int | 105 | static int |
112 | count_address (void *cls, | 106 | count_address (void *cls, |
113 | const char *tname, | 107 | const char *tname, |
114 | struct GNUNET_TIME_Absolute expiration, | 108 | struct GNUNET_TIME_Absolute expiration, |
115 | const void *addr, uint16_t addrlen) | 109 | const void *addr, uint16_t addrlen) |
116 | { | 110 | { |
117 | struct PrintContext *pc = cls; | 111 | struct PrintContext *pc = cls; |
112 | |||
118 | pc->off++; | 113 | pc->off++; |
119 | return GNUNET_OK; | 114 | return GNUNET_OK; |
120 | } | 115 | } |
@@ -132,19 +127,20 @@ count_address (void *cls, | |||
132 | */ | 127 | */ |
133 | static int | 128 | static int |
134 | print_address (void *cls, | 129 | print_address (void *cls, |
135 | const char *tname, | 130 | const char *tname, |
136 | struct GNUNET_TIME_Absolute expiration, | 131 | struct GNUNET_TIME_Absolute expiration, |
137 | const void *addr, uint16_t addrlen) | 132 | const void *addr, uint16_t addrlen) |
138 | { | 133 | { |
139 | struct PrintContext *pc = cls; | 134 | struct PrintContext *pc = cls; |
135 | |||
140 | GNUNET_TRANSPORT_address_lookup (cfg, | 136 | GNUNET_TRANSPORT_address_lookup (cfg, |
141 | addr, | 137 | addr, |
142 | addrlen, | 138 | addrlen, |
143 | no_resolve, | 139 | no_resolve, |
144 | tname, | 140 | tname, |
145 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), | 141 | GNUNET_TIME_relative_multiply |
146 | &process_resolved_address, | 142 | (GNUNET_TIME_UNIT_SECONDS, 10), |
147 | pc); | 143 | &process_resolved_address, pc); |
148 | return GNUNET_OK; | 144 | return GNUNET_OK; |
149 | } | 145 | } |
150 | 146 | ||
@@ -157,32 +153,32 @@ print_address (void *cls, | |||
157 | static void | 153 | static void |
158 | print_peer_info (void *cls, | 154 | print_peer_info (void *cls, |
159 | const struct GNUNET_PeerIdentity *peer, | 155 | const struct GNUNET_PeerIdentity *peer, |
160 | const struct GNUNET_HELLO_Message *hello, | 156 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) |
161 | const char * err_msg) | ||
162 | { | 157 | { |
163 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; | 158 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; |
164 | struct PrintContext *pc; | 159 | struct PrintContext *pc; |
165 | 160 | ||
166 | if (peer == NULL) | 161 | if (peer == NULL) |
167 | { | 162 | { |
168 | if (err_msg != NULL) fprintf (stderr,_("Error in communication with PEERINFO service\n")); | 163 | if (err_msg != NULL) |
169 | GNUNET_PEERINFO_disconnect (peerinfo); | 164 | fprintf (stderr, _("Error in communication with PEERINFO service\n")); |
170 | return; | 165 | GNUNET_PEERINFO_disconnect (peerinfo); |
171 | } | 166 | return; |
167 | } | ||
172 | if (be_quiet) | 168 | if (be_quiet) |
173 | { | 169 | { |
174 | GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &enc); | 170 | GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &enc); |
175 | printf ("%s\n", (const char *) &enc); | 171 | printf ("%s\n", (const char *) &enc); |
176 | return; | 172 | return; |
177 | } | 173 | } |
178 | pc = GNUNET_malloc (sizeof (struct PrintContext)); | 174 | pc = GNUNET_malloc (sizeof (struct PrintContext)); |
179 | pc->peer = *peer; | 175 | pc->peer = *peer; |
180 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &count_address, pc); | 176 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &count_address, pc); |
181 | if (0 == pc->off) | 177 | if (0 == pc->off) |
182 | { | 178 | { |
183 | dump_pc (pc); | 179 | dump_pc (pc); |
184 | return; | 180 | return; |
185 | } | 181 | } |
186 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &print_address, pc); | 182 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &print_address, pc); |
187 | } | 183 | } |
188 | 184 | ||
@@ -198,8 +194,7 @@ print_peer_info (void *cls, | |||
198 | static void | 194 | static void |
199 | run (void *cls, | 195 | run (void *cls, |
200 | char *const *args, | 196 | char *const *args, |
201 | const char *cfgfile, | 197 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) |
202 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
203 | { | 198 | { |
204 | struct GNUNET_CRYPTO_RsaPrivateKey *priv; | 199 | struct GNUNET_CRYPTO_RsaPrivateKey *priv; |
205 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; | 200 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; |
@@ -209,57 +204,52 @@ run (void *cls, | |||
209 | 204 | ||
210 | cfg = c; | 205 | cfg = c; |
211 | if (args[0] != NULL) | 206 | if (args[0] != NULL) |
212 | { | 207 | { |
213 | fprintf (stderr, | 208 | fprintf (stderr, _("Invalid command line argument `%s'\n"), args[0]); |
214 | _("Invalid command line argument `%s'\n"), | 209 | return; |
215 | args[0]); | 210 | } |
216 | return; | ||
217 | } | ||
218 | if (get_self != GNUNET_YES) | 211 | if (get_self != GNUNET_YES) |
212 | { | ||
213 | peerinfo = GNUNET_PEERINFO_connect (cfg); | ||
214 | if (peerinfo == NULL) | ||
219 | { | 215 | { |
220 | peerinfo = GNUNET_PEERINFO_connect (cfg); | 216 | fprintf (stderr, _("Could not access PEERINFO service. Exiting.\n")); |
221 | if (peerinfo == NULL) | 217 | return; |
222 | { | ||
223 | fprintf (stderr, | ||
224 | _("Could not access PEERINFO service. Exiting.\n")); | ||
225 | return; | ||
226 | } | ||
227 | GNUNET_PEERINFO_iterate (peerinfo, | ||
228 | NULL, | ||
229 | GNUNET_TIME_relative_multiply | ||
230 | (GNUNET_TIME_UNIT_SECONDS, 5), | ||
231 | &print_peer_info, NULL); | ||
232 | } | 218 | } |
219 | GNUNET_PEERINFO_iterate (peerinfo, | ||
220 | NULL, | ||
221 | GNUNET_TIME_relative_multiply | ||
222 | (GNUNET_TIME_UNIT_SECONDS, 5), | ||
223 | &print_peer_info, NULL); | ||
224 | } | ||
233 | else | 225 | else |
226 | { | ||
227 | if (GNUNET_OK != | ||
228 | GNUNET_CONFIGURATION_get_value_filename (cfg, | ||
229 | "GNUNETD", "HOSTKEY", &fn)) | ||
230 | { | ||
231 | fprintf (stderr, | ||
232 | _("Could not find option `%s:%s' in configuration.\n"), | ||
233 | "GNUNETD", "HOSTKEYFILE"); | ||
234 | return; | ||
235 | } | ||
236 | priv = GNUNET_CRYPTO_rsa_key_create_from_file (fn); | ||
237 | if (priv == NULL) | ||
234 | { | 238 | { |
235 | if (GNUNET_OK != | 239 | fprintf (stderr, _("Loading hostkey from `%s' failed.\n"), fn); |
236 | GNUNET_CONFIGURATION_get_value_filename (cfg, | ||
237 | "GNUNETD", | ||
238 | "HOSTKEY", &fn)) | ||
239 | { | ||
240 | fprintf (stderr, | ||
241 | _("Could not find option `%s:%s' in configuration.\n"), | ||
242 | "GNUNETD", | ||
243 | "HOSTKEYFILE"); | ||
244 | return; | ||
245 | } | ||
246 | priv = GNUNET_CRYPTO_rsa_key_create_from_file (fn); | ||
247 | if (priv == NULL) | ||
248 | { | ||
249 | fprintf (stderr, _("Loading hostkey from `%s' failed.\n"), fn); | ||
250 | GNUNET_free (fn); | ||
251 | return; | ||
252 | } | ||
253 | GNUNET_free (fn); | 240 | GNUNET_free (fn); |
254 | GNUNET_CRYPTO_rsa_key_get_public (priv, &pub); | 241 | return; |
255 | GNUNET_CRYPTO_rsa_key_free (priv); | ||
256 | GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey); | ||
257 | GNUNET_CRYPTO_hash_to_enc (&pid.hashPubKey, &enc); | ||
258 | if (be_quiet) | ||
259 | printf ("%s\n", (char *) &enc); | ||
260 | else | ||
261 | printf (_("I am peer `%s'.\n"), (const char *) &enc); | ||
262 | } | 242 | } |
243 | GNUNET_free (fn); | ||
244 | GNUNET_CRYPTO_rsa_key_get_public (priv, &pub); | ||
245 | GNUNET_CRYPTO_rsa_key_free (priv); | ||
246 | GNUNET_CRYPTO_hash (&pub, sizeof (pub), &pid.hashPubKey); | ||
247 | GNUNET_CRYPTO_hash_to_enc (&pid.hashPubKey, &enc); | ||
248 | if (be_quiet) | ||
249 | printf ("%s\n", (char *) &enc); | ||
250 | else | ||
251 | printf (_("I am peer `%s'.\n"), (const char *) &enc); | ||
252 | } | ||
263 | } | 253 | } |
264 | 254 | ||
265 | 255 | ||