mirror of https://github.com/dswd/vpncloud.git
Basic framework
This commit is contained in:
parent
5000066646
commit
427c426fde
|
@ -1,9 +1,11 @@
|
||||||
use std::{marker::PhantomData, sync::Arc};
|
use std::{marker::PhantomData, sync::Arc};
|
||||||
|
|
||||||
|
use super::SPACE_BEFORE;
|
||||||
use super::shared::SharedData;
|
use super::shared::SharedData;
|
||||||
use crate::{
|
use crate::{
|
||||||
device::Device,
|
device::Device,
|
||||||
util::{Time, TimeSource}
|
error::Error,
|
||||||
|
util::{MsgBuffer, Time, TimeSource}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,8 +23,24 @@ impl<D: Device, T: TimeSource> DeviceThread<D, T> {
|
||||||
// TODO sync
|
// TODO sync
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn read_device_packet(&mut self, buffer: &mut MsgBuffer) -> Result<(), Error> {
|
||||||
|
// TODO: read data
|
||||||
|
// use 5sec timeout
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn forward_packet(&mut self, buffer: &mut MsgBuffer) -> Result<(), Error> {
|
||||||
|
// TODO: handle data
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn run(mut self) {
|
pub fn run(mut self) {
|
||||||
|
let mut buffer = MsgBuffer::new(SPACE_BEFORE);
|
||||||
loop {
|
loop {
|
||||||
|
try_fail!(self.read_device_packet(&mut buffer), "Failed to read from device: {}");
|
||||||
|
if let Err(e) = self.forward_packet(&mut buffer) {
|
||||||
|
error!("{}", e);
|
||||||
|
}
|
||||||
let now = T::now();
|
let now = T::now();
|
||||||
if self.next_sync < now {
|
if self.next_sync < now {
|
||||||
self.sync();
|
self.sync();
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
use std::marker::PhantomData;
|
use crate::error::Error;
|
||||||
use std::sync::Arc;
|
use std::{marker::PhantomData, net::SocketAddr, sync::Arc};
|
||||||
|
|
||||||
use super::shared::SharedData;
|
use super::{shared::SharedData, SPACE_BEFORE};
|
||||||
use crate::net::Socket;
|
use crate::{
|
||||||
use crate::util::{Time, TimeSource};
|
net::Socket,
|
||||||
|
util::{MsgBuffer, Time, TimeSource}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const SYNC_INTERVAL: Time = 1;
|
const SYNC_INTERVAL: Time = 1;
|
||||||
|
@ -17,11 +19,28 @@ pub struct SocketThread<S: Socket, T: TimeSource> {
|
||||||
|
|
||||||
impl<S: Socket, T: TimeSource> SocketThread<S, T> {
|
impl<S: Socket, T: TimeSource> SocketThread<S, T> {
|
||||||
fn sync(&mut self) {
|
fn sync(&mut self) {
|
||||||
//TODO sync
|
// TODO: sync
|
||||||
}
|
unimplemented!();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn read_socket_data(&mut self, buffer: &mut MsgBuffer) -> Result<SocketAddr, Error> {
|
||||||
|
// TODO: read data
|
||||||
|
// use 5sec timeout
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn handle_message(&mut self, src: SocketAddr, buffer: &mut MsgBuffer) -> Result<(), Error> {
|
||||||
|
// TODO: handle data
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn run(mut self) {
|
pub fn run(mut self) {
|
||||||
|
let mut buffer = MsgBuffer::new(SPACE_BEFORE);
|
||||||
loop {
|
loop {
|
||||||
|
let addr = try_fail!(self.read_socket_data(&mut buffer), "Failed to read from socket: {}");
|
||||||
|
if let Err(e) = self.handle_message(addr, &mut buffer) {
|
||||||
|
error!("{}", e);
|
||||||
|
}
|
||||||
let now = T::now();
|
let now = T::now();
|
||||||
if self.next_sync < now {
|
if self.next_sync < now {
|
||||||
self.sync();
|
self.sync();
|
||||||
|
@ -29,4 +48,4 @@ impl<S: Socket, T: TimeSource> SocketThread<S, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue