Eliminate the Routes Start method

This commit is contained in:
David Wragg committed 2015-06-12 16:11:32 +01:00
1 parent b1308823d2
commit 32b2bcf01b
3 files changed
+8 -15

No files matched your search

+2 -5
View File
@@ -17,11 +17,8 @@ type mockChannelConnection struct {
// Construct a "passive" Router, i.e. without any goroutines, except // Construct a "passive" Router, i.e. without any goroutines, except
// for Routes and GossipSenders. // for Routes and GossipSenders.
func NewTestRouter(name PeerName) *Router { func NewTestRouter(name PeerName) *Router {
router := NewRouter(RouterConfig{}, name, "") router := NewRouter(RouterConfig{}, name, "nick")
// need to create a dummy channel otherwise tests hang on nil router.Start()
// channels when the Router invoked ConnectionMaker.Refresh
router.ConnectionMaker.actionChan = make(chan ConnectionMakerAction, ChannelSize)
router.Routes.Start()
return router return router
} }
-1
View File
@@ -83,7 +83,6 @@ func (router *Router) Start() {
po, err = NewPcapO(router.Iface.Name) po, err = NewPcapO(router.Iface.Name)
checkFatal(err) checkFatal(err)
} }
router.Routes.Start()
router.ConnectionMaker.Start() router.ConnectionMaker.Start()
router.UDPListener = router.listenUDP(router.Port, po) router.UDPListener = router.listenUDP(router.Port, po)
router.listenTCP(router.Port) router.listenTCP(router.Port)
+6 -9
View File
@@ -22,26 +22,23 @@ type Routes struct {
} }
func NewRoutes(ourself *LocalPeer, peers *Peers) *Routes { func NewRoutes(ourself *LocalPeer, peers *Peers) *Routes {
recalculate := make(chan *struct{}, 1)
wait := make(chan chan struct{})
routes := &Routes{ routes := &Routes{
ourself: ourself, ourself: ourself,
peers: peers, peers: peers,
unicast: make(map[PeerName]PeerName), unicast: make(map[PeerName]PeerName),
unicastAll: make(map[PeerName]PeerName), unicastAll: make(map[PeerName]PeerName),
broadcast: make(map[PeerName][]PeerName), broadcast: make(map[PeerName][]PeerName),
broadcastAll: make(map[PeerName][]PeerName)} broadcastAll: make(map[PeerName][]PeerName),
recalculate: recalculate,
wait: wait}
routes.unicast[ourself.Name] = UnknownPeerName routes.unicast[ourself.Name] = UnknownPeerName
routes.unicastAll[ourself.Name] = UnknownPeerName routes.unicastAll[ourself.Name] = UnknownPeerName
routes.broadcast[ourself.Name] = []PeerName{} routes.broadcast[ourself.Name] = []PeerName{}
routes.broadcastAll[ourself.Name] = []PeerName{} routes.broadcastAll[ourself.Name] = []PeerName{}
return routes
}
func (routes *Routes) Start() {
recalculate := make(chan *struct{}, 1)
wait := make(chan chan struct{})
routes.recalculate = recalculate
routes.wait = wait
go routes.run(recalculate, wait) go routes.run(recalculate, wait)
return routes
} }
func (routes *Routes) PeerNames() PeerNameSet { func (routes *Routes) PeerNames() PeerNameSet {