Skip to content

Commit

Permalink
Add tcpMptcp to sockopt (#2520)
Browse files Browse the repository at this point in the history
  • Loading branch information
yylt authored Sep 7, 2023
1 parent 853a866 commit c00e56c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 26 deletions.
2 changes: 2 additions & 0 deletions infra/conf/transport_internet.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ type SocketConfig struct {
TCPUserTimeout int32 `json:"tcpUserTimeout"`
V6only bool `json:"v6only"`
Interface string `json:"interface"`
TcpMptcp bool `json:"tcpMptcp"`
}

// Build implements Buildable.
Expand Down Expand Up @@ -677,6 +678,7 @@ func (c *SocketConfig) Build() (*internet.SocketConfig, error) {
TcpUserTimeout: c.TCPUserTimeout,
V6Only: c.V6only,
Interface: c.Interface,
TcpMptcp: c.TcpMptcp,
}, nil
}

Expand Down
58 changes: 34 additions & 24 deletions transport/internet/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions transport/internet/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,6 @@ message SocketConfig {
int32 tcp_max_seg = 17;

bool tcp_no_delay = 18;

bool tcp_mptcp = 19;
}
3 changes: 3 additions & 0 deletions transport/internet/system_dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ func (d *DefaultSystemDialer) Dial(ctx context.Context, src net.Address, dest ne
}

if sockopt != nil || len(d.controllers) > 0 {
if sockopt != nil && sockopt.TcpMptcp {
dialer.SetMultipathTCP(true)
}
dialer.Control = func(network, address string, c syscall.RawConn) error {
for _, ctl := range d.controllers {
if err := ctl(network, address, c); err != nil {
Expand Down
9 changes: 7 additions & 2 deletions transport/internet/system_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ func (dl *DefaultListener) Listen(ctx context.Context, addr net.Addr, sockopt *S
network = addr.Network()
address = addr.String()
lc.Control = getControlFunc(ctx, sockopt, dl.controllers)
if sockopt != nil && (sockopt.TcpKeepAliveInterval != 0 || sockopt.TcpKeepAliveIdle != 0) {
lc.KeepAlive = time.Duration(-1)
if sockopt != nil {
if sockopt.TcpKeepAliveInterval != 0 || sockopt.TcpKeepAliveIdle != 0 {
lc.KeepAlive = time.Duration(-1)
}
if sockopt.TcpMptcp {
lc.SetMultipathTCP(true)
}
}
case *net.UnixAddr:
lc.Control = nil
Expand Down

0 comments on commit c00e56c

Please sign in to comment.