Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pelican transport fixes and generated after configs #183

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion client/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"strconv"
"strings"

"github.com/pelicanplatform/pelican/config"
namespaces "github.com/pelicanplatform/pelican/namespaces"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -121,7 +122,7 @@ func QueryDirector(source string, directorUrl string) (resp *http.Response, err
// redirect. We use the Location url elsewhere (plus we still need to do the token
// dance!)
var client *http.Client
tr := GetTransport()
tr := config.GetTransport()
client = &http.Client{
Transport: tr,
CheckRedirect: func(req *http.Request, via []*http.Request) error {
Expand Down
53 changes: 5 additions & 48 deletions client/handle_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package client

import (
"context"
"crypto/tls"
"errors"
"fmt"
"io"
Expand All @@ -45,17 +44,12 @@ import (
"github.com/vbauerster/mpb/v8"
"github.com/vbauerster/mpb/v8/decor"

"github.com/pelicanplatform/pelican/config"
namespaces "github.com/pelicanplatform/pelican/namespaces"
"github.com/pelicanplatform/pelican/param"
)

var p = mpb.New()

var (
transport *http.Transport
onceTransport sync.Once
)

type StoppedTransferError struct {
Err string
}
Expand Down Expand Up @@ -445,49 +439,12 @@ func parseTransferStatus(status string) (int, string) {
return statusCode, strings.TrimSpace(parts[1])
}

func setupTransport() *http.Transport {
//Getting timeouts and other information from defaults.yaml
maxIdleConns := viper.GetInt("Transport.MaxIdleIcons")
idleConnTimeout := viper.GetDuration("Transport.IdleConnTimeout")
transportTLSHandshakeTimeout := viper.GetDuration("Transport.TLSHandshakeTimeout")
expectContinueTimeout := viper.GetDuration("Transport.ExpectContinueTimeout")
responseHeaderTimeout := viper.GetDuration("Transport.ResponseHeaderTimeout")

transportDialerTimeout := viper.GetDuration("Transport.Dialer.Timeout")
transportKeepAlive := viper.GetDuration("Transport.Dialer.KeepAlive")

//Set up the transport
return &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: transportDialerTimeout,
KeepAlive: transportKeepAlive,
}).DialContext,
MaxIdleConns: maxIdleConns,
IdleConnTimeout: idleConnTimeout,
TLSHandshakeTimeout: transportTLSHandshakeTimeout,
ExpectContinueTimeout: expectContinueTimeout,
ResponseHeaderTimeout: responseHeaderTimeout,
}
}

// function to get/setup the transport (only once)
func GetTransport() *http.Transport {
onceTransport.Do(func() {
transport = setupTransport()
})
if param.TLSSkipVerify.GetBool() {
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
}
return transport
}

// DownloadHTTP - Perform the actual download of the file
func DownloadHTTP(transfer TransferDetails, dest string, token string) (int64, error) {

// Create the client, request, and context
client := grab.NewClient()
transport := GetTransport()
transport := config.GetTransport()
if !transfer.Proxy {
transport.Proxy = nil
}
Expand Down Expand Up @@ -799,7 +756,7 @@ Loop:

}

var UploadClient = &http.Client{Transport: GetTransport()}
var UploadClient = &http.Client{Transport: config.GetTransport()}

// Actually perform the Put request to the server
func doPut(request *http.Request, responseChan chan<- *http.Response, errorChan chan<- error) {
Expand Down Expand Up @@ -850,7 +807,7 @@ func walkDavDir(url *url.URL, namespace namespaces.Namespace) ([]string, error)
c := gowebdav.NewClient(rootUrl.String(), "", "")

// XRootD does not like keep alives and kills things, so turn them off.
transport = GetTransport()
transport := config.GetTransport()
c.SetTransport(transport)

files, err := walkDir(url.Path, c)
Expand Down Expand Up @@ -902,7 +859,7 @@ func StatHttp(dest *url.URL, namespace namespaces.Namespace) (uint64, error) {

var resp *http.Response
for {
transport := GetTransport()
transport := config.GetTransport()
if disableProxy {
log.Debugln("Performing HEAD (without proxy)", dest.String())
transport.Proxy = nil
Expand Down
49 changes: 49 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
package config

import (
"crypto/tls"
_ "embed"
"encoding/json"
"fmt"
"io"
"net"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -86,6 +88,10 @@
// Potentially holds a directory to cleanup
tempRunDir string
cleanupOnce sync.Once

// Our global transports that only will get reconfigured if needed
transport *http.Transport
onceTransport sync.Once
)

// Based on the name of the current binary, determine the preferred "style"
Expand Down Expand Up @@ -236,6 +242,44 @@
return filepath.Join(home, ".config", "pelican"), nil
}

func setupTransport() {
//Getting timeouts and other information from defaults.yaml
maxIdleConns := viper.GetInt("Transport.MaxIdleIcons")
idleConnTimeout := viper.GetDuration("Transport.IdleConnTimeout")
transportTLSHandshakeTimeout := viper.GetDuration("Transport.TLSHandshakeTimeout")
expectContinueTimeout := viper.GetDuration("Transport.ExpectContinueTimeout")
responseHeaderTimeout := viper.GetDuration("Transport.ResponseHeaderTimeout")

transportDialerTimeout := viper.GetDuration("Transport.Dialer.Timeout")
transportKeepAlive := viper.GetDuration("Transport.Dialer.KeepAlive")

//Set up the transport
transport = &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: transportDialerTimeout,
KeepAlive: transportKeepAlive,
}).DialContext,
MaxIdleConns: maxIdleConns,
IdleConnTimeout: idleConnTimeout,
TLSHandshakeTimeout: transportTLSHandshakeTimeout,
ExpectContinueTimeout: expectContinueTimeout,
ResponseHeaderTimeout: responseHeaderTimeout,
}
if param.TLSSkipVerify.GetBool() {
transport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
Dismissed Show dismissed Hide dismissed
}

}

// function to get/setup the transport (only once)
func GetTransport() *http.Transport {
onceTransport.Do(func() {
setupTransport()
})
return transport
}

func InitServer() error {
configDir := viper.GetString("ConfigDir")
viper.SetConfigType("yaml")
Expand Down Expand Up @@ -314,6 +358,9 @@
return err
}
}

