This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
generated from ipfs/ipfs-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 20
/
blockstore_caboose.go
109 lines (93 loc) · 2.96 KB
/
blockstore_caboose.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"crypto/tls"
"net/http"
"net/url"
"os"
"time"
"github.com/filecoin-saturn/caboose"
blockstore "github.com/ipfs/boxo/blockstore"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
)
const (
EnvSaturnLogger = "STRN_LOGGER_URL"
EnvSaturnLoggerSecret = "STRN_LOGGER_SECRET"
EnvSaturnOrchestrator = "STRN_ORCHESTRATOR_URL"
DefaultSaturnLogger = "http://set-env-variables-STRN_LOGGER_URL-and-STRN_LOGGER_SECRET"
)
func newCabooseBlockStore(orchestrator, loggingEndpoint string, cdns *cachedDNS) (blockstore.Blockstore, error) {
var (
orchURL *url.URL
loggURL *url.URL
err error
)
if orchestrator != "" {
orchURL, err = url.Parse(orchestrator)
if err != nil {
return nil, err
}
}
if loggingEndpoint != "" {
loggURL, err = url.Parse(loggingEndpoint)
if err != nil {
return nil, err
}
}
saturnOrchestratorClient := &http.Client{
Timeout: caboose.DefaultOrchestratorRequestTimeout,
Transport: &customTransport{
AuthorizationBearerToken: os.Getenv(EnvSaturnLoggerSecret),
RoundTripper: &http.Transport{
DialContext: cdns.dialWithCachedDNS,
ForceAttemptHTTP2: true,
},
},
}
saturnLoggerClient := &http.Client{
Timeout: caboose.DefaultOrchestratorRequestTimeout, // caboose does nto provide custom timeout for logger, reusing one for orchestrator
Transport: &customTransport{
AuthorizationBearerToken: os.Getenv(EnvSaturnLoggerSecret),
RoundTripper: &http.Transport{
DialContext: cdns.dialWithCachedDNS,
ForceAttemptHTTP2: true,
},
},
}
saturnRetrievalClient := &http.Client{
Timeout: caboose.DefaultCarRequestTimeout,
Transport: otelhttp.NewTransport(&customTransport{
RoundTripper: &http.Transport{
// Increasing concurrency defaults from http.DefaultTransport
MaxIdleConns: 25000,
MaxConnsPerHost: 1000,
MaxIdleConnsPerHost: 1000,
IdleConnTimeout: 90 * time.Second,
DialContext: cdns.dialWithCachedDNS,
// Saturn Weltschmerz
TLSClientConfig: &tls.Config{
// Saturn use TLS in controversial ways, which sooner or
// later will force them to switch away to different domain
// name and certs, in which case they will break us. Since
// we are fetching raw blocks and dont really care about
// TLS cert being legitimate, let's disable verification
// to save CPU and to avoid catastrophic failure when
// Saturn L1s suddenly switch to certs with different DNS name.
InsecureSkipVerify: true,
// ServerName: "strn.pl",
},
ForceAttemptHTTP2: true,
},
}),
}
return caboose.NewCaboose(&caboose.Config{
OrchestratorEndpoint: orchURL,
OrchestratorClient: saturnOrchestratorClient,
LoggingEndpoint: *loggURL,
LoggingClient: saturnLoggerClient,
LoggingInterval: caboose.DefaultLoggingInterval,
DoValidation: true,
PoolRefresh: caboose.DefaultPoolRefreshInterval,
Client: saturnRetrievalClient,
ComplianceCidPeriod: int64(5),
})
}