feat: add HTTP-over-I2P proxy to router daemon
- Add --http-proxy/--proxy [host:port] (default 127.0.0.1:4444) to route .i2p and .b32.i2p HTTP requests over I2P streams - Block clearnet hosts with 403 and reject CONNECT and https:// with 501 - Support ?i2paddresshelper= jump links that register host aliases - Add `just proxy` target and -h/--help usage output - Expire idle ratchet sessions after 300s and add RatchetSessionManager::drop_session for fresh NewSession handshakes - Add NetDb::remove_lease_set2 and bound the outbound pending queue to 64 entries
This commit is contained in:
1 parent
54cfb2faa9
commit
14eae00f5c
15 files changed
+1941
-41
No files matched your search
+109
-1
@@ -37,11 +37,60 @@ fn split_host_port(spec : String) -> (String, Int32)? {
|
||||
}
|
||||
}
|
||||
|
||||
///|
|
||||
fn print_usage() -> Unit {
|
||||
println("moon-i2p native router daemon")
|
||||
println("")
|
||||
println("Usage:")
|
||||
println(" router.exe [options]")
|
||||
println("")
|
||||
println("Options:")
|
||||
println(
|
||||
" --sam <host:port> SAMv3 TCP listen address (default: 127.0.0.1:7656)",
|
||||
)
|
||||
println(
|
||||
" --http-proxy [host:port] Enable HTTP-over-I2P proxy (default when omitted: 127.0.0.1:4444)",
|
||||
)
|
||||
println(" --proxy [host:port] Alias for --http-proxy")
|
||||
println(
|
||||
" --ntcp2-host <ip> NTCP2 advertise/bind IP (default: 127.0.0.1)",
|
||||
)
|
||||
println(
|
||||
" --ntcp2-port <port> NTCP2 TCP listen port (default: 0 = ephemeral)",
|
||||
)
|
||||
println(
|
||||
" --public Join live public I2P network (auto-reseed + tunnels + NetDB)",
|
||||
)
|
||||
println(
|
||||
" --hops <1..4> Inbound/Outbound tunnel hop count (default: 1)",
|
||||
)
|
||||
println(
|
||||
" --hosts <hosts.txt> Load hostname=dest_or_b32 aliases into addressbook",
|
||||
)
|
||||
println(" --peer <ri.dat> Load a RouterInfo file into NetDB")
|
||||
println(
|
||||
" --peer-dir <dir> Load RouterInfo files from directory into NetDB",
|
||||
)
|
||||
println(
|
||||
" --su3 <i2pseeds.su3> Import peers from local .su3 reseed file",
|
||||
)
|
||||
println(
|
||||
" --reseed <https://...> Import peers from an HTTPS .su3 reseed URL",
|
||||
)
|
||||
println(" --floodfill Advertise LRf floodfill capabilities")
|
||||
println(" --no-clock-skew Disable NTCP2 clock skew check")
|
||||
println(" --debug Enable verbose router debug logs")
|
||||
println(" -h, --help Show this help message")
|
||||
}
|
||||
|
||||
///|
|
||||
fn main {
|
||||
let args = @env.args()
|
||||
let mut sam_host = "127.0.0.1"
|
||||
let mut sam_port = 7656
|
||||
let mut http_proxy_enabled = false
|
||||
let mut http_proxy_host = "127.0.0.1"
|
||||
let mut http_proxy_port = 4444
|
||||
let mut ntcp2_host = "127.0.0.1"
|
||||
let mut ntcp2_port = 0
|
||||
let mut floodfill = false
|
||||
@@ -58,6 +107,10 @@ fn main {
|
||||
let mut i = 1
|
||||
while i < args.length() {
|
||||
match args[i] {
|
||||
"-h" | "--help" => {
|
||||
print_usage()
|
||||
return
|
||||
}
|
||||
"--sam" =>
|
||||
if i + 1 < args.length() {
|
||||
match split_host_port(args[i + 1]) {
|
||||
@@ -71,6 +124,28 @@ fn main {
|
||||
} else {
|
||||
i += 1
|
||||
}
|
||||
"--http-proxy" | "--proxy" => {
|
||||
http_proxy_enabled = true
|
||||
if i + 1 < args.length() && !args[i + 1].has_prefix("-") {
|
||||
match split_host_port(args[i + 1]) {
|
||||
Some((h, p)) => {
|
||||
http_proxy_host = h
|
||||
http_proxy_port = p
|
||||
i += 2
|
||||
}
|
||||
None =>
|
||||
match parse_port(args[i + 1]) {
|
||||
Some(p) => {
|
||||
http_proxy_port = p
|
||||
i += 2
|
||||
}
|
||||
None => i += 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
"--ntcp2-port" =>
|
||||
if i + 1 < args.length() {
|
||||
match parse_port(args[i + 1]) {
|
||||
@@ -149,7 +224,26 @@ fn main {
|
||||
check_clock_skew = false
|
||||
i += 1
|
||||
}
|
||||
_ => i += 1
|
||||
_ =>
|
||||
if args[i].has_prefix("--http-proxy=") {
|
||||
http_proxy_enabled = true
|
||||
let spec = args[i][13:].to_owned()
|
||||
match split_host_port(spec) {
|
||||
Some((h, p)) => {
|
||||
http_proxy_host = h
|
||||
http_proxy_port = p
|
||||
}
|
||||
None =>
|
||||
match parse_port(spec) {
|
||||
Some(p) => http_proxy_port = p
|
||||
None =>
|
||||
println("warning: ignoring invalid --http-proxy \{spec}")
|
||||
}
|
||||
}
|
||||
i += 1
|
||||
} else {
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,6 +260,17 @@ fn main {
|
||||
return
|
||||
}
|
||||
}
|
||||
if http_proxy_enabled {
|
||||
let _ = r.start_http_proxy(host=http_proxy_host, port=http_proxy_port) catch {
|
||||
_ => {
|
||||
r.close()
|
||||
println(
|
||||
"error: failed to bind HTTP proxy on \{http_proxy_host}:\{http_proxy_port}",
|
||||
)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
for pf in peer_files {
|
||||
let _ = r.load_peer_file(pf) catch {
|
||||
_ => {
|
||||
@@ -225,6 +330,9 @@ fn main {
|
||||
" NTCP2: \{ntcp2_host}:\{r.ntcp2_port()} (public=\{public_mode}, hops=\{tunnel_hops})",
|
||||
)
|
||||
println(" SAMv3: \{sam_host}:\{r.sam_port()}")
|
||||
if http_proxy_enabled {
|
||||
println(" HTTP Proxy: \{http_proxy_host}:\{r.http_proxy_port()}")
|
||||
}
|
||||
println(
|
||||
" NetDB peers: \{r.netdb.router_count()} (floodfills=\{r.netdb.floodfill_count()})",
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user