mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
TUN vectorised reads/writes
This commit is contained in:
parent
04c0acf71b
commit
0fb5d76e30
9 changed files with 75 additions and 23 deletions
|
@ -10,9 +10,10 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/Arceliar/phony"
|
||||
"golang.zx2c4.com/wireguard/tun"
|
||||
wgtun "golang.zx2c4.com/wireguard/tun"
|
||||
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/address"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/config"
|
||||
|
@ -39,7 +40,7 @@ type TunAdapter struct {
|
|||
addr address.Address
|
||||
subnet address.Subnet
|
||||
mtu uint64
|
||||
iface tun.Device
|
||||
iface wgtun.Device
|
||||
phony.Inbox // Currently only used for _handlePacket from the reader, TODO: all the stuff that currently needs a mutex below
|
||||
isOpen bool
|
||||
isEnabled bool // Used by the writer to drop sessionTraffic if not enabled
|
||||
|
@ -62,6 +63,20 @@ func getSupportedMTU(mtu uint64) uint64 {
|
|||
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
|
||||
// return a canonical adapter name instead.
|
||||
func (tun *TunAdapter) Name() string {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue