Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2eea6af625 | ||
|
|
15b00db451 | ||
|
|
20935d2380 |
No files matched your search
@@ -1,6 +1,6 @@
|
||||
use tonic::{Request, Response, Status};
|
||||
use coordinator::coordinator_client::CoordinatorClient as GeneratedCoordinatorClient;
|
||||
use coordinator::{RegisterRequest, RegisterResponse, HeartbeatRequest, HeartbeatResponse, PeerRequest, PeerResponse};
|
||||
use crate::coordinator::coordinator_client::CoordinatorClient as GeneratedCoordinatorClient;
|
||||
use crate::coordinator::{RegisterRequest, RegisterResponse, HeartbeatRequest, HeartbeatResponse, PeerRequest, PeerResponse};
|
||||
|
||||
pub struct CoordinatorClient {
|
||||
client: GeneratedCoordinatorClient<tonic::transport::Channel>,
|
||||
|
||||
@@ -11,6 +11,27 @@ mod noise;
|
||||
mod transport;
|
||||
mod tun;
|
||||
|
||||
pub mod coordinator {
|
||||
pub mod coordinator_client {
|
||||
// This is a placeholder for the generated gRPC code
|
||||
pub struct GeneratedCoordinatorClient<T>(T);
|
||||
impl GeneratedCoordinatorClient<tonic::transport::Channel> {
|
||||
pub async fn connect(addr: String) -> Result<Self, tonic::transport::Error> {
|
||||
let channel = tonic::transport::Endpoint::from_shared(addr)?
|
||||
.connect()
|
||||
.await?;
|
||||
Ok(Self(channel))
|
||||
}
|
||||
}
|
||||
}
|
||||
pub struct RegisterRequest { pub network_key: String, pub node_id: String, pub public_key: String, pub local_ip: String }
|
||||
pub struct RegisterResponse { pub virtual_ip: String, pub session_token: String }
|
||||
pub struct HeartbeatRequest { pub node_id: String, pub session_token: String, pub public_endpoint: String }
|
||||
pub struct HeartbeatResponse { pub session_token: String }
|
||||
pub struct PeerRequest { pub target_node_id: String, pub session_token: String }
|
||||
pub struct PeerResponse { pub endpoint: String, pub public_key: String }
|
||||
}
|
||||
|
||||
use coordinator_client::CoordinatorClient;
|
||||
use transport::{Transport, Packet};
|
||||
use tun::TunInterface;
|
||||
|
||||
@@ -54,7 +54,7 @@ impl Transport {
|
||||
let data = Bytes::copy_from_slice(&buf[..len]);
|
||||
|
||||
match crypto::decapsulate(data) {
|
||||
Ok((header, payload, _hmac)) => {
|
||||
Ok((_header, payload, _hmac)) => {
|
||||
// In a real implementation, HMAC verification and decryption would happen here
|
||||
// if verify_hmac(&_hmac, &header, &payload) {
|
||||
// let decrypted_data = decrypt(payload, addr).await;
|
||||
|
||||
+5
-6
@@ -1,8 +1,7 @@
|
||||
use std::ffi::{c_void, OsString};
|
||||
use std::ffi::c_void;
|
||||
use std::os::windows::ffi::OsStrExt;
|
||||
use std::ptr::{null_mut};
|
||||
use std::io::{self, Read, Write};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::ptr::null_mut;
|
||||
use std::io;
|
||||
|
||||
/// Wintun API Constants
|
||||
const WINTUN_RING_BUFFER_SIZE: usize = 65536;
|
||||
@@ -42,7 +41,7 @@ unsafe impl Sync for TunInterface {}
|
||||
|
||||
impl TunInterface {
|
||||
pub fn new(name: &str) -> io::Result<Self> {
|
||||
let wide_name: Vec<u16> = OSString::from(name).encode_utf16().chain(std::iter::once(0)).collect();
|
||||
let wide_name: Vec<u16> = name.encode_utf16().chain(std::iter::once(0)).collect();
|
||||
|
||||
unsafe {
|
||||
let adapter = WintunOpenAdapter(wide_name.as_ptr());
|
||||
@@ -85,7 +84,7 @@ impl TunInterface {
|
||||
pub fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
|
||||
unsafe {
|
||||
let length = buf.len() as u32;
|
||||
let mut packet_ptr_ptr = WintunAllocateSendPacket(self.tx_ring, length);
|
||||
let packet_ptr_ptr = WintunAllocateSendPacket(self.tx_ring, length);
|
||||
|
||||
if packet_ptr_ptr.is_null() {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "Failed to allocate send packet"));
|
||||
|
||||
Reference in new issue
Block a user