Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 37 additions & 45 deletions ffi/moq/ffi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ exclude = [
"group::Consumer::read_frames",
"group::Producer::write_frames",
"origin::Requesting",
"origin::Routing",
"server::Handshake",
"stats::Snapshot::control",
"stats::Snapshot::sessions",
Expand Down Expand Up @@ -123,6 +122,7 @@ exclude = [
"cli::Answer::exit",
"cli::Deprecated::changed",
"cli::Deprecated::flag",
"cli::Deprecated::removed",
"cli::Deprecated::toml",
"cli::FileSource",
"cli::Merge",
Expand All @@ -140,69 +140,69 @@ exclude = [
"panic::isolate",
"panic::message",
"quic::Error",
"quic::Limits",
"quic::LimitsError",
"quic::driver::AckFrequencyConfig",
"quic::driver::ApplicationClose",
"quic::driver::AsyncUdpSocket",
"quic::driver::Chunk",
"quic::driver::ClientConfig",
"quic::driver::ClosedStream",
"quic::driver::ConfigError",
"quic::driver::ConnectError",
"quic::driver::Connecting",
"quic::driver::Connection::accept_bi",
"quic::driver::Connection::accept_uni",
"quic::driver::Connection::close",
"quic::driver::Connection::close_reason",
"quic::driver::Connection::closed",
"quic::driver::Connection::congestion_state",
"quic::driver::Connection::handshake_data",
"quic::driver::Connection::open_bi",
"quic::driver::Connection::open_uni",
"quic::driver::Connection::peer_identity",
"quic::driver::Connection::read_datagram",
"quic::driver::Connection::send_datagram",
"quic::driver::Connection::set_limits",
"quic::driver::Connection::stats",
"quic::driver::ConnectionClose",
"quic::driver::ConnectionError",
"quic::driver::ConnectionId",
"quic::driver::ConnectionIdGenerator",
"quic::driver::ConnectionStats",
"quic::driver::CreditStats",
"quic::driver::Dir",
"quic::driver::EcnCodepoint",
"quic::driver::Endpoint",
"quic::driver::EndpointConfig",
"quic::driver::FrameStats",
"quic::driver::FrameType",
"quic::driver::IdleTimeout",
"quic::driver::Incoming",
"quic::driver::InvalidCid",
"quic::driver::Lease",
"quic::driver::MtuDiscoveryConfig",
"quic::driver::Limits",
"quic::driver::LimitsError",
"quic::driver::PathStats",
"quic::driver::ReadError",
"quic::driver::ReadExactError",
"quic::driver::ReadToEndError",
"quic::driver::RecvStream",
"quic::driver::ResetError",
"quic::driver::SendDatagramError",
"quic::driver::SendStream",
"quic::driver::ServerConfig",
"quic::driver::StoppedError",
"quic::driver::StreamId",
"quic::driver::Transmit",
"quic::driver::TransportConfig",
"quic::driver::TransportErrorCode",
"quic::driver::UdpSender",
"quic::driver::UdpStats",
"quic::driver::ValidationTokenConfig",
"quic::driver::VarInt",
"quic::driver::VarIntBoundsExceeded",
"quic::driver::Version",
"quic::driver::WriteError",
"quic::driver::Written",
"quic::driver::client",
"quic::driver::connection::Connecting",
"quic::driver::connection::Connection::accept_bi",
"quic::driver::connection::Connection::accept_uni",
"quic::driver::connection::Connection::close",
"quic::driver::connection::Connection::close_reason",
"quic::driver::connection::Connection::closed",
"quic::driver::connection::Connection::congestion_state",
"quic::driver::connection::Connection::handshake_data",
"quic::driver::connection::Connection::open_bi",
"quic::driver::connection::Connection::open_uni",
"quic::driver::connection::Connection::peer_identity",
"quic::driver::connection::Connection::read_datagram",
"quic::driver::connection::Connection::send_datagram",
"quic::driver::connection::Connection::set_limits",
"quic::driver::connection::Connection::stats",
"quic::driver::connection::Error",
"quic::driver::connection::SendDatagramError",
"quic::driver::connection::Stats",
"quic::driver::crypto",
"quic::driver::endpoint::AsyncUdpSocket",
"quic::driver::endpoint::CidGenerator",
"quic::driver::endpoint::Config",
"quic::driver::endpoint::ConnectError",
"quic::driver::endpoint::Endpoint",
"quic::driver::endpoint::Error",
"quic::driver::endpoint::Incoming",
"quic::driver::endpoint::Socket",
"quic::driver::server",
"quic::driver::transport",
"rustls",
"secret::Secret::as_bytes",
"server::Config::websocket",
Expand All @@ -222,8 +222,7 @@ exclude = [
"transport::RecvStream",
"transport::SendStream",
"transport::Session",
"unix::Listener::accept",
"unix::Listener::with_protocols",
"unix::Error",
"watch::Files",
"websocket::Error",
"websocket::Listener",
Expand Down Expand Up @@ -253,7 +252,7 @@ exclude = [
[crates.hang]
exclude = [
"Catalog::from_reader",
"catalog::Archive::timelines",
"Catalog::subscribe",
"catalog::Audio::enabled",
"catalog::Audio::ranked",
"catalog::Audio::renditions",
Expand Down Expand Up @@ -285,8 +284,6 @@ exclude = [
"health::publisher",
"health::viewer",
"stats::Snapshot",
"timeline::Record",
"timeline::RecordExt",
]

[crates.hang.rename]
Expand All @@ -309,10 +306,6 @@ exclude = [
"Source::resolve_reference",
"Source::stats",
"Source::subscribe_track",
"binary::Consumer::latest",
"binary::Consumer::next",
"binary::Consumer::poll_latest",
"binary::Consumer::poll_next",
"catalog::Entry",
"catalog::Guard",
"catalog::IntoRendition",
Expand Down Expand Up @@ -379,8 +372,6 @@ exclude = [
"json::Consumer",
"json::Snapshot",
"json::Stream",
"timeline::Entry",
"timeline::Producer::push",
]

[crates.moq-mux.rename]
Expand All @@ -404,6 +395,7 @@ exclude = [
# The waiter a driver's poll registers, which C makes from its waker and holds across polls.
[crates.kio]
exclude = [
"Bridge",
"Closed",
"Consumer",
"ConsumerWeak",
Expand Down
58 changes: 22 additions & 36 deletions ffi/moq/moq.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,6 @@ static int is(moq_buf buf, const char *s) {
return same;
}

/* The catalog `mutate` lends for its call, which lists the binary track: counts it in
* data. */
static void lists_state(void *data, moq_hang_catalog_extra *catalog) {
moq_buf json;
moq_hang_error *hang_err = NULL;
CHECK(moq_hang_catalog_extra_to_json(catalog, &json, &hang_err));
for (size_t i = 0; i + 5 <= json.len; i++) {
if (memcmp(json.ptr + i, "state", 5) == 0) {
(*(int *)data)++;
break;
}
}
moq_buf_free(json);
}

/* Moves the stats track in data into the lent catalog, in place. */
static void sets_stats(void *data, moq_hang_catalog_extra *catalog) {
moq_hang_catalog_extra_set_stats(catalog, data);
Expand Down Expand Up @@ -212,20 +197,21 @@ int main(void) {

/* Paths own their segments, so C builds them, and relative ones, from a string. */
moq_path *cam = NULL;
moq_path_too_long *too_long = NULL;
CHECK(moq_path_new(str("/cam/"), &cam, &too_long));
moq_path_invalid path_invalid;
CHECK(!moq_path_new(str("/cam/"), &cam, &path_invalid) && path_invalid == MOQ_PATH_INVALID_EMPTY_SEGMENT);
CHECK(moq_path_new(str("cam"), &cam, &path_invalid));
CHECK(is(moq_path_as_str(cam), "cam"));
moq_path *joined = NULL;
CHECK(moq_path_join(path, cam, &joined, &too_long));
CHECK(moq_path_join(path, cam, &joined, &path_invalid));
CHECK(is(moq_path_as_str(joined), "room/alice/cam"));
moq_path *stripped = moq_path_strip_prefix(joined, path);
CHECK(stripped != NULL && moq_path_eq(stripped, cam));
moq_path_free(stripped);
CHECK(moq_path_strip_prefix(path, joined) == NULL);
moq_relative *up = NULL;
CHECK(moq_relative_new(str("../bob"), &up, &too_long));
CHECK(moq_relative_new(str("../bob"), &up, &path_invalid));
moq_path *resolved = NULL;
CHECK(moq_path_resolve(joined, up, &resolved, &too_long));
CHECK(moq_path_resolve(joined, up, &resolved, &path_invalid));
CHECK(is(moq_path_as_str(resolved), "room/bob"));
moq_path_free(resolved);
moq_relative_free(up);
Expand Down Expand Up @@ -290,9 +276,9 @@ int main(void) {
moq_mux_error_free(mux_err);
mux_err = NULL;

/* A binary track the catalog lists, published through moq-mux's generic
* `binary_snapshot` at the config C builds, by a catalog at moq-mux's untyped
* extension, each instance named by the last segment of each argument. */
/* A catalog at moq-mux's untyped extension, from the config C builds, whose generic
* `is_claimed` is named by the last segment of its argument, and whose `mutate` lends
* the catalog to C, which sets its fields in place. */
moq_broadcast_info *listed = moq_broadcast_info_new();
moq_broadcast_producer *publisher = moq_broadcast_info_produce(listed);
moq_broadcast_info_free(listed);
Expand All @@ -304,29 +290,29 @@ int main(void) {
moq_catalog_producer_extra *catalog = NULL;
CHECK(moq_catalog_producer_extra_new(publisher, extra, &catalog, &mux_err));
moq_catalog_config_extra_free(extra);
moq_track_producer *state = NULL;
CHECK(moq_broadcast_producer_create_track(publisher, str("state"), NULL, &state, &err));
moq_binary_config *binary = moq_binary_config_default();
moq_binary_snapshot *snapshot = NULL;
CHECK(moq_catalog_producer_extra_binary_snapshot_config(catalog, state, binary, &snapshot, &mux_err));
moq_binary_config_free(binary);
moq_track_producer_free(state);
CHECK(is(moq_binary_snapshot_name(snapshot), "state"));
CHECK(moq_binary_snapshot_update(snapshot, str("latest"), &mux_err));
int listed_state = 0;
CHECK(moq_catalog_producer_extra_mutate(catalog, lists_state, &listed_state, &mux_err));
CHECK(listed_state == 1);
CHECK(!moq_catalog_producer_extra_is_claimed_binary_config(catalog, str("state")));
/* A field of the lent catalog, set in place: the next call reads it. */
moq_catalog_stats *stats = moq_catalog_stats_new(str("stats"));
CHECK(moq_catalog_producer_extra_mutate(catalog, sets_stats, stats, &mux_err));
moq_catalog_stats_free(stats);
int listed_stats = 0;
CHECK(moq_catalog_producer_extra_mutate(catalog, lists_stats, &listed_stats, &mux_err));
CHECK(listed_stats == 1);
moq_binary_snapshot_free(snapshot);
moq_catalog_producer_extra_free(catalog);
moq_broadcast_producer_free(publisher);

/* Outside any tokio runtime, as C is, moq-tokio runs on the fallback it starts. */
moq_origin_producer *spawned = moq_origin_spawn();
moq_origin_producer_free(spawned);
moq_connect_config *client_config = moq_connect_config_default();
moq_quic_config *quic = moq_quic_config_default();
moq_tokio_client *tokio_client = NULL;
moq_tokio_error *tokio_err = NULL;
CHECK(moq_connect_config_init(client_config, quic, &tokio_client, &tokio_err));
moq_connect_config_free(client_config);
moq_quic_config_free(quic);
moq_tokio_client_free(tokio_client);

/* moq-tokio's terminal connect errors, which moq-net's `Error` shares no names with. */
moq_connect_error unauthorized = MOQ_CONNECT_ERROR_UNAUTHORIZED;
CHECK(moq_connect_error_is_auth(&unauthorized));
Expand Down
24 changes: 11 additions & 13 deletions ffi/moq/moq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ int main() {
CHECK(is(path.as_str(), "room/alice"));

// Paths own their segments, so C++ builds them, and relative ones, from a string.
auto cam = moq::path::new_("/cam/");
auto empty = moq::path::new_("/cam/");
CHECK(!empty && empty.error() == moq::path_invalid::empty_segment);
auto cam = moq::path::new_("cam");
CHECK(cam && is(cam->as_str(), "cam"));
auto joined = path.join(*cam);
CHECK(joined && is(joined->as_str(), "room/alice/cam"));
Expand Down Expand Up @@ -172,29 +174,25 @@ int main() {
auto truncated = moq::codec_opus_audio_config(moq::view(head, 8));
CHECK(!truncated && !truncated.error().to_string().empty());

// A binary track the catalog lists, published through moq-mux's generic
// `binary_snapshot` at the config C++ builds, by a catalog at moq-mux's untyped
// extension, each instance named by the last segment of each argument.
// A catalog at moq-mux's untyped extension, from the config C++ builds, whose generic
// `is_claimed` is named by the last segment of its argument, and whose `mutate` lends
// the catalog to C++.
{
moq::broadcast_producer publisher = moq::broadcast_info::new_().produce();
moq::catalog_config_extra extra =
moq::catalog_config::default_().with_catalog_extra(moq::hang_catalog_extra::default_());
auto catalog = moq::catalog_producer_extra::new_(publisher, std::move(extra));
CHECK(catalog);
auto state = publisher.create_track("state", std::nullopt);
CHECK(state);
auto snapshot = catalog->binary_snapshot_config(std::move(*state), moq::binary_config::default_());
CHECK(snapshot && is(snapshot->name(), "state"));
CHECK(snapshot->update("latest"));
int listed_state = 0;
CHECK(!catalog->is_claimed_binary_config("state"));
int read_catalog = 0;
CHECK(catalog->mutate([&](moq::hang_catalog_extra &lent) {
auto json = lent.to_json();
CHECK(json);
if (json && json.value().str().find("state") != std::string_view::npos) {
listed_state++;
if (json && json.value().str().substr(0, 1) == "{") {
read_catalog++;
}
}));
CHECK(listed_state == 1);
CHECK(read_catalog == 1);
}

// A session's config, filled in as Rust assigns it, and a nested field by getting a copy,
Expand Down
26 changes: 15 additions & 11 deletions ffi/moq/moq.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,14 @@ fun main() {
expect(path.asStr() == "room/alice", "a broadcast has its path")

// Paths own their segments, so Kotlin builds them, and relative ones, from a string.
val cam = Path.new("/cam/")
expect(cam.asStr() == "cam", "a path trims its slashes")
try {
Path.new("/cam/")
expect(false, "a path with an empty segment is an error")
} catch (e: PathInvalidException) {
expect(e.error == PathInvalid.EMPTY_SEGMENT, "an empty segment is its own error")
}
val cam = Path.new("cam")
expect(cam.asStr() == "cam", "a path builds from its segments")
val joined = path.join(cam)
expect(joined.asStr() == "room/alice/cam", "paths join")
expect(joined.stripPrefix(path) == cam, "a path strips its prefix")
Expand Down Expand Up @@ -176,20 +182,18 @@ fun main() {
expect(e.message.isNotEmpty(), "a truncated head's error has a message")
}

// A binary track the catalog lists, published through moq-mux's generic
// `binary_snapshot` at the config Kotlin builds, by a catalog at moq-mux's untyped
// extension, each instance named by the last segment of each argument.
// A catalog at moq-mux's untyped extension, from the config Kotlin builds, whose generic
// `is_claimed` is named by the last segment of its argument, and whose `mutate` lends
// the catalog to Kotlin.
val publisher = BroadcastInfo.new().produce()
val extra = CatalogConfig.default().withCatalogExtra(HangCatalogExtra.default())
val catalog = CatalogProducerExtra.new(publisher, extra)
val snapshot = catalog.binarySnapshotConfig(publisher.createTrack("state", null), BinaryConfig.default())
expect(snapshot.name() == "state", "a snapshot has its track's name")
snapshot.update("latest")
var listed = 0
expect(!catalog.isClaimedBinaryConfig("state"), "an unclaimed name is not claimed")
var read = 0
catalog.mutate { lent ->
if (lent.toJson().contains("state")) listed++
if (lent.toJson().startsWith("{")) read++
}
expect(listed == 1, "the catalog lists the snapshot's track")
expect(read == 1, "mutate lends the catalog once")

// moq-tokio's terminal connect errors, which moq-net's `Error` shares no names with.
expect(ConnectError.UNAUTHORIZED.isAuth(), "unauthorized is an auth error")
Expand Down
1 change: 0 additions & 1 deletion quest/m1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ are folded into the [exporter's](/quest/m1/ffi-export/README.md). The

## Required

- [Bump the moq pin past the fallback runtime](/quest/m1/moq-pin.md) - `ts` and `ffi` build against moq with moq-tokio's fallback runtime
- [Waiting: publish the UniFFI fork](/quest/m1/uniffi-release.md) - the fork publishes to crates.io under `rust2-*` names, once the maintainer decides it should
- [Exporter](/quest/m1/ffi-export/README.md) - moq's bindings exported from its crates' `pub` API, replacing the fork
- [Land main through quest land](/quest/m1/land.md) - every queued PR lands as one tested batch through the shared gate
1 change: 1 addition & 0 deletions quest/m1/ffi-export/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Every generator on the C ABI:
- [moq-clock's C names once it moves into kio](/quest/m1/ffi-export/crates.md) - `moq_now` and `moq_origin` become the clock's, after moq moves it into `kio::clock`
- [Sessions on moq-tokio](/quest/m1/ffi-export/session-tokio.md) - bindings connect and accept with one call, the library running moq-tokio inside
- [Sessions on sans-IO QUIC](/quest/m1/ffi-export/session-quic.md) - bindings move UDP datagrams and drive the session's poll themselves
- [Glue that builds without warnings](/quest/m1/ffi-export/warnings.md) - the exporter's Rust glue builds with `-D warnings`
- [The recursion depth lint on moq's export](/quest/m1/ffi-export/recursion-lint.md) - `just ffi moq` builds clean before the lint becomes an error
- [C++ bindings on MSVC and Clang](/quest/m1/ffi-export/cpp.md) - the C++ header built and tested beyond GCC on Linux
- [Kotlin bindings: zero-copy payloads and the read path](/quest/m1/ffi-export/kotlin.md) - the Kotlin lends bytes without a copy, and reads at JNI's cost
Expand Down
Loading