remove wormhole.twisted.util port-allocation functions

This commit is contained in:
Brian Warner 2016-04-15 19:18:33 -07:00
parent e20026488a
commit 1a455c05f5
2 changed files with 11 additions and 35 deletions

View File

@ -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,9 +9,8 @@ class ServerBase:
def setUp(self):
self.sp = service.MultiService()
self.sp.startService()
d = allocate_ports()
def _got_ports(ports):
relayport, transitport = ports
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__)
@ -20,8 +19,6 @@ class ServerBase:
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
def tearDown(self):
# Unit tests that spawn a (blocking) client in a thread might still

View File

@ -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