mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	Support removing Listen interfaces at runtime properly
This commit is contained in:
		
							parent
							
								
									18ef28a477
								
							
						
					
					
						commit
						b8cabf3212
					
				
					 2 changed files with 18 additions and 11 deletions
				
			
		| 
						 | 
				
			
			@ -149,11 +149,11 @@ func (m *multicast) announce() {
 | 
			
		|||
				if l, ok := m.listeners[iface.Name]; !ok || l.listener == nil {
 | 
			
		||||
					// No listener was found - let's create one
 | 
			
		||||
					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)
 | 
			
		||||
						// Store the listener so that we can stop it later if needed
 | 
			
		||||
						m.listeners[iface.Name] = l
 | 
			
		||||
						listener = l
 | 
			
		||||
						m.listeners[iface.Name] = li
 | 
			
		||||
						listener = li
 | 
			
		||||
					}
 | 
			
		||||
				} else {
 | 
			
		||||
					// An existing listener was found
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,7 +16,6 @@ package yggdrasil
 | 
			
		|||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"math/rand"
 | 
			
		||||
	"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)
 | 
			
		||||
			t.link.core.configMutex.RUnlock()
 | 
			
		||||
			if len(added) > 0 || len(deleted) > 0 {
 | 
			
		||||
				for _, add := range added {
 | 
			
		||||
					if add[:6] != "tcp://" {
 | 
			
		||||
						e <- errors.New("unknown scheme: " + add)
 | 
			
		||||
				for _, a := range added {
 | 
			
		||||
					if a[:6] != "tcp://" {
 | 
			
		||||
						continue
 | 
			
		||||
					}
 | 
			
		||||
					if _, err := t.listen(add[6:]); err != nil {
 | 
			
		||||
					if _, err := t.listen(a[6:]); err != nil {
 | 
			
		||||
						e <- err
 | 
			
		||||
						continue
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
				for _, delete := range deleted {
 | 
			
		||||
					t.link.core.log.Warnln("Removing listener", delete, "not currently implemented")
 | 
			
		||||
				for _, d := range deleted {
 | 
			
		||||
					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
 | 
			
		||||
			} else {
 | 
			
		||||
| 
						 | 
				
			
			@ -134,7 +141,7 @@ func (t *tcp) listen(listenaddr string) (*tcpListener, error) {
 | 
			
		|||
			listener: listener,
 | 
			
		||||
			stop:     make(chan bool),
 | 
			
		||||
		}
 | 
			
		||||
		go t.listener(&l, listenaddr[6:])
 | 
			
		||||
		go t.listener(&l, listenaddr)
 | 
			
		||||
		return &l, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue