Skip to content

Commit

Permalink
don't trust peer's node info
Browse files Browse the repository at this point in the history
  • Loading branch information
ebuchman committed Jun 17, 2015
1 parent ad70ce4 commit 3356637
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions p2p/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net"
"strconv"
"sync/atomic"
"time"

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3356637

Please sign in to comment.