eliminate dependency on LocalPeer.Router
(from things outside LocalPeer)
This commit is contained in:
1 parent
2ba8f34132
commit
f3d20111d8
2 files changed
+12
-6
No files matched your search
+8
-6
@@ -83,6 +83,7 @@ type peerSenders map[PeerName]*GossipSender
|
|||||||
type GossipChannel struct {
|
type GossipChannel struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
ourself *LocalPeer
|
ourself *LocalPeer
|
||||||
|
routes *Routes
|
||||||
name string
|
name string
|
||||||
hash uint32
|
hash uint32
|
||||||
gossiper Gossiper
|
gossiper Gossiper
|
||||||
@@ -94,6 +95,7 @@ func (router *Router) NewGossip(channelName string, g Gossiper) Gossip {
|
|||||||
channelHash := hash(channelName)
|
channelHash := hash(channelName)
|
||||||
channel := &GossipChannel{
|
channel := &GossipChannel{
|
||||||
ourself: router.Ourself,
|
ourself: router.Ourself,
|
||||||
|
routes: router.Routes,
|
||||||
name: channelName,
|
name: channelName,
|
||||||
hash: channelHash,
|
hash: channelHash,
|
||||||
gossiper: g,
|
gossiper: g,
|
||||||
@@ -182,9 +184,9 @@ func (c *GossipChannel) deliver(srcName PeerName, _ []byte, dec *gob.Decoder) er
|
|||||||
|
|
||||||
func (c *GossipChannel) Send(srcName PeerName, data GossipData) {
|
func (c *GossipChannel) Send(srcName PeerName, data GossipData) {
|
||||||
// do this outside the lock below so we avoid lock nesting
|
// do this outside the lock below so we avoid lock nesting
|
||||||
c.ourself.Router.Routes.EnsureRecalculated()
|
c.routes.EnsureRecalculated()
|
||||||
selectedConnections := make(ConnectionSet)
|
selectedConnections := make(ConnectionSet)
|
||||||
for name := range c.ourself.Router.Routes.RandomNeighbours(srcName) {
|
for name := range c.routes.RandomNeighbours(srcName) {
|
||||||
if conn, found := c.ourself.ConnectionTo(name); found {
|
if conn, found := c.ourself.ConnectionTo(name); found {
|
||||||
selectedConnections[conn] = void
|
selectedConnections[conn] = void
|
||||||
}
|
}
|
||||||
@@ -247,7 +249,7 @@ func (c *GossipChannel) GossipBroadcast(update GossipData) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *GossipChannel) relayUnicast(dstPeerName PeerName, buf []byte) error {
|
func (c *GossipChannel) relayUnicast(dstPeerName PeerName, buf []byte) error {
|
||||||
if relayPeerName, found := c.ourself.Router.Routes.UnicastAll(dstPeerName); !found {
|
if relayPeerName, found := c.routes.UnicastAll(dstPeerName); !found {
|
||||||
c.log("unknown relay destination:", dstPeerName)
|
c.log("unknown relay destination:", dstPeerName)
|
||||||
} else if conn, found := c.ourself.ConnectionTo(relayPeerName); !found {
|
} else if conn, found := c.ourself.ConnectionTo(relayPeerName); !found {
|
||||||
c.log("unable to find connection to relay peer", relayPeerName)
|
c.log("unable to find connection to relay peer", relayPeerName)
|
||||||
@@ -258,7 +260,7 @@ func (c *GossipChannel) relayUnicast(dstPeerName PeerName, buf []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *GossipChannel) relayBroadcast(srcName PeerName, update GossipData) error {
|
func (c *GossipChannel) relayBroadcast(srcName PeerName, update GossipData) error {
|
||||||
names := c.ourself.Router.Peers.Names() // do this outside the lock so they don't nest
|
names := c.routes.PeerNames() // do this outside the lock so they don't nest
|
||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
// GC - randomly (courtesy of go's map iterator) pick some
|
// GC - randomly (courtesy of go's map iterator) pick some
|
||||||
@@ -291,8 +293,8 @@ 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.ourself.Router.Routes.EnsureRecalculated()
|
c.routes.EnsureRecalculated()
|
||||||
nextHops := c.ourself.Router.Routes.BroadcastAll(srcName)
|
nextHops := c.routes.BroadcastAll(srcName)
|
||||||
if len(nextHops) == 0 {
|
if len(nextHops) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,10 @@ func (routes *Routes) Start() {
|
|||||||
go routes.run(recalculate, wait)
|
go routes.run(recalculate, wait)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (routes *Routes) PeerNames() PeerNameSet {
|
||||||
|
return routes.peers.Names()
|
||||||
|
}
|
||||||
|
|
||||||
func (routes *Routes) Unicast(name PeerName) (PeerName, bool) {
|
func (routes *Routes) Unicast(name PeerName) (PeerName, bool) {
|
||||||
routes.RLock()
|
routes.RLock()
|
||||||
defer routes.RUnlock()
|
defer routes.RUnlock()
|
||||||
|
|||||||
Reference in new issue
Block a user