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