aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-dht.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-03-18 21:19:10 +0000
committerNathan S. Evans <evans@in.tum.de>2010-03-18 21:19:10 +0000
commit72a844be131e93002257213893e4e377993f3cd8 (patch)
tree3b6ed2d9c968ee9e48b6a7ff7ad2aa8e6526fa70 /src/dht/gnunet-service-dht.c
parent40ff2323130e2cbe383f9b00fdb5ddfef995d347 (diff)
downloadgnunet-72a844be131e93002257213893e4e377993f3cd8.tar.gz
gnunet-72a844be131e93002257213893e4e377993f3cd8.zip
basic api to service communication has been hammered out, as well as service confirmations going back. still needs work, many things not finished.
Diffstat (limited to 'src/dht/gnunet-service-dht.c')
-rw-r--r--src/dht/gnunet-service-dht.c106
1 files changed, 74 insertions, 32 deletions
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index 215d39c44..2ff1384d7 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -86,13 +86,19 @@ struct ClientList
86}; 86};
87 87
88/** 88/**
89 * Server handler for initiating local dht get requests 89 * Server handler for handling locally received dht requests
90 */ 90 */
91static void handle_dht_plugin_message (void *cls, struct GNUNET_SERVER_Client * client, 91static void
92 const struct GNUNET_MessageHeader *message); 92handle_dht_start_message(void *cls, struct GNUNET_SERVER_Client * client,
93 const struct GNUNET_MessageHeader *message);
94
95static void
96handle_dht_stop_message(void *cls, struct GNUNET_SERVER_Client * client,
97 const struct GNUNET_MessageHeader *message);
93 98
94static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { 99static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = {
95 {&handle_dht_plugin_message, NULL, GNUNET_MESSAGE_TYPE_DHT, 0}, 100 {&handle_dht_start_message, NULL, GNUNET_MESSAGE_TYPE_DHT, 0},
101 {&handle_dht_stop_message, NULL, GNUNET_MESSAGE_TYPE_DHT_STOP, 0},
96/* {&handle_dht_get_stop, NULL, GNUNET_MESSAGE_TYPE_DHT_GET_STOP, 0}, 102/* {&handle_dht_get_stop, NULL, GNUNET_MESSAGE_TYPE_DHT_GET_STOP, 0},
97 {&handle_dht_put, NULL, GNUNET_MESSAGE_TYPE_DHT_PUT, 0}, 103 {&handle_dht_put, NULL, GNUNET_MESSAGE_TYPE_DHT_PUT, 0},
98 {&handle_dht_find_peer, NULL, GNUNET_MESSAGE_TYPE_DHT_FIND_PEER, 0}, 104 {&handle_dht_find_peer, NULL, GNUNET_MESSAGE_TYPE_DHT_FIND_PEER, 0},
@@ -203,10 +209,64 @@ static void handle_dht_put (void *cls, struct GNUNET_DHT_PutMessage *put_msg, GN
203 GNUNET_free(data); 209 GNUNET_free(data);
204} 210}
205 211
212/**
213 * Context for sending receipt confirmations. Not used yet.
214 */
215struct SendConfirmationContext
216{
217 /**
218 * The message to send.
219 */
220 struct GNUNET_DHT_StopMessage *message;
221
222 /**
223 * Transmit handle.
224 */
225 struct GNUNET_CONNECTION_TransmitHandle * transmit_handle;
226};
227
228size_t send_confirmation (void *cls,
229 size_t size, void *buf)
230{
231 struct GNUNET_DHT_StopMessage *confirmation_message = cls;
232
233 if (buf == NULL) /* Message timed out, that's crappy... */
234 {
235 GNUNET_free(confirmation_message);
236 return 0;
237 }
238
239 if (size >= ntohs(confirmation_message->header.size))
240 {
241 memcpy(buf, confirmation_message, ntohs(confirmation_message->header.size));
242 return ntohs(confirmation_message->header.size);
243 }
244 else
245 return 0;
246}
206 247
207static void 248static void
208handle_dht_start_message(void *cls, struct GNUNET_DHT_Message *dht_msg) 249send_client_receipt_confirmation(struct GNUNET_SERVER_Client *client, uint64_t uid)
209{ 250{
251 struct GNUNET_DHT_StopMessage *confirm_message;
252
253 confirm_message = GNUNET_malloc(sizeof(struct GNUNET_DHT_StopMessage));
254 confirm_message->header.type = htons(GNUNET_MESSAGE_TYPE_DHT_STOP);
255 confirm_message->header.size = htons(sizeof(struct GNUNET_DHT_StopMessage));
256 confirm_message->unique_id = GNUNET_htonll(uid);
257
258 GNUNET_SERVER_notify_transmit_ready (client,
259 sizeof(struct GNUNET_DHT_StopMessage),
260 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5),
261 &send_confirmation, confirm_message);
262
263}
264
265static void
266handle_dht_start_message(void *cls, struct GNUNET_SERVER_Client * client,
267 const struct GNUNET_MessageHeader *message)
268{
269 struct GNUNET_DHT_Message *dht_msg = (struct GNUNET_DHT_Message *)message;
210 struct GNUNET_MessageHeader *enc_msg; 270 struct GNUNET_MessageHeader *enc_msg;
211 size_t enc_type; 271 size_t enc_type;
212 272
@@ -216,7 +276,7 @@ handle_dht_start_message(void *cls, struct GNUNET_DHT_Message *dht_msg)
216 276
217#if DEBUG_DHT 277#if DEBUG_DHT
218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
219 "`%s': Received `%s' request from client, message type %d, key %s, uid %llu\n", "DHT", "GENERIC", enc_type, GNUNET_h2s(&dht_msg->key), ntohl(dht_msg->unique_id)); 279 "`%s': Received `%s' request from client, message type %d, key %s, uid %llu\n", "DHT", "GENERIC", enc_type, GNUNET_h2s(&dht_msg->key), GNUNET_ntohll(dht_msg->unique_id));
220#endif 280#endif
221 281
222 /* FIXME: Implement demultiplexing functionality here */ 282 /* FIXME: Implement demultiplexing functionality here */
@@ -238,44 +298,26 @@ handle_dht_start_message(void *cls, struct GNUNET_DHT_Message *dht_msg)
238#endif 298#endif
239 } 299 }
240 300
301 GNUNET_SERVER_receive_done(client, GNUNET_OK);
302
241} 303}
242 304
243 305
244static void 306static void
245handle_dht_stop_message(void *cls, struct GNUNET_DHT_StopMessage *dht_stop_msg) 307handle_dht_stop_message(void *cls, struct GNUNET_SERVER_Client * client,
308 const struct GNUNET_MessageHeader *message)
246{ 309{
310 struct GNUNET_DHT_StopMessage * dht_stop_msg = (struct GNUNET_DHT_StopMessage *)message;
247 311
248#if DEBUG_DHT 312#if DEBUG_DHT
249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
250 "`%s': Received `%s' request from client, uid %llu\n", "DHT", "GENERIC STOP", ntohl(dht_stop_msg->unique_id)); 314 "`%s': Received `%s' request from client, uid %llu\n", "DHT", "GENERIC STOP", GNUNET_ntohll(dht_stop_msg->unique_id));
251#endif
252}
253
254
255
256/**
257 * Server handler for initiating local dht get requests
258 */
259static void handle_dht_plugin_message (void *cls, struct GNUNET_SERVER_Client * client,
260 const struct GNUNET_MessageHeader *message)
261{
262
263 #if DEBUG_DHT
264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
265 "`%s': Received `%s' request from client, message type %d, size %d\n", "DHT", "GENERIC", ntohs(message->type), ntohs(message->size));
266#endif 315#endif
267 316 send_client_receipt_confirmation(client, GNUNET_ntohll(dht_stop_msg->unique_id));
268 switch(ntohs(message->type))
269 {
270 case GNUNET_MESSAGE_TYPE_DHT:
271 handle_dht_start_message(cls, (struct GNUNET_DHT_Message *)message);
272 case GNUNET_MESSAGE_TYPE_DHT_STOP:
273 handle_dht_stop_message(cls, (struct GNUNET_DHT_StopMessage *)message);
274 }
275
276 GNUNET_SERVER_receive_done(client, GNUNET_OK); 317 GNUNET_SERVER_receive_done(client, GNUNET_OK);
277} 318}
278 319
320
279/** 321/**
280 * Core handler for p2p dht get requests. 322 * Core handler for p2p dht get requests.
281 */ 323 */