1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//! The in-process "internal catalog" [`re_server`].
//!
//! The app hosts a single in-process [`re_server`] (the "internal catalog").
//! The viewer then loads local resources by registering them with that catalog and opening the
//! resulting redap segment URI, instead of importing them directly.
//!
//! The viewer talks to the catalog in-process via [`InternalCatalog::connection`].
//! On native, the same handler is also served on the proxy server's port (see
//! [`InternalCatalog::grpc_service`]) so that other local processes can reach it.
//! The served endpoint is restricted to connections from the local machine.
use std::net::{Ipv4Addr, SocketAddr};
use std::sync::Arc;
use re_redap_client::Connection;
use re_server::RerunCloudHandlerBuilder;
#[cfg(not(target_arch = "wasm32"))]
use {
re_protos::cloud::v1alpha1::rerun_cloud_service_server::RerunCloudServiceServer,
re_server::RerunCloudHandler,
};
/// The in-process internal catalog.
pub struct InternalCatalog {
/// The origin under which the catalog is registered.
pub origin: re_uri::Origin,
/// The in-process connection the viewer uses to talk to the catalog.
pub connection: Connection,
/// The single handler shared between [`Self::connection`] and [`Self::grpc_service`].
#[cfg(not(target_arch = "wasm32"))]
handler: Arc<RerunCloudHandler>,
}
impl InternalCatalog {
/// The catalog as a gRPC service, to be served (loopback-only) on the proxy server's port.
#[cfg(not(target_arch = "wasm32"))]
pub fn grpc_service(&self) -> RerunCloudServiceServer<RerunCloudHandler> {
RerunCloudServiceServer::from_arc(self.handler.clone())
.max_decoding_message_size(re_redap_client::MAX_DECODING_MESSAGE_SIZE)
}
}
/// Build the in-process internal catalog, addressed at the proxy server's port.
#[cfg(not(target_arch = "wasm32"))]
pub fn build(proxy_addr: SocketAddr) -> InternalCatalog {
let origin = re_uri::Origin::from_scheme_and_socket_addr(
re_uri::Scheme::RerunHttp,
SocketAddr::from((Ipv4Addr::LOCALHOST, proxy_addr.port())),
);
let handler = Arc::new(RerunCloudHandlerBuilder::new().build());
let connection = Connection::from_service(handler.clone());
InternalCatalog {
origin,
connection,
handler,
}
}
/// Build the in-process internal catalog.
#[cfg(target_arch = "wasm32")]
pub fn build() -> InternalCatalog {
let handler = Arc::new(RerunCloudHandlerBuilder::new().build());
let connection = Connection::from_service(handler);
// The Wasm catalog lives purely in-process; the loopback address is a stable identity for the
// in-memory handler (matching the native construction), not a reachable endpoint.
let origin = re_uri::Origin::from_scheme_and_socket_addr(
re_uri::Scheme::RerunHttp,
SocketAddr::from((Ipv4Addr::LOCALHOST, 0)),
);
InternalCatalog { origin, connection }
}