refactor: tweak GossipChannel API
This commit is contained in:
1 parent
6c4e9fccd3
commit
592335092c
2 files changed
+12
-3
No files matched your search
+1
-1
@@ -133,7 +133,7 @@ func (router *Router) gossipChannelSet() map[*GossipChannel]struct{} {
|
|||||||
func (router *Router) SendAllGossip() {
|
func (router *Router) SendAllGossip() {
|
||||||
for channel := range router.gossipChannelSet() {
|
for channel := range router.gossipChannelSet() {
|
||||||
if gossip := channel.gossiper.Gossip(); gossip != nil {
|
if gossip := channel.gossiper.Gossip(); gossip != nil {
|
||||||
channel.Send(router.Ourself.Name, gossip)
|
channel.Send(gossip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-2
@@ -94,7 +94,7 @@ func (c *GossipChannel) deliver(srcName PeerName, _ []byte, dec *gob.Decoder) er
|
|||||||
if err != nil || update == nil {
|
if err != nil || update == nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
c.Send(srcName, update)
|
c.relay(srcName, update)
|
||||||
return nil
|
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()
|
c.routes.EnsureRecalculated()
|
||||||
destinations := c.routes.RandomNeighbours(srcName)
|
destinations := c.routes.RandomNeighbours(srcName)
|
||||||
if len(destinations) == 0 {
|
if len(destinations) == 0 {
|
||||||
@@ -174,6 +174,15 @@ func (c *GossipChannel) Send(srcName PeerName, data GossipData) {
|
|||||||
c.sendDown(c.ourself.ConnectionsTo(destinations), data)
|
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) {
|
func (c *GossipChannel) SendDown(conn Connection, data GossipData) {
|
||||||
c.sendDown([]Connection{conn}, data)
|
c.sendDown([]Connection{conn}, data)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user