gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r35299 - in gnunet/src: include rps


From: gnunet
Subject: [GNUnet-SVN] r35299 - in gnunet/src: include rps
Date: Mon, 23 Feb 2015 15:35:03 +0100

Author: ch3
Date: 2015-02-23 15:35:02 +0100 (Mon, 23 Feb 2015)
New Revision: 35299

Modified:
   gnunet/src/include/gnunet_protocols.h
   gnunet/src/include/gnunet_rps_service.h
   gnunet/src/rps/Makefile.am
   gnunet/src/rps/gnunet-service-rps.c
   gnunet/src/rps/rps.h
   gnunet/src/rps/rps_api.c
   gnunet/src/rps/test_rps.conf
   gnunet/src/rps/test_rps_malicious_1.c
Log:
- sending act malicious message

Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2015-02-23 00:39:06 UTC (rev 
35298)
+++ gnunet/src/include/gnunet_protocols.h       2015-02-23 14:35:02 UTC (rev 
35299)
@@ -2677,7 +2677,7 @@
  */
 #define GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS   956
 
-#endif
+#endif /* ENABLE_MALICIOUS */
 
 
/*******************************************************************************/
 

Modified: gnunet/src/include/gnunet_rps_service.h
===================================================================
--- gnunet/src/include/gnunet_rps_service.h     2015-02-23 00:39:06 UTC (rev 
35298)
+++ gnunet/src/include/gnunet_rps_service.h     2015-02-23 14:35:02 UTC (rev 
35299)
@@ -126,7 +126,7 @@
                           uint32_t type,
                           uint32_t num_peers,
                           const struct GNUNET_PeerIdentity *ids);
-#endif
+#endif /* ENABLE_MALICIOUS */
 
 
 /**

Modified: gnunet/src/rps/Makefile.am
===================================================================
--- gnunet/src/rps/Makefile.am  2015-02-23 00:39:06 UTC (rev 35298)
+++ gnunet/src/rps/Makefile.am  2015-02-23 14:35:02 UTC (rev 35299)
@@ -58,9 +58,17 @@
 
 if HAVE_TESTING
 check_PROGRAMS = \
- test_rps_multipeer
+ test_rps_multipeer \
+ test_rps_malicious_1
 endif
 
+ld_rps_test_lib = \
+       libgnunetrps.la \
+  $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/testbed/libgnunettestbed.la \
+  -lm
+
+
 if ENABLE_TEST_RUN
 AM_TESTS_ENVIRONMENT=export 
GNUNET_PREFIX=$${GNUNET_PREFIX:address@hidden@};export 
PATH=$${GNUNET_PREFIX:address@hidden@}/bin:$$PATH;
 TESTS = $(check_PROGRAMS)
@@ -68,12 +76,11 @@
 
 test_rps_multipeer_SOURCES = \
  test_rps_multipeer.c
-test_rps_multipeer_LDADD = \
-  libgnunetrps.la \
-  $(top_builddir)/src/util/libgnunetutil.la \
-  $(top_builddir)/src/testbed/libgnunettestbed.la \
-  -lm
+test_rps_multipeer_LDADD = $(ld_rps_test_lib)
 
+test_rps_malicious_1_SOURCES = \
+       test_rps_malicious_1.c
+test_rps_malicious_1_LDADD = $(ld_rps_test_lib)
 
 EXTRA_DIST = \
   test_rps.conf

Modified: gnunet/src/rps/gnunet-service-rps.c
===================================================================
--- gnunet/src/rps/gnunet-service-rps.c 2015-02-23 00:39:06 UTC (rev 35298)
+++ gnunet/src/rps/gnunet-service-rps.c 2015-02-23 14:35:02 UTC (rev 35299)
@@ -356,6 +356,33 @@
 uint32_t num_hist_update_tasks;
 
 
+#if ENABLE_MALICIOUS
+/**
+ * Type of malicious peer
+ *
+ * 0 Don't act malicious at all - Default
+ * 1 Try to maximise representation
+ * 2 Try to partition the network
+ */
+uint32_t mal_type = 0;
+
+/**
+ * Other malicious peers
+ */
+static struct GNUNET_PeerIdentity *mal_peers;
+
+/**
+ * Number of other malicious peers
+ */
+static uint32_t num_mal_peers;
+
+/**
+ * If type is 2 this is the attacked peer
+ */
+struct struct GNUNET_PeerIdentity attacked_peer;
+#endif /* ENABLE_MALICIOUS */
+
+
 /***********************************************************************
  * /Globals
 ***********************************************************************/
@@ -1239,6 +1266,7 @@
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
+
   in_msg = (struct GNUNET_RPS_P2P_PullReplyMessage *) msg;
   if ((ntohs (msg->size) - sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) /
       sizeof (struct GNUNET_PeerIdentity) != ntohl (in_msg->num_peers))
@@ -1309,42 +1337,64 @@
                            void **channel_ctx,
                            const struct GNUNET_MessageHeader *msg)
 {
+  struct GNUNET_PeerIdentity *peers;
+
   LOG (GNUNET_ERROR_TYPE_DEBUG, "PULL REPLY received\n");
 
   /* Check for protocol violation */
-  //if (sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs (msg->size))
-  //{
-  //  GNUNET_break_op (0);
-  //  return GNUNET_SYSERR;
-  //}
-  //in_msg = (struct GNUNET_RPS_P2P_PullReplyMessage *) msg;
-  //if ((ntohs (msg->size) - sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) /
-  //    sizeof (struct GNUNET_PeerIdentity) != ntohl (in_msg->num_peers))
-  //{
-  //  LOG (GNUNET_ERROR_TYPE_ERROR,
-  //      "message says it sends %" PRIu64 " peers, have space for %i peers\n",
-  //      ntohl (in_msg->num_peers),
-  //      (ntohs (msg->size) - sizeof (struct 
GNUNET_RPS_P2P_PullReplyMessage)) /
-  //          sizeof (struct GNUNET_PeerIdentity));
-  //  GNUNET_break_op (0);
-  //  return GNUNET_SYSERR;
-  //}
+  if (sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs (msg->size))
+  {
+    GNUNET_break_op (0);
+    return GNUNET_SYSERR;
+  }
 
-  //sender = (struct GNUNET_PeerIdentity *) GNUNET_CADET_channel_get_info (
-  //    (struct GNUNET_CADET_Channel *) channel, GNUNET_CADET_OPTION_PEER);
-  //     // Guess simply casting isn't the nicest way...
-  //     // FIXME wait for cadet to change this function
-  //sender_ctx = get_peer_ctx (peer_map, sender);
+  in_msg = (struct GNUNET_RPS_CS_ActMaliciousMessage *) msg;
+  if ((ntohs (msg->size) - sizeof (struct GNUNET_RPS_CS_ActMaliciousMessage)) /
+      sizeof (struct GNUNET_PeerIdentity) != ntohl (in_msg->num_peers))
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+        "message says it sends %" PRIu64 " peers, have space for %i peers\n",
+        ntohl (in_msg->num_peers),
+        (ntohs (msg->size) - sizeof (struct 
GNUNET_RPS_CS_ActMaliciousMessage)) /
+            sizeof (struct GNUNET_PeerIdentity));
+    GNUNET_break_op (0);
+    return GNUNET_SYSERR;
+  }
 
-  //if (GNUNET_YES == get_peer_flag (sender_ctx, PULL_REPLY_PENDING))
-  //{
-  //  GNUNET_break_op (0);
-  //  return GNUNET_OK;
-  //}
+  sender = (struct GNUNET_PeerIdentity *) GNUNET_CADET_channel_get_info (
+      (struct GNUNET_CADET_Channel *) channel, GNUNET_CADET_OPTION_PEER);
+       // Guess simply casting isn't the nicest way...
+       // FIXME wait for cadet to change this function
+  sender_ctx = get_peer_ctx (peer_map, sender);
 
+  if (GNUNET_YES == get_peer_flag (sender_ctx, PULL_REPLY_PENDING))
+  {
+    GNUNET_break_op (0);
+    return GNUNET_OK;
+  }
+
   /* Do actual logic */
+  peers = (struct GNUNET_PeerIdentity *) &msg[1];
+  num_peers = ntohl (in_msg->num_peers);
+  mal_type = ntohl (in_msg->type);
+
+  if (1 == mal_type)
+  { /* Try to maximise representation */
+    num_mal_peers = ntohl (in_msg->num_peers);
+    mal_peers = GNUNET_new_array (num_mal_peers,
+                                  struct GNUNET_PeerIdentity);
+    memcpy (mal_peers, peers, num_mal_peers);
+  }
+  else if (2 == mal_type)
+  { /* Try to partition the network */
+    num_mal_peers = ntohl (in_msg->num_peers) - 1;
+    mal_peers = GNUNET_new_array (num_mal_peers,
+                                  struct GNUNET_PeerIdentity);
+    memcpy (mal_peers, peers, num_mal_peers);
+    attacked_peer = peers[num_mal_peers];
+  }
 }
-#endif
+#endif /* ENABLE_MALICIOUS */
 
 
 /**
@@ -1940,7 +1990,7 @@
     {&handle_peer_pull_reply  , GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY  , 0},
     #if ENABLE_MALICIOUS
     {&handle_peer_act_malicious, GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS , 0},
-    #endif
+    #endif /* ENABLE_MALICIOUS */
     {NULL, 0, 0}
   };
 

Modified: gnunet/src/rps/rps.h
===================================================================
--- gnunet/src/rps/rps.h        2015-02-23 00:39:06 UTC (rev 35298)
+++ gnunet/src/rps/rps.h        2015-02-23 14:35:02 UTC (rev 35299)
@@ -124,6 +124,7 @@
   /* Followed by num_peers * GNUNET_PeerIdentity */
 };
 
+#if ENABLE_MALICIOUS
 /**
  * Message from client to service to turn service malicious.
  */
@@ -150,5 +151,6 @@
 
   /* Followed by num_peers * GNUNET_PeerIdentity */
 };
+#endif /* ENABLE_MALICIOUS */
 
 GNUNET_NETWORK_STRUCT_END

Modified: gnunet/src/rps/rps_api.c
===================================================================
--- gnunet/src/rps/rps_api.c    2015-02-23 00:39:06 UTC (rev 35298)
+++ gnunet/src/rps/rps_api.c    2015-02-23 14:35:02 UTC (rev 35299)
@@ -311,8 +311,61 @@
                           uint32_t num_peers,
                           const struct GNUNET_PeerIdentity *ids)
 {
+  uint32_t size_needed;
+  uint32_t num_peers_max;
+  const struct GNUNET_PeerIdentity *tmp_peer_pointer;
+  struct GNUNET_MQ_Envelope *ev;
+  struct GNUNET_RPS_CS_ActMaliciousMessage *msg;
+
+  unsigned int i;
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Client turns malicious with %" PRIX32 " other peers:\n",
+       n);
+  for (i = 0 ; i < n ; i++)
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+         "%u. peer: %s\n",
+         i,
+         GNUNET_i2s (&ids[i]));
+
+  /* The actual size the message occupies */
+  size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) +
+    n * sizeof (struct GNUNET_PeerIdentity);
+  /* The number of peers that fits in one message together with
+   * the respective header */
+  num_peers_max = (GNUNET_SERVER_MAX_MESSAGE_SIZE -
+      sizeof (struct GNUNET_RPS_CS_SeedMessage)) /
+    sizeof (struct GNUNET_PeerIdentity);
+  tmp_peer_pointer = ids;
+
+  while (GNUNET_SERVER_MAX_MESSAGE_SIZE < size_needed)
+  {
+    ev = GNUNET_MQ_msg_extra (msg,
+                              num_peers_max * sizeof (struct 
GNUNET_PeerIdentity),
+                              GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS);
+    msg->type = ntohl (type);
+    msg->num_peers = ntohl (num_peers_max);
+    memcpy (&msg[1], tmp_peer_pointer, num_peers_max * sizeof (struct 
GNUNET_PeerIdentity));
+    GNUNET_MQ_send (h->mq, ev);
+
+    n -= num_peers_max;
+    size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) +
+                  n * sizeof (struct GNUNET_PeerIdentity);
+    /* Set pointer to beginning of next block of num_peers_max peers */
+    tmp_peer_pointer = &ids[num_peers_max];
+  }
+
+  ev = GNUNET_MQ_msg_extra (msg,
+                            n * sizeof (struct GNUNET_PeerIdentity),
+                            GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS);
+  msg->type = htonl (type);
+  msg->num_peers = htonl (n);
+  memcpy (&msg[1], tmp_peer_pointer, n * sizeof (struct GNUNET_PeerIdentity));
+
+  GNUNET_MQ_send (h->mq, ev);
+
 }
-#endif
+#endif /* ENABLE_MALICIOUS */
 
 
 /**
@@ -335,7 +388,7 @@
   void
 GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h)
 {
-  if ( NULL != h->conn )
+  if (NULL != h->conn)
     GNUNET_CLIENT_disconnect (h->conn);
 }
 

Modified: gnunet/src/rps/test_rps.conf
===================================================================
--- gnunet/src/rps/test_rps.conf        2015-02-23 00:39:06 UTC (rev 35298)
+++ gnunet/src/rps/test_rps.conf        2015-02-23 14:35:02 UTC (rev 35299)
@@ -1,5 +1,5 @@
 [rps]
-#PREFIX = valgrind --log-file=/tmp/rps/valgrind!gnunet-service-rps!%p
+#PREFIX = valgrind --leak-check=full --show-leak-kinds=all 
--log-file=/tmp/rps/valgrind!gnunet-service-rps!%p
 #BINARY = gnunet-service-rps
 UNIXPATH = /tmp/gnunet-service-rps.sock
 HOME = $SERVICEHOME

Modified: gnunet/src/rps/test_rps_malicious_1.c
===================================================================
--- gnunet/src/rps/test_rps_malicious_1.c       2015-02-23 00:39:06 UTC (rev 
35298)
+++ gnunet/src/rps/test_rps_malicious_1.c       2015-02-23 14:35:02 UTC (rev 
35299)
@@ -235,14 +235,17 @@
                                 const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   struct GNUNET_RPS_Handle *h;
+  #if ENABLE_MALICIOUS
   uint64_t num_mal_peers;
+  #endif /* ENABLE_MALICIOUS */
 
-  num_mal_peers = round (portion * NUM_PEERS);
+  h = GNUNET_RPS_connect (cfg);
 
-  h = GNUNET_RPS_connect (cfg);
   #if ENABLE_MALICIOUS
+  num_mal_peers = round (portion * NUM_PEERS);
   GNUNET_RPS_act_malicious (h, htonl (1), htonl (num_mal_peers), rps_peer_ids);
-  #endif
+  #endif /* ENABLE_MALICIOUS */
+
   return h;
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]