diff --git a/sat/bridge/bridge_constructor/constructors/pb/pb_core_template.py b/sat/bridge/bridge_constructor/constructors/pb/pb_core_template.py
index a9d3e185..71e1075b 100644
--- a/sat/bridge/bridge_constructor/constructors/pb/pb_core_template.py
+++ b/sat/bridge/bridge_constructor/constructors/pb/pb_core_template.py
@@ -19,9 +19,11 @@
import dataclasses
-from sat.core.log import getLogger
+from pathlib import Path
from twisted.spread import jelly, pb
from twisted.internet import reactor
+from sat.core.log import getLogger
+from sat.tools import config
log = getLogger(__name__)
@@ -103,7 +105,31 @@ class Bridge(object):
def __init__(self):
log.info("Init Perspective Broker...")
self.root = PBRoot()
- reactor.listenTCP(8789, pb.PBServerFactory(self.root))
+ conf = config.parseMainConf()
+ conn_type = config.getConfig(
+ conf,
+ "",
+ "bridge_pb_connection_type",
+ "unix_socket"
+ )
+ if conn_type == "unix_socket":
+ local_dir = Path(config.getConfig(conf, "", "local_dir")).resolve()
+ socket_path = local_dir / "bridge_pb"
+ log.info(f"using UNIX Socket at {socket_path}")
+ reactor.listenUNIX(
+ str(socket_path), pb.PBServerFactory(self.root), mode=0o600
+ )
+ elif conn_type == "socket":
+ port = int(config.getConfig(
+ conf,
+ "",
+ "bridge_pb_port",
+ 8789
+ ))
+ log.info(f"using TCP Socket at port {port}")
+ reactor.listenTCP(port, pb.PBServerFactory(self.root))
+ else:
+ raise ValueError(f"Unknown pb connection type: {conn_type!r}")
def sendSignal(self, name, *args, **kwargs):
self.root.sendSignal(name, args, kwargs)
@@ -117,7 +143,9 @@ class Bridge(object):
setattr(self.root, "remote_" + name, callback)
# self.root.register_method(name, callback)
- def addMethod(self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={}):
+ def addMethod(
+ self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={}
+ ):
"""Dynamically add a method to PB Bridge"""
# FIXME: doc parameter is kept only temporary, the time to remove it from calls
log.debug("Adding method {name} to PB bridge".format(name=name))
diff --git a/sat/bridge/bridge_constructor/constructors/pb/pb_frontend_template.py b/sat/bridge/bridge_constructor/constructors/pb/pb_frontend_template.py
index f25f4349..9f8a77d8 100644
--- a/sat/bridge/bridge_constructor/constructors/pb/pb_frontend_template.py
+++ b/sat/bridge/bridge_constructor/constructors/pb/pb_frontend_template.py
@@ -17,12 +17,14 @@
# along with this program. If not, see .
import asyncio
+from logging import getLogger
from functools import partial
+from pathlib import Path
from twisted.spread import pb
from twisted.internet import reactor, defer
-from twisted.internet.error import ConnectionRefusedError
-from logging import getLogger
+from twisted.internet.error import ConnectionRefusedError, ConnectError
from sat.core import exceptions
+from sat.tools import config
from sat_frontends.bridge.bridge_frontend import BridgeException
log = getLogger(__name__)
@@ -130,14 +132,40 @@ class Bridge(object):
def getRootObjectEb(self, failure_):
"""Call errback with appropriate bridge error"""
- if failure_.check(ConnectionRefusedError):
+ if failure_.check(ConnectionRefusedError, ConnectError):
raise exceptions.BridgeExceptionNoService
else:
raise failure_
def bridgeConnect(self, callback, errback):
factory = pb.PBClientFactory()
- reactor.connectTCP("localhost", 8789, factory)
+ conf = config.parseMainConf()
+ conn_type = config.getConfig(
+ conf,
+ "",
+ "bridge_pb_connection_type",
+ "unix_socket"
+ )
+ if conn_type == "unix_socket":
+ local_dir = Path(config.getConfig(conf, "", "local_dir")).resolve()
+ socket_path = local_dir / "bridge_pb"
+ reactor.connectUNIX(str(socket_path), factory)
+ elif conn_type == "socket":
+ host = int(config.getConfig(
+ conf,
+ "",
+ "bridge_pb_host",
+ "localhost"
+ ))
+ port = int(config.getConfig(
+ conf,
+ "",
+ "bridge_pb_port",
+ 8789
+ ))
+ reactor.connectTCP(host, port, factory)
+ else:
+ raise ValueError(f"Unknown pb connection type: {conn_type!r}")
d = factory.getRootObject()
d.addCallback(self._set_root)
if callback is not None:
diff --git a/sat/bridge/pb.py b/sat/bridge/pb.py
index 52e8b02c..04132800 100644
--- a/sat/bridge/pb.py
+++ b/sat/bridge/pb.py
@@ -19,9 +19,11 @@
import dataclasses
-from sat.core.log import getLogger
+from pathlib import Path
from twisted.spread import jelly, pb
from twisted.internet import reactor
+from sat.core.log import getLogger
+from sat.tools import config
log = getLogger(__name__)
@@ -103,7 +105,31 @@ class Bridge(object):
def __init__(self):
log.info("Init Perspective Broker...")
self.root = PBRoot()
- reactor.listenTCP(8789, pb.PBServerFactory(self.root))
+ conf = config.parseMainConf()
+ conn_type = config.getConfig(
+ conf,
+ "",
+ "bridge_pb_connection_type",
+ "unix_socket"
+ )
+ if conn_type == "unix_socket":
+ local_dir = Path(config.getConfig(conf, "", "local_dir")).resolve()
+ socket_path = local_dir / "bridge_pb"
+ log.info(f"using UNIX Socket at {socket_path}")
+ reactor.listenUNIX(
+ str(socket_path), pb.PBServerFactory(self.root), mode=0o600
+ )
+ elif conn_type == "socket":
+ port = int(config.getConfig(
+ conf,
+ "",
+ "bridge_pb_port",
+ 8789
+ ))
+ log.info(f"using TCP Socket at port {port}")
+ reactor.listenTCP(port, pb.PBServerFactory(self.root))
+ else:
+ raise ValueError(f"Unknown pb connection type: {conn_type!r}")
def sendSignal(self, name, *args, **kwargs):
self.root.sendSignal(name, args, kwargs)
@@ -117,7 +143,9 @@ class Bridge(object):
setattr(self.root, "remote_" + name, callback)
# self.root.register_method(name, callback)
- def addMethod(self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={}):
+ def addMethod(
+ self, name, int_suffix, in_sign, out_sign, method, async_=False, doc={}
+ ):
"""Dynamically add a method to PB Bridge"""
# FIXME: doc parameter is kept only temporary, the time to remove it from calls
log.debug("Adding method {name} to PB bridge".format(name=name))
diff --git a/sat_frontends/bridge/pb.py b/sat_frontends/bridge/pb.py
index 1ea742d5..3b747078 100644
--- a/sat_frontends/bridge/pb.py
+++ b/sat_frontends/bridge/pb.py
@@ -17,12 +17,14 @@
# along with this program. If not, see .
import asyncio
+from logging import getLogger
from functools import partial
+from pathlib import Path
from twisted.spread import pb
from twisted.internet import reactor, defer
-from twisted.internet.error import ConnectionRefusedError
-from logging import getLogger
+from twisted.internet.error import ConnectionRefusedError, ConnectError
from sat.core import exceptions
+from sat.tools import config
from sat_frontends.bridge.bridge_frontend import BridgeException
log = getLogger(__name__)
@@ -130,14 +132,40 @@ class Bridge(object):
def getRootObjectEb(self, failure_):
"""Call errback with appropriate bridge error"""
- if failure_.check(ConnectionRefusedError):
+ if failure_.check(ConnectionRefusedError, ConnectError):
raise exceptions.BridgeExceptionNoService
else:
raise failure_
def bridgeConnect(self, callback, errback):
factory = pb.PBClientFactory()
- reactor.connectTCP("localhost", 8789, factory)
+ conf = config.parseMainConf()
+ conn_type = config.getConfig(
+ conf,
+ "",
+ "bridge_pb_connection_type",
+ "unix_socket"
+ )
+ if conn_type == "unix_socket":
+ local_dir = Path(config.getConfig(conf, "", "local_dir")).resolve()
+ socket_path = local_dir / "bridge_pb"
+ reactor.connectUNIX(str(socket_path), factory)
+ elif conn_type == "socket":
+ host = int(config.getConfig(
+ conf,
+ "",
+ "bridge_pb_host",
+ "localhost"
+ ))
+ port = int(config.getConfig(
+ conf,
+ "",
+ "bridge_pb_port",
+ 8789
+ ))
+ reactor.connectTCP(host, port, factory)
+ else:
+ raise ValueError(f"Unknown pb connection type: {conn_type!r}")
d = factory.getRootObject()
d.addCallback(self._set_root)
if callback is not None: