feat: add control center, multiple relay nodes and P2P-first transport
This commit is contained in:
1 parent
0988e9c363
commit
2abfb63da9
44 files changed
+3477
-67
No files matched your search
@@ -14,6 +14,7 @@ use tokio_tungstenite::{
|
||||
MaybeTlsStream, WebSocketStream,
|
||||
};
|
||||
use url::Url;
|
||||
pub mod transport;
|
||||
|
||||
pub type Ws = WebSocketStream<MaybeTlsStream<TcpStream>>;
|
||||
pub const CONNECT_TIMEOUT: Duration = Duration::from_secs(10);
|
||||
@@ -112,7 +113,7 @@ pub async fn dial(url: Url, token: &str, connect_address: Option<&str>) -> Resul
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
pub struct Control {
|
||||
#[serde(rename = "type")]
|
||||
pub kind: String,
|
||||
@@ -122,13 +123,29 @@ pub struct Control {
|
||||
pub lease: Option<String>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub session: Option<String>,
|
||||
#[serde(default)]
|
||||
pub protocol: u8,
|
||||
#[serde(default)]
|
||||
pub signal_key: Option<String>,
|
||||
#[serde(default)]
|
||||
pub ice_servers: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub p2p_timeout_ms: u64,
|
||||
#[serde(default)]
|
||||
pub public_only: bool,
|
||||
#[serde(default)]
|
||||
pub routes: Vec<transport::Route>,
|
||||
#[serde(default)]
|
||||
pub sdp: Option<String>,
|
||||
#[serde(default)]
|
||||
pub node: Option<String>,
|
||||
}
|
||||
|
||||
pub async fn next_control(ws: &mut Ws) -> Result<Control> {
|
||||
loop {
|
||||
match ws.next().await.context("control connection closed")?? {
|
||||
Message::Text(text) => {
|
||||
if text.len() > 16 * 1024 {
|
||||
if text.len() > 128 * 1024 {
|
||||
bail!("control message too large");
|
||||
}
|
||||
return Ok(serde_json::from_str(&text)?);
|
||||
|
||||
Reference in new issue
Block a user