This repository has been archived by the owner on Jul 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
/
transport.go
63 lines (51 loc) · 1.5 KB
/
transport.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Package quic implements the QUIC API for Client-to-Server Connections
// https://w3c.github.io/webrtc-quic/
package quic
import (
"fmt"
"io"
"github.com/pion/logging"
"github.com/pion/quic/internal/wrapper"
)
// Transport is a quic transport focused on client/server use cases.
type Transport struct {
TransportBase
}
// NewTransport creates a new Transport
func NewTransport(url string, config *Config) (*Transport, error) {
if config.LoggerFactory == nil {
config.LoggerFactory = logging.NewDefaultLoggerFactory()
}
cfg := config.clone()
cfg.SkipVerify = true // Using self signed certificates for now
s, err := wrapper.Dial(url, cfg)
if err != nil {
return nil, err
}
t := &Transport{}
t.TransportBase.log = config.LoggerFactory.NewLogger("quic")
return t, t.TransportBase.startBase(s)
}
// single accept listen for testing
func newServer(url string, config *Config) (*Transport, io.Closer, error) {
loggerFactory := config.LoggerFactory
if loggerFactory == nil {
loggerFactory = logging.NewDefaultLoggerFactory()
}
cfg := config.clone()
cfg.SkipVerify = true // Using self signed certificates for now
l, err := wrapper.Listen(url, cfg)
if err != nil {
return nil, nil, err
}
s, err := l.Accept()
if err != nil {
if cerr := l.Close(); cerr != nil {
err = fmt.Errorf("failed to close listener (%s) after accept failed: %w", cerr, err)
}
return nil, nil, err
}
t := &Transport{}
t.TransportBase.log = loggerFactory.NewLogger("quic")
return t, l, t.TransportBase.startBase(s)
}