-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
p2p: add human friendly names to peers #624
Conversation
Codecov Report
@@ Coverage Diff @@
## main #624 +/- ##
==========================================
- Coverage 56.89% 56.33% -0.56%
==========================================
Files 96 97 +1
Lines 9126 9145 +19
==========================================
- Hits 5192 5152 -40
- Misses 3195 3249 +54
- Partials 739 744 +5
Continue to review full report at Codecov.
|
cluster/operator.go
Outdated
// randomName returns a deterministic name for an ecdsa public key. The name consists of a noun | ||
// and an adjective separated by a hyphen. The noun is calculated using PublicKey's X coordinate | ||
// while the adjective is calculated using PublicKey's Y coordinate. | ||
func randomName(pk ecdsa.PublicKey) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets move this function to its own file maybe name.go
? and split out the lists to global variables defined one word per line.
cluster/operator.go
Outdated
res := big.NewInt(0) | ||
|
||
// calculate the index of the adjective using X % ADJ_LEN | ||
adjLen := big.NewInt(int64(len(adjectives))) | ||
res.Rem(pk.X, adjLen) | ||
adjIdx := res.Uint64() | ||
|
||
// similarly, calculate the index of the noun using Y % NOUN_LEN | ||
nounLen := big.NewInt(int64(len(nouns))) | ||
nounIdx := res.Rem(pk.Y, nounLen).Uint64() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be a bit more consistent, adjIdx calculated the same as nounIdx. Also please be very careful with big.Int
, it has a bad mutable API. Prefer to use it in a immutable way, by only using one big.Int once and creating new ones with each calculation. You mutate res
multiple times.
// calculate the index of the adjective using X % ADJ_LEN
adjLen := big.NewInt(int64(len(adjectives)))
adjIdx := new(big.Int).Rem(pk.X, adjLen).Uint64()
// similarly, calculate the index of the noun using Y % NOUN_LEN
nounLen := big.NewInt(int64(len(nouns)))
nounIdx := new(big.Int).Rem(pk.Y, nounLen).Uint64()
cluster/operator_internal_test.go
Outdated
|
||
second, err := op.getName() | ||
assert.NoError(t, err) | ||
assert.True(t, strings.Contains(second, "-")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add an assertion for the actual name require.Equal(t, first, "foo-bar")
Also please prefer require
to assert
@@ -41,6 +41,9 @@ type Peer struct { | |||
// Index is the order of this node in the cluster. | |||
// This is only applicable to charon nodes, not relays. | |||
Index int | |||
|
|||
// Name represents a human friendly name for the peer. | |||
Name string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isn't set... or used...
category: feature
ticket: #585