Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert ipv4-mapped ipv6 when accepting peer #3225

Merged
merged 1 commit into from
Feb 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions p2p/src/serv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down