]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
Reverted event changes
authorMathias Hall-Andersen <mathias@hall-andersen.dk>
Sun, 11 Feb 2018 17:55:30 +0000 (18:55 +0100)
committerMathias Hall-Andersen <mathias@hall-andersen.dk>
Sun, 11 Feb 2018 17:55:30 +0000 (18:55 +0100)
This feature was not needed for Android, upon further inspection.

internal/events/event.go [deleted file]
tun.go
tun_linux.go

diff --git a/internal/events/event.go b/internal/events/event.go
deleted file mode 100644 (file)
index 4412bbb..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-package events
-
-import (
-       "sync"
-)
-
-type Event interface {
-       Contains(int) bool
-       Processed()
-       WaitForProcessed()
-}
-
-type EventStruct struct {
-       code int
-       lock sync.Mutex
-}
-
-func (event EventStruct) Contains(code int) bool {
-       return event.code&code != 0
-}
-
-func (event *EventStruct) WaitForProcessed() {
-       event.lock.Lock()
-}
-
-func (event *EventStruct) Processed() {
-       event.lock.Unlock()
-}
-
-func NewEvent(code int) Event {
-       event := &EventStruct{
-               code: code,
-       }
-       event.lock.Lock()
-       return event
-}
diff --git a/tun.go b/tun.go
index 3365845ee9dbe8fd67730c98ce08f744e309808e..6259f33a49c97f58798b5dda1b312238c708e317 100644 (file)
--- a/tun.go
+++ b/tun.go
@@ -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()
        }
 }
index 4585b13fff72e7620fd6da544088ba13d77ea53a..daa2462ad7650c27825cf4eec3074d0f57597f25 100644 (file)
@@ -7,7 +7,6 @@ import (
        "encoding/binary"
        "errors"
        "fmt"
-       "git.zx2c4.com/wireguard-go/internal/events"
        "golang.org/x/net/ipv6"
        "golang.org/x/sys/unix"
        "net"
@@ -53,10 +52,10 @@ const (
 
 type NativeTun struct {
        fd     *os.File
-       index  int32             // if index
-       name   string            // name of interface
-       errors chan error        // async error handling
-       events chan events.Event // device related events
+       index  int32         // if index
+       name   string        // name of interface
+       errors chan error    // async error handling
+       events chan TUNEvent // device related events
 }
 
 func (tun *NativeTun) File() *os.File {
@@ -72,9 +71,9 @@ func (tun *NativeTun) RoutineHackListener() {
                _, err := unix.Write(fd, nil)
                switch err {
                case unix.EINVAL:
-                       tun.events <- events.NewEvent(TUNEventUp)
+                       tun.events <- TUNEventUp
                case unix.EIO:
-                       tun.events <- events.NewEvent(TUNEventDown)
+                       tun.events <- TUNEventDown
                default:
                }
                time.Sleep(time.Second / 10)
@@ -119,14 +118,14 @@ func (tun *NativeTun) RoutineNetlinkListener() {
                                }
 
                                if info.Flags&unix.IFF_RUNNING != 0 {
-                                       tun.events <- events.NewEvent(TUNEventUp)
+                                       tun.events <- TUNEventUp
                                }
 
                                if info.Flags&unix.IFF_RUNNING == 0 {
-                                       tun.events <- events.NewEvent(TUNEventDown)
+                                       tun.events <- TUNEventDown
                                }
 
-                               tun.events <- events.NewEvent(TUNEventMTUUpdate)
+                               tun.events <- TUNEventMTUUpdate
 
                        default:
                                remain = remain[hdr.Len:]
@@ -289,7 +288,7 @@ func (tun *NativeTun) Read(buff []byte, offset int) (int, error) {
        }
 }
 
-func (tun *NativeTun) Events() chan events.Event {
+func (tun *NativeTun) Events() chan TUNEvent {
        return tun.events
 }
 
@@ -301,7 +300,7 @@ func CreateTUNFromFile(name string, fd *os.File) (TUNDevice, error) {
        device := &NativeTun{
                fd:     fd,
                name:   name,
-               events: make(chan events.Event, 5),
+               events: make(chan TUNEvent, 5),
                errors: make(chan error, 5),
        }
 
@@ -358,7 +357,7 @@ func CreateTUN(name string) (TUNDevice, error) {
        device := &NativeTun{
                fd:     fd,
                name:   newName,
-               events: make(chan events.Event, 5),
+               events: make(chan TUNEvent, 5),
                errors: make(chan error, 5),
        }