refactor: tweak GossipChannel API

This commit is contained in:
Matthias Radestock committed 2015-12-21 17:42:20 +00:00
1 parent 6c4e9fccd3
commit 592335092c
2 files changed
+12 -3

No files matched your search

+1 -1
View File
@@ -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)
}
}
}
+11 -2
View File
@@ -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)
}