Skip to content

Commit

Permalink
Merge e1641e3 into 29b1b73
Browse files Browse the repository at this point in the history
  • Loading branch information
meejah committed Jan 20, 2017
2 parents 29b1b73 + e1641e3 commit fefc069
Show file tree
Hide file tree
Showing 30 changed files with 2,188 additions and 690 deletions.
6 changes: 1 addition & 5 deletions .travis.yml
Expand Up @@ -4,13 +4,9 @@ dist: precise

install: "sudo apt-get update && sudo apt-get install -y libgeoip-dev python-dev && pip install -r requirements.txt && pip install -r dev-requirements.txt"
env:
### - TOX_ENV=twisted-debian-squeeze
- TOX_ENV=twisted-debian-wheezy
- TOX_ENV=twisted-latest-12
- TOX_ENV=twisted-latest-13
- TOX_ENV=twisted-latest-14
- TOX_ENV=twisted-latest-15
- TOX_ENV=twisted-latest-16
- TOX_ENV=py35
- TOX_ENV=pypy

script:
Expand Down
16 changes: 13 additions & 3 deletions Dockerfile
@@ -1,9 +1,19 @@
FROM dockerbase-wheezy
FROM dockerbase-jessie

RUN apt-get update
ADD docker-apt-tor /etc/apt/sources.list.d/tor.list
ADD docker-backports /etc/apt/sources.list.d/backports.list
ADD tor-deb-signing-key /root/tor-deb-signing-key

##RUN apt-get update
##RUN `awk '/BEGIN_INSTALL/,/END_INSTALL/' ./README.rst | /bin/grep apt-get | /bin/grep -v development`
## above fails when run via Docker
RUN apt-get install -y python-setuptools python-twisted python-ipaddr python-geoip graphviz tor

RUN apt-key add /root/tor-deb-signing-key
RUN apt-get update && apt-get install -y python-pip python-virtualenv python-dev tor
RUN pip install twisted ipaddress service-identity

# can we do this during build-time somehow?
# RUN pip install --editable /txtorcon

## we make our code available via a "container volume" (-v option to run)
## at /txtorcon
Expand Down
26 changes: 19 additions & 7 deletions Makefile
Expand Up @@ -3,7 +3,7 @@ default: test
VERSION = 0.18.0

test:
trial --reporter=text test
PYTHONPATH=. trial --reporter=text test

tox:
tox -i http://localhost:3141/root/pypi
Expand All @@ -19,9 +19,20 @@ dockerbase-wheezy-image: dockerbase-wheezy
tar -C dockerbase-wheezy -c . | docker import - dockerbase-wheezy
docker run dockerbase-wheezy cat /etc/issue

txtorcon-tester: Dockerfile dockerbase-wheezy-image
# see also http://docs.docker.io/en/latest/use/baseimages/
dockerbase-jessie:
@echo 'Building a minimal "jessie" system.'
@echo "This may take a while...and will consume about 240MB when done."
debootstrap jessie dockerbase-jessie

dockerbase-jessie-image: dockerbase-jessie
@echo 'Importing dockerbase-jessie into docker'
tar -C dockerbase-jessie -c . | docker import - dockerbase-jessie
docker run dockerbase-jessie cat /etc/issue

txtorcon-tester: Dockerfile dockerbase-jessie-image
@echo "Creating a Docker.io container"
docker build -rm -q -t txtorcon-tester ./
docker build --rm -q -t txtorcon-tester ./

