mirror of https://github.com/dswd/vpncloud.git
Fix some lints
This commit is contained in:
parent
13688edd75
commit
5236adf7b3
|
@ -34,7 +34,7 @@ url = { version = "2.2", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
criterion = "0.3"
|
criterion = { version = "0.3", features = ["html_reports"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["nat", "websocket"]
|
default = ["nat", "websocket"]
|
||||||
|
|
|
@ -325,15 +325,17 @@ impl<TS: TimeSource> BeaconSerializer<TS> {
|
||||||
fn encode() {
|
fn encode() {
|
||||||
MockTimeSource::set_time(2000 * 3600);
|
MockTimeSource::set_time(2000 * 3600);
|
||||||
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
||||||
let mut peers = Vec::new();
|
let mut peers = vec![
|
||||||
peers.push(SocketAddr::from_str("1.2.3.4:5678").unwrap());
|
SocketAddr::from_str("1.2.3.4:5678").unwrap(),
|
||||||
peers.push(SocketAddr::from_str("6.6.6.6:53").unwrap());
|
SocketAddr::from_str("6.6.6.6:53").unwrap()
|
||||||
|
];
|
||||||
assert_eq!("WsHI31EWDMBYxvITiILIrm2k9gEik22E", ser.encode(&peers));
|
assert_eq!("WsHI31EWDMBYxvITiILIrm2k9gEik22E", ser.encode(&peers));
|
||||||
peers.push(SocketAddr::from_str("[::1]:5678").unwrap());
|
peers.push(SocketAddr::from_str("[::1]:5678").unwrap());
|
||||||
assert_eq!("WsHI3GXKaXCveo6uejmZizZ72kR6Y0L9T7h49TXONp1ugfKvvvEik22E", ser.encode(&peers));
|
assert_eq!("WsHI3GXKaXCveo6uejmZizZ72kR6Y0L9T7h49TXONp1ugfKvvvEik22E", ser.encode(&peers));
|
||||||
let mut peers = Vec::new();
|
let peers = vec![
|
||||||
peers.push(SocketAddr::from_str("1.2.3.4:5678").unwrap());
|
SocketAddr::from_str("1.2.3.4:5678").unwrap(),
|
||||||
peers.push(SocketAddr::from_str("6.6.6.6:54").unwrap());
|
SocketAddr::from_str("6.6.6.6:54").unwrap()
|
||||||
|
];
|
||||||
assert_eq!("WsHI32gm9eMSHP3Lm1GXcdP7rD3ik22E", ser.encode(&peers));
|
assert_eq!("WsHI32gm9eMSHP3Lm1GXcdP7rD3ik22E", ser.encode(&peers));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,9 +343,10 @@ fn encode() {
|
||||||
fn decode() {
|
fn decode() {
|
||||||
MockTimeSource::set_time(2000 * 3600);
|
MockTimeSource::set_time(2000 * 3600);
|
||||||
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
||||||
let mut peers = Vec::new();
|
let mut peers = vec![
|
||||||
peers.push(SocketAddr::from_str("1.2.3.4:5678").unwrap());
|
SocketAddr::from_str("1.2.3.4:5678").unwrap(),
|
||||||
peers.push(SocketAddr::from_str("6.6.6.6:53").unwrap());
|
SocketAddr::from_str("6.6.6.6:53").unwrap()
|
||||||
|
];
|
||||||
assert_eq!(format!("{:?}", peers), format!("{:?}", ser.decode("WsHI31EWDMBYxvITiILIrm2k9gEik22E", None)));
|
assert_eq!(format!("{:?}", peers), format!("{:?}", ser.decode("WsHI31EWDMBYxvITiILIrm2k9gEik22E", None)));
|
||||||
peers.push(SocketAddr::from_str("[::1]:5678").unwrap());
|
peers.push(SocketAddr::from_str("[::1]:5678").unwrap());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -356,9 +359,10 @@ fn decode() {
|
||||||
fn decode_split() {
|
fn decode_split() {
|
||||||
MockTimeSource::set_time(2000 * 3600);
|
MockTimeSource::set_time(2000 * 3600);
|
||||||
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
||||||
let mut peers = Vec::new();
|
let peers = vec![
|
||||||
peers.push(SocketAddr::from_str("1.2.3.4:5678").unwrap());
|
SocketAddr::from_str("1.2.3.4:5678").unwrap(),
|
||||||
peers.push(SocketAddr::from_str("6.6.6.6:53").unwrap());
|
SocketAddr::from_str("6.6.6.6:53").unwrap()
|
||||||
|
];
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
format!("{:?}", peers),
|
format!("{:?}", peers),
|
||||||
format!("{:?}", ser.decode("WsHI3-1E.WD:MB Yx\tvI\nTi(IL)Ir[m2]k9ügEäik22E", None))
|
format!("{:?}", ser.decode("WsHI3-1E.WD:MB Yx\tvI\nTi(IL)Ir[m2]k9ügEäik22E", None))
|
||||||
|
@ -373,9 +377,10 @@ fn decode_split() {
|
||||||
fn decode_offset() {
|
fn decode_offset() {
|
||||||
MockTimeSource::set_time(2000 * 3600);
|
MockTimeSource::set_time(2000 * 3600);
|
||||||
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
||||||
let mut peers = Vec::new();
|
let peers = vec![
|
||||||
peers.push(SocketAddr::from_str("1.2.3.4:5678").unwrap());
|
SocketAddr::from_str("1.2.3.4:5678").unwrap(),
|
||||||
peers.push(SocketAddr::from_str("6.6.6.6:53").unwrap());
|
SocketAddr::from_str("6.6.6.6:53").unwrap()
|
||||||
|
];
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
format!("{:?}", peers),
|
format!("{:?}", peers),
|
||||||
format!("{:?}", ser.decode("Hello World: WsHI31EWDMBYxvITiILIrm2k9gEik22E! End of the World", None))
|
format!("{:?}", ser.decode("Hello World: WsHI31EWDMBYxvITiILIrm2k9gEik22E! End of the World", None))
|
||||||
|
@ -386,9 +391,10 @@ fn decode_offset() {
|
||||||
fn decode_multiple() {
|
fn decode_multiple() {
|
||||||
MockTimeSource::set_time(2000 * 3600);
|
MockTimeSource::set_time(2000 * 3600);
|
||||||
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
||||||
let mut peers = Vec::new();
|
let peers = vec![
|
||||||
peers.push(SocketAddr::from_str("1.2.3.4:5678").unwrap());
|
SocketAddr::from_str("1.2.3.4:5678").unwrap(),
|
||||||
peers.push(SocketAddr::from_str("6.6.6.6:53").unwrap());
|
SocketAddr::from_str("6.6.6.6:53").unwrap()
|
||||||
|
];
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
format!("{:?}", peers),
|
format!("{:?}", peers),
|
||||||
format!("{:?}", ser.decode("WsHI31HVpqxFNMNSPrvik22E WsHI34yOBcZIulKdtn2ik22E", None))
|
format!("{:?}", ser.decode("WsHI31HVpqxFNMNSPrvik22E WsHI34yOBcZIulKdtn2ik22E", None))
|
||||||
|
@ -399,9 +405,6 @@ fn decode_multiple() {
|
||||||
fn decode_ttl() {
|
fn decode_ttl() {
|
||||||
MockTimeSource::set_time(2000 * 3600);
|
MockTimeSource::set_time(2000 * 3600);
|
||||||
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
||||||
let mut peers = Vec::new();
|
|
||||||
peers.push(SocketAddr::from_str("1.2.3.4:5678").unwrap());
|
|
||||||
peers.push(SocketAddr::from_str("6.6.6.6:53").unwrap());
|
|
||||||
MockTimeSource::set_time(2000 * 3600);
|
MockTimeSource::set_time(2000 * 3600);
|
||||||
assert_eq!(2, ser.decode("WsHI31EWDMBYxvITiILIrm2k9gEik22E", None).len());
|
assert_eq!(2, ser.decode("WsHI31EWDMBYxvITiILIrm2k9gEik22E", None).len());
|
||||||
MockTimeSource::set_time(2100 * 3600);
|
MockTimeSource::set_time(2100 * 3600);
|
||||||
|
@ -440,9 +443,10 @@ fn decode_invalid() {
|
||||||
fn encode_decode() {
|
fn encode_decode() {
|
||||||
MockTimeSource::set_time(2000 * 3600);
|
MockTimeSource::set_time(2000 * 3600);
|
||||||
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
||||||
let mut peers = Vec::new();
|
let peers = vec![
|
||||||
peers.push(SocketAddr::from_str("1.2.3.4:5678").unwrap());
|
SocketAddr::from_str("1.2.3.4:5678").unwrap(),
|
||||||
peers.push(SocketAddr::from_str("6.6.6.6:53").unwrap());
|
SocketAddr::from_str("6.6.6.6:53").unwrap()
|
||||||
|
];
|
||||||
let data = ser.encode(&peers);
|
let data = ser.encode(&peers);
|
||||||
let peers2 = ser.decode(&data, None);
|
let peers2 = ser.decode(&data, None);
|
||||||
assert_eq!(format!("{:?}", peers), format!("{:?}", peers2));
|
assert_eq!(format!("{:?}", peers), format!("{:?}", peers2));
|
||||||
|
@ -452,9 +456,10 @@ fn encode_decode() {
|
||||||
fn encode_decode_file() {
|
fn encode_decode_file() {
|
||||||
MockTimeSource::set_time(2000 * 3600);
|
MockTimeSource::set_time(2000 * 3600);
|
||||||
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
||||||
let mut peers = Vec::new();
|
let peers = vec![
|
||||||
peers.push(SocketAddr::from_str("1.2.3.4:5678").unwrap());
|
SocketAddr::from_str("1.2.3.4:5678").unwrap(),
|
||||||
peers.push(SocketAddr::from_str("6.6.6.6:53").unwrap());
|
SocketAddr::from_str("6.6.6.6:53").unwrap()
|
||||||
|
];
|
||||||
let file = tempfile::NamedTempFile::new().expect("Failed to create temp file");
|
let file = tempfile::NamedTempFile::new().expect("Failed to create temp file");
|
||||||
assert!(ser.write_to_file(&peers, file.path()).is_ok());
|
assert!(ser.write_to_file(&peers, file.path()).is_ok());
|
||||||
let peers2 = ser.read_from_file(file.path(), None);
|
let peers2 = ser.read_from_file(file.path(), None);
|
||||||
|
@ -466,9 +471,10 @@ fn encode_decode_file() {
|
||||||
fn encode_decode_cmd() {
|
fn encode_decode_cmd() {
|
||||||
MockTimeSource::set_time(2000 * 3600);
|
MockTimeSource::set_time(2000 * 3600);
|
||||||
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
let ser = BeaconSerializer::<MockTimeSource>::new(b"mysecretkey");
|
||||||
let mut peers = Vec::new();
|
let peers = vec![
|
||||||
peers.push(SocketAddr::from_str("1.2.3.4:5678").unwrap());
|
SocketAddr::from_str("1.2.3.4:5678").unwrap(),
|
||||||
peers.push(SocketAddr::from_str("6.6.6.6:53").unwrap());
|
SocketAddr::from_str("6.6.6.6:53").unwrap()
|
||||||
|
];
|
||||||
let file = tempfile::NamedTempFile::new().expect("Failed to create temp file");
|
let file = tempfile::NamedTempFile::new().expect("Failed to create temp file");
|
||||||
assert!(ser.write_to_cmd(&peers, &format!("echo $beacon > {}", file.path().display())).is_ok());
|
assert!(ser.write_to_cmd(&peers, &format!("echo $beacon > {}", file.path().display())).is_ok());
|
||||||
thread::sleep(Duration::from_millis(100));
|
thread::sleep(Duration::from_millis(100));
|
||||||
|
|
|
@ -49,6 +49,7 @@ const SPACE_BEFORE: usize = 100;
|
||||||
|
|
||||||
struct PeerData {
|
struct PeerData {
|
||||||
addrs: AddrList,
|
addrs: AddrList,
|
||||||
|
#[allow(dead_code)] //TODO: export in status
|
||||||
last_seen: Time,
|
last_seen: Time,
|
||||||
timeout: Time,
|
timeout: Time,
|
||||||
peer_timeout: u16,
|
peer_timeout: u16,
|
||||||
|
|
|
@ -391,6 +391,7 @@ pub struct InitState<P: Payload> {
|
||||||
last_message: Option<Vec<u8>>,
|
last_message: Option<Vec<u8>>,
|
||||||
crypto: Option<CryptoCore>,
|
crypto: Option<CryptoCore>,
|
||||||
algorithms: Algorithms,
|
algorithms: Algorithms,
|
||||||
|
#[allow(dead_code)] // Used in tests
|
||||||
selected_algorithm: Option<&'static Algorithm>,
|
selected_algorithm: Option<&'static Algorithm>,
|
||||||
failed_retries: usize
|
failed_retries: usize
|
||||||
}
|
}
|
||||||
|
@ -489,7 +490,7 @@ impl<P: Payload> InitState<P> {
|
||||||
if let Some(crypto) = &mut self.crypto {
|
if let Some(crypto) = &mut self.crypto {
|
||||||
crypto.decrypt(data)?;
|
crypto.decrypt(data)?;
|
||||||
}
|
}
|
||||||
Ok(P::read_from(Cursor::new(data.message()))?)
|
P::read_from(Cursor::new(data.message()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_salted_node_id_hash(&self, hash: &SaltedNodeIdHash, node_id: NodeId) -> bool {
|
fn check_salted_node_id_hash(&self, hash: &SaltedNodeIdHash, node_id: NodeId) -> bool {
|
||||||
|
|
Loading…
Reference in New Issue