diff options
| author | Will Hawkins <[email protected]> | 2022-09-07 10:31:46 -0400 |
|---|---|---|
| committer | Will Hawkins <[email protected]> | 2022-09-07 10:31:46 -0400 |
| commit | a4cabcf65b099b67747569b33fe43c345ea317ad (patch) | |
| tree | 30e1f622a6a5d4f8da77998b2092a432ebffdaf5 | |
| parent | 2843fddcf328198ed6bcf4199fa35755ae936692 (diff) | |
[Bugfix] Broken extended-stats compilation for macOS
Sorry everyone!
| -rw-r--r-- | extendedstats/darwin.go | 56 | ||||
| -rw-r--r-- | rpm/rpm.go | 3 |
2 files changed, 37 insertions, 22 deletions
diff --git a/extendedstats/darwin.go b/extendedstats/darwin.go index 92e48fc..0f52be5 100644 --- a/extendedstats/darwin.go +++ b/extendedstats/darwin.go @@ -29,27 +29,24 @@ 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)", - ) - } - 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)", - ) - } - if info, err := getTCPConnectionInfo(tcpConn); err != nil { +type TCPInfo struct { + Rxoutoforderbytes uint64 + Txretransmitbytes uint64 + Txbytes uint64 + Rtt uint32 + Maxseg uint32 + Snd_cwnd uint32 +} + +func (es *ExtendedStats) IncorporateConnectionStats(basicConn net.Conn) error { + if info, err := GetTCPInfo(basicConn); err != nil { return fmt.Errorf("OOPS: Could not get the TCP info for the connection: %v", 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.total_rtt += float64(info.Rtt) es.rtt_measurements += 1 es.AverageRtt = es.total_rtt / float64(es.rtt_measurements) es.RetransmitRatio = (float64(es.TotalRetransmissions) / float64(es.totalSent)) * 100.0 @@ -67,23 +64,40 @@ func (es *ExtendedStats) Repr() string { `, es.Maxseg, es.TotalRetransmissions, es.RetransmitRatio, es.TotalReorderings, es.AverageRtt) } -func getTCPConnectionInfo(connection net.Conn) (*unix.TCPConnectionInfo, error) { - tcpConn, ok := connection.(*net.TCPConn) +func GetTCPInfo(basicConn net.Conn) (*TCPInfo, error) { + tlsConn, ok := basicConn.(*tls.Conn) if !ok { - return nil, fmt.Errorf("connection is not a net.TCPConn") + return nil, fmt.Errorf( + "OOPS: Could not get the TCP info for the connection (not a TLS connection)", + ) + } + tcpConn, ok := tlsConn.NetConn().(*net.TCPConn) + if !ok { + return nil, fmt.Errorf( + "OOPS: Could not get the TCP info for the connection (not a TCP connection)", + ) } rawConn, err := tcpConn.SyscallConn() if err != nil { return nil, err } - var info *unix.TCPConnectionInfo = nil + var rawInfo *unix.TCPConnectionInfo = nil + var tcpInfo *TCPInfo = nil rawConn.Control(func(fd uintptr) { - info, err = unix.GetsockoptTCPConnectionInfo( + rawInfo, err = unix.GetsockoptTCPConnectionInfo( int(fd), unix.IPPROTO_TCP, unix.TCP_CONNECTION_INFO, ) }) - return info, err + if rawInfo != nil && err == nil { + tcpInfo = &TCPInfo{} + tcpInfo.Rxoutoforderbytes = rawInfo.Rxoutoforderbytes + tcpInfo.Txretransmitbytes = rawInfo.Txretransmitbytes + tcpInfo.Rtt = rawInfo.Srtt + tcpInfo.Snd_cwnd = rawInfo.Snd_cwnd + tcpInfo.Maxseg = rawInfo.Maxseg + } + return tcpInfo, err } @@ -190,10 +190,11 @@ func Probe( isThreadPanicing := recover() if isThreadPanicing != nil && debug.IsDebug(debugging.Level) { fmt.Printf( - "(%s) (%s Probe %v) Probe attempted to write to the result channel after its invoker ended.\n", + "(%s) (%s Probe %v) Probe attempted to write to the result channel after its invoker ended (official reason: %v).\n", debugging.Prefix, probeType.Value(), probeId, + isThreadPanicing, ) } }() |
