Commit 9b6566e9 authored by Petar Radovic's avatar Petar Radovic

implemented hive ticker

parent d8bbb8bc
......@@ -5,8 +5,12 @@
package hive
import (
"sync"
"time"
"github.com/ethersphere/bee/pkg/logging"
"github.com/ethersphere/bee/pkg/p2p"
"github.com/ethersphere/bee/pkg/swarm"
)
const (
......@@ -18,17 +22,34 @@ const (
type Service struct {
streamer p2p.Streamer
logger logging.Logger
tickInterval time.Duration
done chan struct{}
wg sync.WaitGroup
}
type Options struct {
Streamer p2p.Streamer
Logger logging.Logger
Streamer p2p.Streamer
Logger logging.Logger
TickInterval time.Duration
}
// PeerSuggester suggests a peer to connect to
type PeerSuggester interface {
SuggestPeer(addr swarm.Address) (peerAddress swarm.Address, err error)
}
// SaturationTracker tracks weather the saturation has changed
type SaturationTracker interface {
SaturationChanged() (saturationDepth int, changed bool)
}
func New(o Options) *Service {
return &Service{
streamer: o.Streamer,
logger: o.Logger,
streamer: o.Streamer,
logger: o.Logger,
tickInterval: o.TickInterval,
done: make(chan struct{}),
}
}
......@@ -45,6 +66,36 @@ func (s *Service) Protocol() p2p.ProtocolSpec {
}
}
func (s *Service) Start() error {
s.wg.Add(1)
go func() {
t := time.NewTicker(s.tickInterval)
defer t.Stop()
defer s.wg.Done()
for {
select {
case <-t.C:
s.hive()
case <-s.done:
return
}
}
}()
return nil
}
func (s *Service) Stop() error {
close(s.done)
s.wg.Wait()
return nil
}
func (s *Service) Handler(peer p2p.Peer, stream p2p.Stream) error {
return nil
}
func (s *Service) hive() {
// todo:
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment