From 449019fbf3d858dd835198413fa60bd2173db106 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Thu, 19 Nov 2026 14:15:24 +0100 Subject: [PATCH] wip Signed-off-by: Jakob Borg --- internal/dht/dht.go | 8 ++++---- internal/dht/records.go | 5 ++--- lib/config/optionsconfiguration.go | 7 ++++++- lib/discover/manager.go | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/internal/dht/dht.go b/internal/dht/dht.go index 789cd453e..8969f7394 100644 --- a/internal/dht/dht.go +++ b/internal/dht/dht.go @@ -84,9 +84,9 @@ type Options struct { } type DHT struct { - host host.Host - ipfs *kad.IpfsDHT - dhtDiagnostics + host host.Host + ipfs *kad.IpfsDHT + dhtDiagnostics //nolint:embeddedstructfieldcheck } func NewSyncthingDHT(options Options) (*DHT, error) { @@ -342,7 +342,7 @@ func (s *DHT) Announce(ctx context.Context, deviceID protocol.DeviceID, addresse r := &discoproto.DHTPayload{ Certificate: certificate, Addresses: addresses, - ExpiresUnix: uint64(now.Add(RecordLifetime).Unix()), + ExpiresUnix: uint64(now.Add(RecordLifetime).Unix()), //nolint:gosec // does not wrap TimeValue: timeValue, } value, err := encodeRecord(r, privateKey) diff --git a/internal/dht/records.go b/internal/dht/records.go index 538f1067b..73388544e 100644 --- a/internal/dht/records.go +++ b/internal/dht/records.go @@ -35,10 +35,9 @@ const ( dhtRecordNamespace = "device" ) -// discoveryTimeValue staggers daily rotation across devices. The addition -// intentionally wraps at 2^64 before division. +// discoveryTimeValue staggers daily rotation across devices. func discoveryTimeValue(id protocol.DeviceID, now time.Time) uint64 { - return (uint64(now.Unix()) + binary.BigEndian.Uint64(id[:8])) / 86400 + return (uint64(now.Unix()) + binary.BigEndian.Uint64(id[:8])) / 86400 //nolint:gosec // intentionally wraps } // dhtRecordKey hashes the seed, raw device ID and big-endian time value. diff --git a/lib/config/optionsconfiguration.go b/lib/config/optionsconfiguration.go index 7091858f8..8d9ad4ad2 100644 --- a/lib/config/optionsconfiguration.go +++ b/lib/config/optionsconfiguration.go @@ -7,11 +7,13 @@ package config import ( + "context" "fmt" "net" "runtime" "slices" "strings" + "time" "github.com/syncthing/syncthing/lib/protocol" "github.com/syncthing/syncthing/lib/rand" @@ -228,10 +230,13 @@ func (opts OptionsConfiguration) GlobalDiscoveryServers() []string { } func (opts OptionsConfiguration) P2PDiscoveryBootstrapPeers() []string { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + var peers []string for _, address := range opts.RawP2PDiscoveryBootstrapPeers { if address == "default" { - if records, err := net.LookupTXT(DefaultDHTBootstrapRecord); err != nil { + if records, err := net.DefaultResolver.LookupTXT(ctx, DefaultDHTBootstrapRecord); err != nil { l.Debugln("Unable to resolve default DHT servers via DNS:", err) } else { peers = append(peers, records...) diff --git a/lib/discover/manager.go b/lib/discover/manager.go index 157572b0b..fac875065 100644 --- a/lib/discover/manager.go +++ b/lib/discover/manager.go @@ -49,7 +49,7 @@ type P2PStats struct { const ( globalCacheTime = 5 * time.Minute - globalNegCacheTime = time.Minute // usually overriden by the servers + globalNegCacheTime = time.Minute // usually overridden by the servers p2pCacheTime = 10 * time.Minute p2pNegCacheTime = 5 * time.Minute )