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