Make RPC reconnect interval configurable (#9)
parent
a13e3e0076
commit
4e30e02ae5
|
@ -86,7 +86,7 @@ Description: The "privs" privilege is granted to the player with this name on st
|
|||
```
|
||||
> `csm_restriction_flags`
|
||||
```
|
||||
Type: Unsigned integer
|
||||
Type: Integer
|
||||
Description: The CSM restriction flags, default is none
|
||||
* 0: No restrictions
|
||||
* 1: No CSM loading
|
||||
|
@ -98,3 +98,8 @@ Description: The CSM restriction flags, default is none
|
|||
* 63: All restrictions
|
||||
To set multiple flags at the same time add the corresponding numbers
|
||||
```
|
||||
> `rpc_reconnect_interval`
|
||||
```
|
||||
Type: Integer
|
||||
Description: Minutes between RPC reconnection attempts, default is 10
|
||||
```
|
||||
|
|
25
rpc.go
25
rpc.go
|
@ -29,8 +29,6 @@ const (
|
|||
ModChStateRO
|
||||
)
|
||||
|
||||
const RpcReconnectInterval = 10 * time.Minute
|
||||
|
||||
var rpcSrvMu sync.Mutex
|
||||
var rpcSrvs map[*Peer]struct{}
|
||||
|
||||
|
@ -222,14 +220,25 @@ func connectRpc() {
|
|||
}
|
||||
}
|
||||
|
||||
func startRpc() {
|
||||
func init() {
|
||||
rpcSrvMu.Lock()
|
||||
rpcSrvs = make(map[*Peer]struct{})
|
||||
rpcSrvMu.Unlock()
|
||||
|
||||
reconnect, ok := GetConfKey("rpc_reconnect_interval").(int)
|
||||
if !ok {
|
||||
reconnect = 10
|
||||
}
|
||||
|
||||
connectRpc()
|
||||
|
||||
go func() {
|
||||
reconnect := time.NewTicker(RpcReconnectInterval)
|
||||
reconnect := time.NewTicker(time.Duration(reconnect) * time.Minute)
|
||||
for {
|
||||
select {
|
||||
case <-reconnect.C:
|
||||
log.Print("Re-establishing closed RPC connections")
|
||||
|
||||
servers := GetConfKey("servers").(map[interface{}]interface{})
|
||||
for server := range servers {
|
||||
clt := &Peer{username: "rpc"}
|
||||
|
@ -319,11 +328,3 @@ func startRpc() {
|
|||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func init() {
|
||||
rpcSrvMu.Lock()
|
||||
rpcSrvs = make(map[*Peer]struct{})
|
||||
rpcSrvMu.Unlock()
|
||||
|
||||
startRpc()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue