-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocol.rs
74 lines (65 loc) · 2.2 KB
/
protocol.rs
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
use std::net::SocketAddr;
use serde::{Deserialize, Serialize};
pub const NO_COMPRESSION: &str = "";
pub const GZIP_COMPRESSION: &str = "gzip";
/// Messages sent from the proxy to the Ambient server
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum ServerMessage {
Allocation {
/// Id of this allocation
id: uuid::Uuid,
/// The endpoint that the players should use to connect to the server via proxy
allocated_endpoint: String,
/// HTTP root for assets downloading
assets_root: String,
/// The endpoint that the players could try to connect to the server directly
external_endpoint: SocketAddr,
},
PlayerConnected {
player_id: String,
},
RequestAsset {
key: String,
},
}
/// Headers for streams sent from proxy to the Ambient server
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum ServerStreamHeader {
/// Player opened a stream to the server
PlayerStreamOpened { player_id: String },
}
/// Messages sent from the Ambient server to the proxy
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum ClientMessage {
AllocateEndpoint { project_id: String },
}
/// Headers for streams sent from the Ambient server to the proxy
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum ClientStreamHeader {
/// Open a stream to selected player
OpenPlayerStream { player_id: String },
/// Store asset
StoreAsset {
key: String,
length: u32,
compression: String,
},
}
/// Header for datagrams sent between the Ambient server and the proxy (both ways)
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct DatagramInfo {
/// Recipient/origin of the datagram
pub player_id: String,
}
/// Stats returned from /stats/ALLOCATION_ID endpoint
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct ProxyStats {
/// The endpoint that the players should use to connect to the server via proxy
pub allocated_endpoint: String,
/// Total size of all assets
pub total_assets_size: u64,
/// Total number of assets
pub total_assets_count: usize,
/// Number of players currently connected via this proxy
pub players_count: usize,
}