Skip to content

Commit

Permalink
Merge pull request #32 from mel-project/renaming
Browse files Browse the repository at this point in the history
Rename options in config
  • Loading branch information
nullchinchilla authored Dec 18, 2023
2 parents 43c9794 + 6e4c572 commit a8c88df
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 118 deletions.
16 changes: 7 additions & 9 deletions cfg_example/alice-rob-bob/alice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ identity_seed: alice-was-here
state_cache: alice_state_cache.db
control_listen: 127.0.0.1:22222


# in_routes:
# # arbitrary names, used for diagnositics and logging
# main_udp:
Expand All @@ -18,17 +17,16 @@ out_routes:
cookie: 11deaee1eb5b796e416d54ad56522083938ea38218e8e7ea00e7466a04b5b750

# udp_forwards:
# - forward_to: 8080
# remote_ep: v7c854h336wtphnk0eqjrydexmffvhgb:69420
# - listen: 127.0.0.1:8080
# remote: v7c854h336wtphnk0eqjrydexmffvhgb:69420

tcp_forwards:
- forward_to: 8081
# remote_ep: v7c854h336wtphnk0eqjrydexmffvhgb:69421 # this has to be bob??
# remote_ep: ar8rfz3mp32m8ffkh86q258kq21j9abk:69421 # this has to be rob??
remote_ep: yqem5bc2m218hqzdk01wbdak42ky715e:69421

- listen: 127.0.0.1:8081
# remote: v7c854h336wtphnk0eqjrydexmffvhgb:69421 # this has to be bob??
# remote: ar8rfz3mp32m8ffkh86q258kq21j9abk:69421 # this has to be rob??
remote: yqem5bc2m218hqzdk01wbdak42ky715e:69421
# socks5:
# port: 1000
# fallback:
# fallback:
# simple_proxy:

8 changes: 4 additions & 4 deletions cfg_example/alice-rob-bob/bob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ havens:
# rendezvous: 91fbz7f7b2fwy0xrvsyqqbwbmmqytdnr
# handler:
# type: udp_forward
# from_dock: 69420
# to_port: 8814 # e.g. listening port of geph4-exit
# listen_dock: 69420
# upstream: 127.0.0.1:8814 # e.g. listening port of geph4-exit
#
# haven fingerprint: vtcwz1tvpgp7ccxzepmw0evb6cpa09t7
- identity_seed: i-am-a-haven-pls-no-eat-me
rendezvous: q29wsm1jpvg6j494kfdyf3wad5m92331 # rob's fingerprint
handler:
type: tcp_forward
from_dock: 69421
to_port: 8815 # e.g. listening port of geph4-exit
listen_dock: 69421
upstream: 127.0.0.1:8815 # e.g. listening port of geph4-exit
12 changes: 6 additions & 6 deletions cfg_example/alice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ in_routes:

# client config
udp_forwards:
- forward_to: 8080
remote_ep: sge818x6f87yk3q2w7mrfjtgn0p67tja:69420
- listen: 127.0.0.1:8080
remote: sge818x6f87yk3q2w7mrfjtgn0p67tja:69420

tcp_forwards:
- forward_to: 8081
remote_ep: pm3atrnq6awfp96qrjg5rmxp39d1bqfh:69421
- listen: 127.0.0.1:8081
remote: pm3atrnq6awfp96qrjg5rmxp39d1bqfh:69421

socks5:
listen_port: 8082
fallback:
fallback:
simple_proxy:
remote_ep: jm21nbaf4c8ejg25yq9mc7bg6sdeksja:69422
remote: jm21nbaf4c8ejg25yq9mc7bg6sdeksja:69422
8 changes: 4 additions & 4 deletions cfg_example/bob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ havens:
rendezvous: 0k28pjf5qa8nwbt7cn8138xetxdknhz3
handler:
type: udp_forward
from_dock: 69420
to_port: 8814 # e.g. listening port of geph4-exit
listen_dock: 69420
upstream: 127.0.0.1:8814 # e.g. listening port of geph4-exit

# fingerprint: pm3atrnq6awfp96qrjg5rmxp39d1bqfh
- identity_seed: TCP_haven
rendezvous: 0k28pjf5qa8nwbt7cn8138xetxdknhz3
handler:
type: tcp_forward
from_dock: 69421
to_port: 8815
listen_dock: 69421
upstream: 127.0.0.1:8815

# fingerprint: jm21nbaf4c8ejg25yq9mc7bg6sdeksja
- identity_seed: simple_proxy_haven
Expand Down
8 changes: 4 additions & 4 deletions cfg_example/self-haven/self-haven.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ in_routes:

