fix_: prevent multiple http or websocket lauches
fixes [5436](https://github.com/status-im/status-go/issues/5436)
This commit is contained in:
parent
cef6db81d6
commit
2fd74bf7f1
|
@ -0,0 +1,13 @@
|
|||
import net
|
||||
|
||||
# Util function to test if a port is busy
|
||||
proc isPortBusy*(port: Port): bool =
|
||||
var sock: Socket
|
||||
try:
|
||||
sock = newSocket()
|
||||
sock.setSockOpt(OptReuseAddr, true)
|
||||
sock.bindAddr(port)
|
||||
sock.close()
|
||||
return false
|
||||
except OSError:
|
||||
return true
|
|
@ -1,5 +1,7 @@
|
|||
import json
|
||||
|
||||
include ../../../common/net_utils
|
||||
|
||||
type APIConfig* = object
|
||||
apiModules*: string
|
||||
connectorEnabled*: bool
|
||||
|
@ -10,13 +12,21 @@ type APIConfig* = object
|
|||
wsHost*: string
|
||||
wsPort*: int
|
||||
|
||||
proc checkAndSetPort(port: Port, isEnabled: var bool) =
|
||||
if isPortBusy(port):
|
||||
isEnabled = false
|
||||
|
||||
proc defaultAPIConfig*(): APIConfig =
|
||||
result.apiModules = "connector"
|
||||
result.connectorEnabled = true
|
||||
|
||||
result.httpEnabled = true
|
||||
checkAndSetPort(Port(8545), result.httpEnabled)
|
||||
result.httpHost = "0.0.0.0"
|
||||
result.httpPort = 8545
|
||||
|
||||
result.wsEnabled = true
|
||||
checkAndSetPort(Port(8586), result.wsEnabled)
|
||||
result.wsHost = "0.0.0.0"
|
||||
result.wsPort = 8586
|
||||
|
||||
|
|
Loading…
Reference in New Issue