Browse Source

types: move NodeInfo from p2p (#6618)

pull/6609/head
Sam Kleinman 3 years ago
committed by GitHub
parent
commit
9ffa7e8a2b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
28 changed files with 219 additions and 177 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +2
    -2
      internal/blockchain/v2/reactor_test.go
  3. +2
    -2
      internal/p2p/mock/peer.go
  4. +8
    -6
      internal/p2p/mocks/connection.go
  5. +9
    -10
      internal/p2p/mocks/peer.go
  6. +2
    -2
      internal/p2p/p2p_test.go
  7. +2
    -2
      internal/p2p/p2ptest/network.go
  8. +4
    -4
      internal/p2p/peer.go
  9. +1
    -1
      internal/p2p/peer_set_test.go
  10. +2
    -2
      internal/p2p/peer_test.go
  11. +3
    -3
      internal/p2p/router.go
  12. +6
    -5
      internal/p2p/router_init_test.go
  13. +6
    -6
      internal/p2p/router_test.go
  14. +10
    -7
      internal/p2p/switch.go
  15. +5
    -5
      internal/p2p/test_util.go
  16. +10
    -1
      internal/p2p/transport.go
  17. +15
    -14
      internal/p2p/transport_mconn.go
  18. +8
    -8
      internal/p2p/transport_memory.go
  19. +18
    -14
      internal/p2p/transport_test.go
  20. +2
    -2
      node/node.go
  21. +19
    -19
      node/setup.go
  22. +7
    -6
      proto/tendermint/p2p/types.pb.go
  23. +1
    -1
      rpc/core/env.go
  24. +4
    -4
      rpc/core/types/responses.go
  25. +7
    -8
      rpc/core/types/responses_test.go
  26. +7
    -7
      test/fuzz/p2p/pex/reactor_receive.go
  27. +7
    -26
      types/node_info.go
  28. +51
    -10
      types/node_info_test.go

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -32,6 +32,7 @@ Friendly reminder: We have a [bug bounty program](https://hackerone.com/tendermi
- P2P Protocol - P2P Protocol
- Go API - Go API
- [p2p] \#6618 Move `p2p.NodeInfo` into `types` to support use of the SDK. (@tychoish)
- [p2p] \#6583 Make `p2p.NodeID` and `p2p.NetAddress` exported types to support their use in the RPC layer. (@tychoish) - [p2p] \#6583 Make `p2p.NodeID` and `p2p.NetAddress` exported types to support their use in the RPC layer. (@tychoish)
- [node] \#6540 Reduce surface area of the `node` package by making most of the implementation details private. (@tychoish) - [node] \#6540 Reduce surface area of the `node` package by making most of the implementation details private. (@tychoish)
- [p2p] \#6547 Move the entire `p2p` package and all reactor implementations into `internal`. (@tychoish) - [p2p] \#6547 Move the entire `p2p` package and all reactor implementations into `internal`. (@tychoish)


+ 2
- 2
internal/blockchain/v2/reactor_test.go View File

@ -45,8 +45,8 @@ func (mp mockPeer) IsOutbound() bool { return true }
func (mp mockPeer) IsPersistent() bool { return true } func (mp mockPeer) IsPersistent() bool { return true }
func (mp mockPeer) CloseConn() error { return nil } func (mp mockPeer) CloseConn() error { return nil }
func (mp mockPeer) NodeInfo() p2p.NodeInfo {
return p2p.NodeInfo{
func (mp mockPeer) NodeInfo() types.NodeInfo {
return types.NodeInfo{
NodeID: "", NodeID: "",
ListenAddr: "", ListenAddr: "",
} }


+ 2
- 2
internal/p2p/mock/peer.go View File

@ -45,8 +45,8 @@ func NewPeer(ip net.IP) *Peer {
func (mp *Peer) FlushStop() { mp.Stop() } //nolint:errcheck //ignore error func (mp *Peer) FlushStop() { mp.Stop() } //nolint:errcheck //ignore error
func (mp *Peer) TrySend(chID byte, msgBytes []byte) bool { return true } func (mp *Peer) TrySend(chID byte, msgBytes []byte) bool { return true }
func (mp *Peer) Send(chID byte, msgBytes []byte) bool { return true } func (mp *Peer) Send(chID byte, msgBytes []byte) bool { return true }
func (mp *Peer) NodeInfo() p2p.NodeInfo {
return p2p.NodeInfo{
func (mp *Peer) NodeInfo() types.NodeInfo {
return types.NodeInfo{
NodeID: mp.addr.ID, NodeID: mp.addr.ID,
ListenAddr: mp.addr.DialString(), ListenAddr: mp.addr.DialString(),
} }


+ 8
- 6
internal/p2p/mocks/connection.go View File

@ -12,6 +12,8 @@ import (
mock "github.com/stretchr/testify/mock" mock "github.com/stretchr/testify/mock"
p2p "github.com/tendermint/tendermint/internal/p2p" p2p "github.com/tendermint/tendermint/internal/p2p"
types "github.com/tendermint/tendermint/types"
) )
// Connection is an autogenerated mock type for the Connection type // Connection is an autogenerated mock type for the Connection type
@ -48,18 +50,18 @@ func (_m *Connection) FlushClose() error {
} }
// Handshake provides a mock function with given fields: _a0, _a1, _a2 // Handshake provides a mock function with given fields: _a0, _a1, _a2
func (_m *Connection) Handshake(_a0 context.Context, _a1 p2p.NodeInfo, _a2 crypto.PrivKey) (p2p.NodeInfo, crypto.PubKey, error) {
func (_m *Connection) Handshake(_a0 context.Context, _a1 types.NodeInfo, _a2 crypto.PrivKey) (types.NodeInfo, crypto.PubKey, error) {
ret := _m.Called(_a0, _a1, _a2) ret := _m.Called(_a0, _a1, _a2)
var r0 p2p.NodeInfo
if rf, ok := ret.Get(0).(func(context.Context, p2p.NodeInfo, crypto.PrivKey) p2p.NodeInfo); ok {
var r0 types.NodeInfo
if rf, ok := ret.Get(0).(func(context.Context, types.NodeInfo, crypto.PrivKey) types.NodeInfo); ok {
r0 = rf(_a0, _a1, _a2) r0 = rf(_a0, _a1, _a2)
} else { } else {
r0 = ret.Get(0).(p2p.NodeInfo)
r0 = ret.Get(0).(types.NodeInfo)
} }
var r1 crypto.PubKey var r1 crypto.PubKey
if rf, ok := ret.Get(1).(func(context.Context, p2p.NodeInfo, crypto.PrivKey) crypto.PubKey); ok {
if rf, ok := ret.Get(1).(func(context.Context, types.NodeInfo, crypto.PrivKey) crypto.PubKey); ok {
r1 = rf(_a0, _a1, _a2) r1 = rf(_a0, _a1, _a2)
} else { } else {
if ret.Get(1) != nil { if ret.Get(1) != nil {
@ -68,7 +70,7 @@ func (_m *Connection) Handshake(_a0 context.Context, _a1 p2p.NodeInfo, _a2 crypt
} }
var r2 error var r2 error
if rf, ok := ret.Get(2).(func(context.Context, p2p.NodeInfo, crypto.PrivKey) error); ok {
if rf, ok := ret.Get(2).(func(context.Context, types.NodeInfo, crypto.PrivKey) error); ok {
r2 = rf(_a0, _a1, _a2) r2 = rf(_a0, _a1, _a2)
} else { } else {
r2 = ret.Error(2) r2 = ret.Error(2)


+ 9
- 10
internal/p2p/mocks/peer.go View File

@ -5,13 +5,12 @@ package mocks
import ( import (
conn "github.com/tendermint/tendermint/internal/p2p/conn" conn "github.com/tendermint/tendermint/internal/p2p/conn"
log "github.com/tendermint/tendermint/libs/log" log "github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/types"
mock "github.com/stretchr/testify/mock" mock "github.com/stretchr/testify/mock"
net "net" net "net"
p2p "github.com/tendermint/tendermint/internal/p2p"
types "github.com/tendermint/tendermint/types"
) )
// Peer is an autogenerated mock type for the Peer type // Peer is an autogenerated mock type for the Peer type
@ -111,14 +110,14 @@ func (_m *Peer) IsRunning() bool {
} }
// NodeInfo provides a mock function with given fields: // NodeInfo provides a mock function with given fields:
func (_m *Peer) NodeInfo() p2p.NodeInfo {
func (_m *Peer) NodeInfo() types.NodeInfo {
ret := _m.Called() ret := _m.Called()
var r0 p2p.NodeInfo
if rf, ok := ret.Get(0).(func() p2p.NodeInfo); ok {
var r0 types.NodeInfo
if rf, ok := ret.Get(0).(func() types.NodeInfo); ok {
r0 = rf() r0 = rf()
} else { } else {
r0 = ret.Get(0).(p2p.NodeInfo)
r0 = ret.Get(0).(types.NodeInfo)
} }
return r0 return r0
@ -244,15 +243,15 @@ func (_m *Peer) SetLogger(_a0 log.Logger) {
} }
// SocketAddr provides a mock function with given fields: // SocketAddr provides a mock function with given fields:
func (_m *Peer) SocketAddr() *p2p.NetAddress {
func (_m *Peer) SocketAddr() *types.NetAddress {
ret := _m.Called() ret := _m.Called()
var r0 *p2p.NetAddress
if rf, ok := ret.Get(0).(func() *p2p.NetAddress); ok {
var r0 *types.NetAddress
if rf, ok := ret.Get(0).(func() *types.NetAddress); ok {
r0 = rf() r0 = rf()
} else { } else {
if ret.Get(0) != nil { if ret.Get(0) != nil {
r0 = ret.Get(0).(*p2p.NetAddress)
r0 = ret.Get(0).(*types.NetAddress)
} }
} }


+ 2
- 2
internal/p2p/p2p_test.go View File

@ -24,7 +24,7 @@ var (
selfKey crypto.PrivKey = ed25519.GenPrivKeyFromSecret([]byte{0xf9, 0x1b, 0x08, 0xaa, 0x38, 0xee, 0x34, 0xdd}) selfKey crypto.PrivKey = ed25519.GenPrivKeyFromSecret([]byte{0xf9, 0x1b, 0x08, 0xaa, 0x38, 0xee, 0x34, 0xdd})
selfID = types.NodeIDFromPubKey(selfKey.PubKey()) selfID = types.NodeIDFromPubKey(selfKey.PubKey())
selfInfo = p2p.NodeInfo{
selfInfo = types.NodeInfo{
NodeID: selfID, NodeID: selfID,
ListenAddr: "0.0.0.0:0", ListenAddr: "0.0.0.0:0",
Network: "test", Network: "test",
@ -33,7 +33,7 @@ var (
peerKey crypto.PrivKey = ed25519.GenPrivKeyFromSecret([]byte{0x84, 0xd7, 0x01, 0xbf, 0x83, 0x20, 0x1c, 0xfe}) peerKey crypto.PrivKey = ed25519.GenPrivKeyFromSecret([]byte{0x84, 0xd7, 0x01, 0xbf, 0x83, 0x20, 0x1c, 0xfe})
peerID = types.NodeIDFromPubKey(peerKey.PubKey()) peerID = types.NodeIDFromPubKey(peerKey.PubKey())
peerInfo = p2p.NodeInfo{
peerInfo = types.NodeInfo{
NodeID: peerID, NodeID: peerID,
ListenAddr: "0.0.0.0:0", ListenAddr: "0.0.0.0:0",
Network: "test", Network: "test",


+ 2
- 2
internal/p2p/p2ptest/network.go View File

@ -215,7 +215,7 @@ func (n *Network) Remove(t *testing.T, id types.NodeID) {
// Node is a node in a Network, with a Router and a PeerManager. // Node is a node in a Network, with a Router and a PeerManager.
type Node struct { type Node struct {
NodeID types.NodeID NodeID types.NodeID
NodeInfo p2p.NodeInfo
NodeInfo types.NodeInfo
NodeAddress p2p.NodeAddress NodeAddress p2p.NodeAddress
PrivKey crypto.PrivKey PrivKey crypto.PrivKey
Router *p2p.Router Router *p2p.Router
@ -229,7 +229,7 @@ type Node struct {
func (n *Network) MakeNode(t *testing.T, opts NodeOptions) *Node { func (n *Network) MakeNode(t *testing.T, opts NodeOptions) *Node {
privKey := ed25519.GenPrivKey() privKey := ed25519.GenPrivKey()
nodeID := types.NodeIDFromPubKey(privKey.PubKey()) nodeID := types.NodeIDFromPubKey(privKey.PubKey())
nodeInfo := p2p.NodeInfo{
nodeInfo := types.NodeInfo{
NodeID: nodeID, NodeID: nodeID,
ListenAddr: "0.0.0.0:0", // FIXME: We have to fake this for now. ListenAddr: "0.0.0.0:0", // FIXME: We have to fake this for now.
Moniker: string(nodeID), Moniker: string(nodeID),


+ 4
- 4
internal/p2p/peer.go View File

@ -32,7 +32,7 @@ type Peer interface {
CloseConn() error // close original connection CloseConn() error // close original connection
NodeInfo() NodeInfo // peer's info
NodeInfo() types.NodeInfo // peer's info
Status() tmconn.ConnectionStatus Status() tmconn.ConnectionStatus
SocketAddr() *NetAddress // actual address of the socket SocketAddr() *NetAddress // actual address of the socket
@ -81,7 +81,7 @@ type peer struct {
// peer's node info and the channel it knows about // peer's node info and the channel it knows about
// channels = nodeInfo.Channels // channels = nodeInfo.Channels
// cached to avoid copying nodeInfo in hasChannel // cached to avoid copying nodeInfo in hasChannel
nodeInfo NodeInfo
nodeInfo types.NodeInfo
channels []byte channels []byte
reactors map[byte]Reactor reactors map[byte]Reactor
onPeerError func(Peer, interface{}) onPeerError func(Peer, interface{})
@ -96,7 +96,7 @@ type peer struct {
type PeerOption func(*peer) type PeerOption func(*peer)
func newPeer( func newPeer(
nodeInfo NodeInfo,
nodeInfo types.NodeInfo,
pc peerConn, pc peerConn,
reactorsByCh map[byte]Reactor, reactorsByCh map[byte]Reactor,
onPeerError func(Peer, interface{}), onPeerError func(Peer, interface{}),
@ -218,7 +218,7 @@ func (p *peer) IsPersistent() bool {
} }
// NodeInfo returns a copy of the peer's NodeInfo. // NodeInfo returns a copy of the peer's NodeInfo.
func (p *peer) NodeInfo() NodeInfo {
func (p *peer) NodeInfo() types.NodeInfo {
return p.nodeInfo return p.nodeInfo
} }


+ 1
- 1
internal/p2p/peer_set_test.go View File

@ -21,7 +21,7 @@ type mockPeer struct {
func (mp *mockPeer) FlushStop() { mp.Stop() } //nolint:errcheck // ignore error func (mp *mockPeer) FlushStop() { mp.Stop() } //nolint:errcheck // ignore error
func (mp *mockPeer) TrySend(chID byte, msgBytes []byte) bool { return true } func (mp *mockPeer) TrySend(chID byte, msgBytes []byte) bool { return true }
func (mp *mockPeer) Send(chID byte, msgBytes []byte) bool { return true } func (mp *mockPeer) Send(chID byte, msgBytes []byte) bool { return true }
func (mp *mockPeer) NodeInfo() NodeInfo { return NodeInfo{} }
func (mp *mockPeer) NodeInfo() types.NodeInfo { return types.NodeInfo{} }
func (mp *mockPeer) Status() ConnectionStatus { return ConnectionStatus{} } func (mp *mockPeer) Status() ConnectionStatus { return ConnectionStatus{} }
func (mp *mockPeer) ID() types.NodeID { return mp.id } func (mp *mockPeer) ID() types.NodeID { return mp.id }
func (mp *mockPeer) IsOutbound() bool { return false } func (mp *mockPeer) IsOutbound() bool { return false }


+ 2
- 2
internal/p2p/peer_test.go View File

@ -221,8 +221,8 @@ func (rp *remotePeer) accept() {
} }
} }
func (rp *remotePeer) nodeInfo() NodeInfo {
return NodeInfo{
func (rp *remotePeer) nodeInfo() types.NodeInfo {
return types.NodeInfo{
ProtocolVersion: defaultProtocolVersion, ProtocolVersion: defaultProtocolVersion,
NodeID: rp.Addr().ID, NodeID: rp.Addr().ID,
ListenAddr: rp.listener.Addr().String(), ListenAddr: rp.listener.Addr().String(),


+ 3
- 3
internal/p2p/router.go View File

@ -248,7 +248,7 @@ type Router struct {
logger log.Logger logger log.Logger
metrics *Metrics metrics *Metrics
options RouterOptions options RouterOptions
nodeInfo NodeInfo
nodeInfo types.NodeInfo
privKey crypto.PrivKey privKey crypto.PrivKey
peerManager *PeerManager peerManager *PeerManager
chDescs []ChannelDescriptor chDescs []ChannelDescriptor
@ -275,7 +275,7 @@ type Router struct {
func NewRouter( func NewRouter(
logger log.Logger, logger log.Logger,
metrics *Metrics, metrics *Metrics,
nodeInfo NodeInfo,
nodeInfo types.NodeInfo,
privKey crypto.PrivKey, privKey crypto.PrivKey,
peerManager *PeerManager, peerManager *PeerManager,
transports []Transport, transports []Transport,
@ -787,7 +787,7 @@ func (r *Router) handshakePeer(
ctx context.Context, ctx context.Context,
conn Connection, conn Connection,
expectID types.NodeID, expectID types.NodeID,
) (NodeInfo, crypto.PubKey, error) {
) (types.NodeInfo, crypto.PubKey, error) {
if r.options.HandshakeTimeout > 0 { if r.options.HandshakeTimeout > 0 {
var cancel context.CancelFunc var cancel context.CancelFunc


+ 6
- 5
internal/p2p/router_init_test.go View File

@ -6,6 +6,7 @@ import (
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/types"
) )
func TestRouter_ConstructQueueFactory(t *testing.T) { func TestRouter_ConstructQueueFactory(t *testing.T) {
@ -17,21 +18,21 @@ func TestRouter_ConstructQueueFactory(t *testing.T) {
t.Run("Default", func(t *testing.T) { t.Run("Default", func(t *testing.T) {
require.Zero(t, os.Getenv("TM_P2P_QUEUE")) require.Zero(t, os.Getenv("TM_P2P_QUEUE"))
opts := RouterOptions{} opts := RouterOptions{}
r, err := NewRouter(log.NewNopLogger(), nil, NodeInfo{}, nil, nil, nil, opts)
r, err := NewRouter(log.NewNopLogger(), nil, types.NodeInfo{}, nil, nil, nil, opts)
require.NoError(t, err) require.NoError(t, err)
_, ok := r.queueFactory(1).(*fifoQueue) _, ok := r.queueFactory(1).(*fifoQueue)
require.True(t, ok) require.True(t, ok)
}) })
t.Run("Fifo", func(t *testing.T) { t.Run("Fifo", func(t *testing.T) {
opts := RouterOptions{QueueType: queueTypeFifo} opts := RouterOptions{QueueType: queueTypeFifo}
r, err := NewRouter(log.NewNopLogger(), nil, NodeInfo{}, nil, nil, nil, opts)
r, err := NewRouter(log.NewNopLogger(), nil, types.NodeInfo{}, nil, nil, nil, opts)
require.NoError(t, err) require.NoError(t, err)
_, ok := r.queueFactory(1).(*fifoQueue) _, ok := r.queueFactory(1).(*fifoQueue)
require.True(t, ok) require.True(t, ok)
}) })
t.Run("Priority", func(t *testing.T) { t.Run("Priority", func(t *testing.T) {
opts := RouterOptions{QueueType: queueTypePriority} opts := RouterOptions{QueueType: queueTypePriority}
r, err := NewRouter(log.NewNopLogger(), nil, NodeInfo{}, nil, nil, nil, opts)
r, err := NewRouter(log.NewNopLogger(), nil, types.NodeInfo{}, nil, nil, nil, opts)
require.NoError(t, err) require.NoError(t, err)
q, ok := r.queueFactory(1).(*pqScheduler) q, ok := r.queueFactory(1).(*pqScheduler)
require.True(t, ok) require.True(t, ok)
@ -39,7 +40,7 @@ func TestRouter_ConstructQueueFactory(t *testing.T) {
}) })
t.Run("WDRR", func(t *testing.T) { t.Run("WDRR", func(t *testing.T) {
opts := RouterOptions{QueueType: queueTypeWDRR} opts := RouterOptions{QueueType: queueTypeWDRR}
r, err := NewRouter(log.NewNopLogger(), nil, NodeInfo{}, nil, nil, nil, opts)
r, err := NewRouter(log.NewNopLogger(), nil, types.NodeInfo{}, nil, nil, nil, opts)
require.NoError(t, err) require.NoError(t, err)
q, ok := r.queueFactory(1).(*wdrrScheduler) q, ok := r.queueFactory(1).(*wdrrScheduler)
require.True(t, ok) require.True(t, ok)
@ -47,7 +48,7 @@ func TestRouter_ConstructQueueFactory(t *testing.T) {
}) })
t.Run("NonExistant", func(t *testing.T) { t.Run("NonExistant", func(t *testing.T) {
opts := RouterOptions{QueueType: "fast"} opts := RouterOptions{QueueType: "fast"}
_, err := NewRouter(log.NewNopLogger(), nil, NodeInfo{}, nil, nil, nil, opts)
_, err := NewRouter(log.NewNopLogger(), nil, types.NodeInfo{}, nil, nil, nil, opts)
require.Error(t, err) require.Error(t, err)
require.Contains(t, err.Error(), "fast") require.Contains(t, err.Error(), "fast")
}) })


+ 6
- 6
internal/p2p/router_test.go View File

@ -319,12 +319,12 @@ func TestRouter_Channel_Error(t *testing.T) {
func TestRouter_AcceptPeers(t *testing.T) { func TestRouter_AcceptPeers(t *testing.T) {
testcases := map[string]struct { testcases := map[string]struct {
peerInfo p2p.NodeInfo
peerInfo types.NodeInfo
peerKey crypto.PubKey peerKey crypto.PubKey
ok bool ok bool
}{ }{
"valid handshake": {peerInfo, peerKey.PubKey(), true}, "valid handshake": {peerInfo, peerKey.PubKey(), true},
"empty handshake": {p2p.NodeInfo{}, nil, false},
"empty handshake": {types.NodeInfo{}, nil, false},
"invalid key": {peerInfo, selfKey.PubKey(), false}, "invalid key": {peerInfo, selfKey.PubKey(), false},
"self handshake": {selfInfo, selfKey.PubKey(), false}, "self handshake": {selfInfo, selfKey.PubKey(), false},
} }
@ -478,7 +478,7 @@ func TestRouter_AcceptPeers_HeadOfLineBlocking(t *testing.T) {
mockConnection := &mocks.Connection{} mockConnection := &mocks.Connection{}
mockConnection.On("String").Maybe().Return("mock") mockConnection.On("String").Maybe().Return("mock")
mockConnection.On("Handshake", mock.Anything, selfInfo, selfKey). mockConnection.On("Handshake", mock.Anything, selfInfo, selfKey).
WaitUntil(closeCh).Return(p2p.NodeInfo{}, nil, io.EOF)
WaitUntil(closeCh).Return(types.NodeInfo{}, nil, io.EOF)
mockConnection.On("Close").Return(nil) mockConnection.On("Close").Return(nil)
mockConnection.On("RemoteEndpoint").Return(p2p.Endpoint{}) mockConnection.On("RemoteEndpoint").Return(p2p.Endpoint{})
@ -522,13 +522,13 @@ func TestRouter_AcceptPeers_HeadOfLineBlocking(t *testing.T) {
func TestRouter_DialPeers(t *testing.T) { func TestRouter_DialPeers(t *testing.T) {
testcases := map[string]struct { testcases := map[string]struct {
dialID types.NodeID dialID types.NodeID
peerInfo p2p.NodeInfo
peerInfo types.NodeInfo
peerKey crypto.PubKey peerKey crypto.PubKey
dialErr error dialErr error
ok bool ok bool
}{ }{
"valid dial": {peerInfo.NodeID, peerInfo, peerKey.PubKey(), nil, true}, "valid dial": {peerInfo.NodeID, peerInfo, peerKey.PubKey(), nil, true},
"empty handshake": {peerInfo.NodeID, p2p.NodeInfo{}, nil, nil, false},
"empty handshake": {peerInfo.NodeID, types.NodeInfo{}, nil, nil, false},
"invalid key": {peerInfo.NodeID, peerInfo, selfKey.PubKey(), nil, false}, "invalid key": {peerInfo.NodeID, peerInfo, selfKey.PubKey(), nil, false},
"unexpected node ID": {peerInfo.NodeID, selfInfo, selfKey.PubKey(), nil, false}, "unexpected node ID": {peerInfo.NodeID, selfInfo, selfKey.PubKey(), nil, false},
"dial error": {peerInfo.NodeID, peerInfo, peerKey.PubKey(), errors.New("boom"), false}, "dial error": {peerInfo.NodeID, peerInfo, peerKey.PubKey(), errors.New("boom"), false},
@ -634,7 +634,7 @@ func TestRouter_DialPeers_Parallel(t *testing.T) {
mockConnection := &mocks.Connection{} mockConnection := &mocks.Connection{}
mockConnection.On("String").Maybe().Return("mock") mockConnection.On("String").Maybe().Return("mock")
mockConnection.On("Handshake", mock.Anything, selfInfo, selfKey). mockConnection.On("Handshake", mock.Anything, selfInfo, selfKey).
WaitUntil(closeCh).Return(p2p.NodeInfo{}, nil, io.EOF)
WaitUntil(closeCh).Return(types.NodeInfo{}, nil, io.EOF)
mockConnection.On("Close").Return(nil) mockConnection.On("Close").Return(nil)
mockTransport := &mocks.Transport{} mockTransport := &mocks.Transport{}


+ 10
- 7
internal/p2p/switch.go View File

@ -103,8 +103,8 @@ type Switch struct {
peers *PeerSet peers *PeerSet
dialing *cmap.CMap dialing *cmap.CMap
reconnecting *cmap.CMap reconnecting *cmap.CMap
nodeInfo NodeInfo // our node info
nodeKey NodeKey // our node privkey
nodeInfo types.NodeInfo // our node info
nodeKey NodeKey // our node privkey
addrBook AddrBook addrBook AddrBook
// peers addresses with whom we'll maintain constant connection // peers addresses with whom we'll maintain constant connection
persistentPeersAddrs []*NetAddress persistentPeersAddrs []*NetAddress
@ -242,13 +242,13 @@ func (sw *Switch) Reactor(name string) Reactor {
// SetNodeInfo sets the switch's NodeInfo for checking compatibility and handshaking with other nodes. // SetNodeInfo sets the switch's NodeInfo for checking compatibility and handshaking with other nodes.
// NOTE: Not goroutine safe. // NOTE: Not goroutine safe.
func (sw *Switch) SetNodeInfo(nodeInfo NodeInfo) {
func (sw *Switch) SetNodeInfo(nodeInfo types.NodeInfo) {
sw.nodeInfo = nodeInfo sw.nodeInfo = nodeInfo
} }
// NodeInfo returns the switch's NodeInfo. // NodeInfo returns the switch's NodeInfo.
// NOTE: Not goroutine safe. // NOTE: Not goroutine safe.
func (sw *Switch) NodeInfo() NodeInfo {
func (sw *Switch) NodeInfo() types.NodeInfo {
return sw.nodeInfo return sw.nodeInfo
} }
@ -669,7 +669,7 @@ func (sw *Switch) IsPeerPersistent(na *NetAddress) bool {
func (sw *Switch) acceptRoutine() { func (sw *Switch) acceptRoutine() {
for { for {
var peerNodeInfo NodeInfo
var peerNodeInfo types.NodeInfo
c, err := sw.transport.Accept() c, err := sw.transport.Accept()
if err == nil { if err == nil {
// NOTE: The legacy MConn transport did handshaking in Accept(), // NOTE: The legacy MConn transport did handshaking in Accept(),
@ -800,7 +800,7 @@ func (sw *Switch) addOutboundPeerWithConfig(
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
var peerNodeInfo NodeInfo
var peerNodeInfo types.NodeInfo
c, err := sw.transport.Dial(ctx, Endpoint{ c, err := sw.transport.Dial(ctx, Endpoint{
Protocol: MConnProtocol, Protocol: MConnProtocol,
IP: addr.IP, IP: addr.IP,
@ -856,7 +856,10 @@ func (sw *Switch) addOutboundPeerWithConfig(
return nil return nil
} }
func (sw *Switch) handshakePeer(c Connection, expectPeerID types.NodeID) (NodeInfo, crypto.PubKey, error) {
func (sw *Switch) handshakePeer(
c Connection,
expectPeerID types.NodeID,
) (types.NodeInfo, crypto.PubKey, error) {
// Moved from transport and hardcoded until legacy P2P stack removal. // Moved from transport and hardcoded until legacy P2P stack removal.
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()


+ 5
- 5
internal/p2p/test_util.go View File

@ -27,7 +27,7 @@ func CreateRandomPeer(outbound bool) Peer {
addr, netAddr := CreateRoutableAddr() addr, netAddr := CreateRoutableAddr()
p := &peer{ p := &peer{
peerConn: peerConn{outbound: outbound}, peerConn: peerConn{outbound: outbound},
nodeInfo: NodeInfo{
nodeInfo: types.NodeInfo{
NodeID: netAddr.ID, NodeID: netAddr.ID,
ListenAddr: netAddr.DialString(), ListenAddr: netAddr.DialString(),
}, },
@ -227,12 +227,12 @@ func testPeerConn(
//---------------------------------------------------------------- //----------------------------------------------------------------
// rand node info // rand node info
func testNodeInfo(id types.NodeID, name string) NodeInfo {
func testNodeInfo(id types.NodeID, name string) types.NodeInfo {
return testNodeInfoWithNetwork(id, name, "testing") return testNodeInfoWithNetwork(id, name, "testing")
} }
func testNodeInfoWithNetwork(id types.NodeID, name, network string) NodeInfo {
return NodeInfo{
func testNodeInfoWithNetwork(id types.NodeID, name, network string) types.NodeInfo {
return types.NodeInfo{
ProtocolVersion: defaultProtocolVersion, ProtocolVersion: defaultProtocolVersion,
NodeID: id, NodeID: id,
ListenAddr: fmt.Sprintf("127.0.0.1:%d", getFreePort()), ListenAddr: fmt.Sprintf("127.0.0.1:%d", getFreePort()),
@ -240,7 +240,7 @@ func testNodeInfoWithNetwork(id types.NodeID, name, network string) NodeInfo {
Version: "1.2.3-rc0-deadbeef", Version: "1.2.3-rc0-deadbeef",
Channels: []byte{testCh}, Channels: []byte{testCh},
Moniker: name, Moniker: name,
Other: NodeInfoOther{
Other: types.NodeInfoOther{
TxIndex: "on", TxIndex: "on",
RPCAddress: fmt.Sprintf("127.0.0.1:%d", getFreePort()), RPCAddress: fmt.Sprintf("127.0.0.1:%d", getFreePort()),
}, },


+ 10
- 1
internal/p2p/transport.go View File

@ -9,6 +9,7 @@ import (
"github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/internal/p2p/conn" "github.com/tendermint/tendermint/internal/p2p/conn"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
"github.com/tendermint/tendermint/version"
) )
//go:generate mockery --case underscore --name Transport|Connection //go:generate mockery --case underscore --name Transport|Connection
@ -19,6 +20,14 @@ const (
defaultProtocol Protocol = MConnProtocol defaultProtocol Protocol = MConnProtocol
) )
// defaultProtocolVersion populates the Block and P2P versions using
// the global values, but not the App.
var defaultProtocolVersion = types.ProtocolVersion{
P2P: version.P2PProtocol,
Block: version.BlockProtocol,
App: 0,
}
// Protocol identifies a transport protocol. // Protocol identifies a transport protocol.
type Protocol string type Protocol string
@ -75,7 +84,7 @@ type Connection interface {
// FIXME: The handshake should really be the Router's responsibility, but // FIXME: The handshake should really be the Router's responsibility, but
// that requires the connection interface to be byte-oriented rather than // that requires the connection interface to be byte-oriented rather than
// message-oriented (see comment above). // message-oriented (see comment above).
Handshake(context.Context, NodeInfo, crypto.PrivKey) (NodeInfo, crypto.PubKey, error)
Handshake(context.Context, types.NodeInfo, crypto.PrivKey) (types.NodeInfo, crypto.PubKey, error)
// ReceiveMessage returns the next message received on the connection, // ReceiveMessage returns the next message received on the connection,
// blocking until one is available. Returns io.EOF if closed. // blocking until one is available. Returns io.EOF if closed.


+ 15
- 14
internal/p2p/transport_mconn.go View File

@ -17,6 +17,7 @@ import (
"github.com/tendermint/tendermint/internal/p2p/conn" "github.com/tendermint/tendermint/internal/p2p/conn"
"github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/log"
p2pproto "github.com/tendermint/tendermint/proto/tendermint/p2p" p2pproto "github.com/tendermint/tendermint/proto/tendermint/p2p"
"github.com/tendermint/tendermint/types"
) )
const ( const (
@ -254,12 +255,12 @@ func newMConnConnection(
// Handshake implements Connection. // Handshake implements Connection.
func (c *mConnConnection) Handshake( func (c *mConnConnection) Handshake(
ctx context.Context, ctx context.Context,
nodeInfo NodeInfo,
nodeInfo types.NodeInfo,
privKey crypto.PrivKey, privKey crypto.PrivKey,
) (NodeInfo, crypto.PubKey, error) {
) (types.NodeInfo, crypto.PubKey, error) {
var ( var (
mconn *conn.MConnection mconn *conn.MConnection
peerInfo NodeInfo
peerInfo types.NodeInfo
peerKey crypto.PubKey peerKey crypto.PubKey
errCh = make(chan error, 1) errCh = make(chan error, 1)
) )
@ -282,16 +283,16 @@ func (c *mConnConnection) Handshake(
select { select {
case <-ctx.Done(): case <-ctx.Done():
_ = c.Close() _ = c.Close()
return NodeInfo{}, nil, ctx.Err()
return types.NodeInfo{}, nil, ctx.Err()
case err := <-errCh: case err := <-errCh:
if err != nil { if err != nil {
return NodeInfo{}, nil, err
return types.NodeInfo{}, nil, err
} }
c.mconn = mconn c.mconn = mconn
c.logger = mconn.Logger c.logger = mconn.Logger
if err = c.mconn.Start(); err != nil { if err = c.mconn.Start(); err != nil {
return NodeInfo{}, nil, err
return types.NodeInfo{}, nil, err
} }
return peerInfo, peerKey, nil return peerInfo, peerKey, nil
} }
@ -302,16 +303,16 @@ func (c *mConnConnection) Handshake(
// unstarted but handshaked MConnection, to avoid concurrent field writes. // unstarted but handshaked MConnection, to avoid concurrent field writes.
func (c *mConnConnection) handshake( func (c *mConnConnection) handshake(
ctx context.Context, ctx context.Context,
nodeInfo NodeInfo,
nodeInfo types.NodeInfo,
privKey crypto.PrivKey, privKey crypto.PrivKey,
) (*conn.MConnection, NodeInfo, crypto.PubKey, error) {
) (*conn.MConnection, types.NodeInfo, crypto.PubKey, error) {
if c.mconn != nil { if c.mconn != nil {
return nil, NodeInfo{}, nil, errors.New("connection is already handshaked")
return nil, types.NodeInfo{}, nil, errors.New("connection is already handshaked")
} }
secretConn, err := conn.MakeSecretConnection(c.conn, privKey) secretConn, err := conn.MakeSecretConnection(c.conn, privKey)
if err != nil { if err != nil {
return nil, NodeInfo{}, nil, err
return nil, types.NodeInfo{}, nil, err
} }
var pbPeerInfo p2pproto.NodeInfo var pbPeerInfo p2pproto.NodeInfo
@ -321,17 +322,17 @@ func (c *mConnConnection) handshake(
errCh <- err errCh <- err
}() }()
go func() { go func() {
_, err := protoio.NewDelimitedReader(secretConn, MaxNodeInfoSize()).ReadMsg(&pbPeerInfo)
_, err := protoio.NewDelimitedReader(secretConn, types.MaxNodeInfoSize()).ReadMsg(&pbPeerInfo)
errCh <- err errCh <- err
}() }()
for i := 0; i < cap(errCh); i++ { for i := 0; i < cap(errCh); i++ {
if err = <-errCh; err != nil { if err = <-errCh; err != nil {
return nil, NodeInfo{}, nil, err
return nil, types.NodeInfo{}, nil, err
} }
} }
peerInfo, err := NodeInfoFromProto(&pbPeerInfo)
peerInfo, err := types.NodeInfoFromProto(&pbPeerInfo)
if err != nil { if err != nil {
return nil, NodeInfo{}, nil, err
return nil, types.NodeInfo{}, nil, err
} }
mconn := conn.NewMConnectionWithConfig( mconn := conn.NewMConnectionWithConfig(


+ 8
- 8
internal/p2p/transport_memory.go View File

@ -218,7 +218,7 @@ type memoryMessage struct {
message []byte message []byte
// For handshakes. // For handshakes.
nodeInfo *NodeInfo
nodeInfo *types.NodeInfo
pubKey crypto.PubKey pubKey crypto.PubKey
} }
@ -270,29 +270,29 @@ func (c *MemoryConnection) Status() conn.ConnectionStatus {
// Handshake implements Connection. // Handshake implements Connection.
func (c *MemoryConnection) Handshake( func (c *MemoryConnection) Handshake(
ctx context.Context, ctx context.Context,
nodeInfo NodeInfo,
nodeInfo types.NodeInfo,
privKey crypto.PrivKey, privKey crypto.PrivKey,
) (NodeInfo, crypto.PubKey, error) {
) (types.NodeInfo, crypto.PubKey, error) {
select { select {
case c.sendCh <- memoryMessage{nodeInfo: &nodeInfo, pubKey: privKey.PubKey()}: case c.sendCh <- memoryMessage{nodeInfo: &nodeInfo, pubKey: privKey.PubKey()}:
c.logger.Debug("sent handshake", "nodeInfo", nodeInfo) c.logger.Debug("sent handshake", "nodeInfo", nodeInfo)
case <-c.closer.Done(): case <-c.closer.Done():
return NodeInfo{}, nil, io.EOF
return types.NodeInfo{}, nil, io.EOF
case <-ctx.Done(): case <-ctx.Done():
return NodeInfo{}, nil, ctx.Err()
return types.NodeInfo{}, nil, ctx.Err()
} }
select { select {
case msg := <-c.receiveCh: case msg := <-c.receiveCh:
if msg.nodeInfo == nil { if msg.nodeInfo == nil {
return NodeInfo{}, nil, errors.New("no NodeInfo in handshake")
return types.NodeInfo{}, nil, errors.New("no NodeInfo in handshake")
} }
c.logger.Debug("received handshake", "peerInfo", msg.nodeInfo) c.logger.Debug("received handshake", "peerInfo", msg.nodeInfo)
return *msg.nodeInfo, msg.pubKey, nil return *msg.nodeInfo, msg.pubKey, nil
case <-c.closer.Done(): case <-c.closer.Done():
return NodeInfo{}, nil, io.EOF
return types.NodeInfo{}, nil, io.EOF
case <-ctx.Done(): case <-ctx.Done():
return NodeInfo{}, nil, ctx.Err()
return types.NodeInfo{}, nil, ctx.Err()
} }
} }


+ 18
- 14
internal/p2p/transport_test.go View File

@ -242,21 +242,25 @@ func TestConnection_Handshake(t *testing.T) {
// A handshake should pass the given keys and NodeInfo. // A handshake should pass the given keys and NodeInfo.
aKey := ed25519.GenPrivKey() aKey := ed25519.GenPrivKey()
aInfo := p2p.NodeInfo{
NodeID: types.NodeIDFromPubKey(aKey.PubKey()),
ProtocolVersion: p2p.NewProtocolVersion(1, 2, 3),
ListenAddr: "listenaddr",
Network: "network",
Version: "1.2.3",
Channels: bytes.HexBytes([]byte{0xf0, 0x0f}),
Moniker: "moniker",
Other: p2p.NodeInfoOther{
aInfo := types.NodeInfo{
NodeID: types.NodeIDFromPubKey(aKey.PubKey()),
ProtocolVersion: types.ProtocolVersion{
P2P: 1,
Block: 2,
App: 3,
},
ListenAddr: "listenaddr",
Network: "network",
Version: "1.2.3",
Channels: bytes.HexBytes([]byte{0xf0, 0x0f}),
Moniker: "moniker",
Other: types.NodeInfoOther{
TxIndex: "txindex", TxIndex: "txindex",
RPCAddress: "rpc.domain.com", RPCAddress: "rpc.domain.com",
}, },
} }
bKey := ed25519.GenPrivKey() bKey := ed25519.GenPrivKey()
bInfo := p2p.NodeInfo{NodeID: types.NodeIDFromPubKey(bKey.PubKey())}
bInfo := types.NodeInfo{NodeID: types.NodeIDFromPubKey(bKey.PubKey())}
errCh := make(chan error, 1) errCh := make(chan error, 1)
go func() { go func() {
@ -287,7 +291,7 @@ func TestConnection_HandshakeCancel(t *testing.T) {
ab, ba := dialAccept(t, a, b) ab, ba := dialAccept(t, a, b)
timeoutCtx, cancel := context.WithTimeout(ctx, 1*time.Minute) timeoutCtx, cancel := context.WithTimeout(ctx, 1*time.Minute)
cancel() cancel()
_, _, err := ab.Handshake(timeoutCtx, p2p.NodeInfo{}, ed25519.GenPrivKey())
_, _, err := ab.Handshake(timeoutCtx, types.NodeInfo{}, ed25519.GenPrivKey())
require.Error(t, err) require.Error(t, err)
require.Equal(t, context.Canceled, err) require.Equal(t, context.Canceled, err)
_ = ab.Close() _ = ab.Close()
@ -297,7 +301,7 @@ func TestConnection_HandshakeCancel(t *testing.T) {
ab, ba = dialAccept(t, a, b) ab, ba = dialAccept(t, a, b)
timeoutCtx, cancel = context.WithTimeout(ctx, 200*time.Millisecond) timeoutCtx, cancel = context.WithTimeout(ctx, 200*time.Millisecond)
defer cancel() defer cancel()
_, _, err = ab.Handshake(timeoutCtx, p2p.NodeInfo{}, ed25519.GenPrivKey())
_, _, err = ab.Handshake(timeoutCtx, types.NodeInfo{}, ed25519.GenPrivKey())
require.Error(t, err) require.Error(t, err)
require.Equal(t, context.DeadlineExceeded, err) require.Equal(t, context.DeadlineExceeded, err)
_ = ab.Close() _ = ab.Close()
@ -619,13 +623,13 @@ func dialAcceptHandshake(t *testing.T, a, b p2p.Transport) (p2p.Connection, p2p.
errCh := make(chan error, 1) errCh := make(chan error, 1)
go func() { go func() {
privKey := ed25519.GenPrivKey() privKey := ed25519.GenPrivKey()
nodeInfo := p2p.NodeInfo{NodeID: types.NodeIDFromPubKey(privKey.PubKey())}
nodeInfo := types.NodeInfo{NodeID: types.NodeIDFromPubKey(privKey.PubKey())}
_, _, err := ba.Handshake(ctx, nodeInfo, privKey) _, _, err := ba.Handshake(ctx, nodeInfo, privKey)
errCh <- err errCh <- err
}() }()
privKey := ed25519.GenPrivKey() privKey := ed25519.GenPrivKey()
nodeInfo := p2p.NodeInfo{NodeID: types.NodeIDFromPubKey(privKey.PubKey())}
nodeInfo := types.NodeInfo{NodeID: types.NodeIDFromPubKey(privKey.PubKey())}
_, _, err := ab.Handshake(ctx, nodeInfo, privKey) _, _, err := ab.Handshake(ctx, nodeInfo, privKey)
require.NoError(t, err) require.NoError(t, err)


+ 2
- 2
node/node.go View File

@ -58,7 +58,7 @@ type nodeImpl struct {
peerManager *p2p.PeerManager peerManager *p2p.PeerManager
router *p2p.Router router *p2p.Router
addrBook pex.AddrBook // known peers addrBook pex.AddrBook // known peers
nodeInfo p2p.NodeInfo
nodeInfo types.NodeInfo
nodeKey p2p.NodeKey // our node privkey nodeKey p2p.NodeKey // our node privkey
isListening bool isListening bool
@ -1022,7 +1022,7 @@ func (n *nodeImpl) IsListening() bool {
} }
// NodeInfo returns the Node's Info from the Switch. // NodeInfo returns the Node's Info from the Switch.
func (n *nodeImpl) NodeInfo() p2p.NodeInfo {
func (n *nodeImpl) NodeInfo() types.NodeInfo {
return n.nodeInfo return n.nodeInfo
} }


+ 19
- 19
node/setup.go View File

@ -537,7 +537,7 @@ func createPeerManager(
func createRouter( func createRouter(
p2pLogger log.Logger, p2pLogger log.Logger,
p2pMetrics *p2p.Metrics, p2pMetrics *p2p.Metrics,
nodeInfo p2p.NodeInfo,
nodeInfo types.NodeInfo,
privKey crypto.PrivKey, privKey crypto.PrivKey,
peerManager *p2p.PeerManager, peerManager *p2p.PeerManager,
transport p2p.Transport, transport p2p.Transport,
@ -565,7 +565,7 @@ func createSwitch(
consensusReactor *p2p.ReactorShim, consensusReactor *p2p.ReactorShim,
evidenceReactor *p2p.ReactorShim, evidenceReactor *p2p.ReactorShim,
proxyApp proxy.AppConns, proxyApp proxy.AppConns,
nodeInfo p2p.NodeInfo,
nodeInfo types.NodeInfo,
nodeKey p2p.NodeKey, nodeKey p2p.NodeKey,
p2pLogger log.Logger, p2pLogger log.Logger,
) *p2p.Switch { ) *p2p.Switch {
@ -713,7 +713,7 @@ func makeNodeInfo(
eventSinks []indexer.EventSink, eventSinks []indexer.EventSink,
genDoc *types.GenesisDoc, genDoc *types.GenesisDoc,
state sm.State, state sm.State,
) (p2p.NodeInfo, error) {
) (types.NodeInfo, error) {
txIndexerStatus := "off" txIndexerStatus := "off"
if indexer.IndexingEnabled(eventSinks) { if indexer.IndexingEnabled(eventSinks) {
@ -729,15 +729,15 @@ func makeNodeInfo(
bcChannel = bcv2.BlockchainChannel bcChannel = bcv2.BlockchainChannel
default: default:
return p2p.NodeInfo{}, fmt.Errorf("unknown fastsync version %s", config.FastSync.Version)
return types.NodeInfo{}, fmt.Errorf("unknown fastsync version %s", config.FastSync.Version)
} }
nodeInfo := p2p.NodeInfo{
ProtocolVersion: p2p.NewProtocolVersion(
version.P2PProtocol, // global
state.Version.Consensus.Block,
state.Version.Consensus.App,
),
nodeInfo := types.NodeInfo{
ProtocolVersion: types.ProtocolVersion{
P2P: version.P2PProtocol, // global
Block: state.Version.Consensus.Block,
App: state.Version.Consensus.App,
},
NodeID: nodeKey.ID, NodeID: nodeKey.ID,
Network: genDoc.ChainID, Network: genDoc.ChainID,
Version: version.TMVersion, Version: version.TMVersion,
@ -754,7 +754,7 @@ func makeNodeInfo(
byte(statesync.LightBlockChannel), byte(statesync.LightBlockChannel),
}, },
Moniker: config.Moniker, Moniker: config.Moniker,
Other: p2p.NodeInfoOther{
Other: types.NodeInfoOther{
TxIndex: txIndexerStatus, TxIndex: txIndexerStatus,
RPCAddress: config.RPC.ListenAddress, RPCAddress: config.RPC.ListenAddress,
}, },
@ -781,19 +781,19 @@ func makeSeedNodeInfo(
nodeKey p2p.NodeKey, nodeKey p2p.NodeKey,
genDoc *types.GenesisDoc, genDoc *types.GenesisDoc,
state sm.State, state sm.State,
) (p2p.NodeInfo, error) {
nodeInfo := p2p.NodeInfo{
ProtocolVersion: p2p.NewProtocolVersion(
version.P2PProtocol, // global
state.Version.Consensus.Block,
state.Version.Consensus.App,
),
) (types.NodeInfo, error) {
nodeInfo := types.NodeInfo{
ProtocolVersion: types.ProtocolVersion{
P2P: version.P2PProtocol, // global
Block: state.Version.Consensus.Block,
App: state.Version.Consensus.App,
},
NodeID: nodeKey.ID, NodeID: nodeKey.ID,
Network: genDoc.ChainID, Network: genDoc.ChainID,
Version: version.TMVersion, Version: version.TMVersion,
Channels: []byte{}, Channels: []byte{},
Moniker: config.Moniker, Moniker: config.Moniker,
Other: p2p.NodeInfoOther{
Other: types.NodeInfoOther{
TxIndex: "off", TxIndex: "off",
RPCAddress: config.RPC.ListenAddress, RPCAddress: config.RPC.ListenAddress,
}, },


+ 7
- 6
proto/tendermint/p2p/types.pb.go View File

@ -5,14 +5,15 @@ package p2p
import ( import (
fmt "fmt" fmt "fmt"
_ "github.com/gogo/protobuf/gogoproto"
proto "github.com/gogo/protobuf/proto"
_ "github.com/gogo/protobuf/types"
github_com_gogo_protobuf_types "github.com/gogo/protobuf/types"
io "io" io "io"
math "math" math "math"
math_bits "math/bits" math_bits "math/bits"
time "time" time "time"
_ "github.com/gogo/protobuf/gogoproto"
proto "github.com/gogo/protobuf/proto"
_ "github.com/gogo/protobuf/types"
github_com_gogo_protobuf_types "github.com/gogo/protobuf/types"
) )
// Reference imports to suppress errors if they are not otherwise used. // Reference imports to suppress errors if they are not otherwise used.
@ -369,8 +370,8 @@ func (m *PeerAddressInfo) GetDialFailures() uint32 {
func init() { func init() {
proto.RegisterType((*ProtocolVersion)(nil), "tendermint.p2p.ProtocolVersion") proto.RegisterType((*ProtocolVersion)(nil), "tendermint.p2p.ProtocolVersion")
proto.RegisterType((*NodeInfo)(nil), "tendermint.p2p.NodeInfo")
proto.RegisterType((*NodeInfoOther)(nil), "tendermint.p2p.NodeInfoOther")
proto.RegisterType((*NodeInfo)(nil), "tendermint.types.NodeInfo")
proto.RegisterType((*NodeInfoOther)(nil), "tendermint.types.NodeInfoOther")
proto.RegisterType((*PeerInfo)(nil), "tendermint.p2p.PeerInfo") proto.RegisterType((*PeerInfo)(nil), "tendermint.p2p.PeerInfo")
proto.RegisterType((*PeerAddressInfo)(nil), "tendermint.p2p.PeerAddressInfo") proto.RegisterType((*PeerAddressInfo)(nil), "tendermint.p2p.PeerAddressInfo")
} }


+ 1
- 1
rpc/core/env.go View File

@ -47,7 +47,7 @@ type Consensus interface {
type transport interface { type transport interface {
Listeners() []string Listeners() []string
IsListening() bool IsListening() bool
NodeInfo() p2p.NodeInfo
NodeInfo() types.NodeInfo
} }
type peers interface { type peers interface {


+ 4
- 4
rpc/core/types/responses.go View File

@ -108,9 +108,9 @@ type ValidatorInfo struct {
// Node Status // Node Status
type ResultStatus struct { type ResultStatus struct {
NodeInfo p2p.NodeInfo `json:"node_info"`
SyncInfo SyncInfo `json:"sync_info"`
ValidatorInfo ValidatorInfo `json:"validator_info"`
NodeInfo types.NodeInfo `json:"node_info"`
SyncInfo SyncInfo `json:"sync_info"`
ValidatorInfo ValidatorInfo `json:"validator_info"`
} }
// Is TxIndexing enabled // Is TxIndexing enabled
@ -141,7 +141,7 @@ type ResultDialPeers struct {
// A peer // A peer
type Peer struct { type Peer struct {
NodeInfo p2p.NodeInfo `json:"node_info"`
NodeInfo types.NodeInfo `json:"node_info"`
IsOutbound bool `json:"is_outbound"` IsOutbound bool `json:"is_outbound"`
ConnectionStatus p2p.ConnectionStatus `json:"connection_status"` ConnectionStatus p2p.ConnectionStatus `json:"connection_status"`
RemoteIP string `json:"remote_ip"` RemoteIP string `json:"remote_ip"`


+ 7
- 8
rpc/core/types/responses_test.go View File

@ -4,8 +4,7 @@ import (
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"github.com/tendermint/tendermint/internal/p2p"
"github.com/tendermint/tendermint/types"
) )
func TestStatusIndexer(t *testing.T) { func TestStatusIndexer(t *testing.T) {
@ -15,17 +14,17 @@ func TestStatusIndexer(t *testing.T) {
status = &ResultStatus{} status = &ResultStatus{}
assert.False(t, status.TxIndexEnabled()) assert.False(t, status.TxIndexEnabled())
status.NodeInfo = p2p.NodeInfo{}
status.NodeInfo = types.NodeInfo{}
assert.False(t, status.TxIndexEnabled()) assert.False(t, status.TxIndexEnabled())
cases := []struct { cases := []struct {
expected bool expected bool
other p2p.NodeInfoOther
other types.NodeInfoOther
}{ }{
{false, p2p.NodeInfoOther{}},
{false, p2p.NodeInfoOther{TxIndex: "aa"}},
{false, p2p.NodeInfoOther{TxIndex: "off"}},
{true, p2p.NodeInfoOther{TxIndex: "on"}},
{false, types.NodeInfoOther{}},
{false, types.NodeInfoOther{TxIndex: "aa"}},
{false, types.NodeInfoOther{TxIndex: "off"}},
{true, types.NodeInfoOther{TxIndex: "on"}},
} }
for _, tc := range cases { for _, tc := range cases {


+ 7
- 7
test/fuzz/p2p/pex/reactor_receive.go View File

@ -64,12 +64,12 @@ func newFuzzPeer() *fuzzPeer {
var privKey = ed25519.GenPrivKey() var privKey = ed25519.GenPrivKey()
var nodeID = types.NodeIDFromPubKey(privKey.PubKey()) var nodeID = types.NodeIDFromPubKey(privKey.PubKey())
var defaultNodeInfo = p2p.NodeInfo{
ProtocolVersion: p2p.NewProtocolVersion(
version.P2PProtocol,
version.BlockProtocol,
0,
),
var defaultNodeInfo = types.NodeInfo{
ProtocolVersion: types.ProtocolVersion{
P2P: version.P2PProtocol,
Block: version.BlockProtocol,
App: 0,
},
NodeID: nodeID, NodeID: nodeID,
ListenAddr: "127.0.0.1:0", ListenAddr: "127.0.0.1:0",
Moniker: "foo1", Moniker: "foo1",
@ -84,7 +84,7 @@ func (fp *fuzzPeer) RemoteAddr() net.Addr {
func (fp *fuzzPeer) IsOutbound() bool { return false } func (fp *fuzzPeer) IsOutbound() bool { return false }
func (fp *fuzzPeer) IsPersistent() bool { return false } func (fp *fuzzPeer) IsPersistent() bool { return false }
func (fp *fuzzPeer) CloseConn() error { return nil } func (fp *fuzzPeer) CloseConn() error { return nil }
func (fp *fuzzPeer) NodeInfo() p2p.NodeInfo { return defaultNodeInfo }
func (fp *fuzzPeer) NodeInfo() types.NodeInfo { return defaultNodeInfo }
func (fp *fuzzPeer) Status() p2p.ConnectionStatus { var cs p2p.ConnectionStatus; return cs } func (fp *fuzzPeer) Status() p2p.ConnectionStatus { var cs p2p.ConnectionStatus; return cs }
func (fp *fuzzPeer) SocketAddr() *p2p.NetAddress { func (fp *fuzzPeer) SocketAddr() *p2p.NetAddress {
return types.NewNetAddress(fp.ID(), fp.RemoteAddr()) return types.NewNetAddress(fp.ID(), fp.RemoteAddr())


internal/p2p/node_info.go → types/node_info.go View File


internal/p2p/node_info_test.go → types/node_info_test.go View File


Loading…
Cancel
Save