Skip to content

Commit

Permalink
Convert ipv4-mapped ipv6 when accepting peer (#3225)
Browse files Browse the repository at this point in the history
quentinlesceller authored Feb 14, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent b400a4b commit 053415d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions p2p/src/serv.rs
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@

use std::fs::File;
use std::io::{self, Read};
use std::net::{Shutdown, SocketAddr, TcpListener, TcpStream};
use std::net::{IpAddr, Shutdown, SocketAddr, SocketAddrV4, TcpListener, TcpStream};
use std::path::PathBuf;
use std::sync::Arc;
use std::thread;
@@ -92,7 +92,20 @@ impl Server {
// we do not want.
stream.set_nonblocking(false)?;

let peer_addr = PeerAddr(peer_addr);
let mut peer_addr = PeerAddr(peer_addr);

// attempt to see if it an ipv4-mapped ipv6
// if yes convert to ipv4
if peer_addr.0.is_ipv6() {
if let IpAddr::V6(ipv6) = peer_addr.0.ip() {
if let Some(ipv4) = ipv6.to_ipv4() {
peer_addr = PeerAddr(SocketAddr::V4(SocketAddrV4::new(
ipv4,
peer_addr.0.port(),
)))
}
}
}

if self.check_undesirable(&stream) {
// Shutdown the incoming TCP connection if it is not desired

0 comments on commit 053415d

Please sign in to comment.