[tor-commits] [ooni-probe/master] Get b0wser to start doing something useful
art at torproject.org
art at torproject.org
Fri Jul 20 14:05:39 UTC 2012
commit 4dbb7426ec0147e6efa946e287f5e6a7f682252f
Author: Arturo Filastò <hellais at torproject.org>
Date: Tue Jul 17 22:10:24 2012 +0200
Get b0wser to start doing something useful
---
ooni/plugins/b0wser.py | 23 +++++++++++++++++++----
ooni/plugoo/tests.py | 6 ++++--
ooni/protocols/b0wser.py | 28 +++++++++++++++++++++++++---
oonib/b0wser.py | 6 ++++--
4 files changed, 52 insertions(+), 11 deletions(-)
diff --git a/ooni/plugins/b0wser.py b/ooni/plugins/b0wser.py
index 5d6687b..3121378 100644
--- a/ooni/plugins/b0wser.py
+++ b/ooni/plugins/b0wser.py
@@ -62,14 +62,23 @@ class b0wserTest(OONITest):
options = b0wserArgs
blocking = False
+ local_options = None
+
+ steps = None
def initialize(self):
+ if not self.local_options:
+ return
#pass
self.factory = B0wserClientFactory()
+ self.steps = b0wser.get_b0wser_dictionary_from_pcap(self.local_options['pcap'])
+
+ def control(self, exp_res, args):
+ mutation = self.factory.mutator.get_mutation(0)
+ return {'mutation_number': args['mutation'], 'value': mutation}
def experiment(self, args):
- steps = b0wser.get_b0wser_dictionary_from_pcap(self.local_options['pcap'])
- print steps
- self.factory.steps = steps
+ log.msg("Doing mutation %s" % args['mutation'])
+ self.factory.steps = self.steps
host = self.local_options['host']
port = int(self.local_options['port'])
log.msg("Connecting to %s:%s" % (host, port))
@@ -78,7 +87,13 @@ class b0wserTest(OONITest):
#return endpoint.connect(B0wserClientFactory)
def load_assets(self):
- return {}
+ if not self.steps:
+ print "No asset!"
+ return {}
+ mutations = 0
+ for x in self.steps:
+ mutations += len(x['data'])
+ return {'mutation': range(mutations)}
# We need to instantiate it otherwise getPlugins does not detect it
# XXX Find a way to load plugins without instantiating them.
diff --git a/ooni/plugoo/tests.py b/ooni/plugoo/tests.py
index a99a144..9b6ea26 100644
--- a/ooni/plugoo/tests.py
+++ b/ooni/plugoo/tests.py
@@ -24,6 +24,7 @@ class OONITest(object):
"""
# By default we set this to False, meaning that we don't block
blocking = False
+ reactor = None
def __init__(self, local_options, global_options, report, ooninet=None,
reactor=None):
@@ -31,13 +32,14 @@ class OONITest(object):
self.local_options = local_options
# These are the options global to all of OONI
self.global_options = global_options
- self.assets = self.load_assets()
self.report = report
#self.ooninet = ooninet
self.reactor = reactor
- self.initialize()
self.result = {}
+ self.initialize()
+ self.assets = self.load_assets()
+
def initialize(self):
"""
Override this method if you are interested in having some extra
diff --git a/ooni/protocols/b0wser.py b/ooni/protocols/b0wser.py
index 6a01d96..5d55c94 100644
--- a/ooni/protocols/b0wser.py
+++ b/ooni/protocols/b0wser.py
@@ -101,7 +101,9 @@ class Mutator:
Returns a dict containg the packet index and the step number.
"""
- return {'idx': self.idx, 'step': self.step}
+ print "[Mutator.state()] Giving out my internal state."
+ current_state = {'idx': self.idx, 'step': self.step}
+ return current_state
def next_mutation(self):
"""
@@ -121,6 +123,8 @@ class Mutator:
"""
if (self.step + 1) > len(self.steps):
# Hack to stop once we have gone through all the steps
+ print "[Mutator.next_mutation()] I believe I have gone over all steps"
+ print " Stopping!"
self.waiting = True
return False
@@ -130,20 +134,24 @@ class Mutator:
current_data = self.steps[current_step]['data']
try:
data_to_receive = len(self.steps[current_step +1 ]['data'])
+ print "[Mutator.next_mutation()] Managed to receive some data."
except:
- print "No more data to receive"
+ print "[Mutator.next_mutation()] No more data to receive."
if self.waiting and self.waiting_step == data_to_receive:
+ print "[Mutator.next_mutation()] I am no longer waiting"
log.debug("I am no longer waiting.")
self.waiting = False
self.waiting_step = 0
self.idx = 0
elif self.waiting:
+ print "[Mutator.next_mutation()] Waiting some more."
log.debug("Waiting some more.")
self.waiting_step += 1
elif current_idx >= len(current_data):
+ print "[Mutator.next_mutation()] Entering waiting mode."
log.debug("Entering waiting mode.")
self.step += 1
self.idx = 0
@@ -164,7 +172,7 @@ class Mutator:
returns the mutated packet for the specified step.
"""
if step != self.step or self.waiting:
- log.debug("I am not going to do anything :)")
+ log.debug("[Mutator.get_mutation()] I am not going to do anything :)")
return self.steps[step]['data']
data = self.steps[step]['data']
@@ -193,12 +201,19 @@ class B0wserProtocol(protocol.Protocol):
This is called once I have completed one step of the protocol and need
to proceed to the next step.
"""
+ if not self.mutator:
+ print "[B0wserProtocol.next_state] No mutator. There is no point to stay on this earth."
+ self.transport.loseConnection()
+ return
if self.role is self.steps[self.state]['sender']:
+ print "[B0wserProtocol.next_state] I am a sender"
data = self.mutator.get_mutation(self.state)
self.transport.write(data)
self.to_receive_data = 0
else:
+ print "[B0wserProtocol.next_state] I am a receiver"
self.to_receive_data = len(self.steps[self.state]['data'])
+
self.state += 1
self.received_data = 0
@@ -209,6 +224,10 @@ class B0wserProtocol(protocol.Protocol):
@param data: the data that has been sent by the client.
"""
+ if not self.mutator:
+ print "I don't have a mutator. My life means nothing."
+ self.transport.loseConnection()
+ return
if len(self.steps) <= self.state:
print "I have reached the end of the state machine"
print "Censorship fingerprint bruteforced!"
@@ -246,6 +265,9 @@ class B0wserProtocol(protocol.Protocol):
The connection was closed. This may be because of a legittimate reason
or it may be because of a censorship event.
"""
+ if not self.mutator:
+ print "Terminated because of little interest in life."
+ return
report = {'reason': reason, 'proto_state': self.state,
'trigger': None, 'mutator_state': self.mutator.state()}
diff --git a/oonib/b0wser.py b/oonib/b0wser.py
index 0bb89fb..4500075 100644
--- a/oonib/b0wser.py
+++ b/oonib/b0wser.py
@@ -25,7 +25,9 @@ class B0wserServer(protocol.ServerFactory):
print "Moving on to next mutation"
if not self.mutations[addr.host].next_mutation():
self.mutations.pop(addr.host)
- else:
- p.mutator = self.mutations[addr.host]
+ try:
+ p.mutator = self.mutations[addr.host]
+ except:
+ pass
return p
More information about the tor-commits
mailing list