From f6b4a9da1ca0bfc310614dff514ab256c30b04e9 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 12 Dec 2019 23:20:31 +0000 Subject: [PATCH] strip some code --- network/default.go | 25 ++++++++++++--------- tunnel/default.go | 55 ++++++---------------------------------------- 2 files changed, 22 insertions(+), 58 deletions(-) diff --git a/network/default.go b/network/default.go index 46cdcd4f..18baab4b 100644 --- a/network/default.go +++ b/network/default.go @@ -682,11 +682,6 @@ func (n *network) processCtrlChan(listener tunnel.Listener) { log.Tracef("Network router flushing routes for: %s", pbRtrSolicit.Id) - // advertise all the routes when a new node has connected - if err := n.router.Solicit(); err != nil { - log.Debugf("Network failed to solicit routes: %s", err) - } - peer := &node{ id: pbRtrSolicit.Id, link: m.msg.Header["Micro-Link"], @@ -698,6 +693,11 @@ func (n *network) processCtrlChan(listener tunnel.Listener) { default: // don't block } + + // advertise all the routes when a new node has connected + if err := n.router.Solicit(); err != nil { + log.Debugf("Network failed to solicit routes: %s", err) + } } case <-n.closed: return @@ -773,10 +773,7 @@ func (n *network) processNetChan(listener tunnel.Listener) { log.Debugf("Network failed to advertise peers: %v", err) } - // advertise all the routes when a new node has connected - if err := n.router.Solicit(); err != nil { - log.Debugf("Network failed to solicit routes: %s", err) - } + <-time.After(time.Millisecond * 100) // specify that we're soliciting select { @@ -784,6 +781,12 @@ func (n *network) processNetChan(listener tunnel.Listener) { default: // don't block } + + // advertise all the routes when a new node has connected + if err := n.router.Solicit(); err != nil { + log.Debugf("Network failed to solicit routes: %s", err) + } + }() case "peer": // mark the time the message has been received @@ -829,7 +832,7 @@ func (n *network) processNetChan(listener tunnel.Listener) { } // wait for a second - <-time.After(time.Second) + <-time.After(time.Millisecond * 100) // then solicit this peer if err := n.sendTo("solicit", ControlChannel, peer, msg); err != nil { @@ -1373,6 +1376,7 @@ func (n *network) Close() error { default: // TODO: send close message to the network channel close(n.closed) + // set connected to false n.connected = false @@ -1389,6 +1393,7 @@ func (n *network) Close() error { if err := n.sendMsg("close", NetworkChannel, msg); err != nil { log.Debugf("Network failed to send close message: %s", err) } + <-time.After(time.Millisecond * 100) } return n.close() diff --git a/tunnel/default.go b/tunnel/default.go index 83c85a64..c8927404 100644 --- a/tunnel/default.go +++ b/tunnel/default.go @@ -42,9 +42,6 @@ type tun struct { // close channel closed chan bool - // control channel to indicate link change - updated chan bool - // a map of sessions based on Micro-Tunnel-Channel sessions map[string]*session @@ -266,7 +263,6 @@ func (t *tun) manageLink(link *link) { // manageLinks is a function that can be called to immediately to link setup // it purges dead links while generating new links for any nodes not connected func (t *tun) manageLinks() { - // if we need to notify of updates delLinks := make(map[*link]string) connected := make(map[string]bool) @@ -323,9 +319,6 @@ func (t *tun) manageLinks() { } t.Unlock() - - // links were deleted so notify - go t.notify() } var wg sync.WaitGroup @@ -359,9 +352,6 @@ func (t *tun) manageLinks() { t.links[node] = link t.Unlock() - - // notify ourselves of the change - go t.notify() }(node) } @@ -371,17 +361,6 @@ func (t *tun) manageLinks() { // process outgoing messages sent by all local sessions func (t *tun) process() { - // wait for the first update - <-t.updated - - // get the list of links - var links []*link - t.RLock() - for _, link := range t.links { - links = append(links, link) - } - t.RUnlock() - // manage the send buffer // all pseudo sessions throw everything down this for { @@ -391,8 +370,10 @@ func (t *tun) process() { var sendTo []*link var err error + t.RLock() + // build the list of links ot send to - for _, link := range links { + for _, link := range t.links { // get the values we need link.RLock() id := link.id @@ -443,6 +424,8 @@ func (t *tun) process() { sendTo = append(sendTo, link) } + t.RUnlock() + // no links to send to if len(sendTo) == 0 { log.Debugf("No links to send message type: %s channel: %s", msg.typ, msg.channel) @@ -452,15 +435,6 @@ func (t *tun) process() { // send the message t.sendTo(sendTo, msg) - case <-t.updated: - t.RLock() - var newLinks []*link - for _, link := range t.links { - newLinks = append(newLinks, link) - } - t.RUnlock() - // links were updated - links = newLinks case <-t.closed: return } @@ -582,18 +556,6 @@ func (t *tun) delLink(remote string) { } t.Unlock() - - // let ourselves know of a link change - go t.notify() -} - -// notify ourselves of a link change -func (t *tun) notify() { - select { - case t.updated <- true: - // unblock after a second - case <-time.After(time.Second): - } } // process incoming messages @@ -670,8 +632,6 @@ func (t *tun) listen(link *link) { t.links[link.Remote()] = link t.Unlock() - // notify of link change - go t.notify() // send back an announcement of our channels discovery go t.announce("", "", link) // ask for the things on the other wise @@ -691,6 +651,8 @@ func (t *tun) listen(link *link) { // remove the channel mapping for it. should we also close sessions? if sessionId == "listener" { link.delChannel(channel) + // TODO: find all the non listener unicast sessions + // and close them. think aboud edge cases first continue } @@ -949,9 +911,6 @@ func (t *tun) setupLinks() { // wait for all threads to finish wg.Wait() - - // notify ourselves of the update - t.notify() } // connect the tunnel to all the nodes and listen for incoming tunnel connections