mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	Merge branch 'master' of https://github.com/yggdrasil-network/yggdrasil-go into develop
This commit is contained in:
		
						commit
						f30d040366
					
				
					 2 changed files with 36 additions and 31 deletions
				
			
		| 
						 | 
					@ -175,7 +175,7 @@ func (a *admin) init(c *Core, listenaddr string) {
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
	a.addHandler("getMulticastInterfaces", []string{}, func(in admin_info) (admin_info, error) {
 | 
						a.addHandler("getMulticastInterfaces", []string{}, func(in admin_info) (admin_info, error) {
 | 
				
			||||||
		var intfs []string
 | 
							var intfs []string
 | 
				
			||||||
		for _, v := range a.core.multicast.interfaces {
 | 
							for _, v := range a.core.multicast.interfaces() {
 | 
				
			||||||
			intfs = append(intfs, v.Name)
 | 
								intfs = append(intfs, v.Name)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return admin_info{"multicast_interfaces": intfs}, nil
 | 
							return admin_info{"multicast_interfaces": intfs}, nil
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,10 +7,9 @@ import "fmt"
 | 
				
			||||||
import "golang.org/x/net/ipv6"
 | 
					import "golang.org/x/net/ipv6"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type multicast struct {
 | 
					type multicast struct {
 | 
				
			||||||
	core       *Core
 | 
						core      *Core
 | 
				
			||||||
	sock       *ipv6.PacketConn
 | 
						sock      *ipv6.PacketConn
 | 
				
			||||||
	groupAddr  string
 | 
						groupAddr string
 | 
				
			||||||
	interfaces []net.Interface
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *multicast) init(core *Core) {
 | 
					func (m *multicast) init(core *Core) {
 | 
				
			||||||
| 
						 | 
					@ -21,31 +20,7 @@ func (m *multicast) init(core *Core) {
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// Ask the system for network interfaces
 | 
						// Ask the system for network interfaces
 | 
				
			||||||
	allifaces, err := net.Interfaces()
 | 
						m.core.log.Println("Found", len(m.interfaces()), "multicast interface(s)")
 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		panic(err)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	// Work out which interfaces to announce on
 | 
					 | 
				
			||||||
	for _, iface := range allifaces {
 | 
					 | 
				
			||||||
		if iface.Flags&net.FlagUp == 0 {
 | 
					 | 
				
			||||||
			// Ignore interfaces that are down
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if iface.Flags&net.FlagMulticast == 0 {
 | 
					 | 
				
			||||||
			// Ignore non-multicast interfaces
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if iface.Flags&net.FlagPointToPoint != 0 {
 | 
					 | 
				
			||||||
			// Ignore point-to-point interfaces
 | 
					 | 
				
			||||||
			continue
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		for _, expr := range m.core.ifceExpr {
 | 
					 | 
				
			||||||
			if expr.MatchString(iface.Name) {
 | 
					 | 
				
			||||||
				m.interfaces = append(m.interfaces, iface)
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	m.core.log.Println("Found", len(m.interfaces), "multicast interface(s)")
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *multicast) start() error {
 | 
					func (m *multicast) start() error {
 | 
				
			||||||
| 
						 | 
					@ -75,6 +50,36 @@ func (m *multicast) start() error {
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (m *multicast) interfaces() []net.Interface {
 | 
				
			||||||
 | 
						// Ask the system for network interfaces
 | 
				
			||||||
 | 
						var interfaces []net.Interface
 | 
				
			||||||
 | 
						allifaces, err := net.Interfaces()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							panic(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						// Work out which interfaces to announce on
 | 
				
			||||||
 | 
						for _, iface := range allifaces {
 | 
				
			||||||
 | 
							if iface.Flags&net.FlagUp == 0 {
 | 
				
			||||||
 | 
								// Ignore interfaces that are down
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if iface.Flags&net.FlagMulticast == 0 {
 | 
				
			||||||
 | 
								// Ignore non-multicast interfaces
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if iface.Flags&net.FlagPointToPoint != 0 {
 | 
				
			||||||
 | 
								// Ignore point-to-point interfaces
 | 
				
			||||||
 | 
								continue
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							for _, expr := range m.core.ifceExpr {
 | 
				
			||||||
 | 
								if expr.MatchString(iface.Name) {
 | 
				
			||||||
 | 
									interfaces = append(interfaces, iface)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return interfaces
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (m *multicast) announce() {
 | 
					func (m *multicast) announce() {
 | 
				
			||||||
	groupAddr, err := net.ResolveUDPAddr("udp6", m.groupAddr)
 | 
						groupAddr, err := net.ResolveUDPAddr("udp6", m.groupAddr)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
| 
						 | 
					@ -88,7 +93,7 @@ func (m *multicast) announce() {
 | 
				
			||||||
		panic(err)
 | 
							panic(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	for {
 | 
						for {
 | 
				
			||||||
		for _, iface := range m.interfaces {
 | 
							for _, iface := range m.interfaces() {
 | 
				
			||||||
			m.sock.JoinGroup(&iface, groupAddr)
 | 
								m.sock.JoinGroup(&iface, groupAddr)
 | 
				
			||||||
			//err := n.sock.JoinGroup(&iface, groupAddr)
 | 
								//err := n.sock.JoinGroup(&iface, groupAddr)
 | 
				
			||||||
			//if err != nil { panic(err) }
 | 
								//if err != nil { panic(err) }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue