def listen_ssl( bind_addresses, port, factory, context_factory, reactor=reactor, backlog=50 ): """ Create an TLS-over-TCP socket for a port and several addresses Returns: list of twisted.internet.tcp.Port listening for TLS connections """ r = [] for address in bind_addresses: try: r.append( reactor.listenSSL( port, factory, context_factory, backlog, address ) ) except error.CannotListenError as e: check_bind_error(e, address, bind_addresses) return r
def listen_ssl( bind_addresses: Collection[str], port: int, factory: ServerFactory, context_factory: IOpenSSLContextFactory, reactor: IReactorSSL = reactor, backlog: int = 50, ) -> List[Port]: """ Create an TLS-over-TCP socket for a port and several addresses Returns: list of twisted.internet.tcp.Port listening for TLS connections """ r = [] for address in bind_addresses: try: r.append( reactor.listenSSL(port, factory, context_factory, backlog, address)) except error.CannotListenError as e: check_bind_error(e, address, bind_addresses) # IReactorSSL incorrectly declares that an int is returned from listenSSL, # it actually returns an object implementing IListeningPort, but we know it # will be a Port instance. return r # type: ignore[return-value]
def listen_ssl( bind_addresses, port, factory, context_factory, reactor=reactor, backlog=50 ): """ Create an TLS-over-TCP socket for a port and several addresses Returns: list of twisted.internet.tcp.Port listening for TLS connections """ r = [] for address in bind_addresses: try: r.append( reactor.listenSSL( port, factory, context_factory, backlog, address ) ) except error.CannotListenError as e: check_bind_error(e, address, bind_addresses) return r
def listen_tcp(bind_addresses, port, factory, reactor=reactor, backlog=50): """ Create a TCP socket for a port and several addresses Returns: list[twisted.internet.tcp.Port]: listening for TCP connections """ r = [] for address in bind_addresses: try: r.append(reactor.listenTCP(port, factory, backlog, address)) except error.CannotListenError as e: check_bind_error(e, address, bind_addresses) return r
def listen_tcp(bind_addresses, port, factory, reactor=reactor, backlog=50): """ Create a TCP socket for a port and several addresses Returns: list (empty) """ for address in bind_addresses: try: reactor.listenTCP(port, factory, backlog, address) except error.CannotListenError as e: check_bind_error(e, address, bind_addresses) logger.info("Synapse now listening on TCP port %d", port) return []
async def start_listening(self) -> None: from synapse.handlers import acme_issuing_service # Configure logging for txacme, if you need to debug # from eliot import add_destinations # from eliot.twisted import TwistedDestination # # add_destinations(TwistedDestination()) well_known = Resource() self._issuer = acme_issuing_service.create_issuing_service( self.reactor, acme_url=self.hs.config.acme_url, account_key_file=self.hs.config.acme_account_key_file, well_known_resource=well_known, ) responder_resource = Resource() responder_resource.putChild(b".well-known", well_known) responder_resource.putChild(b"check", static.Data(b"OK", b"text/plain")) srv = server.Site(responder_resource) bind_addresses = self.hs.config.acme_bind_addresses for host in bind_addresses: logger.info("Listening for ACME requests on %s:%i", host, self.hs.config.acme_port) try: self.reactor.listenTCP(self.hs.config.acme_port, srv, backlog=50, interface=host) except twisted.internet.error.CannotListenError as e: check_bind_error(e, host, bind_addresses) # Make sure we are registered to the ACME server. There's no public API # for this, it is usually triggered by startService, but since we don't # want it to control where we save the certificates, we have to reach in # and trigger the registration machinery ourselves. self._issuer._registered = False try: await self._issuer._ensure_registered() except Exception: logger.error(ACME_REGISTER_FAIL_ERROR) raise
def listen_tcp(bind_addresses, port, factory, reactor=reactor, backlog=50): """ Create a TCP socket for a port and several addresses Returns: list[twisted.internet.tcp.Port]: listening for TCP connections """ r = [] for address in bind_addresses: try: r.append( reactor.listenTCP( port, factory, backlog, address ) ) except error.CannotListenError as e: check_bind_error(e, address, bind_addresses) return r
def listen_tcp( bind_addresses: Collection[str], port: int, factory: ServerFactory, reactor: IReactorTCP = reactor, backlog: int = 50, ) -> List[Port]: """ Create a TCP socket for a port and several addresses Returns: list of twisted.internet.tcp.Port listening for TCP connections """ r = [] for address in bind_addresses: try: r.append(reactor.listenTCP(port, factory, backlog, address)) except error.CannotListenError as e: check_bind_error(e, address, bind_addresses) # IReactorTCP returns an object implementing IListeningPort from listenTCP, # but we know it will be a Port instance. return r # type: ignore[return-value]
def start_listening(self): # Configure logging for txacme, if you need to debug # from eliot import add_destinations # from eliot.twisted import TwistedDestination # # add_destinations(TwistedDestination()) from txacme.challenges import HTTP01Responder from txacme.service import AcmeIssuingService from txacme.endpoint import load_or_create_client_key from txacme.client import Client from josepy.jwa import RS256 self._store = ErsatzStore() responder = HTTP01Responder() self._issuer = AcmeIssuingService( cert_store=self._store, client_creator=(lambda: Client.from_url( reactor=self.reactor, url=URL.from_text(self.hs.config.acme_url), key=load_or_create_client_key( FilePath(self.hs.config.config_dir_path)), alg=RS256, )), clock=self.reactor, responders=[responder], ) well_known = Resource() well_known.putChild(b'acme-challenge', responder.resource) responder_resource = Resource() responder_resource.putChild(b'.well-known', well_known) responder_resource.putChild(b'check', static.Data(b'OK', b'text/plain')) srv = server.Site(responder_resource) bind_addresses = self.hs.config.acme_bind_addresses for host in bind_addresses: logger.info( "Listening for ACME requests on %s:%i", host, self.hs.config.acme_port, ) try: self.reactor.listenTCP( self.hs.config.acme_port, srv, interface=host, ) except twisted.internet.error.CannotListenError as e: check_bind_error(e, host, bind_addresses) # Make sure we are registered to the ACME server. There's no public API # for this, it is usually triggered by startService, but since we don't # want it to control where we save the certificates, we have to reach in # and trigger the registration machinery ourselves. self._issuer._registered = False yield self._issuer._ensure_registered()