[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r34148 - gnunet/src/dht
From: |
gnunet |
Subject: |
[GNUnet-SVN] r34148 - gnunet/src/dht |
Date: |
Wed, 13 Aug 2014 15:58:42 +0200 |
Author: supriti
Date: 2014-08-13 15:58:41 +0200 (Wed, 13 Aug 2014)
New Revision: 34148
Modified:
gnunet/src/dht/
gnunet/src/dht/dht_api.c
gnunet/src/dht/gnunet-service-xdht_clients.c
gnunet/src/dht/gnunet-service-xdht_neighbours.c
gnunet/src/dht/gnunet-service-xdht_neighbours.h
gnunet/src/dht/gnunet_dht_profiler.c
Log:
Act Malicious service code
Index: gnunet/src/dht
===================================================================
--- gnunet/src/dht 2014-08-12 12:51:28 UTC (rev 34147)
+++ gnunet/src/dht 2014-08-13 13:58:41 UTC (rev 34148)
Property changes on: gnunet/src/dht
___________________________________________________________________
Modified: svn:ignore
## -26,3 +26,4 ##
.logfile.swo
gnunet-dht-profiler
.log.3.swo
+.log.4.swo
Modified: gnunet/src/dht/dht_api.c
===================================================================
--- gnunet/src/dht/dht_api.c 2014-08-12 12:51:28 UTC (rev 34147)
+++ gnunet/src/dht/dht_api.c 2014-08-13 13:58:41 UTC (rev 34148)
@@ -1496,4 +1496,44 @@
GNUNET_free (handle);
}
+
+#if ENABLE_MALICIOUS
+/**
+ * Turn the DHT service to act malicious depending on @a flag
+ *
+ * @param handle the DHT handle
+ * @param action 1 to make the service malicious; 0 to make it benign
+ FIXME: perhaps make this an enum of known malicious behaviors?
+ */
+void
+GNUNET_DHT_malicious (struct GNUNET_DHT_Handle *handle, unsigned int action)
+{
+ struct GNUNET_DHT_ActMaliciousMessage *amm;
+ struct PendingMessage *pending;
+ size_t msize;
+
+ msize = sizeof(struct GNUNET_DHT_ActMaliciousMessage);
+ if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
+ {
+ GNUNET_break(0);
+ return;
+ }
+
+ pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
+ amm = (struct GNUNET_DHT_ActMaliciousMessage *)&pending[1];
+ pending->msg = &amm->header;
+ pending->handle = handle;
+ pending->free_on_send = GNUNET_YES;
+ amm->header.size = htons (msize);
+ amm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_ACT_MALICIOUS);
+ amm->action = action;
+
+ GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail,
+ pending);
+ pending->in_pending_queue = GNUNET_YES;
+ process_pending_messages (handle);
+}
+#endif
+
+
/* end of dht_api.c */
Modified: gnunet/src/dht/gnunet-service-xdht_clients.c
===================================================================
--- gnunet/src/dht/gnunet-service-xdht_clients.c 2014-08-12 12:51:28 UTC
(rev 34147)
+++ gnunet/src/dht/gnunet-service-xdht_clients.c 2014-08-13 13:58:41 UTC
(rev 34148)
@@ -1355,7 +1355,6 @@
handle_dht_act_malicious (void *cls, struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- /* FIXME: parse message and set malicious */
const struct GNUNET_DHT_ActMaliciousMessage *msg;
unsigned int malicious;
Modified: gnunet/src/dht/gnunet-service-xdht_neighbours.c
===================================================================
--- gnunet/src/dht/gnunet-service-xdht_neighbours.c 2014-08-12 12:51:28 UTC
(rev 34147)
+++ gnunet/src/dht/gnunet-service-xdht_neighbours.c 2014-08-13 13:58:41 UTC
(rev 34148)
@@ -876,7 +876,7 @@
/**
* Handle for the statistics service.
*/
-extern struct GNUNET_STATISTICS_Handle *GDS_stats;
+//extern struct GNUNET_STATISTICS_Handle *GDS_stats;
/**
* The current finger index that we have want to find trail to. We start the
@@ -892,6 +892,12 @@
unsigned int track_topology;
/**
+ * Should I be a malicious peer and drop the PUT/GET packets?
+ * if 0 then NOT malicious.
+ */
+unsigned int act_malicious;
+
+/**
* Called when core is ready to send a message we asked for
* out to the destination.
*
@@ -992,7 +998,19 @@
}
+#if ENABLE_MALICIOUS
/**
+ * Set the ENABLE_MALICIOUS value to malicious.
+ * @param malicious
+ */
+void
+GDS_NEIGHBOURS_act_malicious (unsigned int malicious)
+{
+ act_malicious = malicious;
+}
+#endif
+
+/**
* Construct a trail setup message and forward it to target_friend
* @param source_peer Peer which wants to setup the trail
* @param ultimate_destination_finger_value Peer identity closest to this value
@@ -2093,6 +2111,8 @@
/**
+ * FIXME; Send put message across all the trail to reach to next hop to handle
+ * malicious peers.
* Construct a Put message and send it to target_peer.
* @param key Key for the content
* @param block_type Type of the block
@@ -2134,6 +2154,18 @@
msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size +
sizeof (struct PeerPutMessage);
+#if ENABLE_MALICIOUS
+ /*Call is made to this function from
+ 1. First peer.
+ 2. Every peer to construct a pending message and send it to next peer.
+ In case of 2nd, this case should have been handled in handle_dht_p2p_put/get
+ No need to check here. First peer can never be malicious. IDEALLY we DONOT
+ need the condition here. REMOVE IT AFTERWARDS once verified.*/
+ if(1 == act_malicious)
+ {
+ return;
+ }
+#endif
if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)
{
put_path_length = 0;
@@ -2212,6 +2244,8 @@
/**
+ * FIXME; Send get message across all the trail to reach to next hop to handle
+ * malicious peers.
* Construct a Get message and send it to target_peer.
* @param key Key for the content
* @param block_type Type of the block
@@ -2249,6 +2283,12 @@
msize = sizeof (struct PeerGetMessage) +
(get_path_length * sizeof (struct GNUNET_PeerIdentity));
+#if ENABLE_MALICIOUS
+ if(1 == act_malicious)
+ {
+ return;
+ }
+#endif
//GNUNET_SERVER_MAX_MESSAGE_SIZE
/* FIXME:TODO:URGENTHere you can try to optimize it a bit. In case the get
path contains you
or your friend then shorten the path. */
@@ -2298,7 +2338,7 @@
{
GNUNET_assert (NULL !=
(target_friend =
- GNUNET_CONTAINER_multipeermap_get (friend_peermap,
target_peer))); //FIXME: assertion fails.
+ GNUNET_CONTAINER_multipeermap_get (friend_peermap,
target_peer)));
}
pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
@@ -3404,7 +3444,6 @@
finger_trail_length,
finger_trail_id,
&updated_finger_trail_length);
-
add_new_finger (finger_identity, updated_trail,
updated_finger_trail_length,
finger_trail_id, finger_table_index);
@@ -3491,7 +3530,10 @@
return;
}
+
/**
+ * FIXME: Check for loop in the request. If you already are part of put path,
+ * then you need to reset the put path length.
* Core handler for P2P put messages.
* @param cls closure
* @param peer sender of the request
@@ -3516,6 +3558,14 @@
size_t payload_size;
uint64_t key_value;
+#if ENABLE_MALICIOUS
+ if(1 == act_malicious)
+ {
+ DEBUG("I am malicious,dropping put request. \n");
+ return GNUNET_OK;
+ }
+#endif
+
msize = ntohs (message->size);
if (msize < sizeof (struct PeerPutMessage))
{
@@ -3668,6 +3718,8 @@
/**
+ * FIXME: Check for loop in the request. If you already are part of get path,
+ * then you need to reset the get path length.
* Core handler for p2p get requests.
*
* @param cls closure
@@ -3689,6 +3741,14 @@
uint64_t key_value;
size_t msize;
+#if ENABLE_MALICIOUS
+ if(1 == act_malicious)
+ {
+ DEBUG("I am malicious,dropping get request. \n");
+ return GNUNET_OK;
+ }
+#endif
+
msize = ntohs (message->size);
if (msize < sizeof (struct PeerGetMessage))
{
@@ -4237,8 +4297,6 @@
ulitmate_destination_finger_value =
GNUNET_ntohll (trail_result->ulitmate_destination_finger_value);
- /* FIXME: here we are calculating my_index and comparing also in this
function.
- And we are doing it again here in this function. Re factor the code. */
/* Ensure that sender peer is the peer from which we were expecting the
message. */
#if 0
if (GNUNET_NO == is_sender_peer_correct (trail_peer_list,
@@ -4433,7 +4491,7 @@
/* Copy all the elements from 0 to i into joined_trail. */
- for(k = 0; k < (i+1); k++)
+ for(k = 0; k < ( i+1); k++)
{
joined_trail[k] = trail_1[k];
}
@@ -4442,7 +4500,7 @@
j = j+1;
/* Copy all the elements from j to trail_2_len-1 to joined trail.*/
- while((k < *joined_trail_len) && (j < trail_2_len));
+ while(k <= (*joined_trail_len - 1))
{
joined_trail[k] = trail_2[j];
j++;
@@ -4911,8 +4969,8 @@
if (closest_peer == ¤t_successor->finger_identity)
{
/* Code for testing ONLY: Store the successor for path tracking */
- track_topology = 1;
- if (track_topology && (NULL != GDS_stats))
+// track_topology = 1;
+ if ((NULL != GDS_stats))
{
char *my_id_str;
uint64_t succ;
@@ -5571,7 +5629,7 @@
matching_trails_count = 0;
/* Iterate over all the trails of finger. */
- for (i = 0; i < MAXIMUM_TRAILS_PER_FINGER; i++)
+ for (i = 0; i < remove_finger->trails_count; i++)
{
struct Trail *trail;
trail = &remove_finger->trail_list[i];
@@ -5787,7 +5845,6 @@
peer_identity, friend,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
-
/* got a first connection, good time to start with FIND FINGER TRAIL
requests...*/
if (GNUNET_SCHEDULER_NO_TASK == find_finger_trail_task)
{
@@ -5855,11 +5912,16 @@
{&handle_dht_p2p_add_trail, GNUNET_MESSAGE_TYPE_XDHT_P2P_ADD_TRAIL, 0},
{NULL, 0, 0}
};
-
+
+#if ENABLE_MALICIOUS
+ act_malicious = 0;
+#endif
+
core_api =
GNUNET_CORE_connect (GDS_cfg, NULL, &core_init, &handle_core_connect,
&handle_core_disconnect, NULL, GNUNET_NO, NULL,
GNUNET_NO, core_handlers);
+
if (NULL == core_api)
return GNUNET_SYSERR;
@@ -5869,6 +5931,26 @@
return GNUNET_OK;
}
+/**
+ * Free the memory held up by trails of a finger.
+ */
+static void
+delete_finger_table_entries()
+{
+ unsigned int i;
+ unsigned int j;
+
+ for(i = 0; i < MAX_FINGERS; i++)
+ {
+ if(GNUNET_NO == finger_table[i].is_present)
+ continue;
+
+ for(j = 0; j < finger_table[i].trails_count; j++)
+ {
+ free_trail(&finger_table[i].trail_list[i]);
+ }
+ }
+}
/**
* Shutdown neighbours subsystem.
@@ -5882,6 +5964,8 @@
GNUNET_CORE_disconnect (core_api);
core_api = NULL;
+ delete_finger_table_entries();
+
GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (friend_peermap));
GNUNET_CONTAINER_multipeermap_destroy (friend_peermap);
friend_peermap = NULL;
Modified: gnunet/src/dht/gnunet-service-xdht_neighbours.h
===================================================================
--- gnunet/src/dht/gnunet-service-xdht_neighbours.h 2014-08-12 12:51:28 UTC
(rev 34147)
+++ gnunet/src/dht/gnunet-service-xdht_neighbours.h 2014-08-13 13:58:41 UTC
(rev 34148)
@@ -32,7 +32,16 @@
#include "gnunet_dht_service.h"
+#if ENABLE_MALICIOUS
/**
+ * Set the ENABLE_MALICIOUS value to malicious.
+ * @param malicious
+ */
+void
+GDS_NEIGHBOURS_act_malicious (unsigned int malicious);
+#endif
+
+/**
* Construct a Put message and send it to target_peer.
* @param key Key for the content
* @param block_type Type of the block
Modified: gnunet/src/dht/gnunet_dht_profiler.c
===================================================================
--- gnunet/src/dht/gnunet_dht_profiler.c 2014-08-12 12:51:28 UTC (rev
34147)
+++ gnunet/src/dht/gnunet_dht_profiler.c 2014-08-13 13:58:41 UTC (rev
34148)
@@ -38,9 +38,16 @@
/**
* Number of peers which should perform a PUT out of 100 peers
*/
-#define PUT_PROBABILITY 50
+#define PUT_PROBABILITY 100
/**
+ * Percentage of peers that should act maliciously.
+ * These peers will never start PUT/GET request.
+ * n_active and n_malicious should not intersect.
+ */
+#define MALICIOUS_PEERS 0
+
+/**
* Configuration
*/
static struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -160,7 +167,14 @@
*/
static unsigned int num_peers;
+#if ENABLE_MALICIOUS
/**
+ * Number or malicious peers.
+ */
+static unsigned int n_malicious;
+#endif
+
+/**
* Number of active peers
*/
static unsigned int n_active;
@@ -585,7 +599,7 @@
delayed_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct ActiveContext *ac = cls;
- DEBUG("PUT SUPU \n");
+
ac->delay_task = GNUNET_SCHEDULER_NO_TASK;
/* Generate and DHT PUT some random data */
ac->put_data_size = 16; /* minimum */
@@ -638,7 +652,7 @@
ctx->op = NULL;
return;
}
-
+
ac->delay_task = GNUNET_SCHEDULER_add_delayed (delay, &delayed_put, ac);
}
@@ -706,6 +720,7 @@
}
}
+static unsigned int tries;
/**
* Stats callback. Iterate over the hashmap and check if all th peers form
@@ -743,7 +758,7 @@
if (start_val == val)
{
- DEBUG("Circle completed\n");
+ DEBUG("CIRCLE COMPLETED after %u tries", tries);
if (GNUNET_SCHEDULER_NO_TASK != successor_stats_task)
{
successor_stats_task = GNUNET_SCHEDULER_NO_TASK;
@@ -760,9 +775,6 @@
}
else
{
- static unsigned int tries;
-
- DEBUG("Circle not complete\n");
if (max_searches == ++tries)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -810,7 +822,6 @@
int is_persistent)
{
static const char *key_string = "XDHT";
-
if (0 == strncmp (key_string, name, strlen (key_string)))
{
char *my_id_str;
@@ -825,10 +836,8 @@
strncpy(truncated_my_id_str, my_id_str, 12);
truncated_my_id_str[12] = '\0';
-
my_id_key = GNUNET_new(struct GNUNET_HashCode);
GNUNET_CRYPTO_hash (truncated_my_id_str,
sizeof(truncated_my_id_str),my_id_key);
-
GNUNET_STRINGS_data_to_string(&value, sizeof(uint64_t), successor_str, 13);
strncpy(truncated_successor_str, successor_str, 12);
truncated_successor_str[12] ='\0';
@@ -862,6 +871,9 @@
return;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start collecting statistics...\n");
+ DEBUG("num_peers = %d", num_peers);
+ GNUNET_assert(NULL != testbed_handles);
+
/* Check for successor pointer, don't start put till the virtual ring topology
is not created. */
@@ -870,6 +882,8 @@
"dht", NULL,
successor_stats_iterator,
successor_stats_cont, cls);
+
+ GNUNET_assert(successor_stats_op);
}
/**
@@ -901,9 +915,9 @@
peer_contexts[peers_started] = ctx;
peers_started++;
- DEBUG("Peers Started = %d \n", peers_started);
+ DEBUG("Peers Started = %d; num_peers = %d \n", peers_started, num_peers);
- if (GNUNET_SCHEDULER_NO_TASK == successor_stats_task)
+ if (GNUNET_SCHEDULER_NO_TASK == successor_stats_task && peers_started ==
num_peers)
{
DEBUG("successor_stats_task \n");
struct Collect_Stat_Context *collect_stat_cls = GNUNET_new(struct
Collect_Stat_Context);
@@ -958,6 +972,25 @@
return;
}
+#if ENABLE_MALICIOUS
+
+ if(PUT_PROBABILITY + MALICIOUS_PEERS > 100)
+ {
+ DEBUG ("Reduce either number of malicious peer or active peers. ");
+ GNUNET_SCHEDULER_shutdown ();
+ GNUNET_free (a_ctx);
+ return;
+ }
+
+ /* Select the peers which should act maliciously. */
+ n_malicious = num_peers * MALICIOUS_PEERS / 100;
+
+ /* Select n_malicious peers and ensure that those are not active peers.
+ keep all malicious peer at one place, and call act malicious for all
+ those peers. */
+
+#endif
+
a_ac = GNUNET_malloc (n_active * sizeof (struct ActiveContext));
ac_cnt = 0;
for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++)
@@ -1051,7 +1084,7 @@
max_searches = 10;
if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
return 2;
- delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2); /*
default delay */
+ delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20); /*
default delay */
timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1); /*
default timeout */
replication = 1; /* default replication */
rc = 0;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r34148 - gnunet/src/dht,
gnunet <=