1impl<C: PlayitHttpClient> PlayitApiClient<C> {
2 pub fn new(client: C) -> Self {
3 PlayitApiClient { client }
4 }
5 pub fn get_client(&self) -> &C {
6 &self.client
7 }
8 fn unwrap<S, F>(res: Result<ApiResult<S, F>, C::Error>) -> Result<S, ApiError<F, C::Error>> {
9 match res {
10 Ok(ApiResult::Success(v)) => Ok(v),
11 Ok(ApiResult::Fail(fail)) => Err(ApiError::Fail(fail)),
12 Ok(ApiResult::Error(error)) => Err(ApiError::ApiError(error)),
13 Err(error) => Err(ApiError::ClientError(error)),
14 }
15 }
16 fn unwrap_no_fail<S>(res: Result<ApiResult<S, ()>, C::Error>) -> Result<S, ApiErrorNoFail<C::Error>> {
17 match res {
18 Ok(ApiResult::Success(v)) => Ok(v),
19 Ok(ApiResult::Fail(_)) => panic!(),
20 Ok(ApiResult::Error(error)) => Err(ApiErrorNoFail::ApiError(error)),
21 Err(error) => Err(ApiErrorNoFail::ClientError(error)),
22 }
23 }
24 #[track_caller]
25 pub fn tunnels_create(&self, req: ReqTunnelsCreate) -> impl std::future::Future<Output = Result<ObjectId, ApiError<TunnelCreateError, C::Error>>> + '_ {
26 let caller = std::panic::Location::caller();
27 async {
28 Self::unwrap(self.client.call(caller, "/tunnels/create", req).await)
29 }
30 }
31 #[track_caller]
32 pub fn tunnels_delete(&self, req: ReqTunnelsDelete) -> impl std::future::Future<Output = Result<(), ApiError<DeleteError, C::Error>>> + '_ {
33 let caller = std::panic::Location::caller();
34 async {
35 Self::unwrap(self.client.call(caller, "/tunnels/delete", req).await)
36 }
37 }
38 #[track_caller]
39 pub fn claim_details(&self, req: ReqClaimDetails) -> impl std::future::Future<Output = Result<AgentClaimDetails, ApiError<ClaimDetailsError, C::Error>>> + '_ {
40 let caller = std::panic::Location::caller();
41 async {
42 Self::unwrap(self.client.call(caller, "/claim/details", req).await)
43 }
44 }
45 #[track_caller]
46 pub fn claim_setup(&self, req: ReqClaimSetup) -> impl std::future::Future<Output = Result<ClaimSetupResponse, ApiError<ClaimSetupError, C::Error>>> + '_ {
47 let caller = std::panic::Location::caller();
48 async {
49 Self::unwrap(self.client.call(caller, "/claim/setup", req).await)
50 }
51 }
52 #[track_caller]
53 pub fn claim_exchange(&self, req: ReqClaimExchange) -> impl std::future::Future<Output = Result<AgentSecretKey, ApiError<ClaimExchangeError, C::Error>>> + '_ {
54 let caller = std::panic::Location::caller();
55 async {
56 Self::unwrap(self.client.call(caller, "/claim/exchange", req).await)
57 }
58 }
59 #[track_caller]
60 pub fn claim_accept(&self, req: ReqClaimAccept) -> impl std::future::Future<Output = Result<AgentAccepted, ApiError<ClaimAcceptError, C::Error>>> + '_ {
61 let caller = std::panic::Location::caller();
62 async {
63 Self::unwrap(self.client.call(caller, "/claim/accept", req).await)
64 }
65 }
66 #[track_caller]
67 pub fn claim_reject(&self, req: ReqClaimReject) -> impl std::future::Future<Output = Result<(), ApiError<ClaimRejectError, C::Error>>> + '_ {
68 let caller = std::panic::Location::caller();
69 async {
70 Self::unwrap(self.client.call(caller, "/claim/reject", req).await)
71 }
72 }
73 #[track_caller]
74 pub fn proto_register(&self, req: ReqProtoRegister) -> impl std::future::Future<Output = Result<SignedAgentKey, ApiErrorNoFail<C::Error>>> + '_ {
75 let caller = std::panic::Location::caller();
76 async {
77 Self::unwrap_no_fail(self.client.call(caller, "/proto/register", req).await)
78 }
79 }
80 #[track_caller]
81 pub fn login_guest(&self) -> impl std::future::Future<Output = Result<WebSession, ApiError<GuestLoginError, C::Error>>> + '_ {
82 let caller = std::panic::Location::caller();
83 async {
84 Self::unwrap(self.client.call(caller, "/login/guest", ReqLoginGuest {}).await)
85 }
86 }
87 #[track_caller]
88 pub fn agents_routing_get(&self, req: ReqAgentsRoutingGet) -> impl std::future::Future<Output = Result<AgentRouting, ApiError<AgentRoutingGetError, C::Error>>> + '_ {
89 let caller = std::panic::Location::caller();
90 async {
91 Self::unwrap(self.client.call(caller, "/agents/routing/get", req).await)
92 }
93 }
94 #[track_caller]
95 pub fn agents_rundata(&self) -> impl std::future::Future<Output = Result<AgentRunData, ApiErrorNoFail<C::Error>>> + '_ {
96 let caller = std::panic::Location::caller();
97 async {
98 Self::unwrap_no_fail(self.client.call(caller, "/agents/rundata", ReqAgentsRundata {}).await)
99 }
100 }
101 #[track_caller]
102 pub fn ping_submit(&self, req: ReqPingSubmit) -> impl std::future::Future<Output = Result<(), ApiErrorNoFail<C::Error>>> + '_ {
103 let caller = std::panic::Location::caller();
104 async {
105 Self::unwrap_no_fail(self.client.call(caller, "/ping/submit", req).await)
106 }
107 }
108 #[track_caller]
109 pub fn ping_get(&self) -> impl std::future::Future<Output = Result<PingExperiments, ApiErrorNoFail<C::Error>>> + '_ {
110 let caller = std::panic::Location::caller();
111 async {
112 Self::unwrap_no_fail(self.client.call(caller, "/ping/get", ReqPingGet {}).await)
113 }
114 }
115 #[track_caller]
116 pub fn tunnels_list_json(&self, req: ReqTunnelsList) -> impl std::future::Future<Output = Result<serde_json::Value, ApiErrorNoFail<C::Error>>> + '_ {
117 let caller = std::panic::Location::caller();
118 async {
119 Self::unwrap_no_fail(self.client.call(caller, "/tunnels/list", req).await)
120 }
121 }
122 #[track_caller]
123 pub fn agents_list_json(&self) -> impl std::future::Future<Output = Result<serde_json::Value, ApiErrorNoFail<C::Error>>> + '_ {
124 let caller = std::panic::Location::caller();
125 async {
126 Self::unwrap_no_fail(self.client.call(caller, "/agents/list", ReqAgentsList {}).await)
127 }
128 }
129 #[track_caller]
130 pub fn query_region(&self, req: ReqQueryRegion) -> impl std::future::Future<Output = Result<QueryRegion, ApiError<QueryRegionError, C::Error>>> + '_ {
131 let caller = std::panic::Location::caller();
132 async {
133 Self::unwrap(self.client.call(caller, "/query/region", req).await)
134 }
135 }
136 #[track_caller]
137 pub fn tunnels_update(&self, req: ReqTunnelsUpdate) -> impl std::future::Future<Output = Result<(), ApiError<UpdateError, C::Error>>> + '_ {
138 let caller = std::panic::Location::caller();
139 async {
140 Self::unwrap(self.client.call(caller, "/tunnels/update", req).await)
141 }
142 }
143 #[track_caller]
144 pub fn tunnels_firewall_assign(&self, req: ReqTunnelsFirewallAssign) -> impl std::future::Future<Output = Result<(), ApiError<TunnelsFirewallAssignError, C::Error>>> + '_ {
145 let caller = std::panic::Location::caller();
146 async {
147 Self::unwrap(self.client.call(caller, "/tunnels/firewall/assign", req).await)
148 }
149 }
150 #[track_caller]
151 pub fn tunnels_proxy_set(&self, req: ReqTunnelsProxySet) -> impl std::future::Future<Output = Result<(), ApiError<TunnelProxySetError, C::Error>>> + '_ {
152 let caller = std::panic::Location::caller();
153 async {
154 Self::unwrap(self.client.call(caller, "/tunnels/proxy/set", req).await)
155 }
156 }
157}
158
159#[derive(serde::Serialize, serde::Deserialize, Debug)]
160#[serde(tag = "status", content = "data")]
161pub enum ApiResult<S, F> {
162 #[serde(rename = "success")]
163 Success(S),
164 #[serde(rename = "fail")]
165 Fail(F),
166 #[serde(rename = "error")]
167 Error(ApiResponseError),
168}
169
170#[derive(Debug, serde::Serialize)]
171pub enum ApiError<F, C> {
172 Fail(F),
173 ApiError(ApiResponseError),
174 ClientError(C),
175}
176
177impl<F: std::fmt::Debug, C: std::fmt::Debug> std::fmt::Display for ApiError<F, C> {
178 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
179 write!(f, "{:?}", self)
180 }
181}
182
183impl<F: std::fmt::Debug, C: std::fmt::Debug> std::error::Error for ApiError<F, C> {
184}
185
186
187#[derive(Debug, serde::Serialize)]
188pub enum ApiErrorNoFail<C> {
189 ApiError(ApiResponseError),
190 ClientError(C),
191}
192
193impl<C: std::fmt::Debug> std::fmt::Display for ApiErrorNoFail<C> {
194 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
195 write!(f, "{:?}", self)
196 }
197}
198
199impl<C: std::fmt::Debug> std::error::Error for ApiErrorNoFail<C> {
200}
201
202
203
204pub trait PlayitHttpClient {
205 type Error;
206
207 fn call<Req: serde::Serialize + std::marker::Send, Res: serde::de::DeserializeOwned, Err: serde::de::DeserializeOwned>(&self, caller: &'static std::panic::Location<'static>, path: &str, req: Req) -> impl std::future::Future<Output = Result<ApiResult<Res, Err>, Self::Error>>;
208}
209
210#[derive(Clone)]
211pub struct PlayitApiClient<C: PlayitHttpClient> {
212 client: C,
213}
214
215#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
216#[serde(tag = "type", content = "message")]
217pub enum ApiResponseError {
218 #[serde(rename = "validation")]
219 Validation(String),
220 #[serde(rename = "path-not-found")]
221 PathNotFound(PathNotFound),
222 #[serde(rename = "auth")]
223 Auth(AuthError),
224 #[serde(rename = "internal")]
225 Internal(ApiInternalError),
226}
227
228
229#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
230pub struct PathNotFound {
231 pub path: String,
232}
233
234#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
235pub enum AuthError {
236 AuthRequired,
237 InvalidHeader,
238 InvalidSignature,
239 InvalidTimestamp,
240 InvalidApiKey,
241 InvalidAgentKey,
242 SessionExpired,
243 InvalidAuthType,
244 ScopeNotAllowed,
245 NoLongerValid,
246 GuestAccountNotAllowed,
247 EmailMustBeVerified,
248 AccountDoesNotExist,
249 AdminOnly,
250 InvalidToken,
251 TotpRequred,
252 NotAllowedWithReadOnly,
253 AgentNotSelfManaged,
254}
255
256#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
257pub struct ApiInternalError {
258 pub trace_id: String,
259}
260
261impl std::fmt::Display for ApiResponseError {
262 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
263 write!(f, "{:?}", self)
264 }
265}
266
267impl std::error::Error for ApiResponseError {
268}
269#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
270pub struct ReqTunnelsCreate {
271 pub name: Option<String>,
272 pub tunnel_type: Option<TunnelType>,
273 pub port_type: PortType,
274 pub port_count: u16,
275 pub origin: TunnelOriginCreate,
276 pub enabled: bool,
277 pub alloc: Option<TunnelCreateUseAllocation>,
278 pub firewall_id: Option<uuid::Uuid>,
279 pub proxy_protocol: Option<ProxyProtocol>,
280}
281
282#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
283pub enum TunnelType {
284 #[serde(rename = "minecraft-java")]
285 MinecraftJava,
286 #[serde(rename = "minecraft-bedrock")]
287 MinecraftBedrock,
288 #[serde(rename = "valheim")]
289 Valheim,
290 #[serde(rename = "terraria")]
291 Terraria,
292 #[serde(rename = "starbound")]
293 Starbound,
294 #[serde(rename = "rust")]
295 Rust,
296 #[serde(rename = "7days")]
297 Num7days,
298 #[serde(rename = "unturned")]
299 Unturned,
300}
301
302#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
303pub enum PortType {
304 #[serde(rename = "tcp")]
305 Tcp,
306 #[serde(rename = "udp")]
307 Udp,
308 #[serde(rename = "both")]
309 Both,
310}
311
312
313#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
314#[serde(tag = "type", content = "data")]
315pub enum TunnelOriginCreate {
316 #[serde(rename = "default")]
317 Default(AssignedDefaultCreate),
318 #[serde(rename = "agent")]
319 Agent(AssignedAgentCreate),
320 #[serde(rename = "managed")]
321 Managed(AssignedManagedCreate),
322}
323
324#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
325pub struct AssignedDefaultCreate {
326 pub local_ip: std::net::IpAddr,
327 pub local_port: Option<u16>,
328}
329
330
331#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
332pub struct AssignedAgentCreate {
333 pub agent_id: uuid::Uuid,
334 pub local_ip: std::net::IpAddr,
335 pub local_port: Option<u16>,
336}
337
338
339#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
340pub struct AssignedManagedCreate {
341 pub agent_id: Option<uuid::Uuid>,
342}
343
344
345#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
346#[serde(tag = "type", content = "details")]
347pub enum TunnelCreateUseAllocation {
348 #[serde(rename = "dedicated-ip")]
349 DedicatedIp(UseAllocDedicatedIp),
350 #[serde(rename = "port-allocation")]
351 PortAllocation(UseAllocPortAlloc),
352 #[serde(rename = "region")]
353 Region(UseRegion),
354}
355
356#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
357pub struct UseAllocDedicatedIp {
358 pub ip_hostname: String,
359 pub port: Option<u16>,
360}
361
362#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
363pub struct UseAllocPortAlloc {
364 pub alloc_id: uuid::Uuid,
365}
366
367#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
368pub struct UseRegion {
369 pub region: AllocationRegion,
370}
371
372#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
373pub enum AllocationRegion {
374 #[serde(rename = "smart-global")]
375 SmartGlobal,
376 #[serde(rename = "global")]
377 Global,
378 #[serde(rename = "north-america")]
379 NorthAmerica,
380 #[serde(rename = "europe")]
381 Europe,
382 #[serde(rename = "asia")]
383 Asia,
384 #[serde(rename = "india")]
385 India,
386 #[serde(rename = "south-america")]
387 SouthAmerica,
388}
389
390#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
391pub enum ProxyProtocol {
392 #[serde(rename = "proxy-protocol-v1")]
393 ProxyProtocolV1,
394 #[serde(rename = "proxy-protocol-v2")]
395 ProxyProtocolV2,
396}
397
398#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
399pub struct ObjectId {
400 pub id: uuid::Uuid,
401}
402
403#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
404pub enum TunnelCreateError {
405 AgentIdRequired,
406 AgentNotFound,
407 InvalidAgentId,
408 DedicatedIpNotFound,
409 DedicatedIpPortNotAvailable,
410 DedicatedIpNotEnoughSpace,
411 PortAllocNotFound,
412 InvalidIpHostname,
413 ManagedMissingAgentId,
414 InvalidPortCount,
415 RequiresVerifiedAccount,
416}
417
418impl std::fmt::Display for TunnelCreateError {
419 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
420 write!(f, "{:?}", self)
421 }
422}
423
424impl std::error::Error for TunnelCreateError {
425}
426#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
427pub struct ReqTunnelsDelete {
428 pub tunnel_id: uuid::Uuid,
429}
430
431
432#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
433pub enum DeleteError {
434 TunnelNotFound,
435}
436
437#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
438pub struct ReqClaimDetails {
439 pub code: String,
440}
441
442#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
443pub struct AgentClaimDetails {
444 pub name: String,
445 pub remote_ip: std::net::IpAddr,
446 pub agent_type: AgentType,
447 pub version: String,
448}
449
450#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
451pub enum AgentType {
452 #[serde(rename = "default")]
453 Default,
454 #[serde(rename = "assignable")]
455 Assignable,
456 #[serde(rename = "self-managed")]
457 SelfManaged,
458}
459
460#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
461pub enum ClaimDetailsError {
462 AlreadyClaimed,
463 AlreadyRejected,
464 ClaimExpired,
465 DifferentOwner,
466 WaitingForAgent,
467 InvalidCode,
468}
469
470impl std::fmt::Display for ClaimDetailsError {
471 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
472 write!(f, "{:?}", self)
473 }
474}
475
476impl std::error::Error for ClaimDetailsError {
477}
478#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
479pub struct ReqClaimSetup {
480 pub code: String,
481 pub agent_type: AgentType,
482 pub version: String,
483}
484
485#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
486pub enum ClaimSetupResponse {
487 WaitingForUserVisit,
488 WaitingForUser,
489 UserAccepted,
490 UserRejected,
491}
492
493#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
494pub enum ClaimSetupError {
495 InvalidCode,
496 CodeExpired,
497 VersionTextTooLong,
498}
499
500impl std::fmt::Display for ClaimSetupError {
501 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
502 write!(f, "{:?}", self)
503 }
504}
505
506impl std::error::Error for ClaimSetupError {
507}
508#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
509pub struct ReqClaimExchange {
510 pub code: String,
511}
512
513#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
514pub struct AgentSecretKey {
515 pub secret_key: String,
516}
517
518#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
519pub enum ClaimExchangeError {
520 CodeNotFound,
521 CodeExpired,
522 UserRejected,
523 NotAccepted,
524 NotSetup,
525}
526
527impl std::fmt::Display for ClaimExchangeError {
528 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
529 write!(f, "{:?}", self)
530 }
531}
532
533impl std::error::Error for ClaimExchangeError {
534}
535#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
536pub struct ReqClaimAccept {
537 pub code: String,
538 pub name: String,
539 pub agent_type: AgentType,
540}
541
542#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
543pub struct AgentAccepted {
544 pub agent_id: uuid::Uuid,
545}
546
547#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
548pub enum ClaimAcceptError {
549 InvalidCode,
550 AgentNotReady,
551 CodeNotFound,
552 InvalidAgentType,
553 ClaimAlreadyAccepted,
554 ClaimRejected,
555 CodeExpired,
556 InvalidName,
557}
558
559impl std::fmt::Display for ClaimAcceptError {
560 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
561 write!(f, "{:?}", self)
562 }
563}
564
565impl std::error::Error for ClaimAcceptError {
566}
567#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
568pub struct ReqClaimReject {
569 pub code: String,
570}
571
572#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
573pub enum ClaimRejectError {
574 InvalidCode,
575 CodeNotFound,
576 ClaimAccepted,
577 ClaimAlreadyRejected,
578}
579
580impl std::fmt::Display for ClaimRejectError {
581 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
582 write!(f, "{:?}", self)
583 }
584}
585
586impl std::error::Error for ClaimRejectError {
587}
588#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
589pub struct ReqProtoRegister {
590 pub agent_version: PlayitAgentVersion,
591 pub client_addr: std::net::SocketAddr,
592 pub tunnel_addr: std::net::SocketAddr,
593}
594
595#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
596pub struct PlayitAgentVersion {
597 pub version: AgentVersion,
598 pub official: bool,
599 pub details_website: Option<String>,
600 pub proto_version: u64,
601}
602
603#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
604pub struct AgentVersion {
605 pub platform: Platform,
606 pub version: String,
607 pub has_expired: bool,
608}
609
610#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
611pub enum Platform {
612 #[serde(rename = "linux")]
613 Linux,
614 #[serde(rename = "freebsd")]
615 Freebsd,
616 #[serde(rename = "windows")]
617 Windows,
618 #[serde(rename = "macos")]
619 Macos,
620 #[serde(rename = "android")]
621 Android,
622 #[serde(rename = "ios")]
623 Ios,
624 #[serde(rename = "docker")]
625 Docker,
626 #[serde(rename = "minecraft-plugin")]
627 MinecraftPlugin,
628 #[serde(rename = "unknown")]
629 Unknown,
630}
631
632
633
634#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
635pub struct SignedAgentKey {
636 pub key: String,
637}
638
639#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
640pub struct ReqLoginGuest {
641}
642
643#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
644pub struct WebSession {
645 pub session_key: String,
646 pub auth: WebAuthToken,
647}
648
649#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
650pub struct WebAuthToken {
651 pub update_version: u32,
652 pub account_id: u64,
653 pub timestamp: u64,
654 pub account_status: AccountStatus,
655 pub totp_status: TotpStatus,
656 pub admin_id: Option<std::num::NonZeroU64>,
657 pub read_only: bool,
658}
659
660
661#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
662pub enum AccountStatus {
663 #[serde(rename = "guest")]
664 Guest,
665 #[serde(rename = "email-not-verified")]
666 EmailNotVerified,
667 #[serde(rename = "verified")]
668 Verified,
669}
670
671#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
672#[serde(tag = "status")]
673pub enum TotpStatus {
674 #[serde(rename = "required")]
675 Required,
676 #[serde(rename = "not-setup")]
677 NotSetup,
678 #[serde(rename = "signed")]
679 Signed(SignedEpoch),
680}
681
682#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
683pub struct SignedEpoch {
684 pub epoch_sec: u32,
685}
686
687#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
688pub enum GuestLoginError {
689 AccountIsNotGuest,
690}
691
692#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
693pub struct ReqAgentsRoutingGet {
694 pub agent_id: Option<uuid::Uuid>,
695}
696
697#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
698pub struct AgentRouting {
699 pub agent_id: uuid::Uuid,
700 pub targets4: Vec<std::net::Ipv4Addr>,
701 pub targets6: Vec<std::net::Ipv6Addr>,
702 pub disable_ip6: bool,
703}
704
705
706
707#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
708pub enum AgentRoutingGetError {
709 MissingAgentId,
710 InvalidAgentId,
711}
712
713impl std::fmt::Display for AgentRoutingGetError {
714 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
715 write!(f, "{:?}", self)
716 }
717}
718
719impl std::error::Error for AgentRoutingGetError {
720}
721#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
722pub struct ReqAgentsRundata {
723}
724
725#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
726pub struct AgentRunData {
727 pub agent_id: uuid::Uuid,
728 pub agent_type: AgentType,
729 pub account_status: AgentAccountStatus,
730 pub tunnels: Vec<AgentTunnel>,
731 pub pending: Vec<AgentPendingTunnel>,
732 pub account_features: AccountFeatures,
733}
734
735#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
736pub enum AgentAccountStatus {
737 #[serde(rename = "account-delete-scheduled")]
738 AccountDeleteScheduled,
739 #[serde(rename = "banned")]
740 Banned,
741 #[serde(rename = "has-message")]
742 HasMessage,
743 #[serde(rename = "email-not-verified")]
744 EmailNotVerified,
745 #[serde(rename = "guest")]
746 Guest,
747 #[serde(rename = "ready")]
748 Ready,
749 #[serde(rename = "agent-over-limit")]
750 AgentOverLimit,
751 #[serde(rename = "agent-disabled")]
752 AgentDisabled,
753}
754
755#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
756pub struct AgentTunnel {
757 pub id: uuid::Uuid,
758 pub internal_id: u64,
759 pub name: Option<String>,
760 pub ip_num: u64,
761 pub region_num: u16,
762 pub port: PortRange,
763 pub proto: PortType,
764 pub local_ip: std::net::IpAddr,
765 pub local_port: u16,
766 pub tunnel_type: Option<String>,
767 pub assigned_domain: String,
768 pub custom_domain: Option<String>,
769 pub disabled: Option<AgentTunnelDisabled>,
770 pub proxy_protocol: Option<ProxyProtocol>,
771}
772
773#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
774pub struct PortRange {
775 pub from: u16,
776 pub to: u16,
777}
778
779#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
780pub enum AgentTunnelDisabled {
781 ByUser,
782 BySystem,
783}
784
785#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
786pub struct AgentPendingTunnel {
787 pub id: uuid::Uuid,
788 pub name: Option<String>,
789 pub proto: PortType,
790 pub port_count: u16,
791 pub tunnel_type: Option<String>,
792 pub is_disabled: bool,
793 pub region_num: u16,
794}
795
796#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
797pub struct AccountFeatures {
798 pub regional_tunnels: bool,
799}
800
801#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
802pub struct ReqPingSubmit {
803 pub results: Vec<PingExperimentResult>,
804}
805
806#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
807pub struct PingExperimentResult {
808 pub id: u64,
809 pub target: PingTarget,
810 pub samples: Vec<PingSample>,
811}
812
813#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
814pub struct PingTarget {
815 pub ip: std::net::IpAddr,
816 pub port: u16,
817}
818
819#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
820pub struct PingSample {
821 pub tunnel_server_id: u64,
822 pub dc_id: u64,
823 pub server_ts: u64,
824 pub latency: u64,
825 pub count: u16,
826 pub num: u16,
827}
828
829#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
830pub struct ReqPingGet {
831}
832
833#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
834pub struct PingExperiments {
835 pub experiments: Vec<PingExperimentDetails>,
836}
837
838#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
839pub struct PingExperimentDetails {
840 pub id: u64,
841 pub test_interval: u64,
842 pub ping_interval: u64,
843 pub samples: u64,
844 pub targets: std::borrow::Cow<'static,[PingTarget]>,
845}
846
847#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
848pub struct ReqTunnelsList {
849 pub tunnel_id: Option<uuid::Uuid>,
850 pub agent_id: Option<uuid::Uuid>,
851}
852
853#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
854pub struct ReqAgentsList {
855}
856
857#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
858pub struct ReqQueryRegion {
859 pub limit_region: Option<PlayitRegion>,
860}
861
862#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
863pub enum PlayitRegion {
864 GlobalAnycast,
865 NorthAmerica,
866 Europe,
867 Asia,
868 India,
869 SouthAmerica,
870}
871
872#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
873pub struct QueryRegion {
874 pub region: PlayitRegion,
875 pub pop: PlayitPop,
876}
877
878#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
879pub enum PlayitPop {
880 Any,
881 #[serde(rename = "USLosAngeles")]
882 UsLosAngeles,
883 #[serde(rename = "USSeattle")]
884 UsSeattle,
885 #[serde(rename = "USDallas")]
886 UsDallas,
887 #[serde(rename = "USMiami")]
888 UsMiami,
889 #[serde(rename = "USChicago")]
890 UsChicago,
891 #[serde(rename = "USNewJersey")]
892 UsNewJersey,
893 CanadaToronto,
894 Mexico,
895 BrazilSaoPaulo,
896 Spain,
897 London,
898 Germany,
899 Poland,
900 Sweden,
901 IndiaDelhi,
902 IndiaMumbai,
903 IndiaBangalore,
904 Singapore,
905 Tokyo,
906 Sydney,
907 SantiagoChile,
908 Israel,
909 Romania,
910 #[serde(rename = "USNewYork")]
911 UsNewYork,
912 #[serde(rename = "USDenver")]
913 UsDenver,
914}
915
916#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
917pub enum QueryRegionError {
918 FailedToDetermineLocation,
919}
920
921#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
922pub struct ReqTunnelsUpdate {
923 pub tunnel_id: uuid::Uuid,
924 pub local_ip: std::net::IpAddr,
925 pub local_port: Option<u16>,
926 pub agent_id: Option<uuid::Uuid>,
927 pub enabled: bool,
928}
929
930#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
931pub enum UpdateError {
932 ChangingAgentIdNotAllowed,
933 TunnelNotFound,
934}
935
936impl std::fmt::Display for UpdateError {
937 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
938 write!(f, "{:?}", self)
939 }
940}
941
942impl std::error::Error for UpdateError {
943}
944#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
945pub struct ReqTunnelsFirewallAssign {
946 pub tunnel_id: uuid::Uuid,
947 pub firewall_id: Option<uuid::Uuid>,
948}
949
950#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
951pub enum TunnelsFirewallAssignError {
952 TunnelNotFound,
953 InvalidFirewallId,
954}
955
956impl std::fmt::Display for TunnelsFirewallAssignError {
957 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
958 write!(f, "{:?}", self)
959 }
960}
961
962impl std::error::Error for TunnelsFirewallAssignError {
963}
964#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
965pub struct ReqTunnelsProxySet {
966 pub tunnel_id: uuid::Uuid,
967 pub proxy_protocol: Option<ProxyProtocol>,
968}
969
970#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, Copy, Clone, Hash)]
971pub enum TunnelProxySetError {
972 TunnelNotFound,
973}
974