async def create_server(cls, bind, tman: interfaces.TokenManager, log, loop, *, _server_context=None): self = cls() self._tokenmanager = tman self.log = log #self.loop = loop bind = bind or ('::', None) bind = (bind[0], bind[1] + (self._default_port - COAP_PORT) if bind[1] else self._default_port) def new_connection(): c = TcpConnection(self, log, loop) self._pool.add(c) return c try: server = await loop.create_server( new_connection, bind[0], bind[1], ssl=_server_context, reuse_port=defaults.has_reuse_port()) except socket.gaierror: raise error.ResolutionError( "No local bindable address found for %s" % bind[0]) self.server = server return self
async def _spawn_protocol(self, message): if message.unresolved_remote is None: host = message.opt.uri_host port = message.opt.uri_port or self._default_port if host is None: raise ValueError( "No location found to send message to (neither in .opt.uri_host nor in .remote)" ) else: host, port = util.hostportsplit(message.unresolved_remote) port = port or self._default_port if (host, port) in self._pool: return self._pool[(host, port)] try: _, protocol = await self.loop.create_connection( lambda: TcpConnection(self, self.log, self.loop, hostinfo=util.hostportjoin(host, port)), host, port, ssl=self._ssl_context_factory()) except socket.gaierror: raise error.ResolutionError( "No address information found for requests to %r" % host) except OSError: raise error.NetworkError("Connection failed to %r" % host) self._pool[(host, port)] = protocol return protocol
async def create_server(cls, bind, log, loop, tman): self = cls() self.loop = loop self.log = log self.tman = tman bind = bind or ('::', None) bind = (bind[0], bind[1] + (self.default_port - COAP_PORT) if bind[1] else self.default_port) config = QuicConfiguration(is_client=False, alpn_protocols='coap') config.load_cert_chain("aiocoap/ssl_cert.pem", "aiocoap/ssl_key.pem") PORT = 5684 PORT = 64999 try: server = await self.loop.create_datagram_endpoint( lambda: QuicServer(configuration=config, create_protocol=Quic), local_addr=(bind[0], PORT), reuse_port=socket.SO_REUSEPORT) Quic.ctx = self except socket.gaierror: raise error.ResolutionError( "No local bindable address found for %s" % bind[0]) self.server = server return self