setupTransport()

return nil
}

Expand Down Expand Up @@ -419,5 +466,7 @@
}
viper.Set("MinimumDownloadSpeed", downloadLimit)

setupTransport()

return DiscoverFederation()
}
4 changes: 1 addition & 3 deletions namespace-registry/client_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/lestrrat-go/jwx/v2/jwa"
"github.com/lestrrat-go/jwx/v2/jwk"
"github.com/lestrrat-go/jwx/v2/jwt"
"github.com/pelicanplatform/pelican/client"
"github.com/pelicanplatform/pelican/config"
"github.com/pelicanplatform/pelican/director"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -62,8 +61,7 @@ func makeRequest(url string, method string, data map[string]interface{}, headers
for key, val := range headers {
req.Header.Set(key, val)
}

tr := client.GetTransport()
tr := config.GetTransport()
client := &http.Client{Transport: tr}

resp, err := client.Do(req)
Expand Down
4 changes: 2 additions & 2 deletions origin_ui/advertise.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"net/url"
"time"

"github.com/pelicanplatform/pelican/client"
"github.com/pelicanplatform/pelican/config"
"github.com/pelicanplatform/pelican/director"
"github.com/pelicanplatform/pelican/param"
"github.com/pkg/errors"
Expand Down Expand Up @@ -122,7 +122,7 @@ func AdvertiseOrigin() error {

// We should switch this over to use the common transport, but for that to happen
// that function needs to be exported from pelican
tr := client.GetTransport()
tr := config.GetTransport()
client := http.Client{Transport: tr}

resp, err := client.Do(req)
Expand Down
Loading