mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2024-12-22 16:07:31 +00:00
parent
5e5de3a343
commit
63cd757525
@ -11,7 +11,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/Arceliar/phony"
|
"github.com/Arceliar/phony"
|
||||||
wgtun "golang.zx2c4.com/wireguard/tun"
|
wgtun "golang.zx2c4.com/wireguard/tun"
|
||||||
@ -65,20 +64,6 @@ func getSupportedMTU(mtu uint64) uint64 {
|
|||||||
return mtu
|
return mtu
|
||||||
}
|
}
|
||||||
|
|
||||||
func waitForTUNUp(ch <-chan wgtun.Event) bool {
|
|
||||||
t := time.After(time.Second * 5)
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case ev := <-ch:
|
|
||||||
if ev == wgtun.EventUp {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
case <-t:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Name returns the name of the adapter, e.g. "tun0". On Windows, this may
|
// Name returns the name of the adapter, e.g. "tun0". On Windows, this may
|
||||||
// return a canonical adapter name instead.
|
// return a canonical adapter name instead.
|
||||||
func (tun *TunAdapter) Name() string {
|
func (tun *TunAdapter) Name() string {
|
||||||
|
@ -80,9 +80,6 @@ func (tun *TunAdapter) setup(ifname string, addr string, mtu uint64) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create TUN: %w", err)
|
return fmt.Errorf("failed to create TUN: %w", err)
|
||||||
}
|
}
|
||||||
if !waitForTUNUp(iface.Events()) {
|
|
||||||
return fmt.Errorf("TUN did not come up in time")
|
|
||||||
}
|
|
||||||
tun.iface = iface
|
tun.iface = iface
|
||||||
if mtu, err := iface.MTU(); err == nil {
|
if mtu, err := iface.MTU(); err == nil {
|
||||||
tun.mtu = getSupportedMTU(uint64(mtu))
|
tun.mtu = getSupportedMTU(uint64(mtu))
|
||||||
|
@ -27,9 +27,6 @@ func (tun *TunAdapter) setup(ifname string, addr string, mtu uint64) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create TUN: %w", err)
|
return fmt.Errorf("failed to create TUN: %w", err)
|
||||||
}
|
}
|
||||||
if !waitForTUNUp(iface.Events()) {
|
|
||||||
return fmt.Errorf("TUN did not come up in time")
|
|
||||||
}
|
|
||||||
tun.iface = iface
|
tun.iface = iface
|
||||||
if m, err := iface.MTU(); err == nil {
|
if m, err := iface.MTU(); err == nil {
|
||||||
tun.mtu = getSupportedMTU(uint64(m))
|
tun.mtu = getSupportedMTU(uint64(m))
|
||||||
|
@ -21,9 +21,6 @@ func (tun *TunAdapter) setup(ifname string, addr string, mtu uint64) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create TUN: %w", err)
|
return fmt.Errorf("failed to create TUN: %w", err)
|
||||||
}
|
}
|
||||||
if !waitForTUNUp(iface.Events()) {
|
|
||||||
return fmt.Errorf("TUN did not come up in time")
|
|
||||||
}
|
|
||||||
tun.iface = iface
|
tun.iface = iface
|
||||||
if mtu, err := iface.MTU(); err == nil {
|
if mtu, err := iface.MTU(); err == nil {
|
||||||
tun.mtu = getSupportedMTU(uint64(mtu))
|
tun.mtu = getSupportedMTU(uint64(mtu))
|
||||||
|
@ -18,9 +18,6 @@ func (tun *TunAdapter) setup(ifname string, addr string, mtu uint64) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create TUN: %w", err)
|
return fmt.Errorf("failed to create TUN: %w", err)
|
||||||
}
|
}
|
||||||
if !waitForTUNUp(iface.Events()) {
|
|
||||||
return fmt.Errorf("TUN did not come up in time")
|
|
||||||
}
|
|
||||||
tun.iface = iface
|
tun.iface = iface
|
||||||
if mtu, err := iface.MTU(); err == nil {
|
if mtu, err := iface.MTU(); err == nil {
|
||||||
tun.mtu = getSupportedMTU(uint64(mtu))
|
tun.mtu = getSupportedMTU(uint64(mtu))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user