fix(p2p): report malformed peer builds
Co-Authored-By: Charon <charon@lethean.io>
This commit is contained in:
parent
ccdcfbaacf
commit
d2caf68d94
2 changed files with 28 additions and 4 deletions
|
|
@ -187,10 +187,15 @@ func ValidateHandshakeResponse(resp *HandshakeResponse, expectedNetworkID [16]by
|
|||
resp.NodeData.NetworkID, expectedNetworkID)
|
||||
}
|
||||
|
||||
if !MeetsMinimumBuildVersion(resp.PayloadData.ClientVersion, isTestnet) {
|
||||
minBuild := MinimumRequiredBuildVersion(isTestnet)
|
||||
return fmt.Errorf("p2p: peer build %q below minimum %d",
|
||||
resp.PayloadData.ClientVersion, minBuild)
|
||||
buildVersion, ok := PeerBuildVersion(resp.PayloadData.ClientVersion)
|
||||
if !ok {
|
||||
return fmt.Errorf("p2p: peer build %q is malformed", resp.PayloadData.ClientVersion)
|
||||
}
|
||||
|
||||
minBuild := MinimumRequiredBuildVersion(isTestnet)
|
||||
if buildVersion < minBuild {
|
||||
return fmt.Errorf("p2p: peer build %q parsed as %d below minimum %d",
|
||||
resp.PayloadData.ClientVersion, buildVersion, minBuild)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -208,3 +208,22 @@ func TestValidateHandshakeResponse_BadBuildVersion(t *testing.T) {
|
|||
t.Fatalf("ValidateHandshakeResponse error: got %v, want build minimum failure", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateHandshakeResponse_BadMalformedBuildVersion(t *testing.T) {
|
||||
resp := &HandshakeResponse{
|
||||
NodeData: NodeData{
|
||||
NetworkID: config.NetworkIDMainnet,
|
||||
},
|
||||
PayloadData: CoreSyncData{
|
||||
ClientVersion: "bogus",
|
||||
},
|
||||
}
|
||||
|
||||
err := ValidateHandshakeResponse(resp, config.NetworkIDMainnet, false)
|
||||
if err == nil {
|
||||
t.Fatal("ValidateHandshakeResponse: expected malformed build version error")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "malformed") {
|
||||
t.Fatalf("ValidateHandshakeResponse error: got %v, want malformed build version failure", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue