github.com/tailscale/wireguard-go@v0.0.20201119-0.20210522003738-46b531feb08a/device/endpoint_test.go (about) 1 /* SPDX-License-Identifier: MIT 2 * 3 * Copyright (C) 2017-2021 WireGuard LLC. All Rights Reserved. 4 */ 5 6 package device 7 8 import ( 9 "math/rand" 10 "net" 11 ) 12 13 type DummyEndpoint struct { 14 src [16]byte 15 dst [16]byte 16 } 17 18 func CreateDummyEndpoint() (*DummyEndpoint, error) { 19 var end DummyEndpoint 20 if _, err := rand.Read(end.src[:]); err != nil { 21 return nil, err 22 } 23 _, err := rand.Read(end.dst[:]) 24 return &end, err 25 } 26 27 func (e *DummyEndpoint) ClearSrc() {} 28 29 func (e *DummyEndpoint) SrcToString() string { 30 var addr net.UDPAddr 31 addr.IP = e.SrcIP() 32 addr.Port = 1000 33 return addr.String() 34 } 35 36 func (e *DummyEndpoint) DstToString() string { 37 var addr net.UDPAddr 38 addr.IP = e.DstIP() 39 addr.Port = 1000 40 return addr.String() 41 } 42 43 func (e *DummyEndpoint) SrcToBytes() []byte { 44 return e.src[:] 45 } 46 47 func (e *DummyEndpoint) DstIP() net.IP { 48 return e.dst[:] 49 } 50 51 func (e *DummyEndpoint) SrcIP() net.IP { 52 return e.src[:] 53 }