|
|
|
|
@ -97,8 +97,9 @@ class ReportMuxClient(NetstringReceiver):
|
|
|
|
|
class ReportMuxFactory(Factory):
|
|
|
|
|
protocol = ReportMuxClient
|
|
|
|
|
|
|
|
|
|
def __init__(self, allowed_clients=('*',)):
|
|
|
|
|
def __init__(self, allowed_clients=('*',), inventory_backends=()):
|
|
|
|
|
self.allowed_clients = frozenset(allowed_clients)
|
|
|
|
|
self.inventory_backends = frozenset(inventory_backends)
|
|
|
|
|
self.clients = set()
|
|
|
|
|
self._config_by_backend = {}
|
|
|
|
|
self._bridges_by_backend = {}
|
|
|
|
|
@ -124,9 +125,22 @@ class ReportMuxFactory(Factory):
|
|
|
|
|
|
|
|
|
|
def ingest(self, backend_number, message):
|
|
|
|
|
opcode = message[:1]
|
|
|
|
|
inventory_only = backend_number in self.inventory_backends
|
|
|
|
|
if inventory_only and opcode != REPORT_OPCODES['CONFIG_SND']:
|
|
|
|
|
return
|
|
|
|
|
try:
|
|
|
|
|
if opcode == REPORT_OPCODES['CONFIG_SND']:
|
|
|
|
|
config = pickle.loads(message[1:])
|
|
|
|
|
if inventory_only:
|
|
|
|
|
# Inventory is not a second source of calls, bridge state or secrets.
|
|
|
|
|
fields = ('MODE', 'ENABLED', 'NETWORK_ID', 'TARGET_IP',
|
|
|
|
|
'TARGET_PORT', 'ENHANCED_OBP', 'VER', 'REPORT_INTERNAL')
|
|
|
|
|
config = {
|
|
|
|
|
name: dict({key: value[key] for key in fields if key in value},
|
|
|
|
|
REPORT_INVENTORY_ONLY=True)
|
|
|
|
|
for name, value in config.items()
|
|
|
|
|
if value.get('MODE') == 'OPENBRIDGE' and value.get('ENABLED')
|
|
|
|
|
}
|
|
|
|
|
self._config_by_backend[backend_number] = prefix_config(
|
|
|
|
|
backend_number,
|
|
|
|
|
config,
|
|
|
|
|
@ -204,7 +218,8 @@ class ReportMuxSource(NetstringReceiver):
|
|
|
|
|
|
|
|
|
|
def connectionMade(self):
|
|
|
|
|
self.sendString(REPORT_OPCODES['CONFIG_REQ'])
|
|
|
|
|
self.sendString(REPORT_OPCODES['BRIDGE_REQ'])
|
|
|
|
|
if self._factory.backend_number not in self._factory.mux.inventory_backends:
|
|
|
|
|
self.sendString(REPORT_OPCODES['BRIDGE_REQ'])
|
|
|
|
|
|
|
|
|
|
def stringReceived(self, data):
|
|
|
|
|
self._factory.mux.ingest(self._factory.backend_number, data)
|
|
|
|
|
@ -270,6 +285,8 @@ if __name__ == '__main__':
|
|
|
|
|
help='numbered source as NUMBER,HOST,PORT; repeat for each backend',
|
|
|
|
|
)
|
|
|
|
|
parser.add_argument('--listen-interface', default='127.0.0.1')
|
|
|
|
|
parser.add_argument('--inventory-backend', action='append', type=parse_backend,
|
|
|
|
|
default=[], help='FBP inventory only, as NUMBER,HOST,PORT')
|
|
|
|
|
parser.add_argument('--listen-port', type=int, default=4321)
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
'--client',
|
|
|
|
|
@ -278,7 +295,8 @@ if __name__ == '__main__':
|
|
|
|
|
)
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
|
|
backend_numbers = [number for number, _host, _port in args.backend]
|
|
|
|
|
backends = args.backend + args.inventory_backend
|
|
|
|
|
backend_numbers = [number for number, _host, _port in backends]
|
|
|
|
|
if len(set(backend_numbers)) != len(backend_numbers):
|
|
|
|
|
parser.error('backend numbers must be unique')
|
|
|
|
|
|
|
|
|
|
@ -288,9 +306,10 @@ if __name__ == '__main__':
|
|
|
|
|
signal.signal(signal.SIGINT, sig_handler)
|
|
|
|
|
signal.signal(signal.SIGTERM, sig_handler)
|
|
|
|
|
|
|
|
|
|
mux = ReportMuxFactory(args.client or ('*',))
|
|
|
|
|
mux = ReportMuxFactory(args.client or ('*',),
|
|
|
|
|
[number for number, _host, _port in args.inventory_backend])
|
|
|
|
|
reactor.listenTCP(args.listen_port, mux, interface=args.listen_interface)
|
|
|
|
|
for backend_number, host, port in args.backend:
|
|
|
|
|
for backend_number, host, port in backends:
|
|
|
|
|
reactor.connectTCP(
|
|
|
|
|
host,
|
|
|
|
|
port,
|
|
|
|
|
|