Skip to content

Commit

Permalink
feat: enable mptcp by default close Ehco1996#245
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehco1996 committed Aug 9, 2024
1 parent a34a489 commit b1ed804
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
23 changes: 23 additions & 0 deletions examples/mptcp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"log_level": "info",
"relay_configs": [
{
"label": "client",
"listen": "127.0.0.1:1234",
"listen_type": "raw",
"transport_type": "raw",
"tcp_remotes": [
"0.0.0.0:1235"
]
},
{
"label": "server",
"listen": "127.0.0.1:1235",
"listen_type": "raw",
"transport_type": "raw",
"tcp_remotes": [
"0.0.0.0:5201"
]
}
]
}
14 changes: 11 additions & 3 deletions internal/transporter/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func newRawClient(cfg *conf.Config) (*RawClient, error) {
cfg: cfg,
dialer: &net.Dialer{Timeout: constant.DialTimeOut},
}
r.dialer.SetMultipathTCP(true)
return r, nil
}

Expand Down Expand Up @@ -59,15 +60,17 @@ func (raw *RawClient) HealthCheck(ctx context.Context, remote *lb.Node) error {

type RawServer struct {
*baseTransporter
lis *net.TCPListener
lis net.Listener
}

func newRawServer(base *baseTransporter) (*RawServer, error) {
addr, err := base.GetTCPListenAddr()
if err != nil {
return nil, err
}
lis, err := net.ListenTCP("tcp", addr)
cfg := net.ListenConfig{}
cfg.SetMultipathTCP(true)
lis, err := cfg.Listen(context.TODO(), "tcp", addr.String())
if err != nil {
return nil, err
}
Expand All @@ -83,10 +86,15 @@ func (s *RawServer) Close() error {

func (s *RawServer) ListenAndServe() error {
for {
c, err := s.lis.AcceptTCP()
c, err := s.lis.Accept()
if err != nil {
return err
}
isMultipathTCP, err := c.(*net.TCPConn).MultipathTCP()
if err != nil {
s.l.Errorf("Check MultipathTCP meet error:%s", err)
}
s.l.Debug("isMultipathTCP:%v", isMultipathTCP)
go func(c net.Conn) {
defer c.Close()
if err := s.RelayTCPConn(c, s.relayer.TCPHandShake); err != nil {
Expand Down

0 comments on commit b1ed804

Please sign in to comment.