func (p *peer) OriginalAddr() *NetAddress {
	if p.peerConn.outbound {
		return p.peerConn.originalAddr
	}
	return nil
}
OriginalAddr returns the original address, which was used to connect with
the peer. Returns nil for inbound peers.
package p2p
import (
	"fmt"
	"net"
	"sync/atomic"
	"time"
	crypto "github.com/tendermint/tendermint/crypto"
	cmn "github.com/tendermint/tendermint/libs/common"
	"github.com/tendermint/tendermint/libs/log"
	"github.com/tendermint/tendermint/config"
	tmconn "github.com/tendermint/tendermint/p2p/conn"
)
var testIPSuffix uint32
type Peer interface {
	cmn.Service
	ID() ID              
	RemoteIP() net.IP    
	IsOutbound() bool    
	IsPersistent() bool  
	NodeInfo() NodeInfo  
	Status() tmconn.ConnectionStatus
	OriginalAddr() *NetAddress
	Send(byte, []byte) bool
	TrySend(byte, []byte) bool
	Set(string, interface{})
	Get(string) interface{}
}
type peerConn struct {
	outbound     bool
	persistent   bool
	config       *config.P2PConfig
	conn         net.Conn  
	ip           net.IP
	originalAddr *NetAddress  
}
func (pc peerConn) ID() ID {
	return PubKeyToID(pc.conn.(*tmconn.SecretConnection).RemotePubKey())
}
func (pc peerConn) RemoteIP() net.IP {
	if pc.ip != nil {
		return pc.ip
	}
	if pc.conn == nil || pc.conn.RemoteAddr().String() == "pipe" {
		pc.ip = net.IP{172, 16, 0, byte(atomic.AddUint32(&testIPSuffix, 1))}
		return pc.ip
	}
	host, _, err := net.SplitHostPort(pc.conn.RemoteAddr().String())
	if err != nil {
		panic(err)
	}
	ips, err := net.LookupIP(host)
	if err != nil {
		panic(err)
	}
	pc.ip = ips[0]
	return pc.ip
}
type peer struct {
	cmn.BaseService
	peerConn
	mconn *tmconn.MConnection
	nodeInfo NodeInfo
	channels []byte
	Data *cmn.CMap
}
func newPeer(
	pc peerConn,
	mConfig tmconn.MConnConfig,
	nodeInfo NodeInfo,
	reactorsByCh map[byte]Reactor,
	chDescs []*tmconn.ChannelDescriptor,
	onPeerError func(Peer, interface{}),
) *peer {
	p := &peer{
		peerConn: pc,
		nodeInfo: nodeInfo,
		channels: nodeInfo.Channels,
		Data:     cmn.NewCMap(),
	}
	p.mconn = createMConnection(
		pc.conn,
		p,
		reactorsByCh,
		chDescs,
		onPeerError,
		mConfig,
	)
	p.BaseService = *cmn.NewBaseService(nil, "Peer", p)
	return p
}
func newOutboundPeerConn(
	addr *NetAddress,
	config *config.P2PConfig,
	persistent bool,
	ourNodePrivKey crypto.PrivKey,
) (peerConn, error) {
	conn, err := dial(addr, config)
	if err != nil {
		return peerConn{}, cmn.ErrorWrap(err, "Error creating peer")
	}
	pc, err := newPeerConn(conn, config, true, persistent, ourNodePrivKey, addr)
	if err != nil {
		if cerr := conn.Close(); cerr != nil {
			return peerConn{}, cmn.ErrorWrap(err, cerr.Error())
		}
		return peerConn{}, err
	}
	if addr.ID != pc.ID() {
		if cerr := conn.Close(); cerr != nil {
			return peerConn{}, cmn.ErrorWrap(err, cerr.Error())
		}
		return peerConn{}, ErrSwitchAuthenticationFailure{addr, pc.ID()}
	}
	return pc, nil
}
func newInboundPeerConn(
	conn net.Conn,
	config *config.P2PConfig,
	ourNodePrivKey crypto.PrivKey,
) (peerConn, error) {
	return newPeerConn(conn, config, false, false, ourNodePrivKey, nil)
}
func newPeerConn(
	rawConn net.Conn,
	cfg *config.P2PConfig,
	outbound, persistent bool,
	ourNodePrivKey crypto.PrivKey,
	originalAddr *NetAddress,
) (pc peerConn, err error) {
	conn := rawConn
	if cfg.TestFuzz {
		conn = FuzzConnAfterFromConfig(conn, 10*time.Second, cfg.TestFuzzConfig)
	}
	dl := time.Now().Add(cfg.HandshakeTimeout)
	if err := conn.SetDeadline(dl); err != nil {
		return pc, cmn.ErrorWrap(
			err,
			"Error setting deadline while encrypting connection",
		)
	}
	conn, err = tmconn.MakeSecretConnection(conn, ourNodePrivKey)
	if err != nil {
		return pc, cmn.ErrorWrap(err, "Error creating peer")
	}
	return peerConn{
		config:       cfg,
		outbound:     outbound,
		persistent:   persistent,
		conn:         conn,
		originalAddr: originalAddr,
	}, nil
}
func (p *peer) SetLogger(l log.Logger) {
	p.Logger = l
	p.mconn.SetLogger(l)
}
func (p *peer) OnStart() error {
	if err := p.BaseService.OnStart(); err != nil {
		return err
	}
	err := p.mconn.Start()
	return err
}
func (p *peer) OnStop() {
	p.BaseService.OnStop()
	p.mconn.Stop()  
}
func (p *peer) ID() ID {
	return p.nodeInfo.ID
}
func (p *peer) IsOutbound() bool {
	return p.peerConn.outbound
}
func (p *peer) IsPersistent() bool {
	return p.peerConn.persistent
}
func (p *peer) NodeInfo() NodeInfo {
	return p.nodeInfo
}