From: Nathan S. Evans Date: Tue, 10 Aug 2010 16:24:53 +0000 (+0000) Subject: api change to allow client to set DHT malicious, still need to implement it on the... X-Git-Tag: initial-import-from-subversion-38251~20717 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=cab00729856bdbe0c60f298a79b1f12aac2aee8b;p=oweals%2Fgnunet.git api change to allow client to set DHT malicious, still need to implement it on the dht driver side --- diff --git a/src/dht/dht.h b/src/dht/dht.h index aeb65a99b..ada628bff 100644 --- a/src/dht/dht.h +++ b/src/dht/dht.h @@ -61,6 +61,23 @@ typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls, const struct GNUNET_MessageHeader *msg); +struct GNUNET_DHT_ControlMessage +{ + /** + * Type: GNUNET_MESSAGE_TYPE_DHT_CONTROL + */ + struct GNUNET_MessageHeader header; + + /** + * Command code of the message. + */ + uint16_t command; + + /** + * Variable parameter for the command. + */ + uint16_t variable; +}; /** * Message which indicates the DHT should cancel outstanding diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index 729905a77..aaa5acb5e 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c @@ -825,7 +825,148 @@ find_peer_reply_iterator (void *cls, const struct GNUNET_MessageHeader *reply) } /** - * Perform an asynchronous FIND_PEER operation on the DHT. + * Send a message to the DHT telling it to start issuing random GET + * requests every 'frequency' milliseconds. + * + * @param handle handle to the DHT service + * @param frequency delay (in milliseconds) between sending malicious messages + * @param cont continuation to call once the message is sent + * @param cont_cls closure for continuation + * + * @return GNUNET_YES if the control message was sent, GNUNET_NO if not + */ +int GNUNET_DHT_set_malicious_getter (struct GNUNET_DHT_Handle *handle, int frequency, GNUNET_SCHEDULER_Task cont, void *cont_cls) +{ + struct GNUNET_DHT_ControlMessage *msg; + struct PendingMessage *pending; + + if ((handle->current != NULL) && (handle->retransmit_stage != DHT_RETRANSMITTING)) + return GNUNET_NO; + + msg = GNUNET_malloc(sizeof(struct GNUNET_DHT_ControlMessage)); + msg->header.size = htons(sizeof(struct GNUNET_DHT_ControlMessage)); + msg->header.type = htons(GNUNET_MESSAGE_TYPE_DHT_CONTROL); + msg->command = htons(GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET); + msg->variable = htons(frequency); + + pending = GNUNET_malloc (sizeof (struct PendingMessage)); + pending->msg = &msg->header; + pending->timeout = GNUNET_TIME_relative_get_forever(); + pending->free_on_send = GNUNET_YES; + pending->cont = cont; + pending->cont_cls = cont_cls; + pending->unique_id = 0; + + if (handle->current == NULL) + { + handle->current = pending; + process_pending_message (handle); + } + else + { + handle->retransmit_stage = DHT_RETRANSMITTING_MESSAGE_QUEUED; + handle->retransmission_buffer = pending; + } + + return GNUNET_YES; +} + +/** + * Send a message to the DHT telling it to start issuing random PUT + * requests every 'frequency' milliseconds. + * + * @param handle handle to the DHT service + * @param frequency delay (in milliseconds) between sending malicious messages + * @param cont continuation to call once the message is sent + * @param cont_cls closure for continuation + * + * @return GNUNET_YES if the control message was sent, GNUNET_NO if not + */ +int GNUNET_DHT_set_malicious_putter (struct GNUNET_DHT_Handle *handle, int frequency, GNUNET_SCHEDULER_Task cont, void *cont_cls) +{ + struct GNUNET_DHT_ControlMessage *msg; + struct PendingMessage *pending; + + if ((handle->current != NULL) && (handle->retransmit_stage != DHT_RETRANSMITTING)) + return GNUNET_NO; + + msg = GNUNET_malloc(sizeof(struct GNUNET_DHT_ControlMessage)); + msg->header.size = htons(sizeof(struct GNUNET_DHT_ControlMessage)); + msg->header.type = htons(GNUNET_MESSAGE_TYPE_DHT_CONTROL); + msg->command = htons(GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT); + msg->variable = htons(frequency); + + pending = GNUNET_malloc (sizeof (struct PendingMessage)); + pending->msg = &msg->header; + pending->timeout = GNUNET_TIME_relative_get_forever(); + pending->free_on_send = GNUNET_YES; + pending->cont = cont; + pending->cont_cls = cont_cls; + pending->unique_id = 0; + + if (handle->current == NULL) + { + handle->current = pending; + process_pending_message (handle); + } + else + { + handle->retransmit_stage = DHT_RETRANSMITTING_MESSAGE_QUEUED; + handle->retransmission_buffer = pending; + } + + return GNUNET_YES; +} + +/** + * Send a message to the DHT telling it to start dropping + * all requests received. + * + * @param handle handle to the DHT service + * @param cont continuation to call once the message is sent + * @param cont_cls closure for continuation + * + * @return GNUNET_YES if the control message was sent, GNUNET_NO if not + */ +int GNUNET_DHT_set_malicious_dropper (struct GNUNET_DHT_Handle *handle, GNUNET_SCHEDULER_Task cont, void *cont_cls) +{ + struct GNUNET_DHT_ControlMessage *msg; + struct PendingMessage *pending; + + if ((handle->current != NULL) && (handle->retransmit_stage != DHT_RETRANSMITTING)) + return GNUNET_NO; + + msg = GNUNET_malloc(sizeof(struct GNUNET_DHT_ControlMessage)); + msg->header.size = htons(sizeof(struct GNUNET_DHT_ControlMessage)); + msg->header.type = htons(GNUNET_MESSAGE_TYPE_DHT_CONTROL); + msg->command = htons(GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP); + msg->variable = htons(0); + + pending = GNUNET_malloc (sizeof (struct PendingMessage)); + pending->msg = &msg->header; + pending->timeout = GNUNET_TIME_relative_get_forever(); + pending->free_on_send = GNUNET_YES; + pending->cont = cont; + pending->cont_cls = cont_cls; + pending->unique_id = 0; + + if (handle->current == NULL) + { + handle->current = pending; + process_pending_message (handle); + } + else + { + handle->retransmit_stage = DHT_RETRANSMITTING_MESSAGE_QUEUED; + handle->retransmission_buffer = pending; + } + + return GNUNET_YES; +} + + +/** + * Initiate a generic DHT route operation. * * @param handle handle to the DHT service * @param key the key to look up diff --git a/src/dht/gnunet-dht-driver.c b/src/dht/gnunet-dht-driver.c index 2254e8e79..c2b618218 100644 --- a/src/dht/gnunet-dht-driver.c +++ b/src/dht/gnunet-dht-driver.c @@ -583,7 +583,7 @@ static int stats_handle (void *cls, int is_persistent) { struct StatisticsIteratorContext *stats_ctx; - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s:%s -- %llu\n", GNUNET_i2s(peer), subsystem, name, value); + if (GNUNET_CONTAINER_multihashmap_contains(stats_map, &peer->hashPubKey)) { stats_ctx = GNUNET_CONTAINER_multihashmap_get(stats_map, &peer->hashPubKey); diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c index 33c85c7d4..3f58088bd 100644 --- a/src/dht/gnunet-service-dht.c +++ b/src/dht/gnunet-service-dht.c @@ -2401,6 +2401,30 @@ find_active_client (struct GNUNET_SERVER_Client *client) return ret; } +/** + * Task to send a malicious put message across the network. + * + * @param cls closure for this task + * @param tc the context under which the task is running + */ +static void +malicious_put_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + return; +} + +/** + * Task to send a malicious put message across the network. + * + * @param cls closure for this task + * @param tc the context under which the task is running + */ +static void +malicious_get_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + return; +} + /** * Task to send a find peer message for our own peer identifier * so that we can find the closest peers in the network to ourselves @@ -2499,6 +2523,56 @@ handle_dht_local_route_request (void *cls, struct GNUNET_SERVER_Client *client, } +/** + * Handler for any locally received DHT control messages, + * sets malicious flags mostly for now. + * + * @param cls closure for the service + * @param client the client we received this message from + * @param message the actual message received + * + */ +static void +handle_dht_control_message (void *cls, struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ + const struct GNUNET_DHT_ControlMessage *dht_control_msg = + (const struct GNUNET_DHT_ControlMessage *) message; +#if DEBUG_DHT + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "`%s:%s': Received `%s' request from client, command %d\n", my_short_id, "DHT", + "CONTROL", ntohs(dht_control_msg->command)); +#endif + + switch (ntohs(dht_control_msg->command)) + { + case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_GET: + if (ntohs(dht_control_msg->variable) > 0) + malicious_get_frequency = ntohs(dht_control_msg->variable); + if (malicious_getter != GNUNET_YES) + GNUNET_SCHEDULER_add_now(sched, &malicious_get_task, NULL); + malicious_getter = GNUNET_YES; + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Initiating malicious GET behavior, frequency %d\n", my_short_id, "DHT", malicious_get_frequency); + break; + case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_PUT: + if (ntohs(dht_control_msg->variable) > 0) + malicious_put_frequency = ntohs(dht_control_msg->variable); + if (malicious_putter != GNUNET_YES) + GNUNET_SCHEDULER_add_now(sched, &malicious_put_task, NULL); + malicious_putter = GNUNET_YES; + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Initiating malicious PUT behavior, frequency %d\n", my_short_id, "DHT", malicious_put_frequency); + break; + case GNUNET_MESSAGE_TYPE_DHT_MALICIOUS_DROP: + malicious_dropper = GNUNET_YES; + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Initiating malicious DROP behavior\n", my_short_id, "DHT"); + break; + default: + GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s:%s Unknown control command type `%d'!\n", ntohs(dht_control_msg->command)); + } + + GNUNET_SERVER_receive_done (client, GNUNET_OK); +} + /** * Handler for any generic DHT stop messages, calls the appropriate handler * depending on message type (if processed locally) @@ -2759,6 +2833,7 @@ core_init (void *cls, static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { {&handle_dht_local_route_request, NULL, GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE, 0}, {&handle_dht_local_route_stop, NULL, GNUNET_MESSAGE_TYPE_DHT_LOCAL_ROUTE_STOP, 0}, + {&handle_dht_control_message, NULL, GNUNET_MESSAGE_TYPE_DHT_CONTROL, 0}, {NULL, NULL, 0, 0} }; diff --git a/src/dht/test_dht_api.c b/src/dht/test_dht_api.c index f7ee94fa4..29606db60 100644 --- a/src/dht/test_dht_api.c +++ b/src/dht/test_dht_api.c @@ -110,10 +110,10 @@ static void end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { /* do work here */ + sleep(2); GNUNET_SCHEDULER_cancel (sched, die_task); GNUNET_DHT_disconnect (p1.dht_handle); - die_task = GNUNET_SCHEDULER_NO_TASK; if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) @@ -160,6 +160,63 @@ end_badly () return; } +/** + * Signature of the main function of a task. + * + * @param cls closure + * @param tc context information (why was this task triggered now) + */ +void test_set_peer_malicious_drop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct PeerContext *peer = cls; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_set_peer_malicious_drop!\n"); + if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) + GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); + + GNUNET_assert (peer->dht_handle != NULL); + + GNUNET_DHT_set_malicious_dropper (peer->dht_handle, &end, &p1); +} + +/** + * Signature of the main function of a task. + * + * @param cls closure + * @param tc context information (why was this task triggered now) + */ +void test_set_peer_malicious_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct PeerContext *peer = cls; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_set_peer_malicious_put!\n"); + if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) + GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); + + GNUNET_assert (peer->dht_handle != NULL); + + GNUNET_DHT_set_malicious_putter (peer->dht_handle, 750, &test_set_peer_malicious_drop, &p1); +} + +/** + * Signature of the main function of a task. + * + * @param cls closure + * @param tc context information (why was this task triggered now) + */ +void test_set_peer_malicious_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct PeerContext *peer = cls; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called test_set_peer_malicious_get!\n"); + if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT) + GNUNET_SCHEDULER_add_now (sched, &end_badly, NULL); + + GNUNET_assert (peer->dht_handle != NULL); + + GNUNET_DHT_set_malicious_getter (peer->dht_handle, 1500, &test_set_peer_malicious_put, &p1); +} + /** * Signature of the main function of a task. * @@ -177,7 +234,7 @@ test_find_peer_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_assert (peer->dht_handle != NULL); - GNUNET_DHT_find_peer_stop (peer->find_peer_handle, &end, &p1); + GNUNET_DHT_find_peer_stop (peer->find_peer_handle, &test_set_peer_malicious_get, &p1); //GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &end, &p1);