Skip to content

Commit e921fee

Browse files
committed
Add support for Multipath TCP
1 parent fec96a3 commit e921fee

File tree

5 files changed

+45
-8
lines changed

5 files changed

+45
-8
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,omitempty"`
2728
RXBytes DataUnit `json:"bytes_recvd,omitempty"`
2829
TXBytes DataUnit `json:"bytes_sent,omitempty"`
2930
Uptime float64 `json:"uptime,omitempty"`
@@ -37,14 +38,15 @@ func (a *AdminSocket) getPeersHandler(req *GetPeersRequest, res *GetPeersRespons
3738
res.Peers = make([]PeerEntry, 0, len(peers))
3839
for _, p := range peers {
3940
peer := PeerEntry{
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-
URI: p.URI,
45-
RXBytes: DataUnit(p.RXBytes),
46-
TXBytes: DataUnit(p.TXBytes),
47-
Uptime: p.Uptime.Seconds(),
41+
Port: p.Port,
42+
Up: p.Up,
43+
Inbound: p.Inbound,
44+
Priority: uint64(p.Priority), // can't be uint8 thanks to gobind
45+
Multipath: p.Multipath,
46+
URI: p.URI,
47+
RXBytes: DataUnit(p.RXBytes),
48+
TXBytes: DataUnit(p.TXBytes),
49+
Uptime: p.Uptime.Seconds(),
4850
}
4951
if p.Latency > 0 {
5052
peer.Latency = p.Latency

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
@@ -87,6 +88,7 @@ func (c *Core) GetPeers() []PeerInfo {
8788
peerinfo.RXBytes = atomic.LoadUint64(&c.rx)
8889
peerinfo.TXBytes = atomic.LoadUint64(&c.tx)
8990
peerinfo.Uptime = time.Since(c.up)
91+
peerinfo.Multipath = isMPTCP(c)
9092
}
9193
if p, ok := conns[conn]; ok {
9294
peerinfo.Key = p.Key

src/core/link_tcp.go

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func (l *links) newLinkTCP() *linkTCP {
2727
_listeners: map[*Listener]context.CancelFunc{},
2828
}
2929
lt.listenconfig.Control = lt.tcpContext
30+
setMPTCPForListener(lt.listenconfig)
3031
return lt
3132
}
3233

@@ -112,6 +113,7 @@ func (l *linkTCP) dialerFor(dst *net.TCPAddr, sintf string) (*net.Dialer, error)
112113
KeepAlive: -1,
113114
Control: l.tcpContext,
114115
}
116+
setMPTCPForDialer(dialer)
115117
if sintf != "" {
116118
dialer.Control = l.getControl(sintf)
117119
ief, err := net.InterfaceByName(sintf)

src/core/link_tcp_mptcp.go

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package core
2+
3+
import (
4+
"crypto/tls"
5+
"net"
6+
)
7+
8+
func setMPTCPForDialer(d *net.Dialer) {
9+
d.SetMultipathTCP(true)
10+
}
11+
12+
func setMPTCPForListener(lc *net.ListenConfig) {
13+
lc.SetMultipathTCP(true)
14+
}
15+
16+
func isMPTCP(c net.Conn) bool {
17+
switch tc := c.(type) {
18+
case *net.TCPConn:
19+
mp, _ := tc.MultipathTCP()
20+
return mp
21+
case *tls.Conn:
22+
if tc, ok := tc.NetConn().(*net.TCPConn); ok {
23+
mp, _ := tc.MultipathTCP()
24+
return mp
25+
}
26+
return false
27+
default:
28+
return false
29+
}
30+
}

src/core/link_tls.go

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func (l *links) newLinkTLS(tcp *linkTCP) *linkTLS {
3030
config: l.core.config.tls.Clone(),
3131
_listeners: map[*Listener]context.CancelFunc{},
3232
}
33+
setMPTCPForListener(lt.listener)
3334
return lt
3435
}
3536

0 commit comments

Comments
 (0)