diff options
| -rw-r--r-- | config/config.go | 46 | ||||
| -rw-r--r-- | lgc/lgc.go | 24 | ||||
| -rw-r--r-- | networkQuality.go | 49 | ||||
| -rw-r--r-- | rpm/rpm.go | 11 |
4 files changed, 88 insertions, 42 deletions
diff --git a/config/config.go b/config/config.go index 63dec5b..8d9eaa5 100644 --- a/config/config.go +++ b/config/config.go @@ -18,6 +18,7 @@ import ( "crypto/tls" "encoding/json" "fmt" + "io" "io/ioutil" "net/http" "net/url" @@ -28,9 +29,12 @@ import ( ) type ConfigUrls struct { - SmallUrl string `json:"small_https_download_url"` - LargeUrl string `json:"large_https_download_url"` - UploadUrl string `json:"https_upload_url"` + SmallUrl string `json:"small_https_download_url"` + SmallUrlHost string + LargeUrl string `json:"large_https_download_url"` + LargeUrlHost string + UploadUrl string `json:"https_upload_url"` + UploadUrlHost string } type Config struct { @@ -40,9 +44,13 @@ type Config struct { Test_Endpoint string } -func (c *Config) Get(configHost string, configPath string) error { +func (c *Config) Get(configHost string, configPath string, keyLogger io.Writer) error { configTransport := http2.Transport{} configTransport.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} + + if !utilities.IsInterfaceNil(keyLogger) { + configTransport.TLSClientConfig.KeyLogWriter = keyLogger + } configClient := &http.Client{Transport: &configTransport} // Extraneous /s in URLs is normally okay, but the Apple CDN does not // like them. Make sure that we put exactly one (1) / between the host @@ -54,7 +62,7 @@ func (c *Config) Get(configHost string, configPath string) error { resp, err := configClient.Get(c.Source) if err != nil { return fmt.Errorf( - "Error: Could not connect to configuration host %s: %v\n", + "could not connect to configuration host %s: %v", configHost, err, ) @@ -63,7 +71,7 @@ func (c *Config) Get(configHost string, configPath string) error { jsonConfig, err := ioutil.ReadAll(resp.Body) if err != nil { return fmt.Errorf( - "Error: Could not read configuration content downloaded from %s: %v\n", + "could not read configuration content downloaded from %s: %v", c.Source, err, ) @@ -72,29 +80,31 @@ func (c *Config) Get(configHost string, configPath string) error { err = json.Unmarshal(jsonConfig, c) if err != nil { return fmt.Errorf( - "Error: Could not parse configuration returned from %s: %v\n", + "could not parse configuration returned from %s: %v", c.Source, err, ) } - //if len(c.Test_Endpoint) != 0 { - if false { + if len(c.Test_Endpoint) != 0 { tempUrl, err := url.Parse(c.Urls.LargeUrl) if err != nil { - return fmt.Errorf("Error parsing large_https_download_url: %v", err) + return fmt.Errorf("error parsing large_https_download_url: %v", err) } - c.Urls.LargeUrl = tempUrl.Scheme + "://" + c.Test_Endpoint + "/" + tempUrl.Path + c.Urls.LargeUrl = tempUrl.Scheme + "://" + c.Test_Endpoint + "" + tempUrl.Path + c.Urls.LargeUrlHost = tempUrl.Host tempUrl, err = url.Parse(c.Urls.SmallUrl) if err != nil { - return fmt.Errorf("Error parsing small_https_download_url: %v", err) + return fmt.Errorf("error parsing small_https_download_url: %v", err) } - c.Urls.SmallUrl = tempUrl.Scheme + "://" + c.Test_Endpoint + "/" + tempUrl.Path + c.Urls.SmallUrl = tempUrl.Scheme + "://" + c.Test_Endpoint + "" + tempUrl.Path + c.Urls.SmallUrlHost = tempUrl.Host tempUrl, err = url.Parse(c.Urls.UploadUrl) if err != nil { - return fmt.Errorf("Error parsing https_upload_url: %v", err) + return fmt.Errorf("error parsing https_upload_url: %v", err) } - c.Urls.UploadUrl = tempUrl.Scheme + "://" + c.Test_Endpoint + "/" + tempUrl.Path + c.Urls.UploadUrl = tempUrl.Scheme + "://" + c.Test_Endpoint + "" + tempUrl.Path + c.Urls.UploadUrlHost = tempUrl.Host } return nil } @@ -114,7 +124,7 @@ func (c *Config) IsValid() error { if parsedUrl, err := url.ParseRequestURI(c.Urls.LargeUrl); err != nil || parsedUrl.Scheme != "https" { return fmt.Errorf( - "Configuration url large_https_download_url is invalid: %s", + "configuration url large_https_download_url is invalid: %s", utilities.Conditional( len(c.Urls.LargeUrl) != 0, c.Urls.LargeUrl, @@ -125,7 +135,7 @@ func (c *Config) IsValid() error { if parsedUrl, err := url.ParseRequestURI(c.Urls.SmallUrl); err != nil || parsedUrl.Scheme != "https" { return fmt.Errorf( - "Configuration url small_https_download_url is invalid: %s", + "configuration url small_https_download_url is invalid: %s", utilities.Conditional( len(c.Urls.SmallUrl) != 0, c.Urls.SmallUrl, @@ -136,7 +146,7 @@ func (c *Config) IsValid() error { if parsedUrl, err := url.ParseRequestURI(c.Urls.UploadUrl); err != nil || parsedUrl.Scheme != "https" { return fmt.Errorf( - "Configuration url https_upload_url is invalid: %s", + "configuration url https_upload_url is invalid: %s", utilities.Conditional( len(c.Urls.UploadUrl) != 0, c.Urls.UploadUrl, @@ -57,6 +57,7 @@ type LoadGeneratingConnectionDownload struct { downloaded uint64 lastIntervalEnd int64 Path string + Host string downloadStartTime time.Time lastDownloaded uint64 client *http.Client @@ -316,6 +317,17 @@ func (lgd *LoadGeneratingConnectionDownload) doDownload(ctx context.Context) { return } + // To support test_endpoint + if len(lgd.Host) != 0 { + if debug.IsDebug(lgd.debug) { + fmt.Printf( + "Because of a test_endpoint in the config, there is a special Host set for this connection: %s\n", + lgd.Host, + ) + } + request.Host = lgd.Host + } + // Used to disable compression request.Header.Set("Accept-Encoding", "identity") @@ -347,6 +359,7 @@ type LoadGeneratingConnectionUpload struct { uploaded uint64 lastIntervalEnd int64 Path string + Host string uploadStartTime time.Time lastUploaded uint64 client *http.Client @@ -411,6 +424,17 @@ func (lgu *LoadGeneratingConnectionUpload) doUpload(ctx context.Context) bool { return false } + // To support test_endpoint + if len(lgu.Host) != 0 { + if debug.IsDebug(lgu.debug) { + fmt.Printf( + "Because of a test_endpoint in the config, there is a special Host set for this connection: %s\n", + lgu.Host, + ) + } + request.Host = lgu.Host + } + // Used to disable compression request.Header.Set("Accept-Encoding", "identity") diff --git a/networkQuality.go b/networkQuality.go index 6f6f8ea..c3db256 100644 --- a/networkQuality.go +++ b/networkQuality.go @@ -132,7 +132,26 @@ func main() { ) } - if err := config.Get(configHostPort, *configPath); err != nil { + var sslKeyFileConcurrentWriter *ccw.ConcurrentWriter = nil + if *sslKeyFileName != "" { + if sslKeyFileHandle, err := os.OpenFile(*sslKeyFileName, os.O_RDWR|os.O_CREATE, os.FileMode(0600)); err != nil { + fmt.Printf("Could not open the keyfile for writing: %v!\n", err) + sslKeyFileConcurrentWriter = nil + } else { + if err = utilities.SeekForAppend(sslKeyFileHandle); err != nil { + fmt.Printf("Could not seek to the end of the key file: %v!\n", err) + sslKeyFileConcurrentWriter = nil + } else { + if debug.IsDebug(debugLevel) { + fmt.Printf("Doing SSL key logging through file %v\n", *sslKeyFileName) + } + sslKeyFileConcurrentWriter = ccw.NewConcurrentFileWriter(sslKeyFileHandle) + defer sslKeyFileHandle.Close() + } + } + } + + if err := config.Get(configHostPort, *configPath, sslKeyFileConcurrentWriter); err != nil { fmt.Fprintf(os.Stderr, "%s\n", err) return } @@ -180,26 +199,6 @@ func main() { pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() } - - var sslKeyFileConcurrentWriter *ccw.ConcurrentWriter = nil - if *sslKeyFileName != "" { - if sslKeyFileHandle, err := os.OpenFile(*sslKeyFileName, os.O_RDWR|os.O_CREATE, os.FileMode(0600)); err != nil { - fmt.Printf("Could not open the keyfile for writing: %v!\n", err) - sslKeyFileConcurrentWriter = nil - } else { - if err = utilities.SeekForAppend(sslKeyFileHandle); err != nil { - fmt.Printf("Could not seek to the end of the key file: %v!\n", err) - sslKeyFileConcurrentWriter = nil - } else { - if debug.IsDebug(debugLevel) { - fmt.Printf("Doing SSL key logging through file %v\n", *sslKeyFileName) - } - sslKeyFileConcurrentWriter = ccw.NewConcurrentFileWriter(sslKeyFileHandle) - defer sslKeyFileHandle.Close() - } - } - } - var selfProbeDataLogger datalogger.DataLogger[rpm.ProbeDataPoint] = nil var foreignProbeDataLogger datalogger.DataLogger[rpm.ProbeDataPoint] = nil var downloadThroughputDataLogger datalogger.DataLogger[rpm.ThroughputDataPoint] = nil @@ -309,25 +308,29 @@ func main() { generate_lgd := func() lgc.LoadGeneratingConnection { return &lgc.LoadGeneratingConnectionDownload{ Path: config.Urls.LargeUrl, + Host: config.Urls.LargeUrlHost, KeyLogger: sslKeyFileConcurrentWriter, } } generate_lgu := func() lgc.LoadGeneratingConnection { return &lgc.LoadGeneratingConnectionUpload{ Path: config.Urls.UploadUrl, + Host: config.Urls.UploadUrlHost, KeyLogger: sslKeyFileConcurrentWriter, } } generateSelfProbeConfiguration := func() rpm.ProbeConfiguration { return rpm.ProbeConfiguration{ - URL: config.Urls.SmallUrl, + URL: config.Urls.SmallUrl, + Host: config.Urls.SmallUrlHost, } } generateForeignProbeConfiguration := func() rpm.ProbeConfiguration { return rpm.ProbeConfiguration{ - URL: config.Urls.SmallUrl, + URL: config.Urls.SmallUrl, + Host: config.Urls.SmallUrlHost, } } @@ -56,7 +56,8 @@ func addFlows( } type ProbeConfiguration struct { - URL string + URL string + Host string } type ProbeDataPoint struct { @@ -111,6 +112,7 @@ func Probe( waitGroup *sync.WaitGroup, client *http.Client, probeUrl string, + probeHost string, // optional: for use with a test_endpoint probeType ProbeType, result *chan ProbeDataPoint, debugging *debug.DebugWithPrefix, @@ -138,6 +140,10 @@ func Probe( return err } + // To support test_endpoint + if len(probeHost) != 0 { + probe_req.Host = probeHost + } // Used to disable compression probe_req.Header.Set("Accept-Encoding", "identity") @@ -296,6 +302,7 @@ func CombinedProber( &wg, foreignProbeClient, foreignProbeConfiguration.URL, + foreignProbeConfiguration.Host, Foreign, &dataPoints, debugging, @@ -307,6 +314,7 @@ func CombinedProber( &wg, selfDownProbeConnection.Client(), selfProbeConfiguration.URL, + selfProbeConfiguration.Host, SelfDown, &dataPoints, debugging, @@ -318,6 +326,7 @@ func CombinedProber( &wg, selfUpProbeConnection.Client(), selfProbeConfiguration.URL, + selfProbeConfiguration.Host, SelfUp, &dataPoints, debugging, |
