stratum_apps/network_helpers/mod.rs
1//! High-level networking utilities for SV2 connections
2//!
3//! This module provides connection management, encrypted streams, and protocol handling
4//! for Stratum V2 applications. It includes support for:
5//!
6//! - Noise-encrypted connections ([`noise_connection`], [`noise_stream`])
7//! - SV1 protocol connections ([`sv1_connection`]) - when `sv1` feature is enabled
8//!
9//! Originally from the `network_helpers_sv2` crate.
10
11pub mod noise_connection;
12pub mod noise_stream;
13
14#[cfg(feature = "sv1")]
15pub mod sv1_connection;
16
17use async_channel::{RecvError, SendError};
18use stratum_core::codec_sv2::Error as CodecError;
19
20/// Networking errors that can occur in SV2 connections
21#[derive(Debug)]
22pub enum Error {
23 /// Invalid handshake message received from remote peer
24 HandshakeRemoteInvalidMessage,
25 /// Error from the codec layer
26 CodecError(CodecError),
27 /// Error receiving from async channel
28 RecvError,
29 /// Error sending to async channel
30 SendError,
31 /// Socket was closed, likely by the peer
32 SocketClosed,
33}
34
35impl From<CodecError> for Error {
36 fn from(e: CodecError) -> Self {
37 Error::CodecError(e)
38 }
39}
40
41impl From<RecvError> for Error {
42 fn from(_: RecvError) -> Self {
43 Error::RecvError
44 }
45}
46
47impl<T> From<SendError<T>> for Error {
48 fn from(_: SendError<T>) -> Self {
49 Error::SendError
50 }
51}