mirror of
https://github.com/n0-computer/iroh.git
synced 2026-12-01 00:01:52 +00:00
deploy: 9889a0bd2f0417d5412373211173edb714bfb9d2
This commit is contained in:
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../iroh_relay/client/enum.ConnSendError.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../iroh_relay/client/enum.ConnSendError.html">../../../iroh_relay/client/enum.ConnSendError.html</a>...</p>
|
||||
<script>location.replace("../../../iroh_relay/client/enum.ConnSendError.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,11 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../iroh_relay/enum.ReceivedMessage.html">
|
||||
<meta http-equiv="refresh" content="0;URL=../../../iroh_relay/client/enum.ReceivedMessage.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../iroh_relay/enum.ReceivedMessage.html">../../../iroh_relay/enum.ReceivedMessage.html</a>...</p>
|
||||
<script>location.replace("../../../iroh_relay/enum.ReceivedMessage.html" + location.search + location.hash);</script>
|
||||
<p>Redirecting to <a href="../../../iroh_relay/client/enum.ReceivedMessage.html">../../../iroh_relay/client/enum.ReceivedMessage.html</a>...</p>
|
||||
<script>location.replace("../../../iroh_relay/client/enum.ReceivedMessage.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../iroh_relay/client/enum.SendMessage.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../iroh_relay/client/enum.SendMessage.html">../../../iroh_relay/client/enum.SendMessage.html</a>...</p>
|
||||
<script>location.replace("../../../iroh_relay/client/enum.SendMessage.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,11 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0;URL=../../../iroh_relay/struct.RelayConn.html">
|
||||
<title>Redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
<p>Redirecting to <a href="../../../iroh_relay/struct.RelayConn.html">../../../iroh_relay/struct.RelayConn.html</a>...</p>
|
||||
<script>location.replace("../../../iroh_relay/struct.RelayConn.html" + location.search + location.hash);</script>
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+10
-10
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,3 +1,3 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Creates a client config that trusts any servers without verifying their TLS certificate."><title>make_dangerous_client_config in iroh_relay::client - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-dbdb5eec.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="iroh_relay" data-themes="" data-resource-suffix="" data-rustdoc-version="1.85.0-nightly (d10a6823f 2024-11-29)" data-channel="nightly" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../iroh_relay/index.html">iroh_<wbr>relay</a><span class="version">0.30.0</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In iroh_<wbr>relay::<wbr>client</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">iroh_relay</a>::<wbr><a href="index.html">client</a></span><h1>Function <span class="fn">make_dangerous_client_config</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/iroh_relay/client.rs.html#354-366">Source</a> </span></div><pre class="rust item-decl"><code>pub fn make_dangerous_client_config() -> ClientConfig</code></pre><span class="item-info"><div class="stab portability">Available on <strong>crate feature <code>test-utils</code></strong> only.</div></span><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Creates a client config that trusts any servers without verifying their TLS certificate.</p>
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Creates a client config that trusts any servers without verifying their TLS certificate."><title>make_dangerous_client_config in iroh_relay::client - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-dbdb5eec.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="iroh_relay" data-themes="" data-resource-suffix="" data-rustdoc-version="1.85.0-nightly (d10a6823f 2024-11-29)" data-channel="nightly" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../iroh_relay/index.html">iroh_<wbr>relay</a><span class="version">0.30.0</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In iroh_<wbr>relay::<wbr>client</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">iroh_relay</a>::<wbr><a href="index.html">client</a></span><h1>Function <span class="fn">make_dangerous_client_config</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/iroh_relay/client.rs.html#303-315">Source</a> </span></div><pre class="rust item-decl"><code>pub fn make_dangerous_client_config() -> ClientConfig</code></pre><span class="item-info"><div class="stab portability">Available on <strong>crate feature <code>test-utils</code></strong> only.</div></span><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Creates a client config that trusts any servers without verifying their TLS certificate.</p>
|
||||
<p>Should be used for testing local relay setups only.</p>
|
||||
</div></details></section></div></main></body></html>
|
||||
@@ -1,3 +1,3 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Exposes `Client`, which allows to establish connections to a relay server."><title>iroh_relay::client - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-dbdb5eec.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="iroh_relay" data-themes="" data-resource-suffix="" data-rustdoc-version="1.85.0-nightly (d10a6823f 2024-11-29)" data-channel="nightly" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../iroh_relay/index.html">iroh_<wbr>relay</a><span class="version">0.30.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module client</a></h2><h3><a href="#structs">Module Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#functions" title="Functions">Functions</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate iroh_<wbr>relay</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">iroh_relay</a></span><h1>Module <span>client</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/iroh_relay/client.rs.html#1-1208">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Exposes <a href="struct.Client.html" title="struct iroh_relay::client::Client"><code>Client</code></a>, which allows to establish connections to a relay server.</p>
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Exposes `Client`, which allows to establish connections to a relay server."><title>iroh_relay::client - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-dbdb5eec.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="iroh_relay" data-themes="" data-resource-suffix="" data-rustdoc-version="1.85.0-nightly (d10a6823f 2024-11-29)" data-channel="nightly" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../iroh_relay/index.html">iroh_<wbr>relay</a><span class="version">0.30.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module client</a></h2><h3><a href="#structs">Module Items</a></h3><ul class="block"><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#functions" title="Functions">Functions</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate iroh_<wbr>relay</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">iroh_relay</a></span><h1>Module <span>client</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/iroh_relay/client.rs.html#1-755">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Exposes <a href="struct.Client.html" title="struct iroh_relay::client::Client"><code>Client</code></a>, which allows to establish connections to a relay server.</p>
|
||||
<p>Based on tailscale/derp/derphttp/derphttp_client.go</p>
|
||||
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Client.html" title="struct iroh_relay::client::Client">Client</a></div><div class="desc docblock-short">An HTTP Relay client.</div></li><li><div class="item-name"><a class="struct" href="struct.ClientBuilder.html" title="struct iroh_relay::client::ClientBuilder">Client<wbr>Builder</a></div><div class="desc docblock-short">Build a Client.</div></li><li><div class="item-name"><a class="struct" href="struct.ClientReceiver.html" title="struct iroh_relay::client::ClientReceiver">Client<wbr>Receiver</a></div><div class="desc docblock-short">Receiving end of a <a href="struct.Client.html" title="struct iroh_relay::client::Client"><code>Client</code></a>.</div></li></ul><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.ClientError.html" title="enum iroh_relay::client::ClientError">Client<wbr>Error</a></div><div class="desc docblock-short">Possible connection errors on the <a href="struct.Client.html" title="struct iroh_relay::client::Client"><code>Client</code></a></div></li></ul><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.make_dangerous_client_config.html" title="fn iroh_relay::client::make_dangerous_client_config">make_<wbr>dangerous_<wbr>client_<wbr>config</a><wbr><span class="stab portability" title="Available on crate feature `test-utils` only"><code>test-utils</code></span></div><div class="desc docblock-short">Creates a client config that trusts any servers without verifying their TLS certificate.</div></li></ul></section></div></main></body></html>
|
||||
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.Client.html" title="struct iroh_relay::client::Client">Client</a></div><div class="desc docblock-short">A relay client.</div></li><li><div class="item-name"><a class="struct" href="struct.ClientBuilder.html" title="struct iroh_relay::client::ClientBuilder">Client<wbr>Builder</a></div><div class="desc docblock-short">Build a Client.</div></li><li><div class="item-name"><a class="struct" href="struct.ClientSink.html" title="struct iroh_relay::client::ClientSink">Client<wbr>Sink</a></div><div class="desc docblock-short">The send half of a relay client.</div></li><li><div class="item-name"><a class="struct" href="struct.ClientStream.html" title="struct iroh_relay::client::ClientStream">Client<wbr>Stream</a></div><div class="desc docblock-short">The receive half of a relay client.</div></li></ul><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.ConnSendError.html" title="enum iroh_relay::client::ConnSendError">Conn<wbr>Send<wbr>Error</a></div><div class="desc docblock-short">Error for sending messages to the relay server.</div></li><li><div class="item-name"><a class="enum" href="enum.ReceivedMessage.html" title="enum iroh_relay::client::ReceivedMessage">Received<wbr>Message</a></div><div class="desc docblock-short">The messages received from a framed relay stream.</div></li><li><div class="item-name"><a class="enum" href="enum.SendMessage.html" title="enum iroh_relay::client::SendMessage">Send<wbr>Message</a></div><div class="desc docblock-short">Messages we can send to a relay server.</div></li></ul><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="fn" href="fn.make_dangerous_client_config.html" title="fn iroh_relay::client::make_dangerous_client_config">make_<wbr>dangerous_<wbr>client_<wbr>config</a><wbr><span class="stab portability" title="Available on crate feature `test-utils` only"><code>test-utils</code></span></div><div class="desc docblock-short">Creates a client config that trusts any servers without verifying their TLS certificate.</div></li></ul></section></div></main></body></html>
|
||||
@@ -1 +1 @@
|
||||
window.SIDEBAR_ITEMS = {"enum":["ClientError"],"fn":["make_dangerous_client_config"],"struct":["Client","ClientBuilder","ClientReceiver"]};
|
||||
window.SIDEBAR_ITEMS = {"enum":["ConnSendError","ReceivedMessage","SendMessage"],"fn":["make_dangerous_client_config"],"struct":["Client","ClientBuilder","ClientSink","ClientStream"]};
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,3 +1,3 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Default values used in the relay."><title>iroh_relay::defaults - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-dbdb5eec.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="iroh_relay" data-themes="" data-resource-suffix="" data-rustdoc-version="1.85.0-nightly (d10a6823f 2024-11-29)" data-channel="nightly" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../iroh_relay/index.html">iroh_<wbr>relay</a><span class="version">0.30.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module defaults</a></h2><h3><a href="#constants">Module Items</a></h3><ul class="block"><li><a href="#constants" title="Constants">Constants</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate iroh_<wbr>relay</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">iroh_relay</a></span><h1>Module <span>defaults</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/iroh_relay/defaults.rs.html#1-53">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Default values used in the relay.</p>
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Default values used in the relay."><title>iroh_relay::defaults - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-dbdb5eec.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="iroh_relay" data-themes="" data-resource-suffix="" data-rustdoc-version="1.85.0-nightly (d10a6823f 2024-11-29)" data-channel="nightly" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../iroh_relay/index.html">iroh_<wbr>relay</a><span class="version">0.30.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module defaults</a></h2><h3><a href="#constants">Module Items</a></h3><ul class="block"><li><a href="#constants" title="Constants">Constants</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate iroh_<wbr>relay</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">iroh_relay</a></span><h1>Module <span>defaults</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/iroh_relay/defaults.rs.html#1-43">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Default values used in the relay.</p>
|
||||
</div></details><h2 id="constants" class="section-header">Constants<a href="#constants" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="constant" href="constant.DEFAULT_HTTPS_PORT.html" title="constant iroh_relay::defaults::DEFAULT_HTTPS_PORT">DEFAULT_<wbr>HTTPS_<wbr>PORT</a></div><div class="desc docblock-short">The default HTTPS port used by the Relay server.</div></li><li><div class="item-name"><a class="constant" href="constant.DEFAULT_HTTP_PORT.html" title="constant iroh_relay::defaults::DEFAULT_HTTP_PORT">DEFAULT_<wbr>HTTP_<wbr>PORT</a></div><div class="desc docblock-short">The default HTTP port used by the Relay server.</div></li><li><div class="item-name"><a class="constant" href="constant.DEFAULT_KEY_CACHE_CAPACITY.html" title="constant iroh_relay::defaults::DEFAULT_KEY_CACHE_CAPACITY">DEFAULT_<wbr>KEY_<wbr>CACHE_<wbr>CAPACITY</a></div><div class="desc docblock-short">The default capacity of the key cache for the relay server.</div></li><li><div class="item-name"><a class="constant" href="constant.DEFAULT_METRICS_PORT.html" title="constant iroh_relay::defaults::DEFAULT_METRICS_PORT">DEFAULT_<wbr>METRICS_<wbr>PORT</a></div><div class="desc docblock-short">The default metrics port used by the Relay server.</div></li><li><div class="item-name"><a class="constant" href="constant.DEFAULT_RELAY_QUIC_PORT.html" title="constant iroh_relay::defaults::DEFAULT_RELAY_QUIC_PORT">DEFAULT_<wbr>RELAY_<wbr>QUIC_<wbr>PORT</a></div><div class="desc docblock-short">The default QUIC port used by the Relay server to accept QUIC connections
|
||||
for QUIC address discovery</div></li><li><div class="item-name"><a class="constant" href="constant.DEFAULT_STUN_PORT.html" title="constant iroh_relay::defaults::DEFAULT_STUN_PORT">DEFAULT_<wbr>STUN_<wbr>PORT</a></div><div class="desc docblock-short">The default STUN port used by the Relay server.</div></li></ul></section></div></main></body></html>
|
||||
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Iroh’s relay is a feature within iroh, a peer-to-peer networking system designed to facilitate direct, encrypted connections between devices. Iroh aims to simplify decentralized communication by automatically handling connections through “relays” when direct connections aren’t immediately possible. The relay server helps establish connections by temporarily routing encrypted traffic until a direct, P2P connection is feasible. Once this direct path is set up, the relay server steps back, and the data flows directly between devices. This approach allows Iroh to maintain a secure, low-latency connection, even in challenging network situations."><title>iroh_relay - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-dbdb5eec.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="iroh_relay" data-themes="" data-resource-suffix="" data-rustdoc-version="1.85.0-nightly (d10a6823f 2024-11-29)" data-channel="nightly" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../iroh_relay/index.html">iroh_<wbr>relay</a><span class="version">0.30.0</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#reexports">Crate Items</a></h3><ul class="block"><li><a href="#reexports" title="Re-exports">Re-exports</a></li><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>iroh_relay</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/iroh_relay/lib.rs.html#1-57">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Iroh’s relay is a feature within <a href="https://github.com/n0-computer/iroh">iroh</a>, a peer-to-peer
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Iroh’s relay is a feature within iroh, a peer-to-peer networking system designed to facilitate direct, encrypted connections between devices. Iroh aims to simplify decentralized communication by automatically handling connections through “relays” when direct connections aren’t immediately possible. The relay server helps establish connections by temporarily routing encrypted traffic until a direct, P2P connection is feasible. Once this direct path is set up, the relay server steps back, and the data flows directly between devices. This approach allows Iroh to maintain a secure, low-latency connection, even in challenging network situations."><title>iroh_relay - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-dbdb5eec.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="iroh_relay" data-themes="" data-resource-suffix="" data-rustdoc-version="1.85.0-nightly (d10a6823f 2024-11-29)" data-channel="nightly" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc mod crate"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../iroh_relay/index.html">iroh_<wbr>relay</a><span class="version">0.30.0</span></h2></div><div class="sidebar-elems"><ul class="block"><li><a id="all-types" href="all.html">All Items</a></li></ul><section id="rustdoc-toc"><h3><a href="#reexports">Crate Items</a></h3><ul class="block"><li><a href="#reexports" title="Re-exports">Re-exports</a></li><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#structs" title="Structs">Structs</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>iroh_relay</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/iroh_relay/lib.rs.html#1-50">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Iroh’s relay is a feature within <a href="https://github.com/n0-computer/iroh">iroh</a>, a peer-to-peer
|
||||
networking system designed to facilitate direct, encrypted connections between devices. Iroh
|
||||
aims to simplify decentralized communication by automatically handling connections through
|
||||
“relays” when direct connections aren’t immediately possible. The relay server helps establish
|
||||
@@ -25,6 +25,6 @@ Tailscale.</p>
|
||||
STUN support and expose metrics.</p>
|
||||
</li>
|
||||
</ul>
|
||||
</div></details><h2 id="reexports" class="section-header">Re-exports<a href="#reexports" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name" id="reexport.MAX_PACKET_SIZE"><code>pub use protos::relay::<a class="constant" href="protos/relay/constant.MAX_PACKET_SIZE.html" title="constant iroh_relay::protos::relay::MAX_PACKET_SIZE">MAX_PACKET_SIZE</a>;</code></div></li><li><div class="item-name" id="reexport.HttpClient"><code>pub use self::client::<a class="struct" href="client/struct.Client.html" title="struct iroh_relay::client::Client">Client</a> as HttpClient;</code></div></li><li><div class="item-name" id="reexport.HttpClientBuilder"><code>pub use self::client::<a class="struct" href="client/struct.ClientBuilder.html" title="struct iroh_relay::client::ClientBuilder">ClientBuilder</a> as HttpClientBuilder;</code></div></li><li><div class="item-name" id="reexport.HttpClientError"><code>pub use self::client::<a class="enum" href="client/enum.ClientError.html" title="enum iroh_relay::client::ClientError">ClientError</a> as HttpClientError;</code></div></li><li><div class="item-name" id="reexport.HttpClientReceiver"><code>pub use self::client::<a class="struct" href="client/struct.ClientReceiver.html" title="struct iroh_relay::client::ClientReceiver">ClientReceiver</a> as HttpClientReceiver;</code></div></li></ul><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="client/index.html" title="mod iroh_relay::client">client</a></div><div class="desc docblock-short">Exposes <a href="client/struct.Client.html" title="struct iroh_relay::client::Client"><code>Client</code></a>, which allows to establish connections to a relay server.</div></li><li><div class="item-name"><a class="mod" href="defaults/index.html" title="mod iroh_relay::defaults">defaults</a></div><div class="desc docblock-short">Default values used in the relay.</div></li><li><div class="item-name"><a class="mod" href="http/index.html" title="mod iroh_relay::http">http</a></div><div class="desc docblock-short">HTTP-specific constants for the relay server and client.</div></li><li><div class="item-name"><a class="mod" href="protos/index.html" title="mod iroh_relay::protos">protos</a></div><div class="desc docblock-short">Protocols used by the iroh-relay</div></li><li><div class="item-name"><a class="mod" href="quic/index.html" title="mod iroh_relay::quic">quic</a></div><div class="desc docblock-short">Create a QUIC server that accepts connections
|
||||
for QUIC address discovery.</div></li><li><div class="item-name"><a class="mod" href="server/index.html" title="mod iroh_relay::server">server</a><wbr><span class="stab portability" title="Available on crate feature `server` only"><code>server</code></span></div><div class="desc docblock-short">A fully-fledged iroh-relay server over HTTP or HTTPS.</div></li></ul><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.RelayConn.html" title="struct iroh_relay::RelayConn">Relay<wbr>Conn</a></div><div class="desc docblock-short">A connection to a relay server.</div></li><li><div class="item-name"><a class="struct" href="struct.RelayMap.html" title="struct iroh_relay::RelayMap">Relay<wbr>Map</a></div><div class="desc docblock-short">Configuration of all the relay servers that can be used.</div></li><li><div class="item-name"><a class="struct" href="struct.RelayNode.html" title="struct iroh_relay::RelayNode">Relay<wbr>Node</a></div><div class="desc docblock-short">Information on a specific relay server.</div></li><li><div class="item-name"><a class="struct" href="struct.RelayQuicConfig.html" title="struct iroh_relay::RelayQuicConfig">Relay<wbr>Quic<wbr>Config</a></div><div class="desc docblock-short">Configuration for speaking to the QUIC endpoint on the relay
|
||||
server to do QUIC address discovery.</div></li></ul><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.ReceivedMessage.html" title="enum iroh_relay::ReceivedMessage">Received<wbr>Message</a></div><div class="desc docblock-short">The messages received from a framed relay stream.</div></li></ul></section></div></main></body></html>
|
||||
</div></details><h2 id="reexports" class="section-header">Re-exports<a href="#reexports" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name" id="reexport.MAX_PACKET_SIZE"><code>pub use protos::relay::<a class="constant" href="protos/relay/constant.MAX_PACKET_SIZE.html" title="constant iroh_relay::protos::relay::MAX_PACKET_SIZE">MAX_PACKET_SIZE</a>;</code></div></li></ul><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="client/index.html" title="mod iroh_relay::client">client</a></div><div class="desc docblock-short">Exposes <a href="client/struct.Client.html" title="struct iroh_relay::client::Client"><code>Client</code></a>, which allows to establish connections to a relay server.</div></li><li><div class="item-name"><a class="mod" href="defaults/index.html" title="mod iroh_relay::defaults">defaults</a></div><div class="desc docblock-short">Default values used in the relay.</div></li><li><div class="item-name"><a class="mod" href="http/index.html" title="mod iroh_relay::http">http</a></div><div class="desc docblock-short">HTTP-specific constants for the relay server and client.</div></li><li><div class="item-name"><a class="mod" href="protos/index.html" title="mod iroh_relay::protos">protos</a></div><div class="desc docblock-short">Protocols used by the iroh-relay</div></li><li><div class="item-name"><a class="mod" href="quic/index.html" title="mod iroh_relay::quic">quic</a></div><div class="desc docblock-short">Create a QUIC server that accepts connections
|
||||
for QUIC address discovery.</div></li><li><div class="item-name"><a class="mod" href="server/index.html" title="mod iroh_relay::server">server</a><wbr><span class="stab portability" title="Available on crate feature `server` only"><code>server</code></span></div><div class="desc docblock-short">A fully-fledged iroh-relay server over HTTP or HTTPS.</div></li></ul><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.RelayMap.html" title="struct iroh_relay::RelayMap">Relay<wbr>Map</a></div><div class="desc docblock-short">Configuration of all the relay servers that can be used.</div></li><li><div class="item-name"><a class="struct" href="struct.RelayNode.html" title="struct iroh_relay::RelayNode">Relay<wbr>Node</a></div><div class="desc docblock-short">Information on a specific relay server.</div></li><li><div class="item-name"><a class="struct" href="struct.RelayQuicConfig.html" title="struct iroh_relay::RelayQuicConfig">Relay<wbr>Quic<wbr>Config</a></div><div class="desc docblock-short">Configuration for speaking to the QUIC endpoint on the relay
|
||||
server to do QUIC address discovery.</div></li></ul></section></div></main></body></html>
|
||||
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="The maximum size of a packet sent over relay. (This only includes the data bytes visible to magicsock, not including its on-wire framing overhead)"><title>MAX_PACKET_SIZE in iroh_relay::protos::relay - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../static.files/rustdoc-dbdb5eec.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="iroh_relay" data-themes="" data-resource-suffix="" data-rustdoc-version="1.85.0-nightly (d10a6823f 2024-11-29)" data-channel="nightly" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-044be391.svg"></head><body class="rustdoc constant"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../iroh_relay/index.html">iroh_<wbr>relay</a><span class="version">0.30.0</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In iroh_<wbr>relay::<wbr>protos::<wbr>relay</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../../index.html">iroh_relay</a>::<wbr><a href="../index.html">protos</a>::<wbr><a href="index.html">relay</a></span><h1>Constant <span class="constant">MAX_PACKET_SIZE</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../src/iroh_relay/protos/relay.rs.html#33">Source</a> </span></div><pre class="rust item-decl"><code>pub const MAX_PACKET_SIZE: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a> = _; // 65_536usize</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>The maximum size of a packet sent over relay.
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="The maximum size of a packet sent over relay. (This only includes the data bytes visible to magicsock, not including its on-wire framing overhead)"><title>MAX_PACKET_SIZE in iroh_relay::protos::relay - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../static.files/rustdoc-dbdb5eec.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="iroh_relay" data-themes="" data-resource-suffix="" data-rustdoc-version="1.85.0-nightly (d10a6823f 2024-11-29)" data-channel="nightly" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-044be391.svg"></head><body class="rustdoc constant"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../iroh_relay/index.html">iroh_<wbr>relay</a><span class="version">0.30.0</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In iroh_<wbr>relay::<wbr>protos::<wbr>relay</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../../index.html">iroh_relay</a>::<wbr><a href="../index.html">protos</a>::<wbr><a href="index.html">relay</a></span><h1>Constant <span class="constant">MAX_PACKET_SIZE</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../src/iroh_relay/protos/relay.rs.html#34">Source</a> </span></div><pre class="rust item-decl"><code>pub const MAX_PACKET_SIZE: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a> = _; // 65_536usize</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>The maximum size of a packet sent over relay.
|
||||
(This only includes the data bytes visible to magicsock, not
|
||||
including its on-wire framing overhead)</p>
|
||||
</div></details></section></div></main></body></html>
|
||||
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="This module implements the relaying protocol used by the `server` and `client`."><title>iroh_relay::protos::relay - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../static.files/rustdoc-dbdb5eec.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="iroh_relay" data-themes="" data-resource-suffix="" data-rustdoc-version="1.85.0-nightly (d10a6823f 2024-11-29)" data-channel="nightly" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../../static.files/storage-59e33391.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../iroh_relay/index.html">iroh_<wbr>relay</a><span class="version">0.30.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module relay</a></h2><h3><a href="#constants">Module Items</a></h3><ul class="block"><li><a href="#constants" title="Constants">Constants</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="../index.html">In iroh_<wbr>relay::<wbr>protos</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../../index.html">iroh_relay</a>::<wbr><a href="../index.html">protos</a></span><h1>Module <span>relay</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../src/iroh_relay/protos/relay.rs.html#1-840">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>This module implements the relaying protocol used by the <code>server</code> and <code>client</code>.</p>
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="This module implements the relaying protocol used by the `server` and `client`."><title>iroh_relay::protos::relay - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../../static.files/rustdoc-dbdb5eec.css"><meta name="rustdoc-vars" data-root-path="../../../" data-static-root-path="../../../static.files/" data-current-crate="iroh_relay" data-themes="" data-resource-suffix="" data-rustdoc-version="1.85.0-nightly (d10a6823f 2024-11-29)" data-channel="nightly" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../../static.files/storage-59e33391.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../../iroh_relay/index.html">iroh_<wbr>relay</a><span class="version">0.30.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module relay</a></h2><h3><a href="#constants">Module Items</a></h3><ul class="block"><li><a href="#constants" title="Constants">Constants</a></li></ul></section><div id="rustdoc-modnav"><h2><a href="../index.html">In iroh_<wbr>relay::<wbr>protos</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../../index.html">iroh_relay</a>::<wbr><a href="../index.html">protos</a></span><h1>Module <span>relay</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../../src/iroh_relay/protos/relay.rs.html#1-844">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>This module implements the relaying protocol used by the <code>server</code> and <code>client</code>.</p>
|
||||
<p>Protocol flow:</p>
|
||||
<p>Login:</p>
|
||||
<ul>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A fully-fledged iroh-relay server over HTTP or HTTPS."><title>iroh_relay::server - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-dbdb5eec.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="iroh_relay" data-themes="" data-resource-suffix="" data-rustdoc-version="1.85.0-nightly (d10a6823f 2024-11-29)" data-channel="nightly" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../iroh_relay/index.html">iroh_<wbr>relay</a><span class="version">0.30.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module server</a></h2><h3><a href="#modules">Module Items</a></h3><ul class="block"><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#constants" title="Constants">Constants</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate iroh_<wbr>relay</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">iroh_relay</a></span><h1>Module <span>server</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/iroh_relay/server.rs.html#1-1143">Source</a> </span></div><span class="item-info"><div class="stab portability">Available on <strong>crate feature <code>server</code></strong> only.</div></span><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A fully-fledged iroh-relay server over HTTP or HTTPS.</p>
|
||||
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="A fully-fledged iroh-relay server over HTTP or HTTPS."><title>iroh_relay::server - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-dbdb5eec.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="iroh_relay" data-themes="" data-resource-suffix="" data-rustdoc-version="1.85.0-nightly (d10a6823f 2024-11-29)" data-channel="nightly" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../../static.files/storage-59e33391.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../../static.files/favicon-044be391.svg"></head><body class="rustdoc mod"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../iroh_relay/index.html">iroh_<wbr>relay</a><span class="version">0.30.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module server</a></h2><h3><a href="#modules">Module Items</a></h3><ul class="block"><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#structs" title="Structs">Structs</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#constants" title="Constants">Constants</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="../index.html">In crate iroh_<wbr>relay</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="../index.html">iroh_relay</a></span><h1>Module <span>server</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../../src/iroh_relay/server.rs.html#1-1110">Source</a> </span></div><span class="item-info"><div class="stab portability">Available on <strong>crate feature <code>server</code></strong> only.</div></span><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>A fully-fledged iroh-relay server over HTTP or HTTPS.</p>
|
||||
<p>This module provides an API to run a full fledged iroh-relay server. It is primarily
|
||||
used by the <code>iroh-relay</code> binary in this crate. It can be used to run a relay server in
|
||||
other locations however.</p>
|
||||
@@ -13,4 +13,4 @@ task. Some tasks additionally have a method to do graceful shutdown.</p>
|
||||
<li>HTTPS <code>/generate_204</code>: Used for net_report probes.</li>
|
||||
<li>STUN: UDP port for STUN requests/responses.</li>
|
||||
</ul>
|
||||
</div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="testing/index.html" title="mod iroh_relay::server::testing">testing</a><wbr><span class="stab portability" title="Available on crate feature `test-utils` only"><code>test-utils</code></span></div><div class="desc docblock-short">Exposes functions to quickly configure a server suitable for testing.</div></li></ul><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.ClientConnRateLimit.html" title="struct iroh_relay::server::ClientConnRateLimit">Client<wbr>Conn<wbr>Rate<wbr>Limit</a></div><div class="desc docblock-short">Per-client rate limit configuration.</div></li><li><div class="item-name"><a class="struct" href="struct.Limits.html" title="struct iroh_relay::server::Limits">Limits</a></div><div class="desc docblock-short">Rate limits.</div></li><li><div class="item-name"><a class="struct" href="struct.Metrics.html" title="struct iroh_relay::server::Metrics">Metrics</a></div><div class="desc docblock-short">Metrics tracked for the relay server</div></li><li><div class="item-name"><a class="struct" href="struct.QuicConfig.html" title="struct iroh_relay::server::QuicConfig">Quic<wbr>Config</a></div><div class="desc docblock-short">Configuration for the QUIC server.</div></li><li><div class="item-name"><a class="struct" href="struct.RelayConfig.html" title="struct iroh_relay::server::RelayConfig">Relay<wbr>Config</a></div><div class="desc docblock-short">Configuration for the Relay HTTP and HTTPS server.</div></li><li><div class="item-name"><a class="struct" href="struct.ReloadingResolver.html" title="struct iroh_relay::server::ReloadingResolver">Reloading<wbr>Resolver</a></div><div class="desc docblock-short">A Certificate resolver that reloads the certificate every interval</div></li><li><div class="item-name"><a class="struct" href="struct.Server.html" title="struct iroh_relay::server::Server">Server</a></div><div class="desc docblock-short">A running Relay + STUN server.</div></li><li><div class="item-name"><a class="struct" href="struct.ServerConfig.html" title="struct iroh_relay::server::ServerConfig">Server<wbr>Config</a></div><div class="desc docblock-short">Configuration for the full Relay & STUN server.</div></li><li><div class="item-name"><a class="struct" href="struct.StunConfig.html" title="struct iroh_relay::server::StunConfig">Stun<wbr>Config</a></div><div class="desc docblock-short">Configuration for the STUN server.</div></li><li><div class="item-name"><a class="struct" href="struct.StunMetrics.html" title="struct iroh_relay::server::StunMetrics">Stun<wbr>Metrics</a></div><div class="desc docblock-short">StunMetrics tracked for the DERPER</div></li><li><div class="item-name"><a class="struct" href="struct.TlsConfig.html" title="struct iroh_relay::server::TlsConfig">TlsConfig</a></div><div class="desc docblock-short">TLS configuration for Relay server.</div></li></ul><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.CertConfig.html" title="enum iroh_relay::server::CertConfig">Cert<wbr>Config</a></div><div class="desc docblock-short">TLS certificate configuration.</div></li><li><div class="item-name"><a class="enum" href="enum.MaybeTlsStreamServer.html" title="enum iroh_relay::server::MaybeTlsStreamServer">Maybe<wbr>TlsStream<wbr>Server</a></div><div class="desc docblock-short">The main underlying IO stream type used for the relay server.</div></li></ul><h2 id="constants" class="section-header">Constants<a href="#constants" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="constant" href="constant.DEFAULT_CERT_RELOAD_INTERVAL.html" title="constant iroh_relay::server::DEFAULT_CERT_RELOAD_INTERVAL">DEFAULT_<wbr>CERT_<wbr>RELOAD_<wbr>INTERVAL</a></div><div class="desc docblock-short">The default certificate reload interval.</div></li></ul></section></div></main></body></html>
|
||||
</div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="mod" href="testing/index.html" title="mod iroh_relay::server::testing">testing</a><wbr><span class="stab portability" title="Available on crate feature `test-utils` only"><code>test-utils</code></span></div><div class="desc docblock-short">Exposes functions to quickly configure a server suitable for testing.</div></li></ul><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="struct" href="struct.ClientConnRateLimit.html" title="struct iroh_relay::server::ClientConnRateLimit">Client<wbr>Conn<wbr>Rate<wbr>Limit</a></div><div class="desc docblock-short">Per-client rate limit configuration.</div></li><li><div class="item-name"><a class="struct" href="struct.Limits.html" title="struct iroh_relay::server::Limits">Limits</a></div><div class="desc docblock-short">Rate limits.</div></li><li><div class="item-name"><a class="struct" href="struct.Metrics.html" title="struct iroh_relay::server::Metrics">Metrics</a></div><div class="desc docblock-short">Metrics tracked for the relay server</div></li><li><div class="item-name"><a class="struct" href="struct.QuicConfig.html" title="struct iroh_relay::server::QuicConfig">Quic<wbr>Config</a></div><div class="desc docblock-short">Configuration for the QUIC server.</div></li><li><div class="item-name"><a class="struct" href="struct.RelayConfig.html" title="struct iroh_relay::server::RelayConfig">Relay<wbr>Config</a></div><div class="desc docblock-short">Configuration for the Relay HTTP and HTTPS server.</div></li><li><div class="item-name"><a class="struct" href="struct.ReloadingResolver.html" title="struct iroh_relay::server::ReloadingResolver">Reloading<wbr>Resolver</a></div><div class="desc docblock-short">A Certificate resolver that reloads the certificate every interval</div></li><li><div class="item-name"><a class="struct" href="struct.Server.html" title="struct iroh_relay::server::Server">Server</a></div><div class="desc docblock-short">A running Relay + STUN server.</div></li><li><div class="item-name"><a class="struct" href="struct.ServerConfig.html" title="struct iroh_relay::server::ServerConfig">Server<wbr>Config</a></div><div class="desc docblock-short">Configuration for the full Relay & STUN server.</div></li><li><div class="item-name"><a class="struct" href="struct.StunConfig.html" title="struct iroh_relay::server::StunConfig">Stun<wbr>Config</a></div><div class="desc docblock-short">Configuration for the STUN server.</div></li><li><div class="item-name"><a class="struct" href="struct.StunMetrics.html" title="struct iroh_relay::server::StunMetrics">Stun<wbr>Metrics</a></div><div class="desc docblock-short">StunMetrics tracked for the relay server</div></li><li><div class="item-name"><a class="struct" href="struct.TlsConfig.html" title="struct iroh_relay::server::TlsConfig">TlsConfig</a></div><div class="desc docblock-short">TLS configuration for Relay server.</div></li></ul><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="enum" href="enum.CertConfig.html" title="enum iroh_relay::server::CertConfig">Cert<wbr>Config</a></div><div class="desc docblock-short">TLS certificate configuration.</div></li><li><div class="item-name"><a class="enum" href="enum.MaybeTlsStreamServer.html" title="enum iroh_relay::server::MaybeTlsStreamServer">Maybe<wbr>TlsStream<wbr>Server</a></div><div class="desc docblock-short">The main underlying IO stream type used for the relay server.</div></li></ul><h2 id="constants" class="section-header">Constants<a href="#constants" class="anchor">§</a></h2><ul class="item-table"><li><div class="item-name"><a class="constant" href="constant.DEFAULT_CERT_RELOAD_INTERVAL.html" title="constant iroh_relay::server::DEFAULT_CERT_RELOAD_INTERVAL">DEFAULT_<wbr>CERT_<wbr>RELOAD_<wbr>INTERVAL</a></div><div class="desc docblock-short">The default certificate reload interval.</div></li></ul></section></div></main></body></html>
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1 +1 @@
|
||||
window.SIDEBAR_ITEMS = {"enum":["ReceivedMessage"],"mod":["client","defaults","http","protos","quic","server"],"struct":["RelayConn","RelayMap","RelayNode","RelayQuicConfig"]};
|
||||
window.SIDEBAR_ITEMS = {"mod":["client","defaults","http","protos","quic","server"],"struct":["RelayMap","RelayNode","RelayQuicConfig"]};
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -3518,8 +3518,8 @@
|
||||
<span class="kw">let </span>eps = ep.bound_sockets();
|
||||
<span class="macro">info!</span>(me = %ep.node_id().fmt_short(), ipv4=%eps.<span class="number">0</span>, ipv6=<span class="question-mark">?</span>eps.<span class="number">1</span>, <span class="string">"server listening on"</span>);
|
||||
<span class="kw">for </span>i <span class="kw">in </span><span class="number">0</span>..n_clients {
|
||||
<span class="kw">let </span>now = Instant::now();
|
||||
<span class="macro">println!</span>(<span class="string">"[server] round {}"</span>, i + <span class="number">1</span>);
|
||||
<span class="kw">let </span>round_start = Instant::now();
|
||||
<span class="macro">info!</span>(<span class="string">"[server] round {i}"</span>);
|
||||
<span class="kw">let </span>incoming = ep.accept().<span class="kw">await</span>.unwrap();
|
||||
<span class="kw">let </span>conn = incoming.<span class="kw">await</span>.unwrap();
|
||||
<span class="kw">let </span>peer_id = get_remote_node_id(<span class="kw-2">&</span>conn).unwrap();
|
||||
@@ -3534,7 +3534,7 @@
|
||||
send.stopped().<span class="kw">await</span>.unwrap();
|
||||
recv.read_to_end(<span class="number">0</span>).<span class="kw">await</span>.unwrap();
|
||||
<span class="macro">info!</span>(%i, peer = %peer_id.fmt_short(), <span class="string">"finished"</span>);
|
||||
<span class="macro">println!</span>(<span class="string">"[server] round {} done in {:?}"</span>, i + <span class="number">1</span>, now.elapsed());
|
||||
<span class="macro">info!</span>(<span class="string">"[server] round {i} done in {:?}"</span>, round_start.elapsed());
|
||||
}
|
||||
}
|
||||
.instrument(<span class="macro">error_span!</span>(<span class="string">"server"</span>)),
|
||||
@@ -3546,8 +3546,8 @@
|
||||
});
|
||||
|
||||
<span class="kw">for </span>i <span class="kw">in </span><span class="number">0</span>..n_clients {
|
||||
<span class="kw">let </span>now = Instant::now();
|
||||
<span class="macro">println!</span>(<span class="string">"[client] round {}"</span>, i + <span class="number">1</span>);
|
||||
<span class="kw">let </span>round_start = Instant::now();
|
||||
<span class="macro">info!</span>(<span class="string">"[client] round {}"</span>, i);
|
||||
<span class="kw">let </span>relay_map = relay_map.clone();
|
||||
<span class="kw">let </span>client_secret_key = SecretKey::generate(<span class="kw-2">&mut </span>rng);
|
||||
<span class="kw">let </span>relay_url = relay_url.clone();
|
||||
@@ -3584,7 +3584,7 @@
|
||||
}
|
||||
.instrument(<span class="macro">error_span!</span>(<span class="string">"client"</span>, %i))
|
||||
.<span class="kw">await</span>;
|
||||
<span class="macro">println!</span>(<span class="string">"[client] round {} done in {:?}"</span>, i + <span class="number">1</span>, now.elapsed());
|
||||
<span class="macro">info!</span>(<span class="string">"[client] round {i} done in {:?}"</span>, round_start.elapsed());
|
||||
}
|
||||
|
||||
server.<span class="kw">await</span>.unwrap();
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -101,7 +101,7 @@
|
||||
<span class="self">Self</span>::default()
|
||||
}
|
||||
|
||||
<span class="doccomment">/// Clears the value
|
||||
<span class="doccomment">/// Sets the future to None again.
|
||||
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn </span>set_none(<span class="kw-2">mut </span><span class="self">self</span>: Pin<<span class="kw-2">&mut </span><span class="self">Self</span>>) {
|
||||
<span class="self">self</span>.as_mut().project_replace(<span class="self">Self</span>::None);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -362,375 +362,110 @@
|
||||
<a href="#361" id="361">361</a>
|
||||
<a href="#362" id="362">362</a>
|
||||
<a href="#363" id="363">363</a>
|
||||
<a href="#364" id="364">364</a>
|
||||
<a href="#365" id="365">365</a>
|
||||
<a href="#366" id="366">366</a>
|
||||
<a href="#367" id="367">367</a>
|
||||
<a href="#368" id="368">368</a>
|
||||
<a href="#369" id="369">369</a>
|
||||
<a href="#370" id="370">370</a>
|
||||
<a href="#371" id="371">371</a>
|
||||
<a href="#372" id="372">372</a>
|
||||
<a href="#373" id="373">373</a>
|
||||
<a href="#374" id="374">374</a>
|
||||
<a href="#375" id="375">375</a>
|
||||
<a href="#376" id="376">376</a>
|
||||
<a href="#377" id="377">377</a>
|
||||
<a href="#378" id="378">378</a>
|
||||
<a href="#379" id="379">379</a>
|
||||
<a href="#380" id="380">380</a>
|
||||
<a href="#381" id="381">381</a>
|
||||
<a href="#382" id="382">382</a>
|
||||
<a href="#383" id="383">383</a>
|
||||
<a href="#384" id="384">384</a>
|
||||
<a href="#385" id="385">385</a>
|
||||
<a href="#386" id="386">386</a>
|
||||
<a href="#387" id="387">387</a>
|
||||
<a href="#388" id="388">388</a>
|
||||
<a href="#389" id="389">389</a>
|
||||
<a href="#390" id="390">390</a>
|
||||
<a href="#391" id="391">391</a>
|
||||
<a href="#392" id="392">392</a>
|
||||
<a href="#393" id="393">393</a>
|
||||
<a href="#394" id="394">394</a>
|
||||
<a href="#395" id="395">395</a>
|
||||
<a href="#396" id="396">396</a>
|
||||
<a href="#397" id="397">397</a>
|
||||
<a href="#398" id="398">398</a>
|
||||
<a href="#399" id="399">399</a>
|
||||
<a href="#400" id="400">400</a>
|
||||
<a href="#401" id="401">401</a>
|
||||
<a href="#402" id="402">402</a>
|
||||
<a href="#403" id="403">403</a>
|
||||
<a href="#404" id="404">404</a>
|
||||
<a href="#405" id="405">405</a>
|
||||
<a href="#406" id="406">406</a>
|
||||
<a href="#407" id="407">407</a>
|
||||
<a href="#408" id="408">408</a>
|
||||
<a href="#409" id="409">409</a>
|
||||
<a href="#410" id="410">410</a>
|
||||
<a href="#411" id="411">411</a>
|
||||
<a href="#412" id="412">412</a>
|
||||
<a href="#413" id="413">413</a>
|
||||
<a href="#414" id="414">414</a>
|
||||
<a href="#415" id="415">415</a>
|
||||
<a href="#416" id="416">416</a>
|
||||
<a href="#417" id="417">417</a>
|
||||
<a href="#418" id="418">418</a>
|
||||
<a href="#419" id="419">419</a>
|
||||
<a href="#420" id="420">420</a>
|
||||
<a href="#421" id="421">421</a>
|
||||
<a href="#422" id="422">422</a>
|
||||
<a href="#423" id="423">423</a>
|
||||
<a href="#424" id="424">424</a>
|
||||
<a href="#425" id="425">425</a>
|
||||
<a href="#426" id="426">426</a>
|
||||
<a href="#427" id="427">427</a>
|
||||
<a href="#428" id="428">428</a>
|
||||
<a href="#429" id="429">429</a>
|
||||
<a href="#430" id="430">430</a>
|
||||
<a href="#431" id="431">431</a>
|
||||
<a href="#432" id="432">432</a>
|
||||
<a href="#433" id="433">433</a>
|
||||
<a href="#434" id="434">434</a>
|
||||
<a href="#435" id="435">435</a>
|
||||
<a href="#436" id="436">436</a>
|
||||
<a href="#437" id="437">437</a>
|
||||
<a href="#438" id="438">438</a>
|
||||
<a href="#439" id="439">439</a>
|
||||
<a href="#440" id="440">440</a>
|
||||
<a href="#441" id="441">441</a>
|
||||
<a href="#442" id="442">442</a>
|
||||
<a href="#443" id="443">443</a>
|
||||
<a href="#444" id="444">444</a>
|
||||
<a href="#445" id="445">445</a>
|
||||
<a href="#446" id="446">446</a>
|
||||
<a href="#447" id="447">447</a>
|
||||
<a href="#448" id="448">448</a>
|
||||
<a href="#449" id="449">449</a>
|
||||
<a href="#450" id="450">450</a>
|
||||
<a href="#451" id="451">451</a>
|
||||
<a href="#452" id="452">452</a>
|
||||
<a href="#453" id="453">453</a>
|
||||
<a href="#454" id="454">454</a>
|
||||
<a href="#455" id="455">455</a>
|
||||
<a href="#456" id="456">456</a>
|
||||
<a href="#457" id="457">457</a>
|
||||
<a href="#458" id="458">458</a>
|
||||
<a href="#459" id="459">459</a>
|
||||
<a href="#460" id="460">460</a>
|
||||
<a href="#461" id="461">461</a>
|
||||
<a href="#462" id="462">462</a>
|
||||
<a href="#463" id="463">463</a>
|
||||
<a href="#464" id="464">464</a>
|
||||
<a href="#465" id="465">465</a>
|
||||
<a href="#466" id="466">466</a></pre></div><pre class="rust"><code><span class="doccomment">//! Manages client-side connections to the relay server.
|
||||
<a href="#364" id="364">364</a></pre></div><pre class="rust"><code><span class="doccomment">//! Manages client-side connections to the relay server.
|
||||
//!
|
||||
//! based on tailscale/derp/derp_client.go
|
||||
|
||||
</span><span class="kw">use </span>std::{
|
||||
net::SocketAddr,
|
||||
io,
|
||||
pin::Pin,
|
||||
sync::Arc,
|
||||
task::{Context, Poll},
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
<span class="kw">use </span>anyhow::{bail, ensure, <span class="prelude-ty">Result</span>};
|
||||
<span class="kw">use </span>anyhow::{bail, <span class="prelude-ty">Result</span>};
|
||||
<span class="kw">use </span>bytes::Bytes;
|
||||
<span class="kw">use </span>futures_lite::Stream;
|
||||
<span class="kw">use </span>futures_sink::Sink;
|
||||
<span class="kw">use </span>futures_util::{
|
||||
stream::{SplitSink, SplitStream},
|
||||
SinkExt,
|
||||
};
|
||||
<span class="kw">use </span>futures_util::Sink;
|
||||
<span class="kw">use </span>iroh_base::{NodeId, SecretKey};
|
||||
<span class="kw">use </span>tokio::sync::mpsc;
|
||||
<span class="kw">use </span>tokio_tungstenite_wasm::WebSocketStream;
|
||||
<span class="kw">use </span>tokio_util::{
|
||||
codec::{FramedRead, FramedWrite},
|
||||
task::AbortOnDropHandle,
|
||||
};
|
||||
<span class="kw">use </span>tracing::{debug, info_span, trace, Instrument};
|
||||
<span class="kw">use </span>tokio_util::codec::Framed;
|
||||
<span class="kw">use </span>tracing::debug;
|
||||
|
||||
<span class="kw">use </span><span class="kw">super</span>::KeyCache;
|
||||
<span class="kw">use crate</span>::{
|
||||
client::streams::{MaybeTlsStreamReader, MaybeTlsStreamWriter},
|
||||
protos::relay::{
|
||||
write_frame, ClientInfo, Frame, RelayCodec, MAX_PACKET_SIZE, PER_CLIENT_SEND_QUEUE_DEPTH,
|
||||
PROTOCOL_VERSION,
|
||||
},
|
||||
client::streams::MaybeTlsStreamChained,
|
||||
protos::relay::{ClientInfo, Frame, RelayCodec, MAX_PACKET_SIZE, PROTOCOL_VERSION},
|
||||
};
|
||||
|
||||
<span class="doccomment">/// The Builder returns a [`Conn`] and a [`ConnMessageStream`] and
|
||||
/// runs a [`ConnWriterTasks`] in the background.
|
||||
</span><span class="kw">pub struct </span>ConnBuilder {
|
||||
secret_key: SecretKey,
|
||||
reader: ConnFrameStream,
|
||||
writer: ConnWriter,
|
||||
local_addr: <span class="prelude-ty">Option</span><SocketAddr>,
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>ConnBuilder {
|
||||
<span class="kw">pub fn </span>new(
|
||||
secret_key: SecretKey,
|
||||
local_addr: <span class="prelude-ty">Option</span><SocketAddr>,
|
||||
reader: ConnFrameStream,
|
||||
writer: ConnWriter,
|
||||
) -> <span class="self">Self </span>{
|
||||
<span class="self">Self </span>{
|
||||
secret_key,
|
||||
reader,
|
||||
writer,
|
||||
local_addr,
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">async fn </span>server_handshake(<span class="kw-2">&mut </span><span class="self">self</span>) -> <span class="prelude-ty">Result</span><()> {
|
||||
<span class="macro">debug!</span>(<span class="string">"server_handshake: started"</span>);
|
||||
<span class="kw">let </span>client_info = ClientInfo {
|
||||
version: PROTOCOL_VERSION,
|
||||
};
|
||||
<span class="macro">debug!</span>(<span class="string">"server_handshake: sending client_key: {:?}"</span>, <span class="kw-2">&</span>client_info);
|
||||
<span class="kw">crate</span>::protos::relay::send_client_key(<span class="kw-2">&mut </span><span class="self">self</span>.writer, <span class="kw-2">&</span><span class="self">self</span>.secret_key, <span class="kw-2">&</span>client_info)
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="macro">debug!</span>(<span class="string">"server_handshake: done"</span>);
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}
|
||||
|
||||
<span class="kw">pub async fn </span>build(<span class="kw-2">mut </span><span class="self">self</span>) -> <span class="prelude-ty">Result</span><(Conn, ConnMessageStream)> {
|
||||
<span class="comment">// exchange information with the server
|
||||
</span><span class="self">self</span>.server_handshake().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="comment">// create task to handle writing to the server
|
||||
</span><span class="kw">let </span>(writer_sender, writer_recv) = mpsc::channel(PER_CLIENT_SEND_QUEUE_DEPTH);
|
||||
<span class="kw">let </span>writer_task = tokio::task::spawn(
|
||||
ConnWriterTasks {
|
||||
writer: <span class="self">self</span>.writer,
|
||||
recv_msgs: writer_recv,
|
||||
}
|
||||
.run()
|
||||
.instrument(<span class="macro">info_span!</span>(<span class="string">"conn.writer"</span>)),
|
||||
);
|
||||
|
||||
<span class="kw">let </span>conn = Conn {
|
||||
inner: Arc::new(ConnTasks {
|
||||
local_addr: <span class="self">self</span>.local_addr,
|
||||
writer_channel: writer_sender,
|
||||
writer_task: AbortOnDropHandle::new(writer_task),
|
||||
}),
|
||||
};
|
||||
<span class="kw">let </span>stream = ConnMessageStream { inner: <span class="self">self</span>.reader };
|
||||
<span class="prelude-val">Ok</span>((conn, stream))
|
||||
}
|
||||
<span class="doccomment">/// Error for sending messages to the relay server.
|
||||
</span><span class="attr">#[derive(Debug, thiserror::Error)]
|
||||
</span><span class="kw">pub enum </span>ConnSendError {
|
||||
<span class="doccomment">/// An IO error.
|
||||
</span><span class="attr">#[error(<span class="string">"IO error"</span>)]
|
||||
</span>Io(<span class="attr">#[from] </span>io::Error),
|
||||
<span class="doccomment">/// A protocol error.
|
||||
</span><span class="attr">#[error(<span class="string">"Protocol error"</span>)]
|
||||
</span>Protocol(<span class="kw-2">&</span><span class="lifetime">'static </span>str),
|
||||
}
|
||||
|
||||
<span class="doccomment">/// A connection to a relay server.
|
||||
///
|
||||
/// Cheaply clonable.
|
||||
/// Call `close` to shut down the write loop and read functionality.
|
||||
</span><span class="attr">#[derive(Debug, Clone)]
|
||||
</span><span class="kw">pub struct </span>Conn {
|
||||
inner: Arc<ConnTasks>,
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>PartialEq <span class="kw">for </span>Conn {
|
||||
<span class="kw">fn </span>eq(<span class="kw-2">&</span><span class="self">self</span>, other: <span class="kw-2">&</span><span class="self">Self</span>) -> bool {
|
||||
Arc::ptr_eq(<span class="kw-2">&</span><span class="self">self</span>.inner, <span class="kw-2">&</span>other.inner)
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>Eq <span class="kw">for </span>Conn {}
|
||||
|
||||
<span class="attr">#[derive(derive_more::Debug)]
|
||||
</span><span class="kw">pub struct </span>ConnTasks {
|
||||
<span class="doccomment">/// Our local address, if known.
|
||||
///
|
||||
/// Is `None` in tests or when using websockets (because we don't control connection
|
||||
/// establishment in browsers).
|
||||
</span>local_addr: <span class="prelude-ty">Option</span><SocketAddr>,
|
||||
<span class="doccomment">/// Channel on which to communicate to the server.
|
||||
///
|
||||
/// The associated [`mpsc::Receiver`] will close if there is ever an error writing to
|
||||
/// the server.
|
||||
</span>writer_channel: mpsc::Sender<ConnWriterMessage>,
|
||||
<span class="doccomment">/// JoinHandle for the [`ConnWriter`] task
|
||||
</span>writer_task: AbortOnDropHandle<<span class="prelude-ty">Result</span><()>>,
|
||||
/// This holds a connection to a relay server. It is:
|
||||
///
|
||||
/// - A [`Stream`] for [`ReceivedMessage`] to receive from the server.
|
||||
/// - A [`Sink`] for [`SendMessage`] to send to the server.
|
||||
/// - A [`Sink`] for [`Frame`] to send to the server.
|
||||
///
|
||||
/// The [`Frame`] sink is a more internal interface, it allows performing the handshake.
|
||||
/// The [`SendMessage`] and [`ReceivedMessage`] are safer wrappers enforcing some protocol
|
||||
/// invariants.
|
||||
</span><span class="attr">#[derive(derive_more::Debug)]
|
||||
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">enum </span>Conn {
|
||||
Relay {
|
||||
<span class="attr">#[debug(<span class="string">"Framed<MaybeTlsStreamChained, RelayCodec>"</span>)]
|
||||
</span>conn: Framed<MaybeTlsStreamChained, RelayCodec>,
|
||||
},
|
||||
Ws {
|
||||
<span class="attr">#[debug(<span class="string">"WebSocketStream"</span>)]
|
||||
</span>conn: WebSocketStream,
|
||||
key_cache: KeyCache,
|
||||
},
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>Conn {
|
||||
<span class="doccomment">/// Sends a packet to the node identified by `dstkey`
|
||||
///
|
||||
/// Errors if the packet is larger than [`MAX_PACKET_SIZE`]
|
||||
</span><span class="kw">pub async fn </span>send(<span class="kw-2">&</span><span class="self">self</span>, dst: NodeId, packet: Bytes) -> <span class="prelude-ty">Result</span><()> {
|
||||
<span class="macro">trace!</span>(dst = dst.fmt_short(), len = packet.len(), <span class="string">"[RELAY] send"</span>);
|
||||
<span class="doccomment">/// Constructs a new websocket connection, including the initial server handshake.
|
||||
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">async fn </span>new_ws(
|
||||
conn: WebSocketStream,
|
||||
key_cache: KeyCache,
|
||||
secret_key: <span class="kw-2">&</span>SecretKey,
|
||||
) -> <span class="prelude-ty">Result</span><<span class="self">Self</span>> {
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>conn = <span class="self">Self</span>::Ws { conn, key_cache };
|
||||
|
||||
<span class="self">self</span>.inner
|
||||
.writer_channel
|
||||
.send(ConnWriterMessage::Packet((dst, packet)))
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
<span class="comment">// exchange information with the server
|
||||
</span>server_handshake(<span class="kw-2">&mut </span>conn, secret_key).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="prelude-val">Ok</span>(conn)
|
||||
}
|
||||
|
||||
<span class="doccomment">/// Send a ping with 8 bytes of random data.
|
||||
</span><span class="kw">pub async fn </span>send_ping(<span class="kw-2">&</span><span class="self">self</span>, data: [u8; <span class="number">8</span>]) -> <span class="prelude-ty">Result</span><()> {
|
||||
<span class="self">self</span>.inner
|
||||
.writer_channel
|
||||
.send(ConnWriterMessage::Ping(data))
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}
|
||||
<span class="doccomment">/// Constructs a new websocket connection, including the initial server handshake.
|
||||
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">async fn </span>new_relay(
|
||||
conn: MaybeTlsStreamChained,
|
||||
key_cache: KeyCache,
|
||||
secret_key: <span class="kw-2">&</span>SecretKey,
|
||||
) -> <span class="prelude-ty">Result</span><<span class="self">Self</span>> {
|
||||
<span class="kw">let </span>conn = Framed::new(conn, RelayCodec::new(key_cache));
|
||||
|
||||
<span class="doccomment">/// Respond to a ping request. The `data` field should be filled
|
||||
/// by the 8 bytes of random data send by the ping.
|
||||
</span><span class="kw">pub async fn </span>send_pong(<span class="kw-2">&</span><span class="self">self</span>, data: [u8; <span class="number">8</span>]) -> <span class="prelude-ty">Result</span><()> {
|
||||
<span class="self">self</span>.inner
|
||||
.writer_channel
|
||||
.send(ConnWriterMessage::Pong(data))
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>conn = <span class="self">Self</span>::Relay { conn };
|
||||
|
||||
<span class="doccomment">/// Sends a packet that tells the server whether this
|
||||
/// connection is to the user's preferred server. This is only
|
||||
/// used in the server for stats.
|
||||
</span><span class="kw">pub async fn </span>note_preferred(<span class="kw-2">&</span><span class="self">self</span>, preferred: bool) -> <span class="prelude-ty">Result</span><()> {
|
||||
<span class="self">self</span>.inner
|
||||
.writer_channel
|
||||
.send(ConnWriterMessage::NotePreferred(preferred))
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}
|
||||
<span class="comment">// exchange information with the server
|
||||
</span>server_handshake(<span class="kw-2">&mut </span>conn, secret_key).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="doccomment">/// The local address that the [`Conn`] is listening on.
|
||||
///
|
||||
/// `None`, when run in a testing environment or when using websockets.
|
||||
</span><span class="kw">pub fn </span>local_addr(<span class="kw-2">&</span><span class="self">self</span>) -> <span class="prelude-ty">Option</span><SocketAddr> {
|
||||
<span class="self">self</span>.inner.local_addr
|
||||
}
|
||||
|
||||
<span class="doccomment">/// Whether or not this [`Conn`] is closed.
|
||||
///
|
||||
/// The [`Conn`] is considered closed if the write side of the connection is no longer running.
|
||||
</span><span class="kw">pub fn </span>is_closed(<span class="kw-2">&</span><span class="self">self</span>) -> bool {
|
||||
<span class="self">self</span>.inner.writer_task.is_finished()
|
||||
}
|
||||
|
||||
<span class="doccomment">/// Close the connection
|
||||
///
|
||||
/// Shuts down the write loop directly and marks the connection as closed. The [`Conn`] will
|
||||
/// check if the it is closed before attempting to read from it.
|
||||
</span><span class="kw">pub async fn </span>close(<span class="kw-2">&</span><span class="self">self</span>) {
|
||||
<span class="kw">if </span><span class="self">self</span>.inner.writer_task.is_finished() {
|
||||
<span class="kw">return</span>;
|
||||
}
|
||||
|
||||
<span class="self">self</span>.inner
|
||||
.writer_channel
|
||||
.send(ConnWriterMessage::Shutdown)
|
||||
.<span class="kw">await
|
||||
</span>.ok();
|
||||
<span class="prelude-val">Ok</span>(conn)
|
||||
}
|
||||
}
|
||||
|
||||
<span class="doccomment">/// The kinds of messages we can send to the [`Server`](crate::server::Server)
|
||||
</span><span class="attr">#[derive(Debug)]
|
||||
</span><span class="kw">enum </span>ConnWriterMessage {
|
||||
<span class="doccomment">/// Send a packet (addressed to the [`NodeId`]) to the server
|
||||
</span>Packet((NodeId, Bytes)),
|
||||
<span class="doccomment">/// Send a pong to the server
|
||||
</span>Pong([u8; <span class="number">8</span>]),
|
||||
<span class="doccomment">/// Send a ping to the server
|
||||
</span>Ping([u8; <span class="number">8</span>]),
|
||||
<span class="doccomment">/// Tell the server whether or not this client is the user's preferred client
|
||||
</span>NotePreferred(bool),
|
||||
<span class="doccomment">/// Shutdown the writer
|
||||
</span>Shutdown,
|
||||
}
|
||||
<span class="doccomment">/// Sends the server handshake message.
|
||||
</span><span class="kw">async fn </span>server_handshake(writer: <span class="kw-2">&mut </span>Conn, secret_key: <span class="kw-2">&</span>SecretKey) -> <span class="prelude-ty">Result</span><()> {
|
||||
<span class="macro">debug!</span>(<span class="string">"server_handshake: started"</span>);
|
||||
<span class="kw">let </span>client_info = ClientInfo {
|
||||
version: PROTOCOL_VERSION,
|
||||
};
|
||||
<span class="macro">debug!</span>(<span class="string">"server_handshake: sending client_key: {:?}"</span>, <span class="kw-2">&</span>client_info);
|
||||
<span class="kw">crate</span>::protos::relay::send_client_key(<span class="kw-2">&mut *</span>writer, secret_key, <span class="kw-2">&</span>client_info).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="doccomment">/// Call [`ConnWriterTasks::run`] to listen for messages to send to the connection.
|
||||
/// Should be used by the [`Conn`]
|
||||
///
|
||||
/// Shutsdown when you send a [`ConnWriterMessage::Shutdown`], or if there is an error writing to
|
||||
/// the server.
|
||||
</span><span class="kw">struct </span>ConnWriterTasks {
|
||||
recv_msgs: mpsc::Receiver<ConnWriterMessage>,
|
||||
writer: ConnWriter,
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>ConnWriterTasks {
|
||||
<span class="kw">async fn </span>run(<span class="kw-2">mut </span><span class="self">self</span>) -> <span class="prelude-ty">Result</span><()> {
|
||||
<span class="kw">while let </span><span class="prelude-val">Some</span>(msg) = <span class="self">self</span>.recv_msgs.recv().<span class="kw">await </span>{
|
||||
<span class="kw">match </span>msg {
|
||||
ConnWriterMessage::Packet((key, bytes)) => {
|
||||
send_packet(<span class="kw-2">&mut </span><span class="self">self</span>.writer, key, bytes).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
}
|
||||
ConnWriterMessage::Pong(data) => {
|
||||
write_frame(<span class="kw-2">&mut </span><span class="self">self</span>.writer, Frame::Pong { data }, <span class="prelude-val">None</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="self">self</span>.writer.flush().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
}
|
||||
ConnWriterMessage::Ping(data) => {
|
||||
write_frame(<span class="kw-2">&mut </span><span class="self">self</span>.writer, Frame::Ping { data }, <span class="prelude-val">None</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="self">self</span>.writer.flush().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
}
|
||||
ConnWriterMessage::NotePreferred(preferred) => {
|
||||
write_frame(<span class="kw-2">&mut </span><span class="self">self</span>.writer, Frame::NotePreferred { preferred }, <span class="prelude-val">None</span>).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="self">self</span>.writer.flush().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
}
|
||||
ConnWriterMessage::Shutdown => {
|
||||
<span class="kw">return </span><span class="prelude-val">Ok</span>(());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="macro">bail!</span>(<span class="string">"channel unexpectedly closed"</span>);
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">enum </span>ConnFrameStream {
|
||||
Derp(FramedRead<MaybeTlsStreamReader, RelayCodec>),
|
||||
Ws(SplitStream<WebSocketStream>, KeyCache),
|
||||
<span class="macro">debug!</span>(<span class="string">"server_handshake: done"</span>);
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>tung_wasm_to_io_err(e: tokio_tungstenite_wasm::Error) -> std::io::Error {
|
||||
@@ -740,15 +475,28 @@
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>Stream <span class="kw">for </span>ConnFrameStream {
|
||||
<span class="kw">type </span>Item = <span class="prelude-ty">Result</span><Frame>;
|
||||
<span class="kw">impl </span>Stream <span class="kw">for </span>Conn {
|
||||
<span class="kw">type </span>Item = <span class="prelude-ty">Result</span><ReceivedMessage>;
|
||||
|
||||
<span class="kw">fn </span>poll_next(<span class="kw-2">mut </span><span class="self">self</span>: Pin<<span class="kw-2">&mut </span><span class="self">Self</span>>, cx: <span class="kw-2">&mut </span>Context<<span class="lifetime">'_</span>>) -> Poll<<span class="prelude-ty">Option</span><<span class="self">Self</span>::Item>> {
|
||||
<span class="kw">match </span><span class="kw-2">*</span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::Derp(<span class="kw-2">ref mut </span>ws) => Pin::new(ws).poll_next(cx),
|
||||
<span class="self">Self</span>::Ws(<span class="kw-2">ref mut </span>ws, <span class="kw-2">ref </span>cache) => <span class="kw">match </span>Pin::new(ws).poll_next(cx) {
|
||||
<span class="self">Self</span>::Relay { <span class="kw-2">ref mut </span>conn } => <span class="kw">match </span>Pin::new(conn).poll_next(cx) {
|
||||
Poll::Pending => Poll::Pending,
|
||||
Poll::Ready(<span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(frame))) => {
|
||||
<span class="kw">let </span>message = ReceivedMessage::try_from(frame);
|
||||
Poll::Ready(<span class="prelude-val">Some</span>(message))
|
||||
}
|
||||
Poll::Ready(<span class="prelude-val">Some</span>(<span class="prelude-val">Err</span>(err))) => Poll::Ready(<span class="prelude-val">Some</span>(<span class="prelude-val">Err</span>(err))),
|
||||
Poll::Ready(<span class="prelude-val">None</span>) => Poll::Ready(<span class="prelude-val">None</span>),
|
||||
},
|
||||
<span class="self">Self</span>::Ws {
|
||||
<span class="kw-2">ref mut </span>conn,
|
||||
<span class="kw-2">ref </span>key_cache,
|
||||
} => <span class="kw">match </span>Pin::new(conn).poll_next(cx) {
|
||||
Poll::Ready(<span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(tokio_tungstenite_wasm::Message::Binary(vec)))) => {
|
||||
Poll::Ready(<span class="prelude-val">Some</span>(Frame::decode_from_ws_msg(vec, cache)))
|
||||
<span class="kw">let </span>frame = Frame::decode_from_ws_msg(vec, key_cache);
|
||||
<span class="kw">let </span>message = frame.and_then(ReceivedMessage::try_from);
|
||||
Poll::Ready(<span class="prelude-val">Some</span>(message))
|
||||
}
|
||||
Poll::Ready(<span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(msg))) => {
|
||||
<span class="macro">tracing::warn!</span>(<span class="question-mark">?</span>msg, <span class="string">"Got websocket message of unsupported type, skipping."</span>);
|
||||
@@ -762,101 +510,105 @@
|
||||
}
|
||||
}
|
||||
|
||||
<span class="attr">#[derive(derive_more::Debug)]
|
||||
#[debug(<span class="string">"ConnMessageStream"</span>)]
|
||||
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">struct </span>ConnMessageStream {
|
||||
inner: ConnFrameStream,
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>Stream <span class="kw">for </span>ConnMessageStream {
|
||||
<span class="kw">type </span>Item = <span class="prelude-ty">Result</span><ReceivedMessage>;
|
||||
|
||||
<span class="kw">fn </span>poll_next(<span class="kw-2">mut </span><span class="self">self</span>: Pin<<span class="kw-2">&mut </span><span class="self">Self</span>>, cx: <span class="kw-2">&mut </span>Context<<span class="lifetime">'_</span>>) -> Poll<<span class="prelude-ty">Option</span><<span class="self">Self</span>::Item>> {
|
||||
<span class="kw">match </span>Pin::new(<span class="kw-2">&mut </span><span class="self">self</span>.inner).poll_next(cx) {
|
||||
Poll::Ready(<span class="prelude-val">Some</span>(item)) => {
|
||||
<span class="kw">let </span>item = item.and_then(process_incoming_frame);
|
||||
Poll::Ready(<span class="prelude-val">Some</span>(item))
|
||||
}
|
||||
Poll::Ready(<span class="prelude-val">None</span>) => Poll::Ready(<span class="prelude-val">None</span>),
|
||||
Poll::Pending => Poll::Pending,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>process_incoming_frame(frame: Frame) -> <span class="prelude-ty">Result</span><ReceivedMessage> {
|
||||
<span class="kw">match </span>frame {
|
||||
Frame::KeepAlive => {
|
||||
<span class="comment">// A one-way keep-alive message that doesn't require an ack.
|
||||
// This predated FrameType::Ping/FrameType::Pong.
|
||||
</span><span class="prelude-val">Ok</span>(ReceivedMessage::KeepAlive)
|
||||
}
|
||||
Frame::NodeGone { node_id } => <span class="prelude-val">Ok</span>(ReceivedMessage::NodeGone(node_id)),
|
||||
Frame::RecvPacket { src_key, content } => {
|
||||
<span class="kw">let </span>packet = ReceivedMessage::ReceivedPacket {
|
||||
remote_node_id: src_key,
|
||||
data: content,
|
||||
};
|
||||
<span class="prelude-val">Ok</span>(packet)
|
||||
}
|
||||
Frame::Ping { data } => <span class="prelude-val">Ok</span>(ReceivedMessage::Ping(data)),
|
||||
Frame::Pong { data } => <span class="prelude-val">Ok</span>(ReceivedMessage::Pong(data)),
|
||||
Frame::Health { problem } => {
|
||||
<span class="kw">let </span>problem = std::str::from_utf8(<span class="kw-2">&</span>problem)<span class="question-mark">?</span>.to_owned();
|
||||
<span class="kw">let </span>problem = <span class="prelude-val">Some</span>(problem);
|
||||
<span class="prelude-val">Ok</span>(ReceivedMessage::Health { problem })
|
||||
}
|
||||
Frame::Restarting {
|
||||
reconnect_in,
|
||||
try_for,
|
||||
} => {
|
||||
<span class="kw">let </span>reconnect_in = Duration::from_millis(reconnect_in <span class="kw">as </span>u64);
|
||||
<span class="kw">let </span>try_for = Duration::from_millis(try_for <span class="kw">as </span>u64);
|
||||
<span class="prelude-val">Ok</span>(ReceivedMessage::ServerRestarting {
|
||||
reconnect_in,
|
||||
try_for,
|
||||
})
|
||||
}
|
||||
<span class="kw">_ </span>=> <span class="macro">bail!</span>(<span class="string">"unexpected packet: {:?}"</span>, frame.typ()),
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">enum </span>ConnWriter {
|
||||
Derp(FramedWrite<MaybeTlsStreamWriter, RelayCodec>),
|
||||
Ws(SplitSink<WebSocketStream, tokio_tungstenite_wasm::Message>),
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>Sink<Frame> <span class="kw">for </span>ConnWriter {
|
||||
<span class="kw">type </span>Error = std::io::Error;
|
||||
<span class="kw">impl </span>Sink<Frame> <span class="kw">for </span>Conn {
|
||||
<span class="kw">type </span>Error = ConnSendError;
|
||||
|
||||
<span class="kw">fn </span>poll_ready(<span class="kw-2">mut </span><span class="self">self</span>: Pin<<span class="kw-2">&mut </span><span class="self">Self</span>>, cx: <span class="kw-2">&mut </span>Context<<span class="lifetime">'_</span>>) -> Poll<<span class="prelude-ty">Result</span><(), <span class="self">Self</span>::Error>> {
|
||||
<span class="kw">match </span><span class="kw-2">*</span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::Derp(<span class="kw-2">ref mut </span>ws) => Pin::new(ws).poll_ready(cx),
|
||||
<span class="self">Self</span>::Ws(<span class="kw-2">ref mut </span>ws) => Pin::new(ws).poll_ready(cx).map_err(tung_wasm_to_io_err),
|
||||
<span class="self">Self</span>::Relay { <span class="kw-2">ref mut </span>conn } => Pin::new(conn).poll_ready(cx).map_err(Into::into),
|
||||
<span class="self">Self</span>::Ws { <span class="kw-2">ref mut </span>conn, .. } => Pin::new(conn)
|
||||
.poll_ready(cx)
|
||||
.map_err(tung_wasm_to_io_err)
|
||||
.map_err(Into::into),
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>start_send(<span class="kw-2">mut </span><span class="self">self</span>: Pin<<span class="kw-2">&mut </span><span class="self">Self</span>>, item: Frame) -> <span class="prelude-ty">Result</span><(), <span class="self">Self</span>::Error> {
|
||||
<span class="kw">fn </span>start_send(<span class="kw-2">mut </span><span class="self">self</span>: Pin<<span class="kw-2">&mut </span><span class="self">Self</span>>, frame: Frame) -> <span class="prelude-ty">Result</span><(), <span class="self">Self</span>::Error> {
|
||||
<span class="kw">if let </span>Frame::SendPacket { dst_key: <span class="kw">_</span>, packet } = <span class="kw-2">&</span>frame {
|
||||
<span class="kw">if </span>packet.len() > MAX_PACKET_SIZE {
|
||||
<span class="kw">return </span><span class="prelude-val">Err</span>(ConnSendError::Protocol(<span class="string">"Packet exceeds MAX_PACKET_SIZE"</span>));
|
||||
}
|
||||
}
|
||||
<span class="kw">match </span><span class="kw-2">*</span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::Derp(<span class="kw-2">ref mut </span>ws) => Pin::new(ws).start_send(item),
|
||||
<span class="self">Self</span>::Ws(<span class="kw-2">ref mut </span>ws) => Pin::new(ws)
|
||||
<span class="self">Self</span>::Relay { <span class="kw-2">ref mut </span>conn } => Pin::new(conn).start_send(frame).map_err(Into::into),
|
||||
<span class="self">Self</span>::Ws { <span class="kw-2">ref mut </span>conn, .. } => Pin::new(conn)
|
||||
.start_send(tokio_tungstenite_wasm::Message::binary(
|
||||
item.encode_for_ws_msg(),
|
||||
frame.encode_for_ws_msg(),
|
||||
))
|
||||
.map_err(tung_wasm_to_io_err),
|
||||
.map_err(tung_wasm_to_io_err)
|
||||
.map_err(Into::into),
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>poll_flush(<span class="kw-2">mut </span><span class="self">self</span>: Pin<<span class="kw-2">&mut </span><span class="self">Self</span>>, cx: <span class="kw-2">&mut </span>Context<<span class="lifetime">'_</span>>) -> Poll<<span class="prelude-ty">Result</span><(), <span class="self">Self</span>::Error>> {
|
||||
<span class="kw">match </span><span class="kw-2">*</span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::Derp(<span class="kw-2">ref mut </span>ws) => Pin::new(ws).poll_flush(cx),
|
||||
<span class="self">Self</span>::Ws(<span class="kw-2">ref mut </span>ws) => Pin::new(ws).poll_flush(cx).map_err(tung_wasm_to_io_err),
|
||||
<span class="self">Self</span>::Relay { <span class="kw-2">ref mut </span>conn } => Pin::new(conn).poll_flush(cx).map_err(Into::into),
|
||||
<span class="self">Self</span>::Ws { <span class="kw-2">ref mut </span>conn, .. } => Pin::new(conn)
|
||||
.poll_flush(cx)
|
||||
.map_err(tung_wasm_to_io_err)
|
||||
.map_err(Into::into),
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>poll_close(<span class="kw-2">mut </span><span class="self">self</span>: Pin<<span class="kw-2">&mut </span><span class="self">Self</span>>, cx: <span class="kw-2">&mut </span>Context<<span class="lifetime">'_</span>>) -> Poll<<span class="prelude-ty">Result</span><(), <span class="self">Self</span>::Error>> {
|
||||
<span class="kw">match </span><span class="kw-2">*</span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::Derp(<span class="kw-2">ref mut </span>ws) => Pin::new(ws).poll_close(cx),
|
||||
<span class="self">Self</span>::Ws(<span class="kw-2">ref mut </span>ws) => Pin::new(ws).poll_close(cx).map_err(tung_wasm_to_io_err),
|
||||
<span class="self">Self</span>::Relay { <span class="kw-2">ref mut </span>conn } => Pin::new(conn).poll_close(cx).map_err(Into::into),
|
||||
<span class="self">Self</span>::Ws { <span class="kw-2">ref mut </span>conn, .. } => Pin::new(conn)
|
||||
.poll_close(cx)
|
||||
.map_err(tung_wasm_to_io_err)
|
||||
.map_err(Into::into),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>Sink<SendMessage> <span class="kw">for </span>Conn {
|
||||
<span class="kw">type </span>Error = ConnSendError;
|
||||
|
||||
<span class="kw">fn </span>poll_ready(<span class="kw-2">mut </span><span class="self">self</span>: Pin<<span class="kw-2">&mut </span><span class="self">Self</span>>, cx: <span class="kw-2">&mut </span>Context<<span class="lifetime">'_</span>>) -> Poll<<span class="prelude-ty">Result</span><(), <span class="self">Self</span>::Error>> {
|
||||
<span class="kw">match </span><span class="kw-2">*</span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::Relay { <span class="kw-2">ref mut </span>conn } => Pin::new(conn).poll_ready(cx).map_err(Into::into),
|
||||
<span class="self">Self</span>::Ws { <span class="kw-2">ref mut </span>conn, .. } => Pin::new(conn)
|
||||
.poll_ready(cx)
|
||||
.map_err(tung_wasm_to_io_err)
|
||||
.map_err(Into::into),
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>start_send(<span class="kw-2">mut </span><span class="self">self</span>: Pin<<span class="kw-2">&mut </span><span class="self">Self</span>>, item: SendMessage) -> <span class="prelude-ty">Result</span><(), <span class="self">Self</span>::Error> {
|
||||
<span class="kw">if let </span>SendMessage::SendPacket(<span class="kw">_</span>, bytes) = <span class="kw-2">&</span>item {
|
||||
<span class="kw">if </span>bytes.len() > MAX_PACKET_SIZE {
|
||||
<span class="kw">return </span><span class="prelude-val">Err</span>(ConnSendError::Protocol(<span class="string">"Packet exceeds MAX_PACKET_SIZE"</span>));
|
||||
}
|
||||
}
|
||||
<span class="kw">let </span>frame = Frame::from(item);
|
||||
<span class="kw">match </span><span class="kw-2">*</span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::Relay { <span class="kw-2">ref mut </span>conn } => Pin::new(conn).start_send(frame).map_err(Into::into),
|
||||
<span class="self">Self</span>::Ws { <span class="kw-2">ref mut </span>conn, .. } => Pin::new(conn)
|
||||
.start_send(tokio_tungstenite_wasm::Message::binary(
|
||||
frame.encode_for_ws_msg(),
|
||||
))
|
||||
.map_err(tung_wasm_to_io_err)
|
||||
.map_err(Into::into),
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>poll_flush(<span class="kw-2">mut </span><span class="self">self</span>: Pin<<span class="kw-2">&mut </span><span class="self">Self</span>>, cx: <span class="kw-2">&mut </span>Context<<span class="lifetime">'_</span>>) -> Poll<<span class="prelude-ty">Result</span><(), <span class="self">Self</span>::Error>> {
|
||||
<span class="kw">match </span><span class="kw-2">*</span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::Relay { <span class="kw-2">ref mut </span>conn } => Pin::new(conn).poll_flush(cx).map_err(Into::into),
|
||||
<span class="self">Self</span>::Ws { <span class="kw-2">ref mut </span>conn, .. } => Pin::new(conn)
|
||||
.poll_flush(cx)
|
||||
.map_err(tung_wasm_to_io_err)
|
||||
.map_err(Into::into),
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>poll_close(<span class="kw-2">mut </span><span class="self">self</span>: Pin<<span class="kw-2">&mut </span><span class="self">Self</span>>, cx: <span class="kw-2">&mut </span>Context<<span class="lifetime">'_</span>>) -> Poll<<span class="prelude-ty">Result</span><(), <span class="self">Self</span>::Error>> {
|
||||
<span class="kw">match </span><span class="kw-2">*</span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::Relay { <span class="kw-2">ref mut </span>conn } => Pin::new(conn).poll_close(cx).map_err(Into::into),
|
||||
<span class="self">Self</span>::Ws { <span class="kw-2">ref mut </span>conn, .. } => Pin::new(conn)
|
||||
.poll_close(cx)
|
||||
.map_err(tung_wasm_to_io_err)
|
||||
.map_err(Into::into),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -910,24 +662,68 @@
|
||||
},
|
||||
}
|
||||
|
||||
<span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">async fn </span>send_packet<S: Sink<Frame, Error = std::io::Error> + Unpin>(
|
||||
<span class="kw-2">mut </span>writer: S,
|
||||
dst: NodeId,
|
||||
packet: Bytes,
|
||||
) -> <span class="prelude-ty">Result</span><()> {
|
||||
<span class="macro">ensure!</span>(
|
||||
packet.len() <= MAX_PACKET_SIZE,
|
||||
<span class="string">"packet too big: {}"</span>,
|
||||
packet.len()
|
||||
);
|
||||
<span class="kw">impl </span>TryFrom<Frame> <span class="kw">for </span>ReceivedMessage {
|
||||
<span class="kw">type </span>Error = anyhow::Error;
|
||||
|
||||
<span class="kw">let </span>frame = Frame::SendPacket {
|
||||
dst_key: dst,
|
||||
packet,
|
||||
};
|
||||
writer.send(frame).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
writer.flush().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">fn </span>try_from(frame: Frame) -> std::result::Result<<span class="self">Self</span>, <span class="self">Self</span>::Error> {
|
||||
<span class="kw">match </span>frame {
|
||||
Frame::KeepAlive => {
|
||||
<span class="comment">// A one-way keep-alive message that doesn't require an ack.
|
||||
// This predated FrameType::Ping/FrameType::Pong.
|
||||
</span><span class="prelude-val">Ok</span>(ReceivedMessage::KeepAlive)
|
||||
}
|
||||
Frame::NodeGone { node_id } => <span class="prelude-val">Ok</span>(ReceivedMessage::NodeGone(node_id)),
|
||||
Frame::RecvPacket { src_key, content } => {
|
||||
<span class="kw">let </span>packet = ReceivedMessage::ReceivedPacket {
|
||||
remote_node_id: src_key,
|
||||
data: content,
|
||||
};
|
||||
<span class="prelude-val">Ok</span>(packet)
|
||||
}
|
||||
Frame::Ping { data } => <span class="prelude-val">Ok</span>(ReceivedMessage::Ping(data)),
|
||||
Frame::Pong { data } => <span class="prelude-val">Ok</span>(ReceivedMessage::Pong(data)),
|
||||
Frame::Health { problem } => {
|
||||
<span class="kw">let </span>problem = std::str::from_utf8(<span class="kw-2">&</span>problem)<span class="question-mark">?</span>.to_owned();
|
||||
<span class="kw">let </span>problem = <span class="prelude-val">Some</span>(problem);
|
||||
<span class="prelude-val">Ok</span>(ReceivedMessage::Health { problem })
|
||||
}
|
||||
Frame::Restarting {
|
||||
reconnect_in,
|
||||
try_for,
|
||||
} => {
|
||||
<span class="kw">let </span>reconnect_in = Duration::from_millis(reconnect_in <span class="kw">as </span>u64);
|
||||
<span class="kw">let </span>try_for = Duration::from_millis(try_for <span class="kw">as </span>u64);
|
||||
<span class="prelude-val">Ok</span>(ReceivedMessage::ServerRestarting {
|
||||
reconnect_in,
|
||||
try_for,
|
||||
})
|
||||
}
|
||||
<span class="kw">_ </span>=> <span class="macro">bail!</span>(<span class="string">"unexpected packet: {:?}"</span>, frame.typ()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
<span class="doccomment">/// Messages we can send to a relay server.
|
||||
</span><span class="attr">#[derive(Debug)]
|
||||
</span><span class="kw">pub enum </span>SendMessage {
|
||||
<span class="doccomment">/// Send a packet of data to the [`NodeId`].
|
||||
</span>SendPacket(NodeId, Bytes),
|
||||
<span class="doccomment">/// Mark or unmark the connected relay as the home relay.
|
||||
</span>NotePreferred(bool),
|
||||
<span class="doccomment">/// Sends a ping message to the connected relay server.
|
||||
</span>Ping([u8; <span class="number">8</span>]),
|
||||
<span class="doccomment">/// Sends a pong message to the connected relay server.
|
||||
</span>Pong([u8; <span class="number">8</span>]),
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>From<SendMessage> <span class="kw">for </span>Frame {
|
||||
<span class="kw">fn </span>from(source: SendMessage) -> <span class="self">Self </span>{
|
||||
<span class="kw">match </span>source {
|
||||
SendMessage::SendPacket(dst_key, packet) => Frame::SendPacket { dst_key, packet },
|
||||
SendMessage::NotePreferred(preferred) => Frame::NotePreferred { preferred },
|
||||
SendMessage::Ping(data) => Frame::Ping { data },
|
||||
SendMessage::Pong(data) => Frame::Pong { data },
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre></div></section></main></body></html>
|
||||
@@ -270,27 +270,7 @@
|
||||
<a href="#269" id="269">269</a>
|
||||
<a href="#270" id="270">270</a>
|
||||
<a href="#271" id="271">271</a>
|
||||
<a href="#272" id="272">272</a>
|
||||
<a href="#273" id="273">273</a>
|
||||
<a href="#274" id="274">274</a>
|
||||
<a href="#275" id="275">275</a>
|
||||
<a href="#276" id="276">276</a>
|
||||
<a href="#277" id="277">277</a>
|
||||
<a href="#278" id="278">278</a>
|
||||
<a href="#279" id="279">279</a>
|
||||
<a href="#280" id="280">280</a>
|
||||
<a href="#281" id="281">281</a>
|
||||
<a href="#282" id="282">282</a>
|
||||
<a href="#283" id="283">283</a>
|
||||
<a href="#284" id="284">284</a>
|
||||
<a href="#285" id="285">285</a>
|
||||
<a href="#286" id="286">286</a>
|
||||
<a href="#287" id="287">287</a>
|
||||
<a href="#288" id="288">288</a>
|
||||
<a href="#289" id="289">289</a>
|
||||
<a href="#290" id="290">290</a>
|
||||
<a href="#291" id="291">291</a>
|
||||
<a href="#292" id="292">292</a></pre></div><pre class="rust"><code><span class="kw">use </span>std::{
|
||||
<a href="#272" id="272">272</a></pre></div><pre class="rust"><code><span class="kw">use </span>std::{
|
||||
net::SocketAddr,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
@@ -307,19 +287,14 @@
|
||||
|
||||
<span class="kw">use </span><span class="kw">super</span>::util;
|
||||
|
||||
<span class="kw">pub enum </span>MaybeTlsStreamReader {
|
||||
Raw(util::Chain<std::io::Cursor<Bytes>, tokio::io::ReadHalf<ProxyStream>>),
|
||||
Tls(
|
||||
util::Chain<
|
||||
std::io::Cursor<Bytes>,
|
||||
tokio::io::ReadHalf<tokio_rustls::client::TlsStream<ProxyStream>>,
|
||||
>,
|
||||
),
|
||||
<span class="kw">pub enum </span>MaybeTlsStreamChained {
|
||||
Raw(util::Chain<std::io::Cursor<Bytes>, ProxyStream>),
|
||||
Tls(util::Chain<std::io::Cursor<Bytes>, tokio_rustls::client::TlsStream<ProxyStream>>),
|
||||
<span class="attr">#[cfg(all(test, feature = <span class="string">"server"</span>))]
|
||||
</span>Mem(tokio::io::ReadHalf<tokio::io::DuplexStream>),
|
||||
</span>Mem(tokio::io::DuplexStream),
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>AsyncRead <span class="kw">for </span>MaybeTlsStreamReader {
|
||||
<span class="kw">impl </span>AsyncRead <span class="kw">for </span>MaybeTlsStreamChained {
|
||||
<span class="kw">fn </span>poll_read(
|
||||
<span class="kw-2">mut </span><span class="self">self</span>: Pin<<span class="kw-2">&mut </span><span class="self">Self</span>>,
|
||||
cx: <span class="kw-2">&mut </span>Context<<span class="lifetime">'_</span>>,
|
||||
@@ -334,22 +309,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">pub enum </span>MaybeTlsStreamWriter {
|
||||
Raw(tokio::io::WriteHalf<ProxyStream>),
|
||||
Tls(tokio::io::WriteHalf<tokio_rustls::client::TlsStream<ProxyStream>>),
|
||||
<span class="attr">#[cfg(all(test, feature = <span class="string">"server"</span>))]
|
||||
</span>Mem(tokio::io::WriteHalf<tokio::io::DuplexStream>),
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>AsyncWrite <span class="kw">for </span>MaybeTlsStreamWriter {
|
||||
<span class="kw">impl </span>AsyncWrite <span class="kw">for </span>MaybeTlsStreamChained {
|
||||
<span class="kw">fn </span>poll_write(
|
||||
<span class="kw-2">mut </span><span class="self">self</span>: Pin<<span class="kw-2">&mut </span><span class="self">Self</span>>,
|
||||
cx: <span class="kw-2">&mut </span>Context<<span class="lifetime">'_</span>>,
|
||||
buf: <span class="kw-2">&</span>[u8],
|
||||
) -> Poll<<span class="prelude-ty">Result</span><usize, std::io::Error>> {
|
||||
<span class="kw">match </span><span class="kw-2">&mut *</span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::Raw(stream) => Pin::new(stream).poll_write(cx, buf),
|
||||
<span class="self">Self</span>::Tls(stream) => Pin::new(stream).poll_write(cx, buf),
|
||||
<span class="self">Self</span>::Raw(stream) => Pin::new(stream.get_mut().<span class="number">1</span>).poll_write(cx, buf),
|
||||
<span class="self">Self</span>::Tls(stream) => Pin::new(stream.get_mut().<span class="number">1</span>).poll_write(cx, buf),
|
||||
<span class="attr">#[cfg(all(test, feature = <span class="string">"server"</span>))]
|
||||
</span><span class="self">Self</span>::Mem(stream) => Pin::new(stream).poll_write(cx, buf),
|
||||
}
|
||||
@@ -360,8 +328,8 @@
|
||||
cx: <span class="kw-2">&mut </span>Context<<span class="lifetime">'_</span>>,
|
||||
) -> Poll<<span class="prelude-ty">Result</span><(), std::io::Error>> {
|
||||
<span class="kw">match </span><span class="kw-2">&mut *</span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::Raw(stream) => Pin::new(stream).poll_flush(cx),
|
||||
<span class="self">Self</span>::Tls(stream) => Pin::new(stream).poll_flush(cx),
|
||||
<span class="self">Self</span>::Raw(stream) => Pin::new(stream.get_mut().<span class="number">1</span>).poll_flush(cx),
|
||||
<span class="self">Self</span>::Tls(stream) => Pin::new(stream.get_mut().<span class="number">1</span>).poll_flush(cx),
|
||||
<span class="attr">#[cfg(all(test, feature = <span class="string">"server"</span>))]
|
||||
</span><span class="self">Self</span>::Mem(stream) => Pin::new(stream).poll_flush(cx),
|
||||
}
|
||||
@@ -372,8 +340,8 @@
|
||||
cx: <span class="kw-2">&mut </span>Context<<span class="lifetime">'_</span>>,
|
||||
) -> Poll<<span class="prelude-ty">Result</span><(), std::io::Error>> {
|
||||
<span class="kw">match </span><span class="kw-2">&mut *</span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::Raw(stream) => Pin::new(stream).poll_shutdown(cx),
|
||||
<span class="self">Self</span>::Tls(stream) => Pin::new(stream).poll_shutdown(cx),
|
||||
<span class="self">Self</span>::Raw(stream) => Pin::new(stream.get_mut().<span class="number">1</span>).poll_shutdown(cx),
|
||||
<span class="self">Self</span>::Tls(stream) => Pin::new(stream.get_mut().<span class="number">1</span>).poll_shutdown(cx),
|
||||
<span class="attr">#[cfg(all(test, feature = <span class="string">"server"</span>))]
|
||||
</span><span class="self">Self</span>::Mem(stream) => Pin::new(stream).poll_shutdown(cx),
|
||||
}
|
||||
@@ -385,41 +353,31 @@
|
||||
bufs: <span class="kw-2">&</span>[std::io::IoSlice<<span class="lifetime">'_</span>>],
|
||||
) -> Poll<<span class="prelude-ty">Result</span><usize, std::io::Error>> {
|
||||
<span class="kw">match </span><span class="kw-2">&mut *</span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::Raw(stream) => Pin::new(stream).poll_write_vectored(cx, bufs),
|
||||
<span class="self">Self</span>::Tls(stream) => Pin::new(stream).poll_write_vectored(cx, bufs),
|
||||
<span class="self">Self</span>::Raw(stream) => Pin::new(stream.get_mut().<span class="number">1</span>).poll_write_vectored(cx, bufs),
|
||||
<span class="self">Self</span>::Tls(stream) => Pin::new(stream.get_mut().<span class="number">1</span>).poll_write_vectored(cx, bufs),
|
||||
<span class="attr">#[cfg(all(test, feature = <span class="string">"server"</span>))]
|
||||
</span><span class="self">Self</span>::Mem(stream) => Pin::new(stream).poll_write_vectored(cx, bufs),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">pub fn </span>downcast_upgrade(
|
||||
upgraded: Upgraded,
|
||||
) -> <span class="prelude-ty">Result</span><(MaybeTlsStreamReader, MaybeTlsStreamWriter)> {
|
||||
<span class="kw">pub fn </span>downcast_upgrade(upgraded: Upgraded) -> <span class="prelude-ty">Result</span><MaybeTlsStreamChained> {
|
||||
<span class="kw">match </span>upgraded.downcast::<TokioIo<ProxyStream>>() {
|
||||
<span class="prelude-val">Ok</span>(Parts { read_buf, io, .. }) => {
|
||||
<span class="kw">let </span>inner = io.into_inner();
|
||||
<span class="kw">let </span>(reader, writer) = tokio::io::split(inner);
|
||||
<span class="kw">let </span>conn = io.into_inner();
|
||||
<span class="comment">// Prepend data to the reader to avoid data loss
|
||||
</span><span class="kw">let </span>reader = util::chain(std::io::Cursor::new(read_buf), reader);
|
||||
<span class="prelude-val">Ok</span>((
|
||||
MaybeTlsStreamReader::Raw(reader),
|
||||
MaybeTlsStreamWriter::Raw(writer),
|
||||
))
|
||||
</span><span class="kw">let </span>conn = util::chain(std::io::Cursor::new(read_buf), conn);
|
||||
<span class="prelude-val">Ok</span>(MaybeTlsStreamChained::Raw(conn))
|
||||
}
|
||||
<span class="prelude-val">Err</span>(upgraded) => {
|
||||
<span class="kw">if let </span><span class="prelude-val">Ok</span>(Parts { read_buf, io, .. }) =
|
||||
upgraded.downcast::<TokioIo<tokio_rustls::client::TlsStream<ProxyStream>>>()
|
||||
{
|
||||
<span class="kw">let </span>inner = io.into_inner();
|
||||
<span class="kw">let </span>(reader, writer) = tokio::io::split(inner);
|
||||
<span class="comment">// Prepend data to the reader to avoid data loss
|
||||
</span><span class="kw">let </span>reader = util::chain(std::io::Cursor::new(read_buf), reader);
|
||||
<span class="kw">let </span>conn = io.into_inner();
|
||||
|
||||
<span class="kw">return </span><span class="prelude-val">Ok</span>((
|
||||
MaybeTlsStreamReader::Tls(reader),
|
||||
MaybeTlsStreamWriter::Tls(writer),
|
||||
));
|
||||
<span class="comment">// Prepend data to the reader to avoid data loss
|
||||
</span><span class="kw">let </span>conn = util::chain(std::io::Cursor::new(read_buf), conn);
|
||||
<span class="kw">return </span><span class="prelude-val">Ok</span>(MaybeTlsStreamChained::Tls(conn));
|
||||
}
|
||||
|
||||
<span class="macro">bail!</span>(
|
||||
@@ -429,7 +387,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">pub enum </span>ProxyStream {
|
||||
<span class="attr">#[derive(Debug)]
|
||||
</span><span class="kw">pub enum </span>ProxyStream {
|
||||
Raw(TcpStream),
|
||||
Proxied(util::Chain<std::io::Cursor<Bytes>, MaybeTlsStream>),
|
||||
}
|
||||
@@ -506,7 +465,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">pub enum </span>MaybeTlsStream {
|
||||
<span class="attr">#[derive(Debug)]
|
||||
</span><span class="kw">pub enum </span>MaybeTlsStream {
|
||||
Raw(TcpStream),
|
||||
Tls(tokio_rustls::client::TlsStream<TcpStream>),
|
||||
}
|
||||
|
||||
@@ -41,17 +41,7 @@
|
||||
<a href="#40" id="40">40</a>
|
||||
<a href="#41" id="41">41</a>
|
||||
<a href="#42" id="42">42</a>
|
||||
<a href="#43" id="43">43</a>
|
||||
<a href="#44" id="44">44</a>
|
||||
<a href="#45" id="45">45</a>
|
||||
<a href="#46" id="46">46</a>
|
||||
<a href="#47" id="47">47</a>
|
||||
<a href="#48" id="48">48</a>
|
||||
<a href="#49" id="49">49</a>
|
||||
<a href="#50" id="50">50</a>
|
||||
<a href="#51" id="51">51</a>
|
||||
<a href="#52" id="52">52</a>
|
||||
<a href="#53" id="53">53</a></pre></div><pre class="rust"><code><span class="doccomment">//! Default values used in the relay.
|
||||
<a href="#43" id="43">43</a></pre></div><pre class="rust"><code><span class="doccomment">//! Default values used in the relay.
|
||||
|
||||
/// The default STUN port used by the Relay server.
|
||||
///
|
||||
@@ -87,19 +77,9 @@
|
||||
<span class="doccomment">/// Timeout used by the relay client while connecting to the relay server,
|
||||
/// using `TcpStream::connect`
|
||||
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">const </span>DIAL_NODE_TIMEOUT: Duration = Duration::from_millis(<span class="number">1500</span>);
|
||||
<span class="doccomment">/// Timeout for expecting a pong from the relay server
|
||||
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">const </span>PING_TIMEOUT: Duration = Duration::from_secs(<span class="number">5</span>);
|
||||
<span class="doccomment">/// Timeout for the entire relay connection, which includes dns, dialing
|
||||
/// the server, upgrading the connection, and completing the handshake
|
||||
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">const </span>CONNECT_TIMEOUT: Duration = Duration::from_secs(<span class="number">10</span>);
|
||||
<span class="doccomment">/// Timeout for our async dns resolver
|
||||
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">const </span>DNS_TIMEOUT: Duration = Duration::from_secs(<span class="number">1</span>);
|
||||
|
||||
<span class="doccomment">/// Maximum time the client will wait to receive on the connection, since
|
||||
/// the last message. Longer than this time and the client will consider
|
||||
/// the connection dead.
|
||||
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">const </span>CLIENT_RECV_TIMEOUT: Duration = Duration::from_secs(<span class="number">120</span>);
|
||||
|
||||
<span class="doccomment">/// Maximum time the server will attempt to get a successful write to the connection.
|
||||
</span><span class="attr">#[cfg(feature = <span class="string">"server"</span>)]
|
||||
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">const </span>SERVER_WRITE_TIMEOUT: Duration = Duration::from_secs(<span class="number">2</span>);
|
||||
|
||||
@@ -48,14 +48,7 @@
|
||||
<a href="#47" id="47">47</a>
|
||||
<a href="#48" id="48">48</a>
|
||||
<a href="#49" id="49">49</a>
|
||||
<a href="#50" id="50">50</a>
|
||||
<a href="#51" id="51">51</a>
|
||||
<a href="#52" id="52">52</a>
|
||||
<a href="#53" id="53">53</a>
|
||||
<a href="#54" id="54">54</a>
|
||||
<a href="#55" id="55">55</a>
|
||||
<a href="#56" id="56">56</a>
|
||||
<a href="#57" id="57">57</a></pre></div><pre class="rust"><code><span class="doccomment">//! Iroh's relay is a feature within [iroh](https://github.com/n0-computer/iroh), a peer-to-peer
|
||||
<a href="#50" id="50">50</a></pre></div><pre class="rust"><code><span class="doccomment">//! Iroh's relay is a feature within [iroh](https://github.com/n0-computer/iroh), a peer-to-peer
|
||||
//! networking system designed to facilitate direct, encrypted connections between devices. Iroh
|
||||
//! aims to simplify decentralized communication by automatically handling connections through
|
||||
//! "relays" when direct connections aren't immediately possible. The relay server helps establish
|
||||
@@ -104,12 +97,5 @@
|
||||
|
||||
<span class="kw">pub use </span>protos::relay::MAX_PACKET_SIZE;
|
||||
|
||||
<span class="kw">pub use </span><span class="self">self</span>::{
|
||||
client::{
|
||||
conn::{Conn <span class="kw">as </span>RelayConn, ReceivedMessage},
|
||||
Client <span class="kw">as </span>HttpClient, ClientBuilder <span class="kw">as </span>HttpClientBuilder, ClientError <span class="kw">as </span>HttpClientError,
|
||||
ClientReceiver <span class="kw">as </span>HttpClientReceiver,
|
||||
},
|
||||
relay_map::{RelayMap, RelayNode, RelayQuicConfig},
|
||||
};
|
||||
<span class="kw">pub use </span><span class="self">self</span>::relay_map::{RelayMap, RelayNode, RelayQuicConfig};
|
||||
</code></pre></div></section></main></body></html>
|
||||
@@ -838,7 +838,11 @@
|
||||
<a href="#837" id="837">837</a>
|
||||
<a href="#838" id="838">838</a>
|
||||
<a href="#839" id="839">839</a>
|
||||
<a href="#840" id="840">840</a></pre></div><pre class="rust"><code><span class="doccomment">//! This module implements the relaying protocol used by the `server` and `client`.
|
||||
<a href="#840" id="840">840</a>
|
||||
<a href="#841" id="841">841</a>
|
||||
<a href="#842" id="842">842</a>
|
||||
<a href="#843" id="843">843</a>
|
||||
<a href="#844" id="844">844</a></pre></div><pre class="rust"><code><span class="doccomment">//! This module implements the relaying protocol used by the `server` and `client`.
|
||||
//!
|
||||
//! Protocol flow:
|
||||
//!
|
||||
@@ -852,6 +856,7 @@
|
||||
//! * clients sends `FrameType::SendPacket`
|
||||
//! * server then sends `FrameType::RecvPacket` to recipient
|
||||
|
||||
</span><span class="attr">#[cfg(feature = <span class="string">"server"</span>)]
|
||||
</span><span class="kw">use </span>std::time::Duration;
|
||||
|
||||
<span class="kw">use </span>anyhow::{bail, ensure};
|
||||
@@ -865,7 +870,7 @@
|
||||
<span class="kw">use </span>serde::{Deserialize, Serialize};
|
||||
<span class="kw">use </span>tokio_util::codec::{Decoder, Encoder};
|
||||
|
||||
<span class="kw">use </span><span class="kw">crate</span>::KeyCache;
|
||||
<span class="kw">use crate</span>::{client::conn::ConnSendError, KeyCache};
|
||||
|
||||
<span class="doccomment">/// The maximum size of a packet sent over relay.
|
||||
/// (This only includes the data bytes visible to magicsock, not
|
||||
@@ -886,6 +891,7 @@
|
||||
</span><span class="attr">#[cfg(feature = <span class="string">"server"</span>)]
|
||||
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">const </span>SERVER_CHANNEL_SIZE: usize = <span class="number">1024 </span>* <span class="number">100</span>;
|
||||
<span class="doccomment">/// The number of packets buffered for sending per client
|
||||
</span><span class="attr">#[cfg(feature = <span class="string">"server"</span>)]
|
||||
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">const </span>PER_CLIENT_SEND_QUEUE_DEPTH: usize = <span class="number">512</span>; <span class="comment">//32;
|
||||
|
||||
</span><span class="doccomment">/// ProtocolVersion is bumped whenever there's a wire-incompatible change.
|
||||
@@ -969,6 +975,7 @@
|
||||
/// Ignores the timeout if `None`
|
||||
///
|
||||
/// Does not flush.
|
||||
</span><span class="attr">#[cfg(feature = <span class="string">"server"</span>)]
|
||||
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">async fn </span>write_frame<S: Sink<Frame, Error = std::io::Error> + Unpin>(
|
||||
<span class="kw-2">mut </span>writer: S,
|
||||
frame: Frame,
|
||||
@@ -987,7 +994,7 @@
|
||||
/// and the client's [`ClientInfo`], sealed using the server's [`PublicKey`].
|
||||
///
|
||||
/// Flushes after writing.
|
||||
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">async fn </span>send_client_key<S: Sink<Frame, Error = std::io::Error> + Unpin>(
|
||||
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">async fn </span>send_client_key<S: Sink<Frame, Error = ConnSendError> + Unpin>(
|
||||
<span class="kw-2">mut </span>writer: S,
|
||||
client_secret_key: <span class="kw-2">&</span>SecretKey,
|
||||
client_info: <span class="kw-2">&</span>ClientInfo,
|
||||
@@ -1453,7 +1460,8 @@
|
||||
</span><span class="kw">async fn </span>test_send_recv_client_key() -> anyhow::Result<()> {
|
||||
<span class="kw">let </span>(reader, writer) = tokio::io::duplex(<span class="number">1024</span>);
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>reader = FramedRead::new(reader, RelayCodec::test());
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>writer = FramedWrite::new(writer, RelayCodec::test());
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>writer =
|
||||
FramedWrite::new(writer, RelayCodec::test()).sink_map_err(ConnSendError::from);
|
||||
|
||||
<span class="kw">let </span>client_key = SecretKey::generate(rand::thread_rng());
|
||||
<span class="kw">let </span>client_info = ClientInfo {
|
||||
|
||||
@@ -1108,40 +1108,7 @@
|
||||
<a href="#1107" id="1107">1107</a>
|
||||
<a href="#1108" id="1108">1108</a>
|
||||
<a href="#1109" id="1109">1109</a>
|
||||
<a href="#1110" id="1110">1110</a>
|
||||
<a href="#1111" id="1111">1111</a>
|
||||
<a href="#1112" id="1112">1112</a>
|
||||
<a href="#1113" id="1113">1113</a>
|
||||
<a href="#1114" id="1114">1114</a>
|
||||
<a href="#1115" id="1115">1115</a>
|
||||
<a href="#1116" id="1116">1116</a>
|
||||
<a href="#1117" id="1117">1117</a>
|
||||
<a href="#1118" id="1118">1118</a>
|
||||
<a href="#1119" id="1119">1119</a>
|
||||
<a href="#1120" id="1120">1120</a>
|
||||
<a href="#1121" id="1121">1121</a>
|
||||
<a href="#1122" id="1122">1122</a>
|
||||
<a href="#1123" id="1123">1123</a>
|
||||
<a href="#1124" id="1124">1124</a>
|
||||
<a href="#1125" id="1125">1125</a>
|
||||
<a href="#1126" id="1126">1126</a>
|
||||
<a href="#1127" id="1127">1127</a>
|
||||
<a href="#1128" id="1128">1128</a>
|
||||
<a href="#1129" id="1129">1129</a>
|
||||
<a href="#1130" id="1130">1130</a>
|
||||
<a href="#1131" id="1131">1131</a>
|
||||
<a href="#1132" id="1132">1132</a>
|
||||
<a href="#1133" id="1133">1133</a>
|
||||
<a href="#1134" id="1134">1134</a>
|
||||
<a href="#1135" id="1135">1135</a>
|
||||
<a href="#1136" id="1136">1136</a>
|
||||
<a href="#1137" id="1137">1137</a>
|
||||
<a href="#1138" id="1138">1138</a>
|
||||
<a href="#1139" id="1139">1139</a>
|
||||
<a href="#1140" id="1140">1140</a>
|
||||
<a href="#1141" id="1141">1141</a>
|
||||
<a href="#1142" id="1142">1142</a>
|
||||
<a href="#1143" id="1143">1143</a></pre></div><pre class="rust"><code><span class="doccomment">//! A fully-fledged iroh-relay server over HTTP or HTTPS.
|
||||
<a href="#1110" id="1110">1110</a></pre></div><pre class="rust"><code><span class="doccomment">//! A fully-fledged iroh-relay server over HTTP or HTTPS.
|
||||
//!
|
||||
//! This module provides an API to run a full fledged iroh-relay server. It is primarily
|
||||
//! used by the `iroh-relay` binary in this crate. It can be used to run a relay server in
|
||||
@@ -1917,12 +1884,13 @@
|
||||
<span class="kw">use </span>std::{net::Ipv4Addr, time::Duration};
|
||||
|
||||
<span class="kw">use </span>bytes::Bytes;
|
||||
<span class="kw">use </span>futures_util::SinkExt;
|
||||
<span class="kw">use </span>http::header::UPGRADE;
|
||||
<span class="kw">use </span>iroh_base::SecretKey;
|
||||
<span class="kw">use </span>iroh_base::{NodeId, SecretKey};
|
||||
|
||||
<span class="kw">use super</span>::<span class="kw-2">*</span>;
|
||||
<span class="kw">use crate</span>::{
|
||||
client::{conn::ReceivedMessage, ClientBuilder},
|
||||
client::{conn::ReceivedMessage, ClientBuilder, SendMessage},
|
||||
http::{Protocol, HTTP_UPGRADE_PROTOCOL},
|
||||
};
|
||||
|
||||
@@ -1941,6 +1909,26 @@
|
||||
.<span class="kw">await
|
||||
</span>}
|
||||
|
||||
<span class="kw">async fn </span>try_send_recv(
|
||||
client_a: <span class="kw-2">&mut </span><span class="kw">crate</span>::client::Client,
|
||||
client_b: <span class="kw-2">&mut </span><span class="kw">crate</span>::client::Client,
|
||||
b_key: NodeId,
|
||||
msg: Bytes,
|
||||
) -> <span class="prelude-ty">Result</span><ReceivedMessage> {
|
||||
<span class="comment">// try resend 10 times
|
||||
</span><span class="kw">for _ in </span><span class="number">0</span>..<span class="number">10 </span>{
|
||||
client_a
|
||||
.send(SendMessage::SendPacket(b_key, msg.clone()))
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">let </span><span class="prelude-val">Ok</span>(res) = tokio::time::timeout(Duration::from_millis(<span class="number">500</span>), client_b.next()).<span class="kw">await
|
||||
else </span>{
|
||||
<span class="kw">continue</span>;
|
||||
};
|
||||
<span class="kw">return </span>res.context(<span class="string">"stream finished"</span>)<span class="question-mark">?</span>;
|
||||
}
|
||||
<span class="macro">panic!</span>(<span class="string">"failed to send and recv message"</span>);
|
||||
}
|
||||
|
||||
<span class="attr">#[tokio::test]
|
||||
</span><span class="kw">async fn </span>test_no_services() {
|
||||
<span class="kw">let </span>_guard = iroh_test::logging::setup();
|
||||
@@ -2029,7 +2017,7 @@
|
||||
}
|
||||
|
||||
<span class="attr">#[tokio::test]
|
||||
</span><span class="kw">async fn </span>test_relay_clients_both_derp() {
|
||||
</span><span class="kw">async fn </span>test_relay_clients_both_relay() -> <span class="prelude-ty">Result</span><()> {
|
||||
<span class="kw">let </span>_guard = iroh_test::logging::setup();
|
||||
<span class="kw">let </span>server = spawn_local_relay().<span class="kw">await</span>.unwrap();
|
||||
<span class="kw">let </span>relay_url = <span class="macro">format!</span>(<span class="string">"http://{}"</span>, server.http_addr().unwrap());
|
||||
@@ -2039,40 +2027,20 @@
|
||||
</span><span class="kw">let </span>a_secret_key = SecretKey::generate(rand::thread_rng());
|
||||
<span class="kw">let </span>a_key = a_secret_key.public();
|
||||
<span class="kw">let </span>resolver = <span class="kw">crate</span>::dns::default_resolver().clone();
|
||||
<span class="kw">let </span>(client_a, <span class="kw-2">mut </span>client_a_receiver) =
|
||||
ClientBuilder::new(relay_url.clone()).build(a_secret_key, resolver);
|
||||
<span class="kw">let </span>connect_client = client_a.clone();
|
||||
|
||||
<span class="comment">// give the relay server some time to accept connections
|
||||
</span><span class="kw">if let </span><span class="prelude-val">Err</span>(err) = tokio::time::timeout(Duration::from_secs(<span class="number">10</span>), <span class="kw">async move </span>{
|
||||
<span class="kw">loop </span>{
|
||||
<span class="kw">match </span>connect_client.connect().<span class="kw">await </span>{
|
||||
<span class="prelude-val">Ok</span>(<span class="kw">_</span>) => <span class="kw">break</span>,
|
||||
<span class="prelude-val">Err</span>(err) => {
|
||||
<span class="macro">warn!</span>(<span class="string">"client unable to connect to relay server: {err:#}"</span>);
|
||||
tokio::time::sleep(Duration::from_millis(<span class="number">100</span>)).<span class="kw">await</span>;
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.<span class="kw">await
|
||||
</span>{
|
||||
<span class="macro">panic!</span>(<span class="string">"error connecting to relay server: {err:#}"</span>);
|
||||
}
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>client_a = ClientBuilder::new(relay_url.clone(), a_secret_key, resolver.clone())
|
||||
.connect()
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="comment">// set up client b
|
||||
</span><span class="kw">let </span>b_secret_key = SecretKey::generate(rand::thread_rng());
|
||||
<span class="kw">let </span>b_key = b_secret_key.public();
|
||||
<span class="kw">let </span>resolver = <span class="kw">crate</span>::dns::default_resolver().clone();
|
||||
<span class="kw">let </span>(client_b, <span class="kw-2">mut </span>client_b_receiver) =
|
||||
ClientBuilder::new(relay_url.clone()).build(b_secret_key, resolver);
|
||||
client_b.connect().<span class="kw">await</span>.unwrap();
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>client_b = ClientBuilder::new(relay_url.clone(), b_secret_key, resolver.clone())
|
||||
.connect()
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="comment">// send message from a to b
|
||||
</span><span class="kw">let </span>msg = Bytes::from(<span class="string">"hello, b"</span>);
|
||||
client_a.send(b_key, msg.clone()).<span class="kw">await</span>.unwrap();
|
||||
|
||||
<span class="kw">let </span>res = client_b_receiver.recv().<span class="kw">await</span>.unwrap().unwrap();
|
||||
<span class="kw">let </span>res = try_send_recv(<span class="kw-2">&mut </span>client_a, <span class="kw-2">&mut </span>client_b, b_key, msg.clone()).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">if let </span>ReceivedMessage::ReceivedPacket {
|
||||
remote_node_id,
|
||||
data,
|
||||
@@ -2086,9 +2054,7 @@
|
||||
|
||||
<span class="comment">// send message from b to a
|
||||
</span><span class="kw">let </span>msg = Bytes::from(<span class="string">"howdy, a"</span>);
|
||||
client_b.send(a_key, msg.clone()).<span class="kw">await</span>.unwrap();
|
||||
|
||||
<span class="kw">let </span>res = client_a_receiver.recv().<span class="kw">await</span>.unwrap().unwrap();
|
||||
<span class="kw">let </span>res = try_send_recv(<span class="kw-2">&mut </span>client_b, <span class="kw-2">&mut </span>client_a, a_key, msg.clone()).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">if let </span>ReceivedMessage::ReceivedPacket {
|
||||
remote_node_id,
|
||||
data,
|
||||
@@ -2099,86 +2065,73 @@
|
||||
} <span class="kw">else </span>{
|
||||
<span class="macro">panic!</span>(<span class="string">"client_a received unexpected message {res:?}"</span>);
|
||||
}
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}
|
||||
|
||||
<span class="attr">#[tokio::test]
|
||||
</span><span class="kw">async fn </span>test_relay_clients_both_websockets() {
|
||||
</span><span class="kw">async fn </span>test_relay_clients_both_websockets() -> <span class="prelude-ty">Result</span><()> {
|
||||
<span class="kw">let </span>_guard = iroh_test::logging::setup();
|
||||
<span class="kw">let </span>server = spawn_local_relay().<span class="kw">await</span>.unwrap();
|
||||
<span class="kw">let </span>server = spawn_local_relay().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="kw">let </span>relay_url = <span class="macro">format!</span>(<span class="string">"http://{}"</span>, server.http_addr().unwrap());
|
||||
<span class="kw">let </span>relay_url: RelayUrl = relay_url.parse().unwrap();
|
||||
<span class="kw">let </span>relay_url: RelayUrl = relay_url.parse()<span class="question-mark">?</span>;
|
||||
|
||||
<span class="comment">// set up client a
|
||||
</span><span class="kw">let </span>a_secret_key = SecretKey::generate(rand::thread_rng());
|
||||
<span class="kw">let </span>a_key = a_secret_key.public();
|
||||
<span class="kw">let </span>resolver = <span class="kw">crate</span>::dns::default_resolver().clone();
|
||||
<span class="kw">let </span>(client_a, <span class="kw-2">mut </span>client_a_receiver) = ClientBuilder::new(relay_url.clone())
|
||||
<span class="kw">let </span>resolver = <span class="kw">crate</span>::dns::default_resolver();
|
||||
<span class="macro">info!</span>(<span class="string">"client a build & connect"</span>);
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>client_a = ClientBuilder::new(relay_url.clone(), a_secret_key, resolver.clone())
|
||||
.protocol(Protocol::Websocket)
|
||||
.build(a_secret_key, resolver);
|
||||
<span class="kw">let </span>connect_client = client_a.clone();
|
||||
|
||||
<span class="comment">// give the relay server some time to accept connections
|
||||
</span><span class="kw">if let </span><span class="prelude-val">Err</span>(err) = tokio::time::timeout(Duration::from_secs(<span class="number">10</span>), <span class="kw">async move </span>{
|
||||
<span class="kw">loop </span>{
|
||||
<span class="kw">match </span>connect_client.connect().<span class="kw">await </span>{
|
||||
<span class="prelude-val">Ok</span>(<span class="kw">_</span>) => <span class="kw">break</span>,
|
||||
<span class="prelude-val">Err</span>(err) => {
|
||||
<span class="macro">warn!</span>(<span class="string">"client unable to connect to relay server: {err:#}"</span>);
|
||||
tokio::time::sleep(Duration::from_millis(<span class="number">100</span>)).<span class="kw">await</span>;
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.<span class="kw">await
|
||||
</span>{
|
||||
<span class="macro">panic!</span>(<span class="string">"error connecting to relay server: {err:#}"</span>);
|
||||
}
|
||||
.connect()
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="comment">// set up client b
|
||||
</span><span class="kw">let </span>b_secret_key = SecretKey::generate(rand::thread_rng());
|
||||
<span class="kw">let </span>b_key = b_secret_key.public();
|
||||
<span class="kw">let </span>resolver = <span class="kw">crate</span>::dns::default_resolver().clone();
|
||||
<span class="kw">let </span>(client_b, <span class="kw-2">mut </span>client_b_receiver) = ClientBuilder::new(relay_url.clone())
|
||||
<span class="macro">info!</span>(<span class="string">"client b build & connect"</span>);
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>client_b = ClientBuilder::new(relay_url.clone(), b_secret_key, resolver.clone())
|
||||
.protocol(Protocol::Websocket) <span class="comment">// another websocket client
|
||||
</span>.build(b_secret_key, resolver);
|
||||
client_b.connect().<span class="kw">await</span>.unwrap();
|
||||
</span>.connect()
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="macro">info!</span>(<span class="string">"sending a -> b"</span>);
|
||||
|
||||
<span class="comment">// send message from a to b
|
||||
</span><span class="kw">let </span>msg = Bytes::from(<span class="string">"hello, b"</span>);
|
||||
client_a.send(b_key, msg.clone()).<span class="kw">await</span>.unwrap();
|
||||
|
||||
<span class="kw">let </span>res = client_b_receiver.recv().<span class="kw">await</span>.unwrap().unwrap();
|
||||
<span class="kw">if let </span>ReceivedMessage::ReceivedPacket {
|
||||
<span class="kw">let </span>res = try_send_recv(<span class="kw-2">&mut </span>client_a, <span class="kw-2">&mut </span>client_b, b_key, msg.clone()).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">let </span>ReceivedMessage::ReceivedPacket {
|
||||
remote_node_id,
|
||||
data,
|
||||
} = res
|
||||
{
|
||||
<span class="macro">assert_eq!</span>(a_key, remote_node_id);
|
||||
<span class="macro">assert_eq!</span>(msg, data);
|
||||
} <span class="kw">else </span>{
|
||||
<span class="kw">else </span>{
|
||||
<span class="macro">panic!</span>(<span class="string">"client_b received unexpected message {res:?}"</span>);
|
||||
}
|
||||
};
|
||||
|
||||
<span class="macro">assert_eq!</span>(a_key, remote_node_id);
|
||||
<span class="macro">assert_eq!</span>(msg, data);
|
||||
|
||||
<span class="macro">info!</span>(<span class="string">"sending b -> a"</span>);
|
||||
<span class="comment">// send message from b to a
|
||||
</span><span class="kw">let </span>msg = Bytes::from(<span class="string">"howdy, a"</span>);
|
||||
client_b.send(a_key, msg.clone()).<span class="kw">await</span>.unwrap();
|
||||
<span class="kw">let </span>res = try_send_recv(<span class="kw-2">&mut </span>client_b, <span class="kw-2">&mut </span>client_a, a_key, msg.clone()).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="kw">let </span>res = client_a_receiver.recv().<span class="kw">await</span>.unwrap().unwrap();
|
||||
<span class="kw">if let </span>ReceivedMessage::ReceivedPacket {
|
||||
<span class="kw">let </span>ReceivedMessage::ReceivedPacket {
|
||||
remote_node_id,
|
||||
data,
|
||||
} = res
|
||||
{
|
||||
<span class="macro">assert_eq!</span>(b_key, remote_node_id);
|
||||
<span class="macro">assert_eq!</span>(msg, data);
|
||||
} <span class="kw">else </span>{
|
||||
<span class="kw">else </span>{
|
||||
<span class="macro">panic!</span>(<span class="string">"client_a received unexpected message {res:?}"</span>);
|
||||
}
|
||||
};
|
||||
|
||||
<span class="macro">assert_eq!</span>(b_key, remote_node_id);
|
||||
<span class="macro">assert_eq!</span>(msg, data);
|
||||
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}
|
||||
|
||||
<span class="attr">#[tokio::test]
|
||||
</span><span class="kw">async fn </span>test_relay_clients_websocket_and_derp() {
|
||||
</span><span class="kw">async fn </span>test_relay_clients_websocket_and_relay() -> <span class="prelude-ty">Result</span><()> {
|
||||
<span class="kw">let </span>_guard = iroh_test::logging::setup();
|
||||
<span class="kw">let </span>server = spawn_local_relay().<span class="kw">await</span>.unwrap();
|
||||
|
||||
@@ -2189,41 +2142,23 @@
|
||||
</span><span class="kw">let </span>a_secret_key = SecretKey::generate(rand::thread_rng());
|
||||
<span class="kw">let </span>a_key = a_secret_key.public();
|
||||
<span class="kw">let </span>resolver = <span class="kw">crate</span>::dns::default_resolver().clone();
|
||||
<span class="kw">let </span>(client_a, <span class="kw-2">mut </span>client_a_receiver) =
|
||||
ClientBuilder::new(relay_url.clone()).build(a_secret_key, resolver);
|
||||
<span class="kw">let </span>connect_client = client_a.clone();
|
||||
|
||||
<span class="comment">// give the relay server some time to accept connections
|
||||
</span><span class="kw">if let </span><span class="prelude-val">Err</span>(err) = tokio::time::timeout(Duration::from_secs(<span class="number">10</span>), <span class="kw">async move </span>{
|
||||
<span class="kw">loop </span>{
|
||||
<span class="kw">match </span>connect_client.connect().<span class="kw">await </span>{
|
||||
<span class="prelude-val">Ok</span>(<span class="kw">_</span>) => <span class="kw">break</span>,
|
||||
<span class="prelude-val">Err</span>(err) => {
|
||||
<span class="macro">warn!</span>(<span class="string">"client unable to connect to relay server: {err:#}"</span>);
|
||||
tokio::time::sleep(Duration::from_millis(<span class="number">100</span>)).<span class="kw">await</span>;
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.<span class="kw">await
|
||||
</span>{
|
||||
<span class="macro">panic!</span>(<span class="string">"error connecting to relay server: {err:#}"</span>);
|
||||
}
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>client_a = ClientBuilder::new(relay_url.clone(), a_secret_key, resolver)
|
||||
.connect()
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="comment">// set up client b
|
||||
</span><span class="kw">let </span>b_secret_key = SecretKey::generate(rand::thread_rng());
|
||||
<span class="kw">let </span>b_key = b_secret_key.public();
|
||||
<span class="kw">let </span>resolver = <span class="kw">crate</span>::dns::default_resolver().clone();
|
||||
<span class="kw">let </span>(client_b, <span class="kw-2">mut </span>client_b_receiver) = ClientBuilder::new(relay_url.clone())
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>client_b = ClientBuilder::new(relay_url.clone(), b_secret_key, resolver)
|
||||
.protocol(Protocol::Websocket) <span class="comment">// Use websockets
|
||||
</span>.build(b_secret_key, resolver);
|
||||
client_b.connect().<span class="kw">await</span>.unwrap();
|
||||
</span>.connect()
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="comment">// send message from a to b
|
||||
</span><span class="kw">let </span>msg = Bytes::from(<span class="string">"hello, b"</span>);
|
||||
client_a.send(b_key, msg.clone()).<span class="kw">await</span>.unwrap();
|
||||
<span class="kw">let </span>res = try_send_recv(<span class="kw-2">&mut </span>client_a, <span class="kw-2">&mut </span>client_b, b_key, msg.clone()).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="kw">let </span>res = client_b_receiver.recv().<span class="kw">await</span>.unwrap().unwrap();
|
||||
<span class="kw">if let </span>ReceivedMessage::ReceivedPacket {
|
||||
remote_node_id,
|
||||
data,
|
||||
@@ -2237,9 +2172,7 @@
|
||||
|
||||
<span class="comment">// send message from b to a
|
||||
</span><span class="kw">let </span>msg = Bytes::from(<span class="string">"howdy, a"</span>);
|
||||
client_b.send(a_key, msg.clone()).<span class="kw">await</span>.unwrap();
|
||||
|
||||
<span class="kw">let </span>res = client_a_receiver.recv().<span class="kw">await</span>.unwrap().unwrap();
|
||||
<span class="kw">let </span>res = try_send_recv(<span class="kw-2">&mut </span>client_b, <span class="kw-2">&mut </span>client_a, a_key, msg.clone()).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">if let </span>ReceivedMessage::ReceivedPacket {
|
||||
remote_node_id,
|
||||
data,
|
||||
@@ -2250,6 +2183,7 @@
|
||||
} <span class="kw">else </span>{
|
||||
<span class="macro">panic!</span>(<span class="string">"client_a received unexpected message {res:?}"</span>);
|
||||
}
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}
|
||||
|
||||
<span class="attr">#[tokio::test]
|
||||
|
||||
@@ -348,7 +348,12 @@
|
||||
<a href="#347" id="347">347</a>
|
||||
<a href="#348" id="348">348</a>
|
||||
<a href="#349" id="349">349</a>
|
||||
<a href="#350" id="350">350</a></pre></div><pre class="rust"><code><span class="doccomment">//! The main event loop for the relay server.
|
||||
<a href="#350" id="350">350</a>
|
||||
<a href="#351" id="351">351</a>
|
||||
<a href="#352" id="352">352</a>
|
||||
<a href="#353" id="353">353</a>
|
||||
<a href="#354" id="354">354</a>
|
||||
<a href="#355" id="355">355</a></pre></div><pre class="rust"><code><span class="doccomment">//! The main event loop for the relay server.
|
||||
//!
|
||||
//! based on tailscale/derp/derp_server.go
|
||||
|
||||
@@ -402,7 +407,7 @@
|
||||
/// Will forcefully abort the server actor loop when dropped.
|
||||
/// For stopping gracefully, use [`ServerActorTask::close`].
|
||||
///
|
||||
/// Responsible for managing connections to relay [`Conn`](crate::RelayConn)s, sending packets from one client to another.
|
||||
/// Responsible for managing connections to a relay, sending packets from one client to another.
|
||||
</span><span class="attr">#[derive(Debug)]
|
||||
</span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">struct </span>ServerActorTask {
|
||||
<span class="doccomment">/// Specifies how long to wait before failing when writing to a client.
|
||||
@@ -599,6 +604,7 @@
|
||||
<span class="attr">#[cfg(test)]
|
||||
</span><span class="kw">mod </span>tests {
|
||||
<span class="kw">use </span>bytes::Bytes;
|
||||
<span class="kw">use </span>futures_util::SinkExt;
|
||||
<span class="kw">use </span>iroh_base::SecretKey;
|
||||
<span class="kw">use </span>tokio::io::DuplexStream;
|
||||
<span class="kw">use </span>tokio_util::codec::Framed;
|
||||
@@ -620,7 +626,7 @@
|
||||
(
|
||||
ClientConnConfig {
|
||||
node_id,
|
||||
stream: RelayedStream::Derp(Framed::new(
|
||||
stream: RelayedStream::Relay(Framed::new(
|
||||
MaybeTlsStream::Test(io),
|
||||
RelayCodec::test(),
|
||||
)),
|
||||
@@ -666,7 +672,11 @@
|
||||
|
||||
<span class="comment">// write message from b to a
|
||||
</span><span class="kw">let </span>msg = <span class="string">b"hello world!"</span>;
|
||||
<span class="kw">crate</span>::client::conn::send_packet(<span class="kw-2">&mut </span>b_io, node_id_a, Bytes::from_static(msg)).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
b_io.send(Frame::SendPacket {
|
||||
dst_key: node_id_a,
|
||||
packet: Bytes::from_static(msg),
|
||||
})
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="comment">// get message on a's reader
|
||||
</span><span class="kw">let </span>frame = recv_frame(FrameType::RecvPacket, <span class="kw-2">&mut </span>a_io).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
@@ -801,7 +801,23 @@
|
||||
<a href="#800" id="800">800</a>
|
||||
<a href="#801" id="801">801</a>
|
||||
<a href="#802" id="802">802</a>
|
||||
<a href="#803" id="803">803</a></pre></div><pre class="rust"><code><span class="doccomment">//! The server-side representation of an ongoing client relaying connection.
|
||||
<a href="#803" id="803">803</a>
|
||||
<a href="#804" id="804">804</a>
|
||||
<a href="#805" id="805">805</a>
|
||||
<a href="#806" id="806">806</a>
|
||||
<a href="#807" id="807">807</a>
|
||||
<a href="#808" id="808">808</a>
|
||||
<a href="#809" id="809">809</a>
|
||||
<a href="#810" id="810">810</a>
|
||||
<a href="#811" id="811">811</a>
|
||||
<a href="#812" id="812">812</a>
|
||||
<a href="#813" id="813">813</a>
|
||||
<a href="#814" id="814">814</a>
|
||||
<a href="#815" id="815">815</a>
|
||||
<a href="#816" id="816">816</a>
|
||||
<a href="#817" id="817">817</a>
|
||||
<a href="#818" id="818">818</a>
|
||||
<a href="#819" id="819">819</a></pre></div><pre class="rust"><code><span class="doccomment">//! The server-side representation of an ongoing client relaying connection.
|
||||
|
||||
</span><span class="kw">use </span>std::{future::Future, num::NonZeroU32, pin::Pin, sync::Arc, task::Poll, time::Duration};
|
||||
|
||||
@@ -1320,7 +1336,6 @@
|
||||
|
||||
<span class="kw">use super</span>::<span class="kw-2">*</span>;
|
||||
<span class="kw">use crate</span>::{
|
||||
client::conn,
|
||||
protos::relay::{recv_frame, FrameType, RelayCodec},
|
||||
server::streams::MaybeTlsStream,
|
||||
};
|
||||
@@ -1335,7 +1350,8 @@
|
||||
<span class="kw">let </span>(io, io_rw) = tokio::io::duplex(<span class="number">1024</span>);
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>io_rw = Framed::new(io_rw, RelayCodec::test());
|
||||
<span class="kw">let </span>(server_channel_s, <span class="kw-2">mut </span>server_channel_r) = mpsc::channel(<span class="number">10</span>);
|
||||
<span class="kw">let </span>stream = RelayedStream::Derp(Framed::new(MaybeTlsStream::Test(io), RelayCodec::test()));
|
||||
<span class="kw">let </span>stream =
|
||||
RelayedStream::Relay(Framed::new(MaybeTlsStream::Test(io), RelayCodec::test()));
|
||||
|
||||
<span class="kw">let </span>actor = Actor {
|
||||
stream: RateLimitedRelayedStream::unlimited(stream),
|
||||
@@ -1420,7 +1436,12 @@
|
||||
<span class="comment">// send packet
|
||||
</span><span class="macro">println!</span>(<span class="string">" send packet"</span>);
|
||||
<span class="kw">let </span>data = <span class="string">b"hello world!"</span>;
|
||||
conn::send_packet(<span class="kw-2">&mut </span>io_rw, target, Bytes::from_static(data)).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
io_rw
|
||||
.send(Frame::SendPacket {
|
||||
dst_key: target,
|
||||
packet: Bytes::from_static(data),
|
||||
})
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">let </span>msg = server_channel_r.recv().<span class="kw">await</span>.unwrap();
|
||||
<span class="kw">match </span>msg {
|
||||
actor::Message::SendPacket {
|
||||
@@ -1443,7 +1464,12 @@
|
||||
</span><span class="kw">let </span><span class="kw-2">mut </span>disco_data = disco::MAGIC.as_bytes().to_vec();
|
||||
disco_data.extend_from_slice(target.as_bytes());
|
||||
disco_data.extend_from_slice(data);
|
||||
conn::send_packet(<span class="kw-2">&mut </span>io_rw, target, disco_data.clone().into()).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
io_rw
|
||||
.send(Frame::SendPacket {
|
||||
dst_key: target,
|
||||
packet: disco_data.clone().into(),
|
||||
})
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">let </span>msg = server_channel_r.recv().<span class="kw">await</span>.unwrap();
|
||||
<span class="kw">match </span>msg {
|
||||
actor::Message::SendDiscoPacket {
|
||||
@@ -1475,7 +1501,8 @@
|
||||
<span class="kw">let </span>(io, io_rw) = tokio::io::duplex(<span class="number">1024</span>);
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>io_rw = Framed::new(io_rw, RelayCodec::test());
|
||||
<span class="kw">let </span>(server_channel_s, <span class="kw-2">mut </span>server_channel_r) = mpsc::channel(<span class="number">10</span>);
|
||||
<span class="kw">let </span>stream = RelayedStream::Derp(Framed::new(MaybeTlsStream::Test(io), RelayCodec::test()));
|
||||
<span class="kw">let </span>stream =
|
||||
RelayedStream::Relay(Framed::new(MaybeTlsStream::Test(io), RelayCodec::test()));
|
||||
|
||||
<span class="macro">println!</span>(<span class="string">"-- create client conn"</span>);
|
||||
<span class="kw">let </span>actor = Actor {
|
||||
@@ -1501,7 +1528,12 @@
|
||||
<span class="kw">let </span>data = <span class="string">b"hello world!"</span>;
|
||||
<span class="kw">let </span>target = SecretKey::generate(rand::thread_rng()).public();
|
||||
|
||||
conn::send_packet(<span class="kw-2">&mut </span>io_rw, target, Bytes::from_static(data)).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
io_rw
|
||||
.send(Frame::SendPacket {
|
||||
dst_key: target,
|
||||
packet: Bytes::from_static(data),
|
||||
})
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">let </span>msg = server_channel_r.recv().<span class="kw">await</span>.unwrap();
|
||||
<span class="kw">match </span>msg {
|
||||
actor::Message::SendPacket {
|
||||
@@ -1554,7 +1586,7 @@
|
||||
<span class="comment">// Build the rate limited stream.
|
||||
</span><span class="kw">let </span>(io_read, io_write) = tokio::io::duplex((LIMIT * MAX_FRAMES) <span class="kw">as _</span>);
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>frame_writer = Framed::new(io_write, RelayCodec::test());
|
||||
<span class="kw">let </span>stream = RelayedStream::Derp(Framed::new(
|
||||
<span class="kw">let </span>stream = RelayedStream::Relay(Framed::new(
|
||||
MaybeTlsStream::Test(io_read),
|
||||
RelayCodec::test(),
|
||||
));
|
||||
|
||||
@@ -561,7 +561,7 @@
|
||||
(
|
||||
ClientConnConfig {
|
||||
node_id: key,
|
||||
stream: RelayedStream::Derp(Framed::new(
|
||||
stream: RelayedStream::Relay(Framed::new(
|
||||
MaybeTlsStream::Test(io),
|
||||
RelayCodec::test(),
|
||||
)),
|
||||
|
||||
@@ -1141,12 +1141,7 @@
|
||||
<a href="#1140" id="1140">1140</a>
|
||||
<a href="#1141" id="1141">1141</a>
|
||||
<a href="#1142" id="1142">1142</a>
|
||||
<a href="#1143" id="1143">1143</a>
|
||||
<a href="#1144" id="1144">1144</a>
|
||||
<a href="#1145" id="1145">1145</a>
|
||||
<a href="#1146" id="1146">1146</a>
|
||||
<a href="#1147" id="1147">1147</a>
|
||||
<a href="#1148" id="1148">1148</a></pre></div><pre class="rust"><code><span class="kw">use </span>std::{
|
||||
<a href="#1143" id="1143">1143</a></pre></div><pre class="rust"><code><span class="kw">use </span>std::{
|
||||
collections::HashMap, future::Future, net::SocketAddr, pin::Pin, sync::Arc, time::Duration,
|
||||
};
|
||||
|
||||
@@ -1651,8 +1646,8 @@
|
||||
<span class="macro">trace!</span>(<span class="question-mark">?</span>protocol, <span class="string">"accept: start"</span>);
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>io = <span class="kw">match </span>protocol {
|
||||
Protocol::Relay => {
|
||||
<span class="macro">inc!</span>(Metrics, derp_accepts);
|
||||
RelayedStream::Derp(Framed::new(io, RelayCodec::new(<span class="self">self</span>.key_cache.clone())))
|
||||
<span class="macro">inc!</span>(Metrics, relay_accepts);
|
||||
RelayedStream::Relay(Framed::new(io, RelayCodec::new(<span class="self">self</span>.key_cache.clone())))
|
||||
}
|
||||
Protocol::Websocket => {
|
||||
<span class="macro">inc!</span>(Metrics, websocket_accepts);
|
||||
@@ -1828,17 +1823,16 @@
|
||||
<span class="kw">use </span>anyhow::Result;
|
||||
<span class="kw">use </span>bytes::Bytes;
|
||||
<span class="kw">use </span>futures_lite::StreamExt;
|
||||
<span class="kw">use </span>futures_util::SinkExt;
|
||||
<span class="kw">use </span>iroh_base::{PublicKey, SecretKey};
|
||||
<span class="kw">use </span>reqwest::Url;
|
||||
<span class="kw">use </span>tokio::{sync::mpsc, task::JoinHandle};
|
||||
<span class="kw">use </span>tokio_util::codec::{FramedRead, FramedWrite};
|
||||
<span class="kw">use </span>tracing::{info, info_span, Instrument};
|
||||
<span class="kw">use </span>tracing::info;
|
||||
<span class="kw">use </span>tracing_subscriber::{prelude::<span class="kw-2">*</span>, EnvFilter};
|
||||
|
||||
<span class="kw">use super</span>::<span class="kw-2">*</span>;
|
||||
<span class="kw">use </span><span class="kw">crate</span>::client::{
|
||||
conn::{ConnBuilder, ConnFrameStream, ConnWriter, ReceivedMessage},
|
||||
streams::{MaybeTlsStreamReader, MaybeTlsStreamWriter},
|
||||
conn::{Conn, ReceivedMessage, SendMessage},
|
||||
streams::MaybeTlsStreamChained,
|
||||
Client, ClientBuilder,
|
||||
};
|
||||
|
||||
@@ -1893,111 +1887,88 @@
|
||||
<span class="kw">let </span>relay_addr: Url = <span class="macro">format!</span>(<span class="string">"http://{addr}:{port}"</span>).parse().unwrap();
|
||||
|
||||
<span class="comment">// create clients
|
||||
</span><span class="kw">let </span>(a_key, <span class="kw-2">mut </span>a_recv, client_a_task, client_a) = {
|
||||
<span class="kw">let </span>span = <span class="macro">info_span!</span>(<span class="string">"client-a"</span>);
|
||||
<span class="kw">let </span>_guard = span.enter();
|
||||
create_test_client(a_key, relay_addr.clone())
|
||||
};
|
||||
</span><span class="kw">let </span>(a_key, <span class="kw-2">mut </span>client_a) = create_test_client(a_key, relay_addr.clone()).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="macro">info!</span>(<span class="string">"created client {a_key:?}"</span>);
|
||||
<span class="kw">let </span>(b_key, <span class="kw-2">mut </span>b_recv, client_b_task, client_b) = {
|
||||
<span class="kw">let </span>span = <span class="macro">info_span!</span>(<span class="string">"client-b"</span>);
|
||||
<span class="kw">let </span>_guard = span.enter();
|
||||
create_test_client(b_key, relay_addr)
|
||||
};
|
||||
<span class="kw">let </span>(b_key, <span class="kw-2">mut </span>client_b) = create_test_client(b_key, relay_addr).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="macro">info!</span>(<span class="string">"created client {b_key:?}"</span>);
|
||||
|
||||
<span class="macro">info!</span>(<span class="string">"ping a"</span>);
|
||||
client_a.ping().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
client_a.send(SendMessage::Ping([<span class="number">1u8</span>; <span class="number">8</span>])).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">let </span>pong = client_a.next().<span class="kw">await</span>.context(<span class="string">"eos"</span>)<span class="question-mark">??</span>;
|
||||
<span class="macro">assert!</span>(<span class="macro">matches!</span>(pong, ReceivedMessage::Pong(<span class="kw">_</span>)));
|
||||
|
||||
<span class="macro">info!</span>(<span class="string">"ping b"</span>);
|
||||
client_b.ping().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
client_b.send(SendMessage::Ping([<span class="number">2u8</span>; <span class="number">8</span>])).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">let </span>pong = client_b.next().<span class="kw">await</span>.context(<span class="string">"eos"</span>)<span class="question-mark">??</span>;
|
||||
<span class="macro">assert!</span>(<span class="macro">matches!</span>(pong, ReceivedMessage::Pong(<span class="kw">_</span>)));
|
||||
|
||||
<span class="macro">info!</span>(<span class="string">"sending message from a to b"</span>);
|
||||
<span class="kw">let </span>msg = Bytes::from_static(<span class="string">b"hi there, client b!"</span>);
|
||||
client_a.send(b_key, msg.clone()).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
client_a
|
||||
.send(SendMessage::SendPacket(b_key, msg.clone()))
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="macro">info!</span>(<span class="string">"waiting for message from a on b"</span>);
|
||||
<span class="kw">let </span>(got_key, got_msg) = b_recv.recv().<span class="kw">await</span>.expect(<span class="string">"expected message from client_a"</span>);
|
||||
<span class="kw">let </span>(got_key, got_msg) =
|
||||
process_msg(client_b.next().<span class="kw">await</span>).expect(<span class="string">"expected message from client_a"</span>);
|
||||
<span class="macro">assert_eq!</span>(a_key, got_key);
|
||||
<span class="macro">assert_eq!</span>(msg, got_msg);
|
||||
|
||||
<span class="macro">info!</span>(<span class="string">"sending message from b to a"</span>);
|
||||
<span class="kw">let </span>msg = Bytes::from_static(<span class="string">b"right back at ya, client b!"</span>);
|
||||
client_b.send(a_key, msg.clone()).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
client_b
|
||||
.send(SendMessage::SendPacket(a_key, msg.clone()))
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="macro">info!</span>(<span class="string">"waiting for message b on a"</span>);
|
||||
<span class="kw">let </span>(got_key, got_msg) = a_recv.recv().<span class="kw">await</span>.expect(<span class="string">"expected message from client_b"</span>);
|
||||
<span class="kw">let </span>(got_key, got_msg) =
|
||||
process_msg(client_a.next().<span class="kw">await</span>).expect(<span class="string">"expected message from client_b"</span>);
|
||||
<span class="macro">assert_eq!</span>(b_key, got_key);
|
||||
<span class="macro">assert_eq!</span>(msg, got_msg);
|
||||
|
||||
client_a.close().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
client_a_task.abort();
|
||||
client_b.close().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
client_b_task.abort();
|
||||
server.shutdown();
|
||||
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>create_test_client(
|
||||
key: SecretKey,
|
||||
server_url: Url,
|
||||
) -> (
|
||||
PublicKey,
|
||||
mpsc::Receiver<(PublicKey, Bytes)>,
|
||||
JoinHandle<()>,
|
||||
Client,
|
||||
) {
|
||||
<span class="kw">let </span>client = ClientBuilder::new(server_url).insecure_skip_cert_verify(<span class="bool-val">true</span>);
|
||||
<span class="kw">let </span>dns_resolver = <span class="kw">crate</span>::dns::default_resolver();
|
||||
<span class="kw">let </span>(client, <span class="kw-2">mut </span>client_reader) = client.build(key.clone(), dns_resolver.clone());
|
||||
<span class="kw">async fn </span>create_test_client(key: SecretKey, server_url: Url) -> <span class="prelude-ty">Result</span><(PublicKey, Client)> {
|
||||
<span class="kw">let </span>public_key = key.public();
|
||||
<span class="kw">let </span>(received_msg_s, received_msg_r) = tokio::sync::mpsc::channel(<span class="number">10</span>);
|
||||
<span class="kw">let </span>client_reader_task = tokio::spawn(
|
||||
<span class="kw">async move </span>{
|
||||
<span class="kw">loop </span>{
|
||||
<span class="macro">info!</span>(<span class="string">"waiting for message on {:?}"</span>, key.public());
|
||||
<span class="kw">match </span>client_reader.recv().<span class="kw">await </span>{
|
||||
<span class="prelude-val">None </span>=> {
|
||||
<span class="macro">info!</span>(<span class="string">"client received nothing"</span>);
|
||||
<span class="kw">return</span>;
|
||||
}
|
||||
<span class="prelude-val">Some</span>(<span class="prelude-val">Err</span>(e)) => {
|
||||
<span class="macro">info!</span>(<span class="string">"client {:?} `recv` error {e}"</span>, key.public());
|
||||
<span class="kw">return</span>;
|
||||
}
|
||||
<span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(msg)) => {
|
||||
<span class="macro">info!</span>(<span class="string">"got message on {:?}: {msg:?}"</span>, key.public());
|
||||
<span class="kw">if let </span>ReceivedMessage::ReceivedPacket {
|
||||
remote_node_id: source,
|
||||
data,
|
||||
} = msg
|
||||
{
|
||||
received_msg_s
|
||||
.send((source, data))
|
||||
.<span class="kw">await
|
||||
</span>.unwrap_or_else(|err| {
|
||||
<span class="macro">panic!</span>(
|
||||
<span class="string">"client {:?}, error sending message over channel: {:?}"</span>,
|
||||
key.public(),
|
||||
err
|
||||
)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
<span class="kw">let </span>dns_resolver = <span class="kw">crate</span>::dns::default_resolver();
|
||||
<span class="kw">let </span>client = ClientBuilder::new(server_url, key, dns_resolver.clone())
|
||||
.insecure_skip_cert_verify(<span class="bool-val">true</span>);
|
||||
<span class="kw">let </span>client = client.connect().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
|
||||
<span class="prelude-val">Ok</span>((public_key, client))
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>process_msg(msg: <span class="prelude-ty">Option</span><<span class="prelude-ty">Result</span><ReceivedMessage>>) -> <span class="prelude-ty">Option</span><(PublicKey, Bytes)> {
|
||||
<span class="kw">match </span>msg {
|
||||
<span class="prelude-val">Some</span>(<span class="prelude-val">Err</span>(e)) => {
|
||||
<span class="macro">info!</span>(<span class="string">"client `recv` error {e}"</span>);
|
||||
<span class="prelude-val">None
|
||||
</span>}
|
||||
<span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(msg)) => {
|
||||
<span class="macro">info!</span>(<span class="string">"got message on: {msg:?}"</span>);
|
||||
<span class="kw">if let </span>ReceivedMessage::ReceivedPacket {
|
||||
remote_node_id: source,
|
||||
data,
|
||||
} = msg
|
||||
{
|
||||
<span class="prelude-val">Some</span>((source, data))
|
||||
} <span class="kw">else </span>{
|
||||
<span class="prelude-val">None
|
||||
</span>}
|
||||
}
|
||||
.instrument(<span class="macro">info_span!</span>(<span class="string">"test-client-reader"</span>)),
|
||||
);
|
||||
(public_key, received_msg_r, client_reader_task, client)
|
||||
<span class="prelude-val">None </span>=> {
|
||||
<span class="macro">info!</span>(<span class="string">"client end of stream"</span>);
|
||||
<span class="prelude-val">None
|
||||
</span>}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="attr">#[tokio::test]
|
||||
</span><span class="kw">async fn </span>test_https_clients_and_server() -> <span class="prelude-ty">Result</span><()> {
|
||||
tracing_subscriber::registry()
|
||||
.with(tracing_subscriber::fmt::layer().with_writer(std::io::stderr))
|
||||
.with(EnvFilter::from_default_env())
|
||||
.try_init()
|
||||
.ok();
|
||||
<span class="kw">let </span>_logging = iroh_test::logging::setup();
|
||||
|
||||
<span class="kw">let </span>a_key = SecretKey::generate(rand::thread_rng());
|
||||
<span class="kw">let </span>b_key = SecretKey::generate(rand::thread_rng());
|
||||
@@ -2027,54 +1998,55 @@
|
||||
<span class="kw">let </span>url: Url = <span class="macro">format!</span>(<span class="string">"https://localhost:{port}"</span>).parse().unwrap();
|
||||
|
||||
<span class="comment">// create clients
|
||||
</span><span class="kw">let </span>(a_key, <span class="kw-2">mut </span>a_recv, client_a_task, client_a) = create_test_client(a_key, url.clone());
|
||||
</span><span class="kw">let </span>(a_key, <span class="kw-2">mut </span>client_a) = create_test_client(a_key, url.clone()).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="macro">info!</span>(<span class="string">"created client {a_key:?}"</span>);
|
||||
<span class="kw">let </span>(b_key, <span class="kw-2">mut </span>b_recv, client_b_task, client_b) = create_test_client(b_key, url);
|
||||
<span class="kw">let </span>(b_key, <span class="kw-2">mut </span>client_b) = create_test_client(b_key, url).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="macro">info!</span>(<span class="string">"created client {b_key:?}"</span>);
|
||||
|
||||
client_a.ping().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
client_b.ping().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="macro">info!</span>(<span class="string">"ping a"</span>);
|
||||
client_a.send(SendMessage::Ping([<span class="number">1u8</span>; <span class="number">8</span>])).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">let </span>pong = client_a.next().<span class="kw">await</span>.context(<span class="string">"eos"</span>)<span class="question-mark">??</span>;
|
||||
<span class="macro">assert!</span>(<span class="macro">matches!</span>(pong, ReceivedMessage::Pong(<span class="kw">_</span>)));
|
||||
|
||||
<span class="macro">info!</span>(<span class="string">"ping b"</span>);
|
||||
client_b.send(SendMessage::Ping([<span class="number">2u8</span>; <span class="number">8</span>])).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">let </span>pong = client_b.next().<span class="kw">await</span>.context(<span class="string">"eos"</span>)<span class="question-mark">??</span>;
|
||||
<span class="macro">assert!</span>(<span class="macro">matches!</span>(pong, ReceivedMessage::Pong(<span class="kw">_</span>)));
|
||||
|
||||
<span class="macro">info!</span>(<span class="string">"sending message from a to b"</span>);
|
||||
<span class="kw">let </span>msg = Bytes::from_static(<span class="string">b"hi there, client b!"</span>);
|
||||
client_a.send(b_key, msg.clone()).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
client_a
|
||||
.send(SendMessage::SendPacket(b_key, msg.clone()))
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="macro">info!</span>(<span class="string">"waiting for message from a on b"</span>);
|
||||
<span class="kw">let </span>(got_key, got_msg) = b_recv.recv().<span class="kw">await</span>.expect(<span class="string">"expected message from client_a"</span>);
|
||||
<span class="kw">let </span>(got_key, got_msg) =
|
||||
process_msg(client_b.next().<span class="kw">await</span>).expect(<span class="string">"expected message from client_a"</span>);
|
||||
<span class="macro">assert_eq!</span>(a_key, got_key);
|
||||
<span class="macro">assert_eq!</span>(msg, got_msg);
|
||||
|
||||
<span class="macro">info!</span>(<span class="string">"sending message from b to a"</span>);
|
||||
<span class="kw">let </span>msg = Bytes::from_static(<span class="string">b"right back at ya, client b!"</span>);
|
||||
client_b.send(a_key, msg.clone()).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
client_b
|
||||
.send(SendMessage::SendPacket(a_key, msg.clone()))
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="macro">info!</span>(<span class="string">"waiting for message b on a"</span>);
|
||||
<span class="kw">let </span>(got_key, got_msg) = a_recv.recv().<span class="kw">await</span>.expect(<span class="string">"expected message from client_b"</span>);
|
||||
<span class="kw">let </span>(got_key, got_msg) =
|
||||
process_msg(client_a.next().<span class="kw">await</span>).expect(<span class="string">"expected message from client_b"</span>);
|
||||
<span class="macro">assert_eq!</span>(b_key, got_key);
|
||||
<span class="macro">assert_eq!</span>(msg, got_msg);
|
||||
|
||||
server.shutdown();
|
||||
server.task_handle().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
client_a.close().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
client_a_task.abort();
|
||||
client_b.close().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
client_b_task.abort();
|
||||
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>make_test_client(secret_key: SecretKey) -> (tokio::io::DuplexStream, ConnBuilder) {
|
||||
<span class="kw">let </span>(client, server) = tokio::io::duplex(<span class="number">10</span>);
|
||||
<span class="kw">let </span>(client_reader, client_writer) = tokio::io::split(client);
|
||||
|
||||
<span class="kw">let </span>client_reader = MaybeTlsStreamReader::Mem(client_reader);
|
||||
<span class="kw">let </span>client_writer = MaybeTlsStreamWriter::Mem(client_writer);
|
||||
|
||||
<span class="kw">let </span>client_reader =
|
||||
ConnFrameStream::Derp(FramedRead::new(client_reader, RelayCodec::test()));
|
||||
<span class="kw">let </span>client_writer = ConnWriter::Derp(FramedWrite::new(client_writer, RelayCodec::test()));
|
||||
|
||||
(
|
||||
server,
|
||||
ConnBuilder::new(secret_key, <span class="prelude-val">None</span>, client_reader, client_writer),
|
||||
)
|
||||
<span class="kw">async fn </span>make_test_client(client: tokio::io::DuplexStream, key: <span class="kw-2">&</span>SecretKey) -> <span class="prelude-ty">Result</span><Conn> {
|
||||
<span class="kw">let </span>client = MaybeTlsStreamChained::Mem(client);
|
||||
<span class="kw">let </span>client = Conn::new_relay(client, KeyCache::test(), key).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="prelude-val">Ok</span>(client)
|
||||
}
|
||||
|
||||
<span class="attr">#[tokio::test]
|
||||
@@ -2095,31 +2067,33 @@
|
||||
<span class="macro">info!</span>(<span class="string">"Create client A and connect it to the server."</span>);
|
||||
<span class="kw">let </span>key_a = SecretKey::generate(rand::thread_rng());
|
||||
<span class="kw">let </span>public_key_a = key_a.public();
|
||||
<span class="kw">let </span>(rw_a, client_a_builder) = make_test_client(key_a);
|
||||
<span class="kw">let </span>(client_a, rw_a) = tokio::io::duplex(<span class="number">10</span>);
|
||||
<span class="kw">let </span>s = service.clone();
|
||||
<span class="kw">let </span>handler_task = tokio::spawn(<span class="kw">async move </span>{
|
||||
s.<span class="number">0</span>.accept(Protocol::Relay, MaybeTlsStream::Test(rw_a))
|
||||
.<span class="kw">await
|
||||
</span>});
|
||||
<span class="kw">let </span>(client_a, <span class="kw-2">mut </span>client_receiver_a) = client_a_builder.build().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>client_a = make_test_client(client_a, <span class="kw-2">&</span>key_a).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
handler_task.<span class="kw">await</span><span class="question-mark">??</span>;
|
||||
|
||||
<span class="macro">info!</span>(<span class="string">"Create client B and connect it to the server."</span>);
|
||||
<span class="kw">let </span>key_b = SecretKey::generate(rand::thread_rng());
|
||||
<span class="kw">let </span>public_key_b = key_b.public();
|
||||
<span class="kw">let </span>(rw_b, client_b_builder) = make_test_client(key_b);
|
||||
<span class="kw">let </span>(client_b, rw_b) = tokio::io::duplex(<span class="number">10</span>);
|
||||
<span class="kw">let </span>s = service.clone();
|
||||
<span class="kw">let </span>handler_task = tokio::spawn(<span class="kw">async move </span>{
|
||||
s.<span class="number">0</span>.accept(Protocol::Relay, MaybeTlsStream::Test(rw_b))
|
||||
.<span class="kw">await
|
||||
</span>});
|
||||
<span class="kw">let </span>(client_b, <span class="kw-2">mut </span>client_receiver_b) = client_b_builder.build().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>client_b = make_test_client(client_b, <span class="kw-2">&</span>key_b).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
handler_task.<span class="kw">await</span><span class="question-mark">??</span>;
|
||||
|
||||
<span class="macro">info!</span>(<span class="string">"Send message from A to B."</span>);
|
||||
<span class="kw">let </span>msg = Bytes::from_static(<span class="string">b"hello client b!!"</span>);
|
||||
client_a.send(public_key_b, msg.clone()).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">match </span>client_receiver_b.next().<span class="kw">await</span>.context(<span class="string">"eos"</span>)<span class="question-mark">?? </span>{
|
||||
client_a
|
||||
.send(SendMessage::SendPacket(public_key_b, msg.clone()))
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">match </span>client_b.next().<span class="kw">await</span>.context(<span class="string">"eos"</span>)<span class="question-mark">?? </span>{
|
||||
ReceivedMessage::ReceivedPacket {
|
||||
remote_node_id,
|
||||
data,
|
||||
@@ -2134,8 +2108,10 @@
|
||||
|
||||
<span class="macro">info!</span>(<span class="string">"Send message from B to A."</span>);
|
||||
<span class="kw">let </span>msg = Bytes::from_static(<span class="string">b"nice to meet you client a!!"</span>);
|
||||
client_b.send(public_key_a, msg.clone()).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">match </span>client_receiver_a.next().<span class="kw">await</span>.context(<span class="string">"eos"</span>)<span class="question-mark">?? </span>{
|
||||
client_b
|
||||
.send(SendMessage::SendPacket(public_key_a, msg.clone()))
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">match </span>client_a.next().<span class="kw">await</span>.context(<span class="string">"eos"</span>)<span class="question-mark">?? </span>{
|
||||
ReceivedMessage::ReceivedPacket {
|
||||
remote_node_id,
|
||||
data,
|
||||
@@ -2154,11 +2130,14 @@
|
||||
|
||||
<span class="macro">info!</span>(<span class="string">"Fail to send message from A to B."</span>);
|
||||
<span class="kw">let </span>_res = client_a
|
||||
.send(public_key_b, Bytes::from_static(<span class="string">b"try to send"</span>))
|
||||
.send(SendMessage::SendPacket(
|
||||
public_key_b,
|
||||
Bytes::from_static(<span class="string">b"try to send"</span>),
|
||||
))
|
||||
.<span class="kw">await</span>;
|
||||
<span class="comment">// TODO: this send seems to succeed currently.
|
||||
// assert!(res.is_err());
|
||||
</span><span class="macro">assert!</span>(client_receiver_b.next().<span class="kw">await</span>.is_none());
|
||||
</span><span class="macro">assert!</span>(client_b.next().<span class="kw">await</span>.is_none());
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}
|
||||
|
||||
@@ -2184,31 +2163,33 @@
|
||||
<span class="macro">info!</span>(<span class="string">"Create client A and connect it to the server."</span>);
|
||||
<span class="kw">let </span>key_a = SecretKey::generate(rand::thread_rng());
|
||||
<span class="kw">let </span>public_key_a = key_a.public();
|
||||
<span class="kw">let </span>(rw_a, client_a_builder) = make_test_client(key_a);
|
||||
<span class="kw">let </span>(client_a, rw_a) = tokio::io::duplex(<span class="number">10</span>);
|
||||
<span class="kw">let </span>s = service.clone();
|
||||
<span class="kw">let </span>handler_task = tokio::spawn(<span class="kw">async move </span>{
|
||||
s.<span class="number">0</span>.accept(Protocol::Relay, MaybeTlsStream::Test(rw_a))
|
||||
.<span class="kw">await
|
||||
</span>});
|
||||
<span class="kw">let </span>(client_a, <span class="kw-2">mut </span>client_receiver_a) = client_a_builder.build().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>client_a = make_test_client(client_a, <span class="kw-2">&</span>key_a).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
handler_task.<span class="kw">await</span><span class="question-mark">??</span>;
|
||||
|
||||
<span class="macro">info!</span>(<span class="string">"Create client B and connect it to the server."</span>);
|
||||
<span class="kw">let </span>key_b = SecretKey::generate(rand::thread_rng());
|
||||
<span class="kw">let </span>public_key_b = key_b.public();
|
||||
<span class="kw">let </span>(rw_b, client_b_builder) = make_test_client(key_b.clone());
|
||||
<span class="kw">let </span>(client_b, rw_b) = tokio::io::duplex(<span class="number">10</span>);
|
||||
<span class="kw">let </span>s = service.clone();
|
||||
<span class="kw">let </span>handler_task = tokio::spawn(<span class="kw">async move </span>{
|
||||
s.<span class="number">0</span>.accept(Protocol::Relay, MaybeTlsStream::Test(rw_b))
|
||||
.<span class="kw">await
|
||||
</span>});
|
||||
<span class="kw">let </span>(client_b, <span class="kw-2">mut </span>client_receiver_b) = client_b_builder.build().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>client_b = make_test_client(client_b, <span class="kw-2">&</span>key_b).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
handler_task.<span class="kw">await</span><span class="question-mark">??</span>;
|
||||
|
||||
<span class="macro">info!</span>(<span class="string">"Send message from A to B."</span>);
|
||||
<span class="kw">let </span>msg = Bytes::from_static(<span class="string">b"hello client b!!"</span>);
|
||||
client_a.send(public_key_b, msg.clone()).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">match </span>client_receiver_b.next().<span class="kw">await</span>.context(<span class="string">"eos"</span>)<span class="question-mark">?? </span>{
|
||||
client_a
|
||||
.send(SendMessage::SendPacket(public_key_b, msg.clone()))
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">match </span>client_b.next().<span class="kw">await</span>.context(<span class="string">"eos"</span>)<span class="question-mark">?? </span>{
|
||||
ReceivedMessage::ReceivedPacket {
|
||||
remote_node_id,
|
||||
data,
|
||||
@@ -2223,8 +2204,10 @@
|
||||
|
||||
<span class="macro">info!</span>(<span class="string">"Send message from B to A."</span>);
|
||||
<span class="kw">let </span>msg = Bytes::from_static(<span class="string">b"nice to meet you client a!!"</span>);
|
||||
client_b.send(public_key_a, msg.clone()).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">match </span>client_receiver_a.next().<span class="kw">await</span>.context(<span class="string">"eos"</span>)<span class="question-mark">?? </span>{
|
||||
client_b
|
||||
.send(SendMessage::SendPacket(public_key_a, msg.clone()))
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">match </span>client_a.next().<span class="kw">await</span>.context(<span class="string">"eos"</span>)<span class="question-mark">?? </span>{
|
||||
ReceivedMessage::ReceivedPacket {
|
||||
remote_node_id,
|
||||
data,
|
||||
@@ -2238,21 +2221,23 @@
|
||||
}
|
||||
|
||||
<span class="macro">info!</span>(<span class="string">"Create client B and connect it to the server"</span>);
|
||||
<span class="kw">let </span>(new_rw_b, new_client_b_builder) = make_test_client(key_b);
|
||||
<span class="kw">let </span>(new_client_b, new_rw_b) = tokio::io::duplex(<span class="number">10</span>);
|
||||
<span class="kw">let </span>s = service.clone();
|
||||
<span class="kw">let </span>handler_task = tokio::spawn(<span class="kw">async move </span>{
|
||||
s.<span class="number">0</span>.accept(Protocol::Relay, MaybeTlsStream::Test(new_rw_b))
|
||||
.<span class="kw">await
|
||||
</span>});
|
||||
<span class="kw">let </span>(new_client_b, <span class="kw-2">mut </span>new_client_receiver_b) = new_client_b_builder.build().<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>new_client_b = make_test_client(new_client_b, <span class="kw-2">&</span>key_b).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
handler_task.<span class="kw">await</span><span class="question-mark">??</span>;
|
||||
|
||||
<span class="comment">// assert!(client_b.recv().await.is_err());
|
||||
|
||||
</span><span class="macro">info!</span>(<span class="string">"Send message from A to B."</span>);
|
||||
<span class="kw">let </span>msg = Bytes::from_static(<span class="string">b"are you still there, b?!"</span>);
|
||||
client_a.send(public_key_b, msg.clone()).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">match </span>new_client_receiver_b.next().<span class="kw">await</span>.context(<span class="string">"eos"</span>)<span class="question-mark">?? </span>{
|
||||
client_a
|
||||
.send(SendMessage::SendPacket(public_key_b, msg.clone()))
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">match </span>new_client_b.next().<span class="kw">await</span>.context(<span class="string">"eos"</span>)<span class="question-mark">?? </span>{
|
||||
ReceivedMessage::ReceivedPacket {
|
||||
remote_node_id,
|
||||
data,
|
||||
@@ -2267,8 +2252,10 @@
|
||||
|
||||
<span class="macro">info!</span>(<span class="string">"Send message from B to A."</span>);
|
||||
<span class="kw">let </span>msg = Bytes::from_static(<span class="string">b"just had a spot of trouble but I'm back now,a!!"</span>);
|
||||
new_client_b.send(public_key_a, msg.clone()).<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">match </span>client_receiver_a.next().<span class="kw">await</span>.context(<span class="string">"eos"</span>)<span class="question-mark">?? </span>{
|
||||
new_client_b
|
||||
.send(SendMessage::SendPacket(public_key_a, msg.clone()))
|
||||
.<span class="kw">await</span><span class="question-mark">?</span>;
|
||||
<span class="kw">match </span>client_a.next().<span class="kw">await</span>.context(<span class="string">"eos"</span>)<span class="question-mark">?? </span>{
|
||||
ReceivedMessage::ReceivedPacket {
|
||||
remote_node_id,
|
||||
data,
|
||||
@@ -2286,11 +2273,14 @@
|
||||
|
||||
<span class="macro">info!</span>(<span class="string">"Sending message from A to B fails"</span>);
|
||||
<span class="kw">let </span>_res = client_a
|
||||
.send(public_key_b, Bytes::from_static(<span class="string">b"try to send"</span>))
|
||||
.send(SendMessage::SendPacket(
|
||||
public_key_b,
|
||||
Bytes::from_static(<span class="string">b"try to send"</span>),
|
||||
))
|
||||
.<span class="kw">await</span>;
|
||||
<span class="comment">// TODO: This used to pass
|
||||
// assert!(res.is_err());
|
||||
</span><span class="macro">assert!</span>(new_client_receiver_b.next().<span class="kw">await</span>.is_none());
|
||||
</span><span class="macro">assert!</span>(new_client_b.next().<span class="kw">await</span>.is_none());
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@
|
||||
<span class="doccomment">/// Number of accepted websocket connections
|
||||
</span><span class="kw">pub </span>websocket_accepts: Counter,
|
||||
<span class="doccomment">/// Number of accepted 'iroh derp http' connection upgrades
|
||||
</span><span class="kw">pub </span>derp_accepts: Counter,
|
||||
</span><span class="kw">pub </span>relay_accepts: Counter,
|
||||
<span class="comment">// TODO: enable when we can have multiple connections for one node id
|
||||
// pub duplicate_client_keys: Counter,
|
||||
// pub duplicate_client_conns: Counter,
|
||||
@@ -281,7 +281,7 @@
|
||||
unique_client_keys: Counter::new(<span class="string">"Number of unique client keys per day."</span>),
|
||||
|
||||
websocket_accepts: Counter::new(<span class="string">"Number of accepted websocket connections"</span>),
|
||||
derp_accepts: Counter::new(<span class="string">"Number of accepted 'iroh derp http' connection upgrades"</span>),
|
||||
relay_accepts: Counter::new(<span class="string">"Number of accepted 'iroh derp http' connection upgrades"</span>),
|
||||
<span class="comment">// TODO: enable when we can have multiple connections for one node id
|
||||
// pub duplicate_client_keys: Counter::new("Number of duplicate client keys."),
|
||||
// pub duplicate_client_conns: Counter::new("Number of duplicate client connections."),
|
||||
@@ -297,7 +297,7 @@
|
||||
</span>}
|
||||
}
|
||||
|
||||
<span class="doccomment">/// StunMetrics tracked for the DERPER
|
||||
<span class="doccomment">/// StunMetrics tracked for the relay server
|
||||
</span><span class="attr">#[derive(Debug, Clone, Iterable)]
|
||||
</span><span class="kw">pub struct </span>StunMetrics {
|
||||
<span class="comment">/*
|
||||
|
||||
@@ -193,7 +193,7 @@
|
||||
/// The stream receives message from the client while the sink sends them to the client.
|
||||
</span><span class="attr">#[derive(Debug)]
|
||||
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">enum </span>RelayedStream {
|
||||
Derp(Framed<MaybeTlsStream, RelayCodec>),
|
||||
Relay(Framed<MaybeTlsStream, RelayCodec>),
|
||||
Ws(WebSocketStream<MaybeTlsStream>, KeyCache),
|
||||
}
|
||||
|
||||
@@ -209,14 +209,14 @@
|
||||
|
||||
<span class="kw">fn </span>poll_ready(<span class="kw-2">mut </span><span class="self">self</span>: Pin<<span class="kw-2">&mut </span><span class="self">Self</span>>, cx: <span class="kw-2">&mut </span>Context<<span class="lifetime">'_</span>>) -> Poll<<span class="prelude-ty">Result</span><(), <span class="self">Self</span>::Error>> {
|
||||
<span class="kw">match </span><span class="kw-2">*</span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::Derp(<span class="kw-2">ref mut </span>framed) => Pin::new(framed).poll_ready(cx),
|
||||
<span class="self">Self</span>::Relay(<span class="kw-2">ref mut </span>framed) => Pin::new(framed).poll_ready(cx),
|
||||
<span class="self">Self</span>::Ws(<span class="kw-2">ref mut </span>ws, <span class="kw">_</span>) => Pin::new(ws).poll_ready(cx).map_err(tung_to_io_err),
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>start_send(<span class="kw-2">mut </span><span class="self">self</span>: Pin<<span class="kw-2">&mut </span><span class="self">Self</span>>, item: Frame) -> <span class="prelude-ty">Result</span><(), <span class="self">Self</span>::Error> {
|
||||
<span class="kw">match </span><span class="kw-2">*</span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::Derp(<span class="kw-2">ref mut </span>framed) => Pin::new(framed).start_send(item),
|
||||
<span class="self">Self</span>::Relay(<span class="kw-2">ref mut </span>framed) => Pin::new(framed).start_send(item),
|
||||
<span class="self">Self</span>::Ws(<span class="kw-2">ref mut </span>ws, <span class="kw">_</span>) => Pin::new(ws)
|
||||
.start_send(tungstenite::Message::Binary(item.encode_for_ws_msg()))
|
||||
.map_err(tung_to_io_err),
|
||||
@@ -225,14 +225,14 @@
|
||||
|
||||
<span class="kw">fn </span>poll_flush(<span class="kw-2">mut </span><span class="self">self</span>: Pin<<span class="kw-2">&mut </span><span class="self">Self</span>>, cx: <span class="kw-2">&mut </span>Context<<span class="lifetime">'_</span>>) -> Poll<<span class="prelude-ty">Result</span><(), <span class="self">Self</span>::Error>> {
|
||||
<span class="kw">match </span><span class="kw-2">*</span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::Derp(<span class="kw-2">ref mut </span>framed) => Pin::new(framed).poll_flush(cx),
|
||||
<span class="self">Self</span>::Relay(<span class="kw-2">ref mut </span>framed) => Pin::new(framed).poll_flush(cx),
|
||||
<span class="self">Self</span>::Ws(<span class="kw-2">ref mut </span>ws, <span class="kw">_</span>) => Pin::new(ws).poll_flush(cx).map_err(tung_to_io_err),
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>poll_close(<span class="kw-2">mut </span><span class="self">self</span>: Pin<<span class="kw-2">&mut </span><span class="self">Self</span>>, cx: <span class="kw-2">&mut </span>Context<<span class="lifetime">'_</span>>) -> Poll<<span class="prelude-ty">Result</span><(), <span class="self">Self</span>::Error>> {
|
||||
<span class="kw">match </span><span class="kw-2">*</span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::Derp(<span class="kw-2">ref mut </span>framed) => Pin::new(framed).poll_close(cx),
|
||||
<span class="self">Self</span>::Relay(<span class="kw-2">ref mut </span>framed) => Pin::new(framed).poll_close(cx),
|
||||
<span class="self">Self</span>::Ws(<span class="kw-2">ref mut </span>ws, <span class="kw">_</span>) => Pin::new(ws).poll_close(cx).map_err(tung_to_io_err),
|
||||
}
|
||||
}
|
||||
@@ -243,7 +243,7 @@
|
||||
|
||||
<span class="kw">fn </span>poll_next(<span class="kw-2">mut </span><span class="self">self</span>: Pin<<span class="kw-2">&mut </span><span class="self">Self</span>>, cx: <span class="kw-2">&mut </span>Context<<span class="lifetime">'_</span>>) -> Poll<<span class="prelude-ty">Option</span><<span class="self">Self</span>::Item>> {
|
||||
<span class="kw">match </span><span class="kw-2">*</span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::Derp(<span class="kw-2">ref mut </span>framed) => Pin::new(framed).poll_next(cx),
|
||||
<span class="self">Self</span>::Relay(<span class="kw-2">ref mut </span>framed) => Pin::new(framed).poll_next(cx),
|
||||
<span class="self">Self</span>::Ws(<span class="kw-2">ref mut </span>ws, <span class="kw-2">ref </span>cache) => <span class="kw">match </span>Pin::new(ws).poll_next(cx) {
|
||||
Poll::Ready(<span class="prelude-val">Some</span>(<span class="prelude-val">Ok</span>(tungstenite::Message::Binary(vec)))) => {
|
||||
Poll::Ready(<span class="prelude-val">Some</span>(Frame::decode_from_ws_msg(vec, cache)))
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,9 +1,9 @@
|
||||
(function() {
|
||||
var implementors = Object.fromEntries([["iroh",[["impl <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/error/trait.Error.html\" title=\"trait core::error::Error\">Error</a> for <a class=\"struct\" href=\"iroh/watchable/struct.Disconnected.html\" title=\"struct iroh::watchable::Disconnected\">Disconnected</a>"]]],["iroh_base",[["impl <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/error/trait.Error.html\" title=\"trait core::error::Error\">Error</a> for <a class=\"enum\" href=\"iroh_base/enum.KeyParsingError.html\" title=\"enum iroh_base::KeyParsingError\">KeyParsingError</a>"],["impl <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/error/trait.Error.html\" title=\"trait core::error::Error\">Error</a> for <a class=\"enum\" href=\"iroh_base/ticket/enum.Error.html\" title=\"enum iroh_base::ticket::Error\">Error</a>"],["impl <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/error/trait.Error.html\" title=\"trait core::error::Error\">Error</a> for <a class=\"struct\" href=\"iroh_base/struct.RelayUrlParseError.html\" title=\"struct iroh_base::RelayUrlParseError\">RelayUrlParseError</a>"]]],["iroh_relay",[["impl <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/error/trait.Error.html\" title=\"trait core::error::Error\">Error</a> for <a class=\"enum\" href=\"iroh_relay/client/enum.ClientError.html\" title=\"enum iroh_relay::client::ClientError\">ClientError</a>"],["impl <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/error/trait.Error.html\" title=\"trait core::error::Error\">Error</a> for <a class=\"enum\" href=\"iroh_relay/protos/stun/enum.Error.html\" title=\"enum iroh_relay::protos::stun::Error\">Error</a>"]]]]);
|
||||
var implementors = Object.fromEntries([["iroh",[["impl <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/error/trait.Error.html\" title=\"trait core::error::Error\">Error</a> for <a class=\"struct\" href=\"iroh/watchable/struct.Disconnected.html\" title=\"struct iroh::watchable::Disconnected\">Disconnected</a>"]]],["iroh_base",[["impl <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/error/trait.Error.html\" title=\"trait core::error::Error\">Error</a> for <a class=\"enum\" href=\"iroh_base/enum.KeyParsingError.html\" title=\"enum iroh_base::KeyParsingError\">KeyParsingError</a>"],["impl <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/error/trait.Error.html\" title=\"trait core::error::Error\">Error</a> for <a class=\"enum\" href=\"iroh_base/ticket/enum.Error.html\" title=\"enum iroh_base::ticket::Error\">Error</a>"],["impl <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/error/trait.Error.html\" title=\"trait core::error::Error\">Error</a> for <a class=\"struct\" href=\"iroh_base/struct.RelayUrlParseError.html\" title=\"struct iroh_base::RelayUrlParseError\">RelayUrlParseError</a>"]]],["iroh_relay",[["impl <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/error/trait.Error.html\" title=\"trait core::error::Error\">Error</a> for <a class=\"enum\" href=\"iroh_relay/client/enum.ConnSendError.html\" title=\"enum iroh_relay::client::ConnSendError\">ConnSendError</a>"],["impl <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/error/trait.Error.html\" title=\"trait core::error::Error\">Error</a> for <a class=\"enum\" href=\"iroh_relay/protos/stun/enum.Error.html\" title=\"enum iroh_relay::protos::stun::Error\">Error</a>"]]]]);
|
||||
if (window.register_implementors) {
|
||||
window.register_implementors(implementors);
|
||||
} else {
|
||||
window.pending_implementors = implementors;
|
||||
}
|
||||
})()
|
||||
//{"start":57,"fragment_lengths":[291,835,566]}
|
||||
//{"start":57,"fragment_lengths":[291,835,572]}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,9 +1,9 @@
|
||||
(function() {
|
||||
var implementors = Object.fromEntries([["iroh",[["impl<T: <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html\" title=\"trait core::clone::Clone\">Clone</a> + <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html\" title=\"trait core::cmp::Eq\">Eq</a>> Stream for <a class=\"struct\" href=\"iroh/watchable/struct.WatcherStream.html\" title=\"struct iroh::watchable::WatcherStream\">WatcherStream</a><T>"]]]]);
|
||||
var implementors = Object.fromEntries([["iroh",[["impl<T: <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/clone/trait.Clone.html\" title=\"trait core::clone::Clone\">Clone</a> + <a class=\"trait\" href=\"https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html\" title=\"trait core::cmp::Eq\">Eq</a>> Stream for <a class=\"struct\" href=\"iroh/watchable/struct.WatcherStream.html\" title=\"struct iroh::watchable::WatcherStream\">WatcherStream</a><T>"]]],["iroh_relay",[["impl Stream for <a class=\"struct\" href=\"iroh_relay/client/struct.Client.html\" title=\"struct iroh_relay::client::Client\">Client</a>"],["impl Stream for <a class=\"struct\" href=\"iroh_relay/client/struct.ClientStream.html\" title=\"struct iroh_relay::client::ClientStream\">ClientStream</a>"]]]]);
|
||||
if (window.register_implementors) {
|
||||
window.register_implementors(implementors);
|
||||
} else {
|
||||
window.pending_implementors = implementors;
|
||||
}
|
||||
})()
|
||||
//{"start":57,"fragment_lengths":[444]}
|
||||
//{"start":57,"fragment_lengths":[444,317]}
|
||||
@@ -0,0 +1,9 @@
|
||||
(function() {
|
||||
var implementors = Object.fromEntries([["iroh_relay",[["impl Sink<<a class=\"enum\" href=\"iroh_relay/client/enum.SendMessage.html\" title=\"enum iroh_relay::client::SendMessage\">SendMessage</a>> for <a class=\"struct\" href=\"iroh_relay/client/struct.Client.html\" title=\"struct iroh_relay::client::Client\">Client</a>"],["impl Sink<<a class=\"enum\" href=\"iroh_relay/client/enum.SendMessage.html\" title=\"enum iroh_relay::client::SendMessage\">SendMessage</a>> for <a class=\"struct\" href=\"iroh_relay/client/struct.ClientSink.html\" title=\"struct iroh_relay::client::ClientSink\">ClientSink</a>"]]]]);
|
||||
if (window.register_implementors) {
|
||||
window.register_implementors(implementors);
|
||||
} else {
|
||||
window.pending_implementors = implementors;
|
||||
}
|
||||
})()
|
||||
//{"start":57,"fragment_lengths":[580]}
|
||||
Reference in New Issue
Block a user