treewide: Move things around

More binaries inbound

Signed-off-by: Konrad Dybcio <konradybcio@kernel.org>
This commit is contained in:
Konrad Dybcio
2024-05-22 00:20:35 +02:00
parent 43a5d276d6
commit 63e86f5b57
7 changed files with 126 additions and 39 deletions

15
Cargo.lock generated
View File

@@ -520,6 +520,21 @@ dependencies = [
[[package]]
name = "sk8brd"
version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"colored",
"crossterm",
"os_pipe",
"serde",
"sk8brd-proto",
"ssh2",
"tokio",
]
[[package]]
name = "sk8brd-proto"
version = "0.1.0"
dependencies = [
"anyhow",
"clap",

View File

@@ -1,32 +1,3 @@
[package]
name = "sk8brd"
version = "0.1.0"
edition = "2021"
authors = ["Konrad Dybcio <konradybcio@kernel.org>"]
license = "BSD-3-Clause"
description = "Simple remote devboard control software"
readme = "README.md"
repository = "https://github.com/linux-msm/sk8brd"
categories = ["command-line-utilities"]
publish = false # TODO
[badges]
maintenance = { status = "actively-developed" }
[[bin]]
name = "sk8brd"
path = "src/main.rs"
[lib]
name = "sk8brd"
path = "src/lib.rs"
[dependencies]
anyhow = "1.0"
clap = { version = "4.5.4", features = ["derive"] }
colored = "2.1.0"
crossterm = "0.27.0"
os_pipe = "1.1.5"
serde = { version = "^1.0.198", features = ["derive"] }
ssh2 = "^0.9.4"
tokio = { version = "^1.37.0", features = ["full"] }
[workspace]
members = ["client", "proto"]
resolver = "2"

29
client/Cargo.toml Normal file
View File

@@ -0,0 +1,29 @@
[package]
name = "sk8brd"
version = "0.1.0"
edition = "2021"
authors = ["Konrad Dybcio <konradybcio@kernel.org>"]
license = "BSD-3-Clause"
description = "Simple remote devboard control software"
readme = "README.md"
repository = "https://github.com/linux-msm/sk8brd"
categories = ["command-line-utilities"]
publish = false # TODO
[badges]
maintenance = { status = "actively-developed" }
[[bin]]
name = "sk8brd"
path = "src/main.rs"
[dependencies]
anyhow = "1.0"
clap = { version = "4.5.4", features = ["derive"] }
colored = "2.1.0"
crossterm = "0.27.0"
sk8brd-proto = { path = "../proto", features = ["ssh"] }
os_pipe = "1.1.5"
serde = { version = "^1.0.198", features = ["derive"] }
ssh2 = "^0.9.4"
tokio = { version = "^1.37.0", features = ["full"] }

View File

@@ -1,17 +1,15 @@
use clap::Parser;
use colored::Colorize;
use sk8brd::ssh::{ssh_connect, ssh_disconnect, ssh_get_chan};
use sk8brd::{
console_print, parse_recv_msg, print_string_msg, select_brd, send_ack, send_break,
send_console, send_image, send_msg, todo, Sk8brdMsgs, MSG_HDR_SIZE,
send_console, send_image, send_msg, todo, Sk8brdMsgs, CDBA_SERVER_BIN_NAME, MSG_HDR_SIZE,
};
use ssh::{ssh_connect, ssh_disconnect, ssh_get_chan};
use std::fs;
use std::io::{stdout, Read, Write};
use std::sync::Arc;
use tokio::sync::Mutex;
mod ssh;
const SSH_BUFFER_SIZE: usize = 2048;
macro_rules! get_arc {
@@ -90,8 +88,8 @@ async fn main() -> anyhow::Result<()> {
println!("sk8brd {}", env!("CARGO_PKG_VERSION"));
let mut sess = ssh_connect(args.farm, args.port).await?;
let mut chan = ssh_get_chan(&mut sess).await?;
let mut sess = ssh_connect(args.farm, args.port, args.user).await?;
let mut chan = ssh_get_chan(&mut sess, CDBA_SERVER_BIN_NAME).await?;
sess.set_blocking(false);
send_ack(&mut chan, Sk8brdMsgs::MsgListDevices).await?;

31
proto/Cargo.toml Normal file
View File

@@ -0,0 +1,31 @@
[package]
name = "sk8brd-proto"
version = "0.1.0"
edition = "2021"
authors = ["Konrad Dybcio <konradybcio@kernel.org>"]
license = "BSD-3-Clause"
description = "Simple remote devboard control software"
readme = "README.md"
repository = "https://github.com/linux-msm/sk8brd"
categories = ["command-line-utilities"]
publish = false # TODO
[badges]
maintenance = { status = "actively-developed" }
[lib]
name = "sk8brd"
path = "src/lib.rs"
[features]
ssh = []
[dependencies]
anyhow = "1.0"
clap = { version = "4.5.4", features = ["derive"] }
colored = "2.1.0"
crossterm = "0.27.0"
os_pipe = "1.1.5"
serde = { version = "^1.0.198", features = ["derive"] }
ssh2 = "^0.9.4"
tokio = { version = "^1.37.0", features = ["full"] }

View File

@@ -5,8 +5,10 @@ use std::mem::size_of;
use std::sync::Arc;
use tokio::sync::Mutex;
#[cfg(feature = "ssh")]
pub mod ssh;
pub const CDBA_SERVER_BIN_NAME: &str = "cdba-server";
pub const USERNAME: &str = "cdba";
#[repr(u8)]
#[derive(Debug, PartialEq)]

41
proto/src/ssh.rs Normal file
View File

@@ -0,0 +1,41 @@
use anyhow::Context as _;
use ssh2::{Channel, Session};
use std::net::TcpStream;
use std::sync::Arc;
use tokio::sync::Mutex;
pub async fn ssh_connect(farm: String, port: String, username: String) -> anyhow::Result<Session> {
// Connect to the local SSH server
let tcp = TcpStream::connect(format!("{}:{}", farm, port))
.with_context(|| format!("Couldn't connect to {}:{}", farm, port))?;
let mut sess = Session::new()?;
sess.set_tcp_stream(tcp);
sess.handshake()?;
// Try to authenticate with the first identity in the agent.
sess.userauth_agent(&username)
.with_context(|| format!("Couldn't authenticate as {username}"))?;
Ok(sess)
}
pub async fn ssh_get_chan(
sess: &mut Session,
server_bin_name: &str,
) -> anyhow::Result<Arc<Mutex<Channel>>> {
let chan = Arc::new(Mutex::new(sess.channel_session()?));
(*chan.lock().await)
.exec(server_bin_name)
.with_context(|| format!("Couldn't execute {server_bin_name} on remote host"))?;
Ok(chan)
}
pub async fn ssh_disconnect(sess: &mut Session) -> anyhow::Result<()> {
sess.disconnect(
Option::Some(ssh2::DisconnectCode::ConnectionLost),
"bye",
Option::Some("C"),
)
.context("Couldn't disconnect cleanly")
}