Skip to content

Commit

Permalink
Report MPTCP state through admin socket
Browse files Browse the repository at this point in the history
  • Loading branch information
neilalexander committed Aug 13, 2023
1 parent 3e33512 commit fd482d6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
18 changes: 10 additions & 8 deletions src/admin/getpeers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type PeerEntry struct {
PublicKey string `json:"key"`
Port uint64 `json:"port"`
Priority uint64 `json:"priority"`
Multipath bool `json:"multipath"`
RXBytes DataUnit `json:"bytes_recvd,omitempty"`
TXBytes DataUnit `json:"bytes_sent,omitempty"`
Uptime float64 `json:"uptime,omitempty"`
Expand All @@ -36,14 +37,15 @@ func (a *AdminSocket) getPeersHandler(req *GetPeersRequest, res *GetPeersRespons
res.Peers = make([]PeerEntry, 0, len(peers))
for _, p := range peers {
peer := PeerEntry{
Port: p.Port,
Up: p.Up,
Inbound: p.Inbound,
Priority: uint64(p.Priority), // can't be uint8 thanks to gobind
URI: p.URI,
RXBytes: DataUnit(p.RXBytes),
TXBytes: DataUnit(p.TXBytes),
Uptime: p.Uptime.Seconds(),
Port: p.Port,
Up: p.Up,
Inbound: p.Inbound,
Priority: uint64(p.Priority), // can't be uint8 thanks to gobind
Multipath: p.Multipath,
URI: p.URI,
RXBytes: DataUnit(p.RXBytes),
TXBytes: DataUnit(p.TXBytes),
Uptime: p.Uptime.Seconds(),
}
if addr := address.AddrForKey(p.Key); addr != nil {
peer.PublicKey = hex.EncodeToString(p.Key)
Expand Down
2 changes: 2 additions & 0 deletions src/core/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type PeerInfo struct {
Coords []uint64
Port uint64
Priority uint8
Multipath bool
RXBytes uint64
TXBytes uint64
Uptime time.Duration
Expand Down Expand Up @@ -87,6 +88,7 @@ func (c *Core) GetPeers() []PeerInfo {
peerinfo.RXBytes = atomic.LoadUint64(&c.rx)
peerinfo.TXBytes = atomic.LoadUint64(&c.tx)
peerinfo.Uptime = time.Since(c.up)
peerinfo.Multipath = isMPTCP(c)
}
if p, ok := conns[conn]; ok {
peerinfo.Key = p.Key
Expand Down
18 changes: 17 additions & 1 deletion src/core/link_tcp_mptcp_go121.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

package core

import "net"
import (
"crypto/tls"
"net"
)

func setMPTCPForDialer(d *net.Dialer) {
d.SetMultipathTCP(true)
Expand All @@ -12,3 +15,16 @@ func setMPTCPForDialer(d *net.Dialer) {
func setMPTCPForListener(lc *net.ListenConfig) {
lc.SetMultipathTCP(true)
}

func isMPTCP(c net.Conn) bool {
switch tc := c.(type) {
case *net.TCPConn:
mp, _ := tc.MultipathTCP()
return mp
case *tls.Conn:
mp, _ := tc.NetConn().(*net.TCPConn).MultipathTCP()
return mp
default:
return false
}
}
4 changes: 4 additions & 0 deletions src/core/link_tcp_mptcp_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ func setMPTCPForDialer(d *net.Dialer) {
func setMPTCPForListener(lc *net.ListenConfig) {
// Not supported on versions under Go 1.21
}

func isMPTCP(c net.Conn) bool {
return false
}

0 comments on commit fd482d6

Please sign in to comment.