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