mirror of
https://github.com/amnezia-vpn/amneziawg-go.git
synced 2025-06-05 04:43:44 +02:00
TLS basic implementation
This commit is contained in:
parent
66b7fea496
commit
186c62412b
1 changed files with 1 additions and 13 deletions
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue