github.com/bepass-org/wireguard-go@v1.0.4-rc2.0.20240304192354-ebce6572bc24/device/endpoint_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  	"math/rand"
    10  	"net/netip"
    11  )
    12  
    13  type DummyEndpoint struct {
    14  	src, dst netip.Addr
    15  }
    16  
    17  func CreateDummyEndpoint() (*DummyEndpoint, error) {
    18  	var src, dst [16]byte
    19  	if _, err := rand.Read(src[:]); err != nil {
    20  		return nil, err
    21  	}
    22  	_, err := rand.Read(dst[:])
    23  	return &DummyEndpoint{netip.AddrFrom16(src), netip.AddrFrom16(dst)}, err
    24  }
    25  
    26  func (e *DummyEndpoint) ClearSrc() {}
    27  
    28  func (e *DummyEndpoint) SrcToString() string {
    29  	return netip.AddrPortFrom(e.SrcIP(), 1000).String()
    30  }
    31  
    32  func (e *DummyEndpoint) DstToString() string {
    33  	return netip.AddrPortFrom(e.DstIP(), 1000).String()
    34  }
    35  
    36  func (e *DummyEndpoint) DstToBytes() []byte {
    37  	out := e.DstIP().AsSlice()
    38  	out = append(out, byte(1000&0xff))
    39  	out = append(out, byte((1000>>8)&0xff))
    40  	return out
    41  }
    42  
    43  func (e *DummyEndpoint) DstIP() netip.Addr {
    44  	return e.dst
    45  }
    46  
    47  func (e *DummyEndpoint) SrcIP() netip.Addr {
    48  	return e.src
    49  }