mirror of
https://github.com/yggdrasil-network/yggstack.git
synced 2025-04-27 13:45:07 +03:00
Implement error checking on listeners
Some checks failed
Trunk / release build / Build Windows/Linux-static/MacOS/*BSD-static/Android (push) Has been cancelled
Some checks failed
Trunk / release build / Build Windows/Linux-static/MacOS/*BSD-static/Android (push) Has been cancelled
Signed-off-by: Vasyl Gello <vasek.gello@gmail.com>
This commit is contained in:
parent
83bc9a2eec
commit
8ad1962f64
1 changed files with 26 additions and 7 deletions
|
@ -39,7 +39,8 @@ type node struct {
|
|||
core *core.Core
|
||||
multicast *multicast.Multicast
|
||||
admin *admin.AdminSocket
|
||||
socks5Listener net.Listener
|
||||
socks5Tcp net.Listener
|
||||
socks5Unix net.Listener
|
||||
}
|
||||
|
||||
type UDPSession struct {
|
||||
|
@ -306,10 +307,19 @@ func main() {
|
|||
server := socks5.NewServer(socksOptions...)
|
||||
if strings.Contains(*socks, ":") {
|
||||
logger.Infof("Starting SOCKS server on %s", *socks)
|
||||
go server.ListenAndServe("tcp", *socks) // nolint:errcheck
|
||||
n.socks5Tcp, err = net.Listen("tcp", *socks)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
go func() {
|
||||
err := server.Serve(n.socks5Tcp)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
} else {
|
||||
logger.Infof("Starting SOCKS server with socket file %s", *socks)
|
||||
n.socks5Listener, err = net.Listen("unix", *socks)
|
||||
n.socks5Unix, err = net.Listen("unix", *socks)
|
||||
if err != nil {
|
||||
// If address in use, try connecting to
|
||||
// the socket to see if other yggstack
|
||||
|
@ -330,7 +340,12 @@ func main() {
|
|||
panic(err)
|
||||
}
|
||||
}
|
||||
go server.Serve(n.socks5Listener) // nolint:errcheck
|
||||
go func() {
|
||||
err := server.Serve(n.socks5Unix)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -519,10 +534,14 @@ func main() {
|
|||
// Shut down the node.
|
||||
_ = n.admin.Stop()
|
||||
_ = n.multicast.Stop()
|
||||
if n.socks5Listener != nil {
|
||||
_ = n.socks5Listener.Close()
|
||||
if n.socks5Unix != nil {
|
||||
_ = n.socks5Unix.Close()
|
||||
_ = os.RemoveAll(*socks)
|
||||
logger.Infof("Stopped UNIX socket listener")
|
||||
logger.Infof("Stopped SOCKS5 UNIX socket listener")
|
||||
}
|
||||
if n.socks5Tcp != nil {
|
||||
_ = n.socks5Tcp.Close()
|
||||
logger.Infof("Stopped SOCKS5 TCP listener")
|
||||
}
|
||||
n.core.Stop()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue