Skip to content

Commit 9f96c76

Browse files
committed
fix: autotls lint issues
1 parent fa2dae3 commit 9f96c76

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

Diff for: nodebuilder/p2p/autotls.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import (
55

66
"github.com/caddyserver/certmagic"
77
p2pForge "github.com/ipshipyard/p2p-forge/client"
8-
"github.com/libp2p/go-libp2p/core/peer"
98
)
109

1110
// User-Agent to use during DNS-01 ACME challenge
1211
const userAgent = "go-libp2p/celestia-node"
1312

1413
// setupAutoTLS attempts to obtain TLS certificates automatically using p2p-forge.
1514
// It returns a TLS config if successful, or nil if AutoTLS is not enabled or fails.
16-
func setupAutoTLS(peerId peer.ID, certstore certmagic.FileStorage) (*tls.Config, error) {
15+
func setupAutoTLS(certstore certmagic.FileStorage) (*tls.Config, error) {
1716
// p2pforge is the AutoTLS client library.
1817
// The cert manager handles the creation and management of certificate
1918
certManager, err := p2pForge.NewP2PForgeCertMgr(
@@ -35,7 +34,12 @@ func setupAutoTLS(peerId peer.ID, certstore certmagic.FileStorage) (*tls.Config,
3534
}
3635

3736
// Start the cert manager
38-
certManager.Start()
37+
certError := certManager.Start()
38+
// Handle certManager errors
39+
if certError != nil {
40+
return nil, err
41+
}
42+
3943
defer certManager.Stop()
4044

4145
return certManager.TLSConfig(), nil

Diff for: nodebuilder/p2p/host.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (ua *UserAgent) String() string {
7272
func newHost(params hostParams) (HostBase, error) {
7373
ua := newUserAgent().WithNetwork(params.Net).WithNodeType(params.Tp)
7474

75-
tlsCfg, isEnabled, err := tlsEnabled(params.Cfg, params.ID, params.Certstore)
75+
tlsCfg, isEnabled, err := tlsEnabled(params.Cfg, params.Tp, params.Certstore)
7676
if err != nil {
7777
return nil, err
7878
}

Diff for: nodebuilder/p2p/tls.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import (
77

88
"github.com/caddyserver/certmagic"
99
"github.com/libp2p/go-libp2p"
10-
"github.com/libp2p/go-libp2p/core/peer"
1110
ws "github.com/libp2p/go-libp2p/p2p/transport/websocket"
1211

1312
"github.com/celestiaorg/celestia-node/libs/utils"
13+
"github.com/celestiaorg/celestia-node/nodebuilder/node"
1414
)
1515

1616
const (
@@ -23,7 +23,12 @@ var tlsPath = "CELESTIA_TLS_PATH"
2323
// tlsEnabled checks whether `tlsPath` is not empty and creates a certificate.
2424
// it returns the cfg itself, the bool flag that specifies whether the config was created
2525
// and an error.
26-
func tlsEnabled(cfg *Config, peerId peer.ID, certstore certmagic.FileStorage) (*tls.Config, bool, error) {
26+
func tlsEnabled(cfg *Config, nodeType node.Type, certstore certmagic.FileStorage) (*tls.Config, bool, error) {
27+
// Disable on light nodes
28+
if nodeType == node.Light {
29+
return nil, false, nil
30+
}
31+
2732
if !cfg.TLSEnabled {
2833
return nil, false, nil
2934
}
@@ -32,7 +37,7 @@ func tlsEnabled(cfg *Config, peerId peer.ID, certstore certmagic.FileStorage) (*
3237
if path == "" {
3338
// use autotls if tls is enabled but no path is set
3439
log.Debug("the CELESTIA_TLS_PATH was not set, using autotls")
35-
autoTLSConfig, err := setupAutoTLS(peerId, certstore)
40+
autoTLSConfig, err := setupAutoTLS(certstore)
3641
if err != nil {
3742
return nil, false, err
3843
}

0 commit comments

Comments
 (0)