Make sure we pick some link when Dialling
This commit is contained in:
		| @@ -984,11 +984,10 @@ func (t *tun) Dial(channel string, opts ...DialOption) (Session, error) { | |||||||
| 	var measured bool | 	var measured bool | ||||||
|  |  | ||||||
| 	// non multicast so we need to find the link | 	// non multicast so we need to find the link | ||||||
| 	if id := options.Link; id != "" { |  | ||||||
| 	t.RLock() | 	t.RLock() | ||||||
| 	for _, link := range t.links { | 	for _, link := range t.links { | ||||||
| 		// use the link specified it its available | 		// use the link specified it its available | ||||||
| 			if link.id != id { | 		if id := options.Link; len(id) > 0 && link.id != id { | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @@ -1004,14 +1003,13 @@ func (t *tun) Dial(channel string, opts ...DialOption) (Session, error) { | |||||||
| 	} | 	} | ||||||
| 	t.RUnlock() | 	t.RUnlock() | ||||||
| 	// link not found | 	// link not found | ||||||
| 		if len(links) == 0 { | 	if len(links) == 0 && len(options.Link) > 0 { | ||||||
| 		// delete session and return error | 		// delete session and return error | ||||||
| 		t.delSession(c.channel, c.session) | 		t.delSession(c.channel, c.session) | ||||||
|  | 		log.Debugf("Tunnel deleting session %s %s: %v", c.session, c.channel, ErrLinkNotFound) | ||||||
| 		return nil, ErrLinkNotFound | 		return nil, ErrLinkNotFound | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	// discovered so set the link if not multicast | 	// discovered so set the link if not multicast | ||||||
| 	// TODO: pick the link efficiently based | 	// TODO: pick the link efficiently based | ||||||
| 	// on link status and saturation. | 	// on link status and saturation. | ||||||
| @@ -1038,10 +1036,12 @@ func (t *tun) Dial(channel string, opts ...DialOption) (Session, error) { | |||||||
| 		select { | 		select { | ||||||
| 		case <-time.After(after()): | 		case <-time.After(after()): | ||||||
| 			t.delSession(c.channel, c.session) | 			t.delSession(c.channel, c.session) | ||||||
|  | 			log.Debugf("Tunnel deleting session %s %s: %v", c.session, c.channel, ErrDialTimeout) | ||||||
| 			return nil, ErrDialTimeout | 			return nil, ErrDialTimeout | ||||||
| 		case err := <-c.errChan: | 		case err := <-c.errChan: | ||||||
| 			if err != nil { | 			if err != nil { | ||||||
| 				t.delSession(c.channel, c.session) | 				t.delSession(c.channel, c.session) | ||||||
|  | 				log.Debugf("Tunnel deleting session %s %s: %v", c.session, c.channel, err) | ||||||
| 				return nil, err | 				return nil, err | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| @@ -1077,6 +1077,7 @@ func (t *tun) Dial(channel string, opts ...DialOption) (Session, error) { | |||||||
| 		// otherwise return an error | 		// otherwise return an error | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			t.delSession(c.channel, c.session) | 			t.delSession(c.channel, c.session) | ||||||
|  | 			log.Debugf("Tunnel deleting session %s %s: %v", c.session, c.channel, err) | ||||||
| 			return nil, err | 			return nil, err | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @@ -1109,6 +1110,7 @@ func (t *tun) Dial(channel string, opts ...DialOption) (Session, error) { | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		// delete the session | 		// delete the session | ||||||
| 		t.delSession(c.channel, c.session) | 		t.delSession(c.channel, c.session) | ||||||
|  | 		log.Debugf("Tunnel deleting session %s %s: %v", c.session, c.channel, err) | ||||||
| 		return nil, err | 		return nil, err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user