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
4 changes: 4 additions & 0 deletions dart/moq/lib/socket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ typedef Endpoint = MoqSocketEndpoint;
/// An incoming track dial, consumed by accepting or rejecting it.
typedef IncomingTrack = MoqSocketIncomingTrack;

/// Whether [path] is an endpoint's broadcast, which only routes sessions and
/// carries no media.
bool isEndpoint(String path) => moqSocketIsEndpoint(path: path);

/// A track session with producer and reliably subscribed consumer halves.
typedef TrackStream = MoqSocketTrackStream;
25 changes: 25 additions & 0 deletions dart/moq_ffi/lib/src/moq.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20253,6 +20253,17 @@ List<String> moqVersions() {
);
}

bool moqSocketIsEndpoint({required String path}) {
return rustCallWithLifter(
(status) => uniffi_moq_ffi_fn_func_moq_socket_is_endpoint(
FfiConverterString.lower(path),
status,
),
FfiConverterBool.lift,
moqExceptionErrorHandler,
);
}

@Native<Pointer<Void> Function(Pointer<Void>, Pointer<RustCallStatus>)>(
assetId: _uniffiAssetId,
)
Expand Down Expand Up @@ -23628,6 +23639,14 @@ external RustBuffer uniffi_moq_ffi_fn_func_moq_versions(
Pointer<RustCallStatus> uniffiStatus,
);

@Native<Int8 Function(RustBuffer, Pointer<RustCallStatus>)>(
assetId: _uniffiAssetId,
)
external int uniffi_moq_ffi_fn_func_moq_socket_is_endpoint(
RustBuffer path,
Pointer<RustCallStatus> uniffiStatus,
);

@Native<
Void Function(
Pointer<Void>,
Expand Down Expand Up @@ -23967,6 +23986,9 @@ external int uniffi_moq_ffi_checksum_func_moq_qlog_supported();
@Native<Uint16 Function()>(assetId: _uniffiAssetId)
external int uniffi_moq_ffi_checksum_func_moq_versions();

@Native<Uint16 Function()>(assetId: _uniffiAssetId)
external int uniffi_moq_ffi_checksum_func_moq_socket_is_endpoint();

@Native<Uint16 Function()>(assetId: _uniffiAssetId)
external int uniffi_moq_ffi_checksum_method_moqaudioconsumer_cancel();

Expand Down Expand Up @@ -24852,6 +24874,9 @@ void _checkApiChecksums() {
if (uniffi_moq_ffi_checksum_func_moq_versions() != 28954) {
throw UniffiInternalError.panicked("UniFFI API checksum mismatch");
}
if (uniffi_moq_ffi_checksum_func_moq_socket_is_endpoint() != 51252) {
throw UniffiInternalError.panicked("UniFFI API checksum mismatch");
}
if (uniffi_moq_ffi_checksum_method_moqaudioconsumer_cancel() != 62285) {
throw UniffiInternalError.panicked("UniFFI API checksum mismatch");
}
Expand Down
6 changes: 5 additions & 1 deletion doc/concept/socket.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ each other. Both role segments start with `.`, so endpoints are

The announcements are used only for routing: they are how a relay finds an
endpoint. Connections are never announced. An endpoint's broadcasts hold only
session tracks, served on request.
session tracks, served on request. A worker that acts on every announced
broadcast, such as a recorder, skips them: a path whose parent segment is
`.server` or `.client` is an endpoint's. Every library checks it as
`is_endpoint` (`isEndpoint` in JS, Swift, Kotlin, and Dart, `IsEndpoint` in Go,
and `moq_socket_is_endpoint` in C).

## Sessions

Expand Down
4 changes: 4 additions & 0 deletions go/wrapper/socket/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
"moq.dev/moq/internal/bridge"
)

// IsEndpoint reports whether path is an endpoint's broadcast, which only routes sessions and
// carries no media.
func IsEndpoint(path string) (bool, error) { return ffi.MoqSocketIsEndpoint(path) }

// Endpoint is a server, a client, or both, and dials and accepts track sessions.
type Endpoint struct{ inner *ffi.MoqSocketEndpoint }

Expand Down
3 changes: 3 additions & 0 deletions kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/socket/Socket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ typealias Endpoint = uniffi.moq.MoqSocketEndpoint
/** An incoming track dial, consumed by accepting or rejecting it. */
typealias IncomingTrack = uniffi.moq.MoqSocketIncomingTrack

/** Whether [path] is an endpoint's broadcast, which only routes sessions and carries no media. */
fun isEndpoint(path: String): Boolean = uniffi.moq.moqSocketIsEndpoint(path)

/** A track session with producer and reliably subscribed consumer halves. */
typealias TrackStream = uniffi.moq.MoqSocketTrackStream
8 changes: 7 additions & 1 deletion py/moq-rs/moq/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
MoqSocketEndpoint,
MoqSocketIncomingTrack,
MoqSocketTrackStream,
moq_socket_is_endpoint,
)

