Switch crosslink into a twistd plugin
This commit is contained in:
parent
5029308039
commit
338d2cf981
|
@ -7,3 +7,4 @@ sounds/*
|
|||
*.sqlite3
|
||||
*.shelve
|
||||
dropin.cache
|
||||
twistd.pid
|
||||
|
|
|
@ -4,10 +4,18 @@
|
|||
# Copyright 2010 Maurizio Porrato <maurizio.porrato@gmail.com>
|
||||
# See LICENSE.txt for copyright info
|
||||
|
||||
from twisted.internet import reactor
|
||||
from twisted.application.service import MultiService
|
||||
from zope.interface import implements
|
||||
from twisted.plugin import IPlugin
|
||||
from twisted.application.service import IServiceMaker
|
||||
from twisted.application import internet
|
||||
from twisted.python import usage
|
||||
from ConfigParser import ConfigParser
|
||||
from frn.protocol.client import FRNClient, FRNClientFactory
|
||||
from frn.user import FRNUser
|
||||
from twisted.python import log
|
||||
from os.path import curdir, join as pjoin
|
||||
|
||||
|
||||
clients = []
|
||||
talking = None
|
||||
|
@ -18,6 +26,8 @@ class FRNCrosslinkClient(FRNClient):
|
|||
self.txOk = False
|
||||
self.txReq = False
|
||||
self.clientId = None
|
||||
from twisted.internet import reactor
|
||||
self.reactor = reactor
|
||||
FRNClient.connectionMade(self)
|
||||
|
||||
def getClientName(self, client_id):
|
||||
|
@ -76,7 +86,7 @@ class FRNCrosslinkClient(FRNClient):
|
|||
log.msg("Requesting TX for %s" % conn.user.ON)
|
||||
conn.startTransmission()
|
||||
conn.txReq = True
|
||||
conn.busyTimer = conn.factory.reactor.callLater(
|
||||
conn.busyTimer = self.reactor.callLater(
|
||||
5.0, conn.goIdle)
|
||||
self.pong()
|
||||
|
||||
|
@ -93,7 +103,6 @@ class FRNCrosslinkClient(FRNClient):
|
|||
|
||||
class FRNCrosslinkClientFactory(FRNClientFactory):
|
||||
protocol = FRNCrosslinkClient
|
||||
reactor = reactor
|
||||
|
||||
def buildProtocol(self, addr):
|
||||
p = FRNClientFactory.buildProtocol(self, addr)
|
||||
|
@ -101,42 +110,65 @@ class FRNCrosslinkClientFactory(FRNClientFactory):
|
|||
return p
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
from os.path import dirname, join as pjoin
|
||||
from ConfigParser import ConfigParser
|
||||
class Options(usage.Options):
|
||||
|
||||
log.startLogging(sys.stderr)
|
||||
optParameters = [
|
||||
["confdir", "c", curdir, "Directory containing config files"]
|
||||
]
|
||||
|
||||
basedir = dirname(__file__)
|
||||
def parseArgs(self, *serverdefs):
|
||||
basedir = self['confdir']
|
||||
acfg = ConfigParser()
|
||||
acfg.read(['/etc/grn/accounts.conf',
|
||||
pjoin(basedir,'accounts.conf'), 'accounts.conf'])
|
||||
|
||||
acfg = ConfigParser()
|
||||
acfg.read(['/etc/grn/accounts.conf',
|
||||
pjoin(basedir,'accounts.conf'), 'accounts.conf'])
|
||||
scfg = ConfigParser()
|
||||
scfg.read(['/etc/grn/servers.conf',
|
||||
pjoin(basedir,'servers.conf'), 'servers.conf'])
|
||||
|
||||
scfg = ConfigParser()
|
||||
scfg.read(['/etc/grn/servers.conf',
|
||||
pjoin(basedir,'servers.conf'), 'servers.conf'])
|
||||
clients = []
|
||||
for serverdef in serverdefs:
|
||||
account_name, server_name, network_name = serverdef.split(':', 2)
|
||||
|
||||
argc = len(sys.argv)
|
||||
if argc > 1:
|
||||
for client_data in sys.argv[1:]:
|
||||
account_name, server_name, network_name = client_data.split(':',2)
|
||||
account_cfg = acfg.items(account_name)+[('network', network_name)]
|
||||
server_cfg = scfg.items(server_name)
|
||||
server = scfg.get(server_name, 'server')
|
||||
port = scfg.getint(server_name, 'port')
|
||||
d = dict(account_cfg)
|
||||
sd = {}
|
||||
sd['server'] = scfg.get(server_name, 'server')
|
||||
sd['port'] = scfg.getint(server_name, 'port')
|
||||
sd['backup_server'] = scfg.get(server_name, 'backup_server')
|
||||
sd['backup_port'] = scfg.getint(server_name, 'backup_port')
|
||||
sd['operator'] = acfg.get(account_name, 'operator')
|
||||
sd['email'] = acfg.get(account_name, 'email')
|
||||
sd['password'] = acfg.get(account_name, 'password')
|
||||
sd['description'] = acfg.get(account_name, 'description')
|
||||
sd['country'] = acfg.get(account_name, 'country')
|
||||
sd['city'] = acfg.get(account_name, 'city')
|
||||
sd['network'] = network_name
|
||||
clients.append(sd)
|
||||
self['clients'] = clients
|
||||
|
||||
|
||||
class FRNCrosslinkServiceMaker(object):
|
||||
implements(IServiceMaker, IPlugin)
|
||||
tapname = "frncrosslink"
|
||||
description = "Freeradionetwork crosslink"
|
||||
options = Options
|
||||
|
||||
def makeService(self, options):
|
||||
s = MultiService()
|
||||
global clients # FIXME: Get rid of this hack
|
||||
for c in options['clients']:
|
||||
user = FRNUser(
|
||||
EA=d['email'],
|
||||
PW=d['password'], ON=d['operator'],
|
||||
# BC=d['transmission'], DS=d['description'],
|
||||
BC="Crosslink", DS=d['description'],
|
||||
NN=d['country'], CT=d['city'], NT=d['network'])
|
||||
EA=c['email'],
|
||||
PW=c['password'], ON=c['operator'],
|
||||
# BC=c['transmission'], DS=c['description'],
|
||||
BC="Crosslink", DS=c['description'],
|
||||
NN=c['country'], CT=c['city'], NT=c['network'])
|
||||
factory = FRNCrosslinkClientFactory(user)
|
||||
clients.append((server, port, user, factory))
|
||||
reactor.connectTCP(server, port, factory)
|
||||
reactor.run()
|
||||
clients.append((c['server'], c['port'], user, factory))
|
||||
s.addService(
|
||||
internet.TCPClient(c['server'], c['port'], factory))
|
||||
return s
|
||||
|
||||
|
||||
serviceMaker = FRNCrosslinkServiceMaker()
|
||||
|
||||
# vim: set et ai sw=4 ts=4 sts=4:
|
Loading…
Reference in New Issue