mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2024-12-29 08:58:49 +01:00
Better naming of bind helpers
This commit is contained in:
parent
b5ae42349c
commit
af464cff00
11
src/conn.go
11
src/conn.go
@ -54,7 +54,7 @@ func parseEndpoint(s string) (*net.UDPAddr, error) {
|
|||||||
|
|
||||||
/* Must hold device and net lock
|
/* Must hold device and net lock
|
||||||
*/
|
*/
|
||||||
func unsafeCloseUDPListener(device *Device) error {
|
func unsafeCloseBind(device *Device) error {
|
||||||
var err error
|
var err error
|
||||||
netc := &device.net
|
netc := &device.net
|
||||||
if netc.bind != nil {
|
if netc.bind != nil {
|
||||||
@ -64,8 +64,7 @@ func unsafeCloseUDPListener(device *Device) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// must inform all listeners
|
func updateBind(device *Device) error {
|
||||||
func UpdateUDPListener(device *Device) error {
|
|
||||||
device.mutex.Lock()
|
device.mutex.Lock()
|
||||||
defer device.mutex.Unlock()
|
defer device.mutex.Unlock()
|
||||||
|
|
||||||
@ -75,7 +74,7 @@ func UpdateUDPListener(device *Device) error {
|
|||||||
|
|
||||||
// close existing sockets
|
// close existing sockets
|
||||||
|
|
||||||
if err := unsafeCloseUDPListener(device); err != nil {
|
if err := unsafeCloseBind(device); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,10 +123,10 @@ func UpdateUDPListener(device *Device) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CloseUDPListener(device *Device) error {
|
func closeBind(device *Device) error {
|
||||||
device.mutex.Lock()
|
device.mutex.Lock()
|
||||||
device.net.mutex.Lock()
|
device.net.mutex.Lock()
|
||||||
err := unsafeCloseUDPListener(device)
|
err := unsafeCloseBind(device)
|
||||||
device.net.mutex.Unlock()
|
device.net.mutex.Unlock()
|
||||||
device.mutex.Unlock()
|
device.mutex.Unlock()
|
||||||
return err
|
return err
|
||||||
|
@ -210,7 +210,7 @@ func (device *Device) Close() {
|
|||||||
device.log.Info.Println("Closing device")
|
device.log.Info.Println("Closing device")
|
||||||
device.RemoveAllPeers()
|
device.RemoveAllPeers()
|
||||||
close(device.signal.stop)
|
close(device.signal.stop)
|
||||||
CloseUDPListener(device)
|
closeBind(device)
|
||||||
device.tun.device.Close()
|
device.tun.device.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,17 +47,19 @@ func (device *Device) RoutineTUNEventReader() {
|
|||||||
|
|
||||||
if event&TUNEventUp != 0 {
|
if event&TUNEventUp != 0 {
|
||||||
if !device.tun.isUp.Get() {
|
if !device.tun.isUp.Get() {
|
||||||
|
// begin listening for incomming datagrams
|
||||||
logInfo.Println("Interface set up")
|
logInfo.Println("Interface set up")
|
||||||
device.tun.isUp.Set(true)
|
device.tun.isUp.Set(true)
|
||||||
UpdateUDPListener(device)
|
updateBind(device)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if event&TUNEventDown != 0 {
|
if event&TUNEventDown != 0 {
|
||||||
if device.tun.isUp.Get() {
|
if device.tun.isUp.Get() {
|
||||||
|
// stop listening for incomming datagrams
|
||||||
logInfo.Println("Interface set down")
|
logInfo.Println("Interface set down")
|
||||||
device.tun.isUp.Set(false)
|
device.tun.isUp.Set(false)
|
||||||
CloseUDPListener(device)
|
closeBind(device)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -139,7 +139,7 @@ func ipcSetOperation(device *Device, socket *bufio.ReadWriter) *IPCError {
|
|||||||
return &IPCError{Code: ipcErrorInvalid}
|
return &IPCError{Code: ipcErrorInvalid}
|
||||||
}
|
}
|
||||||
device.net.port = uint16(port)
|
device.net.port = uint16(port)
|
||||||
if err := UpdateUDPListener(device); err != nil {
|
if err := updateBind(device); err != nil {
|
||||||
logError.Println("Failed to set listen_port:", err)
|
logError.Println("Failed to set listen_port:", err)
|
||||||
return &IPCError{Code: ipcErrorPortInUse}
|
return &IPCError{Code: ipcErrorPortInUse}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user