-
Notifications
You must be signed in to change notification settings - Fork 136
feat: iroh support #794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: iroh support #794
Changes from 3 commits
cf57c18
ecb6473
4479711
ae10087
3396963
0a6e925
c4995e0
32725d8
c1b9a4f
45fc066
a1d7905
68f79ad
ca3ce89
6e341a9
cb770d0
9535833
8e44da9
a90f5dd
8b17e3d
3cb0569
f47b6e1
0b642a1
68bc45f
8c47525
3a089de
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,38 @@ | ||
| use crate::Publish; | ||
|
|
||
| use hang::moq_lite; | ||
| use moq_native::web_transport_quinn::generic; | ||
| use url::Url; | ||
|
|
||
| pub async fn client(config: moq_native::ClientConfig, url: Url, name: String, publish: Publish) -> anyhow::Result<()> { | ||
| let client = config.init()?; | ||
|
|
||
| pub async fn client( | ||
| config: moq_native::ClientConfig, | ||
| #[cfg(feature = "iroh")] iroh: moq_native::iroh::EndpointConfig, | ||
| url: Url, | ||
| name: String, | ||
| publish: Publish, | ||
| ) -> anyhow::Result<()> { | ||
|
||
| tracing::info!(%url, %name, "connecting"); | ||
| let session = client.connect(url).await?; | ||
| match url.scheme() { | ||
| #[cfg(feature = "iroh")] | ||
| "iroh" => { | ||
|
||
| let client = iroh.init_client().await?; | ||
| let session = client.connect(url).await?; | ||
| run_import_session(session, name, publish).await?; | ||
| client.close().await; | ||
| Ok(()) | ||
| } | ||
| _ => { | ||
| let client = config.init()?; | ||
| let session = client.connect(url).await?; | ||
| run_import_session(session, name, publish).await | ||
| } | ||
| } | ||
| } | ||
|
||
|
|
||
| async fn run_import_session<S>(session: S, name: String, publish: Publish) -> anyhow::Result<()> | ||
| where | ||
| S: generic::Session, | ||
| { | ||
| // Create an origin producer to publish to the broadcast. | ||
| let origin = moq_lite::Origin::produce(); | ||
| origin.producer.publish_broadcast(&name, publish.consume()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,16 @@ pub enum Command { | |
| #[command(flatten)] | ||
| config: moq_native::ServerConfig, | ||
|
|
||
| /// Optionally enable serving via iroh. | ||
| #[cfg(feature = "iroh")] | ||
| #[clap(long)] | ||
| iroh: bool, | ||
|
|
||
| /// Configuration for the iroh endpoint. | ||
| #[cfg(feature = "iroh")] | ||
| #[command(flatten)] | ||
| iroh_config: moq_native::iroh::EndpointConfig, | ||
|
||
|
|
||
| /// The name of the broadcast to serve. | ||
| #[arg(long)] | ||
| name: String, | ||
|
|
@@ -42,6 +52,13 @@ pub enum Command { | |
| #[command(flatten)] | ||
| config: moq_native::ClientConfig, | ||
|
|
||
| /// Configuration for the iroh endpoint. | ||
| /// | ||
| /// It will be used for URLs with the iroh:// scheme. | ||
| #[cfg(feature = "iroh")] | ||
| #[command(flatten)] | ||
| iroh_config: moq_native::iroh::EndpointConfig, | ||
|
|
||
| /// The URL of the MoQ server. | ||
| /// | ||
| /// The URL must start with `https://` or `http://`. | ||
|
|
@@ -79,7 +96,43 @@ async fn main() -> anyhow::Result<()> { | |
| publish.init().await?; | ||
|
|
||
| match cli.command { | ||
| Command::Serve { config, dir, name, .. } => server(config, name, dir, publish).await, | ||
| Command::Publish { config, url, name, .. } => client(config, url, name, publish).await, | ||
| Command::Serve { | ||
| config, | ||
| dir, | ||
| name, | ||
| #[cfg(feature = "iroh")] | ||
| iroh, | ||
| #[cfg(feature = "iroh")] | ||
| iroh_config, | ||
| .. | ||
| } => { | ||
| server( | ||
| config, | ||
| #[cfg(feature = "iroh")] | ||
| iroh.then_some(iroh_config), | ||
| name, | ||
| dir, | ||
| publish, | ||
| ) | ||
| .await | ||
| } | ||
| Command::Publish { | ||
| config, | ||
| #[cfg(feature = "iroh")] | ||
| iroh_config, | ||
| url, | ||
| name, | ||
| .. | ||
| } => { | ||
| client( | ||
| config, | ||
| #[cfg(feature = "iroh")] | ||
| iroh_config, | ||
| url, | ||
| name, | ||
| publish, | ||
| ) | ||
| .await | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ categories = ["multimedia", "network-programming", "web-programming"] | |
| default = ["aws-lc-rs"] | ||
| aws-lc-rs = ["rustls/aws-lc-rs", "rcgen/aws_lc_rs", "quinn/rustls-aws-lc-rs"] | ||
| ring = ["rustls/ring", "rcgen/ring", "quinn/rustls-ring"] | ||
| iroh = ["dep:web-transport-iroh"] | ||
|
|
||
| [dependencies] | ||
| anyhow = { version = "1", features = ["backtrace"] } | ||
|
|
@@ -42,6 +43,8 @@ tracing = "0.1" | |
| tracing-subscriber = { version = "0.3", features = ["env-filter"] } | ||
| url = "2" | ||
| web-transport-quinn = { workspace = true } | ||
| web-transport-iroh = { git = "https://github.com/n0-computer/iroh-live", optional = true } | ||
|
||
| rand = "0.9.2" | ||
|
|
||
| [dev-dependencies] | ||
| anyhow = "1" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be checked in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually it shouldn't because if it is different people doing dev will connect to each other haha. Will remove and add instructions instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed