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
@@ -12,7 +12,7 @@ priv struct PendingNetDbLookup {
|
||||
candidate_peers : Array[@common.Hash]
|
||||
started_ms : UInt64
|
||||
mut last_query_ms : UInt64
|
||||
kind : Int32 // 0 = NAMING LOOKUP (.b32), 1 = STREAM CONNECT awaiting LeaseSet2, 2 = background RI/exploration
|
||||
kind : Int32 // 0 = NAMING LOOKUP (.b32), 1 = STREAM CONNECT awaiting LeaseSet2, 2 = background RI/exploration, 3 = HTTP proxy LeaseSet2 lookup
|
||||
client_idx : Int32
|
||||
req_name : String
|
||||
session_id : String
|
||||
@@ -427,6 +427,17 @@ fn Router::start_netdb_lookup(
|
||||
true
|
||||
}
|
||||
|
||||
///|
|
||||
fn Router::start_proxy_netdb_lookup(
|
||||
self : Router,
|
||||
target_hash : @common.Hash,
|
||||
) -> Bool {
|
||||
if self.has_pending_lookup(target_hash, 1) {
|
||||
return true
|
||||
}
|
||||
self.start_netdb_lookup(target_hash, 3, -1, "", "", true)
|
||||
}
|
||||
|
||||
///|
|
||||
fn Router::handle_database_store_msg(
|
||||
self : Router,
|
||||
@@ -690,7 +701,7 @@ fn Router::complete_lookups_for_hash(
|
||||
let lk = self.pending_lookups[i]
|
||||
if lk.target_hash == key {
|
||||
let _ = self.pending_lookups.remove(i)
|
||||
if lk.client_idx < self.sam_clients.length() {
|
||||
if lk.client_idx >= 0 && lk.client_idx < self.sam_clients.length() {
|
||||
let c = self.sam_clients[lk.client_idx]
|
||||
if !c.closed {
|
||||
if lk.kind == 0 {
|
||||
@@ -699,7 +710,7 @@ fn Router::complete_lookups_for_hash(
|
||||
c.sock,
|
||||
"NAMING REPLY RESULT=OK NAME=\{lk.req_name} VALUE=\{val}",
|
||||
)
|
||||
} else {
|
||||
} else if lk.kind == 1 {
|
||||
self.finish_remote_stream_connect(lk, ls2)
|
||||
}
|
||||
}
|
||||
@@ -739,14 +750,15 @@ fn Router::poll_netdb_lookups(self : Router) -> Unit {
|
||||
match self.netdb.get_lease_set2(lk.target_hash, now_sec) {
|
||||
Some(ls2) => {
|
||||
let _ = self.pending_lookups.remove(i)
|
||||
if lk.client_idx < self.sam_clients.length() &&
|
||||
if lk.client_idx >= 0 &&
|
||||
lk.client_idx < self.sam_clients.length() &&
|
||||
!self.sam_clients[lk.client_idx].closed {
|
||||
if lk.kind == 0 {
|
||||
let _ = send_sam_line(
|
||||
self.sam_clients[lk.client_idx].sock,
|
||||
"NAMING REPLY RESULT=OK NAME=\{lk.req_name} VALUE=\{ls2.destination.to_base64()}",
|
||||
)
|
||||
} else {
|
||||
} else if lk.kind == 1 {
|
||||
self.finish_remote_stream_connect(lk, ls2)
|
||||
}
|
||||
}
|
||||
@@ -778,7 +790,7 @@ fn Router::poll_netdb_lookups(self : Router) -> Unit {
|
||||
}
|
||||
if now_ms > lk.started_ms + timeout_ms {
|
||||
let _ = self.pending_lookups.remove(i)
|
||||
if lk.client_idx < self.sam_clients.length() {
|
||||
if lk.client_idx >= 0 && lk.client_idx < self.sam_clients.length() {
|
||||
let c = self.sam_clients[lk.client_idx]
|
||||
if !c.closed {
|
||||
if lk.kind == 0 {
|
||||
@@ -786,7 +798,7 @@ fn Router::poll_netdb_lookups(self : Router) -> Unit {
|
||||
c.sock,
|
||||
"NAMING REPLY RESULT=KEY_NOT_FOUND NAME=\{lk.req_name}",
|
||||
)
|
||||
} else {
|
||||
} else if lk.kind == 1 {
|
||||
if !lk.silent {
|
||||
let _ = send_sam_line(
|
||||
c.sock,
|
||||
|
||||
Reference in new issue
Block a user