summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--extendedstats/darwin.go81
-rw-r--r--extendedstats/other.go4
-rw-r--r--go.mod2
-rw-r--r--go.sum4
-rw-r--r--networkQuality.go2
5 files changed, 87 insertions, 6 deletions
diff --git a/extendedstats/darwin.go b/extendedstats/darwin.go
new file mode 100644
index 0000000..788e36c
--- /dev/null
+++ b/extendedstats/darwin.go
@@ -0,0 +1,81 @@
+//go:build darwin
+// +build darwin
+
+package extendedstats
+
+import (
+ "crypto/tls"
+ "fmt"
+ "net"
+
+ "github.com/network-quality/goresponsiveness/utilities"
+ "golang.org/x/sys/unix"
+)
+
+type ExtendedStats struct {
+ Maxseg uint64
+ MaxSendMss uint64
+ MaxRecvMss uint64
+ TotalRetransmissions uint64
+ totalSent uint64
+ TotalReorderings uint64
+ AverageRtt float64
+ rtt_measurements uint64
+ total_rtt float64
+ RetransmitRatio float64
+}
+
+func ExtendedStatsAvailable() bool {
+ return true
+}
+
+func (es *ExtendedStats) IncorporateConnectionStats(rawConn net.Conn) error {
+ tlsConn, ok := rawConn.(*tls.Conn)
+ if !ok {
+ 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 {
+ return fmt.Errorf("OOPS: Could not get the TCP info for the connection (not a TCP connection)!\n")
+ }
+ if info, err := getTCPConnectionInfo(tcpConn); err != nil {
+ return fmt.Errorf("OOPS: Could not get the TCP info for the connection: %v!\n", err)
+ } else {
+ es.Maxseg = utilities.Max(es.Maxseg, uint64(info.Maxseg))
+ es.TotalReorderings += info.Rxoutoforderbytes
+ es.TotalRetransmissions += info.Txretransmitbytes
+ es.totalSent += info.Txbytes
+ es.total_rtt += float64(info.Srtt)
+ es.rtt_measurements += 1
+ es.AverageRtt = es.total_rtt / float64(es.rtt_measurements)
+ es.RetransmitRatio = (float64(es.TotalRetransmissions) / float64(es.totalSent)) * 100.0
+ }
+ return nil
+}
+
+func (es *ExtendedStats) Repr() string {
+ return fmt.Sprintf(`Extended Statistics:
+ Maximum Segment Size: %v
+ Total Bytes Retransmitted: %v
+ Retransmission Ratio: %.2f%%
+ Total Bytes Reordered: %v
+ Average RTT: %v
+`, es.Maxseg, es.TotalRetransmissions, es.RetransmitRatio, es.TotalReorderings, es.AverageRtt)
+}
+
+func getTCPConnectionInfo(connection net.Conn) (*unix.TCPConnectionInfo, error) {
+ tcpConn, ok := connection.(*net.TCPConn)
+ if !ok {
+ return nil, fmt.Errorf("connection is not a net.TCPConn")
+ }
+ rawConn, err := tcpConn.SyscallConn()
+ if err != nil {
+ return nil, err
+ }
+
+ var info *unix.TCPConnectionInfo = nil
+ rawConn.Control(func(fd uintptr) {
+ info, err = unix.GetsockoptTCPConnectionInfo(int(fd), unix.IPPROTO_TCP, unix.TCP_CONNECTION_INFO)
+ })
+ return info, err
+}
diff --git a/extendedstats/other.go b/extendedstats/other.go
index 78c4dc9..d313826 100644
--- a/extendedstats/other.go
+++ b/extendedstats/other.go
@@ -1,5 +1,5 @@
-//go:build !dragonfly && !freebsd && !linux && !netbsd && !openbsd
-// +build !dragonfly,!freebsd,!linux,!netbsd,!openbsd
+//go:build !dragonfly && !freebsd && !linux && !netbsd && !openbsd && !darwin
+// +build !dragonfly,!freebsd,!linux,!netbsd,!openbsd,!darwin
package extendedstats
diff --git a/go.mod b/go.mod
index b69fccd..40e148a 100644
--- a/go.mod
+++ b/go.mod
@@ -4,7 +4,7 @@ go 1.18
require (
golang.org/x/net v0.0.0-20220225172249-27dd8689420f
- golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a
+ golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c
)
require golang.org/x/text v0.3.7 // indirect
diff --git a/go.sum b/go.sum
index ce291cf..1cbffce 100644
--- a/go.sum
+++ b/go.sum
@@ -1,6 +1,6 @@
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
-golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
-golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c h1:aFV+BgZ4svzjfabn8ERpuB4JI4N6/rdy1iusx77G3oU=
+golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
diff --git a/networkQuality.go b/networkQuality.go
index 3ba783d..eb8bdc4 100644
--- a/networkQuality.go
+++ b/networkQuality.go
@@ -434,7 +434,7 @@ func main() {
}
if *calculateExtendedStats {
- fmt.Printf(extendedStats.Repr())
+ fmt.Println(extendedStats.Repr())
}
cancelOperatingCtx()