diff options
| author | Will Hawkins <[email protected]> | 2023-04-22 01:27:59 -0400 |
|---|---|---|
| committer | Will Hawkins <[email protected]> | 2023-04-22 01:27:59 -0400 |
| commit | d5ec3aba77624387711ffa90e6960e406e9790e6 (patch) | |
| tree | 6c32da06f26e9abc0bc1821b2457a5f32d5cb098 /networkQuality.go | |
| parent | b2e528e07842488e573aefe783f1da755f818ffa (diff) | |
[Refactor] Move components into separate packages
A long-overdue change to split certain packages once smashed into the
RPM package into their own package. The resulting code should make it
easier for people to navigate the source code.
In the process, fixed a bug where a self probe being started on a
load-generating connection races with the establishment of the
load-generating connection and causes a panic because the self probe is
not establishing a connection on an already established connection.
Diffstat (limited to 'networkQuality.go')
| -rw-r--r-- | networkQuality.go | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/networkQuality.go b/networkQuality.go index 06ac0a0..309aa94 100644 --- a/networkQuality.go +++ b/networkQuality.go @@ -32,6 +32,7 @@ import ( "github.com/network-quality/goresponsiveness/extendedstats" "github.com/network-quality/goresponsiveness/lgc" "github.com/network-quality/goresponsiveness/ms" + "github.com/network-quality/goresponsiveness/probe" "github.com/network-quality/goresponsiveness/rpm" "github.com/network-quality/goresponsiveness/stabilizer" "github.com/network-quality/goresponsiveness/timeoutat" @@ -246,8 +247,8 @@ func main() { pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() } - var selfProbeDataLogger datalogger.DataLogger[rpm.ProbeDataPoint] = nil - var foreignProbeDataLogger datalogger.DataLogger[rpm.ProbeDataPoint] = nil + var selfProbeDataLogger datalogger.DataLogger[probe.ProbeDataPoint] = nil + var foreignProbeDataLogger datalogger.DataLogger[probe.ProbeDataPoint] = nil var downloadThroughputDataLogger datalogger.DataLogger[rpm.ThroughputDataPoint] = nil var uploadThroughputDataLogger datalogger.DataLogger[rpm.ThroughputDataPoint] = nil var granularThroughputDataLogger datalogger.DataLogger[rpm.GranularThroughputDataPoint] = nil @@ -275,7 +276,7 @@ func main() { "-throughput-granular-"+unique, ) - selfProbeDataLogger, err = datalogger.CreateCSVDataLogger[rpm.ProbeDataPoint]( + selfProbeDataLogger, err = datalogger.CreateCSVDataLogger[probe.ProbeDataPoint]( dataLoggerSelfFilename, ) if err != nil { @@ -286,7 +287,7 @@ func main() { selfProbeDataLogger = nil } - foreignProbeDataLogger, err = datalogger.CreateCSVDataLogger[rpm.ProbeDataPoint]( + foreignProbeDataLogger, err = datalogger.CreateCSVDataLogger[probe.ProbeDataPoint]( dataLoggerForeignFilename, ) if err != nil { @@ -333,10 +334,10 @@ func main() { // If, for some reason, the data loggers are nil, make them Null Data Loggers so that we don't have conditional // code later. if selfProbeDataLogger == nil { - selfProbeDataLogger = datalogger.CreateNullDataLogger[rpm.ProbeDataPoint]() + selfProbeDataLogger = datalogger.CreateNullDataLogger[probe.ProbeDataPoint]() } if foreignProbeDataLogger == nil { - foreignProbeDataLogger = datalogger.CreateNullDataLogger[rpm.ProbeDataPoint]() + foreignProbeDataLogger = datalogger.CreateNullDataLogger[probe.ProbeDataPoint]() } if downloadThroughputDataLogger == nil { downloadThroughputDataLogger = datalogger.CreateNullDataLogger[rpm.ThroughputDataPoint]() @@ -352,26 +353,26 @@ func main() { * Create (and then, ironically, name) two anonymous functions that, when invoked, * will create load-generating connections for upload/download */ - generate_lgd := func() lgc.LoadGeneratingConnection { + generateLgdc := func() lgc.LoadGeneratingConnection { lgd := lgc.NewLoadGeneratingConnectionDownload(config.Urls.LargeUrl, sslKeyFileConcurrentWriter, config.ConnectToAddr, *insecureSkipVerify) return &lgd } - generate_lgu := func() lgc.LoadGeneratingConnection { + generateLguc := func() lgc.LoadGeneratingConnection { lgu := lgc.NewLoadGeneratingConnectionUpload(config.Urls.UploadUrl, sslKeyFileConcurrentWriter, config.ConnectToAddr, *insecureSkipVerify) return &lgu } - generateSelfProbeConfiguration := func() rpm.ProbeConfiguration { - return rpm.ProbeConfiguration{ + generateSelfProbeConfiguration := func() probe.ProbeConfiguration { + return probe.ProbeConfiguration{ URL: config.Urls.SmallUrl, ConnectToAddr: config.ConnectToAddr, InsecureSkipVerify: *insecureSkipVerify, } } - generateForeignProbeConfiguration := func() rpm.ProbeConfiguration { - return rpm.ProbeConfiguration{ + generateForeignProbeConfiguration := func() probe.ProbeConfiguration { + return probe.ProbeConfiguration{ URL: config.Urls.SmallUrl, ConnectToAddr: config.ConnectToAddr, InsecureSkipVerify: *insecureSkipVerify, @@ -393,7 +394,7 @@ func main() { networkActivityCtx, downloadLoadGeneratorOperatorCtx, time.Second, - generate_lgd, + generateLgdc, &downloadLoadGeneratingConnectionCollection, *calculateExtendedStats, downloadDebugging, @@ -402,7 +403,7 @@ func main() { networkActivityCtx, uploadLoadGeneratorOperatorCtx, time.Second, - generate_lgu, + generateLguc, &uploadLoadGeneratingConnectionCollection, *calculateExtendedStats, uploadDebugging, @@ -410,7 +411,7 @@ func main() { // Handles for the first connection that the load-generating go routines (both up and // download) open are passed back on the self[Down|Up]ProbeConnectionCommunicationChannel - // so that we can then start probes on those handles. + // so that we can then start probes on those connections. selfDownProbeConnection := <-selfDownProbeConnectionCommunicationChannel selfUpProbeConnection := <-selfUpProbeConnectionCommunicationChannel @@ -532,7 +533,7 @@ timeout: fmt.Printf( "################# Responsiveness is instantaneously %s.\n", utilities.Conditional(responsivenessIsStable, "stable", "unstable")) } - if probeMeasurement.Type == rpm.Foreign { + if probeMeasurement.Type == probe.Foreign { // There may be more than one round trip accumulated together. If that is the case, // we will blow them apart in to three separate measurements and each one will just // be 1 / measurement.RoundTripCount of the total length. @@ -540,13 +541,13 @@ timeout: foreignRtts.AddElement(probeMeasurement.Duration.Seconds() / float64(probeMeasurement.RoundTripCount)) } - } else if probeMeasurement.Type == rpm.SelfDown || probeMeasurement.Type == rpm.SelfUp { + } else if probeMeasurement.Type == probe.SelfDown || probeMeasurement.Type == probe.SelfUp { selfRtts.AddElement(probeMeasurement.Duration.Seconds()) } - if probeMeasurement.Type == rpm.Foreign { + if probeMeasurement.Type == probe.Foreign { foreignProbeDataLogger.LogRecord(probeMeasurement) - } else if probeMeasurement.Type == rpm.SelfDown || probeMeasurement.Type == rpm.SelfUp { + } else if probeMeasurement.Type == probe.SelfDown || probeMeasurement.Type == probe.SelfUp { selfProbeDataLogger.LogRecord(probeMeasurement) } } @@ -592,10 +593,11 @@ timeout: defer downloadLoadGeneratingConnectionCollection.Lock.Unlock() // Note: We do not trace upload connections! - for i := 0; i < len(*downloadLoadGeneratingConnectionCollection.LGCs); i++ { + for i := 0; i < downloadLoadGeneratingConnectionCollection.Len(); i++ { // Assume that extended statistics are available -- the check was done explicitly at // program startup if the calculateExtendedStats flag was set by the user on the command line. - if err := extendedStats.IncorporateConnectionStats((*downloadLoadGeneratingConnectionCollection.LGCs)[i].Stats().ConnInfo.Conn); err != nil { + currentLgc, _ := downloadLoadGeneratingConnectionCollection.Get(i) + if err := extendedStats.IncorporateConnectionStats((*currentLgc).Stats().ConnInfo.Conn); err != nil { fmt.Fprintf( os.Stderr, "Warning: Could not add extended stats for the connection: %v\n", |
