cloudflare/cloudflared
Publicmirrored from https://github.com/cloudflare/cloudflaredAvailable
datagramsession/transport_test.go
36lines · modecode
| 1 | package datagramsession |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | |
| 6 | "github.com/google/uuid" |
| 7 | ) |
| 8 | |
| 9 | type mockQUICTransport struct { |
| 10 | reqChan *datagramChannel |
| 11 | respChan *datagramChannel |
| 12 | } |
| 13 | |
| 14 | func (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 | |
| 21 | func (mt *mockQUICTransport) ReceiveFrom() (uuid.UUID, []byte, error) { |
| 22 | return mt.reqChan.Receive(context.Background()) |
| 23 | } |
| 24 | |
| 25 | func (mt *mockQUICTransport) MTU() uint { |
| 26 | return 1217 |
| 27 | } |
| 28 | |
| 29 | func (mt *mockQUICTransport) newRequest(ctx context.Context, sessionID uuid.UUID, payload []byte) error { |
| 30 | return mt.reqChan.Send(ctx, sessionID, payload) |
| 31 | } |
| 32 | |
| 33 | func (mt *mockQUICTransport) close() { |
| 34 | mt.reqChan.Close() |
| 35 | mt.respChan.Close() |
| 36 | } |
| 37 | |