diff --git a/router/gossip.go b/router/gossip.go index bf954bf8..4e9e060d 100644 --- a/router/gossip.go +++ b/router/gossip.go @@ -244,3 +244,27 @@ func (c *GossipChannel) relayGossipBroadcast(srcName PeerName, msg []byte) error func (c *GossipChannel) log(args ...interface{}) { log.Println(append(append([]interface{}{}, "[gossip "+c.name+"]:"), args...)...) } + +// for testing + +// FIXME this doesn't actually guarantee everything has been sent +// since a GossipSender may be in the process of sending and there is +// no easy way for us to know when that has completed. +func (router *Router) sendPendingGossip() { + for _, channel := range router.GossipChannels { + for _, sender := range channel.senders { + sender.flush() + } + } +} + +func (sender *GossipSender) flush() { + for { + select { + case pending := <-sender.cell: + sender.send(pending) + default: + return + } + } +} diff --git a/router/gossip_test.go b/router/gossip_test.go index 66622193..6ce97ebb 100644 --- a/router/gossip_test.go +++ b/router/gossip_test.go @@ -32,28 +32,6 @@ func (conn *mockChannelConnection) SendProtocolMsg(protocolMsg ProtocolMsg) { conn.dest.sendPendingGossip() } -// FIXME this doesn't actually guarantee everything has been sent -// since a GossipSender may be in the process of sending and there is -// no easy way for us to know when that has completed. -func (router *Router) sendPendingGossip() { - for _, channel := range router.GossipChannels { - for _, sender := range channel.senders { - sender.flush() - } - } -} - -func (sender *GossipSender) flush() { - for { - select { - case pending := <-sender.cell: - sender.send(pending) - default: - return - } - } -} - func (router *Router) AddTestChannelConnection(r *Router) { fromName := router.Ourself.Peer.Name toName := r.Ourself.Peer.Name