Skip to content

Commit c2a7bf9

Browse files
committed
Add proxy and onion support for tentacle
Signed-off-by: Eval EXEC <execvy@gmail.com>
1 parent 1276d3a commit c2a7bf9

File tree

19 files changed

+810
-322
lines changed

19 files changed

+810
-322
lines changed

multiaddr/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
///! Mini Implementation of [multiaddr](https://github.com/jbenet/multiaddr) in Rust.
1+
//! Mini Implementation of [multiaddr](https://github.com/jbenet/multiaddr) in Rust.
22
mod error;
33
mod onion_addr;
44
mod protocol;

tentacle/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ tokio-rustls = { version = "0.26.0", optional = true }
4949
# rand 0.8 not support wasm32
5050
rand = "0.8"
5151
socket2 = { version = "0.5.0", features = ["all"] }
52+
shadowsocks = { version = "1.21.0", default-features = false }
53+
url = "2.5.4"
5254

5355
[target.'cfg(target_family = "wasm")'.dependencies]
5456
js-sys = "0.3"

tentacle/src/builder.rs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::{io, sync::Arc, time::Duration};
22

3+
use crate::service::config::TransformerContext;
34
use nohash_hasher::IntMap;
45
use tokio_util::codec::LengthDelimitedCodec;
56

@@ -217,9 +218,33 @@ where
217218
#[cfg(not(target_family = "wasm"))]
218219
pub fn tcp_config<F>(mut self, f: F) -> Self
219220
where
220-
F: Fn(TcpSocket) -> Result<TcpSocket, std::io::Error> + Send + Sync + 'static,
221+
F: Fn(TcpSocket, TransformerContext) -> Result<TcpSocket, std::io::Error>
222+
+ Send
223+
+ Sync
224+
+ 'static,
221225
{
222-
self.config.tcp_config.tcp = Arc::new(f);
226+
self.config.tcp_config.tcp.socket_transformer = Arc::new(f);
227+
self
228+
}
229+
230+
/// Proxy config for tcp
231+
#[cfg(not(target_family = "wasm"))]
232+
pub fn tcp_proxy_config(mut self, proxy_url: String) -> Self {
233+
self.config.tcp_config.tcp.proxy_url = Some(proxy_url);
234+
self
235+
}
236+
237+
/// Onion config for tcp
238+
#[cfg(not(target_family = "wasm"))]
239+
pub fn tcp_onion_config(mut self, onion_url: String) -> Self {
240+
self.config.tcp_config.tcp.onion_url = Some(onion_url);
241+
self
242+
}
243+
244+
/// Onion config for tcp
245+
#[cfg(not(target_family = "wasm"))]
246+
pub fn tcp_onion_random_socks_auth(mut self, onion_random_socks_auth: bool) -> Self {
247+
self.config.tcp_config.tcp.onion_random_socks_auth = onion_random_socks_auth;
223248
self
224249
}
225250

@@ -228,9 +253,12 @@ where
228253
#[cfg_attr(docsrs, doc(cfg(feature = "ws")))]
229254
pub fn tcp_config_on_ws<F>(mut self, f: F) -> Self
230255
where
231-
F: Fn(TcpSocket) -> Result<TcpSocket, std::io::Error> + Send + Sync + 'static,
256+
F: Fn(TcpSocket, TransformerContext) -> Result<TcpSocket, std::io::Error>
257+
+ Send
258+
+ Sync
259+
+ 'static,
232260
{
233-
self.config.tcp_config.ws = Arc::new(f);
261+
self.config.tcp_config.ws.socket_transformer = Arc::new(f);
234262
self
235263
}
236264

@@ -252,9 +280,12 @@ where
252280
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
253281
pub fn tcp_config_on_tls<F>(mut self, f: F) -> Self
254282
where
255-
F: Fn(TcpSocket) -> Result<TcpSocket, std::io::Error> + Send + Sync + 'static,
283+
F: Fn(TcpSocket, TransformerContext) -> Result<TcpSocket, std::io::Error>
284+
+ Send
285+
+ Sync
286+
+ 'static,
256287
{
257-
self.config.tcp_config.tls = Arc::new(f);
288+
self.config.tcp_config.tls.socket_transformer = Arc::new(f);
258289
self
259290
}
260291
}

tentacle/src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ pub enum TransportErrorKind {
99
/// IO error
1010
#[error("transport io error: `{0:?}`")]
1111
Io(#[from] IOError),
12+
/// Proxy server error
13+
#[error("proxy error: `{0:?}`")]
14+
ProxyError(IOError),
1215
/// Protocol not support
1316
#[error("multiaddr `{0:?}` is not supported")]
1417
NotSupported(Multiaddr),

tentacle/src/runtime/async_runtime.rs

Lines changed: 0 additions & 291 deletions
This file was deleted.

0 commit comments

Comments
 (0)