-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from samcm/feat/peer-client-detection
Feat(consensus): Peer client detection
- Loading branch information
Showing
5 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package types | ||
|
||
import ( | ||
"strings" | ||
) | ||
|
||
type Agent string | ||
|
||
const ( | ||
AgentUnknown Agent = "unknown" | ||
AgentLighthouse Agent = "lighthouse" | ||
AgentNimbus Agent = "nimbus" | ||
AgentTeku Agent = "teku" | ||
AgentPrysm Agent = "prysm" | ||
AgentLodestar Agent = "lodestar" | ||
) | ||
|
||
var AllAgents = []Agent{ | ||
AgentUnknown, | ||
AgentLighthouse, | ||
AgentNimbus, | ||
AgentTeku, | ||
AgentPrysm, | ||
AgentLodestar, | ||
} | ||
|
||
type AgentCount struct { | ||
Unknown int `json:"unknown"` | ||
Lighthouse int `json:"lighthouse"` | ||
Nimbus int `json:"nimbus"` | ||
Teku int `json:"teku"` | ||
Prysm int `json:"prysm"` | ||
Lodestar int `json:"lodestar"` | ||
} | ||
|
||
func AgentFromString(agent string) Agent { | ||
asLower := strings.ToLower(agent) | ||
|
||
if strings.Contains(asLower, "lighthouse") { | ||
return AgentLighthouse | ||
} | ||
|
||
if strings.Contains(asLower, "nimbus") { | ||
return AgentNimbus | ||
} | ||
|
||
if strings.Contains(asLower, "teku") { | ||
return AgentTeku | ||
} | ||
|
||
if strings.Contains(asLower, "prysm") { | ||
return AgentPrysm | ||
} | ||
|
||
if strings.Contains(asLower, "lodestar") { | ||
return AgentLodestar | ||
} | ||
|
||
return AgentUnknown | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package types | ||
|
||
import "testing" | ||
|
||
func TestAgentParsing(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := []struct { | ||
input string | ||
expect Agent | ||
}{ | ||
{"Prysm/v2.0.2/4a4a7e97dfd2285a5e48a178f693d870e9a4ff60", AgentPrysm}, | ||
{"Lighthouse/v3.1.0-aa022f4/x86_64-linux", AgentLighthouse}, | ||
{"nimbus", AgentNimbus}, | ||
{"teku/teku/v22.9.0/linux-x86_64/-privatebuild-openjdk64bitservervm-java-17", AgentTeku}, | ||
{"Lodestar/v0.32.0-rc.0-1-gc3b5b6a9/linux-x64/nodejs", AgentLodestar}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.input, func(t *testing.T) { | ||
t.Parallel() | ||
if actual := AgentFromString(test.input); actual != test.expect { | ||
t.Errorf("Expected %s, got %s", test.expect, actual) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters