move channel-pruning responsibility down into Relay
This commit is contained in:
parent
b2336591a7
commit
2da94d5069
|
@ -1,6 +1,7 @@
|
|||
from __future__ import print_function
|
||||
import re, json, time, random
|
||||
from twisted.python import log
|
||||
from twisted.application import service, internet
|
||||
from twisted.web import server, resource, http
|
||||
|
||||
SECONDS = 1.0
|
||||
|
@ -10,6 +11,7 @@ DAY = 24*HOUR
|
|||
MB = 1000*1000
|
||||
|
||||
CHANNEL_EXPIRATION_TIME = 3*DAY
|
||||
EXPIRATION_CHECK_PERIOD = 2*HOUR
|
||||
|
||||
class EventsProtocol:
|
||||
def __init__(self, request):
|
||||
|
@ -191,12 +193,17 @@ class ChannelList(resource.Resource):
|
|||
"channel-ids": allocated}
|
||||
return (json.dumps(data)+"\n").encode("utf-8")
|
||||
|
||||
class Relay(resource.Resource):
|
||||
class Relay(resource.Resource, service.MultiService):
|
||||
def __init__(self, db, welcome):
|
||||
resource.Resource.__init__(self)
|
||||
service.MultiService.__init__(self)
|
||||
self.db = db
|
||||
self.welcome = welcome
|
||||
self.channels = {}
|
||||
t = internet.TimerService(EXPIRATION_CHECK_PERIOD,
|
||||
self.prune_old_channels)
|
||||
t.setServiceParent(self)
|
||||
|
||||
|
||||
def getChild(self, path, request):
|
||||
if path == b"allocate":
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from __future__ import print_function
|
||||
from twisted.internet import reactor, endpoints
|
||||
from twisted.application import service, internet
|
||||
from twisted.application import service
|
||||
from twisted.web import server, static, resource
|
||||
from ..util.endpoint_service import ServerEndpointService
|
||||
from .. import __version__
|
||||
|
@ -8,11 +8,6 @@ from ..database import get_db
|
|||
from .relay_server import Relay
|
||||
from .transit_server import Transit
|
||||
|
||||
SECONDS = 1.0
|
||||
MINUTE = 60*SECONDS
|
||||
HOUR = 60*MINUTE
|
||||
EXPIRATION_CHECK_PERIOD = 2*HOUR
|
||||
|
||||
class Root(resource.Resource):
|
||||
# child_FOO is a nevow thing, not a twisted.web.resource thing
|
||||
def __init__(self):
|
||||
|
@ -42,9 +37,6 @@ class RelayServer(service.MultiService):
|
|||
self.relayport_service.setServiceParent(self)
|
||||
self.relay = Relay(self.db, welcome) # accessible from tests
|
||||
self.root.putChild(b"wormhole-relay", self.relay)
|
||||
t = internet.TimerService(EXPIRATION_CHECK_PERIOD,
|
||||
self.relay.prune_old_channels)
|
||||
t.setServiceParent(self)
|
||||
if transitport:
|
||||
self.transit = Transit()
|
||||
self.transit.setServiceParent(self) # for the timer
|
||||
|
|
Loading…
Reference in New Issue
Block a user