from ._records import _track_info
Expand All @@ -14,7 +15,12 @@
from .subscribe import TrackConsumer
from .types import TrackInfo

__all__ = ["Endpoint", "IncomingTrack", "TrackStream"]
__all__ = ["Endpoint", "IncomingTrack", "TrackStream", "is_endpoint"]


def is_endpoint(path: str) -> bool:
"""Whether ``path`` is an endpoint's broadcast, which only routes sessions and carries no media."""
return moq_socket_is_endpoint(path)


class Endpoint:
Expand Down
23 changes: 0 additions & 23 deletions quest/m1/socket-endpoint-end.md

This file was deleted.

1 change: 1 addition & 0 deletions rs/moq-c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ int32_t moq_consume_track_cancel(uint32_t track);

// Sockets: two-way sessions between endpoints sharing an origin
int32_t moq_socket_create(uint32_t origin, const char *prefix, uintptr_t prefix_len, const char *id, uintptr_t id_len);
int32_t moq_socket_is_endpoint(const char *path, uintptr_t path_len); // 1, 0, or a negative code
int32_t moq_socket_close(uint32_t endpoint);
int32_t moq_socket_dial_track(uint32_t endpoint, const char *peer, uintptr_t peer_len, const moq_track_info *info, moq_status_callback on_stream, void *user_data);
int32_t moq_socket_accept_track(uint32_t endpoint, moq_status_callback on_incoming, void *user_data);
Expand Down
16 changes: 16 additions & 0 deletions rs/moq-c/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,22 @@ pub unsafe extern "C" fn moq_socket_create(
})
}

/// Whether `path` is a socket endpoint's broadcast, which only routes sessions and carries no
/// media, so a worker that acts on every announced broadcast can skip it.
///
/// Returns 1 if it is, 0 if not, or a negative code for a `path` that is not a valid path.
///
/// # Safety
/// - `path` must point at `path_len` bytes.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn moq_socket_is_endpoint(path: *const c_char, path_len: usize) -> i32 {
ffi::enter(move || {
let path = unsafe { ffi::parse_str(path, path_len)? };
let path = moq_net::Path::new(path).map_err(moq_net::Error::from)?;
Ok(i32::from(moq_net::socket::is_endpoint(&path)))
})
}

/// Close a socket endpoint and release its handle.
///
/// Withdraws the endpoint, ends its accept loops with a terminal `0`, fails its pending dials
Expand Down
9 changes: 9 additions & 0 deletions rs/moq-c/src/test/parity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,3 +680,12 @@ fn native_surfaces_are_unsupported_off_apple() {
MOQ_ERROR_UNSUPPORTED
);
}

#[test]
fn socket_is_endpoint() {
let is_endpoint = |path: &str| unsafe { moq_socket_is_endpoint(path.as_ptr().cast(), path.len()) };
assert_eq!(is_endpoint("room/.server/a"), 1);
assert_eq!(is_endpoint("room/.client/a"), 1);
assert_eq!(is_endpoint("room/a"), 0);
assert!(is_endpoint("room//a") < 0);
}
8 changes: 8 additions & 0 deletions rs/moq-ffi/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ use crate::ffi::{Background, OneShot, Polled};
use crate::origin::MoqOriginProducer;
use crate::producer::{MoqTrackInfo, MoqTrackProducer};

/// Whether `path` is a socket endpoint's broadcast, which only routes sessions and carries
/// no media, so a worker that acts on every announced broadcast can skip it.
#[uniffi::export]
pub fn moq_socket_is_endpoint(path: String) -> Result<bool, MoqError> {
let path = moq_net::Path::new(&path).map_err(moq_net::Error::from)?;
Ok(moq_net::socket::is_endpoint(&path))
}

/// A socket endpoint: its first dial announces it as a client, and its first accept as a
/// server.
#[derive(uniffi::Object)]
Expand Down
10 changes: 10 additions & 0 deletions rs/moq-ffi/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10043,3 +10043,13 @@ async fn group_calls_wake_ready_after_unlocking() {
let result = parked.result.lock().unwrap().take();
assert!(matches!(result, Some(Err(MoqError::Closed))), "{result:?}");
}

/// An endpoint's broadcast is told apart from media by path, and a malformed path fails.
#[test]
fn socket_is_endpoint() {
use crate::socket::moq_socket_is_endpoint;
assert!(moq_socket_is_endpoint("room/.server/a".into()).unwrap());
assert!(moq_socket_is_endpoint("room/.client/a".into()).unwrap());
assert!(!moq_socket_is_endpoint("room/a".into()).unwrap());
assert!(moq_socket_is_endpoint("room//a".into()).is_err());
}
Loading