Skip to content

Commit

Permalink
Add bdt-tool to make ping and nc easier to use
Browse files Browse the repository at this point in the history
  • Loading branch information
jing-git committed Apr 27, 2023
1 parent 968d01b commit 1b7b35b
Show file tree
Hide file tree
Showing 8 changed files with 403 additions and 18 deletions.
14 changes: 14 additions & 0 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ members = [
"./tools/cyfs-check",
"./tools/sn-updater",
"./tools/cyfs-backup-tool",
"./tools/bdt-tool",

"./meta/browser-meta-spv",
"./meta/cyfs-meta",
Expand Down
17 changes: 3 additions & 14 deletions src/component/cyfs-bdt/src/debug/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,9 @@ use cyfs_base::*;
use crate::stack::Stack;

pub fn debug_command_line() -> clap::App<'static, 'static> {
App::new("bdt-debug")
.about("bdt stack debug")
.arg(Arg::with_name("host")
.short("h")
.long("host")
.value_name("host")
.help("connect remote host")
.default_value("127.0.0.1"))
.arg(Arg::with_name("port")
.short("p")
.long("port")
.value_name("port")
.help("local server port")
.default_value("12345"))
App::new("bdt-debug").about("bdt stack debug")
.arg(Arg::with_name("host").short("h").long("host").value_name("host").help("connect remote host").default_value("127.0.0.1"))
.arg(Arg::with_name("port").short("p").long("port").value_name("port").help("local server port").default_value("12345"))
.subcommand(SubCommand::with_name("test"))
.subcommand(SubCommand::with_name("ping")
.arg(Arg::with_name("remote").required(true))
Expand Down
2 changes: 1 addition & 1 deletion src/component/cyfs-bdt/src/debug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ mod ping;

pub use command::{debug_command_line, DebugCommand};
pub use stub::{DebugStub, Config};
pub use ping::PingStub;
pub use ping::{PingStub, Pinger};
11 changes: 9 additions & 2 deletions src/component/cyfs-bdt/src/debug/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use async_std::{
future,
};
use std::time::Duration;
use std::io::ErrorKind;

struct PingStubImpl {
stack: WeakStack,
Expand Down Expand Up @@ -94,12 +95,18 @@ impl Pinger {
let ts = cyfs_base::bucky_time_now();
options.sequence = Some(TempSeq::from(ts as u32));

if let Err(err) = self.0.datagram_tunnel.send_to(
if let Err(err) = self.0.datagram_tunnel.send_to(
buf,
&mut options,
&remote.desc().device_id(),
datagram::ReservedVPort::Debug.into()) {
return Err(BuckyError::new(BuckyErrorCode::CodeError, format!("ping remote={:?} send err={:?}", remote, err)))
match err.kind() {
ErrorKind::NotConnected => {
},
_ => {
return Err(BuckyError::new(BuckyErrorCode::CodeError, format!("ping remote={:?} send err={:?}", remote, err)));
}
}
}

match future::timeout(timeout, self.0.datagram_tunnel.recv_v()).await {
Expand Down
2 changes: 1 addition & 1 deletion src/component/cyfs-bdt/src/debug/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{
net::{IpAddr, Ipv4Addr, SocketAddr, Shutdown},
path::Path,
str::FromStr,
time::{Duration, Instant}
time::{Duration, Instant},
};
use async_std::{
sync::Arc,
Expand Down
18 changes: 18 additions & 0 deletions src/tools/bdt-tool/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "bdt-tool"
version = "0.1.0"
edition = "2021"
license = "BSD-2-Clause"
description = "Rust bdt-tool package"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cyfs-debug = { path = "../../component/cyfs-debug" }
cyfs-base = { path = "../../component/cyfs-base" }
cyfs-bdt = { path = "../../component/cyfs-bdt" }
cyfs-util = { path = '../../component/cyfs-util', version = '0.6' }
async-std = { version = "1.11", features = ["unstable", "attributes"] }
clap = "2.34.0"
log = "0.4"
md5 = "0.7.0"
Loading

0 comments on commit 1b7b35b

Please sign in to comment.