~arx10/furemcape

3a7d73ce029596531c4ecad3f3219333049e1190 — Justin Ludwig 6 months ago 124b913 master
Allow feeder to listen on multiple interfaces

Signed-off-by: Justin Ludwig <justin@arcemtene.com>
1 files changed, 19 insertions(+), 7 deletions(-)

M feeder/furemcape/feeder/lumberjack.py
M feeder/furemcape/feeder/lumberjack.py => feeder/furemcape/feeder/lumberjack.py +19 -7
@@ 696,11 696,15 @@ class LumberjackReaderFactory(ServerFactory):
class LumberjackReaderService(Service):
    """Twisted service for lumberjack feeder."""

    def __init__(self, port=0, app="", tls=None, transformer=None, reactor=None):
    # keyword args represent config props
    def __init__(  # noqa: CFQ002
        self, port=0, interfaces=None, app="", tls=None, transformer=None, reactor=None
    ):
        """Creates the service.

        Arguments:
            port (int): Port to listen on (defaults to 5044).
            interfaces (list): List of interfaces to listen on (defaults to ["::"]).
            app (str): App name (defaults to lumberjack).
            tls (dict): Dict of TLS options:
                certificate (str): Optional path to TLS certificate file


@@ 723,6 727,7 @@ class LumberjackReaderService(Service):
        super().setName(self.app)

        self.port = port or environ.get("FUREMCAPE_FEEDER_PORT", 5044)
        self.interfaces = interfaces or ["::"]
        self.tls = build_tls_options(**tls if tls else {})
        self.transformer = transformer or Transformer()



@@ 736,13 741,20 @@ class LumberjackReaderService(Service):
        super().startService()
        self.transformer.validate_db()
        if self.tls:
            self.listener = self.reactor.listenSSL(
                self.port, LumberjackReaderFactory(self.transformer), self.tls
            )
            for interface in self.interfaces:
                self.listener = self.reactor.listenSSL(
                    self.port,
                    LumberjackReaderFactory(self.transformer),
                    self.tls,
                    interface=interface,
                )
        else:
            self.listener = self.reactor.listenTCP(
                self.port, LumberjackReaderFactory(self.transformer)
            )
            for interface in self.interfaces:
                self.listener = self.reactor.listenTCP(
                    self.port,
                    LumberjackReaderFactory(self.transformer),
                    interface=interface,
                )

    # override Service.stopService()
    def stopService(self):  # noqa: N802