V0 #2

Closed
RusticMaple wants to merge 58 commits from v0 into main
4 changed files with 17 additions and 4 deletions
Showing only changes of commit e2b564cc48 - Show all commits

add public ip inferrence

Maple Nebel 2025-11-06 22:55:41 +00:00

2
Cargo.lock generated
View file

@ -1663,7 +1663,9 @@ dependencies = [
"base64",
"bytes",
"encoding_rs",
"futures-channel",
"futures-core",
"futures-util",
"h2 0.4.11",
"http 1.3.1",
"http-body 1.0.1",

View file

@ -26,7 +26,7 @@ rocket = { version = "0.5.1", features = ["json", "serde_json"] }
async-trait = "0.1.86"
paste = "1.0.15"
typenum = "1.18.0"
reqwest = "0.12.18"
reqwest = { version= "0.12.18", features = ["blocking"]}
json = "0.12.4"
ctrlc = "3.4.7"

View file

@ -2,6 +2,16 @@ use std::env;
use std::net::Ipv4Addr;
use once_cell::sync::Lazy;
use crate::nex::account::Account;
use std::error::Error;
const IP_REQ_SERVICE_URL: &str = "https://ipinfo.io/ip";
fn try_get_ip() -> Result<Ipv4Addr, Box<dyn Error>> {
let req = reqwest::blocking::get(IP_REQ_SERVICE_URL)?;
Ok(req.text()?.parse()?)
}
pub static OWN_IP_PRIVATE: Lazy<Ipv4Addr> = Lazy::new(|| {
env::var("SERVER_IP")
@ -13,8 +23,10 @@ pub static OWN_IP_PRIVATE: Lazy<Ipv4Addr> = Lazy::new(|| {
pub static OWN_IP_PUBLIC: Lazy<Ipv4Addr> = Lazy::new(|| {
env::var("SERVER_IP_PUBLIC")
.ok()
.and_then(|s| s.parse().ok())
.expect("SERVER_IP_PUBLIC not specified")
.map(|s| s.parse().expect("invalid ip address"))
.unwrap_or_else(||{
try_get_ip().unwrap()
})
});
pub static SERVER_PORT: Lazy<u16> = Lazy::new(|| {

View file

@ -17,7 +17,6 @@ pub struct PRUDPSockAddr{
impl PRUDPSockAddr{
pub fn new(regular_socket_addr: SocketAddrV4, virtual_port: VirtualPort) -> Self{
Self{
regular_socket_addr,