don't trust peer's node info

This commit is contained in:
Ethan Buchman 2015-06-17 17:55:16 -04:00
parent ad70ce4067
commit 33566375af
1 changed files with 11 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net"
"strconv"
"sync/atomic"
"time"
@ -165,6 +166,16 @@ func (sw *Switch) AddPeerWithConnection(conn net.Conn, outbound bool) (*Peer, er
return nil, err
}
// the peerNodeInfo is not verified,
// so we overwrite the IP with that from the conn
// and if we dialed out, the port too
// everything else we just have to trust
ip, port, _ := net.SplitHostPort(conn.RemoteAddr().String())
peerNodeInfo.Host = ip
if outbound {
porti, _ := strconv.Atoi(port)
peerNodeInfo.P2PPort = uint16(porti)
}
peer := newPeer(conn, peerNodeInfo, outbound, sw.reactorsByCh, sw.chDescs, sw.StopPeerForError)
// Add the peer to .peers