Shorten multicast discovery
This commit is contained in:
parent
d198765c6c
commit
1527a84297
@ -951,27 +951,39 @@ func (t *tun) Dial(channel string, opts ...DialOption) (Session, error) {
|
|||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
// set a dialTimeout
|
||||||
|
dialTimeout := after()
|
||||||
|
|
||||||
|
// set a shorter delay for multicast
|
||||||
|
if c.multicast {
|
||||||
|
// shorten this
|
||||||
|
dialTimeout = time.Millisecond * 500
|
||||||
|
}
|
||||||
|
|
||||||
// wait for announce
|
// wait for announce
|
||||||
select {
|
select {
|
||||||
case msg := <-c.recv:
|
case msg := <-c.recv:
|
||||||
if msg.typ != "announce" {
|
if msg.typ != "announce" {
|
||||||
err = errors.New("failed to discover channel")
|
err = errors.New("failed to discover channel")
|
||||||
}
|
}
|
||||||
case <-time.After(after()):
|
case <-time.After(dialTimeout):
|
||||||
err = ErrDialTimeout
|
err = ErrDialTimeout
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't both sending the error for multicast
|
// if its multicast just go ahead because this is best effort
|
||||||
// we're just going to assume things come online
|
if c.multicast {
|
||||||
if err == nil || c.multicast {
|
|
||||||
c.discovered = true
|
c.discovered = true
|
||||||
|
c.accepted = true
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the error if unicast
|
// otherwise return an error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set discovered to true
|
||||||
|
c.discovered = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// a unicast session so we call "open" and wait for an "accept"
|
// a unicast session so we call "open" and wait for an "accept"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user