github.com/status-im/status-go@v1.1.0/services/peer/service.go (about)

     1  package peer
     2  
     3  import (
     4  	"github.com/ethereum/go-ethereum/node"
     5  	"github.com/ethereum/go-ethereum/p2p"
     6  	"github.com/ethereum/go-ethereum/rpc"
     7  )
     8  
     9  // Make sure that Service implements node.Lifecycle interface.
    10  var _ node.Lifecycle = (*Service)(nil)
    11  
    12  // Discoverer manages peer discovery.
    13  type Discoverer interface {
    14  	Discover(topic string, max, min int) error
    15  }
    16  
    17  // Service it manages all endpoints for peer operations.
    18  type Service struct {
    19  	d Discoverer
    20  }
    21  
    22  // New returns a new Service.
    23  func New() *Service {
    24  	return &Service{}
    25  }
    26  
    27  // Protocols returns a new protocols list. In this case, there are none.
    28  func (s *Service) Protocols() []p2p.Protocol {
    29  	return []p2p.Protocol{}
    30  }
    31  
    32  // APIs returns a list of new APIs.
    33  func (s *Service) APIs() []rpc.API {
    34  	return []rpc.API{
    35  		{
    36  			Namespace: "peer",
    37  			Version:   "1.0",
    38  			Service:   NewAPI(s),
    39  			Public:    false,
    40  		},
    41  	}
    42  }
    43  
    44  // SetDiscoverer sets discoverer for the API calls.
    45  func (s *Service) SetDiscoverer(d Discoverer) {
    46  	s.d = d
    47  }
    48  
    49  // Start is run when a service is started.
    50  // It does nothing in this case but is required by `node.Service` interface.
    51  func (s *Service) Start() error {
    52  	return nil
    53  }
    54  
    55  // Stop is run when a service is stopped.
    56  // It does nothing in this case but is required by `node.Service` interface.
    57  func (s *Service) Stop() error {
    58  	return nil
    59  }