- 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
507 lines
17 KiB
MoonBit
507 lines
17 KiB
MoonBit
///|
|
|
fn step_routers(rs : Array[@router.Router], count : Int32) -> Unit {
|
|
for _i = 0; _i < count; _i = _i + 1 {
|
|
for r in rs {
|
|
r.step(poll_ms=1)
|
|
}
|
|
}
|
|
}
|
|
|
|
///|
|
|
fn pump_read_line(
|
|
sock : @ntcp2_net.TcpSocket,
|
|
rs : Array[@router.Router],
|
|
max_ticks~ : Int32 = 1000,
|
|
) -> String raise {
|
|
for _i = 0; _i < max_ticks; _i = _i + 1 {
|
|
step_routers(rs, 1)
|
|
if sock.poll_readable(0) {
|
|
match sock.read_line() {
|
|
Some(l) => return l
|
|
None => fail("unexpected EOF while waiting for SAM line")
|
|
}
|
|
}
|
|
}
|
|
fail("timed out waiting for SAM line")
|
|
}
|
|
|
|
///|
|
|
fn pump_read_until_eof(
|
|
sock : @ntcp2_net.TcpSocket,
|
|
rs : Array[@router.Router],
|
|
max_ticks~ : Int32 = 1500,
|
|
) -> Bytes raise {
|
|
let out : Array[Byte] = []
|
|
for _i = 0; _i < max_ticks; _i = _i + 1 {
|
|
step_routers(rs, 1)
|
|
while sock.poll_readable(0) {
|
|
let chunk = sock.read_some(4096)
|
|
if chunk.length() == 0 {
|
|
return Bytes::from_array(out)
|
|
}
|
|
for j = 0; j < chunk.length(); j = j + 1 {
|
|
out.push(chunk[j])
|
|
}
|
|
}
|
|
}
|
|
fail("timed out waiting for EOF on stream socket")
|
|
}
|
|
|
|
///|
|
|
test "Router transient startup, self-signed RouterInfo, and embedded SAMv3 bridge" {
|
|
let r = @router.Router::start({
|
|
sam_host: "127.0.0.1",
|
|
sam_port: 0,
|
|
ntcp2_host: "127.0.0.1",
|
|
ntcp2_port: 0,
|
|
})
|
|
assert_eq(r.router_info.verify_signature(), true)
|
|
assert_eq(r.netdb.router_count(), 1)
|
|
assert_true(r.sam_port() > 0)
|
|
assert_true(r.ntcp2_port() > 0)
|
|
|
|
// Connect to embedded SAMv3 bridge and run HELLO + DEST GENERATE + SESSION CREATE + NAMING LOOKUP
|
|
let sock = @ntcp2_net.TcpSocket::connect("127.0.0.1", r.sam_port())
|
|
r.step(poll_ms=50)
|
|
|
|
sock.write_all(b"HELLO VERSION MIN=3.1 MAX=3.3\n")
|
|
assert_eq(pump_read_line(sock, [r]), "HELLO REPLY RESULT=OK VERSION=3.3")
|
|
|
|
sock.write_all(b"DEST GENERATE SIGNATURE_TYPE=7\n")
|
|
let dest_line = pump_read_line(sock, [r])
|
|
assert_true(dest_line.has_prefix("DEST REPLY PUB="))
|
|
|
|
sock.write_all(
|
|
b"SESSION CREATE STYLE=STREAM ID=test1 DESTINATION=TRANSIENT\n",
|
|
)
|
|
let sess_line = pump_read_line(sock, [r])
|
|
assert_true(sess_line.has_prefix("SESSION STATUS RESULT=OK DESTINATION="))
|
|
assert_eq(r.netdb.leaseset_count(), 1)
|
|
|
|
sock.write_all(b"NAMING LOOKUP NAME=ME\n")
|
|
let lookup_line = pump_read_line(sock, [r])
|
|
assert_true(lookup_line.has_prefix("NAMING REPLY RESULT=OK NAME=ME VALUE="))
|
|
|
|
sock.close()
|
|
r.close()
|
|
}
|
|
|
|
///|
|
|
fn sam_connect_and_hello(
|
|
port : Int32,
|
|
rs : Array[@router.Router],
|
|
) -> @ntcp2_net.TcpSocket raise {
|
|
let sock = @ntcp2_net.TcpSocket::connect("127.0.0.1", port)
|
|
sock.write_all(b"HELLO VERSION MIN=3.1 MAX=3.3\n")
|
|
let reply = pump_read_line(sock, rs)
|
|
assert_eq(reply, "HELLO REPLY RESULT=OK VERSION=3.3")
|
|
sock
|
|
}
|
|
|
|
///|
|
|
fn extract_kv(line : String, key : String) -> String {
|
|
let prefix = key + "="
|
|
let tokens = line.split(" ").collect()
|
|
for t in tokens {
|
|
let ts = t.to_owned()
|
|
if ts.has_prefix(prefix) {
|
|
return ts[prefix.length():].to_owned()
|
|
}
|
|
}
|
|
""
|
|
}
|
|
|
|
///|
|
|
test "Two live routers end-to-end: NTCP2 + ECIES NetDB + Garlic Ratchet + Ed25519 Streaming" {
|
|
let router_b = @router.Router::start(
|
|
{
|
|
sam_host: "127.0.0.1",
|
|
sam_port: 0,
|
|
ntcp2_host: "127.0.0.1",
|
|
ntcp2_port: 0,
|
|
},
|
|
floodfill=true,
|
|
)
|
|
defer router_b.close()
|
|
let router_a = @router.Router::start({
|
|
sam_host: "127.0.0.1",
|
|
sam_port: 0,
|
|
ntcp2_host: "127.0.0.1",
|
|
ntcp2_port: 0,
|
|
})
|
|
defer router_a.close()
|
|
let _ = router_a.netdb.store_router_info(router_b.router_info)
|
|
let _ = router_b.netdb.store_router_info(router_a.router_info)
|
|
let rs = [router_a, router_b]
|
|
|
|
// Bob opens SAM control session + STREAM ACCEPT on router B
|
|
let bob_ctrl = sam_connect_and_hello(router_b.sam_port(), rs)
|
|
defer bob_ctrl.close()
|
|
bob_ctrl.write_all(
|
|
b"SESSION CREATE STYLE=STREAM ID=bob DESTINATION=TRANSIENT\n",
|
|
)
|
|
let bob_sess = pump_read_line(bob_ctrl, rs)
|
|
assert_true(bob_sess.has_prefix("SESSION STATUS RESULT=OK"))
|
|
bob_ctrl.write_all(b"NAMING LOOKUP NAME=ME\n")
|
|
let bob_me = pump_read_line(bob_ctrl, rs)
|
|
let bob_pub_b64 = extract_kv(bob_me, "VALUE")
|
|
let bob_dest = @common.Destination::from_base64(bob_pub_b64)
|
|
let bob_b32 = bob_dest.b32_address()
|
|
|
|
let bob_acc = sam_connect_and_hello(router_b.sam_port(), rs)
|
|
defer bob_acc.close()
|
|
bob_acc.write_all(b"STREAM ACCEPT ID=bob SILENT=false\n")
|
|
assert_eq(pump_read_line(bob_acc, rs), "STREAM STATUS RESULT=OK")
|
|
|
|
// Alice creates SAM control session on router A and looks up Bob's .b32.i2p via live NTCP2 ECIES NetDB
|
|
let alice_ctrl = sam_connect_and_hello(router_a.sam_port(), rs)
|
|
defer alice_ctrl.close()
|
|
alice_ctrl.write_all(
|
|
b"SESSION CREATE STYLE=STREAM ID=alice DESTINATION=TRANSIENT\n",
|
|
)
|
|
let alice_sess = pump_read_line(alice_ctrl, rs)
|
|
assert_true(alice_sess.has_prefix("SESSION STATUS RESULT=OK"))
|
|
|
|
alice_ctrl.write_all(
|
|
@encoding.string_to_utf8_bytes("NAMING LOOKUP NAME=\{bob_b32}\n"),
|
|
)
|
|
let alice_lookup = pump_read_line(alice_ctrl, rs)
|
|
assert_true(alice_lookup.has_prefix("NAMING REPLY RESULT=OK"))
|
|
assert_eq(extract_kv(alice_lookup, "VALUE"), bob_pub_b64)
|
|
|
|
// Alice connects over ECIES-X25519-AEAD-Ratchet Garlic + Ed25519 Streaming
|
|
let alice_data = sam_connect_and_hello(router_a.sam_port(), rs)
|
|
defer alice_data.close()
|
|
alice_data.write_all(
|
|
@encoding.string_to_utf8_bytes(
|
|
"STREAM CONNECT ID=alice DESTINATION=\{bob_pub_b64} SILENT=false\n",
|
|
),
|
|
)
|
|
assert_eq(pump_read_line(alice_data, rs), "STREAM STATUS RESULT=OK")
|
|
let seen_peer_b64 = pump_read_line(bob_acc, rs)
|
|
assert_true(seen_peer_b64.length() > 100)
|
|
|
|
// Bidirectional Streaming payload + close exchange
|
|
alice_data.write_all(b"hello-over-ecies-streaming")
|
|
alice_data.shutdown_write()
|
|
let got_on_bob = pump_read_until_eof(bob_acc, rs)
|
|
assert_eq(got_on_bob, b"hello-over-ecies-streaming")
|
|
|
|
bob_acc.write_all(b"ack-from-bob")
|
|
bob_acc.shutdown_write()
|
|
let got_on_alice = pump_read_until_eof(alice_data, rs)
|
|
assert_eq(got_on_alice, b"ack-from-bob")
|
|
}
|
|
|
|
///|
|
|
fn pump_read_until_bytes_contains(
|
|
sock : @ntcp2_net.TcpSocket,
|
|
rs : Array[@router.Router],
|
|
marker : String,
|
|
max_ticks~ : Int32 = 1500,
|
|
) -> String raise {
|
|
let out : Array[Byte] = []
|
|
for _i = 0; _i < max_ticks; _i = _i + 1 {
|
|
step_routers(rs, 1)
|
|
while sock.poll_readable(0) {
|
|
let chunk = sock.read_some(4096)
|
|
if chunk.length() == 0 {
|
|
return @encoding.utf8_bytes_to_string(Bytes::from_array(out))
|
|
}
|
|
for j = 0; j < chunk.length(); j = j + 1 {
|
|
out.push(chunk[j])
|
|
}
|
|
}
|
|
let s = @encoding.utf8_bytes_to_string(Bytes::from_array(out)) catch {
|
|
_ => ""
|
|
}
|
|
if s.contains(marker) {
|
|
return s
|
|
}
|
|
}
|
|
fail("timed out waiting for marker \{marker}")
|
|
}
|
|
|
|
///|
|
|
test "Two-router HTTP-over-I2P proxy GET, POST, clearnet block, CONNECT block, and addresshelper" {
|
|
let router_b = @router.Router::start(
|
|
{
|
|
sam_host: "127.0.0.1",
|
|
sam_port: 0,
|
|
ntcp2_host: "127.0.0.1",
|
|
ntcp2_port: 0,
|
|
},
|
|
floodfill=true,
|
|
)
|
|
defer router_b.close()
|
|
let router_a = @router.Router::start({
|
|
sam_host: "127.0.0.1",
|
|
sam_port: 0,
|
|
ntcp2_host: "127.0.0.1",
|
|
ntcp2_port: 0,
|
|
})
|
|
defer router_a.close()
|
|
let _ = router_a.netdb.store_router_info(router_b.router_info)
|
|
let _ = router_b.netdb.store_router_info(router_a.router_info)
|
|
let proxy_port = router_a.start_http_proxy(host="127.0.0.1", port=0)
|
|
assert_true(proxy_port > 0)
|
|
assert_eq(router_a.http_proxy_port(), proxy_port)
|
|
let rs = [router_a, router_b]
|
|
|
|
// Bob creates a hidden eepsite destination on Router B and opens SAM STREAM ACCEPT
|
|
let bob_ctrl = sam_connect_and_hello(router_b.sam_port(), rs)
|
|
defer bob_ctrl.close()
|
|
bob_ctrl.write_all(
|
|
b"SESSION CREATE STYLE=STREAM ID=bobhttp DESTINATION=TRANSIENT\n",
|
|
)
|
|
assert_true(
|
|
pump_read_line(bob_ctrl, rs).has_prefix("SESSION STATUS RESULT=OK"),
|
|
)
|
|
bob_ctrl.write_all(b"NAMING LOOKUP NAME=ME\n")
|
|
let bob_pub_b64 = extract_kv(pump_read_line(bob_ctrl, rs), "VALUE")
|
|
let bob_b32 = @common.Destination::from_base64(bob_pub_b64).b32_address()
|
|
|
|
// 1. Proxied HTTP/1.1 GET over .b32.i2p -> NetDB -> ECIES Garlic -> Streaming
|
|
let bob_acc1 = sam_connect_and_hello(router_b.sam_port(), rs)
|
|
defer bob_acc1.close()
|
|
bob_acc1.write_all(b"STREAM ACCEPT ID=bobhttp SILENT=false\n")
|
|
assert_eq(pump_read_line(bob_acc1, rs), "STREAM STATUS RESULT=OK")
|
|
|
|
let p1 = @ntcp2_net.TcpSocket::connect("127.0.0.1", proxy_port)
|
|
defer p1.close()
|
|
let req1 = "GET http://\{bob_b32}/hello?x=1 HTTP/1.1\r\nHost: \{bob_b32}\r\nCookie: sid=abc\r\nProxy-Connection: keep-alive\r\nReferer: http://clearnet.example.com/\r\nConnection: keep-alive\r\n\r\n"
|
|
p1.write_all(@encoding.string_to_utf8_bytes(req1))
|
|
|
|
let peer_b64_1 = pump_read_line(bob_acc1, rs)
|
|
assert_true(peer_b64_1.length() > 100)
|
|
let got_req1 = pump_read_until_bytes_contains(bob_acc1, rs, "\r\n\r\n")
|
|
assert_true(got_req1.has_prefix("GET /hello?x=1 HTTP/1.1\r\n"))
|
|
assert_true(got_req1.contains("Host: \{bob_b32}\r\n"))
|
|
assert_true(got_req1.contains("Cookie: sid=abc\r\n"))
|
|
assert_true(got_req1.contains("Connection: close\r\n"))
|
|
assert_true(!got_req1.contains("Proxy-Connection"))
|
|
assert_true(!got_req1.contains("clearnet.example.com"))
|
|
|
|
bob_acc1.write_all(
|
|
b"HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 9\r\n\r\npong-http",
|
|
)
|
|
bob_acc1.shutdown_write()
|
|
let resp1_str = @encoding.utf8_bytes_to_string(pump_read_until_eof(p1, rs))
|
|
assert_true(resp1_str.has_prefix("HTTP/1.1 200 OK\r\n"))
|
|
assert_true(resp1_str.has_suffix("pong-http"))
|
|
|
|
// 2. Proxied HTTP/1.1 POST over .b32.i2p alias with body forwarding & .i2p Referer
|
|
router_a.register_alias("bobsite.i2p", bob_b32)
|
|
let bob_acc2 = sam_connect_and_hello(router_b.sam_port(), rs)
|
|
defer bob_acc2.close()
|
|
bob_acc2.write_all(b"STREAM ACCEPT ID=bobhttp SILENT=false\n")
|
|
assert_eq(pump_read_line(bob_acc2, rs), "STREAM STATUS RESULT=OK")
|
|
|
|
let p2 = @ntcp2_net.TcpSocket::connect("127.0.0.1", proxy_port)
|
|
defer p2.close()
|
|
p2.write_all(
|
|
b"POST http://bobsite.i2p/form HTTP/1.1\r\nHost: bobsite.i2p\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 7\r\nReferer: http://bobsite.i2p/\r\n\r\na=1&b=2",
|
|
)
|
|
let _ = pump_read_line(bob_acc2, rs)
|
|
let got_req2 = pump_read_until_bytes_contains(bob_acc2, rs, "a=1&b=2")
|
|
assert_true(got_req2.has_prefix("POST /form HTTP/1.1\r\n"))
|
|
assert_true(got_req2.contains("Referer: http://bobsite.i2p/\r\n"))
|
|
assert_true(got_req2.has_suffix("a=1&b=2"))
|
|
|
|
bob_acc2.write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\npost-ok")
|
|
bob_acc2.shutdown_write()
|
|
let resp2_str = @encoding.utf8_bytes_to_string(pump_read_until_eof(p2, rs))
|
|
assert_true(resp2_str.has_suffix("post-ok"))
|
|
|
|
// 3. Clearnet host rejection (403 Forbidden)
|
|
let p3 = @ntcp2_net.TcpSocket::connect("127.0.0.1", proxy_port)
|
|
defer p3.close()
|
|
p3.write_all(b"GET http://example.com/ HTTP/1.1\r\nHost: example.com\r\n\r\n")
|
|
let resp3_str = @encoding.utf8_bytes_to_string(pump_read_until_eof(p3, rs))
|
|
assert_true(resp3_str.has_prefix("HTTP/1.1 403 Forbidden\r\n"))
|
|
|
|
// 4. CONNECT rejection (501 Not Implemented)
|
|
let p4 = @ntcp2_net.TcpSocket::connect("127.0.0.1", proxy_port)
|
|
defer p4.close()
|
|
p4.write_all(
|
|
b"CONNECT example.com:443 HTTP/1.1\r\nHost: example.com:443\r\n\r\n",
|
|
)
|
|
let resp4_str = @encoding.utf8_bytes_to_string(pump_read_until_eof(p4, rs))
|
|
assert_true(resp4_str.has_prefix("HTTP/1.1 501 Not Implemented\r\n"))
|
|
|
|
// 5. ?i2paddresshelper= jump link registration + 302 redirect
|
|
let p5 = @ntcp2_net.TcpSocket::connect("127.0.0.1", proxy_port)
|
|
defer p5.close()
|
|
let req5 = "GET http://jumpnew.i2p/page?foo=1&i2paddresshelper=\{bob_pub_b64}&bar=2 HTTP/1.1\r\nHost: jumpnew.i2p\r\n\r\n"
|
|
p5.write_all(@encoding.string_to_utf8_bytes(req5))
|
|
let resp5_str = @encoding.utf8_bytes_to_string(pump_read_until_eof(p5, rs))
|
|
assert_true(resp5_str.has_prefix("HTTP/1.1 302 Found\r\n"))
|
|
assert_true(
|
|
resp5_str.contains("Location: http://jumpnew.i2p/page?foo=1&bar=2\r\n"),
|
|
)
|
|
}
|
|
|
|
///|
|
|
test "Three-router live Proposal 157 multi-hop tunnel build and fragmented 2500B TunnelData stream" {
|
|
let router_b = @router.Router::start(
|
|
{
|
|
sam_host: "127.0.0.1",
|
|
sam_port: 0,
|
|
ntcp2_host: "127.0.0.1",
|
|
ntcp2_port: 0,
|
|
},
|
|
floodfill=true,
|
|
)
|
|
defer router_b.close()
|
|
let router_c = @router.Router::start({
|
|
sam_host: "127.0.0.1",
|
|
sam_port: 0,
|
|
ntcp2_host: "127.0.0.1",
|
|
ntcp2_port: 0,
|
|
})
|
|
defer router_c.close()
|
|
let router_a = @router.Router::start({
|
|
sam_host: "127.0.0.1",
|
|
sam_port: 0,
|
|
ntcp2_host: "127.0.0.1",
|
|
ntcp2_port: 0,
|
|
})
|
|
defer router_a.close()
|
|
|
|
for r in [router_a, router_b, router_c] {
|
|
let _ = r.netdb.store_router_info(router_a.router_info)
|
|
let _ = r.netdb.store_router_info(router_b.router_info)
|
|
let _ = r.netdb.store_router_info(router_c.router_info)
|
|
}
|
|
let rs = [router_a, router_b, router_c]
|
|
|
|
// Router A builds 2-hop Outbound [B -> C] and 2-hop Inbound [B -> C -> A] tunnels via Proposal 157
|
|
let out_tid = router_a.build_tunnel(
|
|
[router_b.router_hash(), router_c.router_hash()],
|
|
Outbound,
|
|
)
|
|
let in_tid = router_a.build_tunnel(
|
|
[router_b.router_hash(), router_c.router_hash()],
|
|
Inbound,
|
|
)
|
|
let mut built = false
|
|
for _i = 0; _i < 1000; _i = _i + 1 {
|
|
step_routers(rs, 1)
|
|
if router_a.has_tunnel(out_tid) && router_a.has_tunnel(in_tid) {
|
|
built = true
|
|
break
|
|
}
|
|
}
|
|
assert_true(built)
|
|
assert_true(router_b.tunnels.transit_count() >= 2)
|
|
assert_true(router_c.tunnels.transit_count() >= 2)
|
|
|
|
// Router C hosts Bob; Router A hosts Alice (whose LS2 uses her Inbound [B -> C -> A] tunnel lease)
|
|
let bob_ctrl = sam_connect_and_hello(router_c.sam_port(), rs)
|
|
defer bob_ctrl.close()
|
|
bob_ctrl.write_all(
|
|
b"SESSION CREATE STYLE=STREAM ID=bob3 DESTINATION=TRANSIENT\n",
|
|
)
|
|
assert_true(
|
|
pump_read_line(bob_ctrl, rs).has_prefix("SESSION STATUS RESULT=OK"),
|
|
)
|
|
bob_ctrl.write_all(b"NAMING LOOKUP NAME=ME\n")
|
|
let bob_pub_b64 = extract_kv(pump_read_line(bob_ctrl, rs), "VALUE")
|
|
let bob_b32 = @common.Destination::from_base64(bob_pub_b64).b32_address()
|
|
|
|
let bob_acc = sam_connect_and_hello(router_c.sam_port(), rs)
|
|
defer bob_acc.close()
|
|
bob_acc.write_all(b"STREAM ACCEPT ID=bob3 SILENT=false\n")
|
|
assert_eq(pump_read_line(bob_acc, rs), "STREAM STATUS RESULT=OK")
|
|
|
|
let alice_ctrl = sam_connect_and_hello(router_a.sam_port(), rs)
|
|
defer alice_ctrl.close()
|
|
alice_ctrl.write_all(
|
|
b"SESSION CREATE STYLE=STREAM ID=alice3 DESTINATION=TRANSIENT\n",
|
|
)
|
|
assert_true(
|
|
pump_read_line(alice_ctrl, rs).has_prefix("SESSION STATUS RESULT=OK"),
|
|
)
|
|
alice_ctrl.write_all(
|
|
@encoding.string_to_utf8_bytes("NAMING LOOKUP NAME=\{bob_b32}\n"),
|
|
)
|
|
assert_eq(extract_kv(pump_read_line(alice_ctrl, rs), "VALUE"), bob_pub_b64)
|
|
|
|
let alice_data = sam_connect_and_hello(router_a.sam_port(), rs)
|
|
defer alice_data.close()
|
|
alice_data.write_all(
|
|
@encoding.string_to_utf8_bytes(
|
|
"STREAM CONNECT ID=alice3 DESTINATION=\{bob_pub_b64} SILENT=false\n",
|
|
),
|
|
)
|
|
assert_eq(pump_read_line(alice_data, rs), "STREAM STATUS RESULT=OK")
|
|
let _ = pump_read_line(bob_acc, rs)
|
|
|
|
// Send 2500 bytes (spanning multiple Streaming packets & fragmented 1024B TunnelData cells)
|
|
let big_payload = Bytes::make(2500, b'\x41')
|
|
alice_data.write_all(big_payload)
|
|
alice_data.shutdown_write()
|
|
assert_eq(pump_read_until_eof(bob_acc, rs), big_payload)
|
|
|
|
bob_acc.write_all(b"tunneled-ok")
|
|
bob_acc.shutdown_write()
|
|
assert_eq(pump_read_until_eof(alice_data, rs), b"tunneled-ok")
|
|
}
|
|
|
|
///|
|
|
test "Proposal 157 Outbound tunnel replying via Inbound tunnel with OBEP ECIES Garlic" {
|
|
let router_b = @router.Router::start({
|
|
sam_host: "127.0.0.1",
|
|
sam_port: 0,
|
|
ntcp2_host: "127.0.0.1",
|
|
ntcp2_port: 0,
|
|
})
|
|
defer router_b.close()
|
|
let router_c = @router.Router::start({
|
|
sam_host: "127.0.0.1",
|
|
sam_port: 0,
|
|
ntcp2_host: "127.0.0.1",
|
|
ntcp2_port: 0,
|
|
})
|
|
defer router_c.close()
|
|
let router_a = @router.Router::start({
|
|
sam_host: "127.0.0.1",
|
|
sam_port: 0,
|
|
ntcp2_host: "127.0.0.1",
|
|
ntcp2_port: 0,
|
|
})
|
|
defer router_a.close()
|
|
|
|
for r in [router_a, router_b, router_c] {
|
|
let _ = r.netdb.store_router_info(router_a.router_info)
|
|
let _ = r.netdb.store_router_info(router_b.router_info)
|
|
let _ = r.netdb.store_router_info(router_c.router_info)
|
|
}
|
|
let rs = [router_a, router_b, router_c]
|
|
|
|
let in_tid = router_a.build_tunnel([router_b.router_hash()], Inbound)
|
|
for _i = 0; _i < 500; _i = _i + 1 {
|
|
step_routers(rs, 1)
|
|
if router_a.has_tunnel(in_tid) {
|
|
break
|
|
}
|
|
}
|
|
assert_true(router_a.has_tunnel(in_tid))
|
|
|
|
let reply_in = router_a.tunnels.inbound[0]
|
|
let out_tid = router_a.build_tunnel(
|
|
[router_c.router_hash()],
|
|
Outbound,
|
|
reply_tunnel=Some(reply_in),
|
|
)
|
|
let mut built_out = false
|
|
for _i = 0; _i < 800; _i = _i + 1 {
|
|
step_routers(rs, 1)
|
|
if router_a.has_tunnel(out_tid) {
|
|
built_out = true
|
|
break
|
|
}
|
|
}
|
|
assert_true(built_out)
|
|
}
|