# client config
udp_forwards:
- forward_to: 8080
remote_ep: cxvc52ndnzvy2kq1x9ajr2ft0tn5wk6n:10000
- listen: 127.0.0.1:8080
remote: cxvc52ndnzvy2kq1x9ajr2ft0tn5wk6n:10000

# server config
havens:
- identity: haven.asc
rendezvous: bnjmrmw1kvjf7jmx5fa6a9x1hjtq7qh3
handler:
type: udp_forward
from_dock: 10000
to_port: 10000
listen_dock: 10000
upstream: 127.0.0.1:10000
8 changes: 4 additions & 4 deletions local-tests/max-hop/judy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ havens:
rendezvous: 7wrkhwar5kj3hybwaf9pe996eydzc969 # alice
handler:
type: tcp_forward
from_dock: 6666
to_port: 8888
listen_dock: 6666
upstream: 127.0.0.1:8888

tcp_forwards:
- forward_to: 4444
remote_ep: pm3atrnq6awfp96qrjg5rmxp39d1bqfh:6666
- listen: 127.0.0.1:4444
remote: pm3atrnq6awfp96qrjg5rmxp39d1bqfh:6666
4 changes: 2 additions & 2 deletions shadow-tests/stream/configs/hosts/alice/alice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ in_routes:
secret: correct horse battery staple

tcp_forwards:
- forward_to: 4444
remote_ep: pm3atrnq6awfp96qrjg5rmxp39d1bqfh:69421
- listen: 127.0.0.1:4444
remote: pm3atrnq6awfp96qrjg5rmxp39d1bqfh:69421
4 changes: 2 additions & 2 deletions shadow-tests/stream/configs/hosts/bob/bob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ havens:
rendezvous: 0k28pjf5qa8nwbt7cn8138xetxdknhz3
handler:
type: tcp_forward
from_dock: 69421
to_port: 8888
listen_dock: 69421
upstream: 127.0.0.1:8888
26 changes: 17 additions & 9 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,25 @@ pub enum OutRouteConfig {
#[derive(Serialize, Deserialize, Clone)]
#[serde(rename_all = "snake_case")]
pub struct UdpForwardConfig {
pub forward_to: u16,
pub listen: SocketAddr,
#[serde_as(as = "serde_with::DisplayFromStr")]
pub remote_ep: Endpoint,
pub remote: Endpoint,
}

#[serde_as]
#[derive(Serialize, Deserialize, Clone)]
#[serde(rename_all = "snake_case")]
pub struct TcpForwardConfig {
pub forward_to: u16,
pub listen: SocketAddr,
#[serde_as(as = "serde_with::DisplayFromStr")]
pub remote_ep: Endpoint,
pub remote: Endpoint,
}

#[serde_as]
#[derive(Serialize, Deserialize, Clone)]
#[serde(rename_all = "snake_case")]
pub struct Socks5 {
pub listen_port: u16,
pub listen: SocketAddr,
pub fallback: Fallback,
}

Expand All @@ -101,7 +101,7 @@ pub enum Fallback {
PassThrough,
SimpleProxy {
#[serde_as(as = "serde_with::DisplayFromStr")]
remote_ep: Endpoint,
remote: Endpoint,
},
}

Expand All @@ -118,7 +118,15 @@ pub struct HavenForwardConfig {
#[derive(Serialize, Deserialize, Clone)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum ForwardHandler {
UdpForward { from_dock: Dock, to_port: u16 },
TcpForward { from_dock: Dock, to_port: u16 },
SimpleProxy { listen_dock: Dock },
UdpService {
listen_dock: Dock,
upstream: SocketAddr,
},
TcpService {
listen_dock: Dock,
upstream: SocketAddr,
},
SimpleProxy {
listen_dock: Dock,
},
}
20 changes: 10 additions & 10 deletions src/daemon/control_protocol_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ impl ControlProtocol for ControlProtocolImpl {
.public()
.fingerprint();
match haven_cfg.handler {
crate::config::ForwardHandler::UdpForward {
from_dock,
to_port: _,
crate::config::ForwardHandler::UdpService {
listen_dock,
upstream: _,
} => (
"UdpForward".to_string(),
fp.to_string() + ":" + &from_dock.to_string(),
"UdpService".to_string(),
fp.to_string() + ":" + &listen_dock.to_string(),
),
crate::config::ForwardHandler::TcpForward {
from_dock,
to_port: _,
crate::config::ForwardHandler::TcpService {
listen_dock,
upstream: _,
} => (
"TcpForward".to_string(),
fp.to_string() + ":" + &from_dock.to_string(),
"TcpService".to_string(),
fp.to_string() + ":" + &listen_dock.to_string(),
),
crate::config::ForwardHandler::SimpleProxy { listen_dock } => (
"SimpleProxy".to_string(),
Expand Down
15 changes: 4 additions & 11 deletions src/daemon/socks5.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::{
net::{Ipv4Addr, SocketAddrV4},
str::FromStr,
};
use std::{net::Ipv4Addr, str::FromStr};

use anyhow::Context;
use earendil_crypt::{Fingerprint, IdentitySecret};
Expand All @@ -24,11 +21,7 @@ use super::DaemonContext;

pub async fn socks5_loop(ctx: DaemonContext, socks5_cfg: Socks5) -> anyhow::Result<()> {
log::debug!("socks5 loop started");
let tcp_listener = TcpListener::bind(SocketAddrV4::new(
"127.0.0.1".parse()?,
socks5_cfg.listen_port,
))
.await?;
let tcp_listener = TcpListener::bind(socks5_cfg.listen).await?;
let fallback = socks5_cfg.fallback;
let reaper = TaskReaper::new();

Expand Down Expand Up @@ -103,14 +96,14 @@ async fn socks5_once(
))
.await?;
}
Fallback::SimpleProxy { remote_ep } => {
Fallback::SimpleProxy { remote: remote } => {
let remote_skt = Socket::bind_haven_internal(
ctx.clone(),
IdentitySecret::generate(),
None,
None,
);
let mut remote_stream = Stream::connect(remote_skt, remote_ep).await?;
let mut remote_stream = Stream::connect(remote_skt, remote).await?;
let prepend = (addr.len() as u16).to_be_bytes();
remote_stream.write(&prepend).await?;

Expand Down
10 changes: 2 additions & 8 deletions src/daemon/tcp_forward.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::net::SocketAddrV4;

use earendil_crypt::IdentitySecret;
use futures_util::io;
use smol::{future::FutureExt, net::TcpListener};
Expand All @@ -14,18 +12,14 @@ pub async fn tcp_forward_loop(
tcp_fwd_cfg: TcpForwardConfig,
) -> anyhow::Result<()> {
log::debug!("tcp forward loop");
let tcp_listener = TcpListener::bind(SocketAddrV4::new(
"127.0.0.1".parse()?,
tcp_fwd_cfg.forward_to,
))
.await?;
let tcp_listener = TcpListener::bind(tcp_fwd_cfg.listen).await?;
let reaper = TaskReaper::new();

loop {
let (tcp_stream, _) = tcp_listener.accept().await?;
let earendil_socket =
Socket::bind_haven_internal(ctx.clone(), IdentitySecret::generate(), None, None);
let earendil_stream = Stream::connect(earendil_socket, tcp_fwd_cfg.remote_ep).await?;
let earendil_stream = Stream::connect(earendil_socket, tcp_fwd_cfg.remote).await?;
reaper.attach(smolscale::spawn(async move {
io::copy(tcp_stream.clone(), &mut earendil_stream.clone())
.race(io::copy(earendil_stream.clone(), &mut tcp_stream.clone()))
Expand Down
16 changes: 3 additions & 13 deletions src/daemon/udp_forward.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use std::{
net::{SocketAddr, SocketAddrV4},
sync::Arc,
time::Duration,
};
use std::{net::SocketAddr, sync::Arc, time::Duration};

use clone_macro::clone;
use earendil_crypt::IdentitySecret;
Expand Down Expand Up @@ -33,13 +29,7 @@ pub async fn udp_forward_loop(
let demux_table: Cache<SocketAddr, (Arc<Socket>, Arc<Immortal>)> = CacheBuilder::default()
.time_to_idle(Duration::from_secs(60 * 60))
.build();
let udp_socket = Arc::new(
UdpSocket::bind(SocketAddrV4::new(
"127.0.0.1".parse()?,
udp_fwd_cfg.forward_to,
))
.await?,
);
let udp_socket = Arc::new(UdpSocket::bind(udp_fwd_cfg.listen).await?);
let mut buf = [0; 10_000];

loop {
Expand Down Expand Up @@ -70,7 +60,7 @@ pub async fn udp_forward_loop(
// using the earendil socket associated with the src_udp_addr
src_earendil_skt
.0
.send_to(msg.into(), udp_fwd_cfg.remote_ep)
.send_to(msg.into(), udp_fwd_cfg.remote)
.await?;
}
}
Loading

0 comments on commit a8c88df

Please sign in to comment.