forked from Silverfish/proton-bridge
feat: simple client manager
This commit is contained in:
@ -26,8 +26,6 @@ import (
|
||||
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
|
||||
)
|
||||
|
||||
func New(cfg bridge.Configer, _ listener.Listener) bridge.PMAPIProviderFactory {
|
||||
return func(userID string) bridge.PMAPIProvider {
|
||||
return pmapi.NewClient(cfg.GetAPIConfig(), userID)
|
||||
}
|
||||
func GetClientConfig(config bridge.Configer, _ listener.Listener) *pmapi.ClientConfig {
|
||||
return config.GetAPIConfig()
|
||||
}
|
||||
|
||||
@ -29,10 +29,10 @@ import (
|
||||
"github.com/ProtonMail/proton-bridge/pkg/pmapi"
|
||||
)
|
||||
|
||||
func New(config bridge.Configer, listener listener.Listener) bridge.PMAPIProviderFactory {
|
||||
cfg := config.GetAPIConfig()
|
||||
func GetClientConfig(config bridge.Configer, listener listener.Listener) *pmapi.ClientConfig {
|
||||
clientConfig := config.GetAPIConfig()
|
||||
|
||||
pin := pmapi.NewPMAPIPinning(cfg.AppVersion)
|
||||
pin := pmapi.NewPMAPIPinning(clientConfig.AppVersion)
|
||||
pin.ReportCertIssueLocal = func() {
|
||||
listener.Emit(events.TLSCertIssue, "")
|
||||
}
|
||||
@ -41,14 +41,12 @@ func New(config bridge.Configer, listener listener.Listener) bridge.PMAPIProvide
|
||||
// - IdleConnTimeout: 5 * time.Minute,
|
||||
// - ExpectContinueTimeout: 500 * time.Millisecond,
|
||||
// - ResponseHeaderTimeout: 30 * time.Second,
|
||||
cfg.Transport = pin.TransportWithPinning()
|
||||
clientConfig.Transport = pin.TransportWithPinning()
|
||||
|
||||
// We set additional timeouts/thresholds for the request as a whole:
|
||||
cfg.Timeout = 10 * time.Minute // Overall request timeout (~25MB / 10 mins => ~40kB/s, should be reasonable).
|
||||
cfg.FirstReadTimeout = 30 * time.Second // 30s to match 30s response header timeout.
|
||||
cfg.MinSpeed = 1 << 13 // Enforce minimum download speed of 8kB/s.
|
||||
clientConfig.Timeout = 10 * time.Minute // Overall request timeout (~25MB / 10 mins => ~40kB/s, should be reasonable).
|
||||
clientConfig.FirstReadTimeout = 30 * time.Second // 30s to match 30s response header timeout.
|
||||
clientConfig.MinSpeed = 1 << 13 // Enforce minimum download speed of 8kB/s.
|
||||
|
||||
return func(userID string) bridge.PMAPIProvider {
|
||||
return pmapi.NewClient(cfg, userID)
|
||||
}
|
||||
return clientConfig
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user