Use StreamServerEndpointService (available since Twisted 10.2)

This commit is contained in:
David Reid 2016-08-04 00:08:36 -07:00
parent dc6416a257
commit 6aa8a47f9a
2 changed files with 2 additions and 30 deletions

View File

@ -1,27 +0,0 @@
from __future__ import unicode_literals
from twisted.python import log
from twisted.internet import defer
from twisted.application import service
# this should probably live in Twisted
class ServerEndpointService(service.Service):
def __init__(self, endpoint, factory):
self.endpoint = endpoint
self.factory = factory
self._started = defer.Deferred()
self._listeningport = None
def startService(self):
d = self.endpoint.listen(self.factory)
def _set_port(listeningport):
self._listeningport = listeningport
self._started.callback(listeningport)
d.addCallback(_set_port)
d.addErrback(log.err)
def stopService(self):
def _stop(port):
return port.stopListening()
self._started.addCallback(_stop)
return self._started

View File

@ -7,7 +7,6 @@ from twisted.internet import reactor, endpoints
from twisted.application import service, internet from twisted.application import service, internet
from twisted.web import server, static, resource from twisted.web import server, static, resource
from autobahn.twisted.resource import WebSocketResource from autobahn.twisted.resource import WebSocketResource
from .endpoint_service import ServerEndpointService
from .. import __version__ from .. import __version__
from .database import get_db from .database import get_db
from .rendezvous import Rendezvous from .rendezvous import Rendezvous
@ -71,14 +70,14 @@ class RelayServer(service.MultiService):
site.logRequests = False site.logRequests = False
r = endpoints.serverFromString(reactor, rendezvous_web_port) r = endpoints.serverFromString(reactor, rendezvous_web_port)
rendezvous_web_service = ServerEndpointService(r, site) rendezvous_web_service = internet.StreamServerEndpointService(r, site)
rendezvous_web_service.setServiceParent(self) rendezvous_web_service.setServiceParent(self)
if transit_port: if transit_port:
transit = Transit(db, blur_usage) transit = Transit(db, blur_usage)
transit.setServiceParent(self) # for the timer transit.setServiceParent(self) # for the timer
t = endpoints.serverFromString(reactor, transit_port) t = endpoints.serverFromString(reactor, transit_port)
transit_service = ServerEndpointService(t, transit) transit_service = internet.StreamServerEndpointService(t, transit)
transit_service.setServiceParent(self) transit_service.setServiceParent(self)
self._stats_file = stats_file self._stats_file = stats_file