Esempio n. 1
0
    def _start_on_server_thread(self) -> None:
        configuration = QuicConfiguration(
            alpn_protocols=H3_ALPN,
            is_client=False,
            max_datagram_frame_size=65536,
        )

        _logger.info("Starting WebTransport over HTTP/3 server on %s:%s",
                     self.host, self.port)

        configuration.load_cert_chain(self.cert_path, self.key_path)

        ticket_store = SessionTicketStore()

        self.loop = asyncio.new_event_loop()
        asyncio.set_event_loop(self.loop)
        self.loop.run_until_complete(
            serve(
                self.host,
                self.port,
                configuration=configuration,
                create_protocol=WebTransportH3Protocol,
                session_ticket_fetcher=ticket_store.pop,
                session_ticket_handler=ticket_store.add,
            ))
        self.loop.run_forever()
Esempio n. 2
0
def start(kwargs):
    configuration = QuicConfiguration(
        alpn_protocols=['wq-vvv-01'] + ['siduck'],
        is_client=False,
        max_datagram_frame_size=65536,
    )

    global handlers_path
    handlers_path = os.path.abspath(os.path.expanduser(
        kwargs['handlers_path']))
    logger.info('port = %s', kwargs['port'])
    logger.info('handlers path = %s', handlers_path)

    # load SSL certificate and key
    configuration.load_cert_chain(kwargs['certificate'], kwargs['private_key'])

    ticket_store = SessionTicketStore()

    loop = asyncio.get_event_loop()
    loop.run_until_complete(
        serve(
            kwargs['host'],
            kwargs['port'],
            configuration=configuration,
            create_protocol=QuicTransportProtocol,
            session_ticket_fetcher=ticket_store.pop,
            session_ticket_handler=ticket_store.add,
        ))
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        pass
Esempio n. 3
0
def configure_http3_server(
        listen_port,
        server_port,
        https_pem,
        ca_pem,
        listening_sentinel,
        h3_to_server=False):

    HttpQuicServerHandler.cert_file = https_pem
    HttpQuicServerHandler.ca_file = ca_pem
    HttpQuicServerHandler.h3_to_server = h3_to_server
    HttpQuicServerHandler.server_port = server_port

    try:
        os.mkdir('quic_log_directory')
    except FileExistsError:
        pass
    quic_logger = QuicDirectoryLogger('quic_log_directory')
    secrets_log_file = open('tls_secrets.log', "a", encoding='utf-8')
    configuration = QuicConfiguration(
        alpn_protocols=H3_ALPN,
        is_client=False,
        max_datagram_frame_size=65536,
        quic_logger=quic_logger,
        secrets_log_file=secrets_log_file,
    )

    configuration.load_cert_chain(https_pem, ca_pem)
    ticket_store = SessionTicketStore()

    # TODO
    # In 3.7: how about asyncio.run(serve(...))
    loop = asyncio.get_event_loop()
    server_side_proto = "HTTP/3" if h3_to_server else "HTTP/1"
    print(
        f"Serving HTTP/3 Proxy on 127.0.0.1:{listen_port} with pem '{https_pem}', "
        f"forwarding to 127.0.0.1:{server_port} over {server_side_proto}")
    loop.run_until_complete(
        serve(
            '0.0.0.0',
            listen_port,
            configuration=configuration,
            create_protocol=HttpQuicServerHandler,
            session_ticket_fetcher=ticket_store.pop,
            session_ticket_handler=ticket_store.add
        )
    )

    # Indicate to the caller that the quic socket is configured and listening.
    Path(listening_sentinel).touch()

    try:
        loop.run_forever()
    except KeyboardInterrupt as e:
        # The calling test_proxy.py will handle this.
        print("Handling KeyboardInterrupt")
        raise e
    except SystemExit:
        pass
Esempio n. 4
0
def rsocket_serve(host: str,
                  port: int,
                  configuration: QuicConfiguration = None,
                  on_server_create=None,
                  **kwargs):
    if configuration is None:
        configuration = QuicConfiguration(
            is_client=False
        )

    def protocol_factory(*protocol_args, **protocol_kwargs):
        protocol = RSocketQuicProtocol(*protocol_args, **protocol_kwargs)
        server = RSocketServer(RSocketQuicTransport(protocol), **kwargs)

        if on_server_create is not None:
            on_server_create(server)

        return protocol

    return serve(
        host,
        port,
        create_protocol=protocol_factory,
        configuration=configuration)
Esempio n. 5
0
    configuration = QuicConfiguration(
        alpn_protocols=H3_ALPN + H0_ALPN + ["siduck"],
        is_client=False,
        max_datagram_frame_size=65536,
        quic_logger=quic_logger,
        secrets_log_file=secrets_log_file,
    )

    # load SSL certificate and key
    configuration.load_cert_chain(args.certificate, args.private_key)

    ticket_store = SessionTicketStore()

    if uvloop is not None:
        uvloop.install()
    loop = asyncio.get_event_loop()
    loop.run_until_complete(
        serve(
            args.host,
            args.port,
            configuration=configuration,
            create_protocol=HttpServerProtocol,
            session_ticket_fetcher=ticket_store.pop,
            session_ticket_handler=ticket_store.add,
            retry=args.retry,
        ))
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        pass
Esempio n. 6
0
if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('certificate')
    parser.add_argument('key')
    args = parser.parse_args()

    configuration = QuicConfiguration(
        # Identifies the protocol used.  The origin trial uses the protocol
        # described in draft-vvv-webtransport-quic-01, hence the ALPN value.
        # See https://tools.ietf.org/html/draft-vvv-webtransport-quic-01#section-3.1
        alpn_protocols=['wq-vvv-01'],
        is_client=False,

        # Note that this is just an upper limit; the real maximum datagram size
        # available depends on the MTU of the path.  See
        # <https://en.wikipedia.org/wiki/Maximum_transmission_unit>.
        max_datagram_frame_size=1500,
    )
    configuration.load_cert_chain(args.certificate, args.key)

    loop = asyncio.get_event_loop()
    loop.run_until_complete(
        serve(
            BIND_ADDRESS,
            BIND_PORT,
            configuration=configuration,
            create_protocol=QuicTransportProtocol,
        ))
    loop.run_forever()
Esempio n. 7
0
        format="%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s",
        level=logging.INFO,
        datefmt="%Y-%m-%d %H:%M:%S",
    )

    configuration.load_cert_chain(args.certificate, args.private_key)

    if uvloop is not None:
        uvloop.install()

    loop = asyncio.get_event_loop()
    loop.create_task(
        serve(
            args.host,
            args.port,
            configuration=configuration,
            create_protocol=VideoStreamServerProtocol,
            retry=True,
        )
    )
    logging.info(
        f"Starting Server with VideoStreamServerProtocol on {args.host}:{args.port}"
    )

    try:
        loop.run_forever()
    except KeyboardInterrupt:
        pass

    logging.info("Program Terminated")
Esempio n. 8
0
    def process_client_indication(self) -> None:
        indication = dict(
            self.parse_client_indication(
                io.BytesIO(self.client_indication_data)))
        origin = urllib.parse.urlparse(indication[0].decode())
        path = urllib.parse.urlparse(indication[1]).decode()

        self.handler = TestHandler(self._quic)

    def is_closing_or_closed(self) -> bool:
        return self._quic._close_pending or self._quic._state in END_STATES


if __name__ == '__main__':
    configuration = QuicConfiguration(
        alpn_protocols=['wq-vvv-01'],
        is_client=False,
        max_datagram_frame_size=1500,
    )
    configuration.load_cert_chain('localhost.crt', 'localhost.key')

    loop = asyncio.get_event_loop()
    loop.run_until_complete(
        serve(
            'localhost',
            4443,
            configuration=configuration,
            create_protocol=QuicTransportProtocol,
        ))
    loop.run_forever()
Esempio n. 9
0
            yield (key, value)

    def process_client_indication(self) -> None:
        indication = dict(self.parse_client_indication(io.BytesIO(self.client_indication_data)))
        origin = urllib.parse.urlparse(indication[0].decode())
        path = urllib.parse.urlparse(indication[1]).decode()

        self.handler = TestHandler(self._quic)

    def is_closing_or_closed(self) -> bool:
        return self._quic._close_pending or self._quic._state in END_STATES


if __name__ == '__main__':
    configuration = QuicConfiguration(
        alpn_protocols=['wq-vvv-01'],
        is_client=False,
        max_datagram_frame_size=1500,
    )
    configuration.load_cert_chain('localhost.crt', 'localhost.key')

    loop = asyncio.get_event_loop()
    loop.run_until_complete(
        serve(
            '::1',
            4443,
            configuration=configuration,
            create_protocol=QuicTransportProtocol,
        ))
    loop.run_forever()
Esempio n. 10
0
    configuration = QuicConfiguration(
        alpn_protocols=['wq-vvv-01'] + ['siduck'],
        is_client=False,
        max_datagram_frame_size=65536,
    )

    handlers_path = os.path.abspath(os.path.expanduser(args.handlers_path))
    logging.log(logging.INFO, 'port = %s' % args.port)
    logging.log(logging.INFO, 'handlers path = %s' % handlers_path)

    # load SSL certificate and key
    configuration.load_cert_chain(args.certificate, args.private_key)

    ticket_store = SessionTicketStore()

    loop = asyncio.get_event_loop()
    loop.run_until_complete(
        serve(
            args.host,
            args.port,
            configuration=configuration,
            create_protocol=QuicTransportProtocol,
            session_ticket_fetcher=ticket_store.pop,
            session_ticket_handler=ticket_store.add,
        )
    )
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        pass
Esempio n. 11
0
                        default=6363,
                        help='router port',
                        metavar='PORT')
    opts = parser.parse_args()

    configuration = QuicConfiguration(
        alpn_protocols=H3_ALPN,
        is_client=False,
        max_datagram_frame_size=32 + opts.mtu,
    )
    configuration.load_cert_chain(opts.cert, opts.key)

    logging.info('Starting QUIC server at [%s]:%d', opts.listen_addr,
                 opts.listen_port)
    logging.info('NDN router is at [%s]:%d', opts.router_addr,
                 opts.router_port)

    def create_protocol(*args, **kwargs):
        return H3Server((opts.router_addr, opts.router_port), opts.mtu, *args,
                        **kwargs)

    loop = aio.new_event_loop()
    loop.run_until_complete(
        serve(
            opts.listen_addr,
            opts.listen_port,
            configuration=configuration,
            create_protocol=create_protocol,
        ))
    loop.run_forever()