Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Rustfmt
run: cargo fmt --check
- name: Build
run: cargo test --no-run --features tuntest
- name: Run tests as sudo
Expand Down
15 changes: 7 additions & 8 deletions src/bin/gentoken.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use pasque::jwt::Jwt;
use std::fs;
use std::process;


fn main() {
let args = Args::parse();

Expand All @@ -16,13 +15,14 @@ fn main() {
}
};

let permissions: Vec<String> = args
.permissions
.split(',')
.map(str::to_string)
.collect();
let permissions: Vec<String> = args.permissions.split(',').map(str::to_string).collect();

match Jwt::create_token(args.sub, Duration::minutes(args.lifetime), permissions, &secret) {
match Jwt::create_token(
args.sub,
Duration::minutes(args.lifetime),
permissions,
&secret,
) {
Ok(token) => println!("{}", token),
Err(e) => {
eprintln!("Failed to create token: {}", e);
Expand All @@ -31,7 +31,6 @@ fn main() {
}
}


#[derive(Parser, Debug)]
#[command(about = "Generate a JWT token", long_about = None)]
struct Args {
Expand Down
29 changes: 10 additions & 19 deletions src/bin/psq-client.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@

#[macro_use]
extern crate log;

use clap::Parser;

use pasque::{
PsqClient,
IpTunnel,
UdpTunnel,
};
use pasque::{IpTunnel, PsqClient, UdpTunnel};

#[tokio::main]
async fn main() {
Expand All @@ -18,10 +13,9 @@ async fn main() {

// Create an HTTP/3 connection to URL given on
// command line `-d` or `--dest` argument.
let mut psqconn = PsqClient::connect(
args.dest(),
args.ignore_cert(),
).await.unwrap();
let mut psqconn = PsqClient::connect(args.dest(), args.ignore_cert())
.await
.unwrap();

if let Some(token) = args.token() {
psqconn.set_token(token.clone());
Expand All @@ -30,13 +24,10 @@ async fn main() {
// Triggers a CONNECT request to "ip" endpoint at the server.
// The call blocks until server has replied and tunnel is established.
if args.ip() {
match IpTunnel::connect(&mut psqconn,
"ip",
"tun-c",
).await {
match IpTunnel::connect(&mut psqconn, "ip", "tun-c").await {
Ok(_iptunnel) => {
info!("IpTunnel set up");
},
}
Err(e) => {
error!("Error connecting IpTunnel: {}", e);
return;
Expand All @@ -53,7 +44,9 @@ async fn main() {
"127.0.0.1",
9000,
"127.0.0.1:0".parse().unwrap(),
).await.unwrap();
)
.await
.unwrap();

println!(
"UDP datagrams to {} are forwarded to HTTP tunnel.",
Expand All @@ -67,7 +60,6 @@ async fn main() {
}
}


#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct Args {
Expand All @@ -92,7 +84,6 @@ pub struct Args {
token: Option<String>,
}


impl Args {
pub fn new() -> Args {
let args = Args::parse();
Expand All @@ -105,7 +96,7 @@ impl Args {
}

pub fn dest(&self) -> &String {
&self.dest
&self.dest
}

pub fn ignore_cert(&self) -> bool {
Expand Down
15 changes: 3 additions & 12 deletions src/bin/psq-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ extern crate log;
use clap::Parser;
use std::net::SocketAddr;

use pasque::{
PsqServer,
server::Config,
};

use pasque::{server::Config, PsqServer};

#[tokio::main]
async fn main() {
Expand All @@ -27,10 +23,7 @@ async fn main() {
}
};

let mut psqserver = PsqServer::start(
&args.address(),
&config,
).await.unwrap();
let mut psqserver = PsqServer::start(&args.address(), &config).await.unwrap();

loop {
if let Err(e) = psqserver.process().await {
Expand All @@ -39,7 +32,6 @@ async fn main() {
}
}


#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
pub struct Args {
Expand All @@ -52,7 +44,6 @@ pub struct Args {
config: String,
}


impl Args {
pub fn new() -> Args {
let args = Args::parse();
Expand All @@ -67,4 +58,4 @@ impl Args {
pub fn config(&self) -> &String {
&self.config
}
}
}
Loading
Loading