aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-dht-get-peer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/gnunet-dht-get-peer.c')
-rw-r--r--src/dht/gnunet-dht-get-peer.c88
1 files changed, 40 insertions, 48 deletions
diff --git a/src/dht/gnunet-dht-get-peer.c b/src/dht/gnunet-dht-get-peer.c
index 8d318efc2..6ca88d232 100644
--- a/src/dht/gnunet-dht-get-peer.c
+++ b/src/dht/gnunet-dht-get-peer.c
@@ -74,29 +74,25 @@ static unsigned int result_count;
74static int ret; 74static int ret;
75 75
76static void 76static void
77shutdown_task (void *cls, 77shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
78 const struct GNUNET_SCHEDULER_TaskContext *tc)
79{ 78{
80 if (dht_handle != NULL) 79 if (dht_handle != NULL)
81 { 80 {
82 GNUNET_DHT_disconnect (dht_handle); 81 GNUNET_DHT_disconnect (dht_handle);
83 dht_handle = NULL; 82 dht_handle = NULL;
84 } 83 }
85 fprintf (stderr, 84 fprintf (stderr, _("Found %u peers\n"), result_count);
86 _("Found %u peers\n"),
87 result_count);
88} 85}
89 86
90 87
91static void 88static void
92cleanup_task (void *cls, 89cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
93 const struct GNUNET_SCHEDULER_TaskContext *tc)
94{ 90{
95 if (find_peer_handle != NULL) 91 if (find_peer_handle != NULL)
96 { 92 {
97 GNUNET_DHT_find_peer_stop (find_peer_handle); 93 GNUNET_DHT_find_peer_stop (find_peer_handle);
98 find_peer_handle = NULL; 94 find_peer_handle = NULL;
99 } 95 }
100 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 96 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
101} 97}
102 98
@@ -107,20 +103,17 @@ cleanup_task (void *cls,
107 * @param cls closure (NULL) 103 * @param cls closure (NULL)
108 * @param hello the response message, a HELLO 104 * @param hello the response message, a HELLO
109 */ 105 */
110static void 106static void
111find_peer_processor (void *cls, 107find_peer_processor (void *cls, const struct GNUNET_HELLO_Message *hello)
112 const struct GNUNET_HELLO_Message *hello)
113{ 108{
114 struct GNUNET_PeerIdentity peer; 109 struct GNUNET_PeerIdentity peer;
115 110
116 if (GNUNET_OK == GNUNET_HELLO_get_id(hello, &peer)) 111 if (GNUNET_OK == GNUNET_HELLO_get_id (hello, &peer))
117 { 112 {
118 result_count++; 113 result_count++;
119 if (verbose) 114 if (verbose)
120 fprintf (stderr, 115 fprintf (stderr, _("Found peer `%s'\n"), GNUNET_i2s (&peer));
121 _("Found peer `%s'\n"), 116 }
122 GNUNET_i2s (&peer));
123 }
124} 117}
125 118
126 119
@@ -139,32 +132,33 @@ run (void *cls,
139{ 132{
140 struct GNUNET_TIME_Relative timeout; 133 struct GNUNET_TIME_Relative timeout;
141 GNUNET_HashCode key; 134 GNUNET_HashCode key;
135
142 cfg = c; 136 cfg = c;
143 137
144 if (query_key == NULL) 138 if (query_key == NULL)
145 { 139 {
146 if (verbose) 140 if (verbose)
147 fprintf (stderr, "Must provide key for DHT GET!\n"); 141 fprintf (stderr, "Must provide key for DHT GET!\n");
148 ret = 1; 142 ret = 1;
149 return; 143 return;
150 } 144 }
151 145
152 dht_handle = GNUNET_DHT_connect (cfg, 1); 146 dht_handle = GNUNET_DHT_connect (cfg, 1);
153 147
154 if (dht_handle == NULL) 148 if (dht_handle == NULL)
155 { 149 {
156 if (verbose) 150 if (verbose)
157 fprintf (stderr, "Couldn't connect to DHT service!\n"); 151 fprintf (stderr, "Couldn't connect to DHT service!\n");
158 ret = 1; 152 ret = 1;
159 return; 153 return;
160 } 154 }
161 else if (verbose) 155 else if (verbose)
162 fprintf (stderr, "Connected to DHT service!\n"); 156 fprintf (stderr, "Connected to DHT service!\n");
163 157
164 GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key); 158 GNUNET_CRYPTO_hash (query_key, strlen (query_key), &key);
165 159
166 timeout = 160 timeout =
167 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_request); 161 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_request);
168 absolute_timeout = GNUNET_TIME_relative_to_absolute (timeout); 162 absolute_timeout = GNUNET_TIME_relative_to_absolute (timeout);
169 163
170 if (verbose) 164 if (verbose)
@@ -173,17 +167,15 @@ run (void *cls,
173 find_peer_handle = GNUNET_DHT_find_peer_start (dht_handle, 167 find_peer_handle = GNUNET_DHT_find_peer_start (dht_handle,
174 timeout, 168 timeout,
175 &key, 169 &key,
176 GNUNET_DHT_RO_NONE, 170 GNUNET_DHT_RO_NONE,
177 &find_peer_processor, 171 &find_peer_processor, NULL);
178 NULL);
179 if (NULL == find_peer_handle) 172 if (NULL == find_peer_handle)
180 { 173 {
181 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); 174 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
182 return; 175 return;
183 } 176 }
184 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining 177 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
185 (absolute_timeout), 178 (absolute_timeout), &cleanup_task, NULL);
186 &cleanup_task, NULL);
187} 179}
188 180
189 181