chiark / gitweb /
messages
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 3 Aug 2021 17:43:30 +0000 (18:43 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 3 Aug 2021 17:43:30 +0000 (18:43 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bin/client.rs
src/prelude.rs
src/reporter.rs

index e437f51164c8c797f9f35e846375a744d1a023c3..656b4b9164d64112ee158e3aa20e78bcf781714e 100644 (file)
@@ -22,6 +22,7 @@ struct ClientContext<'c,C> {
 #[throws(AE)]
 fn submit_request<'r, 'c:'r, C:HCC>(
   c: &'c ClientContext<C>,
+  req_num: &mut ReqNum,
   reqs: &mut Vec<OutstandingRequest<'r>>,
   upbound: FramesData,
 ) {
@@ -39,6 +40,8 @@ fn submit_request<'r, 'c:'r, C:HCC>(
   write!(token, " ").unwrap();
   base64::encode_config_buf(&hmac, BASE64_CONFIG, &mut token);
 
+  let req_num = { *req_num += 1; *req_num };
+
   let prefix1 = format!(into_crlfs!(
     r#"--b
        Content-Type: text/plain; charset="utf-8"
@@ -94,6 +97,9 @@ fn submit_request<'r, 'c:'r, C:HCC>(
     as_ref,
   ).map(|b| b.len()).sum();
 
+  trace!("{} #{}: frames={} bytes={}",
+         &c.ic, req_num, upbound.len(), body_len);
+
   let body = hyper::body::Body::wrap_stream(
     futures::stream::iter(
       content!(
@@ -129,7 +135,7 @@ fn submit_request<'r, 'c:'r, C:HCC>(
       Ok::<_,AE>(resp)
     }).await? }.await;
 
-    let r = c.reporter.lock().report(r);
+    let r = c.reporter.lock().report(req_num, r);
 
     if r.is_none() {
       tokio::time::sleep(c.ic.http_retry).await;
@@ -175,6 +181,8 @@ async fn run_client<C:HCC>(
     Ok::<_,io::Error>(())
   });
 
+  let mut req_num: ReqNum = 0;
+
   let tx_stream = ipif.stdout.take().unwrap();
   let rx_stream = ipif.stdin .take().unwrap();
 
@@ -213,8 +221,8 @@ async fn run_client<C:HCC>(
               Ok(())
             }, |e| match e {
               PE::Empty => { },
-              e@ PE::Src(_) => debug!("{}: tx: discarding: {}", &ic, e),
-              e => error!("{}: tx: discarding: {}", &ic, e),
+              e@ PE::Src(_) => debug!("{}: tx discarding: {}", &ic, e),
+              e => error!("{}: tx discarding: {}", &ic, e),
             });
         },
 
@@ -237,7 +245,8 @@ async fn run_client<C:HCC>(
           // xxx backpressure, if too much in rx_queue
           =>
         {
-          submit_request(&c, &mut reqs, mem::take(&mut upbound).into())?;
+          submit_request(&c, &mut req_num, &mut reqs,
+                         mem::take(&mut upbound).into())?;
         },
 
         (got, goti, _) = async { future::select_all(&mut reqs).await },
@@ -252,7 +261,7 @@ async fn run_client<C:HCC>(
                 let addr = ip_packet_addr::<true>(header)?;
                 if addr != ic.link.client.0 { throw!(PE::Dst(addr)) }
                 Ok(())
-              }, |e| error!("{}: rx: discarding: {}", &ic, e));
+              }, |e| error!("{} #{}: rx discarding: {}", &ic, req_num, e));
           
             dbg!(&rx_queue.len());
             rx_queue = default(); // xxx
index e95aa9c7cf17f2e47461151b0401ae157217aada..7d2b4b8896d16ba678bb0323d7e274bf2dab36e9 100644 (file)
@@ -33,7 +33,7 @@ pub use hyper_tls::HttpsConnector;
 pub use ipnet::IpNet;
 pub use itertools::{iproduct, Itertools};
 pub use lazy_regex::{regex_is_match, regex_replace_all};
-pub use log::{debug, info, error};
+pub use log::{trace, debug, info, warn, error};
 pub use structopt::StructOpt;
 pub use thiserror::Error;
 pub use tokio::io::AsyncBufReadExt;
@@ -49,6 +49,8 @@ pub use crate::reporter::*;
 pub use crate::types::*;
 pub use crate::slip::*;
 
+pub type ReqNum = u64;
+
 pub use anyhow::Error as AE;
 pub use ErrorKind as EK;
 pub use PacketError as PE;
@@ -57,7 +59,7 @@ pub const SLIP_END:     u8 = 0o300; // c0
 pub const SLIP_ESC:     u8 = 0o333; // db
 pub const SLIP_ESC_END: u8 = 0o334; // dc
 pub const SLIP_ESC_ESC: u8 = 0o335; // dd
-pub const SLIP_MIME_ESC: u8 = b'-';
+pub const SLIP_MIME_ESC: u8 = b'-'; // 2d
 
 pub use base64::STANDARD as BASE64_CONFIG;
 
index af4a9249df1ea4ff7585c3aa9c2761f6d0f75bf6..55e645e1ac18368bd114e6cd791086f3ff62c109 100644 (file)
@@ -13,7 +13,7 @@ impl<'r> Reporter<'r> {
     ic
   } }
   
-  pub fn report<T>(&mut self, r: Result<T,AE>) -> Option<T> {
+  pub fn report<T>(&mut self, req_num: ReqNum, r: Result<T,AE>) -> Option<T> {
     match r {
       Ok(t) => {
         // xxx something something success
@@ -21,7 +21,7 @@ impl<'r> Reporter<'r> {
       },
       Err(e) => {
         // xxx something something error
-        error!("ERROR {} {:?}", self.ic, e);
+        warn!("{} #{}: {:?}", self.ic, req_num, e);
         None
       },
     }