github.com/bepass-org/wireguard-go@v1.0.4-rc2.0.20240304192354-ebce6572bc24/device/bind_test.go (about) 1 /* SPDX-License-Identifier: MIT 2 * 3 * Copyright (C) 2017-2023 WireGuard LLC. All Rights Reserved. 4 */ 5 6 package device 7 8 import ( 9 "errors" 10 11 "github.com/bepass-org/wireguard-go/conn" 12 ) 13 14 type DummyDatagram struct { 15 msg []byte 16 endpoint conn.Endpoint 17 } 18 19 type DummyBind struct { 20 in6 chan DummyDatagram 21 in4 chan DummyDatagram 22 closed bool 23 } 24 25 func (b *DummyBind) SetMark(v uint32) error { 26 return nil 27 } 28 29 func (b *DummyBind) ReceiveIPv6(buf []byte) (int, conn.Endpoint, error) { 30 datagram, ok := <-b.in6 31 if !ok { 32 return 0, nil, errors.New("closed") 33 } 34 copy(buf, datagram.msg) 35 return len(datagram.msg), datagram.endpoint, nil 36 } 37 38 func (b *DummyBind) ReceiveIPv4(buf []byte) (int, conn.Endpoint, error) { 39 datagram, ok := <-b.in4 40 if !ok { 41 return 0, nil, errors.New("closed") 42 } 43 copy(buf, datagram.msg) 44 return len(datagram.msg), datagram.endpoint, nil 45 } 46 47 func (b *DummyBind) Close() error { 48 close(b.in6) 49 close(b.in4) 50 b.closed = true 51 return nil 52 } 53 54 func (b *DummyBind) Send(buf []byte, end conn.Endpoint) error { 55 return nil 56 }