Files
firezone/rust/relay/examples/client.rs
dependabot[bot] dc57206027 build(deps): Bump redis from 0.23.3 to 0.24.0 in /rust (#2864)
Bumps [redis](https://github.com/redis-rs/redis-rs) from 0.23.3 to
0.24.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/redis-rs/redis-rs/releases">redis's
releases</a>.</em></p>
<blockquote>
<h2>v0.24.0</h2>
<h3>0.24.0 (2023-12-05)</h3>
<h4>Features</h4>
<ul>
<li><strong>Breaking change</strong>: Support Mutual TLS (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/858">#858</a>
<a href="https://github.com/sp-angel"><code>@​sp-angel</code></a>)</li>
<li>Implement <code>FromRedisValue</code> for
<code>Box&lt;[T]&gt;</code> and <code>Arc&lt;[T]&gt;</code> (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/799">#799</a>
<a href="https://github.com/JOT85"><code>@​JOT85</code></a>)</li>
<li>Sync Cluster: support multi-slot operations. (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/967">#967</a>)</li>
<li>Execute multi-node requests using try_request. (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/919">#919</a>)</li>
<li>Sorted set blocking commands (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/962">#962</a>
<a
href="https://github.com/gheorghitamutu"><code>@​gheorghitamutu</code></a>)</li>
<li>Allow passing routing information to cluster. (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/899">#899</a>)</li>
<li>Add <code>tcp_nodelay</code> feature (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/941">#941</a>
<a
href="https://github.com/PureWhiteWu"><code>@​PureWhiteWu</code></a>)</li>
<li>Add support for multi-shard commands. (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/900">#900</a>)</li>
</ul>
<h4>Changes</h4>
<ul>
<li>Order in usage of ClusterParams. (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/997">#997</a>)</li>
<li><strong>Breaking change</strong>: Fix StreamId::contains_key
signature (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/783">#783</a>
<a
href="https://github.com/Ayush1325"><code>@​Ayush1325</code></a>)</li>
<li><strong>Breaking change</strong>: Update Command expiration values
to be an appropriate type (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/589">#589</a>
<a href="https://github.com/joshleeb"><code>@​joshleeb</code></a>)</li>
<li><strong>Breaking change</strong>: Bump aHash to v0.8.6 (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/966">#966</a>
<a href="https://github.com/aumetra"><code>@​aumetra</code></a>)</li>
<li>Fix features for <code>load_native_certs</code>. (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/996">#996</a>)</li>
<li>Revert redis-test versioning changes (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/993">#993</a>)</li>
<li>Tests: Add retries to test cluster creation (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/994">#994</a>)</li>
<li>Fix sync cluster behavior with transactions. (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/983">#983</a>)</li>
<li>Sync Pub/Sub - cache received pub/sub messages. (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/910">#910</a>)</li>
<li>Prefer routing to primary in a transaction. (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/986">#986</a>)</li>
<li>Accept iterator at <code>ClusterClient</code> initialization (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/987">#987</a>
<a
href="https://github.com/ruanpetterson"><code>@​ruanpetterson</code></a>)</li>
<li><strong>Breaking change</strong>: Change timeouts from usize and
isize to f64 (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/988">#988</a>
<a
href="https://github.com/eythorhel19"><code>@​eythorhel19</code></a>)</li>
<li>Update minimal rust version to 1.6.5 (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/982">#982</a>)</li>
<li>Disable JSON module tests for redis 6.2.4. (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/980">#980</a>)</li>
<li>Add connection string examples (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/976">#976</a>
<a
href="https://github.com/NuclearOreo"><code>@​NuclearOreo</code></a>)</li>
<li>Move response policy into multi-node routing. (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/952">#952</a>)</li>
<li>Added functions that allow tests to check version. (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/963">#963</a>)</li>
<li>Fix XREADGROUP command ordering as per Redis Docs, and compatibility
with Upstash Redis (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/960">#960</a>
<a
href="https://github.com/prabhpreet"><code>@​prabhpreet</code></a>)</li>
<li>Optimize make_pipeline_results by pre-allocate memory (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/957">#957</a>
<a
href="https://github.com/PureWhiteWu"><code>@​PureWhiteWu</code></a>)</li>
<li>Run module tests sequentially. (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/956">#956</a>)</li>
<li>Log cluster creation output in tests. (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/955">#955</a>)</li>
<li>CI: Update and use better maintained github actions. (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/954">#954</a>)</li>
<li>Call CLIENT SETINFO on new connections. (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/945">#945</a>)</li>
<li>Deprecate functions that erroneously use <code>tokio</code> in their
name. (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/913">#913</a>)</li>
<li>CI: Increase timeouts and use newer redis. (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/949">#949</a>)</li>
<li>Remove redis version from redis-test. (<a
href="https://redirect.github.com/redis-rs/redis-rs/pull/943">#943</a>)</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="37ba5614c9"><code>37ba561</code></a>
Release redis 0.24.0 / redis-test 0.3.0 (<a
href="https://redirect.github.com/redis-rs/redis-rs/issues/998">#998</a>)</li>
<li><a
href="bcc6e3ba59"><code>bcc6e3b</code></a>
Order in usage of ClusterParams. (<a
href="https://redirect.github.com/redis-rs/redis-rs/issues/997">#997</a>)</li>
<li><a
href="db19291263"><code>db19291</code></a>
Fix StreamId::contains_key signature (<a
href="https://redirect.github.com/redis-rs/redis-rs/issues/783">#783</a>)</li>
<li><a
href="413f4d947e"><code>413f4d9</code></a>
Update Command expiration values to be an appropriate type (<a
href="https://redirect.github.com/redis-rs/redis-rs/issues/589">#589</a>)</li>
<li><a
href="f4f5344d2c"><code>f4f5344</code></a>
Bump aHash to v0.8.6 (<a
href="https://redirect.github.com/redis-rs/redis-rs/issues/966">#966</a>)</li>
<li><a
href="439118e73e"><code>439118e</code></a>
Fix features for <code>load_native_certs</code>. (<a
href="https://redirect.github.com/redis-rs/redis-rs/issues/996">#996</a>)</li>
<li><a
href="a26373b145"><code>a26373b</code></a>
Revert redis-test versioning changes (<a
href="https://redirect.github.com/redis-rs/redis-rs/issues/993">#993</a>)</li>
<li><a
href="882ecf9c5d"><code>882ecf9</code></a>
Tests: Add retries to test cluster creation (<a
href="https://redirect.github.com/redis-rs/redis-rs/issues/994">#994</a>)</li>
<li><a
href="d8a5ca95e5"><code>d8a5ca9</code></a>
Release redis 0.23.4 / redis-test 0.2.4 (<a
href="https://redirect.github.com/redis-rs/redis-rs/issues/992">#992</a>)</li>
<li><a
href="a6df6e273c"><code>a6df6e2</code></a>
Fix sync cluster behavior with transactions. (<a
href="https://redirect.github.com/redis-rs/redis-rs/issues/983">#983</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/redis-rs/redis-rs/compare/redis-0.23.3...redis-0.24.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=redis&package-manager=cargo&previous-version=0.23.3&new-version=0.24.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

You can trigger a rebase of this PR by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore <dependency name> major version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's major version (unless you unignore this specific
dependency's major version or upgrade to it yourself)
- `@dependabot ignore <dependency name> minor version` will close this
group update PR and stop Dependabot creating any more for the specific
dependency's minor version (unless you unignore this specific
dependency's minor version or upgrade to it yourself)
- `@dependabot ignore <dependency name>` will close this group update PR
and stop Dependabot creating any more for the specific dependency
(unless you unignore this specific dependency or upgrade to it yourself)
- `@dependabot unignore <dependency name>` will remove all of the ignore
conditions of the specified dependency
- `@dependabot unignore <dependency name> <ignore condition>` will
remove the ignore condition of the specified dependency and ignore
conditions


</details>

> **Note**
> Automatic rebases have been disabled on this pull request as it has
been open for over 30 days.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jamil Bou Kheir <jamilbk@users.noreply.github.com>
2024-01-17 03:37:38 +00:00

80 lines
2.5 KiB
Rust

use anyhow::Result;
use redis::AsyncCommands;
use std::net::SocketAddr;
use std::sync::Arc;
use std::time::Duration;
use tokio::net::UdpSocket;
use webrtc::turn::client::*;
use webrtc::turn::Error;
use webrtc::util::Conn;
#[tokio::main]
async fn main() -> Result<()> {
env_logger::init();
let redis_client = redis::Client::open("redis://localhost:6379")?;
let mut redis_connection = redis_client.get_async_connection().await?;
let turn_client = new_turn_client().await?;
let relay_conn = turn_client.allocate().await?;
let relay_addr = relay_conn.local_addr()?;
println!("Allocated relay address: {relay_addr}");
let gateway_addr = redis_connection
.blpop::<_, (String, String)>("gateway_addr", 10.0)
.await?
.1
.parse::<SocketAddr>()?;
println!("Retrieved gateway address: {gateway_addr}");
// The webrtc-rs client has no concept of explicitly creating a channel.
// Instead, it will implicitly create one when trying to send data to a remote.
relay_conn.send_to(b"HOLEPUNCH", gateway_addr).await?;
// `webrtc-ts` does not block on the creation of the channel binding.
// Wait for some amount of time here to avoid race conditions.
tokio::time::sleep(Duration::from_millis(10)).await;
println!("Created channel to gateway");
// Now that our relay connection is active, share the address with the gateway.
redis_connection
.rpush("client_relay_addr", relay_addr.to_string())
.await?;
println!("Pushed relay address to gateway");
// The actual test:
// Wait for an incoming packets and echo them back until the test harness kills us.
loop {
let mut buf = [0u8; 32];
let (_, sender) = relay_conn.recv_from(&mut buf).await?;
println!("Received buffer from {sender}: {}", hex::encode(buf));
relay_conn.send_to(&buf, sender).await?;
}
}
async fn new_turn_client() -> Result<Client, Error> {
let client = Client::new(ClientConfig {
stun_serv_addr: "localhost:3478".to_owned(),
turn_serv_addr: "localhost:3478".to_owned(),
username: "2000000000:client".to_owned(), // 2000000000 expires in 2033, plenty of time
password: "+Qou8TSjw9q3JMnWET7MbFsQh/agwz/LURhpfX7a0hE".to_owned(),
realm: "firezone".to_owned(),
software: String::new(),
rto_in_ms: 0,
conn: Arc::new(UdpSocket::bind("127.0.0.1:0").await?),
vnet: None,
})
.await?;
client.listen().await?;
Ok(client)
}