more ip resolution services
All checks were successful
Build and Test / mario-tennis (push) Successful in 2m2s
Build and Test / minecraft-wiiu (push) Successful in 2m29s
Build and Test / fast-racing-neo (push) Successful in 2m48s
Build and Test / wii-u-chat (push) Successful in 3m17s
Build and Test / friends (push) Successful in 3m44s
Build and Test / super-mario-maker (push) Successful in 4m57s
Build and Test / puyopuyo (push) Successful in 5m12s
Build and Test / splatoon-testfire (push) Successful in 5m53s
Build and Test / wii-sports-club (push) Successful in 6m14s
Build and Test / sonic-transformed (push) Successful in 6m40s
Build and Test / splatoon (push) Successful in 7m16s

This commit is contained in:
Maple Nebel 2026-05-29 09:00:10 +02:00
commit 0ec7328396
3 changed files with 31 additions and 9 deletions

View file

@ -40,9 +40,9 @@ pub enum Error {
#[error("error parsing ip address environment variable \"{0}\": {1}")]
AddrParse(&'static str, AddrParseError),
#[error(
"error error getting public ip address: \n\tattempted to read from env var \"SERVER_IP_PUBLIC\" and got: {0} \n\tattempted to request from internet and failed with: {1}"
"error error getting public ip address: \n\tattempted to read from env var \"SERVER_IP_PUBLIC\" and got: {0}\n\tfor other attempts check logs"
)]
PubAddrGetErr(Box<Self>, Box<dyn error::Error>),
PubAddrGetErr(Box<Self>),
}
impl Into<Error> for (&'static str, AddrParseError) {
fn into(self) -> Error {
@ -88,7 +88,7 @@ impl ProxyStartupParam {
Ok(v) => v,
Err(e) => try_get_ip()
.map(|v| SocketAddrV4::new(v, self_private.port()))
.map_err(move |v| Error::PubAddrGetErr(Box::new(e), v))?,
.ok_or(Error::PubAddrGetErr(Box::new(e)))?,
};
Ok(Self {

View file

@ -4,6 +4,7 @@ use rnex_core::rmc::protocols::{RmcCallable, RmcConnection, new_rmc_gateway_conn
use rnex_core::rmc::structures::RmcSerialize;
use rnex_core::rnex_proxy_common::ConnectionInitData;
use std::env;
use std::fmt::Display;
use std::io::Cursor;
use std::net::{Ipv4Addr, SocketAddrV4};
use std::sync::Arc;
@ -18,7 +19,12 @@ use cfg_if::cfg_if;
use log::error;
use std::error::Error;
const IP_REQ_SERVICE_URL: &str = "https://ipinfo.io/ip";
const IP_REQ_SERVICE_URLS: &[&str] = &[
"https://ipinfo.io/ip",
"https://api.ipify.org",
"http://ipinfo.io/ip",
"http://api.ipify.org",
];
cfg_if! {
if #[cfg(feature = "datastore")] {
@ -44,10 +50,26 @@ cfg_if! {
}
}
pub fn try_get_ip() -> Result<Ipv4Addr, Box<dyn Error>> {
let mut req = ureq::get(IP_REQ_SERVICE_URL).call()?;
pub fn try_to_log<R, E: Display>(fun: impl FnOnce() -> Result<R, E>) -> Option<R> {
match fun() {
Ok(v) => Some(v),
Err(e) => {
error!("{}", e);
None
}
}
}
Ok(req.body_mut().read_to_string()?.parse()?)
pub fn try_get_ip() -> Option<Ipv4Addr> {
for url in IP_REQ_SERVICE_URLS {
if let Some(v) = try_to_log::<_, Box<dyn Error>>(|| {
let mut req = ureq::get(*url).call()?;
Ok(req.body_mut().read_to_string()?.parse()?)
}) {
return Some(v);
}
}
None
}
pub static OWN_IP_PRIVATE: Lazy<Ipv4Addr> = Lazy::new(|| {
@ -120,7 +142,7 @@ mod test {
use crate::executables::common::try_get_ip;
#[test]
fn test() {
fn get_ip() {
try_get_ip().unwrap();
}
}

View file

@ -14,7 +14,7 @@ echo ENV SETTINGS:
env
if [[ ! -v RNEX_STATIC ]]; then
cargo test --features "$EDITION_FEATURES"
cargo test --features "$EDITION_FEATURES" --no-run --verbose
else
OPENSSL_LIB_DIR=/usr/lib OPENSSL_INCLUDE_DIR=/usr/include/openssl OPENSSL_STATIC=1 RUSTFLAGS="-C relocation-model=static -C linker=ld.lld" cargo test --features "$EDITION_FEATURES" --target x86_64-unknown-linux-musl
fi