geph5_misc_rpc/
client_control.rs

1use std::time::SystemTime;
2
3use async_trait::async_trait;
4use geph5_broker_protocol::{
5    AccountLevel, BwConsumptionInfo, ExitDescriptor, NetStatus, VoucherInfo,
6};
7use nanorpc::nanorpc_derive;
8use serde::{Deserialize, Serialize};
9
10#[derive(Serialize, Deserialize, Clone, Debug)]
11#[serde(tag = "state")]
12pub enum ConnInfo {
13    Disconnected,
14    Connecting,
15    Connected(ConnectedInfo),
16}
17
18#[derive(Serialize, Deserialize, Clone, Debug)]
19pub struct ConnectedInfo {
20    pub protocol: String,
21    pub bridge: String,
22
23    pub exit: ExitDescriptor,
24}
25
26#[derive(Serialize, Deserialize, Clone, Debug)]
27pub struct ControlUserInfo {
28    pub user_id: u64,
29    pub level: AccountLevel,
30
31    pub recurring: bool,
32    pub expiry: Option<u64>,
33
34    pub bw_consumption: Option<BwConsumptionInfo>,
35}
36
37#[nanorpc_derive]
38#[async_trait]
39pub trait ControlProtocol {
40    async fn conn_info(&self) -> ConnInfo;
41    async fn stat_num(&self, stat: String) -> f64;
42    async fn start_time(&self) -> SystemTime;
43    async fn stop(&self);
44
45    async fn recent_logs(&self) -> Vec<String>;
46
47    // broker-proxying stuff
48
49    async fn check_secret(&self, secret: String) -> Result<bool, String>;
50    async fn user_info(&self, secret: String) -> Result<ControlUserInfo, String>;
51    async fn start_registration(&self) -> Result<usize, String>;
52    async fn delete_account(&self, secret: String) -> Result<(), String>;
53    async fn poll_registration(&self, idx: usize) -> Result<RegistrationProgress, String>;
54    async fn convert_legacy_account(
55        &self,
56        username: String,
57        password: String,
58    ) -> Result<String, String>;
59    async fn stat_history(&self, stat: String) -> Result<Vec<f64>, String>;
60
61    async fn net_status(&self) -> Result<NetStatus, String>;
62    async fn latest_news(&self, lang: String) -> Result<Vec<NewsItem>, String>;
63    async fn price_points(&self) -> Result<Vec<(u32, f64)>, String>;
64    async fn basic_price_points(&self) -> Result<Vec<(u32, f64)>, String>;
65    async fn payment_methods(&self) -> Result<Vec<String>, String>;
66    async fn create_payment(
67        &self,
68        secret: String,
69        days: u32,
70        method: String,
71    ) -> Result<String, String>;
72    async fn create_basic_payment(
73        &self,
74        secret: String,
75        days: u32,
76        method: String,
77    ) -> Result<String, String>;
78    async fn get_free_voucher(&self, secret: String) -> Result<Option<VoucherInfo>, String>;
79    async fn redeem_voucher(&self, secret: String, code: String) -> Result<i32, String>;
80    async fn export_debug_pack(
81        &self,
82        email: Option<String>,
83        contents: String,
84    ) -> Result<(), String>;
85
86    async fn get_update_manifest(&self) -> Result<(serde_json::Value, String), String>;
87}
88
89#[derive(Serialize, Deserialize, Clone)]
90pub struct RegistrationProgress {
91    pub progress: f64,
92    pub secret: Option<String>,
93}
94
95#[derive(Serialize, Deserialize, Clone, Debug)]
96pub struct NewsItem {
97    pub title: String,
98    pub date_unix: u64,
99    pub contents: String,
100    pub important: bool,
101}