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

map + ircd: implemented ping/ pong method

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

+ 4 - 4
bin/ircd/src/main.rs

@@ -204,7 +204,7 @@ impl RequestHandler for JsonRpcInterface {
         debug!(target: "RPC", "--> {}", serde_json::to_string(&req).unwrap());
 
         match req.method.as_str() {
-            //Some("ping") => return self.pong(req.id, req.params).await,
+            Some("ping") => return self.pong(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)),
         }
@@ -214,9 +214,9 @@ impl RequestHandler for JsonRpcInterface {
 impl JsonRpcInterface {
     // --> {"jsonrpc": "2.0", "method": "ping", "params": [], "id": 42}
     // <-- {"jsonrpc": "2.0", "result": "pong", "id": 42}
-    //async fn pong(&self, id: Value, _params: Value) -> JsonResult {
-    //    JsonResult::Resp(jsonresp(json!("pong"), id))
-    //}
+    async fn pong(&self, id: Value, _params: Value) -> JsonResult {
+        JsonResult::Resp(jsonresp(json!("pong"), id))
+    }
 
     //--> {"jsonrpc": "2.0", "method": "poll", "params": [], "id": 42}
     // <-- {"jsonrpc": "2.0", "result": {"nodeID": [], "nodeinfo" [], "id": 42}

+ 7 - 5
bin/map/src/main.rs

@@ -70,10 +70,10 @@ impl Map {
         }
     }
 
-    // --> {"jsonrpc": "2.0", "method": "say_hello", "params": [], "id": 42}
-    // <-- {"jsonrpc": "2.0", "result": "hello world", "id": 42}
-    async fn _say_hello(&self) -> Result<Value> {
-        let req = jsonrpc::request(json!("say_hello"), json!([]));
+    // --> {"jsonrpc": "2.0", "method": "ping", "params": [], "id": 42}
+    // <-- {"jsonrpc": "2.0", "result": "pong", "id": 42}
+    async fn ping(&self) -> Result<Value> {
+        let req = jsonrpc::request(json!("ping"), json!([]));
         Ok(self.request(req).await?)
     }
 
@@ -152,6 +152,8 @@ async fn poll(client: Map, model: Arc<Model>) -> Result<()> {
     debug!("Attemping to poll: {}", client.url);
     let mut index = 0;
     loop {
+        let reply = client.ping().await?;
+
         let reply = client.get_info().await?;
 
         if reply.as_object().is_some() && !reply.as_object().unwrap().is_empty() {
@@ -248,7 +250,7 @@ async fn render<B: Backend>(terminal: &mut Terminal<B>, model: Arc<Model>) -> io
             match k.unwrap() {
                 Key::Char('q') => {
                     terminal.clear()?;
-                    return Ok(())
+                    return Ok(());
                 }
                 Key::Char('j') => {
                     view.id_list.next();

+ 1 - 0
bin/map/src/ui.rs

@@ -26,6 +26,7 @@ pub fn ui<B: Backend>(f: &mut Frame<'_, B>, mut view: View) {
         .map(|id| {
             let mut lines = vec![Spans::from(id.to_string())];
             // TODO: handle the None case
+            // TODO: fix formatting (indentation must be margins)
             let connects = info.get(id).unwrap();
             for line in lines.clone() {
                 lines.push(Spans::from(Span::styled("  Outgoing:", Style::default())));