summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Hawkins <[email protected]>2022-06-12 17:31:09 -0400
committerWill Hawkins <[email protected]>2022-06-12 17:31:09 -0400
commitc93a4dedc897f84992a6a34200fe954ba2ca435d (patch)
tree83643f39a3037599924485dffa7af114ecacea3b
parentbce8d0a53c56816e6b5acd4e0c9b53514981910a (diff)
[Bugfix] Dereference nil when type assertions failed in IncorporateConnectionStats
Errors as a result of failed type assertions in IncorporateConnectionStats were caught/logged but there was no function-termination control flow associated with these error conditions. As a result, control would continue and cause problems. This patch fixes that.
-rw-r--r--extendedstats/other.go4
-rw-r--r--extendedstats/unix.go12
-rw-r--r--networkQuality.go4
3 files changed, 12 insertions, 8 deletions
diff --git a/extendedstats/other.go b/extendedstats/other.go
index 825ea95..369c8f6 100644
--- a/extendedstats/other.go
+++ b/extendedstats/other.go
@@ -9,7 +9,9 @@ import (
type ExtendedStats struct{}
-func (es *ExtendedStats) IncorporateConnectionStats(conn net.Conn) {}
+func (es *ExtendedStats) IncorporateConnectionStats(conn net.Conn) error {
+ return fmt.Errorf("OOPS: IncorporateConnectionStats is not supported on this platform.")
+}
func (es *ExtendedStats) Repr() string {
return ""
diff --git a/extendedstats/unix.go b/extendedstats/unix.go
index c4dc065..fb4a2c8 100644
--- a/extendedstats/unix.go
+++ b/extendedstats/unix.go
@@ -1,5 +1,5 @@
//go:build dragonfly || freebsd || linux || netbsd || openbsd
-// +build dragonfly freebsd linux netbsd openbsd
+// +build dragonfly freebsd linux netbsd openbsd
package extendedstats
@@ -24,17 +24,17 @@ func ExtendedStatsAvailable() bool {
return true
}
-func (es *ExtendedStats) IncorporateConnectionStats(rawConn net.Conn) {
+func (es *ExtendedStats) IncorporateConnectionStats(rawConn net.Conn) error {
tlsConn, ok := rawConn.(*tls.Conn)
if !ok {
- fmt.Printf("OOPS: Could not get the TCP info for the connection (not a TLS connection)!\n")
+ return fmt.Errorf("OOPS: Could not get the TCP info for the connection (not a TLS connection)!\n")
}
tcpConn, ok := tlsConn.NetConn().(*net.TCPConn)
if !ok {
- fmt.Printf("OOPS: Could not get the TCP info for the connection (not a TCP connection)!\n")
+ return fmt.Errorf("OOPS: Could not get the TCP info for the connection (not a TCP connection)!\n")
}
if info, err := getTCPInfo(tcpConn); err != nil {
- fmt.Printf("OOPS: Could not get the TCP info for the connection: %v!\n", err)
+ return fmt.Errorf("OOPS: Could not get the TCP info for the connection: %v!\n", err)
} else {
es.MaxPathMtu = utilities.Max(es.MaxPathMtu, uint64(info.Pmtu))
// https://lkml.iu.edu/hypermail/linux/kernel/1705.0/01790.html
@@ -42,8 +42,8 @@ func (es *ExtendedStats) IncorporateConnectionStats(rawConn net.Conn) {
es.total_rtt += float64(info.Rtt)
es.rtt_measurements += 1
es.AverageRtt = es.total_rtt / float64(es.rtt_measurements)
-
}
+ return nil
}
func (es *ExtendedStats) Repr() string {
diff --git a/networkQuality.go b/networkQuality.go
index e5e3631..c7dd74b 100644
--- a/networkQuality.go
+++ b/networkQuality.go
@@ -313,7 +313,9 @@ func main() {
if !extendedstats.ExtendedStatsAvailable() {
panic("Extended stats are not available but the user requested their calculation.")
}
- extendedStats.IncorporateConnectionStats(downloadSaturation.LGCs[i].Stats().ConnInfo.Conn)
+ if err := extendedStats.IncorporateConnectionStats(downloadSaturation.LGCs[i].Stats().ConnInfo.Conn); err != nil {
+ fmt.Fprintf(os.Stderr, "Warning: Could not add extended stats for the connection: %v", err)
+ }
}
}