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
|
import json
|
||||||
|
|
||||||
|
include ../../../common/net_utils
|
||||||
|
|
||||||
type APIConfig* = object
|
type APIConfig* = object
|
||||||
apiModules*: string
|
apiModules*: string
|
||||||
connectorEnabled*: bool
|
connectorEnabled*: bool
|
||||||
|
@ -10,13 +12,21 @@ type APIConfig* = object
|
||||||
wsHost*: string
|
wsHost*: string
|
||||||
wsPort*: int
|
wsPort*: int
|
||||||
|
|
||||||
|
proc checkAndSetPort(port: Port, isEnabled: var bool) =
|
||||||
|
if isPortBusy(port):
|
||||||
|
isEnabled = false
|
||||||
|
|
||||||
proc defaultAPIConfig*(): APIConfig =
|
proc defaultAPIConfig*(): APIConfig =
|
||||||
result.apiModules = "connector"
|
result.apiModules = "connector"
|
||||||
result.connectorEnabled = true
|
result.connectorEnabled = true
|
||||||
|
|
||||||
result.httpEnabled = true
|
result.httpEnabled = true
|
||||||
|
checkAndSetPort(Port(8545), result.httpEnabled)
|
||||||
result.httpHost = "0.0.0.0"
|
result.httpHost = "0.0.0.0"
|
||||||
result.httpPort = 8545
|
result.httpPort = 8545
|
||||||
|
|
||||||
result.wsEnabled = true
|
result.wsEnabled = true
|
||||||
|
checkAndSetPort(Port(8586), result.wsEnabled)
|
||||||
result.wsHost = "0.0.0.0"
|
result.wsHost = "0.0.0.0"
|
||||||
result.wsPort = 8586
|
result.wsPort = 8586
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue