Пример #1
0
func (d *Discoverer) startLocalIPv6Multicasts(localMCAddr string) {
	intfs, err := net.Interfaces()
	if err != nil {
		if debug {
			l.Debugln("discover: interfaces:", err)
		}
		l.Infoln("Local discovery over IPv6 unavailable")
		return
	}

	v6Intfs := 0
	for _, intf := range intfs {
		// Interface flags seem to always be 0 on Windows
		if runtime.GOOS != "windows" && (intf.Flags&net.FlagUp == 0 || intf.Flags&net.FlagMulticast == 0) {
			continue
		}

		mb, err := beacon.NewMulticast(localMCAddr, intf.Name)
		if err != nil {
			if debug {
				l.Debugln("discover: Start local v6:", err)
			}
			continue
		}

		d.beacons = append(d.beacons, mb)
		go d.recvAnnouncements(mb)
		v6Intfs++
	}

	if v6Intfs == 0 {
		l.Infoln("Local discovery over IPv6 unavailable")
	}
}
Пример #2
0
func (d *Discoverer) StartLocal(localPort int, localMCAddr string) {
	if localPort > 0 {
		bb, err := beacon.NewBroadcast(localPort)
		if err != nil {
			if debug {
				l.Debugln(err)
			}
			l.Infoln("Local discovery over IPv4 unavailable")
		} else {
			d.broadcastBeacon = bb
			go d.recvAnnouncements(bb)
		}
	}

	if len(localMCAddr) > 0 {
		mb, err := beacon.NewMulticast(localMCAddr)
		if err != nil {
			if debug {
				l.Debugln(err)
			}
			l.Infoln("Local discovery over IPv6 unavailable")
		} else {
			d.multicastBeacon = mb
			go d.recvAnnouncements(mb)
		}
	}

	if d.broadcastBeacon == nil && d.multicastBeacon == nil {
		l.Warnln("Local discovery unavailable")
	} else {
		d.localBcastTick = time.Tick(d.localBcastIntv)
		d.forcedBcastTick = make(chan time.Time)
		go d.sendLocalAnnouncements()
	}
}