mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-15 19:31:06 +01:00
33 lines
641 B
Go
33 lines
641 B
Go
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
|
|
}
|