diff options
Diffstat (limited to 'src/core/gnunet-core-list-connections.c')
-rw-r--r-- | src/core/gnunet-core-list-connections.c | 84 |
1 files changed, 40 insertions, 44 deletions
diff --git a/src/core/gnunet-core-list-connections.c b/src/core/gnunet-core-list-connections.c index 8b0f6773a..284a79f69 100644 --- a/src/core/gnunet-core-list-connections.c +++ b/src/core/gnunet-core-list-connections.c | |||
@@ -36,7 +36,7 @@ | |||
36 | static int no_resolve; | 36 | static int no_resolve; |
37 | 37 | ||
38 | #if VERBOSE | 38 | #if VERBOSE |
39 | static unsigned int peer_count; | 39 | static unsigned int peer_count; |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 42 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
@@ -74,15 +74,15 @@ dump_pc (struct PrintContext *pc) | |||
74 | struct AddressStringList *address; | 74 | struct AddressStringList *address; |
75 | 75 | ||
76 | GNUNET_CRYPTO_hash_to_enc (&pc->peer.hashPubKey, &enc); | 76 | GNUNET_CRYPTO_hash_to_enc (&pc->peer.hashPubKey, &enc); |
77 | printf (_("Peer `%s'\n"), | 77 | printf (_("Peer `%s'\n"), (const char *) &enc); |
78 | (const char *) &enc); | ||
79 | while (NULL != (address = pc->address_list_head)) | 78 | while (NULL != (address = pc->address_list_head)) |
80 | { | 79 | { |
81 | printf ("\t%s\n", address->address_string); | 80 | printf ("\t%s\n", address->address_string); |
82 | GNUNET_free(address->address_string); | 81 | GNUNET_free (address->address_string); |
83 | GNUNET_CONTAINER_DLL_remove(pc->address_list_head, pc->address_list_tail, address); | 82 | GNUNET_CONTAINER_DLL_remove (pc->address_list_head, pc->address_list_tail, |
84 | GNUNET_free(address); | 83 | address); |
85 | } | 84 | GNUNET_free (address); |
85 | } | ||
86 | 86 | ||
87 | printf ("\n"); | 87 | printf ("\n"); |
88 | 88 | ||
@@ -97,24 +97,24 @@ dump_pc (struct PrintContext *pc) | |||
97 | * @param address NULL on error, otherwise 0-terminated printable UTF-8 string | 97 | * @param address NULL on error, otherwise 0-terminated printable UTF-8 string |
98 | */ | 98 | */ |
99 | static void | 99 | static void |
100 | process_resolved_address (void *cls, | 100 | process_resolved_address (void *cls, const char *address) |
101 | const char *address) | ||
102 | { | 101 | { |
103 | struct PrintContext *pc = cls; | 102 | struct PrintContext *pc = cls; |
104 | struct AddressStringList *new_address; | 103 | struct AddressStringList *new_address; |
105 | 104 | ||
106 | if (address == NULL) | 105 | if (address == NULL) |
107 | { | 106 | { |
108 | dump_pc (pc); | 107 | dump_pc (pc); |
109 | return; | 108 | return; |
110 | } | 109 | } |
111 | 110 | ||
112 | new_address = GNUNET_malloc(sizeof(struct AddressStringList)); | 111 | new_address = GNUNET_malloc (sizeof (struct AddressStringList)); |
113 | #if VERBOSE | 112 | #if VERBOSE |
114 | fprintf(stderr, "Received address %s\n", address); | 113 | fprintf (stderr, "Received address %s\n", address); |
115 | #endif | 114 | #endif |
116 | new_address->address_string = GNUNET_strdup(address); | 115 | new_address->address_string = GNUNET_strdup (address); |
117 | GNUNET_CONTAINER_DLL_insert(pc->address_list_head, pc->address_list_tail, new_address); | 116 | GNUNET_CONTAINER_DLL_insert (pc->address_list_head, pc->address_list_tail, |
117 | new_address); | ||
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
@@ -127,23 +127,23 @@ connected_peer_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
127 | { | 127 | { |
128 | struct PrintContext *pc; | 128 | struct PrintContext *pc; |
129 | 129 | ||
130 | if (peer != NULL) /* Not yet finished */ | 130 | if (peer != NULL) /* Not yet finished */ |
131 | { | 131 | { |
132 | #if VERBOSE | 132 | #if VERBOSE |
133 | fprintf(stderr, "Learned about peer %s\n", GNUNET_i2s(peer)); | 133 | fprintf (stderr, "Learned about peer %s\n", GNUNET_i2s (peer)); |
134 | peer_count++; | 134 | peer_count++; |
135 | #endif | 135 | #endif |
136 | pc = GNUNET_malloc (sizeof (struct PrintContext)); | 136 | pc = GNUNET_malloc (sizeof (struct PrintContext)); |
137 | pc->peer = *peer; | 137 | pc->peer = *peer; |
138 | GNUNET_TRANSPORT_peer_address_lookup (cfg, peer, | 138 | GNUNET_TRANSPORT_peer_address_lookup (cfg, peer, |
139 | GNUNET_TIME_UNIT_MINUTES, | 139 | GNUNET_TIME_UNIT_MINUTES, |
140 | &process_resolved_address, pc); | 140 | &process_resolved_address, pc); |
141 | } | 141 | } |
142 | #if VERBOSE | 142 | #if VERBOSE |
143 | else | 143 | else |
144 | { | 144 | { |
145 | fprintf(stderr, "Counted %u total connected peers.\n", peer_count); | 145 | fprintf (stderr, "Counted %u total connected peers.\n", peer_count); |
146 | } | 146 | } |
147 | #endif | 147 | #endif |
148 | } | 148 | } |
149 | 149 | ||
@@ -159,22 +159,17 @@ connected_peer_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
159 | static void | 159 | static void |
160 | run (void *cls, | 160 | run (void *cls, |
161 | char *const *args, | 161 | char *const *args, |
162 | const char *cfgfile, | 162 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) |
163 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
164 | { | 163 | { |
165 | 164 | ||
166 | cfg = c; | 165 | cfg = c; |
167 | if (args[0] != NULL) | 166 | if (args[0] != NULL) |
168 | { | 167 | { |
169 | fprintf (stderr, | 168 | fprintf (stderr, _("Invalid command line argument `%s'\n"), args[0]); |
170 | _("Invalid command line argument `%s'\n"), | 169 | return; |
171 | args[0]); | 170 | } |
172 | return; | ||
173 | } | ||
174 | 171 | ||
175 | GNUNET_CORE_iterate_peers (cfg, | 172 | GNUNET_CORE_iterate_peers (cfg, &connected_peer_callback, NULL); |
176 | &connected_peer_callback, | ||
177 | NULL); | ||
178 | 173 | ||
179 | } | 174 | } |
180 | 175 | ||
@@ -199,7 +194,8 @@ main (int argc, char *const *argv) | |||
199 | GNUNET_PROGRAM_run (argc, | 194 | GNUNET_PROGRAM_run (argc, |
200 | argv, | 195 | argv, |
201 | "gnunet-list-connections", | 196 | "gnunet-list-connections", |
202 | gettext_noop ("Print information about connected peers."), | 197 | gettext_noop |
198 | ("Print information about connected peers."), | ||
203 | options, &run, NULL)) ? 0 : 1; | 199 | options, &run, NULL)) ? 0 : 1; |
204 | } | 200 | } |
205 | 201 | ||