Skip to main content

nntp_proxy/protocol/
mod.rs

1//! NNTP protocol handling module
2//!
3//! This module contains response parsing and protocol utilities for NNTP communication.
4
5use anyhow::Result;
6use tokio::io::AsyncWriteExt;
7use tokio::net::TcpStream;
8use tracing::debug;
9
10mod article;
11mod commands;
12mod response;
13mod responses;
14
15// Re-export article parsing types
16pub use article::{Article, HeaderIter, Headers, ParseError, yenc};
17
18// Re-export response types and utilities
19pub use response::{NntpResponse, StatusCode};
20
21// Re-export command construction helpers
22pub use commands::{
23    DATE, QUIT, article_by_msgid, authinfo_pass, authinfo_user, body_by_msgid, head_by_msgid,
24    stat_by_msgid,
25};
26
27// Re-export response constants and helpers
28pub use responses::{
29    AUTH_ACCEPTED, AUTH_FAILED, AUTH_REQUIRED, AUTH_REQUIRED_FOR_COMMAND, BACKEND_ERROR,
30    BACKEND_UNAVAILABLE, COMMAND_NOT_SUPPORTED, COMMAND_NOT_SUPPORTED_STATELESS,
31    CONNECTION_CLOSING, CRLF, GOODBYE, MIN_RESPONSE_LENGTH, MULTILINE_TERMINATOR, NO_SUCH_ARTICLE,
32    PROXY_GREETING_PCR, TERMINATOR_TAIL_SIZE, error_response, greeting, greeting_readonly,
33    ok_response, response,
34};
35
36/// Send NNTP proxy greeting to a client
37///
38/// Sends the standard "200 NNTP Proxy Ready" greeting message.
39/// The greeting is flushed immediately to ensure the client receives it
40/// before we start processing commands.
41pub async fn send_proxy_greeting(
42    client_stream: &mut TcpStream,
43    client_addr: impl std::fmt::Display,
44) -> Result<()> {
45    let proxy_greeting = b"200 NNTP Proxy Ready\r\n";
46    client_stream.write_all(proxy_greeting).await?;
47    client_stream.flush().await?;
48    debug!("Sent and flushed proxy greeting to client {}", client_addr);
49    Ok(())
50}