mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-23 02:36:42 +00:00
Add quic transporter
This commit is contained in:
32
relay/client/dialer/quic/quic.go
Normal file
32
relay/client/dialer/quic/quic.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package quic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"net"
|
||||
|
||||
"github.com/quic-go/quic-go"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func Dial(address string) (net.Conn, error) {
|
||||
tlsConf := &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
NextProtos: []string{"quic-echo-example"},
|
||||
}
|
||||
qConn, err := quic.DialAddr(context.Background(), address, tlsConf, &quic.Config{
|
||||
EnableDatagrams: true,
|
||||
})
|
||||
if err != nil {
|
||||
log.Errorf("dial quic address %s failed: %s", address, err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
stream, err := qConn.OpenStreamSync(context.Background())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
conn := NewConn(stream, qConn)
|
||||
return conn, nil
|
||||
}
|
||||
Reference in New Issue
Block a user