[tor-commits] [stegotorus/master] enabling steg modules to pick a better/smaller payload to reduce cover traffic overhead
zwol at torproject.org
zwol at torproject.org
Fri Jul 20 23:17:06 UTC 2012
commit c2485e44f69d40855f330300cbd59a7a9c2cbd22
Author: Steven Cheung <steven.cheung at sri.com>
Date: Tue Jan 31 15:54:25 2012 -0800
enabling steg modules to pick a better/smaller payload to reduce cover traffic overhead
---
src/steg/payloads.cc | 50 ++++++++++++++++++++++++++++++++++----------------
src/steg/payloads.h | 3 +++
2 files changed, 37 insertions(+), 16 deletions(-)
diff --git a/src/steg/payloads.cc b/src/steg/payloads.cc
index 8d08b1a..250f149 100644
--- a/src/steg/payloads.cc
+++ b/src/steg/payloads.cc
@@ -1496,14 +1496,11 @@ int get_next_payload (int contentType, char** buf, int* size, int* cap) {
int get_payload (int contentType, int cap, char** buf, int* size) {
- int r;
- unsigned int i = 0;
- unsigned int cnt = 0;
+ int r, i, cnt, found = 0, numCandidate = 0, first, best, current;
log_debug("get_payload: contentType = %d, initTypePayload = %d, typePayloadCount = %d",
contentType, initTypePayload[contentType], typePayloadCount[contentType]);
-
if (contentType <= 0 ||
contentType >= MAX_CONTENT_TYPE ||
initTypePayload[contentType] == 0 ||
@@ -1512,22 +1509,43 @@ int get_payload (int contentType, int cap, char** buf, int* size) {
cnt = typePayloadCount[contentType];
- r = rand() % cnt;
-
- for (i=0; i < cnt; i++) {
-
- if (typePayloadCap[contentType][(r+i) % cnt] <= cap)
+ r = rand() % cnt;
+ best = r;
+ first = r;
+
+ i = -1;
+ // we look at MAX_CANDIDATE_PAYLOADS payloads that have enough capacity
+ // and select the best fit
+ while (i < (cnt-1) && numCandidate < MAX_CANDIDATE_PAYLOADS) {
+ i++;
+ current = (r+i)%cnt;
+
+ if (typePayloadCap[contentType][current] <= cap)
continue;
- *buf = payloads[typePayload[contentType][(r+i)%cnt]];
- *size = payload_hdrs[typePayload[contentType][(r+i)%cnt]].length;
- return 1;
+ if (found) {
+ if (payload_hdrs[typePayload[contentType][best]].length >
+ payload_hdrs[typePayload[contentType][current]].length)
+ best = current;
+ } else {
+ first = current;
+ best = current;
+ found = 1;
+ }
+ numCandidate++;
}
-
-
- return 0;
-
+ if (found) {
+ log_debug("first payload size=%d, best payload size=%d, num candidate=%d\n",
+ payload_hdrs[typePayload[contentType][first]].length,
+ payload_hdrs[typePayload[contentType][best]].length,
+ numCandidate);
+ *buf = payloads[typePayload[contentType][best]];
+ *size = payload_hdrs[typePayload[contentType][best]].length;
+ return 1;
+ } else {
+ return 0;
+ }
}
diff --git a/src/steg/payloads.h b/src/steg/payloads.h
index 0104ee0..34e7edc 100644
--- a/src/steg/payloads.h
+++ b/src/steg/payloads.h
@@ -28,6 +28,9 @@
#define MAX_PAYLOADS 10000
#define MAX_RESP_HDR_SIZE 512
+// max number of payloads that have enough capacity from which
+// we choose the best fit
+#define MAX_CANDIDATE_PAYLOADS 10
// jsSteg-specific defines
#define JS_DELIMITER '?'
More information about the tor-commits
mailing list