add public ip inferrence
This commit is contained in:
parent
79835a1e19
commit
e2b564cc48
4 changed files with 17 additions and 4 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
|
|
@ -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(|| {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ pub struct PRUDPSockAddr{
|
|||
|
||||
|
||||
impl PRUDPSockAddr{
|
||||
|
||||
pub fn new(regular_socket_addr: SocketAddrV4, virtual_port: VirtualPort) -> Self{
|
||||
Self{
|
||||
regular_socket_addr,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue