Close RPC connection if server doesnt meet reqs

This commit is contained in:
jholdstock 2020-08-03 14:20:59 +01:00 committed by David Hill
parent 4139f25670
commit c308b8a9a6
2 changed files with 13 additions and 0 deletions

View File

@ -58,16 +58,19 @@ func (d *DcrdConnect) Client(ctx context.Context, netParams *chaincfg.Params) (*
var verMap map[string]dcrdtypes.VersionResult
err = c.Call(ctx, "version", &verMap)
if err != nil {
d.Close()
return nil, fmt.Errorf("dcrd version check failed: %v", err)
}
ver, exists := verMap["dcrdjsonrpcapi"]
if !exists {
d.Close()
return nil, fmt.Errorf("dcrd version response missing 'dcrdjsonrpcapi'")
}
sVer := semver{ver.Major, ver.Minor, ver.Patch}
if !semverCompatible(requiredDcrdVersion, sVer) {
d.Close()
return nil, fmt.Errorf("dcrd has incompatible JSON-RPC version: got %s, expected %s",
sVer, requiredDcrdVersion)
}
@ -76,9 +79,11 @@ func (d *DcrdConnect) Client(ctx context.Context, netParams *chaincfg.Params) (*
var netID wire.CurrencyNet
err = c.Call(ctx, "getcurrentnet", &netID)
if err != nil {
d.Close()
return nil, fmt.Errorf("dcrd getcurrentnet check failed: %v", err)
}
if netID != netParams.Net {
d.Close()
return nil, fmt.Errorf("dcrd running on %s, expected %s", netID, netParams.Net)
}
@ -86,9 +91,11 @@ func (d *DcrdConnect) Client(ctx context.Context, netParams *chaincfg.Params) (*
var info dcrdtypes.InfoChainResult
err = c.Call(ctx, "getinfo", &info)
if err != nil {
d.Close()
return nil, fmt.Errorf("dcrd getinfo check failed: %v", err)
}
if !info.TxIndex {
d.Close()
return nil, errors.New("dcrd does not have transaction index enabled (--txindex)")
}

View File

@ -68,6 +68,7 @@ func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params)
if err != nil {
log.Errorf("dcrwallet.Version error (wallet=%s): %v", c.String(), err)
failedConnections = append(failedConnections, connect.addr)
connect.Close()
continue
}
@ -76,6 +77,7 @@ func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params)
log.Errorf("dcrwallet.Version response missing 'dcrwalletjsonrpcapi' (wallet=%s)",
c.String())
failedConnections = append(failedConnections, connect.addr)
connect.Close()
continue
}
@ -84,6 +86,7 @@ func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params)
log.Errorf("dcrwallet has incompatible JSON-RPC version (wallet=%s): got %s, expected %s",
c.String(), sVer, requiredWalletVersion)
failedConnections = append(failedConnections, connect.addr)
connect.Close()
continue
}
@ -93,12 +96,14 @@ func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params)
if err != nil {
log.Errorf("dcrwallet.GetCurrentNet error (wallet=%s): %v", c.String(), err)
failedConnections = append(failedConnections, connect.addr)
connect.Close()
continue
}
if netID != netParams.Net {
log.Errorf("dcrwallet on wrong network (wallet=%s): running on %s, expected %s",
c.String(), netID, netParams.Net)
failedConnections = append(failedConnections, connect.addr)
connect.Close()
continue
}
@ -108,6 +113,7 @@ func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params)
if err != nil {
log.Errorf("dcrwallet.WalletInfo error (wallet=%s): %v", c.String(), err)
failedConnections = append(failedConnections, connect.addr)
connect.Close()
continue
}