refactor: relocate an optimisation -> reduce duplication
This commit is contained in:
1 parent
5473995305
commit
f58e3bf2a9
2 files changed
+7
-13
No files matched your search
+4
-13
@@ -151,11 +151,10 @@ func (c *GossipChannel) relayBroadcast(srcName PeerName, update GossipData) erro
|
|||||||
|
|
||||||
func (c *GossipChannel) sendBroadcast(srcName PeerName, update GossipData) {
|
func (c *GossipChannel) sendBroadcast(srcName PeerName, update GossipData) {
|
||||||
c.routes.EnsureRecalculated()
|
c.routes.EnsureRecalculated()
|
||||||
nextHops := c.routes.BroadcastAll(srcName)
|
connections := c.ourself.ConnectionsTo(c.routes.BroadcastAll(srcName))
|
||||||
if len(nextHops) == 0 {
|
if len(connections) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
connections := c.ourself.ConnectionsTo(nextHops)
|
|
||||||
for _, msg := range update.Encode() {
|
for _, msg := range update.Encode() {
|
||||||
protocolMsg := ProtocolMsg{ProtocolGossipBroadcast, GobEncode(c.name, srcName, msg)}
|
protocolMsg := ProtocolMsg{ProtocolGossipBroadcast, GobEncode(c.name, srcName, msg)}
|
||||||
// FIXME a single blocked connection can stall us
|
// FIXME a single blocked connection can stall us
|
||||||
@@ -167,20 +166,12 @@ func (c *GossipChannel) sendBroadcast(srcName PeerName, update GossipData) {
|
|||||||
|
|
||||||
func (c *GossipChannel) relay(srcName PeerName, data GossipData) {
|
func (c *GossipChannel) relay(srcName PeerName, data GossipData) {
|
||||||
c.routes.EnsureRecalculated()
|
c.routes.EnsureRecalculated()
|
||||||
destinations := c.routes.RandomNeighbours(srcName)
|
c.sendDown(c.ourself.ConnectionsTo(c.routes.RandomNeighbours(srcName)), data)
|
||||||
if len(destinations) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
c.sendDown(c.ourself.ConnectionsTo(destinations), data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *GossipChannel) Send(data GossipData) {
|
func (c *GossipChannel) Send(data GossipData) {
|
||||||
c.routes.EnsureRecalculated()
|
c.routes.EnsureRecalculated()
|
||||||
destinations := c.routes.RandomNeighbours(c.ourself.Name)
|
c.sendDown(c.ourself.ConnectionsTo(c.routes.RandomNeighbours(c.ourself.Name)), data)
|
||||||
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) {
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ func (peer *LocalPeer) ConnectionTo(name PeerName) (Connection, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (peer *LocalPeer) ConnectionsTo(names []PeerName) []Connection {
|
func (peer *LocalPeer) ConnectionsTo(names []PeerName) []Connection {
|
||||||
|
if len(names) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
conns := make([]Connection, 0, len(names))
|
conns := make([]Connection, 0, len(names))
|
||||||
peer.RLock()
|
peer.RLock()
|
||||||
defer peer.RUnlock()
|
defer peer.RUnlock()
|
||||||
|
|||||||
Reference in new issue
Block a user