-
Notifications
You must be signed in to change notification settings - Fork 2
/
dial.go
40 lines (34 loc) 路 862 Bytes
/
dial.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package quic
import (
"context"
"crypto/tls"
"fmt"
"log/slog"
"os"
"github.com/webtransport/quic"
)
// 2^60 == 1152921504606846976
var MaxBidiRemoteStreams int64 = 1 << 60
var TLSConfig = &tls.Config{
InsecureSkipVerify: true,
MinVersion: tls.VersionTLS13,
}
var QUICConfig = &quic.Config{
TLSConfig: TLSConfig,
MaxBidiRemoteStreams: MaxBidiRemoteStreams,
QLogLogger: slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{
AddSource: true,
Level: quic.QLogLevelFrame,
})),
}
func Dial(ctx context.Context, addr string) (*QuicSession, error) {
l, err := quic.Listen("udp", ":0", QUICConfig)
if err != nil {
return nil, err
}
session, err := l.Dial(ctx, "udp", addr, QUICConfig)
if err != nil {
return nil, fmt.Errorf("error dialing %s (go-quic): %w", addr, err)
}
return &QuicSession{session}, nil
}