From fe307da094c36f7833be100ba9194b306502a376 Mon Sep 17 00:00:00 2001 From: Marcin Rataj Date: Thu, 19 Sep 2024 00:37:38 +0200 Subject: [PATCH] refactor(config): Swarm.ForgeClient --- config/experiments.go | 1 - config/forge.go | 30 ++++++++++++++++++++++++++ config/swarm.go | 4 ++++ core/node/groups.go | 5 +++-- docs/examples/kubo-as-a-library/go.mod | 2 +- docs/examples/kubo-as-a-library/go.sum | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- 8 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 config/forge.go diff --git a/config/experiments.go b/config/experiments.go index 76531865eb8..fab1f953c2e 100644 --- a/config/experiments.go +++ b/config/experiments.go @@ -10,7 +10,6 @@ type Experiments struct { OptimisticProvide bool OptimisticProvideJobsPoolSize int GatewayOverLibp2p bool `json:",omitempty"` - P2PForgeClient bool `json:",omitempty"` GraphsyncEnabled graphsyncEnabled `json:",omitempty"` AcceleratedDHTClient experimentalAcceleratedDHTClient `json:",omitempty"` diff --git a/config/forge.go b/config/forge.go new file mode 100644 index 00000000000..749e713ffa3 --- /dev/null +++ b/config/forge.go @@ -0,0 +1,30 @@ +package config + +import p2pforge "github.com/ipshipyard/p2p-forge/client" + +// ForgeClient includes optional configuration of p2p-forge client of service +// for obtaining a domain and TLS certificate to improve connectivity for web +// browser clients. More: https://github.com/ipshipyard/p2p-forge#readme +type ForgeClient struct { + // Enables the p2p-forge feature + Enabled Flag `json:",omitempty"` + + // Optional override of the parent domain that will be used + ForgeDomain *OptionalString `json:",omitempty"` + + // Optional override of HTTP API that acts as ACME DNS-01 Challenge broker + ForgeEndpoint *OptionalString `json:",omitempty"` + + // Optional Authorization token, used with private/test instances of p2p-forge + ForgeAuth *OptionalString `json:",omitempty"` + + // Optional override of CA ACME API used by p2p-forge system + CAEndpoint *OptionalString `json:",omitempty"` +} + +const ( + DefaultForgeEnabled = false // experimental, opt-in for now (https://github.com/ipfs/kubo/pull/10521) + DefaultForgeDomain = p2pforge.DefaultForgeDomain + DefaultForgeEndpoint = p2pforge.DefaultForgeEndpoint + DefaultCAEndpoint = p2pforge.DefaultCAEndpoint +) diff --git a/config/swarm.go b/config/swarm.go index f15634b578a..24cf5510266 100644 --- a/config/swarm.go +++ b/config/swarm.go @@ -32,6 +32,10 @@ type SwarmConfig struct { // ResourceMgr configures the libp2p Network Resource Manager ResourceMgr ResourceMgr + + // ForgeClient controls the client of a service for obtaining a domain + // and TLS certificate to improve connectivity for web browser clients. + ForgeClient ForgeClient } type RelayClient struct { diff --git a/core/node/groups.go b/core/node/groups.go index c3da964b52f..84239928918 100644 --- a/core/node/groups.go +++ b/core/node/groups.go @@ -113,6 +113,7 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config, userResourceOverrides rcmgr.Part enableRelayTransport := cfg.Swarm.Transports.Network.Relay.WithDefault(true) // nolint enableRelayService := cfg.Swarm.RelayService.Enabled.WithDefault(enableRelayTransport) enableRelayClient := cfg.Swarm.RelayClient.Enabled.WithDefault(enableRelayTransport) + enableForgeClient := cfg.Swarm.ForgeClient.Enabled.WithDefault(config.DefaultForgeEnabled) // Log error when relay subsystem could not be initialized due to missing dependency if !enableRelayTransport { @@ -133,8 +134,8 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config, userResourceOverrides rcmgr.Part // Services (resource management) fx.Provide(libp2p.ResourceManager(cfg.Swarm, userResourceOverrides)), - maybeProvide(libp2p.P2PForgeCertMgr, cfg.Experimental.P2PForgeClient), - maybeInvoke(libp2p.StartP2PForgeCertMgr, cfg.Experimental.P2PForgeClient), + maybeProvide(libp2p.P2PForgeCertMgr, enableForgeClient), + maybeInvoke(libp2p.StartP2PForgeCertMgr, enableForgeClient), fx.Provide(libp2p.AddrFilters(cfg.Swarm.AddrFilters)), fx.Provide(libp2p.AddrsFactory(cfg.Addresses.Announce, cfg.Addresses.AppendAnnounce, cfg.Addresses.NoAnnounce)), fx.Provide(libp2p.SmuxTransport(cfg.Swarm.Transports)), diff --git a/docs/examples/kubo-as-a-library/go.mod b/docs/examples/kubo-as-a-library/go.mod index d7f4b31d50e..3943566a0eb 100644 --- a/docs/examples/kubo-as-a-library/go.mod +++ b/docs/examples/kubo-as-a-library/go.mod @@ -101,7 +101,7 @@ require ( github.com/ipld/go-car/v2 v2.13.1 // indirect github.com/ipld/go-codec-dagpb v1.6.0 // indirect github.com/ipld/go-ipld-prime v0.21.0 // indirect - github.com/ipshipyard/p2p-forge v0.0.0-20240918214012-dbeb701d58c3 // indirect + github.com/ipshipyard/p2p-forge v0.0.0-20240918220446-2ecd19ac95e1 // indirect github.com/jackpal/go-nat-pmp v1.0.2 // indirect github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect github.com/jbenet/goprocess v0.1.4 // indirect diff --git a/docs/examples/kubo-as-a-library/go.sum b/docs/examples/kubo-as-a-library/go.sum index 1ee847797b0..71a30f9241f 100644 --- a/docs/examples/kubo-as-a-library/go.sum +++ b/docs/examples/kubo-as-a-library/go.sum @@ -375,8 +375,8 @@ github.com/ipld/go-ipld-prime v0.21.0 h1:n4JmcpOlPDIxBcY037SVfpd1G+Sj1nKZah0m6QH github.com/ipld/go-ipld-prime v0.21.0/go.mod h1:3RLqy//ERg/y5oShXXdx5YIp50cFGOanyMctpPjsvxQ= github.com/ipld/go-ipld-prime/storage/bsadapter v0.0.0-20230102063945-1a409dc236dd h1:gMlw/MhNr2Wtp5RwGdsW23cs+yCuj9k2ON7i9MiJlRo= github.com/ipld/go-ipld-prime/storage/bsadapter v0.0.0-20230102063945-1a409dc236dd/go.mod h1:wZ8hH8UxeryOs4kJEJaiui/s00hDSbE37OKsL47g+Sw= -github.com/ipshipyard/p2p-forge v0.0.0-20240918214012-dbeb701d58c3 h1:U63TlIHVN9XX5Dk0pbKVfoD0fYe9gZvslTcin9ANy1E= -github.com/ipshipyard/p2p-forge v0.0.0-20240918214012-dbeb701d58c3/go.mod h1:0DQ69wQJ5Xxx9xOdP7S7yyF4OqqYcrcbWi0qKNcwC9Q= +github.com/ipshipyard/p2p-forge v0.0.0-20240918220446-2ecd19ac95e1 h1:tYfEXvR65J5Pyk7GRhLWunA6MyAXhnakmXoS9Q1y+r8= +github.com/ipshipyard/p2p-forge v0.0.0-20240918220446-2ecd19ac95e1/go.mod h1:0DQ69wQJ5Xxx9xOdP7S7yyF4OqqYcrcbWi0qKNcwC9Q= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jbenet/go-cienv v0.1.0 h1:Vc/s0QbQtoxX8MwwSLWWh+xNNZvM3Lw7NsTcHrvvhMc= diff --git a/go.mod b/go.mod index c3b9e019e0f..b762bee11de 100644 --- a/go.mod +++ b/go.mod @@ -45,7 +45,7 @@ require ( github.com/ipld/go-car/v2 v2.13.1 github.com/ipld/go-codec-dagpb v1.6.0 github.com/ipld/go-ipld-prime v0.21.0 - github.com/ipshipyard/p2p-forge v0.0.0-20240918214012-dbeb701d58c3 + github.com/ipshipyard/p2p-forge v0.0.0-20240918220446-2ecd19ac95e1 github.com/jbenet/go-temp-err-catcher v0.1.0 github.com/jbenet/goprocess v0.1.4 github.com/julienschmidt/httprouter v1.3.0 diff --git a/go.sum b/go.sum index 051ada08307..9338218d489 100644 --- a/go.sum +++ b/go.sum @@ -444,8 +444,8 @@ github.com/ipld/go-ipld-prime v0.21.0 h1:n4JmcpOlPDIxBcY037SVfpd1G+Sj1nKZah0m6QH github.com/ipld/go-ipld-prime v0.21.0/go.mod h1:3RLqy//ERg/y5oShXXdx5YIp50cFGOanyMctpPjsvxQ= github.com/ipld/go-ipld-prime/storage/bsadapter v0.0.0-20230102063945-1a409dc236dd h1:gMlw/MhNr2Wtp5RwGdsW23cs+yCuj9k2ON7i9MiJlRo= github.com/ipld/go-ipld-prime/storage/bsadapter v0.0.0-20230102063945-1a409dc236dd/go.mod h1:wZ8hH8UxeryOs4kJEJaiui/s00hDSbE37OKsL47g+Sw= -github.com/ipshipyard/p2p-forge v0.0.0-20240918214012-dbeb701d58c3 h1:U63TlIHVN9XX5Dk0pbKVfoD0fYe9gZvslTcin9ANy1E= -github.com/ipshipyard/p2p-forge v0.0.0-20240918214012-dbeb701d58c3/go.mod h1:0DQ69wQJ5Xxx9xOdP7S7yyF4OqqYcrcbWi0qKNcwC9Q= +github.com/ipshipyard/p2p-forge v0.0.0-20240918220446-2ecd19ac95e1 h1:tYfEXvR65J5Pyk7GRhLWunA6MyAXhnakmXoS9Q1y+r8= +github.com/ipshipyard/p2p-forge v0.0.0-20240918220446-2ecd19ac95e1/go.mod h1:0DQ69wQJ5Xxx9xOdP7S7yyF4OqqYcrcbWi0qKNcwC9Q= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jbenet/go-cienv v0.1.0 h1:Vc/s0QbQtoxX8MwwSLWWh+xNNZvM3Lw7NsTcHrvvhMc=