summaryrefslogtreecommitdiffhomepage
path: root/src/config.go
diff options
context:
space:
mode:
authorMathias Hall-Andersen <mathias@hall-andersen.dk>2017-08-11 16:18:20 +0200
committerMathias Hall-Andersen <mathias@hall-andersen.dk>2017-08-11 16:18:20 +0200
commita4eff12d7f749c992247579161c4ce9e60e2df47 (patch)
tree6032dd0a96ced8313d7199e569ab657f3ba91ca7 /src/config.go
parentcba1d6585ab9b12ae3e0897db85675ba452c3f09 (diff)
Improved receive.go
- Fixed configuration listen-port semantics - Improved receive.go code for updating listen port - Updated under load detection, how follows the kernel space implementation - Fixed trie bug accidentally introduced in last commit - Added interface name to log (format still subject to change) - Can now configure the logging level using the LOG_LEVEL variable - Begin porting netsh.sh tests - A number of smaller changes
Diffstat (limited to 'src/config.go')
-rw-r--r--src/config.go57
1 files changed, 19 insertions, 38 deletions
diff --git a/src/config.go b/src/config.go
index d952a3a..474134b 100644
--- a/src/config.go
+++ b/src/config.go
@@ -28,6 +28,7 @@ func ipcGetOperation(device *Device, socket *bufio.ReadWriter) *IPCError {
// create lines
device.mutex.RLock()
+ device.net.mutex.RLock()
lines := make([]string, 0, 100)
send := func(line string) {
@@ -38,7 +39,9 @@ func ipcGetOperation(device *Device, socket *bufio.ReadWriter) *IPCError {
send("private_key=" + device.privateKey.ToHex())
}
- send(fmt.Sprintf("listen_port=%d", device.net.addr.Port))
+ if device.net.addr != nil {
+ send(fmt.Sprintf("listen_port=%d", device.net.addr.Port))
+ }
for _, peer := range device.peers {
func() {
@@ -68,6 +71,7 @@ func ipcGetOperation(device *Device, socket *bufio.ReadWriter) *IPCError {
}()
}
+ device.net.mutex.RUnlock()
device.mutex.RUnlock()
// send lines
@@ -84,38 +88,6 @@ func ipcGetOperation(device *Device, socket *bufio.ReadWriter) *IPCError {
return nil
}
-func updateUDPConn(device *Device) error {
- var err error
- netc := &device.net
- netc.mutex.Lock()
-
- // close existing connection
-
- if netc.conn != nil {
- netc.conn.Close()
- netc.conn = nil
- }
-
- // open new existing connection
-
- conn, err := net.ListenUDP("udp", netc.addr)
- if err == nil {
- netc.conn = conn
- signalSend(device.signal.newUDPConn)
- }
-
- netc.mutex.Unlock()
- return err
-}
-
-func closeUDPConn(device *Device) {
- device.net.mutex.Lock()
- device.net.conn = nil
- device.net.mutex.Unlock()
- println("send signal")
- signalSend(device.signal.newUDPConn)
-}
-
func ipcSetOperation(device *Device, socket *bufio.ReadWriter) *IPCError {
scanner := bufio.NewScanner(socket)
logInfo := device.log.Info
@@ -166,13 +138,22 @@ func ipcSetOperation(device *Device, socket *bufio.ReadWriter) *IPCError {
logError.Println("Failed to set listen_port:", err)
return &IPCError{Code: ipcErrorInvalid}
}
+
+ addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf(":%d", port))
+ if err != nil {
+ logError.Println("Failed to set listen_port:", err)
+ return &IPCError{Code: ipcErrorInvalid}
+ }
+
netc := &device.net
netc.mutex.Lock()
- if netc.addr.Port != int(port) {
- netc.addr.Port = int(port)
- }
+ netc.addr = addr
netc.mutex.Unlock()
- updateUDPConn(device)
+ err = updateUDPConn(device)
+ if err != nil {
+ logError.Println("Failed to set listen_port:", err)
+ return &IPCError{Code: ipcErrorIO}
+ }
// TODO: Clear source address of all peers
@@ -298,7 +279,7 @@ func ipcSetOperation(device *Device, socket *bufio.ReadWriter) *IPCError {
logError.Println("Failed to get tun device status:", err)
return &IPCError{Code: ipcErrorIO}
}
- if atomic.LoadInt32(&device.isUp) == AtomicTrue && !dummy {
+ if device.tun.isUp.Get() && !dummy {
peer.SendKeepAlive()
}
}