Browse Source

don't trust peer's node info

pull/92/head
Ethan Buchman 10 years ago
parent
commit
33566375af
1 changed files with 11 additions and 0 deletions
  1. +11
    -0
      p2p/switch.go

+ 11
- 0
p2p/switch.go View File

@ -4,6 +4,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"net" "net"
"strconv"
"sync/atomic" "sync/atomic"
"time" "time"
@ -165,6 +166,16 @@ func (sw *Switch) AddPeerWithConnection(conn net.Conn, outbound bool) (*Peer, er
return nil, err 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) peer := newPeer(conn, peerNodeInfo, outbound, sw.reactorsByCh, sw.chDescs, sw.StopPeerForError)
// Add the peer to .peers // Add the peer to .peers


Loading…
Cancel
Save