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 std::net::SocketAddr;
7use tokio::io::AsyncWriteExt;
8use tokio::net::TcpStream;
9use tracing::debug;
10
11mod commands;
12mod response;
13mod responses;
14
15pub use response::ResponseParser;
16
17// Re-export for future use
18#[allow(unused_imports)]
19pub use response::{NntpResponse, ResponseCode};
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_REQUIRED, BACKEND_ERROR, BACKEND_UNAVAILABLE, COMMAND_NOT_SUPPORTED,
30    COMMAND_NOT_SUPPORTED_STATELESS, CONNECTION_CLOSING, CRLF, GOODBYE, MIN_RESPONSE_LENGTH,
31    MULTILINE_TERMINATOR, PROXY_GREETING_PCR, TERMINATOR_TAIL_SIZE, error_response, greeting,
32    greeting_readonly, ok_response, response,
33};
34
35/// Send NNTP proxy greeting to a client
36///
37/// Sends the standard "200 NNTP Proxy Ready" greeting message.
38pub async fn send_proxy_greeting(
39    client_stream: &mut TcpStream,
40    client_addr: SocketAddr,
41) -> Result<()> {
42    let proxy_greeting = b"200 NNTP Proxy Ready\r\n";
43    client_stream.write_all(proxy_greeting).await?;
44    debug!("Sent proxy greeting to client {}", client_addr);
45    Ok(())
46}