2018-07-16 07:40:40 +00:00
|
|
|
package peer
|
|
|
|
|
2024-10-03 19:59:44 +00:00
|
|
|
//go:generate mockgen -package=mock_peer -source=service.go -destination=mock/service.go
|
|
|
|
|
2018-07-16 07:40:40 +00:00
|
|
|
import (
|
|
|
|
"github.com/ethereum/go-ethereum/node"
|
|
|
|
"github.com/ethereum/go-ethereum/p2p"
|
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
|
|
|
)
|
|
|
|
|
2021-06-28 07:28:59 +00:00
|
|
|
// Make sure that Service implements node.Lifecycle interface.
|
|
|
|
var _ node.Lifecycle = (*Service)(nil)
|
2018-07-16 07:40:40 +00:00
|
|
|
|
|
|
|
// Discoverer manages peer discovery.
|
|
|
|
type Discoverer interface {
|
|
|
|
Discover(topic string, max, min int) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// Service it manages all endpoints for peer operations.
|
|
|
|
type Service struct {
|
|
|
|
d Discoverer
|
|
|
|
}
|
|
|
|
|
|
|
|
// New returns a new Service.
|
|
|
|
func New() *Service {
|
|
|
|
return &Service{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Protocols returns a new protocols list. In this case, there are none.
|
|
|
|
func (s *Service) Protocols() []p2p.Protocol {
|
|
|
|
return []p2p.Protocol{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// APIs returns a list of new APIs.
|
|
|
|
func (s *Service) APIs() []rpc.API {
|
|
|
|
return []rpc.API{
|
|
|
|
{
|
|
|
|
Namespace: "peer",
|
|
|
|
Version: "1.0",
|
|
|
|
Service: NewAPI(s),
|
|
|
|
Public: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetDiscoverer sets discoverer for the API calls.
|
|
|
|
func (s *Service) SetDiscoverer(d Discoverer) {
|
|
|
|
s.d = d
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start is run when a service is started.
|
|
|
|
// It does nothing in this case but is required by `node.Service` interface.
|
2021-06-28 07:28:59 +00:00
|
|
|
func (s *Service) Start() error {
|
2018-07-16 07:40:40 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop is run when a service is stopped.
|
|
|
|
// It does nothing in this case but is required by `node.Service` interface.
|
|
|
|
func (s *Service) Stop() error {
|
|
|
|
return nil
|
|
|
|
}
|