github.com/noisysockets/noisysockets@v0.21.2-0.20240515114641-7f467e651c90/network/host.go (about) 1 // SPDX-License-Identifier: MPL-2.0 2 /* 3 * Copyright (C) 2024 The Noisy Sockets Authors. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 */ 9 10 package network 11 12 import ( 13 "context" 14 stdnet "net" 15 "os" 16 ) 17 18 // Host returns a Network implementation that uses the standard library's network operations. 19 // This is used in integration testing to avoid needing to mock out WireGuard. 20 func Host() Network { 21 return &hostNetwork{} 22 } 23 24 type hostNetwork struct{} 25 26 func (net *hostNetwork) Close() error { 27 return nil 28 } 29 30 func (net *hostNetwork) InterfaceAddrs() ([]stdnet.Addr, error) { 31 return stdnet.InterfaceAddrs() 32 } 33 34 func (net *hostNetwork) Hostname() (string, error) { 35 return os.Hostname() 36 } 37 38 func (net *hostNetwork) LookupHost(host string) ([]string, error) { 39 return stdnet.LookupHost(host) 40 } 41 42 func (net *hostNetwork) Dial(network, address string) (stdnet.Conn, error) { 43 return stdnet.Dial(network, address) 44 } 45 46 func (net *hostNetwork) DialContext(ctx context.Context, network, address string) (stdnet.Conn, error) { 47 var d stdnet.Dialer 48 return d.DialContext(ctx, network, address) 49 } 50 51 func (net *hostNetwork) Listen(network, address string) (stdnet.Listener, error) { 52 return stdnet.Listen(network, address) 53 } 54 55 func (net *hostNetwork) ListenPacket(network, address string) (stdnet.PacketConn, error) { 56 return stdnet.ListenPacket(network, address) 57 }