deploy: 712a63563b1fb67014e443fedab17eb3ac90e8be

This commit is contained in:
rklaehn
2026-04-09 08:00:20 +00:00
parent da12715003
commit 4ecfa16e8a
8 changed files with 320 additions and 327 deletions
@@ -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="Parses a `EndpointId` from iroh DNS name."><title>endpoint_id_from_txt_name in iroh_dns::attrs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.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"href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="iroh_dns" data-themes="" data-resource-suffix="" data-rustdoc-version="1.92.0-nightly (b6f0945e4 2025-10-08)" data-channel="nightly" data-search-js="search-8d3311b9.js" data-stringdex-js="stringdex-828709d0.js" data-settings-js="settings-c38705f0.js" ><script src="../../static.files/storage-e2aeef58.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-ce535bd0.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-eab170b8.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]--><rustdoc-topbar><h2><a href="#">endpoint_id_from_txt_name</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../iroh_dns/index.html">iroh_<wbr>dns</a><span class="version">0.97.0</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In iroh_<wbr>dns::<wbr>attrs</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../index.html">iroh_dns</a>::<wbr><a href="index.html">attrs</a></div><h1>Function <span class="fn">endpoint_<wbr>id_<wbr>from_<wbr>txt_<wbr>name</span>&nbsp;<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_dns/attrs.rs.html#58-73">Source</a> </span></div><pre class="rust item-decl"><code>pub fn endpoint_id_from_txt_name(name: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="type" href="../../iroh_base/key/type.EndpointId.html" title="type iroh_base::key::EndpointId">EndpointId</a>, <a class="enum" href="enum.ParseError.html" title="enum iroh_dns::attrs::ParseError">ParseError</a>&gt;</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Parses a <a href="../../iroh_base/key/type.EndpointId.html" title="type iroh_base::key::EndpointId"><code>EndpointId</code></a> from iroh DNS name.</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="Parses a `EndpointId` from iroh DNS name."><title>endpoint_id_from_txt_name in iroh_dns::attrs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.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"href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="iroh_dns" data-themes="" data-resource-suffix="" data-rustdoc-version="1.92.0-nightly (b6f0945e4 2025-10-08)" data-channel="nightly" data-search-js="search-8d3311b9.js" data-stringdex-js="stringdex-828709d0.js" data-settings-js="settings-c38705f0.js" ><script src="../../static.files/storage-e2aeef58.js"></script><script defer src="sidebar-items.js"></script><script defer src="../../static.files/main-ce535bd0.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-eab170b8.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]--><rustdoc-topbar><h2><a href="#">endpoint_id_from_txt_name</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../iroh_dns/index.html">iroh_<wbr>dns</a><span class="version">0.97.0</span></h2></div><div class="sidebar-elems"><div id="rustdoc-modnav"><h2><a href="index.html">In iroh_<wbr>dns::<wbr>attrs</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../index.html">iroh_dns</a>::<wbr><a href="index.html">attrs</a></div><h1>Function <span class="fn">endpoint_<wbr>id_<wbr>from_<wbr>txt_<wbr>name</span>&nbsp;<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_dns/attrs.rs.html#58-73">Source</a> </span></div><pre class="rust item-decl"><code>pub fn endpoint_id_from_txt_name(name: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;EndpointId, <a class="enum" href="enum.ParseError.html" title="enum iroh_dns::attrs::ParseError">ParseError</a>&gt;</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Parses a [<code>EndpointId</code>] from iroh DNS name.</p>
<p>Takes a DNS name and expects the first label to be <a href="constant.IROH_TXT_NAME.html" title="constant iroh_dns::attrs::IROH_TXT_NAME"><code>IROH_TXT_NAME</code></a> and the second
label to be a z32 encoded <a href="../../iroh_base/key/type.EndpointId.html" title="type iroh_base::key::EndpointId"><code>EndpointId</code></a>. Ignores subsequent labels.</p>
label to be a z32 encoded [<code>EndpointId</code>]. Ignores subsequent labels.</p>
</div></details></section></div></main></body></html>
+2 -2
View File
@@ -1,6 +1,6 @@
<!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="Support for handling DNS resource records for dialing by `EndpointId`."><title>iroh_dns::attrs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.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"href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="iroh_dns" data-themes="" data-resource-suffix="" data-rustdoc-version="1.92.0-nightly (b6f0945e4 2025-10-08)" data-channel="nightly" data-search-js="search-8d3311b9.js" data-stringdex-js="stringdex-828709d0.js" data-settings-js="settings-c38705f0.js" ><script src="../../static.files/storage-e2aeef58.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-ce535bd0.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-eab170b8.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]--><rustdoc-topbar><h2><a href="#">Module attrs</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../iroh_dns/index.html">iroh_<wbr>dns</a><span class="version">0.97.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module attrs</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="#constants" title="Constants">Constants</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>dns</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../index.html">iroh_dns</a></div><h1>Module <span>attrs</span>&nbsp;<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_dns/attrs.rs.html#1-188">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Support for handling DNS resource records for dialing by <a href="../../iroh_base/key/type.EndpointId.html" title="type iroh_base::key::EndpointId"><code>EndpointId</code></a>.</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="Support for handling DNS resource records for dialing by `EndpointId`."><title>iroh_dns::attrs - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.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"href="../../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../../" data-static-root-path="../../static.files/" data-current-crate="iroh_dns" data-themes="" data-resource-suffix="" data-rustdoc-version="1.92.0-nightly (b6f0945e4 2025-10-08)" data-channel="nightly" data-search-js="search-8d3311b9.js" data-stringdex-js="stringdex-828709d0.js" data-settings-js="settings-c38705f0.js" ><script src="../../static.files/storage-e2aeef58.js"></script><script defer src="../sidebar-items.js"></script><script defer src="../../static.files/main-ce535bd0.js"></script><noscript><link rel="stylesheet" href="../../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../../static.files/favicon-32x32-eab170b8.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]--><rustdoc-topbar><h2><a href="#">Module attrs</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../../iroh_dns/index.html">iroh_<wbr>dns</a><span class="version">0.97.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Module attrs</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="#constants" title="Constants">Constants</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>dns</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="../index.html">iroh_dns</a></div><h1>Module <span>attrs</span>&nbsp;<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_dns/attrs.rs.html#1-188">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Support for handling DNS resource records for dialing by [<code>EndpointId</code>].</p>
<p>DNS records are published under the following names:</p>
<p><code>_iroh.&lt;z32-endpoint-id&gt;.&lt;origin-domain&gt; TXT</code></p>
<p>The returned TXT records must contain a string value of the form <code>key=value</code> as defined
in <a href="https://www.rfc-editor.org/rfc/rfc1464">RFC1464</a>.</p>
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.TxtAttrs.html" title="struct iroh_dns::attrs::TxtAttrs">TxtAttrs</a></dt><dd>Attributes parsed from <a href="constant.IROH_TXT_NAME.html" title="constant iroh_dns::attrs::IROH_TXT_NAME"><code>IROH_TXT_NAME</code></a> TXT records.</dd></dl><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><dl class="item-table"><dt><a class="enum" href="enum.EncodingError.html" title="enum iroh_dns::attrs::EncodingError">Encoding<wbr>Error</a></dt><dt><a class="enum" href="enum.IrohAttr.html" title="enum iroh_dns::attrs::IrohAttr">Iroh<wbr>Attr</a></dt><dd>The attributes supported by iroh for <a href="constant.IROH_TXT_NAME.html" title="constant iroh_dns::attrs::IROH_TXT_NAME"><code>IROH_TXT_NAME</code></a> DNS resource records.</dd><dt><a class="enum" href="enum.ParseError.html" title="enum iroh_dns::attrs::ParseError">Parse<wbr>Error</a></dt></dl><h2 id="constants" class="section-header">Constants<a href="#constants" class="anchor">§</a></h2><dl class="item-table"><dt><a class="constant" href="constant.IROH_TXT_NAME.html" title="constant iroh_dns::attrs::IROH_TXT_NAME">IROH_<wbr>TXT_<wbr>NAME</a></dt><dd>The DNS name for the iroh TXT record.</dd></dl><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><dl class="item-table"><dt><a class="fn" href="fn.endpoint_id_from_txt_name.html" title="fn iroh_dns::attrs::endpoint_id_from_txt_name">endpoint_<wbr>id_<wbr>from_<wbr>txt_<wbr>name</a></dt><dd>Parses a <a href="../../iroh_base/key/type.EndpointId.html" title="type iroh_base::key::EndpointId"><code>EndpointId</code></a> from iroh DNS name.</dd></dl></section></div></main></body></html>
</div></details><h2 id="structs" class="section-header">Structs<a href="#structs" class="anchor">§</a></h2><dl class="item-table"><dt><a class="struct" href="struct.TxtAttrs.html" title="struct iroh_dns::attrs::TxtAttrs">TxtAttrs</a></dt><dd>Attributes parsed from <a href="constant.IROH_TXT_NAME.html" title="constant iroh_dns::attrs::IROH_TXT_NAME"><code>IROH_TXT_NAME</code></a> TXT records.</dd></dl><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><dl class="item-table"><dt><a class="enum" href="enum.EncodingError.html" title="enum iroh_dns::attrs::EncodingError">Encoding<wbr>Error</a></dt><dt><a class="enum" href="enum.IrohAttr.html" title="enum iroh_dns::attrs::IrohAttr">Iroh<wbr>Attr</a></dt><dd>The attributes supported by iroh for <a href="constant.IROH_TXT_NAME.html" title="constant iroh_dns::attrs::IROH_TXT_NAME"><code>IROH_TXT_NAME</code></a> DNS resource records.</dd><dt><a class="enum" href="enum.ParseError.html" title="enum iroh_dns::attrs::ParseError">Parse<wbr>Error</a></dt></dl><h2 id="constants" class="section-header">Constants<a href="#constants" class="anchor">§</a></h2><dl class="item-table"><dt><a class="constant" href="constant.IROH_TXT_NAME.html" title="constant iroh_dns::attrs::IROH_TXT_NAME">IROH_<wbr>TXT_<wbr>NAME</a></dt><dd>The DNS name for the iroh TXT record.</dd></dl><h2 id="functions" class="section-header">Functions<a href="#functions" class="anchor">§</a></h2><dl class="item-table"><dt><a class="fn" href="fn.endpoint_id_from_txt_name.html" title="fn iroh_dns::attrs::endpoint_id_from_txt_name">endpoint_<wbr>id_<wbr>from_<wbr>txt_<wbr>name</a></dt><dd>Parses a [<code>EndpointId</code>] from iroh DNS name.</dd></dl></section></div></main></body></html>
@@ -3,15 +3,15 @@
all attributes. Can also be used with an enum, if it implements <a href="https://doc.rust-lang.org/nightly/core/str/traits/trait.FromStr.html" title="trait core::str::traits::FromStr"><code>FromStr</code></a> and
<a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display"><code>Display</code></a>.</p>
</div></details><h2 id="implementations" class="section-header">Implementations<a href="#implementations" class="anchor">§</a></h2><div id="implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-TxtAttrs%3CT%3E" class="impl"><a class="src rightside" href="../../src/iroh_dns/attrs.rs.html#102-188">Source</a><a href="#impl-TxtAttrs%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/str/traits/trait.FromStr.html" title="trait core::str::traits::FromStr">FromStr</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/hash/trait.Hash.html" title="trait core::hash::Hash">Hash</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a>&gt; <a class="struct" href="struct.TxtAttrs.html" title="struct iroh_dns::attrs::TxtAttrs">TxtAttrs</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.from_parts" class="method"><a class="src rightside" href="../../src/iroh_dns/attrs.rs.html#104-110">Source</a><h4 class="code-header">pub fn <a href="#method.from_parts" class="fn">from_parts</a>(
endpoint_id: <a class="type" href="../../iroh_base/key/type.EndpointId.html" title="type iroh_base::key::EndpointId">EndpointId</a>,
endpoint_id: EndpointId,
pairs: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a>&lt;Item = (T, <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>)&gt;,
) -&gt; Self</h4></section></summary><div class="docblock"><p>Creates <a href="struct.TxtAttrs.html" title="struct iroh_dns::attrs::TxtAttrs"><code>TxtAttrs</code></a> from an endpoint id and an iterator of key-value pairs.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.from_strings" class="method"><a class="src rightside" href="../../src/iroh_dns/attrs.rs.html#113-131">Source</a><h4 class="code-header">pub fn <a href="#method.from_strings" class="fn">from_strings</a>(
endpoint_id: <a class="type" href="../../iroh_base/key/type.EndpointId.html" title="type iroh_base::key::EndpointId">EndpointId</a>,
endpoint_id: EndpointId,
strings: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a>&lt;Item = <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;Self, <a class="enum" href="enum.ParseError.html" title="enum iroh_dns::attrs::ParseError">ParseError</a>&gt;</h4></section></summary><div class="docblock"><p>Creates <a href="struct.TxtAttrs.html" title="struct iroh_dns::attrs::TxtAttrs"><code>TxtAttrs</code></a> from an endpoint id and an iterator of “{key}={value}” strings.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.attrs" class="method"><a class="src rightside" href="../../src/iroh_dns/attrs.rs.html#134-136">Source</a><h4 class="code-header">pub fn <a href="#method.attrs" class="fn">attrs</a>(&amp;self) -&gt; &amp;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/collections/btree/map/struct.BTreeMap.html" title="struct alloc::collections::btree::map::BTreeMap">BTreeMap</a>&lt;T, <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;&gt;</h4></section></summary><div class="docblock"><p>Returns the parsed attributes.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.endpoint_id" class="method"><a class="src rightside" href="../../src/iroh_dns/attrs.rs.html#139-141">Source</a><h4 class="code-header">pub fn <a href="#method.endpoint_id" class="fn">endpoint_id</a>(&amp;self) -&gt; <a class="type" href="../../iroh_base/key/type.EndpointId.html" title="type iroh_base::key::EndpointId">EndpointId</a></h4></section></summary><div class="docblock"><p>Returns the endpoint id.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.endpoint_id" class="method"><a class="src rightside" href="../../src/iroh_dns/attrs.rs.html#139-141">Source</a><h4 class="code-header">pub fn <a href="#method.endpoint_id" class="fn">endpoint_id</a>(&amp;self) -&gt; EndpointId</h4></section></summary><div class="docblock"><p>Returns the endpoint id.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.from_txt_lookup" class="method"><a class="src rightside" href="../../src/iroh_dns/attrs.rs.html#147-154">Source</a><h4 class="code-header">pub fn <a href="#method.from_txt_lookup" class="fn">from_txt_lookup</a>(
name: <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>,
lookup: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a>&lt;Item = impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html" title="trait core::fmt::Display">Display</a>&gt;,
@@ -24,10 +24,10 @@ values that implement <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.
</div></details><details class="toggle method-toggle" open><summary><section id="method.to_txt_strings" class="method"><a class="src rightside" href="../../src/iroh_dns/attrs.rs.html#165-169">Source</a><h4 class="code-header">pub fn <a href="#method.to_txt_strings" class="fn">to_txt_strings</a>(&amp;self) -&gt; impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/iterator/trait.Iterator.html" title="trait core::iter::traits::iterator::Iterator">Iterator</a>&lt;Item = <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt; + '_</h4></section></summary><div class="docblock"><p>Converts to <code>{key}={value}</code> strings.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.to_pkarr_signed_packet" class="method"><a class="src rightside" href="../../src/iroh_dns/attrs.rs.html#174-187">Source</a><h4 class="code-header">pub fn <a href="#method.to_pkarr_signed_packet" class="fn">to_pkarr_signed_packet</a>(
&amp;self,
secret_key: &amp;<a class="struct" href="../../iroh_base/key/struct.SecretKey.html" title="struct iroh_base::key::SecretKey">SecretKey</a>,
secret_key: &amp;SecretKey,
ttl: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>,
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="../pkarr/struct.SignedPacket.html" title="struct iroh_dns::pkarr::SignedPacket">SignedPacket</a>, <a class="enum" href="enum.EncodingError.html" title="enum iroh_dns::attrs::EncodingError">EncodingError</a>&gt;</h4></section></summary><div class="docblock"><p>Creates a <a href="../pkarr/struct.SignedPacket.html" title="struct iroh_dns::pkarr::SignedPacket"><code>pkarr::SignedPacket</code></a></p>
<p>This constructs a DNS packet and signs it with a <a href="../../iroh_base/key/struct.SecretKey.html" title="struct iroh_base::key::SecretKey"><code>SecretKey</code></a>.</p>
<p>This constructs a DNS packet and signs it with a [<code>SecretKey</code>].</p>
</div></details></div></details></div><h2 id="trait-implementations" class="section-header">Trait Implementations<a href="#trait-implementations" class="anchor">§</a></h2><div id="trait-implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-Debug-for-TxtAttrs%3CT%3E" class="impl"><a class="src rightside" href="../../src/iroh_dns/attrs.rs.html#96">Source</a><a href="#impl-Debug-for-TxtAttrs%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a>&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html" title="trait core::fmt::Debug">Debug</a> for <a class="struct" href="struct.TxtAttrs.html" title="struct iroh_dns::attrs::TxtAttrs">TxtAttrs</a>&lt;T&gt;</h3></section></summary><div class="impl-items"><details class="toggle method-toggle" open><summary><section id="method.fmt" class="method trait-impl"><a class="src rightside" href="../../src/iroh_dns/attrs.rs.html#96">Source</a><a href="#method.fmt" class="anchor">§</a><h4 class="code-header">fn <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt" class="fn">fmt</a>(&amp;self, f: &amp;mut <a class="struct" href="https://doc.rust-lang.org/nightly/core/fmt/struct.Formatter.html" title="struct core::fmt::Formatter">Formatter</a>&lt;'_&gt;) -&gt; <a class="type" href="https://doc.rust-lang.org/nightly/core/fmt/type.Result.html" title="type core::fmt::Result">Result</a></h4></section></summary><div class='docblock'>Formats the value using the given formatter. <a href="https://doc.rust-lang.org/nightly/core/fmt/trait.Debug.html#tymethod.fmt">Read more</a></div></details></div></details></div><h2 id="synthetic-implementations" class="section-header">Auto Trait Implementations<a href="#synthetic-implementations" class="anchor">§</a></h2><div id="synthetic-implementations-list"><section id="impl-Freeze-for-TxtAttrs%3CT%3E" class="impl"><a href="#impl-Freeze-for-TxtAttrs%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Freeze.html" title="trait core::marker::Freeze">Freeze</a> for <a class="struct" href="struct.TxtAttrs.html" title="struct iroh_dns::attrs::TxtAttrs">TxtAttrs</a>&lt;T&gt;</h3></section><section id="impl-RefUnwindSafe-for-TxtAttrs%3CT%3E" class="impl"><a href="#impl-RefUnwindSafe-for-TxtAttrs%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a> for <a class="struct" href="struct.TxtAttrs.html" title="struct iroh_dns::attrs::TxtAttrs">TxtAttrs</a>&lt;T&gt;<div class="where">where
T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/panic/unwind_safe/trait.RefUnwindSafe.html" title="trait core::panic::unwind_safe::RefUnwindSafe">RefUnwindSafe</a>,</div></h3></section><section id="impl-Send-for-TxtAttrs%3CT%3E" class="impl"><a href="#impl-Send-for-TxtAttrs%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a> for <a class="struct" href="struct.TxtAttrs.html" title="struct iroh_dns::attrs::TxtAttrs">TxtAttrs</a>&lt;T&gt;<div class="where">where
T: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Send.html" title="trait core::marker::Send">Send</a>,</div></h3></section><section id="impl-Sync-for-TxtAttrs%3CT%3E" class="impl"><a href="#impl-Sync-for-TxtAttrs%3CT%3E" class="anchor">§</a><h3 class="code-header">impl&lt;T&gt; <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sync.html" title="trait core::marker::Sync">Sync</a> for <a class="struct" href="struct.TxtAttrs.html" title="struct iroh_dns::attrs::TxtAttrs">TxtAttrs</a>&lt;T&gt;<div class="where">where
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,5 +1,5 @@
<!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="DNS-based endpoint discovery for iroh."><title>iroh_dns - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.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"href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="iroh_dns" data-themes="" data-resource-suffix="" data-rustdoc-version="1.92.0-nightly (b6f0945e4 2025-10-08)" data-channel="nightly" data-search-js="search-8d3311b9.js" data-stringdex-js="stringdex-828709d0.js" data-settings-js="settings-c38705f0.js" ><script src="../static.files/storage-e2aeef58.js"></script><script defer src="../crates.js"></script><script defer src="../static.files/main-ce535bd0.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-eab170b8.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]--><rustdoc-topbar><h2><a href="#">Crate iroh_dns</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../iroh_dns/index.html">iroh_<wbr>dns</a><span class="version">0.97.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="#modules">Crate Items</a></h3><ul class="block"><li><a href="#modules" title="Modules">Modules</a></li><li><a href="#enums" title="Enums">Enums</a></li><li><a href="#traits" title="Traits">Traits</a></li></ul></section><div id="rustdoc-modnav"></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><h1>Crate <span>iroh_<wbr>dns</span>&nbsp;<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_dns/lib.rs.html#1-59">Source</a> </span></div><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>DNS-based endpoint discovery for iroh.</p>
<p>This crate contains the core types for publishing and resolving iroh endpoint
information via DNS, using the <a href="https://pkarr.org">pkarr</a> signed packet format.</p>
</div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><dl class="item-table"><dt><a class="mod" href="attrs/index.html" title="mod iroh_dns::attrs">attrs</a></dt><dd>Support for handling DNS resource records for dialing by <a href="../iroh_base/key/type.EndpointId.html" title="type iroh_base::key::EndpointId"><code>EndpointId</code></a>.</dd><dt><a class="mod" href="pkarr/index.html" title="mod iroh_dns::pkarr">pkarr</a></dt><dd>Pkarr signed packet encoding.</dd></dl><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><dl class="item-table"><dt><a class="enum" href="enum.DecodingError.html" title="enum iroh_dns::DecodingError">Decoding<wbr>Error</a></dt></dl><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><dl class="item-table"><dt><a class="trait" href="trait.EndpointIdExt.html" title="trait iroh_dns::EndpointIdExt">Endpoint<wbr>IdExt</a></dt><dd>Extension methods for <a href="../iroh_base/key/type.EndpointId.html" title="type iroh_base::key::EndpointId"><code>EndpointId</code></a> to encode to and decode from z-base-32,
</div></details><h2 id="modules" class="section-header">Modules<a href="#modules" class="anchor">§</a></h2><dl class="item-table"><dt><a class="mod" href="attrs/index.html" title="mod iroh_dns::attrs">attrs</a></dt><dd>Support for handling DNS resource records for dialing by [<code>EndpointId</code>].</dd><dt><a class="mod" href="pkarr/index.html" title="mod iroh_dns::pkarr">pkarr</a></dt><dd>Pkarr signed packet encoding.</dd></dl><h2 id="enums" class="section-header">Enums<a href="#enums" class="anchor">§</a></h2><dl class="item-table"><dt><a class="enum" href="enum.DecodingError.html" title="enum iroh_dns::DecodingError">Decoding<wbr>Error</a></dt></dl><h2 id="traits" class="section-header">Traits<a href="#traits" class="anchor">§</a></h2><dl class="item-table"><dt><a class="trait" href="trait.EndpointIdExt.html" title="trait iroh_dns::EndpointIdExt">Endpoint<wbr>IdExt</a></dt><dd>Extension methods for [<code>EndpointId</code>] to encode to and decode from z-base-32,
which is the encoding used by <a href="https://pkarr.org">pkarr</a> domain names.</dd></dl></section></div></main></body></html>
@@ -3,7 +3,7 @@
<p>The DNS packet must be at most 1000 bytes. Total max size is 1104 bytes.</p>
</div></details><h2 id="implementations" class="section-header">Implementations<a href="#implementations" class="anchor">§</a></h2><div id="implementations-list"><details class="toggle implementors-toggle" open><summary><section id="impl-SignedPacket" class="impl"><a class="src rightside" href="../../src/iroh_dns/pkarr.rs.html#36-274">Source</a><a href="#impl-SignedPacket" class="anchor">§</a><h3 class="code-header">impl <a class="struct" href="struct.SignedPacket.html" title="struct iroh_dns::pkarr::SignedPacket">SignedPacket</a></h3></section></summary><div class="impl-items"><details class="toggle" open><summary><section id="associatedconstant.MAX_BYTES" class="associatedconstant"><a class="src rightside" href="../../src/iroh_dns/pkarr.rs.html#38">Source</a><h4 class="code-header">pub const <a href="#associatedconstant.MAX_BYTES" class="constant">MAX_BYTES</a>: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a> = 1_104usize</h4></section></summary><div class="docblock"><p>Maximum total byte size of a signed packet.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.from_txt_strings" class="method"><a class="src rightside" href="../../src/iroh_dns/pkarr.rs.html#43-85">Source</a><h4 class="code-header">pub fn <a href="#method.from_txt_strings" class="fn">from_txt_strings</a>(
secret_key: &amp;<a class="struct" href="../../iroh_base/key/struct.SecretKey.html" title="struct iroh_base::key::SecretKey">SecretKey</a>,
secret_key: &amp;SecretKey,
name: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>,
values: impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/iter/traits/collect/trait.IntoIterator.html" title="trait core::iter::traits::collect::IntoIterator">IntoIterator</a>&lt;Item = impl <a class="trait" href="https://doc.rust-lang.org/nightly/core/convert/trait.AsRef.html" title="trait core::convert::AsRef">AsRef</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>&gt;&gt;,
ttl: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>,
@@ -11,7 +11,7 @@
<p>This is the common case: multiple TXT values under the same DNS name (e.g. <code>"_iroh"</code>).</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.from_bytes" class="method"><a class="src rightside" href="../../src/iroh_dns/pkarr.rs.html#88-114">Source</a><h4 class="code-header">pub fn <a href="#method.from_bytes" class="fn">from_bytes</a>(bytes: &amp;[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>]) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="struct.SignedPacket.html" title="struct iroh_dns::pkarr::SignedPacket">SignedPacket</a>, <a class="enum" href="enum.SignedPacketVerifyError.html" title="enum iroh_dns::pkarr::SignedPacketVerifyError">SignedPacketVerifyError</a>&gt;</h4></section></summary><div class="docblock"><p>Parse and verify a signed packet from its wire representation.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.from_relay_payload" class="method"><a class="src rightside" href="../../src/iroh_dns/pkarr.rs.html#117-125">Source</a><h4 class="code-header">pub fn <a href="#method.from_relay_payload" class="fn">from_relay_payload</a>(
public_key: &amp;<a class="struct" href="../../iroh_base/key/struct.PublicKey.html" title="struct iroh_base::key::PublicKey">PublicKey</a>,
public_key: &amp;PublicKey,
payload: &amp;[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>],
) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="struct" href="struct.SignedPacket.html" title="struct iroh_dns::pkarr::SignedPacket">SignedPacket</a>, <a class="enum" href="enum.SignedPacketVerifyError.html" title="enum iroh_dns::pkarr::SignedPacketVerifyError">SignedPacketVerifyError</a>&gt;</h4></section></summary><div class="docblock"><p>Create from a public key and relay payload (signature + timestamp + dns).</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.from_bytes_unchecked" class="method"><a class="src rightside" href="../../src/iroh_dns/pkarr.rs.html#130-142">Source</a><h4 class="code-header">pub fn <a href="#method.from_bytes_unchecked" class="fn">from_bytes_unchecked</a>(
@@ -20,8 +20,8 @@
<p>Still validates minimum length and DNS parsing.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.as_bytes" class="method"><a class="src rightside" href="../../src/iroh_dns/pkarr.rs.html#145-147">Source</a><h4 class="code-header">pub fn <a href="#method.as_bytes" class="fn">as_bytes</a>(&amp;self) -&gt; &amp;[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>] <a href="#" class="tooltip" data-notable-ty="&amp;[u8]">ⓘ</a></h4></section></summary><div class="docblock"><p>Return the full serialized bytes.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.to_relay_payload" class="method"><a class="src rightside" href="../../src/iroh_dns/pkarr.rs.html#150-152">Source</a><h4 class="code-header">pub fn <a href="#method.to_relay_payload" class="fn">to_relay_payload</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>&gt; <a href="#" class="tooltip" data-notable-ty="Vec&lt;u8&gt;">ⓘ</a></h4></section></summary><div class="docblock"><p>Return the relay payload (everything after the public key).</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.public_key" class="method"><a class="src rightside" href="../../src/iroh_dns/pkarr.rs.html#155-157">Source</a><h4 class="code-header">pub fn <a href="#method.public_key" class="fn">public_key</a>(&amp;self) -&gt; <a class="struct" href="../../iroh_base/key/struct.PublicKey.html" title="struct iroh_base::key::PublicKey">PublicKey</a></h4></section></summary><div class="docblock"><p>Return the public key.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.signature" class="method"><a class="src rightside" href="../../src/iroh_dns/pkarr.rs.html#160-166">Source</a><h4 class="code-header">pub fn <a href="#method.signature" class="fn">signature</a>(&amp;self) -&gt; <a class="struct" href="../../iroh_base/key/struct.Signature.html" title="struct iroh_base::key::Signature">Signature</a></h4></section></summary><div class="docblock"><p>Return the signature.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.public_key" class="method"><a class="src rightside" href="../../src/iroh_dns/pkarr.rs.html#155-157">Source</a><h4 class="code-header">pub fn <a href="#method.public_key" class="fn">public_key</a>(&amp;self) -&gt; PublicKey</h4></section></summary><div class="docblock"><p>Return the public key.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.signature" class="method"><a class="src rightside" href="../../src/iroh_dns/pkarr.rs.html#160-166">Source</a><h4 class="code-header">pub fn <a href="#method.signature" class="fn">signature</a>(&amp;self) -&gt; Signature</h4></section></summary><div class="docblock"><p>Return the signature.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.timestamp" class="method"><a class="src rightside" href="../../src/iroh_dns/pkarr.rs.html#169-175">Source</a><h4 class="code-header">pub fn <a href="#method.timestamp" class="fn">timestamp</a>(&amp;self) -&gt; <a class="struct" href="struct.Timestamp.html" title="struct iroh_dns::pkarr::Timestamp">Timestamp</a></h4></section></summary><div class="docblock"><p>Return the timestamp.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.encoded_packet" class="method"><a class="src rightside" href="../../src/iroh_dns/pkarr.rs.html#178-180">Source</a><h4 class="code-header">pub fn <a href="#method.encoded_packet" class="fn">encoded_packet</a>(&amp;self) -&gt; &amp;[<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a>] <a href="#" class="tooltip" data-notable-ty="&amp;[u8]">ⓘ</a></h4></section></summary><div class="docblock"><p>Return the encoded DNS packet bytes.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="method.txt_records" class="method"><a class="src rightside" href="../../src/iroh_dns/pkarr.rs.html#186-217">Source</a><h4 class="code-header">pub fn <a href="#method.txt_records" class="fn">txt_records</a>(&amp;self, name: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/vec/struct.Vec.html" title="struct alloc::vec::Vec">Vec</a>&lt;<a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>&gt;</h4></section></summary><div class="docblock"><p>Iterate over TXT records under a specific DNS name.</p>
@@ -1,9 +1,9 @@
<!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="Extension methods for `EndpointId` to encode to and decode from z-base-32, which is the encoding used by pkarr domain names."><title>EndpointIdExt in iroh_dns - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Italic-81dc35de.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-MediumItalic-ccf7e434.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"href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-ca0dd0c4.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="iroh_dns" data-themes="" data-resource-suffix="" data-rustdoc-version="1.92.0-nightly (b6f0945e4 2025-10-08)" data-channel="nightly" data-search-js="search-8d3311b9.js" data-stringdex-js="stringdex-828709d0.js" data-settings-js="settings-c38705f0.js" ><script src="../static.files/storage-e2aeef58.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-ce535bd0.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-263c88ec.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-eab170b8.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc trait"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><rustdoc-topbar><h2><a href="#">EndpointIdExt</a></h2></rustdoc-topbar><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../iroh_dns/index.html">iroh_<wbr>dns</a><span class="version">0.97.0</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">Endpoint<wbr>IdExt</a></h2><h3><a href="#required-methods">Required Methods</a></h3><ul class="block"><li><a href="#tymethod.from_z32" title="from_z32">from_z32</a></li><li><a href="#tymethod.to_z32" title="to_z32">to_z32</a></li></ul><h3><a href="#foreign-impls">Implementations on Foreign Types</a></h3><ul class="block"><li><a href="#impl-EndpointIdExt-for-PublicKey" title="EndpointId">EndpointId</a></li></ul><h3><a href="#dyn-compatibility">Dyn Compatibility</a></h3><h3><a href="#implementors">Implementors</a></h3></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate iroh_<wbr>dns</a></h2></div></div></nav><div class="sidebar-resizer" title="Drag to resize sidebar"></div><main><div class="width-limiter"><section id="main-content" class="content"><div class="main-heading"><div class="rustdoc-breadcrumbs"><a href="index.html">iroh_dns</a></div><h1>Trait <span class="trait">Endpoint<wbr>IdExt</span>&nbsp;<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_dns/lib.rs.html#38-44">Source</a> </span></div><pre class="rust item-decl"><code>pub trait EndpointIdExt {
// Required methods
fn <a href="#tymethod.to_z32" class="fn">to_z32</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a>;
<span class="item-spacer"></span> fn <a href="#tymethod.from_z32" class="fn">from_z32</a>(s: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="type" href="../iroh_base/key/type.EndpointId.html" title="type iroh_base::key::EndpointId">EndpointId</a>, <a class="enum" href="enum.DecodingError.html" title="enum iroh_dns::DecodingError">DecodingError</a>&gt;;
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Extension methods for <a href="../iroh_base/key/type.EndpointId.html" title="type iroh_base::key::EndpointId"><code>EndpointId</code></a> to encode to and decode from z-base-32,
<span class="item-spacer"></span> fn <a href="#tymethod.from_z32" class="fn">from_z32</a>(s: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;EndpointId, <a class="enum" href="enum.DecodingError.html" title="enum iroh_dns::DecodingError">DecodingError</a>&gt;;
}</code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Extension methods for [<code>EndpointId</code>] to encode to and decode from z-base-32,
which is the encoding used by <a href="https://pkarr.org">pkarr</a> domain names.</p>
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.to_z32" class="method"><a class="src rightside" href="../src/iroh_dns/lib.rs.html#40">Source</a><h4 class="code-header">fn <a href="#tymethod.to_z32" class="fn">to_z32</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a></h4></section></summary><div class="docblock"><p>Encodes a <a href="../iroh_base/key/type.EndpointId.html" title="type iroh_base::key::EndpointId"><code>EndpointId</code></a> in <a href="https://philzimmermann.com/docs/human-oriented-base-32-encoding.txt">z-base-32</a> encoding.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.from_z32" class="method"><a class="src rightside" href="../src/iroh_dns/lib.rs.html#43">Source</a><h4 class="code-header">fn <a href="#tymethod.from_z32" class="fn">from_z32</a>(s: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="type" href="../iroh_base/key/type.EndpointId.html" title="type iroh_base::key::EndpointId">EndpointId</a>, <a class="enum" href="enum.DecodingError.html" title="enum iroh_dns::DecodingError">DecodingError</a>&gt;</h4></section></summary><div class="docblock"><p>Parses a <a href="../iroh_base/key/type.EndpointId.html" title="type iroh_base::key::EndpointId"><code>EndpointId</code></a> from <a href="https://philzimmermann.com/docs/human-oriented-base-32-encoding.txt">z-base-32</a> encoding.</p>
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/nightly/reference/items/traits.html#dyn-compatibility">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-EndpointIdExt-for-PublicKey" class="impl"><a class="src rightside" href="../src/iroh_dns/lib.rs.html#46-59">Source</a><a href="#impl-EndpointIdExt-for-PublicKey" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.EndpointIdExt.html" title="trait iroh_dns::EndpointIdExt">EndpointIdExt</a> for <a class="type" href="../iroh_base/key/type.EndpointId.html" title="type iroh_base::key::EndpointId">EndpointId</a></h3></section></summary><div class="impl-items"><section id="method.to_z32" class="method trait-impl"><a class="src rightside" href="../src/iroh_dns/lib.rs.html#47-49">Source</a><a href="#method.to_z32" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.to_z32" class="fn">to_z32</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a></h4></section><section id="method.from_z32" class="method trait-impl"><a class="src rightside" href="../src/iroh_dns/lib.rs.html#51-58">Source</a><a href="#method.from_z32" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.from_z32" class="fn">from_z32</a>(s: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;<a class="type" href="../iroh_base/key/type.EndpointId.html" title="type iroh_base::key::EndpointId">EndpointId</a>, <a class="enum" href="enum.DecodingError.html" title="enum iroh_dns::DecodingError">DecodingError</a>&gt;</h4></section></div></details><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"></div><script src="../trait.impl/iroh_dns/trait.EndpointIdExt.js" data-ignore-extern-crates="iroh_base" async></script></section></div></main></body></html>
</div></details><h2 id="required-methods" class="section-header">Required Methods<a href="#required-methods" class="anchor">§</a></h2><div class="methods"><details class="toggle method-toggle" open><summary><section id="tymethod.to_z32" class="method"><a class="src rightside" href="../src/iroh_dns/lib.rs.html#40">Source</a><h4 class="code-header">fn <a href="#tymethod.to_z32" class="fn">to_z32</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a></h4></section></summary><div class="docblock"><p>Encodes a [<code>EndpointId</code>] in <a href="https://philzimmermann.com/docs/human-oriented-base-32-encoding.txt">z-base-32</a> encoding.</p>
</div></details><details class="toggle method-toggle" open><summary><section id="tymethod.from_z32" class="method"><a class="src rightside" href="../src/iroh_dns/lib.rs.html#43">Source</a><h4 class="code-header">fn <a href="#tymethod.from_z32" class="fn">from_z32</a>(s: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;EndpointId, <a class="enum" href="enum.DecodingError.html" title="enum iroh_dns::DecodingError">DecodingError</a>&gt;</h4></section></summary><div class="docblock"><p>Parses a [<code>EndpointId</code>] from <a href="https://philzimmermann.com/docs/human-oriented-base-32-encoding.txt">z-base-32</a> encoding.</p>
</div></details></div><h2 id="dyn-compatibility" class="section-header">Dyn Compatibility<a href="#dyn-compatibility" class="anchor">§</a></h2><div class="dyn-compatibility-info"><p>This trait is <b>not</b> <a href="https://doc.rust-lang.org/nightly/reference/items/traits.html#dyn-compatibility">dyn compatible</a>.</p><p><i>In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.</i></p></div><h2 id="foreign-impls" class="section-header">Implementations on Foreign Types<a href="#foreign-impls" class="anchor">§</a></h2><details class="toggle implementors-toggle"><summary><section id="impl-EndpointIdExt-for-PublicKey" class="impl"><a class="src rightside" href="../src/iroh_dns/lib.rs.html#46-59">Source</a><a href="#impl-EndpointIdExt-for-PublicKey" class="anchor">§</a><h3 class="code-header">impl <a class="trait" href="trait.EndpointIdExt.html" title="trait iroh_dns::EndpointIdExt">EndpointIdExt</a> for EndpointId</h3></section></summary><div class="impl-items"><section id="method.to_z32" class="method trait-impl"><a class="src rightside" href="../src/iroh_dns/lib.rs.html#47-49">Source</a><a href="#method.to_z32" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.to_z32" class="fn">to_z32</a>(&amp;self) -&gt; <a class="struct" href="https://doc.rust-lang.org/nightly/alloc/string/struct.String.html" title="struct alloc::string::String">String</a></h4></section><section id="method.from_z32" class="method trait-impl"><a class="src rightside" href="../src/iroh_dns/lib.rs.html#51-58">Source</a><a href="#method.from_z32" class="anchor">§</a><h4 class="code-header">fn <a href="#tymethod.from_z32" class="fn">from_z32</a>(s: &amp;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.str.html">str</a>) -&gt; <a class="enum" href="https://doc.rust-lang.org/nightly/core/result/enum.Result.html" title="enum core::result::Result">Result</a>&lt;EndpointId, <a class="enum" href="enum.DecodingError.html" title="enum iroh_dns::DecodingError">DecodingError</a>&gt;</h4></section></div></details><h2 id="implementors" class="section-header">Implementors<a href="#implementors" class="anchor">§</a></h2><div id="implementors-list"></div><script src="../trait.impl/iroh_dns/trait.EndpointIdExt.js" data-ignore-extern-crates="iroh_base" async></script></section></div></main></body></html>
@@ -6,7 +6,7 @@
<a href=#6 id=6 data-nosnippet>6</a> time::{Duration, SystemTime},
<a href=#7 id=7 data-nosnippet>7</a>};
<a href=#8 id=8 data-nosnippet>8</a>
<a href=#9 id=9 data-nosnippet>9</a><span class="kw">use </span>iroh_dns::pkarr::SignedPacket;
<a href=#9 id=9 data-nosnippet>9</a><span class="kw">use </span>iroh_dns::pkarr::{SignedPacket, Timestamp};
<a href=#10 id=10 data-nosnippet>10</a><span class="kw">use </span>n0_error::{<span class="prelude-ty">Result</span>, StackResultExt, StdResultExt, anyerr};
<a href=#11 id=11 data-nosnippet>11</a><span class="kw">use </span>redb::{
<a href=#12 id=12 data-nosnippet>12</a> Database, MultimapTableDefinition, ReadableDatabase, ReadableTable, TableDefinition,
@@ -59,7 +59,7 @@
<a href=#59 id=59 data-nosnippet>59</a> </span>res: oneshot::Sender&lt;Snapshot&gt;,
<a href=#60 id=60 data-nosnippet>60</a> },
<a href=#61 id=61 data-nosnippet>61</a> CheckExpired {
<a href=#62 id=62 data-nosnippet>62</a> time: u64,
<a href=#62 id=62 data-nosnippet>62</a> time: Timestamp,
<a href=#63 id=63 data-nosnippet>63</a> key: PublicKeyBytes,
<a href=#64 id=64 data-nosnippet>64</a> },
<a href=#65 id=65 data-nosnippet>65</a>}
@@ -216,7 +216,7 @@
<a href=#216 id=216 data-nosnippet>216</a> <span class="prelude-val">Some</span>(packet) =&gt; {
<a href=#217 id=217 data-nosnippet>217</a> <span class="kw">let </span>expiry_us = <span class="self">self</span>.options.eviction.as_micros() <span class="kw">as </span>u64;
<a href=#218 id=218 data-nosnippet>218</a> <span class="kw">let </span>expired =
<a href=#219 id=219 data-nosnippet>219</a> iroh_dns::pkarr::Timestamp::from_micros(timestamp_now() - expiry_us);
<a href=#219 id=219 data-nosnippet>219</a> Timestamp::from_micros(Timestamp::now().as_micros() - expiry_us);
<a href=#220 id=220 data-nosnippet>220</a> <span class="kw">if </span>packet.timestamp() &lt; expired {
<a href=#221 id=221 data-nosnippet>221</a> tables
<a href=#222 id=222 data-nosnippet>222</a> .update_time
@@ -249,313 +249,306 @@
<a href=#249 id=249 data-nosnippet>249</a> }
<a href=#250 id=250 data-nosnippet>250</a>}
<a href=#251 id=251 data-nosnippet>251</a>
<a href=#252 id=252 data-nosnippet>252</a><span class="kw">fn </span>fmt_time(t: u64) -&gt; String {
<a href=#253 id=253 data-nosnippet>253</a> <span class="kw">let </span>duration = std::time::Duration::from_micros(t);
<a href=#252 id=252 data-nosnippet>252</a><span class="kw">fn </span>fmt_time(t: Timestamp) -&gt; String {
<a href=#253 id=253 data-nosnippet>253</a> <span class="kw">let </span>duration = std::time::Duration::from_micros(t.as_micros());
<a href=#254 id=254 data-nosnippet>254</a> humantime::format_rfc3339_micros(SystemTime::UNIX_EPOCH + duration).to_string()
<a href=#255 id=255 data-nosnippet>255</a>}
<a href=#256 id=256 data-nosnippet>256</a>
<a href=#257 id=257 data-nosnippet>257</a><span class="kw">fn </span>timestamp_now() -&gt; u64 {
<a href=#258 id=258 data-nosnippet>258</a> SystemTime::now()
<a href=#259 id=259 data-nosnippet>259</a> .duration_since(SystemTime::UNIX_EPOCH)
<a href=#260 id=260 data-nosnippet>260</a> .expect(<span class="string">"system time before UNIX epoch"</span>)
<a href=#261 id=261 data-nosnippet>261</a> .as_micros() <span class="kw">as </span>u64
<a href=#257 id=257 data-nosnippet>257</a><span class="doccomment">/// A struct similar to [`redb::Table`] but for all tables that make up the
<a href=#258 id=258 data-nosnippet>258</a>/// signed packet store.
<a href=#259 id=259 data-nosnippet>259</a></span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">struct </span>Tables&lt;<span class="lifetime">'a</span>&gt; {
<a href=#260 id=260 data-nosnippet>260</a> <span class="kw">pub </span>signed_packets: redb::Table&lt;<span class="lifetime">'a</span>, <span class="kw-2">&amp;</span><span class="lifetime">'static </span>SignedPacketsKey, <span class="kw-2">&amp;</span><span class="lifetime">'static </span>[u8]&gt;,
<a href=#261 id=261 data-nosnippet>261</a> <span class="kw">pub </span>update_time: redb::MultimapTable&lt;<span class="lifetime">'a</span>, [u8; <span class="number">8</span>], SignedPacketsKey&gt;,
<a href=#262 id=262 data-nosnippet>262</a>}
<a href=#263 id=263 data-nosnippet>263</a>
<a href=#264 id=264 data-nosnippet>264</a><span class="doccomment">/// A struct similar to [`redb::Table`] but for all tables that make up the
<a href=#265 id=265 data-nosnippet>265</a>/// signed packet store.
<a href=#266 id=266 data-nosnippet>266</a></span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">struct </span>Tables&lt;<span class="lifetime">'a</span>&gt; {
<a href=#267 id=267 data-nosnippet>267</a> <span class="kw">pub </span>signed_packets: redb::Table&lt;<span class="lifetime">'a</span>, <span class="kw-2">&amp;</span><span class="lifetime">'static </span>SignedPacketsKey, <span class="kw-2">&amp;</span><span class="lifetime">'static </span>[u8]&gt;,
<a href=#268 id=268 data-nosnippet>268</a> <span class="kw">pub </span>update_time: redb::MultimapTable&lt;<span class="lifetime">'a</span>, [u8; <span class="number">8</span>], SignedPacketsKey&gt;,
<a href=#269 id=269 data-nosnippet>269</a>}
<a href=#270 id=270 data-nosnippet>270</a>
<a href=#271 id=271 data-nosnippet>271</a><span class="kw">impl</span>&lt;<span class="lifetime">'txn</span>&gt; Tables&lt;<span class="lifetime">'txn</span>&gt; {
<a href=#272 id=272 data-nosnippet>272</a> <span class="kw">pub fn </span>new(tx: <span class="kw-2">&amp;</span><span class="lifetime">'txn </span>redb::WriteTransaction) -&gt; result::Result&lt;<span class="self">Self</span>, redb::TableError&gt; {
<a href=#273 id=273 data-nosnippet>273</a> <span class="prelude-val">Ok</span>(<span class="self">Self </span>{
<a href=#274 id=274 data-nosnippet>274</a> signed_packets: tx.open_table(SIGNED_PACKETS_TABLE)<span class="question-mark">?</span>,
<a href=#275 id=275 data-nosnippet>275</a> update_time: tx.open_multimap_table(UPDATE_TIME_TABLE)<span class="question-mark">?</span>,
<a href=#276 id=276 data-nosnippet>276</a> })
<a href=#277 id=277 data-nosnippet>277</a> }
<a href=#278 id=278 data-nosnippet>278</a>}
<a href=#279 id=279 data-nosnippet>279</a>
<a href=#280 id=280 data-nosnippet>280</a><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">struct </span>Snapshot {
<a href=#281 id=281 data-nosnippet>281</a> <span class="attr">#[allow(dead_code)]
<a href=#282 id=282 data-nosnippet>282</a> </span><span class="kw">pub </span>signed_packets: redb::ReadOnlyTable&lt;<span class="kw-2">&amp;</span><span class="lifetime">'static </span>SignedPacketsKey, <span class="kw-2">&amp;</span><span class="lifetime">'static </span>[u8]&gt;,
<a href=#283 id=283 data-nosnippet>283</a> <span class="kw">pub </span>update_time: redb::ReadOnlyMultimapTable&lt;[u8; <span class="number">8</span>], SignedPacketsKey&gt;,
<a href=#284 id=284 data-nosnippet>284</a>}
<a href=#285 id=285 data-nosnippet>285</a>
<a href=#286 id=286 data-nosnippet>286</a><span class="kw">impl </span>Snapshot {
<a href=#287 id=287 data-nosnippet>287</a> <span class="kw">pub fn </span>new(db: <span class="kw-2">&amp;</span>Database) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="self">Self</span>&gt; {
<a href=#288 id=288 data-nosnippet>288</a> <span class="kw">let </span>tx = db.begin_read().anyerr()<span class="question-mark">?</span>;
<a href=#289 id=289 data-nosnippet>289</a> <span class="prelude-val">Ok</span>(<span class="self">Self </span>{
<a href=#290 id=290 data-nosnippet>290</a> signed_packets: tx.open_table(SIGNED_PACKETS_TABLE).anyerr()<span class="question-mark">?</span>,
<a href=#291 id=291 data-nosnippet>291</a> update_time: tx.open_multimap_table(UPDATE_TIME_TABLE).anyerr()<span class="question-mark">?</span>,
<a href=#292 id=292 data-nosnippet>292</a> })
<a href=#293 id=293 data-nosnippet>293</a> }
<a href=#294 id=294 data-nosnippet>294</a>}
<a href=#295 id=295 data-nosnippet>295</a>
<a href=#296 id=296 data-nosnippet>296</a><span class="kw">impl </span>SignedPacketStore {
<a href=#297 id=297 data-nosnippet>297</a> <span class="kw">pub fn </span>persistent(
<a href=#298 id=298 data-nosnippet>298</a> path: <span class="kw">impl </span>AsRef&lt;Path&gt;,
<a href=#299 id=299 data-nosnippet>299</a> options: Options,
<a href=#300 id=300 data-nosnippet>300</a> metrics: Arc&lt;Metrics&gt;,
<a href=#301 id=301 data-nosnippet>301</a> ) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="self">Self</span>&gt; {
<a href=#302 id=302 data-nosnippet>302</a> <span class="kw">let </span>path = path.as_ref();
<a href=#303 id=303 data-nosnippet>303</a> <span class="macro">info!</span>(<span class="string">"loading packet database from {}"</span>, path.to_string_lossy());
<a href=#304 id=304 data-nosnippet>304</a> <span class="kw">if let </span><span class="prelude-val">Some</span>(parent) = path.parent() {
<a href=#305 id=305 data-nosnippet>305</a> std::fs::create_dir_all(parent).with_std_context(|<span class="kw">_</span>| {
<a href=#306 id=306 data-nosnippet>306</a> <span class="macro">format!</span>(
<a href=#307 id=307 data-nosnippet>307</a> <span class="string">"failed to create database directory at {}"</span>,
<a href=#308 id=308 data-nosnippet>308</a> path.to_string_lossy()
<a href=#309 id=309 data-nosnippet>309</a> )
<a href=#310 id=310 data-nosnippet>310</a> })<span class="question-mark">?</span>;
<a href=#311 id=311 data-nosnippet>311</a> }
<a href=#312 id=312 data-nosnippet>312</a> <span class="kw">let </span>db = Database::builder()
<a href=#313 id=313 data-nosnippet>313</a> .create(path)
<a href=#314 id=314 data-nosnippet>314</a> .std_context(<span class="string">"failed to open packet database"</span>)<span class="question-mark">?</span>;
<a href=#315 id=315 data-nosnippet>315</a> <span class="self">Self</span>::open(db, options, metrics)
<a href=#316 id=316 data-nosnippet>316</a> }
<a href=#317 id=317 data-nosnippet>317</a>
<a href=#318 id=318 data-nosnippet>318</a> <span class="kw">pub fn </span>in_memory(options: Options, metrics: Arc&lt;Metrics&gt;) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="self">Self</span>&gt; {
<a href=#319 id=319 data-nosnippet>319</a> <span class="macro">info!</span>(<span class="string">"using in-memory packet database"</span>);
<a href=#320 id=320 data-nosnippet>320</a> <span class="kw">let </span>db = Database::builder()
<a href=#321 id=321 data-nosnippet>321</a> .create_with_backend(InMemoryBackend::new())
<a href=#322 id=322 data-nosnippet>322</a> .anyerr()<span class="question-mark">?</span>;
<a href=#323 id=323 data-nosnippet>323</a> <span class="self">Self</span>::open(db, options, metrics)
<a href=#324 id=324 data-nosnippet>324</a> }
<a href=#325 id=325 data-nosnippet>325</a>
<a href=#326 id=326 data-nosnippet>326</a> <span class="kw">pub fn </span>open(db: Database, options: Options, metrics: Arc&lt;Metrics&gt;) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="self">Self</span>&gt; {
<a href=#327 id=327 data-nosnippet>327</a> <span class="comment">// create tables
<a href=#328 id=328 data-nosnippet>328</a> </span><span class="kw">let </span>write_tx = db.begin_write().anyerr()<span class="question-mark">?</span>;
<a href=#329 id=329 data-nosnippet>329</a> <span class="kw">let _ </span>= Tables::new(<span class="kw-2">&amp;</span>write_tx).anyerr()<span class="question-mark">?</span>;
<a href=#330 id=330 data-nosnippet>330</a> write_tx.commit().anyerr()<span class="question-mark">?</span>;
<a href=#331 id=331 data-nosnippet>331</a> <span class="kw">let </span>(send, recv) = mpsc::channel(<span class="number">1024</span>);
<a href=#332 id=332 data-nosnippet>332</a> <span class="kw">let </span>send2 = send.clone();
<a href=#333 id=333 data-nosnippet>333</a> <span class="kw">let </span>cancel = CancellationToken::new();
<a href=#334 id=334 data-nosnippet>334</a> <span class="kw">let </span>cancel2 = cancel.clone();
<a href=#335 id=335 data-nosnippet>335</a> <span class="kw">let </span>cancel3 = cancel.clone();
<a href=#336 id=336 data-nosnippet>336</a> <span class="kw">let </span>actor = Actor {
<a href=#337 id=337 data-nosnippet>337</a> db,
<a href=#338 id=338 data-nosnippet>338</a> recv: PeekableReceiver::new(recv),
<a href=#339 id=339 data-nosnippet>339</a> cancel: cancel2,
<a href=#340 id=340 data-nosnippet>340</a> options,
<a href=#341 id=341 data-nosnippet>341</a> metrics,
<a href=#342 id=342 data-nosnippet>342</a> };
<a href=#343 id=343 data-nosnippet>343</a> <span class="comment">// start an io thread and donate it to the tokio runtime so we can do blocking IO
<a href=#344 id=344 data-nosnippet>344</a> // inside the thread despite being in a tokio runtime
<a href=#345 id=345 data-nosnippet>345</a> </span><span class="kw">let </span>_write_thread = IoThread::new(<span class="string">"packet-store-actor"</span>, <span class="kw">move </span>|| actor.run())<span class="question-mark">?</span>;
<a href=#346 id=346 data-nosnippet>346</a> <span class="kw">let </span>_evict_thread = IoThread::new(<span class="string">"packet-store-evict"</span>, <span class="kw">move </span>|| {
<a href=#347 id=347 data-nosnippet>347</a> evict_task(send2, options, cancel3)
<a href=#348 id=348 data-nosnippet>348</a> })<span class="question-mark">?</span>;
<a href=#349 id=349 data-nosnippet>349</a> <span class="prelude-val">Ok</span>(<span class="self">Self </span>{
<a href=#350 id=350 data-nosnippet>350</a> send,
<a href=#351 id=351 data-nosnippet>351</a> cancel,
<a href=#352 id=352 data-nosnippet>352</a> _write_thread,
<a href=#353 id=353 data-nosnippet>353</a> _evict_thread,
<a href=#354 id=354 data-nosnippet>354</a> })
<a href=#355 id=355 data-nosnippet>355</a> }
<a href=#356 id=356 data-nosnippet>356</a>
<a href=#357 id=357 data-nosnippet>357</a> <span class="kw">pub async fn </span>upsert(<span class="kw-2">&amp;</span><span class="self">self</span>, packet: SignedPacket) -&gt; <span class="prelude-ty">Result</span>&lt;bool&gt; {
<a href=#358 id=358 data-nosnippet>358</a> <span class="kw">let </span>(tx, rx) = oneshot::channel();
<a href=#359 id=359 data-nosnippet>359</a> <span class="self">self</span>.send
<a href=#360 id=360 data-nosnippet>360</a> .send(Message::Upsert { packet, res: tx })
<a href=#361 id=361 data-nosnippet>361</a> .<span class="kw">await
<a href=#362 id=362 data-nosnippet>362</a> </span>.anyerr()<span class="question-mark">?</span>;
<a href=#363 id=363 data-nosnippet>363</a> rx.<span class="kw">await</span>.anyerr()
<a href=#364 id=364 data-nosnippet>364</a> }
<a href=#365 id=365 data-nosnippet>365</a>
<a href=#366 id=366 data-nosnippet>366</a> <span class="kw">pub async fn </span>get(<span class="kw-2">&amp;</span><span class="self">self</span>, key: <span class="kw-2">&amp;</span>PublicKeyBytes) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="prelude-ty">Option</span>&lt;SignedPacket&gt;&gt; {
<a href=#367 id=367 data-nosnippet>367</a> <span class="kw">let </span>(tx, rx) = oneshot::channel();
<a href=#368 id=368 data-nosnippet>368</a> <span class="self">self</span>.send
<a href=#369 id=369 data-nosnippet>369</a> .send(Message::Get { key: <span class="kw-2">*</span>key, res: tx })
<a href=#370 id=370 data-nosnippet>370</a> .<span class="kw">await
<a href=#371 id=371 data-nosnippet>371</a> </span>.anyerr()<span class="question-mark">?</span>;
<a href=#372 id=372 data-nosnippet>372</a> rx.<span class="kw">await</span>.anyerr()
<a href=#373 id=373 data-nosnippet>373</a> }
<a href=#374 id=374 data-nosnippet>374</a>
<a href=#375 id=375 data-nosnippet>375</a> <span class="kw">pub async fn </span>remove(<span class="kw-2">&amp;</span><span class="self">self</span>, key: <span class="kw-2">&amp;</span>PublicKeyBytes) -&gt; <span class="prelude-ty">Result</span>&lt;bool&gt; {
<a href=#376 id=376 data-nosnippet>376</a> <span class="kw">let </span>(tx, rx) = oneshot::channel();
<a href=#377 id=377 data-nosnippet>377</a> <span class="self">self</span>.send
<a href=#378 id=378 data-nosnippet>378</a> .send(Message::Remove { key: <span class="kw-2">*</span>key, res: tx })
<a href=#379 id=379 data-nosnippet>379</a> .<span class="kw">await
<a href=#380 id=380 data-nosnippet>380</a> </span>.anyerr()<span class="question-mark">?</span>;
<a href=#381 id=381 data-nosnippet>381</a> rx.<span class="kw">await</span>.anyerr()
<a href=#382 id=382 data-nosnippet>382</a> }
<a href=#383 id=383 data-nosnippet>383</a>}
<a href=#384 id=384 data-nosnippet>384</a>
<a href=#385 id=385 data-nosnippet>385</a><span class="doccomment">/// Serialize a signed packet for storage: `&lt;8 bytes last_seen&gt;&lt;packet bytes&gt;`.
<a href=#386 id=386 data-nosnippet>386</a></span><span class="kw">fn </span>serialize(packet: <span class="kw-2">&amp;</span>SignedPacket) -&gt; Vec&lt;u8&gt; {
<a href=#387 id=387 data-nosnippet>387</a> <span class="kw">let </span><span class="kw-2">mut </span>out = Vec::with_capacity(<span class="number">8 </span>+ packet.as_bytes().len());
<a href=#388 id=388 data-nosnippet>388</a> out.extend_from_slice(<span class="kw-2">&amp;</span>timestamp_now().to_be_bytes());
<a href=#389 id=389 data-nosnippet>389</a> out.extend_from_slice(packet.as_bytes());
<a href=#390 id=390 data-nosnippet>390</a> out
<a href=#391 id=391 data-nosnippet>391</a>}
<a href=#392 id=392 data-nosnippet>392</a>
<a href=#393 id=393 data-nosnippet>393</a><span class="doccomment">/// Deserialize a signed packet from storage format.
<a href=#394 id=394 data-nosnippet>394</a>///
<a href=#395 id=395 data-nosnippet>395</a>/// Handles backwards compatibility with older storage formats that didn't include
<a href=#396 id=396 data-nosnippet>396</a>/// the `last_seen` prefix.
<a href=#397 id=397 data-nosnippet>397</a></span><span class="kw">fn </span>deserialize(data: <span class="kw-2">&amp;</span>[u8]) -&gt; <span class="prelude-ty">Result</span>&lt;SignedPacket&gt; {
<a href=#398 id=398 data-nosnippet>398</a> <span class="comment">// Try parsing as &lt;8 bytes last_seen&gt;&lt;packet&gt; (pkarr v3 format)
<a href=#399 id=399 data-nosnippet>399</a> </span><span class="kw">if </span>data.len() &gt;= <span class="number">8
<a href=#400 id=400 data-nosnippet>400</a> </span>&amp;&amp; <span class="kw">let </span><span class="prelude-val">Ok</span>(packet) = SignedPacket::from_bytes_unchecked(<span class="kw-2">&amp;</span>data[<span class="number">8</span>..])
<a href=#401 id=401 data-nosnippet>401</a> {
<a href=#402 id=402 data-nosnippet>402</a> <span class="kw">return </span><span class="prelude-val">Ok</span>(packet);
<a href=#403 id=403 data-nosnippet>403</a> }
<a href=#404 id=404 data-nosnippet>404</a> <span class="comment">// Fall back to raw packet bytes (pre-v0.35 format without last_seen prefix)
<a href=#405 id=405 data-nosnippet>405</a> </span>SignedPacket::from_bytes_unchecked(data)
<a href=#406 id=406 data-nosnippet>406</a> .map_err(|err| <span class="macro">anyerr!</span>(<span class="string">"Failed to decode stored packet: {err:#}"</span>))
<a href=#407 id=407 data-nosnippet>407</a>}
<a href=#408 id=408 data-nosnippet>408</a>
<a href=#409 id=409 data-nosnippet>409</a><span class="kw">fn </span>get_packet(
<a href=#410 id=410 data-nosnippet>410</a> table: <span class="kw-2">&amp;</span><span class="kw">impl </span>ReadableTable&lt;<span class="kw-2">&amp;</span><span class="lifetime">'static </span>SignedPacketsKey, <span class="kw-2">&amp;</span><span class="lifetime">'static </span>[u8]&gt;,
<a href=#411 id=411 data-nosnippet>411</a> key: <span class="kw-2">&amp;</span>PublicKeyBytes,
<a href=#412 id=412 data-nosnippet>412</a>) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="prelude-ty">Option</span>&lt;SignedPacket&gt;&gt; {
<a href=#413 id=413 data-nosnippet>413</a> <span class="kw">let </span><span class="prelude-val">Some</span>(row) = table
<a href=#414 id=414 data-nosnippet>414</a> .get(key.as_ref())
<a href=#415 id=415 data-nosnippet>415</a> .std_context(<span class="string">"database fetch failed"</span>)<span class="question-mark">?
<a href=#416 id=416 data-nosnippet>416</a> </span><span class="kw">else </span>{
<a href=#417 id=417 data-nosnippet>417</a> <span class="kw">return </span><span class="prelude-val">Ok</span>(<span class="prelude-val">None</span>);
<a href=#418 id=418 data-nosnippet>418</a> };
<a href=#419 id=419 data-nosnippet>419</a> <span class="prelude-val">Ok</span>(<span class="prelude-val">Some</span>(deserialize(row.value())<span class="question-mark">?</span>))
<a href=#420 id=420 data-nosnippet>420</a>}
<a href=#421 id=421 data-nosnippet>421</a>
<a href=#422 id=422 data-nosnippet>422</a><span class="kw">async fn </span>evict_task(send: mpsc::Sender&lt;Message&gt;, options: Options, cancel: CancellationToken) {
<a href=#423 id=423 data-nosnippet>423</a> <span class="kw">let </span>cancel2 = cancel.clone();
<a href=#424 id=424 data-nosnippet>424</a> <span class="kw">let _ </span>= cancel2
<a href=#425 id=425 data-nosnippet>425</a> .run_until_cancelled(<span class="kw">async move </span>{
<a href=#426 id=426 data-nosnippet>426</a> <span class="macro">info!</span>(<span class="string">"starting evict task"</span>);
<a href=#427 id=427 data-nosnippet>427</a> <span class="kw">if let </span><span class="prelude-val">Err</span>(cause) = evict_task_inner(send, options).<span class="kw">await </span>{
<a href=#428 id=428 data-nosnippet>428</a> <span class="macro">error!</span>(<span class="string">"evict task failed: {:?}"</span>, cause);
<a href=#429 id=429 data-nosnippet>429</a> }
<a href=#430 id=430 data-nosnippet>430</a> <span class="comment">// when we are done for whatever reason we want to shut down the actor
<a href=#431 id=431 data-nosnippet>431</a> </span>cancel.cancel();
<a href=#432 id=432 data-nosnippet>432</a> })
<a href=#433 id=433 data-nosnippet>433</a> .<span class="kw">await</span>;
<a href=#434 id=434 data-nosnippet>434</a>}
<a href=#435 id=435 data-nosnippet>435</a>
<a href=#436 id=436 data-nosnippet>436</a><span class="doccomment">/// Periodically check for expired packets and remove them.
<a href=#437 id=437 data-nosnippet>437</a></span><span class="kw">async fn </span>evict_task_inner(send: mpsc::Sender&lt;Message&gt;, options: Options) -&gt; <span class="prelude-ty">Result</span>&lt;()&gt; {
<a href=#438 id=438 data-nosnippet>438</a> <span class="kw">let </span>expiry_us = options.eviction.as_micros() <span class="kw">as </span>u64;
<a href=#439 id=439 data-nosnippet>439</a> <span class="kw">loop </span>{
<a href=#440 id=440 data-nosnippet>440</a> <span class="kw">let </span>(tx, rx) = oneshot::channel();
<a href=#441 id=441 data-nosnippet>441</a> <span class="kw">let _ </span>= send.send(Message::Snapshot { res: tx }).<span class="kw">await</span>.ok();
<a href=#442 id=442 data-nosnippet>442</a> <span class="comment">// if we can't get the snapshot we exit the loop, main actor dead
<a href=#443 id=443 data-nosnippet>443</a> </span><span class="kw">let </span>snapshot = rx.<span class="kw">await</span>.std_context(<span class="string">"failed to get snapshot"</span>)<span class="question-mark">?</span>;
<a href=#444 id=444 data-nosnippet>444</a>
<a href=#445 id=445 data-nosnippet>445</a> <span class="kw">let </span>expired = timestamp_now() - expiry_us;
<a href=#446 id=446 data-nosnippet>446</a> <span class="macro">trace!</span>(<span class="string">"evicting packets older than {}"</span>, fmt_time(expired));
<a href=#447 id=447 data-nosnippet>447</a> <span class="comment">// if getting the range fails we exit the loop and shut down
<a href=#448 id=448 data-nosnippet>448</a> // if individual reads fail we log the error and limp on
<a href=#449 id=449 data-nosnippet>449</a> </span><span class="kw">for </span>item <span class="kw">in </span>snapshot
<a href=#450 id=450 data-nosnippet>450</a> .update_time
<a href=#451 id=451 data-nosnippet>451</a> .range(..expired.to_be_bytes())
<a href=#452 id=452 data-nosnippet>452</a> .anyerr()<span class="question-mark">?
<a href=#453 id=453 data-nosnippet>453</a> </span>{
<a href=#454 id=454 data-nosnippet>454</a> <span class="kw">let </span>(time, keys) = <span class="kw">match </span>item {
<a href=#455 id=455 data-nosnippet>455</a> <span class="prelude-val">Ok</span>(v) =&gt; v,
<a href=#456 id=456 data-nosnippet>456</a> <span class="prelude-val">Err</span>(e) =&gt; {
<a href=#457 id=457 data-nosnippet>457</a> <span class="macro">error!</span>(<span class="string">"failed to read update_time row {:?}"</span>, e);
<a href=#458 id=458 data-nosnippet>458</a> <span class="kw">continue</span>;
<a href=#459 id=459 data-nosnippet>459</a> }
<a href=#460 id=460 data-nosnippet>460</a> };
<a href=#461 id=461 data-nosnippet>461</a> <span class="kw">let </span>time = u64::from_be_bytes(time.value());
<a href=#462 id=462 data-nosnippet>462</a> <span class="macro">trace!</span>(<span class="string">"evicting expired packets at {}"</span>, fmt_time(time));
<a href=#463 id=463 data-nosnippet>463</a> <span class="kw">for </span>item <span class="kw">in </span>keys {
<a href=#464 id=464 data-nosnippet>464</a> <span class="kw">let </span>key = <span class="kw">match </span>item {
<a href=#465 id=465 data-nosnippet>465</a> <span class="prelude-val">Ok</span>(v) =&gt; v,
<a href=#466 id=466 data-nosnippet>466</a> <span class="prelude-val">Err</span>(e) =&gt; {
<a href=#467 id=467 data-nosnippet>467</a> <span class="macro">error!</span>(
<a href=#468 id=468 data-nosnippet>468</a> <span class="string">"failed to read update_time item at {}: {:?}"</span>,
<a href=#469 id=469 data-nosnippet>469</a> fmt_time(time),
<a href=#470 id=470 data-nosnippet>470</a> e
<a href=#471 id=471 data-nosnippet>471</a> );
<a href=#472 id=472 data-nosnippet>472</a> <span class="kw">continue</span>;
<a href=#473 id=473 data-nosnippet>473</a> }
<a href=#474 id=474 data-nosnippet>474</a> };
<a href=#475 id=475 data-nosnippet>475</a> <span class="kw">let </span>key = PublicKeyBytes::new(key.value());
<a href=#476 id=476 data-nosnippet>476</a>
<a href=#477 id=477 data-nosnippet>477</a> <span class="macro">debug!</span>(<span class="string">"evicting expired packet {} {}"</span>, fmt_time(time), key);
<a href=#478 id=478 data-nosnippet>478</a> send.send(Message::CheckExpired { time, key })
<a href=#479 id=479 data-nosnippet>479</a> .<span class="kw">await
<a href=#480 id=480 data-nosnippet>480</a> </span>.anyerr()<span class="question-mark">?</span>;
<a href=#481 id=481 data-nosnippet>481</a> }
<a href=#482 id=482 data-nosnippet>482</a> }
<a href=#483 id=483 data-nosnippet>483</a> <span class="comment">// sleep for the eviction interval so we don't constantly check
<a href=#484 id=484 data-nosnippet>484</a> </span>tokio::time::sleep(options.eviction_interval).<span class="kw">await</span>;
<a href=#485 id=485 data-nosnippet>485</a> }
<a href=#486 id=486 data-nosnippet>486</a>}
<a href=#487 id=487 data-nosnippet>487</a>
<a href=#488 id=488 data-nosnippet>488</a><span class="doccomment">/// An io thread that drives a future to completion on the current tokio runtime
<a href=#489 id=489 data-nosnippet>489</a>///
<a href=#490 id=490 data-nosnippet>490</a>/// Inside the future, blocking IO can be done without blocking one of the tokio
<a href=#491 id=491 data-nosnippet>491</a>/// pool threads.
<a href=#492 id=492 data-nosnippet>492</a></span><span class="attr">#[derive(Debug)]
<a href=#493 id=493 data-nosnippet>493</a></span><span class="kw">struct </span>IoThread {
<a href=#494 id=494 data-nosnippet>494</a> handle: <span class="prelude-ty">Option</span>&lt;std::thread::JoinHandle&lt;()&gt;&gt;,
<a href=#495 id=495 data-nosnippet>495</a>}
<a href=#496 id=496 data-nosnippet>496</a>
<a href=#497 id=497 data-nosnippet>497</a><span class="kw">impl </span>IoThread {
<a href=#498 id=498 data-nosnippet>498</a> <span class="doccomment">/// Spawn a new io thread.
<a href=#499 id=499 data-nosnippet>499</a> ///
<a href=#500 id=500 data-nosnippet>500</a> /// Calling this function requires that the current thread is running in a
<a href=#501 id=501 data-nosnippet>501</a> /// tokio runtime. It is up to the caller to make sure the future exits,
<a href=#502 id=502 data-nosnippet>502</a> /// e.g. by using a cancellation token. Otherwise, drop will block.
<a href=#503 id=503 data-nosnippet>503</a> </span><span class="kw">fn </span>new&lt;F, Fut&gt;(name: <span class="kw-2">&amp;</span>str, f: F) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="self">Self</span>&gt;
<a href=#504 id=504 data-nosnippet>504</a> <span class="kw">where
<a href=#505 id=505 data-nosnippet>505</a> </span>F: FnOnce() -&gt; Fut + Send + <span class="lifetime">'static</span>,
<a href=#506 id=506 data-nosnippet>506</a> Fut: Future&lt;Output = ()&gt;,
<a href=#507 id=507 data-nosnippet>507</a> {
<a href=#508 id=508 data-nosnippet>508</a> <span class="kw">let </span>rt = tokio::runtime::Handle::try_current().std_context(<span class="string">"get tokio handle"</span>)<span class="question-mark">?</span>;
<a href=#509 id=509 data-nosnippet>509</a> <span class="kw">let </span>handle = std::thread::Builder::new()
<a href=#510 id=510 data-nosnippet>510</a> .name(name.into())
<a href=#511 id=511 data-nosnippet>511</a> .spawn(<span class="kw">move </span>|| rt.block_on(f()))
<a href=#512 id=512 data-nosnippet>512</a> .std_context(<span class="string">"failed to spawn thread"</span>)<span class="question-mark">?</span>;
<a href=#513 id=513 data-nosnippet>513</a> <span class="prelude-val">Ok</span>(<span class="self">Self </span>{
<a href=#514 id=514 data-nosnippet>514</a> handle: <span class="prelude-val">Some</span>(handle),
<a href=#515 id=515 data-nosnippet>515</a> })
<a href=#516 id=516 data-nosnippet>516</a> }
<a href=#517 id=517 data-nosnippet>517</a>}
<a href=#518 id=518 data-nosnippet>518</a>
<a href=#519 id=519 data-nosnippet>519</a><span class="kw">impl </span>Drop <span class="kw">for </span>IoThread {
<a href=#520 id=520 data-nosnippet>520</a> <span class="kw">fn </span>drop(<span class="kw-2">&amp;mut </span><span class="self">self</span>) {
<a href=#521 id=521 data-nosnippet>521</a> <span class="kw">if let </span><span class="prelude-val">Some</span>(handle) = <span class="self">self</span>.handle.take() {
<a href=#522 id=522 data-nosnippet>522</a> <span class="kw">let _ </span>= handle.join();
<a href=#523 id=523 data-nosnippet>523</a> }
<a href=#524 id=524 data-nosnippet>524</a> }
<a href=#264 id=264 data-nosnippet>264</a><span class="kw">impl</span>&lt;<span class="lifetime">'txn</span>&gt; Tables&lt;<span class="lifetime">'txn</span>&gt; {
<a href=#265 id=265 data-nosnippet>265</a> <span class="kw">pub fn </span>new(tx: <span class="kw-2">&amp;</span><span class="lifetime">'txn </span>redb::WriteTransaction) -&gt; result::Result&lt;<span class="self">Self</span>, redb::TableError&gt; {
<a href=#266 id=266 data-nosnippet>266</a> <span class="prelude-val">Ok</span>(<span class="self">Self </span>{
<a href=#267 id=267 data-nosnippet>267</a> signed_packets: tx.open_table(SIGNED_PACKETS_TABLE)<span class="question-mark">?</span>,
<a href=#268 id=268 data-nosnippet>268</a> update_time: tx.open_multimap_table(UPDATE_TIME_TABLE)<span class="question-mark">?</span>,
<a href=#269 id=269 data-nosnippet>269</a> })
<a href=#270 id=270 data-nosnippet>270</a> }
<a href=#271 id=271 data-nosnippet>271</a>}
<a href=#272 id=272 data-nosnippet>272</a>
<a href=#273 id=273 data-nosnippet>273</a><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">struct </span>Snapshot {
<a href=#274 id=274 data-nosnippet>274</a> <span class="attr">#[allow(dead_code)]
<a href=#275 id=275 data-nosnippet>275</a> </span><span class="kw">pub </span>signed_packets: redb::ReadOnlyTable&lt;<span class="kw-2">&amp;</span><span class="lifetime">'static </span>SignedPacketsKey, <span class="kw-2">&amp;</span><span class="lifetime">'static </span>[u8]&gt;,
<a href=#276 id=276 data-nosnippet>276</a> <span class="kw">pub </span>update_time: redb::ReadOnlyMultimapTable&lt;[u8; <span class="number">8</span>], SignedPacketsKey&gt;,
<a href=#277 id=277 data-nosnippet>277</a>}
<a href=#278 id=278 data-nosnippet>278</a>
<a href=#279 id=279 data-nosnippet>279</a><span class="kw">impl </span>Snapshot {
<a href=#280 id=280 data-nosnippet>280</a> <span class="kw">pub fn </span>new(db: <span class="kw-2">&amp;</span>Database) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="self">Self</span>&gt; {
<a href=#281 id=281 data-nosnippet>281</a> <span class="kw">let </span>tx = db.begin_read().anyerr()<span class="question-mark">?</span>;
<a href=#282 id=282 data-nosnippet>282</a> <span class="prelude-val">Ok</span>(<span class="self">Self </span>{
<a href=#283 id=283 data-nosnippet>283</a> signed_packets: tx.open_table(SIGNED_PACKETS_TABLE).anyerr()<span class="question-mark">?</span>,
<a href=#284 id=284 data-nosnippet>284</a> update_time: tx.open_multimap_table(UPDATE_TIME_TABLE).anyerr()<span class="question-mark">?</span>,
<a href=#285 id=285 data-nosnippet>285</a> })
<a href=#286 id=286 data-nosnippet>286</a> }
<a href=#287 id=287 data-nosnippet>287</a>}
<a href=#288 id=288 data-nosnippet>288</a>
<a href=#289 id=289 data-nosnippet>289</a><span class="kw">impl </span>SignedPacketStore {
<a href=#290 id=290 data-nosnippet>290</a> <span class="kw">pub fn </span>persistent(
<a href=#291 id=291 data-nosnippet>291</a> path: <span class="kw">impl </span>AsRef&lt;Path&gt;,
<a href=#292 id=292 data-nosnippet>292</a> options: Options,
<a href=#293 id=293 data-nosnippet>293</a> metrics: Arc&lt;Metrics&gt;,
<a href=#294 id=294 data-nosnippet>294</a> ) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="self">Self</span>&gt; {
<a href=#295 id=295 data-nosnippet>295</a> <span class="kw">let </span>path = path.as_ref();
<a href=#296 id=296 data-nosnippet>296</a> <span class="macro">info!</span>(<span class="string">"loading packet database from {}"</span>, path.to_string_lossy());
<a href=#297 id=297 data-nosnippet>297</a> <span class="kw">if let </span><span class="prelude-val">Some</span>(parent) = path.parent() {
<a href=#298 id=298 data-nosnippet>298</a> std::fs::create_dir_all(parent).with_std_context(|<span class="kw">_</span>| {
<a href=#299 id=299 data-nosnippet>299</a> <span class="macro">format!</span>(
<a href=#300 id=300 data-nosnippet>300</a> <span class="string">"failed to create database directory at {}"</span>,
<a href=#301 id=301 data-nosnippet>301</a> path.to_string_lossy()
<a href=#302 id=302 data-nosnippet>302</a> )
<a href=#303 id=303 data-nosnippet>303</a> })<span class="question-mark">?</span>;
<a href=#304 id=304 data-nosnippet>304</a> }
<a href=#305 id=305 data-nosnippet>305</a> <span class="kw">let </span>db = Database::builder()
<a href=#306 id=306 data-nosnippet>306</a> .create(path)
<a href=#307 id=307 data-nosnippet>307</a> .std_context(<span class="string">"failed to open packet database"</span>)<span class="question-mark">?</span>;
<a href=#308 id=308 data-nosnippet>308</a> <span class="self">Self</span>::open(db, options, metrics)
<a href=#309 id=309 data-nosnippet>309</a> }
<a href=#310 id=310 data-nosnippet>310</a>
<a href=#311 id=311 data-nosnippet>311</a> <span class="kw">pub fn </span>in_memory(options: Options, metrics: Arc&lt;Metrics&gt;) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="self">Self</span>&gt; {
<a href=#312 id=312 data-nosnippet>312</a> <span class="macro">info!</span>(<span class="string">"using in-memory packet database"</span>);
<a href=#313 id=313 data-nosnippet>313</a> <span class="kw">let </span>db = Database::builder()
<a href=#314 id=314 data-nosnippet>314</a> .create_with_backend(InMemoryBackend::new())
<a href=#315 id=315 data-nosnippet>315</a> .anyerr()<span class="question-mark">?</span>;
<a href=#316 id=316 data-nosnippet>316</a> <span class="self">Self</span>::open(db, options, metrics)
<a href=#317 id=317 data-nosnippet>317</a> }
<a href=#318 id=318 data-nosnippet>318</a>
<a href=#319 id=319 data-nosnippet>319</a> <span class="kw">pub fn </span>open(db: Database, options: Options, metrics: Arc&lt;Metrics&gt;) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="self">Self</span>&gt; {
<a href=#320 id=320 data-nosnippet>320</a> <span class="comment">// create tables
<a href=#321 id=321 data-nosnippet>321</a> </span><span class="kw">let </span>write_tx = db.begin_write().anyerr()<span class="question-mark">?</span>;
<a href=#322 id=322 data-nosnippet>322</a> <span class="kw">let _ </span>= Tables::new(<span class="kw-2">&amp;</span>write_tx).anyerr()<span class="question-mark">?</span>;
<a href=#323 id=323 data-nosnippet>323</a> write_tx.commit().anyerr()<span class="question-mark">?</span>;
<a href=#324 id=324 data-nosnippet>324</a> <span class="kw">let </span>(send, recv) = mpsc::channel(<span class="number">1024</span>);
<a href=#325 id=325 data-nosnippet>325</a> <span class="kw">let </span>send2 = send.clone();
<a href=#326 id=326 data-nosnippet>326</a> <span class="kw">let </span>cancel = CancellationToken::new();
<a href=#327 id=327 data-nosnippet>327</a> <span class="kw">let </span>cancel2 = cancel.clone();
<a href=#328 id=328 data-nosnippet>328</a> <span class="kw">let </span>cancel3 = cancel.clone();
<a href=#329 id=329 data-nosnippet>329</a> <span class="kw">let </span>actor = Actor {
<a href=#330 id=330 data-nosnippet>330</a> db,
<a href=#331 id=331 data-nosnippet>331</a> recv: PeekableReceiver::new(recv),
<a href=#332 id=332 data-nosnippet>332</a> cancel: cancel2,
<a href=#333 id=333 data-nosnippet>333</a> options,
<a href=#334 id=334 data-nosnippet>334</a> metrics,
<a href=#335 id=335 data-nosnippet>335</a> };
<a href=#336 id=336 data-nosnippet>336</a> <span class="comment">// start an io thread and donate it to the tokio runtime so we can do blocking IO
<a href=#337 id=337 data-nosnippet>337</a> // inside the thread despite being in a tokio runtime
<a href=#338 id=338 data-nosnippet>338</a> </span><span class="kw">let </span>_write_thread = IoThread::new(<span class="string">"packet-store-actor"</span>, <span class="kw">move </span>|| actor.run())<span class="question-mark">?</span>;
<a href=#339 id=339 data-nosnippet>339</a> <span class="kw">let </span>_evict_thread = IoThread::new(<span class="string">"packet-store-evict"</span>, <span class="kw">move </span>|| {
<a href=#340 id=340 data-nosnippet>340</a> evict_task(send2, options, cancel3)
<a href=#341 id=341 data-nosnippet>341</a> })<span class="question-mark">?</span>;
<a href=#342 id=342 data-nosnippet>342</a> <span class="prelude-val">Ok</span>(<span class="self">Self </span>{
<a href=#343 id=343 data-nosnippet>343</a> send,
<a href=#344 id=344 data-nosnippet>344</a> cancel,
<a href=#345 id=345 data-nosnippet>345</a> _write_thread,
<a href=#346 id=346 data-nosnippet>346</a> _evict_thread,
<a href=#347 id=347 data-nosnippet>347</a> })
<a href=#348 id=348 data-nosnippet>348</a> }
<a href=#349 id=349 data-nosnippet>349</a>
<a href=#350 id=350 data-nosnippet>350</a> <span class="kw">pub async fn </span>upsert(<span class="kw-2">&amp;</span><span class="self">self</span>, packet: SignedPacket) -&gt; <span class="prelude-ty">Result</span>&lt;bool&gt; {
<a href=#351 id=351 data-nosnippet>351</a> <span class="kw">let </span>(tx, rx) = oneshot::channel();
<a href=#352 id=352 data-nosnippet>352</a> <span class="self">self</span>.send
<a href=#353 id=353 data-nosnippet>353</a> .send(Message::Upsert { packet, res: tx })
<a href=#354 id=354 data-nosnippet>354</a> .<span class="kw">await
<a href=#355 id=355 data-nosnippet>355</a> </span>.anyerr()<span class="question-mark">?</span>;
<a href=#356 id=356 data-nosnippet>356</a> rx.<span class="kw">await</span>.anyerr()
<a href=#357 id=357 data-nosnippet>357</a> }
<a href=#358 id=358 data-nosnippet>358</a>
<a href=#359 id=359 data-nosnippet>359</a> <span class="kw">pub async fn </span>get(<span class="kw-2">&amp;</span><span class="self">self</span>, key: <span class="kw-2">&amp;</span>PublicKeyBytes) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="prelude-ty">Option</span>&lt;SignedPacket&gt;&gt; {
<a href=#360 id=360 data-nosnippet>360</a> <span class="kw">let </span>(tx, rx) = oneshot::channel();
<a href=#361 id=361 data-nosnippet>361</a> <span class="self">self</span>.send
<a href=#362 id=362 data-nosnippet>362</a> .send(Message::Get { key: <span class="kw-2">*</span>key, res: tx })
<a href=#363 id=363 data-nosnippet>363</a> .<span class="kw">await
<a href=#364 id=364 data-nosnippet>364</a> </span>.anyerr()<span class="question-mark">?</span>;
<a href=#365 id=365 data-nosnippet>365</a> rx.<span class="kw">await</span>.anyerr()
<a href=#366 id=366 data-nosnippet>366</a> }
<a href=#367 id=367 data-nosnippet>367</a>
<a href=#368 id=368 data-nosnippet>368</a> <span class="kw">pub async fn </span>remove(<span class="kw-2">&amp;</span><span class="self">self</span>, key: <span class="kw-2">&amp;</span>PublicKeyBytes) -&gt; <span class="prelude-ty">Result</span>&lt;bool&gt; {
<a href=#369 id=369 data-nosnippet>369</a> <span class="kw">let </span>(tx, rx) = oneshot::channel();
<a href=#370 id=370 data-nosnippet>370</a> <span class="self">self</span>.send
<a href=#371 id=371 data-nosnippet>371</a> .send(Message::Remove { key: <span class="kw-2">*</span>key, res: tx })
<a href=#372 id=372 data-nosnippet>372</a> .<span class="kw">await
<a href=#373 id=373 data-nosnippet>373</a> </span>.anyerr()<span class="question-mark">?</span>;
<a href=#374 id=374 data-nosnippet>374</a> rx.<span class="kw">await</span>.anyerr()
<a href=#375 id=375 data-nosnippet>375</a> }
<a href=#376 id=376 data-nosnippet>376</a>}
<a href=#377 id=377 data-nosnippet>377</a>
<a href=#378 id=378 data-nosnippet>378</a><span class="doccomment">/// Serialize a signed packet for storage: `&lt;8 bytes last_seen&gt;&lt;packet bytes&gt;`.
<a href=#379 id=379 data-nosnippet>379</a></span><span class="kw">fn </span>serialize(packet: <span class="kw-2">&amp;</span>SignedPacket) -&gt; Vec&lt;u8&gt; {
<a href=#380 id=380 data-nosnippet>380</a> <span class="kw">let </span><span class="kw-2">mut </span>out = Vec::with_capacity(<span class="number">8 </span>+ packet.as_bytes().len());
<a href=#381 id=381 data-nosnippet>381</a> out.extend_from_slice(<span class="kw-2">&amp;</span>Timestamp::now().to_be_bytes());
<a href=#382 id=382 data-nosnippet>382</a> out.extend_from_slice(packet.as_bytes());
<a href=#383 id=383 data-nosnippet>383</a> out
<a href=#384 id=384 data-nosnippet>384</a>}
<a href=#385 id=385 data-nosnippet>385</a>
<a href=#386 id=386 data-nosnippet>386</a><span class="doccomment">/// Deserialize a signed packet from storage format.
<a href=#387 id=387 data-nosnippet>387</a>///
<a href=#388 id=388 data-nosnippet>388</a>/// Handles backwards compatibility with older storage formats that didn't include
<a href=#389 id=389 data-nosnippet>389</a>/// the `last_seen` prefix.
<a href=#390 id=390 data-nosnippet>390</a></span><span class="kw">fn </span>deserialize(data: <span class="kw-2">&amp;</span>[u8]) -&gt; <span class="prelude-ty">Result</span>&lt;SignedPacket&gt; {
<a href=#391 id=391 data-nosnippet>391</a> <span class="comment">// Try parsing as &lt;8 bytes last_seen&gt;&lt;packet&gt; (pkarr v3 format)
<a href=#392 id=392 data-nosnippet>392</a> </span><span class="kw">if </span>data.len() &gt;= <span class="number">8
<a href=#393 id=393 data-nosnippet>393</a> </span>&amp;&amp; <span class="kw">let </span><span class="prelude-val">Ok</span>(packet) = SignedPacket::from_bytes_unchecked(<span class="kw-2">&amp;</span>data[<span class="number">8</span>..])
<a href=#394 id=394 data-nosnippet>394</a> {
<a href=#395 id=395 data-nosnippet>395</a> <span class="kw">return </span><span class="prelude-val">Ok</span>(packet);
<a href=#396 id=396 data-nosnippet>396</a> }
<a href=#397 id=397 data-nosnippet>397</a> <span class="comment">// Fall back to raw packet bytes (pre-v0.35 format without last_seen prefix)
<a href=#398 id=398 data-nosnippet>398</a> </span>SignedPacket::from_bytes_unchecked(data)
<a href=#399 id=399 data-nosnippet>399</a> .map_err(|err| <span class="macro">anyerr!</span>(<span class="string">"Failed to decode stored packet: {err:#}"</span>))
<a href=#400 id=400 data-nosnippet>400</a>}
<a href=#401 id=401 data-nosnippet>401</a>
<a href=#402 id=402 data-nosnippet>402</a><span class="kw">fn </span>get_packet(
<a href=#403 id=403 data-nosnippet>403</a> table: <span class="kw-2">&amp;</span><span class="kw">impl </span>ReadableTable&lt;<span class="kw-2">&amp;</span><span class="lifetime">'static </span>SignedPacketsKey, <span class="kw-2">&amp;</span><span class="lifetime">'static </span>[u8]&gt;,
<a href=#404 id=404 data-nosnippet>404</a> key: <span class="kw-2">&amp;</span>PublicKeyBytes,
<a href=#405 id=405 data-nosnippet>405</a>) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="prelude-ty">Option</span>&lt;SignedPacket&gt;&gt; {
<a href=#406 id=406 data-nosnippet>406</a> <span class="kw">let </span><span class="prelude-val">Some</span>(row) = table
<a href=#407 id=407 data-nosnippet>407</a> .get(key.as_ref())
<a href=#408 id=408 data-nosnippet>408</a> .std_context(<span class="string">"database fetch failed"</span>)<span class="question-mark">?
<a href=#409 id=409 data-nosnippet>409</a> </span><span class="kw">else </span>{
<a href=#410 id=410 data-nosnippet>410</a> <span class="kw">return </span><span class="prelude-val">Ok</span>(<span class="prelude-val">None</span>);
<a href=#411 id=411 data-nosnippet>411</a> };
<a href=#412 id=412 data-nosnippet>412</a> <span class="prelude-val">Ok</span>(<span class="prelude-val">Some</span>(deserialize(row.value())<span class="question-mark">?</span>))
<a href=#413 id=413 data-nosnippet>413</a>}
<a href=#414 id=414 data-nosnippet>414</a>
<a href=#415 id=415 data-nosnippet>415</a><span class="kw">async fn </span>evict_task(send: mpsc::Sender&lt;Message&gt;, options: Options, cancel: CancellationToken) {
<a href=#416 id=416 data-nosnippet>416</a> <span class="kw">let </span>cancel2 = cancel.clone();
<a href=#417 id=417 data-nosnippet>417</a> <span class="kw">let _ </span>= cancel2
<a href=#418 id=418 data-nosnippet>418</a> .run_until_cancelled(<span class="kw">async move </span>{
<a href=#419 id=419 data-nosnippet>419</a> <span class="macro">info!</span>(<span class="string">"starting evict task"</span>);
<a href=#420 id=420 data-nosnippet>420</a> <span class="kw">if let </span><span class="prelude-val">Err</span>(cause) = evict_task_inner(send, options).<span class="kw">await </span>{
<a href=#421 id=421 data-nosnippet>421</a> <span class="macro">error!</span>(<span class="string">"evict task failed: {:?}"</span>, cause);
<a href=#422 id=422 data-nosnippet>422</a> }
<a href=#423 id=423 data-nosnippet>423</a> <span class="comment">// when we are done for whatever reason we want to shut down the actor
<a href=#424 id=424 data-nosnippet>424</a> </span>cancel.cancel();
<a href=#425 id=425 data-nosnippet>425</a> })
<a href=#426 id=426 data-nosnippet>426</a> .<span class="kw">await</span>;
<a href=#427 id=427 data-nosnippet>427</a>}
<a href=#428 id=428 data-nosnippet>428</a>
<a href=#429 id=429 data-nosnippet>429</a><span class="doccomment">/// Periodically check for expired packets and remove them.
<a href=#430 id=430 data-nosnippet>430</a></span><span class="kw">async fn </span>evict_task_inner(send: mpsc::Sender&lt;Message&gt;, options: Options) -&gt; <span class="prelude-ty">Result</span>&lt;()&gt; {
<a href=#431 id=431 data-nosnippet>431</a> <span class="kw">let </span>expiry_us = options.eviction.as_micros() <span class="kw">as </span>u64;
<a href=#432 id=432 data-nosnippet>432</a> <span class="kw">loop </span>{
<a href=#433 id=433 data-nosnippet>433</a> <span class="kw">let </span>(tx, rx) = oneshot::channel();
<a href=#434 id=434 data-nosnippet>434</a> <span class="kw">let _ </span>= send.send(Message::Snapshot { res: tx }).<span class="kw">await</span>.ok();
<a href=#435 id=435 data-nosnippet>435</a> <span class="comment">// if we can't get the snapshot we exit the loop, main actor dead
<a href=#436 id=436 data-nosnippet>436</a> </span><span class="kw">let </span>snapshot = rx.<span class="kw">await</span>.std_context(<span class="string">"failed to get snapshot"</span>)<span class="question-mark">?</span>;
<a href=#437 id=437 data-nosnippet>437</a>
<a href=#438 id=438 data-nosnippet>438</a> <span class="kw">let </span>expired = Timestamp::from_micros(Timestamp::now().as_micros() - expiry_us);
<a href=#439 id=439 data-nosnippet>439</a> <span class="macro">trace!</span>(<span class="string">"evicting packets older than {}"</span>, fmt_time(expired));
<a href=#440 id=440 data-nosnippet>440</a> <span class="comment">// if getting the range fails we exit the loop and shut down
<a href=#441 id=441 data-nosnippet>441</a> // if individual reads fail we log the error and limp on
<a href=#442 id=442 data-nosnippet>442</a> </span><span class="kw">for </span>item <span class="kw">in </span>snapshot
<a href=#443 id=443 data-nosnippet>443</a> .update_time
<a href=#444 id=444 data-nosnippet>444</a> .range(..expired.to_be_bytes())
<a href=#445 id=445 data-nosnippet>445</a> .anyerr()<span class="question-mark">?
<a href=#446 id=446 data-nosnippet>446</a> </span>{
<a href=#447 id=447 data-nosnippet>447</a> <span class="kw">let </span>(time, keys) = <span class="kw">match </span>item {
<a href=#448 id=448 data-nosnippet>448</a> <span class="prelude-val">Ok</span>(v) =&gt; v,
<a href=#449 id=449 data-nosnippet>449</a> <span class="prelude-val">Err</span>(e) =&gt; {
<a href=#450 id=450 data-nosnippet>450</a> <span class="macro">error!</span>(<span class="string">"failed to read update_time row {:?}"</span>, e);
<a href=#451 id=451 data-nosnippet>451</a> <span class="kw">continue</span>;
<a href=#452 id=452 data-nosnippet>452</a> }
<a href=#453 id=453 data-nosnippet>453</a> };
<a href=#454 id=454 data-nosnippet>454</a> <span class="kw">let </span>time = Timestamp::from_be_bytes(time.value());
<a href=#455 id=455 data-nosnippet>455</a> <span class="macro">trace!</span>(<span class="string">"evicting expired packets at {}"</span>, fmt_time(time));
<a href=#456 id=456 data-nosnippet>456</a> <span class="kw">for </span>item <span class="kw">in </span>keys {
<a href=#457 id=457 data-nosnippet>457</a> <span class="kw">let </span>key = <span class="kw">match </span>item {
<a href=#458 id=458 data-nosnippet>458</a> <span class="prelude-val">Ok</span>(v) =&gt; v,
<a href=#459 id=459 data-nosnippet>459</a> <span class="prelude-val">Err</span>(e) =&gt; {
<a href=#460 id=460 data-nosnippet>460</a> <span class="macro">error!</span>(
<a href=#461 id=461 data-nosnippet>461</a> <span class="string">"failed to read update_time item at {}: {:?}"</span>,
<a href=#462 id=462 data-nosnippet>462</a> fmt_time(time),
<a href=#463 id=463 data-nosnippet>463</a> e
<a href=#464 id=464 data-nosnippet>464</a> );
<a href=#465 id=465 data-nosnippet>465</a> <span class="kw">continue</span>;
<a href=#466 id=466 data-nosnippet>466</a> }
<a href=#467 id=467 data-nosnippet>467</a> };
<a href=#468 id=468 data-nosnippet>468</a> <span class="kw">let </span>key = PublicKeyBytes::new(key.value());
<a href=#469 id=469 data-nosnippet>469</a>
<a href=#470 id=470 data-nosnippet>470</a> <span class="macro">debug!</span>(<span class="string">"evicting expired packet {} {}"</span>, fmt_time(time), key);
<a href=#471 id=471 data-nosnippet>471</a> send.send(Message::CheckExpired { time, key })
<a href=#472 id=472 data-nosnippet>472</a> .<span class="kw">await
<a href=#473 id=473 data-nosnippet>473</a> </span>.anyerr()<span class="question-mark">?</span>;
<a href=#474 id=474 data-nosnippet>474</a> }
<a href=#475 id=475 data-nosnippet>475</a> }
<a href=#476 id=476 data-nosnippet>476</a> <span class="comment">// sleep for the eviction interval so we don't constantly check
<a href=#477 id=477 data-nosnippet>477</a> </span>tokio::time::sleep(options.eviction_interval).<span class="kw">await</span>;
<a href=#478 id=478 data-nosnippet>478</a> }
<a href=#479 id=479 data-nosnippet>479</a>}
<a href=#480 id=480 data-nosnippet>480</a>
<a href=#481 id=481 data-nosnippet>481</a><span class="doccomment">/// An io thread that drives a future to completion on the current tokio runtime
<a href=#482 id=482 data-nosnippet>482</a>///
<a href=#483 id=483 data-nosnippet>483</a>/// Inside the future, blocking IO can be done without blocking one of the tokio
<a href=#484 id=484 data-nosnippet>484</a>/// pool threads.
<a href=#485 id=485 data-nosnippet>485</a></span><span class="attr">#[derive(Debug)]
<a href=#486 id=486 data-nosnippet>486</a></span><span class="kw">struct </span>IoThread {
<a href=#487 id=487 data-nosnippet>487</a> handle: <span class="prelude-ty">Option</span>&lt;std::thread::JoinHandle&lt;()&gt;&gt;,
<a href=#488 id=488 data-nosnippet>488</a>}
<a href=#489 id=489 data-nosnippet>489</a>
<a href=#490 id=490 data-nosnippet>490</a><span class="kw">impl </span>IoThread {
<a href=#491 id=491 data-nosnippet>491</a> <span class="doccomment">/// Spawn a new io thread.
<a href=#492 id=492 data-nosnippet>492</a> ///
<a href=#493 id=493 data-nosnippet>493</a> /// Calling this function requires that the current thread is running in a
<a href=#494 id=494 data-nosnippet>494</a> /// tokio runtime. It is up to the caller to make sure the future exits,
<a href=#495 id=495 data-nosnippet>495</a> /// e.g. by using a cancellation token. Otherwise, drop will block.
<a href=#496 id=496 data-nosnippet>496</a> </span><span class="kw">fn </span>new&lt;F, Fut&gt;(name: <span class="kw-2">&amp;</span>str, f: F) -&gt; <span class="prelude-ty">Result</span>&lt;<span class="self">Self</span>&gt;
<a href=#497 id=497 data-nosnippet>497</a> <span class="kw">where
<a href=#498 id=498 data-nosnippet>498</a> </span>F: FnOnce() -&gt; Fut + Send + <span class="lifetime">'static</span>,
<a href=#499 id=499 data-nosnippet>499</a> Fut: Future&lt;Output = ()&gt;,
<a href=#500 id=500 data-nosnippet>500</a> {
<a href=#501 id=501 data-nosnippet>501</a> <span class="kw">let </span>rt = tokio::runtime::Handle::try_current().std_context(<span class="string">"get tokio handle"</span>)<span class="question-mark">?</span>;
<a href=#502 id=502 data-nosnippet>502</a> <span class="kw">let </span>handle = std::thread::Builder::new()
<a href=#503 id=503 data-nosnippet>503</a> .name(name.into())
<a href=#504 id=504 data-nosnippet>504</a> .spawn(<span class="kw">move </span>|| rt.block_on(f()))
<a href=#505 id=505 data-nosnippet>505</a> .std_context(<span class="string">"failed to spawn thread"</span>)<span class="question-mark">?</span>;
<a href=#506 id=506 data-nosnippet>506</a> <span class="prelude-val">Ok</span>(<span class="self">Self </span>{
<a href=#507 id=507 data-nosnippet>507</a> handle: <span class="prelude-val">Some</span>(handle),
<a href=#508 id=508 data-nosnippet>508</a> })
<a href=#509 id=509 data-nosnippet>509</a> }
<a href=#510 id=510 data-nosnippet>510</a>}
<a href=#511 id=511 data-nosnippet>511</a>
<a href=#512 id=512 data-nosnippet>512</a><span class="kw">impl </span>Drop <span class="kw">for </span>IoThread {
<a href=#513 id=513 data-nosnippet>513</a> <span class="kw">fn </span>drop(<span class="kw-2">&amp;mut </span><span class="self">self</span>) {
<a href=#514 id=514 data-nosnippet>514</a> <span class="kw">if let </span><span class="prelude-val">Some</span>(handle) = <span class="self">self</span>.handle.take() {
<a href=#515 id=515 data-nosnippet>515</a> <span class="kw">let _ </span>= handle.join();
<a href=#516 id=516 data-nosnippet>516</a> }
<a href=#517 id=517 data-nosnippet>517</a> }
<a href=#518 id=518 data-nosnippet>518</a>}
<a href=#519 id=519 data-nosnippet>519</a>
<a href=#520 id=520 data-nosnippet>520</a><span class="doccomment">/// A wrapper for a tokio mpsc receiver that allows peeking at the next message.
<a href=#521 id=521 data-nosnippet>521</a></span><span class="attr">#[derive(Debug)]
<a href=#522 id=522 data-nosnippet>522</a></span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">struct </span>PeekableReceiver&lt;T&gt; {
<a href=#523 id=523 data-nosnippet>523</a> msg: <span class="prelude-ty">Option</span>&lt;T&gt;,
<a href=#524 id=524 data-nosnippet>524</a> recv: tokio::sync::mpsc::Receiver&lt;T&gt;,
<a href=#525 id=525 data-nosnippet>525</a>}
<a href=#526 id=526 data-nosnippet>526</a>
<a href=#527 id=527 data-nosnippet>527</a><span class="doccomment">/// A wrapper for a tokio mpsc receiver that allows peeking at the next message.
<a href=#528 id=528 data-nosnippet>528</a></span><span class="attr">#[derive(Debug)]
<a href=#529 id=529 data-nosnippet>529</a></span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">struct </span>PeekableReceiver&lt;T&gt; {
<a href=#530 id=530 data-nosnippet>530</a> msg: <span class="prelude-ty">Option</span>&lt;T&gt;,
<a href=#531 id=531 data-nosnippet>531</a> recv: tokio::sync::mpsc::Receiver&lt;T&gt;,
<a href=#532 id=532 data-nosnippet>532</a>}
<a href=#533 id=533 data-nosnippet>533</a>
<a href=#534 id=534 data-nosnippet>534</a><span class="attr">#[allow(dead_code)]
<a href=#535 id=535 data-nosnippet>535</a></span><span class="kw">impl</span>&lt;T&gt; PeekableReceiver&lt;T&gt; {
<a href=#536 id=536 data-nosnippet>536</a> <span class="kw">pub fn </span>new(recv: tokio::sync::mpsc::Receiver&lt;T&gt;) -&gt; <span class="self">Self </span>{
<a href=#537 id=537 data-nosnippet>537</a> <span class="self">Self </span>{ msg: <span class="prelude-val">None</span>, recv }
<a href=#538 id=538 data-nosnippet>538</a> }
<a href=#539 id=539 data-nosnippet>539</a>
<a href=#540 id=540 data-nosnippet>540</a> <span class="doccomment">/// Receive the next message.
<a href=#541 id=541 data-nosnippet>541</a> ///
<a href=#542 id=542 data-nosnippet>542</a> /// Will block if there are no messages.
<a href=#543 id=543 data-nosnippet>543</a> /// Returns None only if there are no more messages (sender is dropped).
<a href=#544 id=544 data-nosnippet>544</a> </span><span class="kw">pub async fn </span>recv(<span class="kw-2">&amp;mut </span><span class="self">self</span>) -&gt; <span class="prelude-ty">Option</span>&lt;T&gt; {
<a href=#545 id=545 data-nosnippet>545</a> <span class="kw">if let </span><span class="prelude-val">Some</span>(msg) = <span class="self">self</span>.msg.take() {
<a href=#546 id=546 data-nosnippet>546</a> <span class="kw">return </span><span class="prelude-val">Some</span>(msg);
<a href=#547 id=547 data-nosnippet>547</a> }
<a href=#548 id=548 data-nosnippet>548</a> <span class="self">self</span>.recv.recv().<span class="kw">await
<a href=#549 id=549 data-nosnippet>549</a> </span>}
<a href=#550 id=550 data-nosnippet>550</a>
<a href=#551 id=551 data-nosnippet>551</a> <span class="doccomment">/// Push back a message. This will only work if there is room for it.
<a href=#552 id=552 data-nosnippet>552</a> /// Otherwise, it will fail and return the message.
<a href=#553 id=553 data-nosnippet>553</a> </span><span class="kw">pub fn </span>push_back(<span class="kw-2">&amp;mut </span><span class="self">self</span>, msg: T) -&gt; std::result::Result&lt;(), T&gt; {
<a href=#554 id=554 data-nosnippet>554</a> <span class="kw">if </span><span class="self">self</span>.msg.is_none() {
<a href=#555 id=555 data-nosnippet>555</a> <span class="self">self</span>.msg = <span class="prelude-val">Some</span>(msg);
<a href=#556 id=556 data-nosnippet>556</a> <span class="prelude-val">Ok</span>(())
<a href=#557 id=557 data-nosnippet>557</a> } <span class="kw">else </span>{
<a href=#558 id=558 data-nosnippet>558</a> <span class="prelude-val">Err</span>(msg)
<a href=#559 id=559 data-nosnippet>559</a> }
<a href=#560 id=560 data-nosnippet>560</a> }
<a href=#561 id=561 data-nosnippet>561</a>}</code></pre></div></section></main></body></html>
<a href=#527 id=527 data-nosnippet>527</a><span class="attr">#[allow(dead_code)]
<a href=#528 id=528 data-nosnippet>528</a></span><span class="kw">impl</span>&lt;T&gt; PeekableReceiver&lt;T&gt; {
<a href=#529 id=529 data-nosnippet>529</a> <span class="kw">pub fn </span>new(recv: tokio::sync::mpsc::Receiver&lt;T&gt;) -&gt; <span class="self">Self </span>{
<a href=#530 id=530 data-nosnippet>530</a> <span class="self">Self </span>{ msg: <span class="prelude-val">None</span>, recv }
<a href=#531 id=531 data-nosnippet>531</a> }
<a href=#532 id=532 data-nosnippet>532</a>
<a href=#533 id=533 data-nosnippet>533</a> <span class="doccomment">/// Receive the next message.
<a href=#534 id=534 data-nosnippet>534</a> ///
<a href=#535 id=535 data-nosnippet>535</a> /// Will block if there are no messages.
<a href=#536 id=536 data-nosnippet>536</a> /// Returns None only if there are no more messages (sender is dropped).
<a href=#537 id=537 data-nosnippet>537</a> </span><span class="kw">pub async fn </span>recv(<span class="kw-2">&amp;mut </span><span class="self">self</span>) -&gt; <span class="prelude-ty">Option</span>&lt;T&gt; {
<a href=#538 id=538 data-nosnippet>538</a> <span class="kw">if let </span><span class="prelude-val">Some</span>(msg) = <span class="self">self</span>.msg.take() {
<a href=#539 id=539 data-nosnippet>539</a> <span class="kw">return </span><span class="prelude-val">Some</span>(msg);
<a href=#540 id=540 data-nosnippet>540</a> }
<a href=#541 id=541 data-nosnippet>541</a> <span class="self">self</span>.recv.recv().<span class="kw">await
<a href=#542 id=542 data-nosnippet>542</a> </span>}
<a href=#543 id=543 data-nosnippet>543</a>
<a href=#544 id=544 data-nosnippet>544</a> <span class="doccomment">/// Push back a message. This will only work if there is room for it.
<a href=#545 id=545 data-nosnippet>545</a> /// Otherwise, it will fail and return the message.
<a href=#546 id=546 data-nosnippet>546</a> </span><span class="kw">pub fn </span>push_back(<span class="kw-2">&amp;mut </span><span class="self">self</span>, msg: T) -&gt; std::result::Result&lt;(), T&gt; {
<a href=#547 id=547 data-nosnippet>547</a> <span class="kw">if </span><span class="self">self</span>.msg.is_none() {
<a href=#548 id=548 data-nosnippet>548</a> <span class="self">self</span>.msg = <span class="prelude-val">Some</span>(msg);
<a href=#549 id=549 data-nosnippet>549</a> <span class="prelude-val">Ok</span>(())
<a href=#550 id=550 data-nosnippet>550</a> } <span class="kw">else </span>{
<a href=#551 id=551 data-nosnippet>551</a> <span class="prelude-val">Err</span>(msg)
<a href=#552 id=552 data-nosnippet>552</a> }
<a href=#553 id=553 data-nosnippet>553</a> }
<a href=#554 id=554 data-nosnippet>554</a>}</code></pre></div></section></main></body></html>