Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Output ENR text representation in admin.nodeInfo RPC#5697

Closed
twinstar26 wants to merge 1 commit intoethereum:masterfrom
twinstar26:aleth-depfunc
Closed

Output ENR text representation in admin.nodeInfo RPC#5697
twinstar26 wants to merge 1 commit intoethereum:masterfrom
twinstar26:aleth-depfunc

Conversation

@twinstar26
Copy link
Copy Markdown
Contributor

Fixes #5622

@gumb0 gumb0 self-requested a review July 23, 2019 13:32
@codecov-io
Copy link
Copy Markdown

Codecov Report

Merging #5697 into master will decrease coverage by 0.2%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5697      +/-   ##
==========================================
- Coverage   62.97%   62.76%   -0.21%     
==========================================
  Files         350      349       -1     
  Lines       29994    29744     -250     
  Branches     3362     3349      -13     
==========================================
- Hits        18888    18670     -218     
+ Misses       9886     9862      -24     
+ Partials     1220     1212       -8

Copy link
Copy Markdown
Member

@gumb0 gumb0 left a comment

Choose a reason for hiding this comment

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

Instead of processing the result of toBase64 it's better to create another similar function, then make both functions implemented in terms of the third internal function, taking bytesConstRef _in and the chars that vary as parameters.
It could be for example string toBase64(bytesConstRef _in, char const* _base64_chars, bool _pad)
(then define two variants of base64_chars array to pass there; _pad flags enables padding with =)

Copy link
Copy Markdown
Member

@gumb0 gumb0 left a comment

Choose a reason for hiding this comment

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

Add a unit test for encoding at least.
(at most for RPC method, too)

bytes content() const;
size_t contentRlpListItemCount() const { return m_keyValuePairs.size() * 2 + 1; }
void streamContent(RLPStream& _s) const;
Host* h;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not correct (ENR can belong to some peer, not to Host) and not needed, just use streamRLP of this object in encodeEnr

{

std::string toBase64(bytesConstRef _in);
std::string toBase64url(bytesConstRef _in);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Call it toBase64URLSafe


#pragma once

#include <libdevcore/Base64.h>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Move this to ENR.cpp

ENR update(
std::map<std::string, bytes> const& _keyValuePair, SignFunction const& _signFunction) const;

std::string encodeEnr();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Call it textEncoding()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also make it const method

/// Create with given sign function
ENR(uint64_t _seq, std::map<std::string, bytes> const& _keyValuePairs,
SignFunction const& _signFunction);
ENR() = default;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You shouldn't need this.

/// Get the node information.
p2p::NodeInfo nodeInfo() const { return NodeInfo(id(), (networkConfig().publicIPAddress.empty() ? m_tcpPublic.address().to_string() : networkConfig().publicIPAddress), m_tcpPublic.port(), m_clientVersion); }
p2p::NodeInfo nodeInfo() const {
ENR e;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You will return empty ENR this way, not useful to anyone.
Get it from enr() method

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also use clang-format for you changes as described in https://github.com/ethereum/aleth/blob/master/CONTRIBUTING.md

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the reviews!!

@twinstar26
Copy link
Copy Markdown
Contributor Author

Instead of processing the result of toBase64 it's better to create another similar function, then make both functions implemented in terms of the third internal function, taking bytesConstRef _in and the chars that vary as parameters.
It could be for example string toBase64(bytesConstRef _in, char const* _base64_chars, bool _pad)
(then define two variants of base64_chars array to pass there; _pad flags enables padding with =)

Oh some sort of wrapper functionality??

@gumb0
Copy link
Copy Markdown
Member

gumb0 commented Jul 24, 2019

There will be one internal function, and then two public function will wrap internal one, passing it different arguments.

@gumb0
Copy link
Copy Markdown
Member

gumb0 commented Jul 29, 2019

Replaced by #5701

@gumb0 gumb0 closed this Jul 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Output ENR text representation in admin.nodeInfo RPC

3 participants