tfo listener

This commit is contained in:
Frank Denis 2019-12-30 20:57:17 +01:00
parent d14d2b613a
commit 1fbe726080
1 changed files with 14 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"context"
crypto_rand "crypto/rand" crypto_rand "crypto/rand"
"encoding/binary" "encoding/binary"
"io" "io"
@ -8,6 +9,7 @@ import (
"net" "net"
"os" "os"
"sync/atomic" "sync/atomic"
"syscall"
"time" "time"
"github.com/jedisct1/dlog" "github.com/jedisct1/dlog"
@ -15,6 +17,7 @@ import (
stamps "github.com/jedisct1/go-dnsstamps" stamps "github.com/jedisct1/go-dnsstamps"
"github.com/miekg/dns" "github.com/miekg/dns"
"golang.org/x/crypto/curve25519" "golang.org/x/crypto/curve25519"
"golang.org/x/sys/unix"
) )
type Proxy struct { type Proxy struct {
@ -313,13 +316,22 @@ func (proxy *Proxy) tcpListener(acceptPc *net.TCPListener) {
} }
} }
func (proxy *Proxy) tcpListenerSetup(network, address string, cnx syscall.RawConn) error {
cnx.Write(func(fd uintptr) bool {
_ = syscall.SetsockoptInt(int(fd), unix.IPPROTO_TCP, unix.TCP_FASTOPEN, 10)
return true
})
return nil
}
func (proxy *Proxy) tcpListenerFromAddr(listenAddr *net.TCPAddr) error { func (proxy *Proxy) tcpListenerFromAddr(listenAddr *net.TCPAddr) error {
acceptPc, err := net.ListenTCP("tcp", listenAddr) listenConfig := net.ListenConfig{Control: proxy.tcpListenerSetup}
acceptPc, err := listenConfig.Listen(context.Background(), "tcp", listenAddr.String())
if err != nil { if err != nil {
return err return err
} }
dlog.Noticef("Now listening to %v [TCP]", listenAddr) dlog.Noticef("Now listening to %v [TCP]", listenAddr)
go proxy.tcpListener(acceptPc) go proxy.tcpListener(acceptPc.(*net.TCPListener))
return nil return nil
} }