Просмотр исходного кода

map, ircd: dummy get_info() request

lunar-mining 4 лет назад
Родитель
Сommit
779067a776
2 измененных файлов с 16 добавлено и 1 удалено
  1. 7 0
      bin/ircd/src/main.rs
  2. 9 1
      bin/map/src/main.rs

+ 7 - 0
bin/ircd/src/main.rs

@@ -207,6 +207,7 @@ impl RequestHandler for JsonRpcInterface {
 
         match req.method.as_str() {
             Some("say_hello") => return self.say_hello(req.id, req.params).await,
+            Some("get_info") => return self.get_info(req.id, req.params).await,
             Some(_) | None => return JsonResult::Err(jsonerr(MethodNotFound, None, req.id)),
         }
     }
@@ -218,6 +219,12 @@ impl JsonRpcInterface {
     async fn say_hello(&self, id: Value, _params: Value) -> JsonResult {
         JsonResult::Resp(jsonresp(json!("hello world"), id))
     }
+
+    //--> {"jsonrpc": "2.0", "method": "poll", "params": [], "id": 42}
+    // <-- {"jsonrpc": "2.0", "result": {"nodeID": [], "nodeinfo" [], "id": 42}
+    async fn get_info(&self, id: Value, _params: Value) -> JsonResult {
+        JsonResult::Resp(jsonresp(json!("get_info"), id))
+    }
 }
 
 fn main() -> Result<()> {

+ 9 - 1
bin/map/src/main.rs

@@ -57,11 +57,19 @@ impl Map {
         let req = jsonrpc::request(json!("say_hello"), json!([]));
         Ok(self.request(req).await?)
     }
+
+    //--> {"jsonrpc": "2.0", "method": "poll", "params": [], "id": 42}
+    // <-- {"jsonrpc": "2.0", "result": {"nodeID": [], "nodeinfo" [], "id": 42}
+    async fn get_info(&self) -> Result<Value> {
+        let req = jsonrpc::request(json!("get_info"), json!([]));
+        Ok(self.request(req).await?)
+    }
 }
 
 async fn start() -> Result<()> {
     let client = Map::new("tcp://127.0.0.1:8000".to_string());
-    let reply = client.say_hello().await?;
+    // call this every 1 second (poll)
+    let reply = client.get_info().await?;
     println!("Server replied: {}", &reply.to_string());
     Ok(())
 }