peer info

This commit is contained in:
asxalex 2024-02-19 23:10:59 +08:00
parent c12d62e4b1
commit 84330922b5
2 changed files with 16 additions and 14 deletions

View File

@ -47,8 +47,8 @@ mod test {
port: 1,
has_v6: true,
v6_port: 2345,
v4: [0; 4],
v6: [1; 16],
v4: vec![0; 4],
v6: vec![1; 16],
}),
dev_addr: peer::IpSubnet::new(192, 24),
pub_key: "public key",

View File

@ -1,7 +1,7 @@
#![allow(unused)]
use std::default::Default;
use std::os::unix::net;
use std::sync::atomic::{AtomicI64, AtomicU32, AtomicU8, Ordering};
use std::sync::atomic::{AtomicU32, AtomicU64, AtomicU8, Ordering};
use std::sync::Mutex;
use serde::{Deserialize, Serialize};
@ -18,11 +18,11 @@ pub struct Peer {
pub timeout: isize,
// 最近一次遇见
pub last_seen: AtomicI64,
pub last_seen: AtomicU64,
// 最近一次p2p消息
pub last_p2p: AtomicI64,
pub last_p2p: AtomicU64,
// 最近一次发送query
pub last_send_query: AtomicI64,
pub last_send_query: AtomicU64,
// 该节点锁属的网络
pub network_id: Mutex<String>,
@ -38,14 +38,14 @@ impl Peer {
port: 0,
has_v6: false,
v6_port: 0,
v4: [0; 4],
v6: [0; 16],
v4: vec![0; 4],
v6: vec![0; 16],
}),
pub_key: Mutex::new(vec![]),
timeout: 0,
last_seen: AtomicI64::new(0),
last_p2p: AtomicI64::new(0),
last_send_query: AtomicI64::new(0),
last_seen: AtomicU64::new(0),
last_p2p: AtomicU64::new(0),
last_send_query: AtomicU64::new(0),
network_id: Mutex::new(String::new()),
}
}
@ -98,12 +98,14 @@ impl IpSubnetAtomic {
}
/// SdlanSock: 对端对外的ip信息包括ipv4和ipv6
#[derive(Debug, Serialize, Deserialize, PartialEq)]
#[derive(Debug, Serialize, Deserialize, PartialEq, sqlx::FromRow)]
pub struct SdlanSock {
pub family: u8,
pub port: u32,
pub has_v6: bool,
pub v6_port: u32,
pub v4: [u8; 4],
pub v6: [u8; 16],
pub v4: Vec<u8>,
pub v6: Vec<u8>,
// pub v4: [u8; 4],
// pub v6: [u8; 16],
}