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 super::SPACE_BEFORE;
|
||||
use super::shared::SharedData;
|
||||
use crate::{
|
||||
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
|
||||
}
|
||||
|
||||
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) {
|
||||
let mut buffer = MsgBuffer::new(SPACE_BEFORE);
|
||||
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();
|
||||
if self.next_sync < now {
|
||||
self.sync();
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
use std::marker::PhantomData;
|
||||
use std::sync::Arc;
|
||||
use crate::error::Error;
|
||||
use std::{marker::PhantomData, net::SocketAddr, sync::Arc};
|
||||
|
||||
use super::shared::SharedData;
|
||||
use crate::net::Socket;
|
||||
use crate::util::{Time, TimeSource};
|
||||
use super::{shared::SharedData, SPACE_BEFORE};
|
||||
use crate::{
|
||||
net::Socket,
|
||||
util::{MsgBuffer, Time, TimeSource}
|
||||
};
|
||||
|
||||
|
||||
const SYNC_INTERVAL: Time = 1;
|
||||
|
@ -17,11 +19,28 @@ pub struct SocketThread<S: Socket, T: TimeSource> {
|
|||
|
||||
impl<S: Socket, T: TimeSource> SocketThread<S, T> {
|
||||
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) {
|
||||
let mut buffer = MsgBuffer::new(SPACE_BEFORE);
|
||||
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();
|
||||
if self.next_sync < now {
|
||||
self.sync();
|
||||
|
|
Loading…
Reference in New Issue