Small improvements

This commit is contained in:
Dennis Schwerdel 2021-02-04 23:38:08 +01:00
parent 791ecfb0fe
commit 65eef143cd
5 changed files with 20 additions and 11 deletions

View File

@ -8,7 +8,7 @@ from datetime import date
# Note: this script will run for ~8 minutes and incur costs of about $ 0.02 # Note: this script will run for ~8 minutes and incur costs of about $ 0.02
FILE = "../target/release/vpncloud" FILE = "../target/release/vpncloud"
VERSION = "2.0.0-alpha1" VERSION = "2.0.1"
REGION = "eu-central-1" REGION = "eu-central-1"
env = EC2Environment( env = EC2Environment(

View File

@ -5,7 +5,7 @@ import atexit, argparse, os
REGION = "eu-central-1" REGION = "eu-central-1"
VERSION = "2.0.0" VERSION = "2.0.1"
parser = argparse.ArgumentParser(description='Create a test setup') parser = argparse.ArgumentParser(description='Create a test setup')
@ -25,15 +25,22 @@ if args.keyname:
with open(args.keyfile, 'r') as fp: with open(args.keyfile, 'r') as fp:
privatekey = fp.read() privatekey = fp.read()
opts = {}
if os.path.exists(args.version):
opts["vpncloud_file"] = args.version
opts["vpncloud_version"] = None
else:
opts["vpncloud_version"] = args.version
setup = EC2Environment( setup = EC2Environment(
region = REGION, region = REGION,
node_count = args.count, node_count = args.count,
instance_type = args.instancetype, instance_type = args.instancetype,
vpncloud_version = args.version,
cluster_nodes = args.cluster, cluster_nodes = args.cluster,
subnet = args.subnet or CREATE, subnet = args.subnet or CREATE,
keyname = args.keyname or CREATE, keyname = args.keyname or CREATE,
privatekey = privatekey privatekey = privatekey,
**opts
) )
if not args.keyname: if not args.keyname:

View File

@ -358,7 +358,7 @@ pub struct Args {
pub mode: Option<Mode>, pub mode: Option<Mode>,
/// The shared password to encrypt all traffic /// The shared password to encrypt all traffic
#[structopt(short, long, required_unless_one = &["private-key", "config", "genkey", "version", "completion"], env)] #[structopt(short, long, env)]
pub password: Option<String>, pub password: Option<String>,
/// The private key to use /// The private key to use

View File

@ -10,7 +10,6 @@ use std::{
collections::{HashMap, VecDeque}, collections::{HashMap, VecDeque},
io::Write, io::Write,
net::SocketAddr, net::SocketAddr,
str::FromStr,
sync::{ sync::{
atomic::{AtomicUsize, Ordering}, atomic::{AtomicUsize, Ordering},
Once Once
@ -91,12 +90,12 @@ impl<P: Protocol> Simulator<P> {
let mut config = config.clone(); let mut config = config.clone();
MockSocket::set_nat(nat); MockSocket::set_nat(nat);
config.listen = format!("[::]:{}", self.next_port); config.listen = format!("[::]:{}", self.next_port);
let addr = config.listen.parse::<SocketAddr>().unwrap();
if config.crypto.password.is_none() && config.crypto.private_key.is_none() { if config.crypto.password.is_none() && config.crypto.private_key.is_none() {
config.crypto.password = Some("test123".to_string()) config.crypto.password = Some("test123".to_string())
} }
DebugLogger::set_node(self.next_port as usize); DebugLogger::set_node(self.next_port as usize);
self.next_port += 1; self.next_port += 1;
let addr = SocketAddr::from_str(&config.listen).unwrap();
let node = TestNode::new(&config, MockSocket::new(addr), MockDevice::new(), None, None); let node = TestNode::new(&config, MockSocket::new(addr), MockDevice::new(), None, None);
DebugLogger::set_node(0); DebugLogger::set_node(0);
self.nodes.insert(addr, node); self.nodes.insert(addr, node);

View File

@ -1,5 +1,5 @@
use super::{ use super::{
net::{mapped_addr, get_ip, parse_listen, Socket}, net::{get_ip, mapped_addr, parse_listen, Socket},
poll::{WaitImpl, WaitResult}, poll::{WaitImpl, WaitResult},
port_forwarding::PortForwarding, port_forwarding::PortForwarding,
util::MsgBuffer util::MsgBuffer
@ -47,6 +47,7 @@ fn read_addr<R: Read>(mut r: R) -> Result<SocketAddr, io::Error> {
fn serve_proxy_connection(stream: TcpStream) -> Result<(), io::Error> { fn serve_proxy_connection(stream: TcpStream) -> Result<(), io::Error> {
let peer = stream.peer_addr()?; let peer = stream.peer_addr()?;
info!("WS client {} connected", peer); info!("WS client {} connected", peer);
stream.set_nodelay(true)?;
let mut websocket = io_error!(accept(stream), "Failed to initialize websocket with {}: {}", peer)?; let mut websocket = io_error!(accept(stream), "Failed to initialize websocket with {}: {}", peer)?;
let udpsocket = UdpSocket::bind("[::]:0")?; let udpsocket = UdpSocket::bind("[::]:0")?;
let mut msg = Vec::with_capacity(18); let mut msg = Vec::with_capacity(18);
@ -56,7 +57,7 @@ fn serve_proxy_connection(stream: TcpStream) -> Result<(), io::Error> {
write_addr(addr, &mut msg)?; write_addr(addr, &mut msg)?;
io_error!(websocket.write_message(Message::Binary(msg)), "Failed to write to ws connection: {}")?; io_error!(websocket.write_message(Message::Binary(msg)), "Failed to write to ws connection: {}")?;
let websocketfd = websocket.get_ref().as_raw_fd(); let websocketfd = websocket.get_ref().as_raw_fd();
let poll = WaitImpl::new(websocketfd, udpsocket.as_raw_fd(), 60*1000)?; let poll = WaitImpl::new(websocketfd, udpsocket.as_raw_fd(), 60 * 1000)?;
let mut buffer = [0; 65535]; let mut buffer = [0; 65535];
for evt in poll { for evt in poll {
match evt { match evt {
@ -90,6 +91,7 @@ fn serve_proxy_connection(stream: TcpStream) -> Result<(), io::Error> {
pub fn run_proxy(listen: &str) -> Result<(), io::Error> { pub fn run_proxy(listen: &str) -> Result<(), io::Error> {
let addr = parse_listen(listen); let addr = parse_listen(listen);
let server = TcpListener::bind(addr)?; let server = TcpListener::bind(addr)?;
info!("Listening on ws://{}", server.local_addr()?);
for stream in server.incoming() { for stream in server.incoming() {
let stream = stream?; let stream = stream?;
let peer = stream.peer_addr()?; let peer = stream.peer_addr()?;
@ -126,7 +128,8 @@ impl AsRawFd for ProxyConnection {
impl Socket for ProxyConnection { impl Socket for ProxyConnection {
fn listen(url: &str) -> Result<Self, io::Error> { fn listen(url: &str) -> Result<Self, io::Error> {
let parsed_url = io_error!(Url::parse(url), "Invalid URL {}: {}", url)?; let parsed_url = io_error!(Url::parse(url), "Invalid URL {}: {}", url)?;
let (socket, _) = io_error!(connect(parsed_url), "Failed to connect to URL {}: {}", url)?; let (mut socket, _) = io_error!(connect(parsed_url), "Failed to connect to URL {}: {}", url)?;
socket.get_mut().set_nodelay(true)?;
let addr = "0.0.0.0:0".parse::<SocketAddr>().unwrap(); let addr = "0.0.0.0:0".parse::<SocketAddr>().unwrap();
let mut con = ProxyConnection { addr, socket }; let mut con = ProxyConnection { addr, socket };
let addr_data = con.read_message()?; let addr_data = con.read_message()?;