Skip to content

Commit

Permalink
chore: simplify base router config
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanchriswhite committed Jul 11, 2023
1 parent 3b9845b commit 3acfbc8
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions p2p/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/libp2p/go-libp2p/core/protocol"
"go.uber.org/multierr"

"github.com/pokt-network/pocket/p2p/providers"
typesP2P "github.com/pokt-network/pocket/p2p/types"
"github.com/pokt-network/pocket/shared/crypto"
"github.com/pokt-network/pocket/shared/modules"
Expand All @@ -20,18 +19,16 @@ var (
_ typesP2P.RouterConfig = &RainTreeConfig{}
)

// baseConfig implements `RouterConfig` using the given libp2p host and current
// height and peerstore providers. Intended for internal use by other `RouterConfig`
// baseConfig implements `RouterConfig` using the given libp2p host, pokt address
// and handler function. Intended for internal use by other `RouterConfig`
// implementations with common config parameters.
//
// NB: intentionally *not* embedding `baseConfig` to improve readability of usages
// of would-be embedders (e.g. `BackgroundConfig`).
type baseConfig struct {
Host host.Host
Addr crypto.Address
CurrentHeightProvider providers.CurrentHeightProvider
PeerstoreProvider providers.PeerstoreProvider
Handler func(data []byte) error
Host host.Host
Addr crypto.Address
Handler func(data []byte) error
}

type UnicastRouterConfig struct {
Expand Down Expand Up @@ -62,18 +59,10 @@ func (cfg *baseConfig) IsValid() (err error) {
err = multierr.Append(err, fmt.Errorf("pokt address not configured"))
}

if cfg.CurrentHeightProvider == nil {
err = multierr.Append(err, fmt.Errorf("current height provider not configured"))
}

if cfg.Host == nil {
err = multierr.Append(err, fmt.Errorf("host not configured"))
}

if cfg.PeerstoreProvider == nil {
err = multierr.Append(err, fmt.Errorf("peerstore provider not configured"))
}

if cfg.Handler == nil {
err = multierr.Append(err, fmt.Errorf("handler not configured"))
}
Expand Down

0 comments on commit 3acfbc8

Please sign in to comment.