mirror of
https://github.com/n0-computer/iroh.git
synced 2026-12-01 00:01:52 +00:00
deploy: dbb8b13fa658c7f79e0b9a75e53d7ca05560ed51
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
@@ -3562,23 +3562,7 @@
|
||||
<a href="#3561" id="3561">3561</a>
|
||||
<a href="#3562" id="3562">3562</a>
|
||||
<a href="#3563" id="3563">3563</a>
|
||||
<a href="#3564" id="3564">3564</a>
|
||||
<a href="#3565" id="3565">3565</a>
|
||||
<a href="#3566" id="3566">3566</a>
|
||||
<a href="#3567" id="3567">3567</a>
|
||||
<a href="#3568" id="3568">3568</a>
|
||||
<a href="#3569" id="3569">3569</a>
|
||||
<a href="#3570" id="3570">3570</a>
|
||||
<a href="#3571" id="3571">3571</a>
|
||||
<a href="#3572" id="3572">3572</a>
|
||||
<a href="#3573" id="3573">3573</a>
|
||||
<a href="#3574" id="3574">3574</a>
|
||||
<a href="#3575" id="3575">3575</a>
|
||||
<a href="#3576" id="3576">3576</a>
|
||||
<a href="#3577" id="3577">3577</a>
|
||||
<a href="#3578" id="3578">3578</a>
|
||||
<a href="#3579" id="3579">3579</a>
|
||||
<a href="#3580" id="3580">3580</a></pre></div><pre class="rust"><code><span class="doccomment">//! Implements a socket that can change its communication path while in use, actively searching for the best way to communicate.
|
||||
<a href="#3564" id="3564">3564</a></pre></div><pre class="rust"><code><span class="doccomment">//! Implements a socket that can change its communication path while in use, actively searching for the best way to communicate.
|
||||
//!
|
||||
//! Based on tailscale/wgengine/magicsock
|
||||
//!
|
||||
@@ -4592,34 +4576,14 @@
|
||||
SendAddr::Relay(url) => transports::Addr::Relay(url, dst_key),
|
||||
};
|
||||
|
||||
n0_future::future::poll_fn(<span class="kw">move </span>|cx| <span class="kw">loop </span>{
|
||||
<span class="kw">match </span><span class="self">self</span>.poll_send_disco_message(cx, <span class="kw-2">&</span>dst, dst_key, <span class="kw-2">&</span>msg) {
|
||||
Poll::Ready(res) => <span class="kw">return </span>Poll::Ready(res),
|
||||
Poll::Pending => <span class="kw">match </span><span class="self">self</span>.transports.poll_writable(cx, <span class="kw-2">&</span>dst) {
|
||||
Poll::Ready(<span class="prelude-val">Ok</span>(())) => <span class="kw">continue</span>,
|
||||
Poll::Ready(<span class="prelude-val">Err</span>(err)) => <span class="kw">return </span>Poll::Ready(<span class="prelude-val">Err</span>(err)),
|
||||
Poll::Pending => <span class="kw">return </span>Poll::Pending,
|
||||
},
|
||||
}
|
||||
})
|
||||
.<span class="kw">await
|
||||
</span>}
|
||||
|
||||
<span class="kw">fn </span>poll_send_disco_message(
|
||||
<span class="kw-2">&</span><span class="self">self</span>,
|
||||
cx: <span class="kw-2">&mut </span>Context,
|
||||
dst: <span class="kw-2">&</span>transports::Addr,
|
||||
dst_key: PublicKey,
|
||||
msg: <span class="kw-2">&</span>disco::Message,
|
||||
) -> Poll<io::Result<()>> {
|
||||
<span class="macro">trace!</span>(<span class="question-mark">?</span>dst, %msg, <span class="string">"send disco message (UDP)"</span>);
|
||||
<span class="kw">if </span><span class="self">self</span>.is_closed() {
|
||||
<span class="kw">return </span>Poll::Ready(<span class="prelude-val">Err</span>(io::Error::new(
|
||||
<span class="kw">return </span><span class="prelude-val">Err</span>(io::Error::new(
|
||||
io::ErrorKind::NotConnected,
|
||||
<span class="string">"connection closed"</span>,
|
||||
)));
|
||||
));
|
||||
}
|
||||
<span class="kw">let </span>pkt = <span class="self">self</span>.encode_disco_message(dst_key, msg);
|
||||
<span class="kw">let </span>pkt = <span class="self">self</span>.encode_disco_message(dst_key, <span class="kw-2">&</span>msg);
|
||||
|
||||
<span class="kw">let </span>transmit = transports::Transmit {
|
||||
contents: <span class="kw-2">&</span>pkt,
|
||||
@@ -4627,18 +4591,22 @@
|
||||
segment_size: <span class="prelude-val">None</span>,
|
||||
};
|
||||
|
||||
<span class="kw">match </span><span class="self">self</span>.transports.poll_send(cx, dst, <span class="prelude-val">None</span>, <span class="kw-2">&</span>transmit) {
|
||||
Poll::Ready(<span class="prelude-val">Ok</span>(())) => {
|
||||
<span class="kw">let </span>dst2 = dst.clone();
|
||||
<span class="kw">match </span>n0_future::future::poll_fn(<span class="kw">move </span>|cx| {
|
||||
<span class="self">self</span>.transports.poll_send(cx, <span class="kw-2">&</span>dst2, <span class="prelude-val">None</span>, <span class="kw-2">&</span>transmit)
|
||||
})
|
||||
.<span class="kw">await
|
||||
</span>{
|
||||
<span class="prelude-val">Ok</span>(()) => {
|
||||
<span class="macro">trace!</span>(<span class="question-mark">?</span>dst, %msg, <span class="string">"sent disco message"</span>);
|
||||
<span class="self">self</span>.metrics.magicsock.sent_disco_udp.inc();
|
||||
disco_message_sent(msg, <span class="kw-2">&</span><span class="self">self</span>.metrics.magicsock);
|
||||
Poll::Ready(<span class="prelude-val">Ok</span>(()))
|
||||
disco_message_sent(<span class="kw-2">&</span>msg, <span class="kw-2">&</span><span class="self">self</span>.metrics.magicsock);
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}
|
||||
Poll::Ready(<span class="prelude-val">Err</span>(err)) => {
|
||||
<span class="prelude-val">Err</span>(err) => {
|
||||
<span class="macro">warn!</span>(<span class="question-mark">?</span>dst, <span class="question-mark">?</span>msg, <span class="question-mark">?</span>err, <span class="string">"failed to send disco message"</span>);
|
||||
Poll::Ready(<span class="prelude-val">Err</span>(err))
|
||||
<span class="prelude-val">Err</span>(err)
|
||||
}
|
||||
Poll::Pending => Poll::Pending,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -365,33 +365,7 @@
|
||||
<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></pre></div><pre class="rust"><code><span class="kw">use </span>std::{
|
||||
<a href="#367" id="367">367</a></pre></div><pre class="rust"><code><span class="kw">use </span>std::{
|
||||
io::{<span class="self">self</span>, IoSliceMut},
|
||||
net::{IpAddr, Ipv6Addr, SocketAddr, SocketAddrV6},
|
||||
pin::Pin,
|
||||
@@ -615,32 +589,6 @@
|
||||
<span class="bool-val">false
|
||||
</span>}
|
||||
|
||||
<span class="doccomment">/// Check if a transport is writable, aka sendable on, for the given `addr`.
|
||||
</span><span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn </span>poll_writable(<span class="kw-2">&</span><span class="self">self</span>, cx: <span class="kw-2">&mut </span>Context, addr: <span class="kw-2">&</span>Addr) -> Poll<io::Result<()>> {
|
||||
<span class="comment">// TODO: what about multiple matches?
|
||||
</span><span class="kw">match </span>addr {
|
||||
<span class="attr">#[cfg(wasm_browser)]
|
||||
</span>Addr::Ip(..) => Poll::Ready(<span class="prelude-val">Err</span>(io::Error::other(
|
||||
<span class="string">"IP based addressing is not supported in the browser"</span>,
|
||||
))),
|
||||
<span class="attr">#[cfg(not(wasm_browser))]
|
||||
</span>Addr::Ip(addr) => <span class="kw">match </span><span class="self">self</span>.ip.iter().find(|t| t.is_valid_send_addr(addr)) {
|
||||
<span class="prelude-val">Some</span>(t) => t.poll_writable(cx),
|
||||
<span class="prelude-val">None </span>=> Poll::Pending,
|
||||
},
|
||||
Addr::Relay(url, node_id) => {
|
||||
<span class="kw">match </span><span class="self">self
|
||||
</span>.relay
|
||||
.iter()
|
||||
.find(|t| t.is_valid_send_addr(url, node_id))
|
||||
{
|
||||
<span class="prelude-val">Some</span>(t) => t.poll_writable(cx),
|
||||
<span class="prelude-val">None </span>=> Poll::Pending,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn </span>create_sender(<span class="kw-2">&</span><span class="self">self</span>, msock: Arc<MagicSock>) -> UdpSender {
|
||||
UdpSender {
|
||||
<span class="attr">#[cfg(not(wasm_browser))]
|
||||
|
||||
@@ -149,11 +149,7 @@
|
||||
<a href="#148" id="148">148</a>
|
||||
<a href="#149" id="149">149</a>
|
||||
<a href="#150" id="150">150</a>
|
||||
<a href="#151" id="151">151</a>
|
||||
<a href="#152" id="152">152</a>
|
||||
<a href="#153" id="153">153</a>
|
||||
<a href="#154" id="154">154</a>
|
||||
<a href="#155" id="155">155</a></pre></div><pre class="rust"><code><span class="kw">use </span>std::{
|
||||
<a href="#151" id="151">151</a></pre></div><pre class="rust"><code><span class="kw">use </span>std::{
|
||||
io,
|
||||
net::{IpAddr, SocketAddr},
|
||||
sync::Arc,
|
||||
@@ -284,10 +280,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>poll_writable(<span class="kw-2">&</span><span class="self">self</span>, cx: <span class="kw-2">&mut </span>Context) -> Poll<io::Result<()>> {
|
||||
<span class="self">self</span>.socket.poll_writable(cx)
|
||||
}
|
||||
|
||||
<span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn </span>bind_addr(<span class="kw-2">&</span><span class="self">self</span>) -> SocketAddr {
|
||||
<span class="self">self</span>.bind_addr
|
||||
}
|
||||
|
||||
@@ -446,28 +446,7 @@
|
||||
<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>
|
||||
<a href="#467" id="467">467</a>
|
||||
<a href="#468" id="468">468</a>
|
||||
<a href="#469" id="469">469</a></pre></div><pre class="rust"><code><span class="kw">use </span>std::{
|
||||
<a href="#448" id="448">448</a></pre></div><pre class="rust"><code><span class="kw">use </span>std::{
|
||||
io,
|
||||
sync::Arc,
|
||||
task::{Context, Poll, Waker},
|
||||
@@ -553,14 +532,12 @@
|
||||
|
||||
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>poll_send(
|
||||
<span class="kw-2">&</span><span class="self">self</span>,
|
||||
_cx: <span class="kw-2">&mut </span>Context,
|
||||
cx: <span class="kw-2">&mut </span>Context,
|
||||
dest_url: RelayUrl,
|
||||
dest_node: NodeId,
|
||||
transmit: <span class="kw-2">&</span>Transmit<<span class="lifetime">'_</span>>,
|
||||
) -> Poll<io::Result<()>> {
|
||||
<span class="comment">// TODO: use context
|
||||
|
||||
</span><span class="kw">let </span>contents = split_packets(transmit);
|
||||
<span class="kw">let </span>contents = split_packets(transmit);
|
||||
|
||||
<span class="kw">let </span>msg = RelaySendItem {
|
||||
remote_node: dest_node,
|
||||
@@ -568,26 +545,7 @@
|
||||
datagrams: contents,
|
||||
};
|
||||
|
||||
<span class="kw">match </span><span class="self">self</span>.relay_datagram_send_channel.try_send(msg) {
|
||||
<span class="prelude-val">Ok</span>(<span class="kw">_</span>) => {
|
||||
<span class="macro">trace!</span>(node = %dest_node.fmt_short(), relay_url = %dest_url,
|
||||
<span class="string">"send relay: message queued"</span>);
|
||||
Poll::Ready(<span class="prelude-val">Ok</span>(()))
|
||||
}
|
||||
<span class="prelude-val">Err</span>(mpsc::error::TrySendError::Closed(<span class="kw">_</span>)) => {
|
||||
<span class="macro">error!</span>(node = %dest_node.fmt_short(), relay_url = %dest_url,
|
||||
<span class="string">"send relay: message dropped, channel to actor is closed"</span>);
|
||||
Poll::Ready(<span class="prelude-val">Err</span>(io::Error::new(
|
||||
io::ErrorKind::ConnectionReset,
|
||||
<span class="string">"channel to actor is closed"</span>,
|
||||
)))
|
||||
}
|
||||
<span class="prelude-val">Err</span>(mpsc::error::TrySendError::Full(<span class="kw">_</span>)) => {
|
||||
<span class="macro">warn!</span>(node = %dest_node.fmt_short(), relay_url = %dest_url,
|
||||
<span class="string">"send relay: message dropped, channel to actor is full"</span>);
|
||||
Poll::Pending
|
||||
}
|
||||
}
|
||||
<span class="self">self</span>.relay_datagram_send_channel.poll_send(cx, msg)
|
||||
}
|
||||
|
||||
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>poll_recv(
|
||||
@@ -650,10 +608,6 @@
|
||||
<span class="bool-val">true
|
||||
</span>}
|
||||
|
||||
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>poll_writable(<span class="kw-2">&</span><span class="self">self</span>, cx: <span class="kw-2">&mut </span>Context) -> Poll<io::Result<()>> {
|
||||
<span class="self">self</span>.relay_datagram_send_channel.poll_writable(cx)
|
||||
}
|
||||
|
||||
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>rebind(<span class="kw-2">&</span><span class="self">self</span>) -> io::Result<()> {
|
||||
<span class="self">self</span>.send_relay_actor(RelayActorMessage::MaybeCloseRelaysOnRebind);
|
||||
|
||||
@@ -765,30 +719,34 @@
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>RelayDatagramSendChannelSender {
|
||||
<span class="kw">fn </span>try_send(
|
||||
<span class="kw-2">&</span><span class="self">self</span>,
|
||||
item: RelaySendItem,
|
||||
) -> <span class="prelude-ty">Result</span><(), mpsc::error::TrySendError<RelaySendItem>> {
|
||||
<span class="self">self</span>.sender.try_send(item)
|
||||
}
|
||||
<span class="kw">fn </span>poll_send(<span class="kw-2">&</span><span class="self">self</span>, cx: <span class="kw-2">&mut </span>Context, item: RelaySendItem) -> Poll<io::Result<()>> {
|
||||
<span class="kw">let </span>dest_node = item.remote_node;
|
||||
<span class="kw">let </span>dest_url = item.url.clone();
|
||||
|
||||
<span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>poll_writable(<span class="kw-2">&</span><span class="self">self</span>, cx: <span class="kw-2">&mut </span>Context) -> Poll<io::Result<()>> {
|
||||
<span class="kw">match </span><span class="self">self</span>.sender.capacity() {
|
||||
<span class="number">0 </span>=> {
|
||||
<span class="kw">match </span><span class="self">self</span>.sender.try_send(item) {
|
||||
<span class="prelude-val">Ok</span>(<span class="kw">_</span>) => {
|
||||
<span class="macro">trace!</span>(node = %dest_node.fmt_short(), relay_url = %dest_url,
|
||||
<span class="string">"send relay: message queued"</span>);
|
||||
Poll::Ready(<span class="prelude-val">Ok</span>(()))
|
||||
}
|
||||
<span class="prelude-val">Err</span>(mpsc::error::TrySendError::Closed(<span class="kw">_</span>)) => {
|
||||
<span class="macro">error!</span>(node = %dest_node.fmt_short(), relay_url = %dest_url,
|
||||
<span class="string">"send relay: message dropped, channel to actor is closed"</span>);
|
||||
Poll::Ready(<span class="prelude-val">Err</span>(io::Error::new(
|
||||
io::ErrorKind::ConnectionReset,
|
||||
<span class="string">"channel to actor is closed"</span>,
|
||||
)))
|
||||
}
|
||||
<span class="prelude-val">Err</span>(mpsc::error::TrySendError::Full(<span class="kw">_</span>)) => {
|
||||
<span class="macro">warn!</span>(node = %dest_node.fmt_short(), relay_url = %dest_url,
|
||||
<span class="string">"send relay: message dropped, channel to actor is full"</span>);
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>wakers = <span class="self">self</span>.wakers.lock().expect(<span class="string">"poisoned"</span>);
|
||||
<span class="kw">if </span>!wakers.iter().any(|waker| waker.will_wake(cx.waker())) {
|
||||
wakers.push(cx.waker().clone());
|
||||
}
|
||||
drop(wakers);
|
||||
<span class="kw">if </span><span class="self">self</span>.sender.capacity() != <span class="number">0 </span>{
|
||||
<span class="comment">// We "risk" a spurious wake-up in this case, but rather that
|
||||
// than potentially skipping a receive.
|
||||
</span>Poll::Ready(<span class="prelude-val">Ok</span>(()))
|
||||
} <span class="kw">else </span>{
|
||||
Poll::Pending
|
||||
}
|
||||
Poll::Pending
|
||||
}
|
||||
<span class="kw">_ </span>=> Poll::Ready(<span class="prelude-val">Ok</span>(())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user