[tor-commits] [ooni-probe/master] Restructure directories to reflect architecture spec.

art at torproject.org art at torproject.org
Tue Jul 24 19:26:19 UTC 2012


commit 178ab96765ddec35d0dc42e764d2bd45dd361d23
Author: Arturo Filastò <arturo at filasto.net>
Date:   Tue Jul 24 15:16:04 2012 +0200

    Restructure directories to reflect architecture spec.
---
 oonib/README.md               |    7 ++++
 oonib/backends/daphn3.py      |   37 --------------------
 oonib/backends/dns.py         |   16 ---------
 oonib/backends/http.py        |   74 -----------------------------------------
 oonib/backends/ssl.py         |    7 ----
 oonib/common.py               |    6 ---
 oonib/lib/__init__.py         |    6 +++
 oonib/lib/ssl.py              |    7 ++++
 oonib/oonibackend.py          |   10 +++---
 oonib/testhelpers/daphn3.py   |   37 ++++++++++++++++++++
 oonib/testhelpers/dns.py      |   16 +++++++++
 oonib/testhelpers/http.py     |   74 +++++++++++++++++++++++++++++++++++++++++
 12 files changed, 152 insertions(+), 145 deletions(-)

diff --git a/oonib/README.md b/oonib/README.md
index 6823d06..2d6caba 100644
--- a/oonib/README.md
+++ b/oonib/README.md
@@ -1,3 +1,10 @@
+# Dependencies
+
+The extra dependencies necessary to run OONIB are:
+
+* cyclone: https://github.com/fiorix/cyclone
+*
+
 # Generate self signed certs for OONIB
 
     openssl genrsa -des3 -out private.key 4096
