rust stable compatibility using ip_rfc crate

remove mollysocket.db and add it to .gitignore
This commit is contained in:
Drew Nutter 2023-07-29 18:28:36 -03:00 committed by sim
parent 3c917cb6c7
commit 0718d09ae7
6 changed files with 376 additions and 430 deletions

3
.gitignore vendored
View file

@ -1,2 +1,3 @@
/target
/tmp
/tmp
mollysocket.db

792
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -12,6 +12,7 @@ env_logger = "0.10.0"
futures-channel = "0.3"
futures-util = "0.3"
http = "0.2.4"
ip_rfc = "0.1.0"
lazy_static = "1.4.0"
log = "0.4.17"
native-tls = "0.2.10"

View file

@ -1,4 +1,4 @@
FROM docker.io/rustlang/rust:nightly-buster as builder
FROM docker.io/rust:buster as builder
WORKDIR app
COPY . .

View file

@ -1,4 +1,3 @@
#![feature(ip)]
use lazy_static::lazy_static;
use config::Config;

View file

@ -98,8 +98,8 @@ impl ResolveAllowed for Host<&str> {
.resolve_allowed()
.await
}
Host::Ipv4(ip) if ip.is_global() => Ok(vec![IpAddr::V4(ip.clone())]),
Host::Ipv6(ip) if ip.is_global() => Ok(vec![IpAddr::V6(ip.clone())]),
Host::Ipv4(ip) if ip_rfc::global_v4(ip) => Ok(vec![IpAddr::V4(ip.clone())]),
Host::Ipv6(ip) if ip_rfc::global_v6(ip) => Ok(vec![IpAddr::V6(ip.clone())]),
_ => Err(eyre!(Error::HostNotAllowed)),
}
}
@ -108,13 +108,14 @@ impl ResolveAllowed for Host<&str> {
#[async_trait]
impl ResolveAllowed for LookupIp {
async fn resolve_allowed(&self) -> Result<Vec<IpAddr>> {
Ok(self.iter().filter(|ip| ip.is_global()).collect())
Ok(self.iter().filter(|ip| ip_rfc::global(ip)).collect())
}
}
#[cfg(test)]
mod tests {
use super::*;
use std::str::FromStr;
async fn len_from_str(url: &str) -> usize {
Url::from_str(url)