integration: ## txtorcon-tester
python integration/run.py
Expand All @@ -35,8 +46,9 @@ doc: docs/*.rst
-cp dist/txtorcon-${VERSION}.tar.gz docs/_build/html

coverage:
coverage run --source=txtorcon `which trial` test
coverage report --show-missing
PYTHONPATH=. coverage run --source=txtorcon `which trial` test
#coverage report --show-missing
cuv graph

htmlcoverage:
coverage run --source=txtorcon `which trial` test
Expand Down Expand Up @@ -72,9 +84,9 @@ clean:
-rm MANIFEST
-rm `find . -name \*.py[co]`
-cd docs && make clean
-rm -rf dockerbase-wheezy
-rm -rf dockerbase-jessie
-docker rmi txtorcon-tester
-docker rmi dockerbase-wheezy
-docker rmi dockerbase-jessie

counts:
ohcount -s txtorcon/*.py
Expand Down
1 change: 1 addition & 0 deletions dev-requirements.txt
@@ -1,5 +1,6 @@
tox
coverage
cuvner
setuptools>=0.8.0
Sphinx
repoze.sphinx.autointerface>=0.4
Expand Down
54 changes: 54 additions & 0 deletions examples/lookups.py
@@ -0,0 +1,54 @@
from __future__ import print_function

from twisted.internet.task import react
from twisted.internet.defer import inlineCallbacks
from twisted.internet.endpoints import clientFromString
from twisted.web.client import Agent, readBody
import txtorcon
from txtorcon import socks

class _AgentEndpointFactoryUsingTor(object):
def __init__(self, reactor, ep):
self._reactor = reactor
self._proxy_ep = ep

def endpointForURI(self, uri):
print("creating torsocksep for", uri)
return socks.TorSocksEndpoint(
self._proxy_ep,
uri.host,
uri.port,
tls=(uri.scheme == b'https'),
)


@inlineCallbacks
def main(reactor):
tor_ep = clientFromString(reactor, "tcp:localhost:9050")
if True:
for domain in [u'www.torproject.org', u'meejah.ca']:
print("Looking up '{}' via Tor".format(domain))
ans = yield socks.resolve(tor_ep, domain)
print("...got answer: {}".format(ans))
print("Doing PTR on {}".format(ans))
ans = yield socks.resolve_ptr(tor_ep, ans)
print("...got answer: {}".format(ans))

ep = txtorcon.TorClientEndpoint(
'www.torproject.org', 80,
socks_endpoint=tor_ep,
)
factory = _AgentEndpointFactoryUsingTor(reactor, tor_ep)
agent = Agent.usingEndpointFactory(reactor, factory)
reply = yield agent.request('GET', 'https://www.torproject.org')
#reply = yield agent.request('GET', 'http://boingboing.net')
print("{}: {} ({} bytes)".format(reply.code, reply.phrase, reply.length))
text = yield readBody(reply)
if len(text) > 400:
print(text[:200], "...", text[-200:])
else:
print(text)


if __name__ == '__main__':
react(main)
27 changes: 9 additions & 18 deletions integration/hidden_service_listen_ports/container_run
Expand Up @@ -9,7 +9,7 @@ import sys
import tempfile
import functools

from twisted.internet import reactor, defer
from twisted.internet import reactor, defer, task
from twisted.internet.endpoints import TCP4ServerEndpoint
from twisted.web import server, resource
from twisted.python import log
Expand All @@ -21,41 +21,32 @@ print sys.argv[0]
sys.path.insert(0, '/txtorcon')
import txtorcon


class Simple(resource.Resource):
isLeaf = True

def render_GET(self, request):
return "<html>Hello, world! I'm a hidden service!</html>"

config = txtorcon.TorConfig()
config.SOCKSPort = 0
config.ORPort = 0
hs_public_port = 80
#config.DataDirectory = 'tmp_datadir'
## note that TCPHiddenServiceEndpoint adds the config to above...
hs_endpoint = txtorcon.TCPHiddenServiceEndpoint(reactor, config, hs_public_port)

def updates(prog, tag, summary):
p = ('#' * int(10*(prog/100.0))) + ('.'*(10 - int(10*(prog/100.0))))
print "%s %s" % (p, summary)

def failed(f):
print "FAIL", f
reactor.stop()

@defer.inlineCallbacks
def main():
def main(reactor):
print "Launching Tor"
proto = yield txtorcon.launch_tor(config, reactor, progress_updates=updates)
tor = yield txtorcon.launch(reactor, socks_port=0, progress_updates=updates)

hs_endpoint = tor.create_onion_endpoint(80)

print "Starting site"
site = server.Site(Simple())
port = yield hs_endpoint.listen(site)

print port.address.onion_uri, port.address.onion_port, port.local_address
print port.getHost().onion_uri, port.getHost().onion_port, port.local_address
print "liftoff"
os.system("netstat -pltn")

## launch a new Tor and wait for the setup to happen
d = main()
d.addErrback(failed)
reactor.run()
task.react(main)
23 changes: 6 additions & 17 deletions integration/timeout_tor_launch/container_run
Expand Up @@ -10,7 +10,7 @@ import sys
import tempfile
import functools

from twisted.internet import reactor, defer
from twisted.internet import reactor, defer, task
from twisted.internet.endpoints import TCP4ServerEndpoint
from twisted.web import server, resource
from twisted.python import log
Expand All @@ -25,23 +25,12 @@ def updates(prog, tag, summary):
p = ('#' * int(10*(prog/100.0))) + ('.'*(10 - int(10*(prog/100.0))))
print "%s %s" % (p, summary)

def run_ps_exit(arg):
print "run_ps_exit called with:", arg
print 'Running "ps afxu":'
os.system("ps afxu")
reactor.stop()

@defer.inlineCallbacks
def main():
def main(reactor):
print "Launching Tor"
config = txtorcon.TorConfig()
config.SOCKSPort = 0
config.ORPort = 0
proto = yield txtorcon.launch_tor(config, reactor,
timeout=1, progress_updates=updates)
tor = yield txtorcon.launch(reactor, progress_updates=updates)
print "launch over:", proto
print 'Running "ps afxu":'
os.system("ps afxu")

d = main()
d.addBoth(run_ps_exit)
reactor.callLater(5, run_ps_exit)
reactor.run()
task.react(main)
1 change: 0 additions & 1 deletion requirements.txt
Expand Up @@ -4,4 +4,3 @@
Twisted>=11.1.0
ipaddress>=1.0.16
zope.interface>=3.6.1
txsocksx>=1.13.0
4 changes: 2 additions & 2 deletions test/test_addrmap.py
Expand Up @@ -2,14 +2,14 @@
from twisted.trial import unittest
from twisted.internet import task
from twisted.internet.interfaces import IReactorTime
from zope.interface import implements
from zope.interface import implementer

from txtorcon.addrmap import AddrMap
from txtorcon.interface import IAddrListener


@implementer(IAddrListener)
class AddrMapTests(unittest.TestCase):
implements(IAddrListener)

fmt = '%Y-%m-%d %H:%M:%S'

Expand Down
4 changes: 2 additions & 2 deletions test/test_circuit.py
Expand Up @@ -3,8 +3,8 @@
from twisted.trial import unittest
from twisted.internet import defer, task
from twisted.python.failure import Failure
from zope.interface import implements
from mock import patch
from zope.interface import implementer

from txtorcon import Circuit
from txtorcon import build_timeout_circuit
Expand All @@ -23,8 +23,8 @@
from mock import Mock


@implementer(IRouterContainer, ICircuitListener, ICircuitContainer, ITorControlProtocol)
class FakeTorController(object):
implements(IRouterContainer, ICircuitListener, ICircuitContainer, ITorControlProtocol)

post_bootstrap = defer.Deferred()
queue_command = Mock()
Expand Down

0 comments on commit fefc069

Please sign in to comment.