mirror of
https://github.com/netbirdio/netbird.git
synced 2024-12-13 18:31:18 +01:00
7ebe58f20a
* Add DNS list argument for mobile client * Write testable code Many places are checked the wgInterface != nil condition. It is doing it just because to avoid the real wgInterface creation for tests. Instead of this involve a wgInterface interface what is moc-able. * Refactor the DNS server internal code structure With the fake resolver has been involved several if-else statement and generated some unused variables to distinguish the listener and fake resolver solutions at running time. With this commit the fake resolver and listener based solution has been moved into two separated structure. Name of this layer is the 'service'. With this modification the unit test looks simpler and open the option to add new logic for the permanent DNS service usage for mobile systems. * Remove is running check in test We can not ensure the state well so remove this check. The test will fail if the server is not running well.
42 lines
1019 B
Go
42 lines
1019 B
Go
//go:build !android
|
|
|
|
package iface
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
|
|
"github.com/pion/transport/v2"
|
|
)
|
|
|
|
// NewWGIFace Creates a new WireGuard interface instance
|
|
func NewWGIFace(iFaceName string, address string, mtu int, tunAdapter TunAdapter, transportNet transport.Net) (*WGIface, error) {
|
|
wgIFace := &WGIface{
|
|
mu: sync.Mutex{},
|
|
}
|
|
|
|
wgAddress, err := parseWGAddress(address)
|
|
if err != nil {
|
|
return wgIFace, err
|
|
}
|
|
|
|
wgIFace.tun = newTunDevice(iFaceName, wgAddress, mtu, transportNet)
|
|
|
|
wgIFace.configurer = newWGConfigurer(iFaceName)
|
|
wgIFace.userspaceBind = !WireGuardModuleIsLoaded()
|
|
return wgIFace, nil
|
|
}
|
|
|
|
// CreateOnMobile this function make sense on mobile only
|
|
func (w *WGIface) CreateOnMobile(mIFaceArgs MobileIFaceArguments) error {
|
|
return fmt.Errorf("this function has not implemented on non mobile")
|
|
}
|
|
|
|
// Create creates a new Wireguard interface, sets a given IP and brings it up.
|
|
// Will reuse an existing one.
|
|
func (w *WGIface) Create() error {
|
|
w.mu.Lock()
|
|
defer w.mu.Unlock()
|
|
return w.tun.Create()
|
|
}
|