Documentation ¶
Overview ¶
Package tcpinfo implements encoding and decoding of TCP-level socket options regarding connection information.
The Transmission Control Protocol (TCP) is defined in RFC 793. TCP Selective Acknowledgment Options is defined in RFC 2018. Management Information Base for the Transmission Control Protocol (TCP) is defined in RFC 4022. TCP Congestion Control is defined in RFC 5681. Computing TCP's Retransmission Timer is described in RFC 6298. TCP Options and Maximum Segment Size (MSS) is defined in RFC 6691. Shared Use of Experimental TCP Options is defined in RFC 6994. TCP Extensions for High Performance is defined in RFC 7323.
NOTE: Older Linux kernels may not support extended TCP statistics described in RFC 4898.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BBRInfo ¶
type BBRInfo struct { MaxBW uint64 `json:"max_bw"` // maximum-filtered bandwidth in bps MinRTT time.Duration `json:"min_rtt"` // minimum-filtered round-trip time PacingGain uint `json:"pacing_gain"` // pacing gain shifted left 8 bits CongWindowGain uint `json:"cwnd_gain"` // congestion window gain shifted left 8 bits }
A BBRInfo represents Bottleneck Bandwidth and Round-trip propagation time-based congestion control information.
type CCAlgorithm ¶
type CCAlgorithm string
A CCAlgorithm represents a name of congestion control algorithm.
Only supported on Linux.
func (CCAlgorithm) Level ¶
func (cca CCAlgorithm) Level() int
Level implements the Level method of tcpopt.Option interface.
func (CCAlgorithm) Marshal ¶
func (cca CCAlgorithm) Marshal() ([]byte, error)
Marshal implements the Marshal method of tcpopt.Option interface.
func (CCAlgorithm) Name ¶
func (cca CCAlgorithm) Name() int
Name implements the Name method of tcpopt.Option interface.
type CCAlgorithmInfo ¶
type CCAlgorithmInfo interface {
Algorithm() string
}
A CCAlgorithmInfo represents congestion control algorithm information.
Only supported on Linux.
func ParseCCAlgorithmInfo ¶
func ParseCCAlgorithmInfo(name string, b []byte) (CCAlgorithmInfo, error)
ParseCCAlgorithmInfo parses congestion control algorithm information.
Only supported on Linux.
type CCInfo ¶
type CCInfo struct {
Raw []byte `json:"raw,omitempty"`
}
A CCInfo represents raw information of congestion control algorithm.
Only supported on Linux.
type CEState ¶
type CEState int
A CEState represents a state of ECN congestion encountered (CE) codepoint.
type CongestionControl ¶
type CongestionControl struct { SenderSSThreshold uint `json:"snd_ssthresh"` // slow start threshold for sender in bytes or # of segments ReceiverSSThreshold uint `json:"rcv_ssthresh"` // slow start threshold for receiver in bytes [Linux only] SenderWindowBytes uint `json:"snd_cwnd_bytes"` // congestion window for sender in bytes [Darwin and FreeBSD] SenderWindowSegs uint `json:"snd_cwnd_segs"` // congestion window for sender in # of segments [Linux and NetBSD] }
A CongestionControl represents congestion control information.
type DCTCPInfo ¶
type DCTCPInfo struct { Enabled bool `json:"enabled"` CEState CEState `json:"ce_state"` // state of ECN CE codepoint Alpha uint `json:"alpha"` // fraction of bytes sent ECNAckedBytes uint `json:"ecn_acked"` // # of acked bytes with ECN TotalAckedBytes uint `json:"total_acked"` // total # of acked bytes }
A DCTCPInfo represents Datacenter TCP congestion control information.
type FlowControl ¶
type FlowControl struct {
ReceiverWindow uint `json:"rcv_wnd"` // advertised receiver window in bytes
}
A FlowControl represents flow control information.
type Info ¶
type Info struct { State State `json:"state"` // connection state Options []Option `json:"opts,omitempty"` // requesting options PeerOptions []Option `json:"peer_opts,omitempty"` // options requested from peer SenderMSS MaxSegSize `json:"snd_mss"` // maximum segment size for sender in bytes ReceiverMSS MaxSegSize `json:"rcv_mss"` // maximum segment size for receiver in bytes RTT time.Duration `json:"rtt"` // round-trip time RTTVar time.Duration `json:"rttvar"` // round-trip time variation RTO time.Duration `json:"rto"` // retransmission timeout ATO time.Duration `json:"ato"` // delayed acknowledgement timeout [Linux only] LastDataSent time.Duration `json:"last_data_sent"` // since last data sent [Linux only] LastDataReceived time.Duration `json:"last_data_rcvd"` // since last data received [FreeBSD and Linux] LastAckReceived time.Duration `json:"last_ack_rcvd"` // since last ack received [Linux only] FlowControl *FlowControl `json:"flow_ctl,omitempty"` // flow control information CongestionControl *CongestionControl `json:"cong_ctl,omitempty"` // congestion control information Sys *SysInfo `json:"sys,omitempty"` // platform-specific information }
An Info represents connection information.
Only supported on Darwin, FreeBSD, Linux and NetBSD.
Example ¶
package main import ( "encoding/json" "fmt" "log" "net" "github.com/mikioh/tcp" "github.com/mikioh/tcpinfo" ) func main() { c, err := net.Dial("tcp", "golang.org:80") if err != nil { log.Fatal(err) } defer c.Close() tc, err := tcp.NewConn(c) if err != nil { log.Fatal(err) } var o tcpinfo.Info var b [256]byte i, err := tc.Option(o.Level(), o.Name(), b[:]) if err != nil { log.Fatal(err) } txt, err := json.Marshal(i) if err != nil { log.Fatal(err) } fmt.Println(string(txt)) }
Output:
func (*Info) MarshalJSON ¶
MarshalJSON implements the MarshalJSON method of json.Marshaler interface.
type OptionKind ¶
type OptionKind int
An OptionKind represents an option kind.
const ( KindMaxSegSize OptionKind = 2 KindWindowScale OptionKind = 3 KindSACKPermitted OptionKind = 4 KindTimestamps OptionKind = 8 )
func (OptionKind) String ¶
func (k OptionKind) String() string
type SACKPermitted ¶
type SACKPermitted bool
A SACKPermitted reports whether a selective acknowledgment permitted option is enabled.
func (SACKPermitted) Kind ¶
func (sp SACKPermitted) Kind() OptionKind
Kind returns an option kind field.
type SysInfo ¶
type SysInfo struct { PathMTU uint `json:"path_mtu"` // path maximum transmission unit AdvertisedMSS MaxSegSize `json:"adv_mss"` // advertised maximum segment size CAState CAState `json:"ca_state"` // state of congestion avoidance Retransmissions uint `json:"rexmits"` // # of retranmissions on timeout invoked Backoffs uint `json:"backoffs"` // # of times retransmission backoff timer invoked WindowOrKeepAliveProbes uint `json:"wnd_ka_probes"` // # of window or keep alive probes sent UnackedSegs uint `json:"unacked_segs"` // # of unack'd segments SackedSegs uint `json:"sacked_segs"` // # of sack'd segments LostSegs uint `json:"lost_segs"` // # of lost segments RetransSegs uint `json:"retrans_segs"` // # of retransmitting segments in transmission queue ForwardAckSegs uint `json:"fack_segs"` // # of forward ack segments in transmission queue ReorderedSegs uint `json:"reord_segs"` // # of reordered segments allowed ReceiverRTT time.Duration `json:"rcv_rtt"` // current RTT for receiver TotalRetransSegs uint `json:"total_retrans_segs"` // # of retransmitted segments PacingRate uint64 `json:"pacing_rate"` // pacing rate ThruBytesAcked uint64 `json:"thru_bytes_acked"` // # of bytes for which cumulative acknowledgments have been received ThruBytesReceived uint64 `json:"thru_bytes_rcvd"` // # of bytes for which cumulative acknowledgments have been sent SegsOut uint `json:"segs_out"` // # of segments sent SegsIn uint `json:"segs_in"` // # of segments received NotSentBytes uint `json:"not_sent_bytes"` // # of bytes not sent yet MinRTT time.Duration `json:"min_rtt"` // current measured minimum RTT; zero means not available DataSegsOut uint `json:"data_segs_out"` // # of segments sent containing a positive length data segment DataSegsIn uint `json:"data_segs_in"` // # of segments received containing a positive length data segment }
A SysInfo represents platform-specific information.
type VegasInfo ¶
type VegasInfo struct { Enabled bool `json:"enabled"` RoundTrips uint `json:"rnd_trips"` // # of round-trips RTT time.Duration `json:"rtt"` // round-trip time MinRTT time.Duration `json:"min_rtt"` // minimum round-trip time }
A VegasInfo represents Vegas congestion control information.
type WindowScale ¶
type WindowScale int
A WindowScale represents a windows scale option.
func (WindowScale) Kind ¶
func (ws WindowScale) Kind() OptionKind
Kind returns an option kind field.