From 2f55af506514030d532c01e1b819d1536f4c4723 Mon Sep 17 00:00:00 2001 From: Gary Malouf <982483+gmalouf@users.noreply.github.com> Date: Wed, 10 Jul 2024 15:48:51 -0400 Subject: [PATCH] Add DisableRelayP2PTransport param to expose ability for certain node classes to not gossip messages on the P2P network (while still connecting to it). --- config/localTemplate.go | 4 ++++ config/local_defaults.go | 1 + installer/config.json.example | 1 + network/p2p/p2p.go | 11 ++++++++--- test/testdata/configs/config-v34.json | 1 + 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/config/localTemplate.go b/config/localTemplate.go index 314b83a78b..b3d4789fb4 100644 --- a/config/localTemplate.go +++ b/config/localTemplate.go @@ -610,6 +610,10 @@ type Local struct { // EnableDHT will turn on the hash table for use with capabilities advertisement EnableDHTProviders bool `version[34]:"false"` + // DisableP2PRelayTransport disables the relay transport for the P2P network. Relay transport is + // enabled by default when EnableP2P or EnableP2PHybridMode is set to true. + DisableP2PRelayTransport bool `version[34]:"false"` + // P2PPersistPeerID will write the private key used for the node's PeerID to the P2PPrivateKeyLocation. // This is only used when P2PEnable is true. If P2PPrivateKey is not specified, it uses the default location. P2PPersistPeerID bool `version[29]:"false"` diff --git a/config/local_defaults.go b/config/local_defaults.go index ae2ed22ebf..5f67abf9c7 100644 --- a/config/local_defaults.go +++ b/config/local_defaults.go @@ -59,6 +59,7 @@ var defaultLocal = Local{ DisableLocalhostConnectionRateLimit: true, DisableNetworking: false, DisableOutgoingConnectionThrottling: false, + DisableP2PRelayTransport: false, EnableAccountUpdatesStats: false, EnableAgreementReporting: false, EnableAgreementTimeMetrics: false, diff --git a/installer/config.json.example b/installer/config.json.example index 7f16155303..7ee1eecfa8 100644 --- a/installer/config.json.example +++ b/installer/config.json.example @@ -38,6 +38,7 @@ "DisableLocalhostConnectionRateLimit": true, "DisableNetworking": false, "DisableOutgoingConnectionThrottling": false, + "DisableP2PRelayTransport": false, "EnableAccountUpdatesStats": false, "EnableAgreementReporting": false, "EnableAgreementTimeMetrics": false, diff --git a/network/p2p/p2p.go b/network/p2p/p2p.go index ac0489d5e1..23af7e817b 100644 --- a/network/p2p/p2p.go +++ b/network/p2p/p2p.go @@ -115,9 +115,14 @@ func MakeHost(cfg config.Local, datadir string, pstore *pstore.PeerStore) (host. listenAddr = "/ip4/0.0.0.0/tcp/0" } - // the libp2p.NoListenAddrs builtin disables relays but this one does not - var noListenAddrs = func(cfg *libp2p.Config) error { - cfg.ListenAddrs = []multiaddr.Multiaddr{} + // the libp2p.NoListenAddrs builtin disables relays but this one only does if + // DisableP2PRelayTransport is set to true + var noListenAddrs = func(p2pCfg *libp2p.Config) error { + if cfg.DisableP2PRelayTransport { + return libp2p.NoListenAddrs(p2pCfg) + } + + p2pCfg.ListenAddrs = []multiaddr.Multiaddr{} return nil } diff --git a/test/testdata/configs/config-v34.json b/test/testdata/configs/config-v34.json index 7f16155303..7ee1eecfa8 100644 --- a/test/testdata/configs/config-v34.json +++ b/test/testdata/configs/config-v34.json @@ -38,6 +38,7 @@ "DisableLocalhostConnectionRateLimit": true, "DisableNetworking": false, "DisableOutgoingConnectionThrottling": false, + "DisableP2PRelayTransport": false, "EnableAccountUpdatesStats": false, "EnableAgreementReporting": false, "EnableAgreementTimeMetrics": false,