From 592335092c869dc14660df375cfd5a39aed117bb Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Mon, 21 Dec 2015 17:42:20 +0000 Subject: [PATCH] refactor: tweak GossipChannel API --- mesh/gossip.go | 2 +- mesh/gossip_channel.go | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/mesh/gossip.go b/mesh/gossip.go index 2b3a4807..b66cb26d 100644 --- a/mesh/gossip.go +++ b/mesh/gossip.go @@ -133,7 +133,7 @@ func (router *Router) gossipChannelSet() map[*GossipChannel]struct{} { func (router *Router) SendAllGossip() { for channel := range router.gossipChannelSet() { if gossip := channel.gossiper.Gossip(); gossip != nil { - channel.Send(router.Ourself.Name, gossip) + channel.Send(gossip) } } } diff --git a/mesh/gossip_channel.go b/mesh/gossip_channel.go index 5efb4914..0f35bfd3 100644 --- a/mesh/gossip_channel.go +++ b/mesh/gossip_channel.go @@ -94,7 +94,7 @@ func (c *GossipChannel) deliver(srcName PeerName, _ []byte, dec *gob.Decoder) er if err != nil || update == nil { return err } - c.Send(srcName, update) + c.relay(srcName, update) return nil } @@ -165,7 +165,7 @@ func (c *GossipChannel) sendBroadcast(srcName PeerName, update GossipData) { } } -func (c *GossipChannel) Send(srcName PeerName, data GossipData) { +func (c *GossipChannel) relay(srcName PeerName, data GossipData) { c.routes.EnsureRecalculated() destinations := c.routes.RandomNeighbours(srcName) if len(destinations) == 0 { @@ -174,6 +174,15 @@ func (c *GossipChannel) Send(srcName PeerName, data GossipData) { c.sendDown(c.ourself.ConnectionsTo(destinations), data) } +func (c *GossipChannel) Send(data GossipData) { + c.routes.EnsureRecalculated() + destinations := c.routes.RandomNeighbours(c.ourself.Name) + if len(destinations) == 0 { + return + } + c.sendDown(c.ourself.ConnectionsTo(destinations), data) +} + func (c *GossipChannel) SendDown(conn Connection, data GossipData) { c.sendDown([]Connection{conn}, data) }