TLS basic implementation

This commit is contained in:
Iurii Egorov 2024-03-11 19:26:44 +03:00
parent 66b7fea496
commit 186c62412b

View file

@ -22,12 +22,10 @@ package conn
import ( import (
"bytes" "bytes"
"errors" "errors"
"fmt"
"io" "io"
"net" "net"
"net/netip" "net/netip"
"sync" "sync"
"syscall"
"time" "time"
tls "github.com/refraction-networking/utls" tls "github.com/refraction-networking/utls"
@ -80,18 +78,8 @@ func (bind *StdNetBindTcp) ParseEndpoint(s string) (Endpoint, error) {
} }
func dialTcp(addr string, protectSocket func(fd int) int) (*net.TCPConn, int, error) { func dialTcp(addr string, protectSocket func(fd int) int) (*net.TCPConn, int, error) {
protectStatus := -1 dialer := net.Dialer{Timeout: 5 * time.Second}
control := func(network, address string, conn syscall.RawConn) error {
return conn.Control(func(fd uintptr) {
protectStatus = protectSocket(int(fd))
})
}
dialer := net.Dialer{Timeout: 5 * time.Second, Control: control}
netConn, err := dialer.Dial("tcp", addr) netConn, err := dialer.Dial("tcp", addr)
if protectStatus < 0 {
return nil, 0, fmt.Errorf("Failed to protect socket: status=%d", protectStatus)
}
if err != nil { if err != nil {
return nil, 0, err return nil, 0, err
} }