Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.tron.p2p.discover.Node;
import org.tron.p2p.protos.Connect;
import org.tron.p2p.protos.Discover;
import org.tron.p2p.utils.ByteArray;
import org.tron.p2p.utils.NetUtil;

public class HelloMessage extends Message {
Expand Down Expand Up @@ -52,12 +53,25 @@ public Node getFrom() {

@Override
public String toString() {
return "[HelloMessage: " + helloMessage;
return "[HelloMessage: " + format();
}

@Override
public boolean valid() {
return NetUtil.validNode(getFrom());
}

public String format() {
String[] lines = helloMessage.toString().split("\n");
StringBuilder sb = new StringBuilder();
for (String line : lines) {
if (line.contains("nodeId")) {

Choose a reason for hiding this comment

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

Is it possible that using string matching may unintentionally replace unrelated content? I think it's not a good way for 3 reasons:1. If there are multiple fields containing "nodeId" in different contexts 2. If helloMessage add a new filed which name contains "nodeId" 3. If the proto toString() format changes in future?

String nodeId = ByteArray.toHexString(helloMessage.getFrom().getNodeId().toByteArray());
line = " nodeId: \"" + nodeId + "\"";
}
sb.append(line).append("\n");
}
return sb.toString();
}

}