Skip to content

Commit

Permalink
feat: add P2PModule#GetConnections() interface method and impl.
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanchriswhite committed Jun 6, 2023
1 parent 8ba9522 commit 10e00d0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions p2p/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/hashicorp/go-multierror"
"github.com/libp2p/go-libp2p"
libp2pHost "github.com/libp2p/go-libp2p/core/host"
libp2pNetwork "github.com/libp2p/go-libp2p/core/network"
"github.com/multiformats/go-multiaddr"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
Expand Down Expand Up @@ -276,6 +277,11 @@ func (m *p2pModule) GetUnstakedPeerstore() (typesP2P.Peerstore, error) {
return m.unstakedActorRouter.GetPeerstore(), nil
}

// GetConnections implements the respective `modules.P2PModule` interface method.
func (m *p2pModule) GetConnections() []libp2pNetwork.Conn {
return m.host.Network().Conns()
}

// setupDependencies sets up the module's current height and peerstore providers.
func (m *p2pModule) setupDependencies() error {
if err := m.setupCurrentHeightProvider(); err != nil {
Expand Down
8 changes: 7 additions & 1 deletion shared/modules/p2p_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package modules
//go:generate mockgen -destination=./mocks/p2p_module_mock.go github.com/pokt-network/pocket/shared/modules P2PModule

import (
cryptoPocket "github.com/pokt-network/pocket/shared/crypto"
libp2pNetwork "github.com/libp2p/go-libp2p/core/network"
"google.golang.org/protobuf/types/known/anypb"

cryptoPocket "github.com/pokt-network/pocket/shared/crypto"
)

const P2PModuleName = "p2p"
Expand All @@ -17,6 +19,10 @@ type P2PModule interface {
// TECHDEBT(#xxx): uncomment after moving `typesP2P.Peerstore` interface to a shared package
// GetUnstakedPeerstore() (typesP2P.Peerstore, error)

// GetConnections returns a list of all connections between the local libp2p
// host and connected remote peers.
GetConnections() []libp2pNetwork.Conn

// A network broadcast to all staked actors on the network using RainTree
Broadcast(msg *anypb.Any) error

Expand Down

0 comments on commit 10e00d0

Please sign in to comment.