def connection_made(self, transport: asyncio.BaseTransport) -> None: """Called twice, when the execution connection and the information channel are established.""" if transport.get_extra_info("peername") is not None: Connection.connection_made(self, transport) self.send_message(MessageType.LOGIN, LOGIN_MESSAGE.pack(self.team_name, self.secret), LOGIN_MESSAGE_SIZE) else: Subscription.connection_made(self, transport)
def connection_made(self, transport: asyncio.BaseTransport) -> None: """Accept an incoming TCP connection. Args: transport: Passed in asyncio.Transport """ peername = transport.get_extra_info("peername") logger.debug(f"Connection made with: {peername}") self.transport = cast(asyncio.Transport, transport)
def connection_made(self, transport: asyncio.BaseTransport) -> None: """ Configure write buffer limits. The high-water limit is defined by ``self.write_limit``. The low-water limit currently defaults to ``self.write_limit // 4`` in :meth:`~asyncio.WriteTransport.set_write_buffer_limits`, which should be all right for reasonable use cases of this library. This is the earliest point where we can get hold of the transport, which means it's the best point for configuring it. """ logger.debug("%s - event = connection_made(%s)", self.side, transport) # mypy thinks transport is a BaseTransport, not a Transport. transport.set_write_buffer_limits(self.write_limit) # type: ignore super().connection_made(transport)
def connection_made(self, transport: BaseTransport) -> None: self.transport = typing.cast(Transport, transport) sock = transport.get_extra_info("socket") self.file_no = sock.fileno() sock.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) if self._node.opts.enable_tcp_quickack: self.enable_tcp_quickack() if self.direction == NetworkDirection.INBOUND: self.endpoint = IpEndpoint(*transport.get_extra_info("peername")) logger.debug("[{}] - accepted connection.", self) self._node.on_connection_added(self) self.state = SocketConnectionStates.INITIALIZED self.can_send = True self.send() logger.debug("[{}] - connection established successfully.", self)
def data_received(self, transport: asyncio.BaseTransport, data: bytes) -> None: self.peername = transport.get_extra_info('peername') for m in self.reader.data_received(data): try: f = getattr(self, '_m_{}'.format(m[0].lower())) f(*m[1:]) except Exception as ex: self.logger.error(ex)
def connection_made(self, transport: asyncio.BaseTransport) -> None: self.transport = cast(asyncio.Transport, transport) self._over_ssl = transport.get_extra_info("sslcontext") is not None self._response_waiter = self._loop.create_future() self._command_lock = asyncio.Lock(loop=self._loop) if self._connection_lost_callback is not None: self._connection_lost_waiter = self._loop.create_future() self._connection_lost_waiter.add_done_callback( self._connection_lost_callback)
def connection_made(self, transport: asyncio.BaseTransport) -> None: ssl_object = transport.get_extra_info('ssl_object') if ssl_object is not None: protocol = ssl_object.selected_alpn_protocol() else: protocol = 'http/1.1' if protocol == 'h2': self._http_server = H2Server(self.app, self.loop, transport) else: self._http_server = H11Server(self.app, self.loop, transport)
def data_received(self, transport: asyncio.BaseTransport, data: bytes) -> None: self.peername = transport.get_extra_info('peername') for y in self.decoder.data_received(data): try: # check version and vendorId if y[1] > 16 or y[2] not in (0, 100): return f = getattr(self, '_y_{}'.format(binascii.hexlify(struct.pack('!H', y[0])).decode())) f(*y[1:]) except Exception as ex: self.logger.error(ex)
def connection_made(self, transport: asyncio.BaseTransport) -> None: ssl_object = transport.get_extra_info("ssl_object") if ssl_object is not None: self._ssl_enabled = True protocol = ssl_object.selected_alpn_protocol() else: protocol = "http/1.1" if protocol == "h2": self._server = H2Server(self.app, self.loop, self.config, transport) else: self._server = H11Server(self.app, self.loop, self.config, transport)
def connection_made(self, transport: BaseTransport) -> None: sock = transport.get_extra_info('socket') if sock is not None: _set_nodelay(sock) h2_conn = H2Connection(config=self.config) h2_conn.initiate_connection() self.connection = Connection(h2_conn, cast(Transport, transport), loop=self.loop) self.connection.flush() self.processor = EventsProcessor(self.handler, self.connection)
async def backport_start_tls( transport: asyncio.BaseTransport, protocol: asyncio.BaseProtocol, sslcontext: ssl.SSLContext = None, *, server_side: bool = False, server_hostname: str = None, ssl_handshake_timeout: float = None, ) -> asyncio.Transport: # pragma: nocover (Since it's not used on all Python versions.) """ Python 3.6 asyncio doesn't have a start_tls() method on the loop so we use this function in place of the loop's start_tls() method. Adapted from this comment: https://github.com/urllib3/urllib3/issues/1323#issuecomment-362494839 """ import asyncio.sslproto loop = asyncio.get_event_loop() waiter = loop.create_future() ssl_protocol = asyncio.sslproto.SSLProtocol( loop, protocol, sslcontext, waiter, server_side=False, server_hostname=server_hostname, call_connection_made=False, ) transport.set_protocol(ssl_protocol) loop.call_soon(ssl_protocol.connection_made, transport) loop.call_soon(transport.resume_reading) # type: ignore await waiter return ssl_protocol._app_transport
def connection_made(self, transport: asyncio.BaseTransport) -> None: self.request_start = clock_ns() print('connection made') self.connections.add(self) self.transport = transport self.flow = FlowControl(transport) sn_info = pn_info = None # sockname, peername t_sock = transport.get_extra_info('socket') if t_sock is not None: t_sock: socket.socket # INET: (host, port) # INET6: ??? # UNIX: path sn_info = t_sock.getsockname() if not sn_info: sn_info = transport.get_extra_info('sockname') if sn_info: self.server = sn_info pn_info = t_sock.getpeername() if not pn_info: pn_info = transport.get_extra_info('peername') if pn_info: self.client = pn_info else: print('couldnt get socket from transport') breakpoint() is_ssl = bool(transport.get_extra_info('sslcontext')) self.scheme = 'https' if is_ssl else 'http'
def connection_made(self, transport: asyncio.BaseTransport) -> None: """ Modified ``connection_made`` that supports upgrading our transport in place using STARTTLS. The only difference here from StreamReaderProtocol's version is we are setting the _transport directly on the StreamReader, rather than calling set_transport (which will raise an AssertionError on upgrade). """ self._stream_reader._transport = transport # type: ignore self._over_ssl = transport.get_extra_info('sslcontext') is not None if self._client_connected_cb is not None: # type: ignore self._stream_writer = asyncio.StreamWriter( transport, self, self._stream_reader, self._loop) res = self._client_connected_cb( # type: ignore self._stream_reader, self._stream_writer) if asyncio.iscoroutine(res): self._loop.create_task(res)
def connection_made(self, transport: asyncio.BaseTransport) -> None: """ Modified ``connection_made`` that supports upgrading our transport in place using STARTTLS. We set the _transport directly on the StreamReader, rather than calling set_transport (which will raise an AssertionError on upgrade). """ if self._stream_reader is None: raise SMTPServerDisconnected("Client not connected") self._stream_reader._transport = transport # type: ignore self._over_ssl = transport.get_extra_info("sslcontext") is not None self._stream_writer = asyncio.StreamWriter(transport, self, self._stream_reader, self._loop) self._client_connected_cb( # type: ignore self._stream_reader, self._stream_writer)
def connection_made(self, transport: BaseTransport) -> None: transport = typing.cast(Transport, transport) if self._endpoint is None: self._endpoint = IpEndpoint(*transport.get_extra_info("peername")) endpoint = self._endpoint assert endpoint is not None if self._is_server: try: cert = self.get_peer_certificate(transport) key = extensions_factory.get_node_id(cert) if key is None: key = endpoint.ip_address except TypeError: key = endpoint.ip_address attempts = self._node.report_connection_attempt(key) if attempts >= constants.MAX_HIGH_RECONNECT_ATTEMPTS_ALLOWED: logger.debug( "Rejecting connection attempt from {} / {}. Too many attempts: {}", self._endpoint, key, attempts) # transport.abort() # return if sys.version.startswith("3.6."): protocol_cls = SocketConnectionProtocolPy36 else: from bxcommon.network.socket_connection_protocol import SocketConnectionProtocol protocol_cls = SocketConnectionProtocol if self._is_server: endpoint = None delegate_protocol = protocol_cls(self._node, endpoint, self.is_ssl) delegate_protocol.connection_made(transport) self._delegate_protocol = delegate_protocol
def connection_made(self, transport: BaseTransport) -> None: if not isinstance(transport, Transport): raise ValueError("transport must be a proper Transport") super().connection_made(transport) # when we get a TCP connection to the HTTP proxy, we invoke the CONNECT # method on it to open a tunnelled TCP connection through the proxy to # the other side host, port = self._target_hostport transport.write(f"CONNECT {host}:{port} HTTP/1.0\r\n".encode()) if self._proxy_credentials: username, password = self._proxy_credentials # a credential pair is a urlsafe-base64-encoded pair separated by colon encoded_credentials = urlsafe_b64encode( f"{username}:{password}".encode()) transport.write(b"Proxy-Authorization: basic " + encoded_credentials + b"\r\n") # a blank line terminates the request headers transport.write(b"\r\n") logger.debug("Initiating proxy CONNECT") # now we wait ... self._transport = transport
def connection_made(self, transport: asyncio.BaseTransport) -> None: super().connection_made(transport) assert isinstance(transport, asyncio.Transport) transport.write(b"HTTP/1.1 204 No Content\r\n" b"Access-Control-Allow-Origin: *\r\n\r\n")
def connection_made(self, transport: asyncio.BaseTransport) -> None: super().connection_made(transport) sock = transport.get_extra_info('socket') sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
def connection_made(self, transport: asyncio.BaseTransport) -> None: self.transport = transport self.peer = transport.get_extra_info( "peername") # type: Tuple[str, int] logger.debug(f"{self.__class__.__name__} connected to {self.peer}") self.server.register_protocol(self.peer, self)
def connection_made(self, transport: asyncio.BaseTransport) -> None: super().connection_made(transport) assert isinstance(transport, asyncio.Transport) transport.write(b"HTTP/1.1 200 OK\r\nContent-Length: 13\r\n\r\n")
def connection_made(self, transport: asyncio.BaseTransport) -> None: super().connection_made(transport) assert isinstance(transport, asyncio.Transport) transport.write(b"HTTP/1.1 404 Not Found\r\nContent-Length: 19\r\n\r\n" b"HTTP 404: Not Found")
def connection_made(self, transport: asyncio.BaseTransport) -> None: super().connection_made(transport) assert isinstance(transport, asyncio.Transport) transport.write(os.urandom(128 * 1024))
def connection_made(self, transport: asyncio.BaseTransport) -> None: self.transport = transport transport.write(self.initial_data)