Skip to content

Commit

Permalink
Add a CLOCK. (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
kixelated authored Nov 7, 2023
1 parent df5d362 commit 93830a2
Show file tree
Hide file tree
Showing 17 changed files with 570 additions and 117 deletions.
95 changes: 95 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
members = ["moq-transport", "moq-relay", "moq-pub", "moq-api"]
members = ["moq-transport", "moq-relay", "moq-pub", "moq-api", "moq-clock"]
resolver = "2"
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ RUN apt-get update && \
# Copy the publish script into the image
COPY deploy/publish.sh /usr/local/bin/publish

# Copy the compiled binary
COPY --from=builder /usr/local/cargo/bin/moq-pub /usr/local/cargo/bin/moq-pub
# Copy the compiled binaries
COPY --from=builder /usr/local/cargo/bin /usr/local/cargo/bin
CMD [ "publish" ]

# moq-rs image with just the binaries
# moq-rs image with just the binaries (default)
FROM rust:latest as moq-rs

LABEL org.opencontainers.image.source=https://github.com/kixelated/moq-rs
Expand Down
53 changes: 0 additions & 53 deletions HACKATHON.md

This file was deleted.

19 changes: 19 additions & 0 deletions dev/clock
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -euo pipefail

# Change directory to the root of the project
cd "$(dirname "$0")/.."

# Use debug logging by default
export RUST_LOG="${RUST_LOG:-debug}"

# Connect to localhost by default.
HOST="${HOST:-localhost}"
PORT="${PORT:-4443}"
ADDR="${ADDR:-$HOST:$PORT}"
NAME="${NAME:-clock}"

# Combine the host and name into a URL.
URL="${URL:-"https://$ADDR/$NAME"}"

cargo run --bin moq-clock -- "$URL" "$@"
46 changes: 46 additions & 0 deletions moq-clock/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[package]
name = "moq-clock"
description = "CLOCK over QUIC"
authors = ["Luke Curley"]
repository = "https://github.com/kixelated/moq-rs"
license = "MIT OR Apache-2.0"

version = "0.1.0"
edition = "2021"

keywords = ["quic", "http3", "webtransport", "media", "live"]
categories = ["multimedia", "network-programming", "web-programming"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
moq-transport = { path = "../moq-transport" }

# QUIC
quinn = "0.10"
webtransport-quinn = "0.6"
url = "2"

# Crypto
rustls = { version = "0.21", features = ["dangerous_configuration"] }
rustls-native-certs = "0.6"
rustls-pemfile = "1"

# Async stuff
tokio = { version = "1", features = ["full"] }

# CLI, logging, error handling
clap = { version = "4", features = ["derive"] }
log = { version = "0.4", features = ["std"] }
env_logger = "0.9"
anyhow = { version = "1", features = ["backtrace"] }
tracing = "0.1"
tracing-subscriber = "0.3"

# CLOCK STUFF
chrono = "0.4"

[build-dependencies]
clap = { version = "4", features = ["derive"] }
clap_mangen = "0.2"
url = "2"
46 changes: 46 additions & 0 deletions moq-clock/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use clap::Parser;
use std::{net, path};
use url::Url;

#[derive(Parser, Clone, Debug)]
pub struct Config {
/// Listen for UDP packets on the given address.
#[arg(long, default_value = "[::]:0")]
pub bind: net::SocketAddr,

/// Connect to the given URL starting with https://
#[arg(value_parser = moq_url)]
pub url: Url,

/// Use the TLS root CA at this path, encoded as PEM.
///
/// This value can be provided multiple times for multiple roots.
/// If this is empty, system roots will be used instead
#[arg(long)]
pub tls_root: Vec<path::PathBuf>,

/// Danger: Disable TLS certificate verification.
///
/// Fine for local development, but should be used in caution in production.
#[arg(long)]
pub tls_disable_verify: bool,

/// Publish the current time to the relay, otherwise only subscribe.
#[arg(long)]
pub publish: bool,

/// The name of the clock track.
#[arg(long, default_value = "now")]
pub track: String,
}

fn moq_url(s: &str) -> Result<Url, String> {
let url = Url::try_from(s).map_err(|e| e.to_string())?;

// Make sure the scheme is moq
if url.scheme() != "https" {
return Err("url scheme must be https:// for WebTransport".to_string());
}

Ok(url)
}
Loading

0 comments on commit 93830a2

Please sign in to comment.