get rid of GossipSender gc

With the per-broadcast-source GossipSenders gone, we can get rid of
GossipSender gc...

Instead of maintaining a Connection->GossipSender map in the
GossipChannels - which we then need to gc when connections get closed
- we keep gossip_channel_name->GossipSender maps in LocalConnections.

Access to the map is guarded by a separate lock, rather than re-using
the LocalConnection lock. This reduces lock contention and risk of
deadlock.

In the GossipSenders, we replace the Stop() method with a signalling
channel, i.e. senders stop when that channel gets closed. Handily, the
LocalConnection.finished channel fits that description. So when a
LocalConnection's run loop terminates, any existing and future
associated GossipSenders will end up terminating too.
This commit is contained in:
Matthias Radestock committed 2016-01-06 17:38:40 +00:00
1 parent bbd0b15792
commit 969dc4e527
4 files changed
+61 -53

No files matched your search

+12 -3
View File
@@ -13,8 +13,9 @@ import (
type MockGossipConnection struct {
RemoteConnection
dest *Router
start chan struct{}
dest *Router
gossipSenders *GossipSenders
start chan struct{}
}
func NewTestRouter(name string) *Router {
@@ -29,6 +30,10 @@ func (conn *MockGossipConnection) SendProtocolMsg(protocolMsg ProtocolMsg) error
return conn.dest.handleGossip(protocolMsg.tag, protocolMsg.msg)
}
func (conn *MockGossipConnection) GossipSenders() *GossipSenders {
return conn.gossipSenders
}
func (conn *MockGossipConnection) Start() {
close(conn.start)
}
@@ -56,7 +61,11 @@ func (router *Router) NewTestGossipConnection(r *Router) *MockGossipConnection {
toPeer = router.Peers.FetchWithDefault(toPeer) // Has side-effect of incrementing refcount
conn := &MockGossipConnection{
RemoteConnection{router.Ourself.Peer, toPeer, "", false, true}, r, make(chan struct{})}
RemoteConnection: RemoteConnection{router.Ourself.Peer, toPeer, "", false, true},
dest: r,
start: make(chan struct{}),
}
conn.gossipSenders = NewGossipSenders(conn, make(chan struct{}))
router.Ourself.handleAddConnection(conn)
router.Ourself.handleConnectionEstablished(conn)
return conn