mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-03 07:12:27 +00:00
saves some traffic (potential mobile wakeups), may help with #5957.
This commit is contained in:
parent
f08d09f607
commit
1e68ab3f90
@ -44,19 +44,31 @@ func writeBroadcasts(ctx context.Context, inbox <-chan []byte, port int) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
intfs, err := net.Interfaces()
|
||||
if err != nil {
|
||||
l.Debugln(err)
|
||||
return err
|
||||
}
|
||||
|
||||
var dsts []net.IP
|
||||
for _, intf := range intfs {
|
||||
if intf.Flags&net.FlagBroadcast == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
addrs, err := intf.Addrs()
|
||||
if err != nil {
|
||||
l.Debugln(err)
|
||||
return err
|
||||
}
|
||||
|
||||
for _, addr := range addrs {
|
||||
if iaddr, ok := addr.(*net.IPNet); ok && len(iaddr.IP) >= 4 && iaddr.IP.IsGlobalUnicast() && iaddr.IP.To4() != nil {
|
||||
baddr := bcast(iaddr)
|
||||
dsts = append(dsts, baddr.IP)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(dsts) == 0 {
|
||||
// Fall back to the general IPv4 broadcast address
|
||||
|
@ -67,6 +67,10 @@ func writeMulticasts(ctx context.Context, inbox <-chan []byte, addr string) erro
|
||||
|
||||
success := 0
|
||||
for _, intf := range intfs {
|
||||
if intf.Flags&net.FlagMulticast == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
wcm.IfIndex = intf.Index
|
||||
pconn.SetWriteDeadline(time.Now().Add(time.Second))
|
||||
_, err = pconn.WriteTo(bs, wcm, gaddr)
|
||||
|
Loading…
Reference in New Issue
Block a user