[tor-commits] [stegotorus/master] fixing a couple of chopper bugs; changing steg module constructor to have access to is_clientside

zwol at torproject.org zwol at torproject.org
Fri Jul 20 23:17:06 UTC 2012


commit 87030aa09dbb837da1aaeac79834bf829ffabb75
Author: Jeffrey Wang <jeffreyw at stanford.edu>
Date:   Wed Dec 7 08:10:58 2011 +0000

    fixing a couple of chopper bugs; changing steg module constructor to have access to is_clientside
    
    git-svn-id: svn+ssh://spartan.csl.sri.com/svn/private/DEFIANCE@177 a58ff0ac-194c-e011-a152-003048836090
---
 src/protocol/chop.cc |   15 ++++++++++++---
 src/steg.h           |    7 ++-----
 src/steg/embed.cc    |   34 +++++++++++++++-------------------
 src/steg/http.cc     |    3 ++-
 4 files changed, 31 insertions(+), 28 deletions(-)

diff --git a/src/protocol/chop.cc b/src/protocol/chop.cc
index 3e87428..f960fbb 100644
--- a/src/protocol/chop.cc
+++ b/src/protocol/chop.cc
@@ -38,6 +38,7 @@ struct chop_header
 #define CHOP_WIRE_HDR_LEN (sizeof(struct chop_header))
 #define CHOP_MAX_DATA 16384
 #define CHOP_MAX_CHAFF 2048
+#define CHOP_BLOCK_OVERHD (CHOP_WIRE_HDR_LEN + GCM_TAG_LEN)
 
 #define CHOP_F_SYN   0x0001
 #define CHOP_F_FIN   0x0002
@@ -247,6 +248,11 @@ chop_pick_connection(chop_circuit_t *ckt, size_t desired, size_t *blocksize)
       log_debug(conn, "offers %lu bytes (%s)", (unsigned long)room,
                 conn->steg->name());
 
+      if (room <= CHOP_BLOCK_OVERHD)
+	room = 0;
+      else
+	room -= CHOP_BLOCK_OVERHD;
+      
       if (room > CHOP_MAX_DATA)
         room = CHOP_MAX_DATA;
 
@@ -326,6 +332,11 @@ chop_send_block(conn_t *d,
   if (evbuffer_commit_space(block, &v, 1))
     goto fail;
 
+  // TODO: this should be moved after the steg transmit, but currently that
+  // prevents conn_transmit_soon calls inside steg transmit
+  if (dest->must_transmit_timer)
+    evtimer_del(dest->must_transmit_timer);
+
   if (dest->steg->transmit(block, dest))
     goto fail_committed;
 
@@ -341,8 +352,6 @@ chop_send_block(conn_t *d,
     ckt->sent_fin = true;
   log_debug(dest, "sent %lu+%u byte block [flags %04hx]",
             (unsigned long)CHOP_WIRE_HDR_LEN, length, flags);
-  if (dest->must_transmit_timer)
-    evtimer_del(dest->must_transmit_timer);
   return 0;
 
  fail:
@@ -451,7 +460,7 @@ chop_send_targeted(circuit_t *c, conn_t *target, size_t blocksize)
     if (blocksize > CHOP_MAX_CHAFF)
       blocksize = CHOP_MAX_CHAFF;
 
-    blocksize = rng_range(1, blocksize);
+    blocksize = rng_range(1, blocksize + 1);
     log_debug(target, "generating %lu bytes chaff", (unsigned long)blocksize);
 
     chaff = evbuffer_new();
diff --git a/src/steg.h b/src/steg.h
index 0f83c93..c78ffd7 100644
--- a/src/steg.h
+++ b/src/steg.h
@@ -100,10 +100,7 @@ steg_t *steg_detect(conn_t *conn);
   static bool mod##_detect(conn_t *conn)                \
   { return mod::detect(conn); }                         \
   static steg_t *mod##_new(bool is_clientside)          \
-  { steg_t *s = new mod;                                \
-    s->is_clientside = is_clientside;                   \
-    return s;                                           \
-  }                                                     \
+  { return new mod(is_clientside); }			\
                                                         \
   /* canned methods */                                  \
   const char *mod::name() { return #mod; }              \
@@ -116,7 +113,7 @@ steg_t *steg_detect(conn_t *conn);
 
 #define STEG_DECLARE_METHODS(mod)                               \
   static bool detect(conn_t *conn);                             \
-  mod();                                                        \
+  mod(bool is_clientside);                                      \
   virtual ~mod();                                               \
   virtual const char *name();                                   \
   virtual size_t transmit_room(conn_t *conn);                   \
diff --git a/src/steg/embed.cc b/src/steg/embed.cc
index d887ea7..75562bc 100644
--- a/src/steg/embed.cc
+++ b/src/steg/embed.cc
@@ -1,6 +1,7 @@
 #include "util.h"
 #include "connections.h"
 #include "steg.h"
+#include "rng.h"
 
 #include <event2/buffer.h>
 #include <event2/event.h>
@@ -66,12 +67,11 @@ void init_embed_traces() {
   }
   log_debug("read %d traces to use", embed_num_traces);
 
-  srand(time(NULL));
   embed_init = 1;
 }
 
 int get_random_trace() {
-  return rand() % embed_num_traces;
+  return rng_int(embed_num_traces);
 }
 
 bool embed::advance_packet() {
@@ -96,9 +96,16 @@ bool embed::is_finished() {
   return cur_pkt >= cur->num_pkt;
 }
 
-embed::embed() {
+embed::embed(bool is_clientside) {
   if (!embed_init) init_embed_traces();
+
+  this->is_clientside = is_clientside;
   cur_idx = -1;
+  if (is_clientside) {
+    cur_idx = get_random_trace();
+    cur = &embed_traces[cur_idx];
+    cur_pkt = 0;
+  }
   gettimeofday(&last_pkt, NULL);
 }
 
@@ -110,8 +117,7 @@ bool embed::detect(conn_t *conn) {
   struct evbuffer *source = conn_get_inbound(conn);
   size_t src_len = evbuffer_get_length(source);
 
-  log_debug("detecting buffer of length %lu",
-            (unsigned long)src_len);
+  log_debug("detecting buffer of length %lu", (unsigned long)src_len);
 
   int cur_idx;
   if (evbuffer_copyout(source, &cur_idx, 4) != 4) return 0;
@@ -131,24 +137,14 @@ bool embed::detect(conn_t *conn) {
 }
 
 size_t embed::transmit_room(conn_t * /* conn */) {
-  if (cur_idx == -1 && is_clientside) {
-    cur_idx = get_random_trace();
-    cur = &embed_traces[cur_idx];
-    cur_pkt = 0;
-  }
+  if (is_finished() || !is_outgoing()) return 0;
 
   int time_diff = millis_since(&last_pkt);
-  size_t room;
-
-  if (is_finished() || !is_outgoing()) return 0;
   if (get_pkt_time() > time_diff+10) return 0;
 
-  // 24 bytes for chop header, 16 bytes for GCM tag, 2 bytes for data length
-  // 4 bytes for the index of a new trace
-  room = get_pkt_size() - 42;
-  if (cur_pkt == 0) {
-    room -= 4;
-  }
+  // 2 bytes for data length, 4 bytes for the index of a new trace
+  size_t room = get_pkt_size() - 2;
+  if (cur_pkt == 0) room -= 4;
   return room;
 }
 
diff --git a/src/steg/http.cc b/src/steg/http.cc
index aed9322..e4bdb0e 100644
--- a/src/steg/http.cc
+++ b/src/steg/http.cc
@@ -130,9 +130,10 @@ buf_dump(unsigned char* buf, int len, FILE *out)
 }
 
 
-http::http()
+http::http(bool is_clientside)
   : have_transmitted(false), have_received(false)
 {
+  this->is_clientside = is_clientside;
   if (is_clientside)
     load_payloads("traces/client.out");
   else {





More information about the tor-commits mailing list