mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-26 17:03:43 +02:00
Factor out the use of Rust "Any" to avoid unnecessary indirections.
This commit is contained in:
parent
deec3b807b
commit
1e555ef24d
16 changed files with 156 additions and 75 deletions
|
@ -25,7 +25,7 @@ pub struct Fingerprint {
|
|||
}
|
||||
|
||||
impl Fingerprint {
|
||||
#[inline]
|
||||
#[inline(always)]
|
||||
pub(crate) fn new_from_capi(fp: &ztcore::ZT_Fingerprint) -> Fingerprint {
|
||||
Fingerprint{
|
||||
address: Address(fp.address),
|
||||
|
|
|
@ -94,23 +94,15 @@ impl Identity {
|
|||
}
|
||||
|
||||
/// Validate this identity, which can be slightly time consuming in some cases (20-40ms).
|
||||
#[inline(always)]
|
||||
pub fn validate(&self) -> bool {
|
||||
unsafe {
|
||||
if ztcore::ZT_Identity_validate(self.capi) != 0 {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
unsafe { ztcore::ZT_Identity_validate(self.capi) != 0 }
|
||||
}
|
||||
|
||||
/// Returns true if this Identity includes its corresponding private key.
|
||||
#[inline(always)]
|
||||
pub fn has_private(&self) -> bool {
|
||||
unsafe {
|
||||
if ztcore::ZT_Identity_hasPrivate(self.capi) != 0 {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
unsafe { ztcore::ZT_Identity_hasPrivate(self.capi) != 0 }
|
||||
}
|
||||
|
||||
/// Obtain the full fingerprint of this identity, which includes a SHA384 hash of the public key.
|
||||
|
@ -138,16 +130,9 @@ impl Identity {
|
|||
}
|
||||
|
||||
/// Verify a signature by this identity.
|
||||
#[inline(always)]
|
||||
pub fn verify(&self, data: &[u8], signature: &[u8]) -> bool {
|
||||
if signature.len() == 0 {
|
||||
return false;
|
||||
}
|
||||
unsafe {
|
||||
if ztcore::ZT_Identity_verify(self.capi, data.as_ptr() as *const c_void, data.len() as c_uint, signature.as_ptr() as *const c_void, signature.len() as c_uint) != 0 {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
unsafe { signature.len() > 0 && ztcore::ZT_Identity_verify(self.capi, data.as_ptr() as *const c_void, data.len() as c_uint, signature.as_ptr() as *const c_void, signature.len() as c_uint) != 0 }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -95,6 +95,7 @@ impl InetAddress {
|
|||
/// Unsafely transmute a raw sockaddr_storage structure into an InetAddress.
|
||||
/// The type S MUST have a size equal to the size of this type and the
|
||||
/// OS's sockaddr_storage. If not, this may crash.
|
||||
#[inline(always)]
|
||||
pub unsafe fn transmute_raw_sockaddr_storage<S>(ss: &S) -> &InetAddress {
|
||||
transmute(ss)
|
||||
}
|
||||
|
@ -149,12 +150,14 @@ impl InetAddress {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn port(&self) -> u16 {
|
||||
unsafe {
|
||||
ztcore::ZT_InetAddress_port(self.as_capi_ptr()) as u16
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn set_port(&mut self, port: u16) {
|
||||
unsafe {
|
||||
ztcore::ZT_InetAddress_setPort(self.as_capi_mut_ptr(), port as c_uint);
|
||||
|
@ -162,6 +165,7 @@ impl InetAddress {
|
|||
}
|
||||
|
||||
/// Get the network scope of the IP in this object.
|
||||
#[inline(always)]
|
||||
pub fn ip_scope(&self) -> IpScope {
|
||||
unsafe {
|
||||
IpScope::from_i32(ztcore::ZT_InetAddress_ipScope(self.as_capi_ptr()) as i32).unwrap_or(IpScope::None)
|
||||
|
|
|
@ -23,7 +23,7 @@ pub struct Locator {
|
|||
}
|
||||
|
||||
impl Locator {
|
||||
#[inline]
|
||||
#[inline(always)]
|
||||
pub(crate) fn new_from_capi(l: *const ztcore::ZT_Locator, requires_delete: bool) -> Locator {
|
||||
Locator{
|
||||
capi: l,
|
||||
|
@ -46,6 +46,7 @@ impl Locator {
|
|||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn timestamp(&self) -> i64 {
|
||||
unsafe {
|
||||
return ztcore::ZT_Locator_timestamp(self.capi) as i64;
|
||||
|
|
|
@ -47,6 +47,13 @@ impl PartialEq for MAC {
|
|||
|
||||
impl Eq for MAC {}
|
||||
|
||||
impl Clone for MAC {
|
||||
#[inline(always)]
|
||||
fn clone(&self) -> Self {
|
||||
MAC(self.0)
|
||||
}
|
||||
}
|
||||
|
||||
struct AddressVisitor;
|
||||
|
||||
impl<'de> serde::de::Visitor<'de> for AddressVisitor {
|
||||
|
|
|
@ -23,7 +23,6 @@ impl NetworkId {
|
|||
}
|
||||
|
||||
impl ToString for NetworkId {
|
||||
#[inline(always)]
|
||||
fn to_string(&self) -> String {
|
||||
format!("{:0>16x}", self.0)
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
*/
|
||||
/****/
|
||||
|
||||
use std::any::Any;
|
||||
use std::cell::Cell;
|
||||
use std::collections::hash_map::HashMap;
|
||||
use std::ffi::CStr;
|
||||
|
@ -67,12 +66,12 @@ pub struct NodeStatus {
|
|||
/// An event handler that receives events, frames, and packets from the core.
|
||||
/// Note that these handlers can be called concurrently from any thread and
|
||||
/// must be thread safe.
|
||||
pub trait NodeEventHandler {
|
||||
pub trait NodeEventHandler<N: 'static> {
|
||||
/// Called when a configuration change or update should be applied to a network.
|
||||
fn virtual_network_config(&self, network_id: NetworkId, network_obj: &Arc<dyn Any>, config_op: VirtualNetworkConfigOperation, config: Option<&VirtualNetworkConfig>);
|
||||
fn virtual_network_config(&self, network_id: NetworkId, network_obj: &Arc<N>, config_op: VirtualNetworkConfigOperation, config: Option<&VirtualNetworkConfig>);
|
||||
|
||||
/// Called when a frame should be injected into the virtual network (physical -> virtual).
|
||||
fn virtual_network_frame(&self, network_id: NetworkId, network_obj: &Arc<dyn Any>, source_mac: MAC, dest_mac: MAC, ethertype: u16, vlan_id: u16, data: &[u8]);
|
||||
fn virtual_network_frame(&self, network_id: NetworkId, network_obj: &Arc<N>, source_mac: MAC, dest_mac: MAC, ethertype: u16, vlan_id: u16, data: &[u8]);
|
||||
|
||||
/// Called when a core ZeroTier event occurs.
|
||||
fn event(&self, event: Event, event_data: &[u8]);
|
||||
|
@ -96,13 +95,13 @@ pub trait NodeEventHandler {
|
|||
/// An instance of the ZeroTier core.
|
||||
/// This is templated on the actual implementation of NodeEventHandler for performance reasons,
|
||||
/// as it avoids an extra indirect function call.
|
||||
pub struct Node<T: NodeEventHandler + 'static> {
|
||||
pub struct Node<T: NodeEventHandler<N> + 'static, N: 'static> {
|
||||
event_handler: Arc<T>,
|
||||
capi: Cell<*mut ztcore::ZT_Node>,
|
||||
background_thread: Cell<Option<std::thread::JoinHandle<()>>>,
|
||||
background_thread_run: Arc<AtomicBool>,
|
||||
now: PortableAtomicI64,
|
||||
networks_by_id: Mutex<HashMap<u64, *mut Arc<dyn Any>>> // pointer to an Arc<> is a raw value created from Box<Arc<N>>
|
||||
networks_by_id: Mutex<HashMap<u64, *mut Arc<N>>> // pointer to an Arc<> is a raw value created from Box<Arc<N>>
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -110,14 +109,14 @@ pub struct Node<T: NodeEventHandler + 'static> {
|
|||
macro_rules! node_from_raw_ptr {
|
||||
($uptr:ident) => {
|
||||
unsafe {
|
||||
let ntmp: *const Node<T> = $uptr.cast::<Node<T>>();
|
||||
let ntmp: &Node<T> = &*ntmp;
|
||||
let ntmp: *const Node<T, N> = $uptr.cast::<Node<T, N>>();
|
||||
let ntmp: &Node<T, N> = &*ntmp;
|
||||
ntmp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" fn zt_virtual_network_config_function<T: NodeEventHandler + 'static>(
|
||||
extern "C" fn zt_virtual_network_config_function<T: NodeEventHandler<N> + 'static, N: 'static>(
|
||||
_: *mut ztcore::ZT_Node,
|
||||
uptr: *mut c_void,
|
||||
_: *mut c_void,
|
||||
|
@ -130,7 +129,7 @@ extern "C" fn zt_virtual_network_config_function<T: NodeEventHandler + 'static>(
|
|||
if op2.is_some() {
|
||||
let op2 = op2.unwrap();
|
||||
let n = node_from_raw_ptr!(uptr);
|
||||
let network_obj: &Arc<dyn Any> = unsafe { &*((*nptr).cast::<Arc<dyn Any>>()) };
|
||||
let network_obj = unsafe { &*((*nptr).cast::<Arc<N>>()) };
|
||||
if conf.is_null() {
|
||||
n.event_handler.virtual_network_config(NetworkId(nwid), network_obj, op2, None);
|
||||
} else {
|
||||
|
@ -140,7 +139,7 @@ extern "C" fn zt_virtual_network_config_function<T: NodeEventHandler + 'static>(
|
|||
}
|
||||
}
|
||||
|
||||
extern "C" fn zt_virtual_network_frame_function<T: NodeEventHandler + 'static>(
|
||||
extern "C" fn zt_virtual_network_frame_function<T: NodeEventHandler<N> + 'static, N: 'static>(
|
||||
_: *mut ztcore::ZT_Node,
|
||||
uptr: *mut c_void,
|
||||
_: *mut c_void,
|
||||
|
@ -157,7 +156,7 @@ extern "C" fn zt_virtual_network_frame_function<T: NodeEventHandler + 'static>(
|
|||
let n = node_from_raw_ptr!(uptr);
|
||||
n.event_handler.virtual_network_frame(
|
||||
NetworkId(nwid),
|
||||
unsafe { &*((*nptr).cast::<Arc<dyn Any>>()) },
|
||||
unsafe { &*((*nptr).cast::<Arc<N>>()) },
|
||||
MAC(source_mac),
|
||||
MAC(dest_mac),
|
||||
ethertype as u16,
|
||||
|
@ -166,7 +165,7 @@ extern "C" fn zt_virtual_network_frame_function<T: NodeEventHandler + 'static>(
|
|||
}
|
||||
}
|
||||
|
||||
extern "C" fn zt_event_callback<T: NodeEventHandler + 'static>(
|
||||
extern "C" fn zt_event_callback<T: NodeEventHandler<N> + 'static, N: 'static>(
|
||||
_: *mut ztcore::ZT_Node,
|
||||
uptr: *mut c_void,
|
||||
_: *mut c_void,
|
||||
|
@ -187,7 +186,7 @@ extern "C" fn zt_event_callback<T: NodeEventHandler + 'static>(
|
|||
}
|
||||
}
|
||||
|
||||
extern "C" fn zt_state_put_function<T: NodeEventHandler + 'static>(
|
||||
extern "C" fn zt_state_put_function<T: NodeEventHandler<N> + 'static, N: 'static>(
|
||||
_: *mut ztcore::ZT_Node,
|
||||
uptr: *mut c_void,
|
||||
_: *mut c_void,
|
||||
|
@ -207,7 +206,7 @@ extern "C" fn zt_state_put_function<T: NodeEventHandler + 'static>(
|
|||
}
|
||||
}
|
||||
|
||||
extern "C" fn zt_state_get_function<T: NodeEventHandler + 'static>(
|
||||
extern "C" fn zt_state_get_function<T: NodeEventHandler<N> + 'static, N: 'static>(
|
||||
_: *mut ztcore::ZT_Node,
|
||||
uptr: *mut c_void,
|
||||
_: *mut c_void,
|
||||
|
@ -249,7 +248,7 @@ extern "C" fn zt_state_get_function<T: NodeEventHandler + 'static>(
|
|||
return -1;
|
||||
}
|
||||
|
||||
extern "C" fn zt_wire_packet_send_function<T: NodeEventHandler + 'static>(
|
||||
extern "C" fn zt_wire_packet_send_function<T: NodeEventHandler<N> + 'static, N: 'static>(
|
||||
_: *mut ztcore::ZT_Node,
|
||||
uptr: *mut c_void,
|
||||
_: *mut c_void,
|
||||
|
@ -263,7 +262,7 @@ extern "C" fn zt_wire_packet_send_function<T: NodeEventHandler + 'static>(
|
|||
return n.event_handler.wire_packet_send(local_socket, InetAddress::transmute_capi(unsafe { &*sock_addr }), unsafe { &*slice_from_raw_parts(data.cast::<u8>(), data_size as usize) }, packet_ttl as u32) as c_int;
|
||||
}
|
||||
|
||||
extern "C" fn zt_path_check_function<T: NodeEventHandler + 'static>(
|
||||
extern "C" fn zt_path_check_function<T: NodeEventHandler<N> + 'static, N: 'static>(
|
||||
_: *mut ztcore::ZT_Node,
|
||||
uptr: *mut c_void,
|
||||
_: *mut c_void,
|
||||
|
@ -280,7 +279,7 @@ extern "C" fn zt_path_check_function<T: NodeEventHandler + 'static>(
|
|||
return 0;
|
||||
}
|
||||
|
||||
extern "C" fn zt_path_lookup_function<T: NodeEventHandler + 'static>(
|
||||
extern "C" fn zt_path_lookup_function<T: NodeEventHandler<N> + 'static, N: 'static>(
|
||||
_: *mut ztcore::ZT_Node,
|
||||
uptr: *mut c_void,
|
||||
_: *mut c_void,
|
||||
|
@ -319,9 +318,9 @@ extern "C" fn zt_path_lookup_function<T: NodeEventHandler + 'static>(
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
impl<T: NodeEventHandler + 'static> Node<T> {
|
||||
impl<T: NodeEventHandler<N> + 'static, N: 'static> Node<T, N> {
|
||||
/// Create a new Node with a given event handler.
|
||||
pub fn new(event_handler: Arc<T>) -> Result<Arc<Node<T>>, ResultCode> {
|
||||
pub fn new(event_handler: Arc<T>) -> Result<Arc<Node<T, N>>, ResultCode> {
|
||||
let now = now();
|
||||
|
||||
let n = Arc::new(Node {
|
||||
|
@ -336,14 +335,14 @@ impl<T: NodeEventHandler + 'static> Node<T> {
|
|||
let mut capi: *mut ztcore::ZT_Node = null_mut();
|
||||
unsafe {
|
||||
let callbacks = ztcore::ZT_Node_Callbacks {
|
||||
statePutFunction: transmute(zt_state_put_function::<T> as *const ()),
|
||||
stateGetFunction: transmute(zt_state_get_function::<T> as *const ()),
|
||||
wirePacketSendFunction: transmute(zt_wire_packet_send_function::<T> as *const ()),
|
||||
virtualNetworkFrameFunction: transmute(zt_virtual_network_frame_function::<T> as *const ()),
|
||||
virtualNetworkConfigFunction: transmute(zt_virtual_network_config_function::<T> as *const ()),
|
||||
eventCallback: transmute(zt_event_callback::<T> as *const ()),
|
||||
pathCheckFunction: transmute(zt_path_check_function::<T> as *const ()),
|
||||
pathLookupFunction: transmute(zt_path_lookup_function::<T> as *const ()),
|
||||
statePutFunction: transmute(zt_state_put_function::<T, N> as *const ()),
|
||||
stateGetFunction: transmute(zt_state_get_function::<T, N> as *const ()),
|
||||
wirePacketSendFunction: transmute(zt_wire_packet_send_function::<T, N> as *const ()),
|
||||
virtualNetworkFrameFunction: transmute(zt_virtual_network_frame_function::<T, N> as *const ()),
|
||||
virtualNetworkConfigFunction: transmute(zt_virtual_network_config_function::<T, N> as *const ()),
|
||||
eventCallback: transmute(zt_event_callback::<T, N> as *const ()),
|
||||
pathCheckFunction: transmute(zt_path_check_function::<T, N> as *const ()),
|
||||
pathLookupFunction: transmute(zt_path_lookup_function::<T, N> as *const ()),
|
||||
};
|
||||
|
||||
let rc = ztcore::ZT_Node_new(&mut capi as *mut *mut ztcore::ZT_Node, transmute(Arc::as_ptr(&n)), null_mut(), &callbacks as *const ztcore::ZT_Node_Callbacks, now);
|
||||
|
@ -396,7 +395,7 @@ impl<T: NodeEventHandler + 'static> Node<T> {
|
|||
next_delay
|
||||
}
|
||||
|
||||
pub fn join(&self, nwid: NetworkId, controller_fingerprint: Option<Fingerprint>, network_obj: &Arc<dyn Any>) -> ResultCode {
|
||||
pub fn join(&self, nwid: NetworkId, controller_fingerprint: Option<Fingerprint>, network_obj: &Arc<N>) -> ResultCode {
|
||||
let mut cfp: MaybeUninit<ztcore::ZT_Fingerprint> = MaybeUninit::uninit();
|
||||
let mut cfpp: *mut ztcore::ZT_Fingerprint = null_mut();
|
||||
if controller_fingerprint.is_some() {
|
||||
|
@ -458,12 +457,14 @@ impl<T: NodeEventHandler + 'static> Node<T> {
|
|||
rc
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn multicast_subscribe(&self, nwid: &NetworkId, multicast_group: &MAC, multicast_adi: u32) -> ResultCode {
|
||||
unsafe {
|
||||
return ResultCode::from_i32(ztcore::ZT_Node_multicastSubscribe(self.capi.get(), null_mut(), nwid.0, multicast_group.0, multicast_adi as c_ulong) as i32).unwrap_or(ResultCode::ErrorInternalNonFatal);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn multicast_unsubscribe(&self, nwid: &NetworkId, multicast_group: &MAC, multicast_adi: u32) -> ResultCode {
|
||||
unsafe {
|
||||
return ResultCode::from_i32(ztcore::ZT_Node_multicastUnsubscribe(self.capi.get(), nwid.0, multicast_group.0, multicast_adi as c_ulong) as i32).unwrap_or(ResultCode::ErrorInternalNonFatal);
|
||||
|
@ -471,6 +472,7 @@ impl<T: NodeEventHandler + 'static> Node<T> {
|
|||
}
|
||||
|
||||
/// Get a copy of this node's identity.
|
||||
#[inline(always)]
|
||||
pub fn identity(&self) -> Identity {
|
||||
unsafe { self.identity_fast().clone() }
|
||||
}
|
||||
|
@ -550,11 +552,11 @@ impl<T: NodeEventHandler + 'static> Node<T> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe impl<T: NodeEventHandler + 'static> Sync for Node<T> {}
|
||||
unsafe impl<T: NodeEventHandler<N> + 'static, N: 'static> Sync for Node<T, N> {}
|
||||
|
||||
unsafe impl<T: NodeEventHandler + 'static> Send for Node<T> {}
|
||||
unsafe impl<T: NodeEventHandler<N> + 'static, N: 'static> Send for Node<T, N> {}
|
||||
|
||||
impl<T: NodeEventHandler + 'static> Drop for Node<T> {
|
||||
impl<T: NodeEventHandler<N> + 'static,N: 'static> Drop for Node<T, N> {
|
||||
fn drop(&mut self) {
|
||||
self.background_thread_run.store(false, Ordering::Relaxed);
|
||||
let bt = self.background_thread.replace(None);
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::*;
|
||||
use crate::bindings::capi as ztcore;
|
||||
use crate::Endpoint;
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Path {
|
||||
|
|
|
@ -20,7 +20,7 @@ use crate::bindings::capi as ztcore;
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(FromPrimitive,ToPrimitive, PartialEq, Eq)]
|
||||
#[derive(FromPrimitive,ToPrimitive, PartialEq, Eq, Clone)]
|
||||
pub enum VirtualNetworkType {
|
||||
Private = ztcore::ZT_VirtualNetworkType_ZT_NETWORK_TYPE_PRIVATE as isize,
|
||||
Public = ztcore::ZT_VirtualNetworkType_ZT_NETWORK_TYPE_PUBLIC as isize
|
||||
|
@ -81,7 +81,7 @@ impl<'de> serde::Deserialize<'de> for VirtualNetworkType {
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(FromPrimitive,ToPrimitive, PartialEq, Eq)]
|
||||
#[derive(FromPrimitive,ToPrimitive, PartialEq, Eq, Clone)]
|
||||
pub enum VirtualNetworkRuleType {
|
||||
ActionDrop = ztcore::ZT_VirtualNetworkRuleType_ZT_NETWORK_RULE_ACTION_DROP as isize,
|
||||
ActionAccept = ztcore::ZT_VirtualNetworkRuleType_ZT_NETWORK_RULE_ACTION_ACCEPT as isize,
|
||||
|
@ -122,7 +122,7 @@ pub enum VirtualNetworkRuleType {
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(FromPrimitive,ToPrimitive, PartialEq, Eq)]
|
||||
#[derive(FromPrimitive,ToPrimitive, PartialEq, Eq, Clone)]
|
||||
pub enum VirtualNetworkConfigOperation {
|
||||
Up = ztcore::ZT_VirtualNetworkConfigOperation_ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP as isize,
|
||||
ConfigUpdate = ztcore::ZT_VirtualNetworkConfigOperation_ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE as isize,
|
||||
|
@ -132,7 +132,7 @@ pub enum VirtualNetworkConfigOperation {
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(FromPrimitive,ToPrimitive, PartialEq, Eq)]
|
||||
#[derive(FromPrimitive,ToPrimitive, PartialEq, Eq, Clone)]
|
||||
pub enum VirtualNetworkStatus {
|
||||
RequestingConfiguration = ztcore::ZT_VirtualNetworkStatus_ZT_NETWORK_STATUS_REQUESTING_CONFIGURATION as isize,
|
||||
Ok = ztcore::ZT_VirtualNetworkStatus_ZT_NETWORK_STATUS_OK as isize,
|
||||
|
@ -198,7 +198,7 @@ impl<'de> serde::Deserialize<'de> for VirtualNetworkStatus {
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone)]
|
||||
pub struct VirtualNetworkRoute {
|
||||
pub target: Option<InetAddress>,
|
||||
pub via: Option<InetAddress>,
|
||||
|
@ -208,7 +208,7 @@ pub struct VirtualNetworkRoute {
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq)]
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone)]
|
||||
pub struct VirtualNetworkConfig {
|
||||
pub nwid: NetworkId,
|
||||
pub mac: MAC,
|
||||
|
|
|
@ -1,3 +1,16 @@
|
|||
/*
|
||||
* Copyright (c)2013-2020 ZeroTier, Inc.
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file in the project's root directory.
|
||||
*
|
||||
* Change Date: 2025-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2.0 of the Apache License.
|
||||
*/
|
||||
/****/
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use zerotier_core::{Buffer, InetAddress, InetAddressFamily};
|
||||
|
@ -264,7 +277,7 @@ impl<H: FastUDPSocketPacketHandler + Send + Sync + 'static> Drop for FastUDPSock
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::fastudp::*;
|
||||
use crate::fastudpsocket::*;
|
||||
use zerotier_core::{InetAddress, Buffer};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
|
|
|
@ -1,3 +1,16 @@
|
|||
/*
|
||||
* Copyright (c)2013-2020 ZeroTier, Inc.
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file in the project's root directory.
|
||||
*
|
||||
* Change Date: 2025-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2.0 of the Apache License.
|
||||
*/
|
||||
/****/
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use zerotier_core::{InetAddress, Address, NetworkId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
|
@ -1,3 +1,16 @@
|
|||
/*
|
||||
* Copyright (c)2013-2020 ZeroTier, Inc.
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file in the project's root directory.
|
||||
*
|
||||
* Change Date: 2025-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2.0 of the Apache License.
|
||||
*/
|
||||
/****/
|
||||
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::sync::Mutex;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
|
|
@ -1,10 +1,23 @@
|
|||
/*
|
||||
* Copyright (c)2013-2020 ZeroTier, Inc.
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file in the project's root directory.
|
||||
*
|
||||
* Change Date: 2025-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2.0 of the Apache License.
|
||||
*/
|
||||
/****/
|
||||
|
||||
mod fastudpsocket;
|
||||
mod localconfig;
|
||||
mod physicallink;
|
||||
mod log;
|
||||
mod store;
|
||||
mod network;
|
||||
|
||||
use std::any::Any;
|
||||
use std::cell::Cell;
|
||||
use std::collections::BTreeMap;
|
||||
use std::net::IpAddr;
|
||||
|
@ -16,26 +29,28 @@ use std::time::Duration;
|
|||
|
||||
use warp::Filter;
|
||||
|
||||
use zerotier_core::{Address, Buffer, Event, Identity, InetAddress, InetAddressFamily, MAC, NetworkId, Node, NodeEventHandler, StateObjectType, VirtualNetworkConfig, VirtualNetworkConfigOperation};
|
||||
use zerotier_core::*;
|
||||
|
||||
use crate::fastudpsocket::*;
|
||||
use crate::localconfig::*;
|
||||
use crate::physicallink::PhysicalLink;
|
||||
use crate::log::Log;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
use crate::physicallink::PhysicalLink;
|
||||
use crate::network::Network;
|
||||
|
||||
pub struct ServiceEventHandler {}
|
||||
|
||||
impl FastUDPSocketPacketHandler for ServiceEventHandler {
|
||||
fn incoming_udp_packet(&self, raw_socket: &FastUDPRawOsSocket, from_adddress: &InetAddress, data: Buffer) {}
|
||||
#[inline(always)]
|
||||
fn incoming_udp_packet(&self, raw_socket: &FastUDPRawOsSocket, from_adddress: &InetAddress, data: Buffer) {
|
||||
}
|
||||
}
|
||||
|
||||
impl NodeEventHandler for ServiceEventHandler {
|
||||
fn virtual_network_config(&self, network_id: NetworkId, network_obj: &Arc<dyn Any>, config_op: VirtualNetworkConfigOperation, config: Option<&VirtualNetworkConfig>) {
|
||||
impl NodeEventHandler<Network> for ServiceEventHandler {
|
||||
fn virtual_network_config(&self, network_id: NetworkId, network_obj: &Arc<Network>, config_op: VirtualNetworkConfigOperation, config: Option<&VirtualNetworkConfig>) {
|
||||
}
|
||||
|
||||
fn virtual_network_frame(&self, network_id: NetworkId, network_obj: &Arc<dyn Any>, source_mac: MAC, dest_mac: MAC, ethertype: u16, vlan_id: u16, data: &[u8]) {
|
||||
#[inline(always)]
|
||||
fn virtual_network_frame(&self, network_id: NetworkId, network_obj: &Arc<Network>, source_mac: MAC, dest_mac: MAC, ethertype: u16, vlan_id: u16, data: &[u8]) {
|
||||
}
|
||||
|
||||
fn event(&self, event: Event, event_data: &[u8]) {
|
||||
|
@ -48,6 +63,7 @@ impl NodeEventHandler for ServiceEventHandler {
|
|||
None
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn wire_packet_send(&self, local_socket: i64, sock_addr: &InetAddress, data: &[u8], packet_ttl: u32) -> i32 {
|
||||
0
|
||||
}
|
||||
|
@ -61,8 +77,6 @@ impl NodeEventHandler for ServiceEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
fn main() {
|
||||
tokio::runtime::Builder::new_multi_thread().thread_stack_size(zerotier_core::RECOMMENDED_THREAD_STACK_SIZE).build().unwrap().block_on(async {
|
||||
let inaddr_v6_any = IpAddr::from_str("::0").unwrap();
|
||||
|
|
4
rust-zerotier-service/src/network.rs
Normal file
4
rust-zerotier-service/src/network.rs
Normal file
|
@ -0,0 +1,4 @@
|
|||
pub struct Network {}
|
||||
|
||||
impl Network {
|
||||
}
|
|
@ -1,3 +1,16 @@
|
|||
/*
|
||||
* Copyright (c)2013-2020 ZeroTier, Inc.
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file in the project's root directory.
|
||||
*
|
||||
* Change Date: 2025-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2.0 of the Apache License.
|
||||
*/
|
||||
/****/
|
||||
|
||||
use zerotier_core::InetAddress;
|
||||
use std::ffi::CStr;
|
||||
use std::ptr::{null_mut, copy_nonoverlapping};
|
||||
|
|
|
@ -1,3 +1,16 @@
|
|||
/*
|
||||
* Copyright (c)2013-2020 ZeroTier, Inc.
|
||||
*
|
||||
* Use of this software is governed by the Business Source License included
|
||||
* in the LICENSE.TXT file in the project's root directory.
|
||||
*
|
||||
* Change Date: 2025-01-01
|
||||
*
|
||||
* On the date above, in accordance with the Business Source License, use
|
||||
* of this software will be governed by version 2.0 of the Apache License.
|
||||
*/
|
||||
/****/
|
||||
|
||||
use std::error::Error;
|
||||
use std::path::{Path, PathBuf};
|
||||
use zerotier_core::StateObjectType;
|
||||
|
|
Loading…
Add table
Reference in a new issue