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 ab_test(&self, key: String, secret: String) -> Result<bool, String>;
41    async fn conn_info(&self) -> ConnInfo;
42    async fn stat_num(&self, stat: String) -> f64;
43    async fn start_time(&self) -> SystemTime;
44    async fn stop(&self);
45
46    async fn recent_logs(&self) -> Vec<String>;
47
48    // broker-proxying stuff
49
50    async fn check_secret(&self, secret: String) -> Result<bool, String>;
51    async fn user_info(&self, secret: String) -> Result<ControlUserInfo, String>;
52    async fn start_registration(&self) -> Result<usize, String>;
53    async fn delete_account(&self, secret: String) -> Result<(), String>;
54    async fn poll_registration(&self, idx: usize) -> Result<RegistrationProgress, String>;
55    async fn convert_legacy_account(
56        &self,
57        username: String,
58        password: String,
59    ) -> Result<String, String>;
60    async fn stat_history(&self, stat: String) -> Result<Vec<f64>, String>;
61
62    async fn net_status(&self) -> Result<NetStatus, String>;
63    async fn latest_news(&self, lang: String) -> Result<Vec<NewsItem>, String>;
64    async fn price_points(&self) -> Result<Vec<(u32, f64)>, String>;
65    async fn basic_price_points(&self) -> Result<Vec<(u32, f64)>, String>;
66    async fn basic_mb_limit(&self) -> Result<u32, String>;
67    async fn payment_methods(&self) -> Result<Vec<String>, String>;
68    async fn create_payment(
69        &self,
70        secret: String,
71        days: u32,
72        method: String,
73    ) -> Result<String, String>;
74    async fn create_basic_payment(
75        &self,
76        secret: String,
77        days: u32,
78        method: String,
79    ) -> Result<String, String>;
80    async fn get_free_voucher(&self, secret: String) -> Result<Option<VoucherInfo>, String>;
81    async fn redeem_voucher(&self, secret: String, code: String) -> Result<i32, String>;
82    async fn export_debug_pack(
83        &self,
84        email: Option<String>,
85        contents: String,
86    ) -> Result<(), String>;
87
88    async fn get_update_manifest(&self) -> Result<(serde_json::Value, String), String>;
89}
90
91#[derive(Serialize, Deserialize, Clone)]
92pub struct RegistrationProgress {
93    pub progress: f64,
94    pub secret: Option<String>,
95}
96
97#[derive(Serialize, Deserialize, Clone, Debug)]
98pub struct NewsItem {
99    pub title: String,
100    pub date_unix: u64,
101    pub contents: String,
102    pub important: bool,
103}