You've already forked AstralRinth
forked from didirus/AstralRinth
Ratelimit acct creation (#2933)
This commit is contained in:
25
apps/labrinth/src/util/ip.rs
Normal file
25
apps/labrinth/src/util/ip.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use std::net::{AddrParseError, IpAddr, Ipv6Addr};
|
||||
|
||||
pub fn convert_to_ip_v6(src: &str) -> Result<Ipv6Addr, AddrParseError> {
|
||||
let ip_addr: IpAddr = src.parse()?;
|
||||
|
||||
Ok(match ip_addr {
|
||||
IpAddr::V4(x) => x.to_ipv6_mapped(),
|
||||
IpAddr::V6(x) => x,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn strip_ip(ip: Ipv6Addr) -> u64 {
|
||||
if let Some(ip) = ip.to_ipv4_mapped() {
|
||||
let octets = ip.octets();
|
||||
u64::from_be_bytes([
|
||||
octets[0], octets[1], octets[2], octets[3], 0, 0, 0, 0,
|
||||
])
|
||||
} else {
|
||||
let octets = ip.octets();
|
||||
u64::from_be_bytes([
|
||||
octets[0], octets[1], octets[2], octets[3], octets[4], octets[5],
|
||||
octets[6], octets[7],
|
||||
])
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ pub mod env;
|
||||
pub mod ext;
|
||||
pub mod guards;
|
||||
pub mod img;
|
||||
pub mod ip;
|
||||
pub mod ratelimit;
|
||||
pub mod redis;
|
||||
pub mod routes;
|
||||
|
||||
Reference in New Issue
Block a user