inbound tfo

This commit is contained in:
zhudan
2022-07-22 15:16:09 +08:00
parent b0fd50453a
commit 143c5de51d
8 changed files with 43 additions and 12 deletions

View File

@ -1,6 +1,8 @@
package http
import (
"context"
"github.com/database64128/tfo-go"
"net"
"time"
@ -30,12 +32,16 @@ func (l *Listener) Close() error {
return l.listener.Close()
}
func New(addr string, in chan<- C.ConnContext) (*Listener, error) {
return NewWithAuthenticate(addr, in, true)
func New(addr string, inboundTfo bool, in chan<- C.ConnContext) (*Listener, error) {
return NewWithAuthenticate(addr, in, true, inboundTfo)
}
func NewWithAuthenticate(addr string, in chan<- C.ConnContext, authenticate bool) (*Listener, error) {
l, err := net.Listen("tcp", addr)
func NewWithAuthenticate(addr string, in chan<- C.ConnContext, authenticate bool, inboundTfo bool) (*Listener, error) {
lc := tfo.ListenConfig{
DisableTFO: !inboundTfo,
}
l, err := lc.Listen(context.Background(), "tcp", addr)
if err != nil {
return nil, err
}

View File

@ -26,6 +26,7 @@ var (
allowLan = false
bindAddress = "*"
lastTunConf *config.Tun
inboundTfo = false
socksListener *socks.Listener
socksUDPListener *socks.UDPListener
@ -80,6 +81,10 @@ func SetBindAddress(host string) {
bindAddress = host
}
func SetInboundTfo(itfo bool) {
inboundTfo = itfo
}
func NewInner(tcpIn chan<- C.ConnContext) {
inner.New(tcpIn)
}
@ -109,7 +114,7 @@ func ReCreateHTTP(port int, tcpIn chan<- C.ConnContext) {
return
}
httpListener, err = http.New(addr, tcpIn)
httpListener, err = http.New(addr, inboundTfo, tcpIn)
if err != nil {
log.Errorln("Start HTTP server error: %s", err.Error())
return
@ -160,7 +165,7 @@ func ReCreateSocks(port int, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.P
return
}
tcpListener, err := socks.New(addr, tcpIn)
tcpListener, err := socks.New(addr, inboundTfo, tcpIn)
if err != nil {
return
}
@ -310,7 +315,7 @@ func ReCreateMixed(port int, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.P
return
}
mixedListener, err = mixed.New(addr, tcpIn)
mixedListener, err = mixed.New(addr, inboundTfo, tcpIn)
if err != nil {
return
}

View File

@ -1,6 +1,8 @@
package mixed
import (
"context"
"github.com/database64128/tfo-go"
"net"
"time"
@ -36,8 +38,11 @@ func (l *Listener) Close() error {
return l.listener.Close()
}
func New(addr string, in chan<- C.ConnContext) (*Listener, error) {
l, err := net.Listen("tcp", addr)
func New(addr string, inboundTfo bool, in chan<- C.ConnContext) (*Listener, error) {
lc := tfo.ListenConfig{
DisableTFO: !inboundTfo,
}
l, err := lc.Listen(context.Background(), "tcp", addr)
if err != nil {
return nil, err
}

View File

@ -1,6 +1,8 @@
package socks
import (
"context"
"github.com/database64128/tfo-go"
"io"
"net"
@ -34,8 +36,11 @@ func (l *Listener) Close() error {
return l.listener.Close()
}
func New(addr string, in chan<- C.ConnContext) (*Listener, error) {
l, err := net.Listen("tcp", addr)
func New(addr string, inboundTfo bool, in chan<- C.ConnContext) (*Listener, error) {
lc := tfo.ListenConfig{
DisableTFO: !inboundTfo,
}
l, err := lc.Listen(context.Background(), "tcp", addr)
if err != nil {
return nil, err
}