Skip to content

Commit 940d6aa

Browse files
cryptixSean-Der
authored andcommitted
Update pion/quic binings
* fix gathering for quic transport test * quic e2e test: make sure data is received * fix loggingFactory setup * CI: add '-tags quic' in 'go test' * CI: add --build-tags to golangci-lint. * use latest pion/[email protected]
1 parent d893dcf commit 940d6aa

File tree

7 files changed

+104
-40
lines changed

7 files changed

+104
-40
lines changed

.github/.ci.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
GO_JS_WASM_EXEC=${PWD}/test-wasm/go_js_wasm_exec
2+
TEST_EXTRA_ARGS="-tags quic"
3+
GOLANGCI_LINT_EXRA_ARGS="--build-tags quic"
24
EXCLUDED_CONTRIBUTORS=('Josh Bleecher Snyder')

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu
183183
* [JacobZwang](https://github.com/JacobZwang)
184184
* [박종훈](https://github.com/JonghunBok)
185185
* [Sam Lancia](https://github.com/nerd2)
186+
* [Henry](https://github.com/cryptix)
186187

187188
### License
188189
MIT License - see [LICENSE](LICENSE) for full text

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/pion/dtls/v2 v2.0.2
88
github.com/pion/ice/v2 v2.0.0-rc.8
99
github.com/pion/logging v0.2.2
10-
github.com/pion/quic v0.1.1
10+
github.com/pion/quic v0.1.3
1111
github.com/pion/randutil v0.1.0
1212
github.com/pion/rtcp v1.2.3
1313
github.com/pion/rtp v1.6.0

go.sum

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/alangpierce/go-forceexport v0.0.0-20160317203124-8f1d6941cd75 h1:3ILjVyslFbc4jl1w5TWuvvslFD/nDfR2H8tVaMVLrEY=
2+
github.com/alangpierce/go-forceexport v0.0.0-20160317203124-8f1d6941cd75/go.mod h1:uAXEEpARkRhCZfEvy/y0Jcc888f9tHCc1W7/UeEtreE=
13
github.com/cheekybits/genny v1.0.0 h1:uGGa4nei+j20rOSeDeP5Of12XVm7TGUd4dJA9RDitfE=
24
github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wXkRAgjxjQ=
35
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -7,8 +9,9 @@ github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV
79
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
810
github.com/golang/mock v1.2.0 h1:28o5sBqPkBsMGnC6b4MvE2TzSr5/AT4c/1fLqVGIwlk=
911
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
10-
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
1112
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
13+
github.com/golang/protobuf v1.3.0 h1:kbxbvI4Un1LUWKxufD+BiE6AEExYYgkQLQmLFqA1LFk=
14+
github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0=
1215
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
1316
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
1417
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
@@ -18,10 +21,13 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
1821
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
1922
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
2023
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
21-
github.com/lucas-clemente/quic-go v0.7.1-0.20190401152353-907071221cf9 h1:tbuodUh2vuhOVZAdW3NEUvosFHUMJwUNl7jk/VSEiwc=
22-
github.com/lucas-clemente/quic-go v0.7.1-0.20190401152353-907071221cf9/go.mod h1:PpMmPfPKO9nKJ/psF49ESTAGQSdfXxlg1otPbEB2nOw=
23-
github.com/marten-seemann/qtls v0.2.3 h1:0yWJ43C62LsZt08vuQJDK1uC1czUc3FJeCLPoNAI4vA=
24-
github.com/marten-seemann/qtls v0.2.3/go.mod h1:xzjG7avBwGGbdZ8dTGxlBnLArsVKLvwmjgmPuiQEcYk=
24+
github.com/lucas-clemente/quic-go v0.14.4 h1:LdXgELrB93kvTqbZyEf+mcsGvmyE+EHsLFz1dqbR5PI=
25+
github.com/lucas-clemente/quic-go v0.14.4/go.mod h1:Vn3/Fb0/77b02SGhQk36KzOUmXgVpFfizUfW5WMaqyU=
26+
github.com/marten-seemann/chacha20 v0.2.0 h1:f40vqzzx+3GdOmzQoItkLX5WLvHgPgyYqFFIO5Gh4hQ=
27+
github.com/marten-seemann/chacha20 v0.2.0/go.mod h1:HSdjFau7GzYRj+ahFNwsO3ouVJr1HFkWoEwNDb4TMtE=
28+
github.com/marten-seemann/qpack v0.1.0/go.mod h1:LFt1NU/Ptjip0C2CPkhimBz5CGE3WGDAUWqna+CNTrI=
29+
github.com/marten-seemann/qtls v0.4.1 h1:YlT8QP3WCCvvok7MGEZkMldXbyqgr8oFg5/n8Gtbkks=
30+
github.com/marten-seemann/qtls v0.4.1/go.mod h1:pxVXcHHw1pNIt8Qo0pwSYQEoZ8yYOOPXTCZLQQunvRc=
2531
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
2632
github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
2733
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
@@ -37,8 +43,8 @@ github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
3743
github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
3844
github.com/pion/mdns v0.0.4 h1:O4vvVqr4DGX63vzmO6Fw9vpy3lfztVWHGCQfyw0ZLSY=
3945
github.com/pion/mdns v0.0.4/go.mod h1:R1sL0p50l42S5lJs91oNdUL58nm0QHrhxnSegr++qC0=
40-
github.com/pion/quic v0.1.1 h1:D951FV+TOqI9A0rTF7tHx0Loooqz+nyzjEyj8o3PuMA=
41-
github.com/pion/quic v0.1.1/go.mod h1:zEU51v7ru8Mp4AUBJvj6psrSth5eEFNnVQK5K48oV3k=
46+
github.com/pion/quic v0.1.3 h1:nLXLffDaOb7z4T6c048ie+z9N/4KkpYv5Ev1oStVN2Y=
47+
github.com/pion/quic v0.1.3/go.mod h1:kJunziWkHVCYcxV4Ws6CpB62IWFsMB4ld3hsdsFRYV0=
4248
github.com/pion/randutil v0.0.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
4349
github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
4450
github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
@@ -54,9 +60,7 @@ github.com/pion/srtp v1.5.0 h1:sck6L9NExXDTc/6h9ak0ZxBvoQU5uuo04Z4po5de/zA=
5460
github.com/pion/srtp v1.5.0/go.mod h1:B+QgX5xPeQTNc1CJStJPHzOlHK66ViMDWTT0HZTCkcA=
5561
github.com/pion/stun v0.3.5 h1:uLUCBCkQby4S1cf6CGuR9QrVOKcvUwFeemaC865QHDg=
5662
github.com/pion/stun v0.3.5/go.mod h1:gDMim+47EeEtfWogA37n6qXZS88L5V6LqFcf+DZA2UA=
57-
github.com/pion/transport v0.6.0/go.mod h1:iWZ07doqOosSLMhZ+FXUTq+TamDoXSllxpbGcfkCmbE=
5863
github.com/pion/transport v0.8.10/go.mod h1:tBmha/UCjpum5hqTWhfAEs3CO4/tHSg0MYRhSzR+CZ8=
59-
github.com/pion/transport v0.10.0 h1:9M12BSneJm6ggGhJyWpDveFOstJsTiQjkLf4M44rm80=
6064
github.com/pion/transport v0.10.0/go.mod h1:BnHnUipd0rZQyTVB2SBGojFHT9CBt5C5TcsJSQGkvSE=
6165
github.com/pion/transport v0.10.1 h1:2W+yJT+0mOQ160ThZYUx5Zp2skzshiNgxrNE9GUfhJM=
6266
github.com/pion/transport v0.10.1/go.mod h1:PBis1stIILMiis0PewDw91WJeLJkyIMcEk+DwKOzf4A=
@@ -71,16 +75,16 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
7175
github.com/sclevine/agouti v3.0.0+incompatible h1:8IBJS6PWz3uTlMP3YBIR5f+KAldcGuOeFkFbUWfBgK4=
7276
github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw=
7377
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
74-
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
7578
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
7679
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
7780
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
7881
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
79-
golang.org/x/crypto v0.0.0-20190228161510-8dd112bcdc25/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
8082
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
83+
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
8184
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
8285
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
8386
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
87+
golang.org/x/net v0.0.0-20190228165749-92fc7df08ae7/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
8488
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
8589
golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
8690
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
@@ -90,14 +94,15 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6Zh
9094
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
9195
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
9296
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
93-
golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
9497
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
98+
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
9599
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
96100
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
97101
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
98102
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
99103
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
100104
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
105+
google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
101106
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
102107
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
103108
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

internal/mux/endpoint.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (e *Endpoint) LocalAddr() net.Addr {
5555

5656
// RemoteAddr is a stub
5757
func (e *Endpoint) RemoteAddr() net.Addr {
58-
return e.mux.nextConn.LocalAddr()
58+
return e.mux.nextConn.RemoteAddr()
5959
}
6060

6161
// SetDeadline is a stub

quictransport.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ type QUICTransport struct {
3131
certificates []Certificate
3232

3333
api *API
34-
log logging.LeveledLogger
34+
35+
loggingFactory logging.LoggerFactory
3536
}
3637

3738
// NewQUICTransport creates a new QUICTransport.
@@ -42,9 +43,9 @@ type QUICTransport struct {
4243
// any browsers yet.
4344
func (api *API) NewQUICTransport(transport *ICETransport, certificates []Certificate) (*QUICTransport, error) {
4445
t := &QUICTransport{
45-
iceTransport: transport,
46-
api: api,
47-
log: api.settingEngine.LoggerFactory.NewLogger("quic"),
46+
iceTransport: transport,
47+
api: api,
48+
loggingFactory: api.settingEngine.LoggerFactory,
4849
}
4950

5051
if len(certificates) > 0 {
@@ -110,11 +111,11 @@ func (t *QUICTransport) Start(remoteParameters QUICParameters) error {
110111
isClient = false
111112
}
112113
}
113-
114114
cfg := &quic.Config{
115-
Client: isClient,
116-
Certificate: cert.x509Cert,
117-
PrivateKey: cert.privateKey,
115+
Client: isClient,
116+
Certificate: cert.x509Cert,
117+
PrivateKey: cert.privateKey,
118+
LoggerFactory: t.loggingFactory,
118119
}
119120
endpoint := t.iceTransport.NewEndpoint(mux.MatchAll)
120121
err := t.TransportBase.StartBase(endpoint, cfg)
@@ -130,7 +131,8 @@ func (t *QUICTransport) Start(remoteParameters QUICParameters) error {
130131
return err
131132
}
132133
} else {
133-
t.log.Errorf("Warning: Certificate not checked")
134+
log := t.loggingFactory.NewLogger("quic-go")
135+
log.Errorf("Warning: Certificate not checked")
134136
}
135137

136138
return nil

quictransport_test.go

Lines changed: 71 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,36 @@
44
package webrtc
55

66
import (
7+
"bytes"
8+
"encoding/binary"
79
"testing"
810
"time"
911

1012
"github.com/pion/quic"
1113
"github.com/pion/transport/test"
1214
"github.com/pion/webrtc/v3/internal/util"
15+
"github.com/stretchr/testify/assert"
1316
)
1417

1518
func TestQUICTransport_E2E(t *testing.T) {
1619
// Limit runtime in case of deadlocks
1720
lim := test.TimeOut(time.Second * 20)
1821
defer lim.Stop()
1922

20-
// TODO: Check how we can make sure quic-go closes without leaking
21-
// report := test.CheckRoutines(t)
22-
// defer report()
23+
// Check how we can make sure quic-go closes without leaking
24+
report := test.CheckRoutines(t)
25+
defer report()
2326

2427
stackA, stackB, err := newQuicPair()
2528
if err != nil {
2629
t.Fatal(err)
2730
}
2831

2932
awaitSetup := make(chan struct{})
33+
dataAgot := make(chan []byte)
34+
dataBgot := make(chan []byte)
3035
stackB.quic.OnBidirectionalStream(func(stream *quic.BidirectionalStream) {
31-
go quicReadLoop(stream) // Read to pull incoming messages
36+
go quicReadLoop(stream, dataBgot) // Read to pull incoming messages
3237

3338
close(awaitSetup)
3439
})
@@ -43,18 +48,55 @@ func TestQUICTransport_E2E(t *testing.T) {
4348
t.Fatal(err)
4449
}
4550

46-
go quicReadLoop(stream) // Read to pull incoming messages
51+
go quicReadLoop(stream, dataAgot) // Read to pull incoming messages
4752

48-
// Write to open stream
49-
data := quic.StreamWriteParameters{
50-
Data: []byte("Hello"),
51-
}
52-
err = stream.Write(data)
53-
if err != nil {
54-
t.Fatal(err)
53+
go func() {
54+
for d := range dataAgot {
55+
t.Errorf("unexpected data: %q", d)
56+
}
57+
}()
58+
59+
testData := bytes.Repeat([]byte("Hello"), 128)
60+
count := 1024
61+
62+
var bufSent, bufGot bytes.Buffer
63+
64+
// read side
65+
done := make(chan struct{})
66+
go func() {
67+
<-awaitSetup
68+
t.Log("connection established")
69+
70+
for rx := range dataBgot {
71+
_, werr := bufGot.Write(rx)
72+
assert.NoError(t, werr)
73+
}
74+
close(done)
75+
}()
76+
77+
// sent side
78+
for i := 0; i < count; i++ {
79+
var buf [2]byte
80+
binary.BigEndian.PutUint16(buf[:], uint16(i))
81+
msg := append(buf[:], testData...)
82+
_, werr := bufSent.Write(msg)
83+
assert.NoError(t, werr)
84+
85+
data := quic.StreamWriteParameters{Data: msg}
86+
if i == count-1 {
87+
data.Finished = true
88+
}
89+
werr = stream.Write(data)
90+
if werr != nil {
91+
t.Fatal(werr)
92+
}
5593
}
5694

57-
<-awaitSetup
95+
<-done
96+
t.Log("read all data from stream")
97+
98+
assert.Equal(t, bufSent.Len(), count*(len(testData)+2))
99+
assert.Equal(t, bufSent.Len(), bufGot.Len())
58100

59101
err = stackA.close()
60102
if err != nil {
@@ -67,11 +109,15 @@ func TestQUICTransport_E2E(t *testing.T) {
67109
}
68110
}
69111

70-
func quicReadLoop(s *quic.BidirectionalStream) {
112+
func quicReadLoop(s *quic.BidirectionalStream, got chan<- []byte) {
113+
defer close(got)
71114
for {
72-
buffer := make([]byte, 15)
73-
_, err := s.ReadInto(buffer)
74-
if err != nil {
115+
buffer := make([]byte, 4098)
116+
res, err := s.ReadInto(buffer)
117+
if res.Amount > 0 {
118+
got <- buffer[:res.Amount]
119+
}
120+
if err != nil || res.Finished {
75121
return
76122
}
77123
}
@@ -112,11 +158,19 @@ func (s *testQuicStack) setSignal(sig *testQuicSignal, isOffer bool) error {
112158

113159
func (s *testQuicStack) getSignal() (*testQuicSignal, error) {
114160
// Gather candidates
161+
gatherFinished := make(chan struct{})
162+
s.gatherer.OnLocalCandidate(func(i *ICECandidate) {
163+
if i == nil {
164+
close(gatherFinished)
165+
return
166+
}
167+
})
115168
err := s.gatherer.Gather()
116169
if err != nil {
117170
return nil, err
118171
}
119172

173+
<-gatherFinished
120174
iceCandidates, err := s.gatherer.GetLocalCandidates()
121175
if err != nil {
122176
return nil, err

0 commit comments

Comments
 (0)