The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/api/service/networkinfo/service.go

64 lines
1.3 KiB

package networkinfo
import (
"github.com/harmony-one/harmony/internal/utils"
"github.com/harmony-one/harmony/p2p"
)
// Service is the role conversion service.
type Service struct {
stopChan chan struct{}
stoppedChan chan struct{}
peerChan chan *p2p.Peer
}
// New returns role conversion service.
func New(peerChan chan *p2p.Peer) *Service {
return &Service{
stopChan: make(chan struct{}),
stoppedChan: make(chan struct{}),
peerChan: peerChan,
}
}
// StartService starts role conversion service.
func (s *Service) StartService() {
s.Init()
s.Run()
}
// Init initializes role conversion service.
func (s *Service) Init() {
}
// Run runs role conversion.
func (s *Service) Run() {
go func() {
defer close(s.stoppedChan)
for {
select {
default:
utils.GetLogInstance().Info("Running role conversion")
// TODO: Write some logic here.
s.DoService()
case <-s.stopChan:
return
}
}
}()
}
// DoService does role conversion.
func (s *Service) DoService() {
// At the end, send Peer info to peer channel
s.peerChan <- &p2p.Peer{}
}
// StopService stops role conversion service.
func (s *Service) StopService() {
utils.GetLogInstance().Info("Stopping role conversion service.")
s.stopChan <- struct{}{}
<-s.stoppedChan
utils.GetLogInstance().Info("Role conversion stopped.")
}