aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo-tool/gnunet-peerinfo.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-03-19 15:00:11 +0000
committerChristian Grothoff <christian@grothoff.org>2010-03-19 15:00:11 +0000
commitc4de1a2663fa98e2e9837146306d315f0d1fcfe8 (patch)
treeb129a67de9f6c0fa2fe30d99c4d7566180f77b2e /src/peerinfo-tool/gnunet-peerinfo.c
parent0df346263a1bd8c4369258aa9b7de8336e2cf4f2 (diff)
downloadgnunet-c4de1a2663fa98e2e9837146306d315f0d1fcfe8.tar.gz
gnunet-c4de1a2663fa98e2e9837146306d315f0d1fcfe8.zip
fix
Diffstat (limited to 'src/peerinfo-tool/gnunet-peerinfo.c')
-rw-r--r--src/peerinfo-tool/gnunet-peerinfo.c97
1 files changed, 82 insertions, 15 deletions
diff --git a/src/peerinfo-tool/gnunet-peerinfo.c b/src/peerinfo-tool/gnunet-peerinfo.c
index c056b390e..63c5cc008 100644
--- a/src/peerinfo-tool/gnunet-peerinfo.c
+++ b/src/peerinfo-tool/gnunet-peerinfo.c
@@ -41,9 +41,40 @@ static struct GNUNET_SCHEDULER_Handle *sched;
41 41
42static const struct GNUNET_CONFIGURATION_Handle *cfg; 42static const struct GNUNET_CONFIGURATION_Handle *cfg;
43 43
44#define FIXME 0 44struct PrintContext
45{
46 struct GNUNET_PeerIdentity peer;
47 char **address_list;
48 unsigned int num_addresses;
49 uint32_t off;
50 uint32_t trust;
51};
52
53
54static void
55dump_pc (struct PrintContext *pc)
56{
57 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
58 unsigned int i;
59
60 GNUNET_CRYPTO_hash_to_enc (&pc->peer.hashPubKey, &enc);
61 printf (_("Peer `%s' with trust %8u\n"),
62 (const char *) &enc,
63 pc->trust);
64 for (i=0;i<pc->num_addresses;i++)
65 {
66 printf ("\t%s\n",
67 pc->address_list[i]);
68 GNUNET_free (pc->address_list[i]);
69 }
70 printf ("\n");
71 GNUNET_array_grow (pc->address_list,
72 pc->num_addresses,
73 0);
74 GNUNET_free (pc);
75}
76
45 77
46#if FIXME
47/** 78/**
48 * Function to call with a human-readable format of an address 79 * Function to call with a human-readable format of an address
49 * 80 *
@@ -51,18 +82,45 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
51 * @param address NULL on error, otherwise 0-terminated printable UTF-8 string 82 * @param address NULL on error, otherwise 0-terminated printable UTF-8 string
52 */ 83 */
53static void 84static void
54print_resolved_address (void *cls, 85process_resolved_address (void *cls,
55 const char *address) 86 const char *address)
56{ 87{
57 /* FIXME: need to buffer output from all requests and print it at 88 struct PrintContext *pc = cls;
58 once, otherwise we mix results... */ 89
59 if (address == NULL) 90 if (address == NULL)
60 { 91 {
92 pc->off--;
93 if (pc->off == 0)
94 dump_pc (pc);
61 return; 95 return;
62 } 96 }
63 fprintf (stderr, " %s\n", address); 97 GNUNET_array_append (pc->address_list,
98 pc->num_addresses,
99 GNUNET_strdup (address));
64} 100}
65#endif 101
102
103/**
104 * Iterator callback to go over all addresses.
105 *
106 * @param cls closure
107 * @param tname name of the transport
108 * @param expiration expiration time
109 * @param addr the address
110 * @param addrlen length of the address
111 * @return GNUNET_OK to keep the address and continue
112 */
113static int
114count_address (void *cls,
115 const char *tname,
116 struct GNUNET_TIME_Absolute expiration,
117 const void *addr, size_t addrlen)
118{
119 struct PrintContext *pc = cls;
120 pc->off++;
121 return GNUNET_OK;
122}
123
66 124
67/** 125/**
68 * Iterator callback to go over all addresses. 126 * Iterator callback to go over all addresses.
@@ -80,7 +138,7 @@ print_address (void *cls,
80 struct GNUNET_TIME_Absolute expiration, 138 struct GNUNET_TIME_Absolute expiration,
81 const void *addr, size_t addrlen) 139 const void *addr, size_t addrlen)
82{ 140{
83#if FIXME 141 struct PrintContext *pc = cls;
84 GNUNET_TRANSPORT_address_lookup (sched, 142 GNUNET_TRANSPORT_address_lookup (sched,
85 cfg, 143 cfg,
86 addr, 144 addr,
@@ -88,9 +146,8 @@ print_address (void *cls,
88 no_resolve, 146 no_resolve,
89 tname, 147 tname,
90 GNUNET_TIME_UNIT_SECONDS, 148 GNUNET_TIME_UNIT_SECONDS,
91 &print_resolved_address, 149 &process_resolved_address,
92 NULL); 150 pc);
93#endif
94 return GNUNET_OK; 151 return GNUNET_OK;
95} 152}
96 153
@@ -106,19 +163,29 @@ print_peer_info (void *cls,
106 const struct GNUNET_HELLO_Message *hello, uint32_t trust) 163 const struct GNUNET_HELLO_Message *hello, uint32_t trust)
107{ 164{
108 struct GNUNET_CRYPTO_HashAsciiEncoded enc; 165 struct GNUNET_CRYPTO_HashAsciiEncoded enc;
166 struct PrintContext *pc;
109 167
110 if (peer == NULL) 168 if (peer == NULL)
111 return; 169 return;
112 GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &enc);
113 if (be_quiet) 170 if (be_quiet)
114 { 171 {
172 GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &enc);
115 printf ("%s\n", (const char *) &enc); 173 printf ("%s\n", (const char *) &enc);
116 return; 174 return;
117 } 175 }
118 printf (_("Peer `%s' with trust %8u\n"), (const char *) &enc, trust); 176 pc = GNUNET_malloc (sizeof (struct PrintContext));
119 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &print_address, NULL); 177 pc->peer = *peer;
178 pc->trust = trust;
179 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &count_address, pc);
180 if (0 == pc->off)
181 {
182 dump_pc (pc);
183 return;
184 }
185 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &print_address, pc);
120} 186}
121 187
188
122/** 189/**
123 * Main function that will be run by the scheduler. 190 * Main function that will be run by the scheduler.
124 * 191 *