From 1a455c05f591115fbb4db11ab1e710879dd4b138 Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Fri, 15 Apr 2016 19:18:33 -0700 Subject: [PATCH] remove wormhole.twisted.util port-allocation functions --- src/wormhole/test/common.py | 25 +++++++++++-------------- src/wormhole/twisted/util.py | 21 --------------------- 2 files changed, 11 insertions(+), 35 deletions(-) delete mode 100644 src/wormhole/twisted/util.py diff --git a/src/wormhole/test/common.py b/src/wormhole/test/common.py index 56aa38e..ee2de77 100644 --- a/src/wormhole/test/common.py +++ b/src/wormhole/test/common.py @@ -1,7 +1,7 @@ from twisted.application import service from twisted.internet import reactor, defer from twisted.python import log -from ..twisted.util import allocate_ports +from ..twisted.transit import allocate_tcp_port from ..servers.server import RelayServer from .. import __version__ @@ -9,19 +9,16 @@ class ServerBase: def setUp(self): self.sp = service.MultiService() self.sp.startService() - d = allocate_ports() - def _got_ports(ports): - relayport, transitport = ports - s = RelayServer("tcp:%d:interface=127.0.0.1" % relayport, - "tcp:%s:interface=127.0.0.1" % transitport, - __version__) - s.setServiceParent(self.sp) - self._relay_server = s.relay - self._transit_server = s.transit - self.relayurl = u"http://127.0.0.1:%d/wormhole-relay/" % relayport - self.transit = u"tcp:127.0.0.1:%d" % transitport - d.addCallback(_got_ports) - return d + relayport = allocate_tcp_port() + transitport = allocate_tcp_port() + s = RelayServer("tcp:%d:interface=127.0.0.1" % relayport, + "tcp:%s:interface=127.0.0.1" % transitport, + __version__) + s.setServiceParent(self.sp) + self._relay_server = s.relay + self._transit_server = s.transit + self.relayurl = u"http://127.0.0.1:%d/wormhole-relay/" % relayport + self.transit = u"tcp:127.0.0.1:%d" % transitport def tearDown(self): # Unit tests that spawn a (blocking) client in a thread might still diff --git a/src/wormhole/twisted/util.py b/src/wormhole/twisted/util.py deleted file mode 100644 index 182fc34..0000000 --- a/src/wormhole/twisted/util.py +++ /dev/null @@ -1,21 +0,0 @@ -from twisted.internet import defer, protocol, endpoints, reactor - -def allocate_port(): - ep = endpoints.serverFromString(reactor, "tcp:0:interface=127.0.0.1") - d = ep.listen(protocol.Factory()) - def _listening(lp): - port = lp.getHost().port - d2 = lp.stopListening() - d2.addCallback(lambda _: port) - return d2 - d.addCallback(_listening) - return d - -def allocate_ports(): - d = defer.DeferredList([allocate_port(), allocate_port()]) - def _done(results): - port1 = results[0][1] - port2 = results[1][1] - return (port1, port2) - d.addCallback(_done) - return d