Skip to content

Commit 62610a8

Browse files
committed
Report MPTCP state through admin socket
1 parent 04f423c commit 62610a8

File tree

4 files changed

+33
-9
lines changed

4 files changed

+33
-9
lines changed

src/admin/getpeers.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type PeerEntry struct {
2424
PublicKey string `json:"key"`
2525
Port uint64 `json:"port"`
2626
Priority uint64 `json:"priority"`
27+
Multipath bool `json:"multipath"`
2728
RXBytes DataUnit `json:"bytes_recvd,omitempty"`
2829
TXBytes DataUnit `json:"bytes_sent,omitempty"`
2930
Uptime float64 `json:"uptime,omitempty"`
@@ -36,14 +37,15 @@ func (a *AdminSocket) getPeersHandler(req *GetPeersRequest, res *GetPeersRespons
3637
res.Peers = make([]PeerEntry, 0, len(peers))
3738
for _, p := range peers {
3839
peer := PeerEntry{
39-
Port: p.Port,
40-
Up: p.Up,
41-
Inbound: p.Inbound,
42-
Priority: uint64(p.Priority), // can't be uint8 thanks to gobind
43-
URI: p.URI,
44-
RXBytes: DataUnit(p.RXBytes),
45-
TXBytes: DataUnit(p.TXBytes),
46-
Uptime: p.Uptime.Seconds(),
40+
Port: p.Port,
41+
Up: p.Up,
42+
Inbound: p.Inbound,
43+
Priority: uint64(p.Priority), // can't be uint8 thanks to gobind
44+
Multipath: p.Multipath,
45+
URI: p.URI,
46+
RXBytes: DataUnit(p.RXBytes),
47+
TXBytes: DataUnit(p.TXBytes),
48+
Uptime: p.Uptime.Seconds(),
4749
}
4850
if addr := address.AddrForKey(p.Key); addr != nil {
4951
peer.PublicKey = hex.EncodeToString(p.Key)

src/core/api.go

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ type PeerInfo struct {
3030
Coords []uint64
3131
Port uint64
3232
Priority uint8
33+
Multipath bool
3334
RXBytes uint64
3435
TXBytes uint64
3536
Uptime time.Duration
@@ -86,6 +87,7 @@ func (c *Core) GetPeers() []PeerInfo {
8687
peerinfo.RXBytes = atomic.LoadUint64(&c.rx)
8788
peerinfo.TXBytes = atomic.LoadUint64(&c.tx)
8889
peerinfo.Uptime = time.Since(c.up)
90+
peerinfo.Multipath = isMPTCP(c)
8991
}
9092
if p, ok := conns[conn]; ok {
9193
peerinfo.Key = p.Key

src/core/link_tcp_mptcp_go121.go

+17-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33

44
package core
55

6-
import "net"
6+
import (
7+
"crypto/tls"
8+
"net"
9+
)
710

811
func setMPTCPForDialer(d *net.Dialer) {
912
d.SetMultipathTCP(true)
@@ -12,3 +15,16 @@ func setMPTCPForDialer(d *net.Dialer) {
1215
func setMPTCPForListener(lc *net.ListenConfig) {
1316
lc.SetMultipathTCP(true)
1417
}
18+
19+
func isMPTCP(c net.Conn) bool {
20+
switch tc := c.(type) {
21+
case *net.TCPConn:
22+
mp, _ := tc.MultipathTCP()
23+
return mp
24+
case *tls.Conn:
25+
mp, _ := tc.NetConn().(*net.TCPConn).MultipathTCP()
26+
return mp
27+
default:
28+
return false
29+
}
30+
}

src/core/link_tcp_mptcp_other.go

+4
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ func setMPTCPForDialer(d *net.Dialer) {
1212
func setMPTCPForListener(lc *net.ListenConfig) {
1313
// Not supported on versions under Go 1.21
1414
}
15+
16+
func isMPTCP(c net.Conn) bool {
17+
return false
18+
}

0 commit comments

Comments
 (0)