Skip to content

Commit

Permalink
adds method to get gossip interval from router object's config
Browse files Browse the repository at this point in the history
  • Loading branch information
murali-reddy committed Jun 6, 2019
1 parent 54557d4 commit e586672
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
8 changes: 3 additions & 5 deletions local_peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,9 @@ func (peer *localPeer) encode(enc *gob.Encoder) {
// ACTOR server

func (peer *localPeer) actorLoop(actionChan <-chan localPeerAction) {
var gossipInterval time.Duration
if peer.router != nil && peer.router.Config.GossipInterval != nil {
gossipInterval = *peer.router.Config.GossipInterval
} else {
gossipInterval = defaultGossipInterval
gossipInterval := defaultGossipInterval
if peer.router != nil {
gossipInterval = peer.router.gossipInterval()
}
gossipTimer := time.Tick(gossipInterval)

Expand Down
11 changes: 8 additions & 3 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ func NewRouter(config Config, name PeerName, nickName string, overlay Overlay, l
}
router.topologyGossip = gossip
router.acceptLimiter = newTokenBucket(acceptMaxTokens, acceptTokenDelay)
if router.Config.GossipInterval == nil {
router.Config.GossipInterval = &defaultGossipInterval
}
return router, nil
}

Expand Down Expand Up @@ -175,6 +172,14 @@ func (router *Router) gossipChannelSet() map[*gossipChannel]struct{} {
return channels
}

func (router *Router) gossipInterval() time.Duration {
if router.Config.GossipInterval != nil {
return *router.Config.GossipInterval
} else {
return defaultGossipInterval
}
}

func (router *Router) handleGossip(tag protocolTag, payload []byte) error {
decoder := gob.NewDecoder(bytes.NewReader(payload))
var channelName string
Expand Down
9 changes: 4 additions & 5 deletions surrogate_gossiper.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ func (s *surrogateGossiper) OnGossip(update []byte) (GossipData, error) {
// (this time limit is arbitrary; surrogateGossiper should pass on new gossip immediately
// so there should be no reason for a duplicate to show up after a long time)
updateTime := now()
var deleteBefore time.Time
if s.router != nil && s.router.Config.GossipInterval != nil {
deleteBefore = updateTime.Add(-*s.router.Config.GossipInterval)
} else {
deleteBefore = updateTime.Add(-defaultGossipInterval)
gossipInterval := defaultGossipInterval
if s.router != nil {
gossipInterval = s.router.gossipInterval()
}
deleteBefore := updateTime.Add(-gossipInterval)
keepFrom := len(s.prevUpdates)
for i, p := range s.prevUpdates {
if p.t.After(deleteBefore) {
Expand Down

0 comments on commit e586672

Please sign in to comment.