Lines Matching +full:closed +full:- +full:loop

2  *  Copyright 2024-2025 The OpenSSL Project Authors. All Rights Reserved.
11 * @file quic-hq-interop-server.c
17 * requests. Intended for use with the quic-interop-runner
21 * - Setting up SSL_CTX with QUIC support.
22 * - Negotiating ALPN strings during the TLS handshake.
23 * - Listening and accepting incoming QUIC connections.
24 * - Handling client requests via HTTP/0.9 protocol.
32 * - FILEPREFIX: Specifies the directory containing files to serve.
34 * - SSLKEYLOGFILE: specifies that keylogging should be preformed on the server
36 * - NO_ADDR_VALIDATE: Disables server address validation of clients
61 * @brief ALPN (Application-Layer Protocol Negotiation) identifier for QUIC.
64 * to negotiate the application-layer protocol between the client and
65 * the server. It specifies "hq-interop" as the supported protocol.
68 * - The first byte represents the length of the ALPN string.
69 * - Subsequent bytes represent the ASCII characters of the protocol name.
72 * - Protocol: "hq-interop"
73 * - Length: 10 bytes
80 10, 'h', 'q', '-', 'i', 'n', 't', 'e', 'r', 'o', 'p',
91 * - If not set via the FILEPREFIX environment variable, it defaults to
95 * - Updated at runtime based on the FILEPREFIX environment variable.
96 * - Used to locate and serve files during incoming requests.
101 * @brief Callback for ALPN (Application-Layer Protocol Negotiation) selection.
104 * validate and negotiate the desired ALPN (Application-Layer Protocol
106 * protocol matches the predefined "hq-interop" string.
111 * @param in Pointer to the client-provided ALPN protocol list.
112 * @param in_len Length of the client-provided ALPN protocol list.
113 * @param arg Optional user-defined argument (unused in this context).
119 * - This function is set as the ALPN selection callback in the SSL_CTX
121 * - Ensures that only the predefined ALPN protocol is accepted.
124 * - The predefined protocol is specified in the `alpn_ossltest` array.
148 * ALPN (Application-Layer Protocol Negotiation).
160 * - Loads the certificate chain and private key into the context.
161 * - Disables client certificate verification (no mutual TLS).
162 * - Sets up the ALPN selection callback for protocol negotiation.
165 * - If any step fails (e.g., loading the certificate or key), the function
169 * - Call this function to create an SSL_CTX before starting the QUIC server.
170 * - Ensure valid paths for the certificate and private key are provided.
173 * - The ALPN callback only supports the predefined protocol defined in
182 * subsequent per-client connections. We specifically load a QUIC in create_ctx()
191 * not only the leaf (end-entity) server certificate, but also any in create_ctx()
192 * intermediate issuer-CA certificates. The leaf certificate must be the in create_ctx()
195 * In advanced use-cases this can be called multiple times, once per public in create_ctx()
211 * key matches the just loaded end-entity certificate. It does not check in create_ctx()
222 * need to configure a trusted-certificate store, so no call to in create_ctx()
251 * - Creates a new UDP socket using the `socket` system call.
252 * - Configures the socket address structure to bind to the specified port
254 * - Binds the socket to the port using the `bind` system call.
257 * - If socket creation or binding fails, an error message is printed to
258 * `stderr`, the socket (if created) is closed, and -1 is returned.
261 * - Call this function to set up a socket for handling incoming QUIC
265 * - This function assumes UDP (`SOCK_DGRAM`).
266 * - This function accepts on both IPv4 and IPv6.
267 * - The specified port is converted to network byte order using `htons`.
271 int fd = -1; in create_socket()
363 * - 0: EOF, indicating the stream has been closed.
364 * - -1: A fatal error occurred or the stream has been reset.
378 return -1; in handle_io_failure()
383 * stream reset - or some failure occurred on the underlying in handle_io_failure()
396 fprintf(stderr, "Connection closed\n"); in handle_io_failure()
397 /* Connection is already closed. */ in handle_io_failure()
411 return -1; in handle_io_failure()
414 return -1; in handle_io_failure()
428 * - Reads the HTTP/0.9 GET request from the client.
429 * - Parses the request to extract the requested file name.
430 * - Constructs the file path using the `fileprefix` directory.
431 * - Reads the requested file in chunks and sends it to the client.
432 * - Concludes the QUIC stream once the file is fully sent.
435 * - If the request is invalid or the file cannot be opened, appropriate
437 * - Errors during file reading or writing to the stream are handled, with
438 * retries for buffer-related issues (e.g., full send buffer).
441 * - The request is expected to be a valid HTTP/0.9 GET request.
442 * - File paths are sanitized to prevent path traversal vulnerabilities.
443 * - The function uses blocking operations for reading and writing data.
446 * - Called for each accepted QUIC stream to handle client requests.
468 sizeof(buf) - total_read - 1, &nread); in process_new_stream()
537 bytes_read -= bytes_written; in process_new_stream()
558 * socket, and enters a loop to accept client connections and process incoming
568 * - Creates a QUIC listener using the provided SSL_CTX and associates it
570 * - Waits for incoming QUIC connections and accepts them.
571 * - For each connection:
572 * - Accepts incoming streams.
573 * - Processes each stream using `process_new_stream`.
574 * - Shuts down the connection upon completion.
577 * - If listener creation or connection acceptance fails, the function logs
578 * an error message and exits the loop.
579 * - Cleans up allocated resources (e.g., listener, connection) on failure.
582 * - Call this function in the main server loop after setting up the
586 * - Uses blocking operations for listener, connection, and stream handling.
587 * - Incoming streams are processed based on the configured stream policy.
588 * - The server runs in an infinite loop unless a fatal error occurs.
620 * Begin an infinite loop of listening for connections. We will only in run_quic_server()
621 * exit this loop if we encounter an error. in run_quic_server()
651 * Until the connection is closed, accept incomming stream in run_quic_server()
667 * The Client closed the connection, and there are no in run_quic_server()
704 * socket to the specified port, and starts the main QUIC server loop to handle
707 * @param argc Number of command-line arguments.
708 * @param argv Array of command-line arguments:
709 * - argv[0]: Program name.
710 * - argv[1]: Port number to bind the server.
711 * - argv[2]: Path to the server's certificate file (PEM format).
712 * - argv[3]: Path to the server's private key file (PEM format).
718 * - Validates the command-line arguments.
719 * - Reads the FILEPREFIX environment variable to set the file prefix for
721 * - Creates an SSL_CTX with QUIC support using the provided certificate and
723 * - Parses and validates the port number.
724 * - Creates and binds a UDP socket to the specified port.
725 * - Starts the server loop using `run_quic_server` to accept and process
729 * - If any initialization step fails (e.g., invalid arguments, socket
734 * - Run the program with the required arguments to start the server:
738 * - Ensure that the certificate and key files exist and are valid.
739 * - The server serves files from the directory specified by FILEPREFIX.
781 /* QUIC server connection acceptance loop. */ in main()