diff --git a/oonib/backends/__init__.py b/oonib/backends/__init__.py
deleted file mode 100644
index e69de29..0000000
diff --git a/oonib/backends/daphn3.py b/oonib/backends/daphn3.py
deleted file mode 100644
index 59bdeea..0000000
--- a/oonib/backends/daphn3.py
+++ /dev/null
@@ -1,37 +0,0 @@
-from twisted.internet import protocol
-from twisted.internet.error import ConnectionDone
-
-from oonib.common import config
-
-from ooni.plugoo import reports
-from ooni.protocols.daphn3 import Mutator, Daphn3Protocol
-from ooni.protocols.daphn3 import read_pcap
-
-class Daphn3Server(protocol.ServerFactory):
-    """
-    This is the main class that deals with the daphn3 server side component.
-    We keep track of global state of every client here.
-    Every client is identified by their IP address and the state of mutation is
-    stored by using their IP address as a key. This may lead to some bugs if
-    two different clients are sharing the same IP, but hopefully the
-    probability of such thing is not that likely.
-    """
-    protocol = Daphn3Protocol
-    mutations = {}
-    def buildProtocol(self, addr):
-        p = self.protocol()
-        p.factory = self
-        p.factory.steps = read_pcap(config.daphn3.pcap_file)
-
-        if addr.host not in self.mutations:
-            self.mutations[addr.host] = Mutator(p.steps)
-        else:
-            print "Moving on to next mutation"
-            if not self.mutations[addr.host].next_mutation():
-                self.mutations.pop(addr.host)
-        try:
-            p.mutator = self.mutations[addr.host]
-        except:
-            pass
-        return p
-
diff --git a/oonib/backends/dns.py b/oonib/backends/dns.py
deleted file mode 100644
index 689d1a4..0000000
--- a/oonib/backends/dns.py
+++ /dev/null
@@ -1,16 +0,0 @@
-from twisted.internet.protocol import Factory, Protocol
-from twisted.internet import reactor
-from twisted.names import dns
-from twisted.names import client, server
-
-class ProxyDNSServer(server.DNSServerFactory):
-    def __init__(self, authorities = None,
-                 caches = None, clients = None,
-                 verbose = 0):
-        resolver = client.Resolver(servers=[('8.8.8.8', 53)])
-        server.DNSServerFactory.__init__(self, authorities = authorities,
-                                         caches = caches, clients = [resolver],
-                                         verbose = verbose)
-    def handleQuery(self, message, protocol, address):
-        print message, protocol, address
-        server.DNSServerFactory.handleQuery(self, message, protocol, address)
diff --git a/oonib/backends/http.py b/oonib/backends/http.py
deleted file mode 100644
index 79a487b..0000000
--- a/oonib/backends/http.py
+++ /dev/null
@@ -1,74 +0,0 @@
-import json
-import random
-import string
-
-from twisted.application import internet, service
-from twisted.internet import protocol, reactor, defer
-from twisted.protocols import basic
-from twisted.web import resource, server, static
-from twisted.web.microdom import escape
-
-server.version = "Apache"
-
-class HTTPRandomPage(resource.Resource):
-    """
-    This generates a random page of arbitrary length and containing the string
-    selected by the user.
-    The format is the following:
-    /random/<length>/<keyword>
-    """
-    isLeaf = True
-    def _gen_random_string(self, length):
-        return ''.join(random.choice(string.letters) for x in range(length))
-
-    def genRandomPage(self, length=100, keyword=None):
-        data = self._gen_random_string(length/2)
-        if keyword:
-            data += keyword
-        data += self._gen_random_string(length - length/2)
-        data += '\n'
-        return data
-
-    def render(self, request):
-        length = 100
-        keyword = None
-        path_parts = request.path.split('/')
-        if len(path_parts) > 2:
-            length = int(path_parts[2])
-            if length > 100000:
-                length = 100000
-
-        if len(path_parts) > 3:
-            keyword = escape(path_parts[3])
-
-        return self.genRandomPage(length, keyword)
-
-class HTTPReturnHeaders(resource.Resource):
-    """
-    This returns the headers being sent by the client in JSON format.
-    """
-    isLeaf = True
-    def render(self, request):
-        req_headers = request.getAllHeaders()
-        return json.dumps(req_headers)
-
-class HTTPSendHeaders(resource.Resource):
-    """
-    This sends to the client the headers that they send inside of the POST
-    request encoded in json.
-    """
-    isLeaf = True
-    def render_POST(self, request):
-        headers = json.loads(request.content.read())
-        for header, value in headers.items():
-            request.setHeader(str(header), str(value))
-        return ''
-
-class HTTPBackend(resource.Resource):
-    def __init__(self):
-        resource.Resource.__init__(self)
-        self.putChild('random', HTTPRandomPage())
-        self.putChild('returnheaders', HTTPReturnHeaders())
-        self.putChild('sendheaders', HTTPSendHeaders())
-
-
diff --git a/oonib/backends/ssl.py b/oonib/backends/ssl.py
deleted file mode 100644
index 5f19686..0000000
--- a/oonib/backends/ssl.py
+++ /dev/null
@@ -1,7 +0,0 @@
-from twisted.internet import ssl
-
-class SSLContext(ssl.DefaultOpenSSLContextFactory):
-    def __init__(self, config):
-        ssl.DefaultOpenSSLContextFactory.__init__(self, config.main.ssl_private_key,
-                                                  config.main.ssl_certificate)
-
diff --git a/oonib/common.py b/oonib/common.py
deleted file mode 100644
index 2f1b6f9..0000000
--- a/oonib/common.py
+++ /dev/null
@@ -1,6 +0,0 @@
-from ooni.utils import Storage
-from ooni.utils.config import Config
-
-config = Storage()
-config.main = Config('main', 'oonibackend.conf')
-config.daphn3 = Config('daphn3', 'oonibackend.conf')
diff --git a/oonib/lib/__init__.py b/oonib/lib/__init__.py
new file mode 100644
index 0000000..2f1b6f9
--- /dev/null
+++ b/oonib/lib/__init__.py
@@ -0,0 +1,6 @@
+from ooni.utils import Storage
+from ooni.utils.config import Config
+
+config = Storage()
+config.main = Config('main', 'oonibackend.conf')
+config.daphn3 = Config('daphn3', 'oonibackend.conf')
diff --git a/oonib/lib/ssl.py b/oonib/lib/ssl.py
new file mode 100644
index 0000000..5f19686
--- /dev/null
+++ b/oonib/lib/ssl.py
@@ -0,0 +1,7 @@
+from twisted.internet import ssl
+
+class SSLContext(ssl.DefaultOpenSSLContextFactory):
+    def __init__(self, config):
+        ssl.DefaultOpenSSLContextFactory.__init__(self, config.main.ssl_private_key,
+                                                  config.main.ssl_certificate)
+
diff --git a/oonib/oonibackend.py b/oonib/oonibackend.py
index c5a866b..d6ba3f0 100755
--- a/oonib/oonibackend.py
+++ b/oonib/oonibackend.py
@@ -16,11 +16,11 @@ from twisted.web import resource, server, static
 from twisted.web.microdom import escape
 from twisted.names import dns
 
-from oonib.common import config
-from oonib.backends.http import HTTPBackend
-from oonib.backends.ssl import SSLContext
-from oonib.backends.dns import ProxyDNSServer
-from oonib.backends.daphn3 import Daphn3Server
+from oonib.lib import config
+from oonib.testhelpers.http import HTTPBackend
+from oonib.lib.ssl import SSLContext
+from oonib.testhelpers.dns import ProxyDNSServer
+from oonib.testhelpers.daphn3 import Daphn3Server
 
 # This tells twisted to set the
 server.version = config.main.server_version
