Skip to content
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

feat: Add ability to display peer id #719

Merged
merged 21 commits into from
Aug 19, 2022

Conversation

fredcarle
Copy link
Collaborator

Relevant issue(s)

Resolves #663

Description

This PR adds the ability to display the peer id of a given node both through the HTTP API and CLI.

Tasks

  • I made sure the code is well commented, particularly hard-to-understand areas.
  • I made sure the repository-held documentation is changed accordingly.
  • I made sure the pull request title adheres to the conventional commit style (the subset used in the project can be found in tools/configs/chglog/config.yml).
  • I made sure to discuss its limitations such as threats to validity, vulnerability to mistake and misuse, robustness to invalidation of assumptions, resource requirements, ...

How has this been tested?

unit tests and manual tests

Specify the platform(s) on which this was tested:

  • MacOS

@fredcarle fredcarle added feature New feature or request area/api Related to the external API component area/p2p Related to the p2p networking system action/no-benchmark Skips the action that runs the benchmark. area/cli Related to the CLI binary labels Aug 3, 2022
@fredcarle fredcarle added this to the DefraDB v0.3.1 milestone Aug 3, 2022
@fredcarle fredcarle requested a review from a team August 3, 2022 07:00
@fredcarle fredcarle self-assigned this Aug 3, 2022
@fredcarle
Copy link
Collaborator Author

One of the test is failing for a known reason. Trying to come up with a solution but in the mean time I welcome your feedback on the rest of the code :)

api/http/router.go Show resolved Hide resolved
cli/peerid.go Show resolved Hide resolved
cli/peerid.go Outdated Show resolved Hide resolved
cli/peerid_test.go Outdated Show resolved Hide resolved
@fredcarle fredcarle force-pushed the fredcarle/feat/I663-display-peerid branch from 1e8951c to 100d6d9 Compare August 5, 2022 00:53
@codecov
Copy link

codecov bot commented Aug 5, 2022

Codecov Report

Merging #719 (98b3fe6) into develop (da7088e) will increase coverage by 0.36%.
The diff coverage is 51.33%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #719      +/-   ##
===========================================
+ Coverage    57.66%   58.02%   +0.36%     
===========================================
  Files          143      144       +1     
  Lines        16456    16593     +137     
===========================================
+ Hits          9489     9628     +139     
+ Misses        6083     6052      -31     
- Partials       884      913      +29     
Impacted Files Coverage Δ
node/node.go 60.10% <ø> (ø)
cli/peerid.go 37.28% <37.28%> (ø)
cli/start.go 43.17% <43.13%> (+26.41%) ⬆️
logging/logger.go 75.77% <60.00%> (-1.05%) ⬇️
api/http/errors.go 100.00% <100.00%> (ø)
api/http/handler.go 100.00% <100.00%> (ø)
api/http/handlerfuncs.go 89.01% <100.00%> (+0.91%) ⬆️
api/http/router.go 100.00% <100.00%> (ø)
api/http/server.go 100.00% <100.00%> (ø)
... and 6 more

@fredcarle fredcarle force-pushed the fredcarle/feat/I663-display-peerid branch from 3942f22 to 2b49372 Compare August 5, 2022 16:49
cli/start.go Outdated Show resolved Hide resolved
http.Server
}

type serverOptions struct {
allowedOrigins []string
peerID string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question (non-blocking): I wonder what is best: to pass the peerID as param to http API and for it to be part of context of each request, or for the http API to not hold the info and instead obtain the info from node every time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the info to the context is very lightweight. Not sure how it would obtain the info from node.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a .PeerID() func to the node interface, which replies either with an empty string or its PeerID?

If the public key of a node changes, its PeerID would have to change. When that happens, with the construction of this PR, we would also have to restart the HTTP API. I'm not convinced that supporting live changing the public key and PeerID of a node is a good idea, but I do want to acknowledge the dependency that is made here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR already adds a PeerID method to the node. But the HTTP API isn't aware of the node at the moment. In the future it probably should be though. So right now the only way this can work is if we pass along the PeerID to the HTTP API when we start the instance.

@fredcarle fredcarle force-pushed the fredcarle/feat/I663-display-peerid branch 3 times, most recently from 57dd095 to cab57e8 Compare August 8, 2022 19:37
core/api/http.go Outdated Show resolved Hide resolved
core/api/http.go Outdated Show resolved Hide resolved
cli/peerid.go Outdated Show resolved Hide resolved
api/http/errors.go Show resolved Hide resolved
api/http/errors.go Show resolved Hide resolved
api/http/handler.go Show resolved Hide resolved
api/http/handler_test.go Outdated Show resolved Hide resolved
cli/start.go Outdated Show resolved Hide resolved
cli/start.go Outdated Show resolved Hide resolved
cli/start.go Outdated Show resolved Hide resolved
cli/start.go Outdated Show resolved Hide resolved
cli/start.go Outdated Show resolved Hide resolved
cli/start.go Outdated Show resolved Hide resolved
@@ -91,34 +91,44 @@ func (l *logger) FatalE(ctx context.Context, message string, err error, keyvals

func (l *logger) FeedbackInfo(ctx context.Context, message string, keyvals ...KV) {
l.Info(ctx, message, keyvals...)
l.syncLock.RLock()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: why?

Copy link
Collaborator Author

@fredcarle fredcarle Aug 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because with the new test there was a race condition error caused by trying to read consoleLogger while it was being set.

@orpheuslummis
Copy link
Contributor

suggestion: Because the PR now has more changes than what stated in its title, the title should be update to represent that

@fredcarle
Copy link
Collaborator Author

suggestion: Because the PR now has more changes than what stated in its title, the title should be update to represent that

All changes are related to what is represented in the PR title. Not sure it really has to change.

cli/start.go Outdated Show resolved Hide resolved
cli/start.go Outdated Show resolved Hide resolved
@fredcarle fredcarle force-pushed the fredcarle/feat/I663-display-peerid branch from e7d60e2 to 667f441 Compare August 16, 2022 03:45
@fredcarle fredcarle changed the title feat: Add ability to display peer id through the HTTP API and CLI feat: Add ability to display peer id Aug 16, 2022
@fredcarle fredcarle force-pushed the fredcarle/feat/I663-display-peerid branch 2 times, most recently from f0b64c7 to 24696a3 Compare August 18, 2022 20:40
@fredcarle fredcarle force-pushed the fredcarle/feat/I663-display-peerid branch from 24696a3 to f48bd08 Compare August 18, 2022 20:53
Copy link
Contributor

@orpheuslummis orpheuslummis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Just a few typos to fix

api/http/errors.go Outdated Show resolved Hide resolved
api/http/handler.go Outdated Show resolved Hide resolved
api/http/server.go Outdated Show resolved Hide resolved
@fredcarle
Copy link
Collaborator Author

LGTM Just a few typos to fix

Very glad that we have someone on the team that has a radar for that kind of thing. 😄

@fredcarle fredcarle merged commit e9f5f70 into develop Aug 19, 2022
@fredcarle fredcarle deleted the fredcarle/feat/I663-display-peerid branch August 19, 2022 14:48
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
Description
This PR adds the ability to display the peer id of a given node both through the HTTP API and CLI.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/no-benchmark Skips the action that runs the benchmark. area/api Related to the external API component area/cli Related to the CLI binary area/p2p Related to the p2p networking system feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add CLI command to display PeerID
3 participants