Browse Source

service: add NopService and use for PexReactor (#8100)

pull/8104/head
William Banfield 2 years ago
committed by GitHub
parent
commit
ddbc93d993
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions
  1. +11
    -0
      libs/service/service.go
  2. +1
    -1
      node/node.go

+ 11
- 0
libs/service/service.go View File

@ -14,6 +14,11 @@ var (
errAlreadyStopped = errors.New("already stopped")
)
var (
_ Service = (*BaseService)(nil)
_ Service = (*NopService)(nil)
)
// Service defines a service that can be started, stopped, and reset.
type Service interface {
// Start is called to start the service, which should run until
@ -85,6 +90,12 @@ type BaseService struct {
impl Implementation
}
type NopService struct{}
func (NopService) Start(_ context.Context) error { return nil }
func (NopService) IsRunning() bool { return true }
func (NopService) Wait() {}
// NewBaseService creates a new BaseService.
func NewBaseService(logger log.Logger, name string, impl Implementation) *BaseService {
return &BaseService{


+ 1
- 1
node/node.go View File

@ -357,7 +357,7 @@ func makeNode(
return nil, combineCloseError(err, makeCloser(closers))
}
var pexReactor service.Service
var pexReactor service.Service = service.NopService{}
if cfg.P2P.PexReactor {
pexReactor, err = pex.NewReactor(ctx, logger, peerManager, router.OpenChannel, peerManager.Subscribe(ctx))
if err != nil {


Loading…
Cancel
Save