ss_light/
lib.rs

1//! # Examples
2//! tcp relay with aes-256-gcm:
3//! ```no_run
4//! use tokio::net::TcpListener;
5//! use std::io;
6//! use ss_light::*;
7//!
8//! #[tokio::main]
9//! async fn main() -> io::Result<()> {
10//!     let pwd = "123456";
11//!     let key = util::evp_bytes_to_key(pwd.as_bytes(), CipherKind::AES_256_GCM.key_len());
12//!
13//!     let listener = TcpListener::bind("127.0.0.1:8080").await?;
14//!     let (socket, _) = listener.accept().await?;
15//!
16//!     // notice: one connection one task
17//!     let mut ss = Stream::new_from_stream(socket, CipherKind::AES_256_GCM, &key);
18//!
19//!     let target_addr = Address::read_from(&mut ss).await.unwrap();
20//!     let target = target_addr.connect().await.unwrap();
21//!
22//!     util::copy_bidirectional(ss, target).await;
23//!     Ok(())
24//! }
25//! ```
26//!
27//! udp relay with aes-256-gcm:
28//! ```no_run
29//! use tokio::net::UdpSocket;
30//! use std::{io,time};
31//! use ss_light::*;
32//!
33//! #[tokio::main]
34//! async fn main() -> io::Result<()> {
35//!     let pwd = "123456";
36//!     let key = util::evp_bytes_to_key(pwd.as_bytes(), CipherKind::AES_256_GCM.key_len());
37//!
38//!     let socket = UdpSocket::bind("127.0.0.1:8080").await?;
39//!
40//!     let udp_server = ss_light::UdpServer::new(
41//!         socket,
42//!         CipherKind::AES_256_GCM,
43//!         &key,
44//!         1000,
45//!         time::Duration::from_secs(30),
46//!     );
47//!
48//!     udp_server.run().await;
49//!     Ok(())
50//! }
51//! ```
52//!
53//!
54//!
55
56pub mod consts;
57pub use consts::Error;
58pub mod crypto;
59pub use crypto::kind::CipherKind;
60pub use crypto::Stream;
61mod handshake;
62pub use handshake::Address;
63mod udprelay;
64pub use udprelay::UdpServer;
65pub mod plugin;
66pub mod util;
67pub const VERSION: &str = env!("CARGO_PKG_VERSION");
68
69#[cfg(test)]
70mod tests {
71    #[test]
72    fn it_works() {
73        let result = 2 + 2;
74        assert_eq!(result, 4);
75    }
76}