mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-10 06:20:26 +00:00
Support removing Listen interfaces at runtime properly
This commit is contained in:
parent
18ef28a477
commit
b8cabf3212
@ -149,11 +149,11 @@ func (m *multicast) announce() {
|
|||||||
if l, ok := m.listeners[iface.Name]; !ok || l.listener == nil {
|
if l, ok := m.listeners[iface.Name]; !ok || l.listener == nil {
|
||||||
// No listener was found - let's create one
|
// No listener was found - let's create one
|
||||||
listenaddr := fmt.Sprintf("[%s%%%s]:0", addrIP, iface.Name)
|
listenaddr := fmt.Sprintf("[%s%%%s]:0", addrIP, iface.Name)
|
||||||
if l, err := m.core.link.tcp.listen(listenaddr); err == nil {
|
if li, err := m.core.link.tcp.listen(listenaddr); err == nil {
|
||||||
m.core.log.Debugln("Started multicasting on", iface.Name)
|
m.core.log.Debugln("Started multicasting on", iface.Name)
|
||||||
// Store the listener so that we can stop it later if needed
|
// Store the listener so that we can stop it later if needed
|
||||||
m.listeners[iface.Name] = l
|
m.listeners[iface.Name] = li
|
||||||
listener = l
|
listener = li
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// An existing listener was found
|
// An existing listener was found
|
||||||
|
@ -16,7 +16,6 @@ package yggdrasil
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
@ -87,18 +86,26 @@ func (t *tcp) init(l *link) error {
|
|||||||
deleted := util.Difference(t.link.core.configOld.Listen, t.link.core.config.Listen)
|
deleted := util.Difference(t.link.core.configOld.Listen, t.link.core.config.Listen)
|
||||||
t.link.core.configMutex.RUnlock()
|
t.link.core.configMutex.RUnlock()
|
||||||
if len(added) > 0 || len(deleted) > 0 {
|
if len(added) > 0 || len(deleted) > 0 {
|
||||||
for _, add := range added {
|
for _, a := range added {
|
||||||
if add[:6] != "tcp://" {
|
if a[:6] != "tcp://" {
|
||||||
e <- errors.New("unknown scheme: " + add)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if _, err := t.listen(add[6:]); err != nil {
|
if _, err := t.listen(a[6:]); err != nil {
|
||||||
e <- err
|
e <- err
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, delete := range deleted {
|
for _, d := range deleted {
|
||||||
t.link.core.log.Warnln("Removing listener", delete, "not currently implemented")
|
if d[:6] != "tcp://" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
t.mutex.Lock()
|
||||||
|
if listener, ok := t.listeners[d[6:]]; ok {
|
||||||
|
t.mutex.Unlock()
|
||||||
|
listener.stop <- true
|
||||||
|
} else {
|
||||||
|
t.mutex.Unlock()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
e <- nil
|
e <- nil
|
||||||
} else {
|
} else {
|
||||||
@ -134,7 +141,7 @@ func (t *tcp) listen(listenaddr string) (*tcpListener, error) {
|
|||||||
listener: listener,
|
listener: listener,
|
||||||
stop: make(chan bool),
|
stop: make(chan bool),
|
||||||
}
|
}
|
||||||
go t.listener(&l, listenaddr[6:])
|
go t.listener(&l, listenaddr)
|
||||||
return &l, nil
|
return &l, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user