summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2019-09-10 21:42:21 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2019-09-10 21:42:21 +0200
commit02d9bdcc96c955b654a45d3629b1ee515902078d (patch)
treed0231989ccca424d26f0dcded640acac079aa9de /src/main.rs
parentBegin work on full router interaction unittest (diff)
downloadwireguard-rs-02d9bdcc96c955b654a45d3629b1ee515902078d.tar.xz
wireguard-rs-02d9bdcc96c955b654a45d3629b1ee515902078d.zip
Full inbound/outbound router test
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs129
1 files changed, 6 insertions, 123 deletions
diff --git a/src/main.rs b/src/main.rs
index 8d92048..53b2a51 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,130 +1,13 @@
#![feature(test)]
+extern crate jemallocator;
+
+#[global_allocator]
+static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
+
mod constants;
mod handshake;
mod router;
mod types;
-use hjul::*;
-
-use std::error::Error;
-use std::fmt;
-use std::net::SocketAddr;
-use std::time::Duration;
-
-use types::{Bind, Tun};
-
-#[derive(Debug)]
-enum TunError {}
-
-impl Error for TunError {
- fn description(&self) -> &str {
- "Generic Tun Error"
- }
-
- fn source(&self) -> Option<&(dyn Error + 'static)> {
- None
- }
-}
-
-impl fmt::Display for TunError {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "Not Possible")
- }
-}
-
-struct TunTest {}
-
-impl Tun for TunTest {
- type Error = TunError;
-
- fn mtu(&self) -> usize {
- 1500
- }
-
- fn read(&self, buf: &mut [u8], offset: usize) -> Result<usize, Self::Error> {
- Ok(0)
- }
-
- fn write(&self, src: &[u8]) -> Result<(), Self::Error> {
- Ok(())
- }
-}
-
-struct BindTest {}
-
-impl Bind for BindTest {
- type Error = BindError;
- type Endpoint = SocketAddr;
-
- fn new() -> BindTest {
- BindTest {}
- }
-
- fn set_port(&self, port: u16) -> Result<(), Self::Error> {
- Ok(())
- }
-
- fn get_port(&self) -> Option<u16> {
- None
- }
-
- fn recv(&self, buf: &mut [u8]) -> Result<(usize, Self::Endpoint), Self::Error> {
- Ok((0, "127.0.0.1:8080".parse().unwrap()))
- }
-
- fn send(&self, buf: &[u8], dst: &Self::Endpoint) -> Result<(), Self::Error> {
- Ok(())
- }
-}
-
-#[derive(Debug)]
-enum BindError {}
-
-impl Error for BindError {
- fn description(&self) -> &str {
- "Generic Bind Error"
- }
-
- fn source(&self) -> Option<&(dyn Error + 'static)> {
- None
- }
-}
-
-impl fmt::Display for BindError {
- fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "Not Possible")
- }
-}
-
-#[derive(Debug, Clone)]
-struct PeerTimer {
- a: Timer,
- b: Timer,
-}
-
-fn main() {
- let runner = Runner::new(Duration::from_millis(100), 1000, 1024);
-
- {
- let router = router::Device::new(
- 4,
- TunTest {},
- BindTest {},
- |t: &PeerTimer, data: bool, sent: bool| t.a.reset(Duration::from_millis(1000)),
- |t: &PeerTimer, data: bool, sent: bool| t.b.reset(Duration::from_millis(1000)),
- |t: &PeerTimer| println!("new key requested"),
- );
-
- let pt = PeerTimer {
- a: runner.timer(|| println!("timer-a fired for peer")),
- b: runner.timer(|| println!("timer-b fired for peer")),
- };
-
- let peer = router.new_peer(pt.clone());
-
- println!("{:?}", pt);
- }
-
- println!("joined");
-}
+fn main() {}