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