Revert "wip"

This reverts commit 792f8ce938.
This commit is contained in:
Jakob Borg committed 2026-11-19 12:29:03 +01:00
1 parent 7b0329c64a
commit 99bd01d34f
4 files changed
+27 -52

No files matched your search

-1
View File
@@ -383,7 +383,6 @@ jobs:
done
env:
CGO_ENABLED: "1"
TAGS: "nolibp2p sqlite_omit_load_extension sqlite_dbstat"
- name: Archive artifacts
uses: actions/upload-artifact@v4
+11 -9
View File
@@ -20,6 +20,7 @@ import (
"github.com/thejerf/suture/v4"
"github.com/syncthing/syncthing/internal/db"
"github.com/syncthing/syncthing/internal/dht"
"github.com/syncthing/syncthing/internal/slogutil"
"github.com/syncthing/syncthing/lib/config"
"github.com/syncthing/syncthing/lib/connections/registry"
@@ -216,7 +217,7 @@ func (m *manager) CommitConfiguration(_, to config.Configuration) (handled bool)
toIdentities[ipv6Identity(to.Options.LocalAnnMCAddr)] = struct{}{}
}
if p2pDiscoveryAvailable && to.Options.P2PDiscoveryEnabled {
if to.Options.P2PDiscoveryEnabled {
toIdentities[p2pIdentity()] = struct{}{}
}
@@ -268,10 +269,16 @@ func (m *manager) CommitConfiguration(_, to config.Configuration) (handled bool)
}
}
if p2pDiscoveryAvailable && to.Options.P2PDiscoveryEnabled {
if to.Options.P2PDiscoveryEnabled {
ident := p2pIdentity()
if _, ok := m.finders[ident]; !ok {
dht, err := NewPeerToPeerDiscovery(m.cert, m.addressLister, m.evLogger, m.kv, m.registry.UDP, to.Options)
listenAddresses := p2pQUICListenAddresses(to.Options.ListenAddresses())
bootstrapPeers := to.Options.P2PDiscoveryBootstrapPeers()
dht, err := NewPeerToPeerDiscovery(m.cert, m.addressLister, m.evLogger, m.kv, dht.Options{
UDP: m.registry.UDP,
ListenAddresses: listenAddresses,
BootstrapPeers: bootstrapPeers,
})
if err != nil {
slog.Warn("Failed to initialize peer-to-peer discovery", slogutil.Error(err))
} else {
@@ -286,15 +293,10 @@ func (m *manager) CommitConfiguration(_, to config.Configuration) (handled bool)
// P2PStats returns statistics about the currently running peer-to-peer
// discovery.
func (m *manager) P2PStats() P2PStats {
type p2pImpl interface {
Mode() string
Peers() int
}
m.mut.RLock()
defer m.mut.RUnlock()
p2p, ok := m.finders[p2pIdentity()].Finder.(p2pImpl)
p2p, ok := m.finders[p2pIdentity()].Finder.(*PeerToPeerDiscovery)
if !ok {
return P2PStats{}
}
+16 -17
View File
@@ -4,8 +4,6 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
//go:build !nolibp2p
package discover
import (
@@ -27,15 +25,13 @@ import (
"github.com/syncthing/syncthing/internal/db"
"github.com/syncthing/syncthing/internal/dht"
"github.com/syncthing/syncthing/lib/config"
"github.com/syncthing/syncthing/lib/connections/registry"
"github.com/syncthing/syncthing/lib/events"
"github.com/syncthing/syncthing/lib/protocol"
)
const (
p2pDiscoveryAvailable = true
p2pIdentityKey = "dht-identity"
p2pIdentityLifetime = 7 * 24 * time.Hour
p2pIdentityKey = "dht-identity"
p2pIdentityLifetime = 7 * 24 * time.Hour
)
type PeerToPeerDiscovery struct {
@@ -52,25 +48,28 @@ type PeerToPeerDiscovery struct {
var _ FinderService = (*PeerToPeerDiscovery)(nil)
func NewPeerToPeerDiscovery(cert tls.Certificate, addresses AddressLister, evLogger events.Logger, kv db.KV, udp *registry.UDPReuseManager, cfg config.OptionsConfiguration) (Finder, error) {
func NewPeerToPeerDiscovery(cert tls.Certificate, addresses AddressLister, evLogger events.Logger, kv db.KV, opts dht.Options) (*PeerToPeerDiscovery, error) {
privateKey, ok := cert.PrivateKey.(crypto.Signer)
if !ok {
return nil, errors.New("TLS private key must implement crypto.Signer")
}
identity, err := loadDHTIdentity(db.NewMiscDB(kv), time.Now())
if err != nil {
return nil, fmt.Errorf("loading DHT identity: %w", err)
if opts.ValueDatastore == nil {
opts.ValueDatastore = dht.NewDatastore(db.NewTyped(kv, "dht-values"))
}
opts := dht.Options{
UDP: udp,
ListenAddresses: p2pQUICListenAddresses(cfg.ListenAddresses()),
BootstrapPeers: cfg.P2PDiscoveryBootstrapPeers(),
ValueDatastore: dht.NewDatastore(db.NewTyped(kv, "dht-values")),
RoutingDatastore: dht.NewDatastore(db.NewTyped(kv, "dht-routing")),
Identity: identity,
if opts.RoutingDatastore == nil {
opts.RoutingDatastore = dht.NewDatastore(db.NewTyped(kv, "dht-routing"))
}
if opts.Identity == nil {
identity, err := loadDHTIdentity(db.NewMiscDB(kv), time.Now())
if err != nil {
return nil, fmt.Errorf("loading DHT identity: %w", err)
}
opts.Identity = identity
}
dht, err := dht.NewSyncthingDHT(opts)
if err != nil {
return nil, err
-25
View File
@@ -1,25 +0,0 @@
// Copyright (C) 2026 The Syncthing Authors.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
//go:build nolibp2p
package discover
import (
"crypto/tls"
"errors"
"github.com/syncthing/syncthing/internal/db"
"github.com/syncthing/syncthing/lib/config"
"github.com/syncthing/syncthing/lib/connections/registry"
"github.com/syncthing/syncthing/lib/events"
)
const p2pDiscoveryAvailable = false
func NewPeerToPeerDiscovery(tls.Certificate, AddressLister, events.Logger, db.KV, *registry.UDPReuseManager, config.OptionsConfiguration) (Finder, error) {
return nil, errors.New("peer-to-peer discovery is disabled in this build")
}