Added new UDPBind interface

This commit is contained in:
Mathias Hall-Andersen
2017-10-08 22:03:32 +02:00
parent 2d856045a0
commit a72b0f7ae5
6 changed files with 236 additions and 214 deletions

View File

@@ -1,18 +1,14 @@
package main
import (
"golang.org/x/net/ipv4"
"golang.org/x/net/ipv6"
"runtime"
"sync"
"sync/atomic"
"time"
)
type Listener struct {
sock Socket
active bool
update chan struct{}
}
type Device struct {
log *Logger // collection of loggers for levels
idCounter uint // for assigning debug ids to peers
@@ -27,8 +23,7 @@ type Device struct {
}
net struct {
mutex sync.RWMutex
ipv4 Listener
ipv6 Listener
bind UDPBind
port uint16
fwmark uint32
}
@@ -43,9 +38,8 @@ type Device struct {
handshake chan QueueHandshakeElement
}
signal struct {
stop chan struct{} // halts all go routines
updateIPv4Socket chan struct{} // a net.conn was set (consumed by the receiver routine)
updateIPv6Socket chan struct{} // a net.conn was set (consumed by the receiver routine)
stop chan struct{}
updateBind chan struct{}
}
underLoadUntil atomic.Value
ratelimiter Ratelimiter
@@ -146,8 +140,6 @@ func NewDevice(tun TUNDevice, logLevel int) *Device {
device.tun.device = tun
device.indices.Init()
device.net.ipv4.Init()
device.net.ipv6.Init()
device.ratelimiter.Init()
device.routingTable.Reset()
@@ -181,8 +173,8 @@ func NewDevice(tun TUNDevice, logLevel int) *Device {
go device.RoutineReadFromTUN()
go device.RoutineTUNEventReader()
go device.ratelimiter.RoutineGarbageCollector(device.signal.stop)
go device.RoutineReceiveIncomming(&device.net.ipv4)
go device.RoutineReceiveIncomming(&device.net.ipv6)
go device.RoutineReceiveIncomming(ipv4.Version)
go device.RoutineReceiveIncomming(ipv6.Version)
return device
}