cloudflare/cloudflared

Public

mirrored from https://github.com/cloudflare/cloudflaredAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
2021.12.3

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

datagramsession/transport_test.go

36lines · modecode

1package datagramsession
2
3import (
4 "context"
5
6 "github.com/google/uuid"
7)
8
9type mockQUICTransport struct {
10 reqChan *datagramChannel
11 respChan *datagramChannel
12}
13
14func (mt *mockQUICTransport) SendTo(sessionID uuid.UUID, payload []byte) error {
15 buf := make([]byte, len(payload))
16 // The QUIC implementation copies data to another buffer before returning https://github.com/lucas-clemente/quic-go/blob/v0.24.0/session.go#L1967-L1975
17 copy(buf, payload)
18 return mt.respChan.Send(context.Background(), sessionID, buf)
19}
20
21func (mt *mockQUICTransport) ReceiveFrom() (uuid.UUID, []byte, error) {
22 return mt.reqChan.Receive(context.Background())
23}
24
25func (mt *mockQUICTransport) MTU() uint {
26 return 1217
27}
28
29func (mt *mockQUICTransport) newRequest(ctx context.Context, sessionID uuid.UUID, payload []byte) error {
30 return mt.reqChan.Send(ctx, sessionID, payload)
31}
32
33func (mt *mockQUICTransport) close() {
34 mt.reqChan.Close()
35 mt.respChan.Close()
36}
37