Reverted event changes

This feature was not needed for Android, upon further inspection.
This commit is contained in:
Mathias Hall-Andersen
2018-02-11 18:55:30 +01:00
parent b461343171
commit 73cb1a1155
3 changed files with 18 additions and 57 deletions

14
tun.go
View File

@@ -1,13 +1,14 @@
package main
import (
"git.zx2c4.com/wireguard-go/internal/events"
"os"
"sync/atomic"
)
const DefaultMTU = 1420
type TUNEvent int
const (
TUNEventUp = 1 << iota
TUNEventDown
@@ -20,7 +21,7 @@ type TUNDevice interface {
Write([]byte, int) (int, error) // writes a packet to the device (without any additional headers)
MTU() (int, error) // returns the MTU of the device
Name() string // returns the current name
Events() chan events.Event // returns a constant channel of events related to the device
Events() chan TUNEvent // returns a constant channel of events related to the device
Close() error // stops the device and closes the event channel
}
@@ -29,8 +30,7 @@ func (device *Device) RoutineTUNEventReader() {
logError := device.log.Error
for event := range device.tun.device.Events() {
if event.Contains(TUNEventMTUUpdate) {
if event&TUNEventMTUUpdate != 0 {
mtu, err := device.tun.device.MTU()
old := atomic.LoadInt32(&device.tun.mtu)
if err != nil {
@@ -45,16 +45,14 @@ func (device *Device) RoutineTUNEventReader() {
}
}
if event.Contains(TUNEventUp) && !device.isUp.Get() {
if event&TUNEventUp != 0 && !device.isUp.Get() {
logInfo.Println("Interface set up")
device.Up()
}
if event.Contains(TUNEventDown) && device.isUp.Get() {
if event&TUNEventDown != 0 && device.isUp.Get() {
logInfo.Println("Interface set down")
device.Down()
}
event.Processed()
}
}