summaryrefslogtreecommitdiff
path: root/utilities/utilities.go
diff options
context:
space:
mode:
authorWill Hawkins <[email protected]>2022-06-04 21:24:19 -0400
committerWill Hawkins <[email protected]>2022-06-04 21:24:19 -0400
commit9be87fa5ec89c9e393c9c93b3cb36668c71593d6 (patch)
tree7c5a5df400370660c670935dc36e2e4b0493ab86 /utilities/utilities.go
parentde7a7bf994a020049eca89098aab9d13ff81f361 (diff)
[Feature] Add conditional compilation support for GetTCPInfo
Now there is functionality for conditionally supporting GetTCPInfo depending on the platform. If the platform supports it, then the client can call utilities.GetTCPInfo. In the case that the platform does not support the GetTCPInfo function call, the result is an error of the type `NotImplemented`.
Diffstat (limited to 'utilities/utilities.go')
-rw-r--r--utilities/utilities.go54
1 files changed, 4 insertions, 50 deletions
diff --git a/utilities/utilities.go b/utilities/utilities.go
index e4c8a0d..7e26ab9 100644
--- a/utilities/utilities.go
+++ b/utilities/utilities.go
@@ -18,13 +18,10 @@ import (
"fmt"
"math"
"math/rand"
- "net"
"os"
"reflect"
"sync/atomic"
"time"
-
- "golang.org/x/sys/unix"
)
func IsInterfaceNil(ifc interface{}) bool {
@@ -126,53 +123,10 @@ func RandBetween(max int) int {
return rand.New(rand.NewSource(int64(time.Now().Nanosecond()))).Int() % max
}
-func GetTCPInfo(connection net.Conn) (*unix.TCPInfo, 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.TCPInfo = nil
- rawConn.Control(func(fd uintptr) {
- info, err = unix.GetsockoptTCPInfo(int(fd), unix.SOL_TCP, unix.TCP_INFO)
- })
- return info, err
+type NotImplemented struct {
+ Functionality string
}
-func PrintTCPInfo(info *unix.TCPInfo) {
- fmt.Printf("TCPInfo: \n")
- fmt.Printf(" State: %v\n", info.State)
- fmt.Printf(" Ca_state: %v\n", info.Ca_state)
- fmt.Printf(" Retransmits: %v\n", info.Retransmits)
- fmt.Printf(" Probes: %v\n", info.Probes)
- fmt.Printf(" Backoff: %v\n", info.Backoff)
- fmt.Printf(" Options: %v\n", info.Options)
- fmt.Printf(" Rto: %v\n", info.Rto)
- fmt.Printf(" Ato: %v\n", info.Ato)
- fmt.Printf(" Snd_mss: %v\n", info.Snd_mss)
- fmt.Printf(" Rcv_mss: %v\n", info.Rcv_mss)
- fmt.Printf(" Unacked: %v\n", info.Unacked)
- fmt.Printf(" Sacked: %v\n", info.Sacked)
- fmt.Printf(" Lost: %v\n", info.Lost)
- fmt.Printf(" Retrans: %v\n", info.Retrans)
- fmt.Printf(" Fackets: %v\n", info.Fackets)
- fmt.Printf(" Last_data_sent: %v\n", info.Last_data_sent)
- fmt.Printf(" Last_ack_sent: %v\n", info.Last_ack_sent)
- fmt.Printf(" Last_data_recv: %v\n", info.Last_data_recv)
- fmt.Printf(" Last_ack_recv: %v\n", info.Last_ack_recv)
- fmt.Printf(" Pmtu: %v\n", info.Pmtu)
- fmt.Printf(" Rcv_ssthresh: %v\n", info.Rcv_ssthresh)
- fmt.Printf(" Rtt: %v\n", info.Rtt)
- fmt.Printf(" Rttvar: %v\n", info.Rttvar)
- fmt.Printf(" Snd_ssthresh: %v\n", info.Snd_ssthresh)
- fmt.Printf(" Snd_cwnd: %v\n", info.Snd_cwnd)
- fmt.Printf(" Advmss: %v\n", info.Advmss)
- fmt.Printf(" Reordering: %v\n", info.Reordering)
- fmt.Printf(" Rcv_rtt: %v\n", info.Rcv_rtt)
- fmt.Printf(" Rcv_space: %v\n", info.Rcv_space)
- fmt.Printf(" Total_retrans: %v\n", info.Total_retrans)
+func (ni *NotImplemented) Error() string {
+ return fmt.Sprintf("%v not implemented.\n", ni.Functionality)
}