diff --git a/oonib/testhelpers/__init__.py b/oonib/testhelpers/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/oonib/testhelpers/daphn3.py b/oonib/testhelpers/daphn3.py
new file mode 100644
index 0000000..59bdeea
--- /dev/null
+++ b/oonib/testhelpers/daphn3.py
@@ -0,0 +1,37 @@
+from twisted.internet import protocol
+from twisted.internet.error import ConnectionDone
+
+from oonib.common import config
+
+from ooni.plugoo import reports
+from ooni.protocols.daphn3 import Mutator, Daphn3Protocol
+from ooni.protocols.daphn3 import read_pcap
+
+class Daphn3Server(protocol.ServerFactory):
+    """
+    This is the main class that deals with the daphn3 server side component.
+    We keep track of global state of every client here.
+    Every client is identified by their IP address and the state of mutation is
+    stored by using their IP address as a key. This may lead to some bugs if
+    two different clients are sharing the same IP, but hopefully the
+    probability of such thing is not that likely.
+    """
+    protocol = Daphn3Protocol
+    mutations = {}
+    def buildProtocol(self, addr):
+        p = self.protocol()
+        p.factory = self
+        p.factory.steps = read_pcap(config.daphn3.pcap_file)
+
+        if addr.host not in self.mutations:
+            self.mutations[addr.host] = Mutator(p.steps)
+        else:
+            print "Moving on to next mutation"
+            if not self.mutations[addr.host].next_mutation():
+                self.mutations.pop(addr.host)
+        try:
+            p.mutator = self.mutations[addr.host]
+        except:
+            pass
+        return p
+
diff --git a/oonib/testhelpers/dns.py b/oonib/testhelpers/dns.py
new file mode 100644
index 0000000..689d1a4
--- /dev/null
+++ b/oonib/testhelpers/dns.py
@@ -0,0 +1,16 @@
+from twisted.internet.protocol import Factory, Protocol
+from twisted.internet import reactor
+from twisted.names import dns
+from twisted.names import client, server
+
+class ProxyDNSServer(server.DNSServerFactory):
+    def __init__(self, authorities = None,
+                 caches = None, clients = None,
+                 verbose = 0):
+        resolver = client.Resolver(servers=[('8.8.8.8', 53)])
+        server.DNSServerFactory.__init__(self, authorities = authorities,
+                                         caches = caches, clients = [resolver],
+                                         verbose = verbose)
+    def handleQuery(self, message, protocol, address):
+        print message, protocol, address
+        server.DNSServerFactory.handleQuery(self, message, protocol, address)
diff --git a/oonib/testhelpers/http.py b/oonib/testhelpers/http.py
new file mode 100644
index 0000000..79a487b
--- /dev/null
+++ b/oonib/testhelpers/http.py
@@ -0,0 +1,74 @@
+import json
+import random
+import string
+
+from twisted.application import internet, service
+from twisted.internet import protocol, reactor, defer
+from twisted.protocols import basic
+from twisted.web import resource, server, static
+from twisted.web.microdom import escape
+
+server.version = "Apache"
+
+class HTTPRandomPage(resource.Resource):
+    """
+    This generates a random page of arbitrary length and containing the string
+    selected by the user.
+    The format is the following:
+    /random/<length>/<keyword>
+    """
+    isLeaf = True
+    def _gen_random_string(self, length):
+        return ''.join(random.choice(string.letters) for x in range(length))
+
+    def genRandomPage(self, length=100, keyword=None):
+        data = self._gen_random_string(length/2)
+        if keyword:
+            data += keyword
+        data += self._gen_random_string(length - length/2)
+        data += '\n'
+        return data
+
+    def render(self, request):
+        length = 100
+        keyword = None
+        path_parts = request.path.split('/')
+        if len(path_parts) > 2:
+            length = int(path_parts[2])
+            if length > 100000:
+                length = 100000
+
+        if len(path_parts) > 3:
+            keyword = escape(path_parts[3])
+
+        return self.genRandomPage(length, keyword)
+
+class HTTPReturnHeaders(resource.Resource):
+    """
+    This returns the headers being sent by the client in JSON format.
+    """
+    isLeaf = True
+    def render(self, request):
+        req_headers = request.getAllHeaders()
+        return json.dumps(req_headers)
+
+class HTTPSendHeaders(resource.Resource):
+    """
+    This sends to the client the headers that they send inside of the POST
+    request encoded in json.
+    """
+    isLeaf = True
+    def render_POST(self, request):
+        headers = json.loads(request.content.read())
+        for header, value in headers.items():
+            request.setHeader(str(header), str(value))
+        return ''
+
+class HTTPBackend(resource.Resource):
+    def __init__(self):
+        resource.Resource.__init__(self)
+        self.putChild('random', HTTPRandomPage())
+        self.putChild('returnheaders', HTTPReturnHeaders())
+        self.putChild('sendheaders', HTTPSendHeaders())
+
+





More information about the tor-commits mailing list