Skip to content

Commit

Permalink
refactor(modp2p): Introduce String method for Network and use it ever…
Browse files Browse the repository at this point in the history
…ywhere (celestiaorg#1765)
  • Loading branch information
Wondertan authored Feb 22, 2023
1 parent d478502 commit dabe2c4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/flags_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func ParseNodeFlags(ctx context.Context, cmd *cobra.Command, network p2p.Network
if store == "" {
tp := NodeType(ctx)
var err error
store, err = DefaultNodeStorePath(tp.String(), string(network))
store, err = DefaultNodeStorePath(tp.String(), network.String())
if err != nil {
return ctx, err
}
Expand Down
2 changes: 1 addition & 1 deletion nodebuilder/fraud/constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func newFraudService(syncerEnabled bool) func(
ds datastore.Batching,
network p2p.Network,
) (Module, fraud.Service, error) {
pservice := fraud.NewProofService(sub, host, hstore.GetByHeight, ds, syncerEnabled, string(network))
pservice := fraud.NewProofService(sub, host, hstore.GetByHeight, ds, syncerEnabled, network.String())
lc.Append(fx.Hook{
OnStart: pservice.Start,
OnStop: pservice.Stop,
Expand Down
6 changes: 3 additions & 3 deletions nodebuilder/header/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func ConstructModule(tp node.Type, cfg *Config) fx.Option {
p2p.WithReadDeadline(cfg.Server.ReadDeadline),
p2p.WithMaxRequestSize[p2p.ServerParameters](cfg.Server.MaxRequestSize),
p2p.WithRequestTimeout[p2p.ServerParameters](cfg.Server.RequestTimeout),
p2p.WithProtocolSuffix[p2p.ServerParameters](string(network)),
p2p.WithProtocolSuffix[p2p.ServerParameters](network.String()),
}
}),
fx.Provide(newHeaderService),
Expand Down Expand Up @@ -87,7 +87,7 @@ func ConstructModule(tp node.Type, cfg *Config) fx.Option {
)),
fx.Provide(fx.Annotate(
func(ps *pubsub.PubSub, network modp2p.Network) *p2p.Subscriber[*header.ExtendedHeader] {
return p2p.NewSubscriber[*header.ExtendedHeader](ps, header.MsgID, string(network))
return p2p.NewSubscriber[*header.ExtendedHeader](ps, header.MsgID, network.String())
},
fx.OnStart(func(ctx context.Context, sub *p2p.Subscriber[*header.ExtendedHeader]) error {
return sub.Start(ctx)
Expand Down Expand Up @@ -122,7 +122,7 @@ func ConstructModule(tp node.Type, cfg *Config) fx.Option {
p2p.WithDefaultScore(cfg.Client.DefaultScore),
p2p.WithRequestTimeout[p2p.ClientParameters](cfg.Client.RequestTimeout),
p2p.WithMaxTrackerSize(cfg.Client.MaxPeerTrackerSize),
p2p.WithProtocolSuffix[p2p.ClientParameters](string(network)),
p2p.WithProtocolSuffix[p2p.ClientParameters](network.String()),
}
},
),
Expand Down
5 changes: 5 additions & 0 deletions nodebuilder/p2p/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ func (n Network) Validate() (Network, error) {
return n, nil
}

// String returns string representation of the Network.
func (n Network) String() string {
return string(n)
}

// networksList is a strict list of all known long-standing networks.
var networksList = map[Network]struct{}{
Arabica: {},
Expand Down
10 changes: 5 additions & 5 deletions nodebuilder/share/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func ConstructModule(tp node.Type, cfg *Config, options ...fx.Option) fx.Option
fx.Invoke(func(edsSrv *shrexeds.Server, ndSrc *shrexnd.Server) {}),
fx.Provide(fx.Annotate(
func(host host.Host, store *eds.Store, network modp2p.Network) (*shrexeds.Server, error) {
return shrexeds.NewServer(host, store, shrexeds.WithProtocolSuffix(string(network)))
return shrexeds.NewServer(host, store, shrexeds.WithProtocolSuffix(network.String()))
},
fx.OnStart(func(ctx context.Context, server *shrexeds.Server) error {
return server.Start(ctx)
Expand All @@ -83,7 +83,7 @@ func ConstructModule(tp node.Type, cfg *Config, options ...fx.Option) fx.Option
getter *getters.IPLDGetter,
network modp2p.Network,
) (*shrexnd.Server, error) {
return shrexnd.NewServer(host, store, getter, shrexnd.WithProtocolSuffix(string(network)))
return shrexnd.NewServer(host, store, getter, shrexnd.WithProtocolSuffix(network.String()))
},
fx.OnStart(func(ctx context.Context, server *shrexnd.Server) error {
return server.Start(ctx)
Expand Down Expand Up @@ -126,12 +126,12 @@ func ConstructModule(tp node.Type, cfg *Config, options ...fx.Option) fx.Option
fx.Provide(fullGetter),
fx.Provide(
func(host host.Host, network modp2p.Network) (*shrexnd.Client, error) {
return shrexnd.NewClient(host, shrexnd.WithProtocolSuffix(string(network)))
return shrexnd.NewClient(host, shrexnd.WithProtocolSuffix(network.String()))
},
),
fx.Provide(
func(host host.Host, network modp2p.Network) (*shrexeds.Client, error) {
return shrexeds.NewClient(host, shrexeds.WithProtocolSuffix(string(network)))
return shrexeds.NewClient(host, shrexeds.WithProtocolSuffix(network.String()))
},
),
fx.Provide(fx.Annotate(
Expand All @@ -148,7 +148,7 @@ func ConstructModule(tp node.Type, cfg *Config, options ...fx.Option) fx.Option
return shrexsub.NewPubSub(
ctx,
h,
string(network),
network.String(),
)
},
),
Expand Down

0 comments on commit dabe2c4

Please sign in to comment.