re-use remote transports in Peer,Storage,Locker clients (#10788)

use one transport for internode communication
This commit is contained in:
Harshavardhana
2020-11-02 07:43:11 -08:00
committed by GitHub
parent d8e07f2c41
commit 4c773f7068
12 changed files with 31 additions and 67 deletions

View File

@@ -19,7 +19,6 @@ package cmd
import (
"bytes"
"context"
"crypto/tls"
"encoding/gob"
"errors"
"fmt"
@@ -872,23 +871,13 @@ func newPeerRESTClient(peer *xnet.Host) *peerRESTClient {
Path: peerRESTPath,
}
var tlsConfig *tls.Config
if globalIsSSL {
tlsConfig = &tls.Config{
ServerName: peer.Name,
RootCAs: globalRootCAs,
}
}
trFn := newInternodeHTTPTransport(tlsConfig, rest.DefaultTimeout)
restClient := rest.NewClient(serverURL, trFn, newAuthToken)
restClient := rest.NewClient(serverURL, globalInternodeTransport, newAuthToken)
// Construct a new health function.
restClient.HealthCheckFn = func() bool {
ctx, cancel := context.WithTimeout(GlobalContext, restClient.HealthCheckTimeout)
// Instantiate a new rest client for healthcheck
// to avoid recursive healthCheckFn()
respBody, err := rest.NewClient(serverURL, trFn, newAuthToken).Call(ctx, peerRESTMethodHealth, nil, nil, -1)
respBody, err := rest.NewClient(serverURL, globalInternodeTransport, newAuthToken).Call(ctx, peerRESTMethodHealth, nil, nil, -1)
xhttp.DrainBody(respBody)
cancel()
var ne *rest.NetworkError