Skip to content

Commit 5b6b40f

Browse files
authored
Merge pull request #2518 from tronprotocol/develop_v3.6.5
Develop v3.6.5 merge to master
2 parents 8d8ad48 + 34421f6 commit 5b6b40f

File tree

85 files changed

+4291
-1751
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+4291
-1751
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ dependencies {
175175
// http
176176
compile 'org.eclipse.jetty:jetty-server:9.4.11.v20180605'
177177
compile 'org.eclipse.jetty:jetty-servlet:9.4.11.v20180605'
178-
compile 'com.alibaba:fastjson:1.2.47'
178+
compile 'com.alibaba:fastjson:1.2.60'
179179
compile group: 'org.apache.httpcomponents', name:'httpasyncclient', version:'4.1.1'
180180
// end http
181181

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
1-
/*
2-
* Copyright (c) [2016] [ <ether.camp> ]
3-
* This file is part of the ethereumJ library.
4-
*
5-
* The ethereumJ library is free software: you can redistribute it and/or modify
6-
* it under the terms of the GNU Lesser General Public License as published by
7-
* the Free Software Foundation, either version 3 of the License, or
8-
* (at your option) any later version.
9-
*
10-
* The ethereumJ library is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU Lesser General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU Lesser General Public License
16-
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
17-
*/
18-
191
package org.tron.common.overlay.discover;
202

213
import java.util.ArrayList;
@@ -24,18 +6,17 @@
246
import org.tron.common.overlay.discover.node.Node;
257
import org.tron.common.overlay.discover.node.NodeManager;
268
import org.tron.common.overlay.discover.table.KademliaOptions;
27-
import org.tron.common.overlay.discover.table.NodeEntry;
289

2910
@Slf4j(topic = "discover")
3011
public class DiscoverTask implements Runnable {
3112

32-
NodeManager nodeManager;
13+
private NodeManager nodeManager;
3314

34-
byte[] nodeId;
15+
private byte[] nodeId;
3516

3617
public DiscoverTask(NodeManager nodeManager) {
3718
this.nodeManager = nodeManager;
38-
nodeId = nodeManager.getPublicHomeNode().getId();
19+
this.nodeId = nodeManager.getPublicHomeNode().getId();
3920
}
4021

4122
@Override
@@ -47,12 +28,6 @@ public synchronized void discover(byte[] nodeId, int round, List<Node> prevTried
4728

4829
try {
4930
if (round == KademliaOptions.MAX_STEPS) {
50-
logger.debug("Node table contains [{}] peers", nodeManager.getTable().getNodesCount());
51-
logger.debug("{}", String
52-
.format("(KademliaOptions.MAX_STEPS) Terminating discover after %d rounds.", round));
53-
logger.trace("{}\n{}",
54-
String.format("Nodes discovered %d ", nodeManager.getTable().getNodesCount()),
55-
dumpNodes());
5631
return;
5732
}
5833

@@ -74,11 +49,6 @@ public synchronized void discover(byte[] nodeId, int round, List<Node> prevTried
7449
}
7550

7651
if (tried.isEmpty()) {
77-
logger.debug("{}",
78-
String.format("(tried.isEmpty()) Terminating discover after %d rounds.", round));
79-
logger.trace("{}\n{}",
80-
String.format("Nodes discovered %d ", nodeManager.getTable().getNodesCount()),
81-
dumpNodes());
8252
return;
8353
}
8454

@@ -90,11 +60,4 @@ public synchronized void discover(byte[] nodeId, int round, List<Node> prevTried
9060
}
9161
}
9262

93-
private String dumpNodes() {
94-
String ret = "";
95-
for (NodeEntry entry : nodeManager.getTable().getAllNodes()) {
96-
ret += " " + entry.getNode() + "\n";
97-
}
98-
return ret;
99-
}
10063
}

src/main/java/org/tron/common/overlay/discover/RefreshTask.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.tron.common.overlay.discover;
2020

2121
import java.util.ArrayList;
22-
import java.util.Random;
2322
import lombok.extern.slf4j.Slf4j;
2423
import org.tron.common.overlay.discover.node.Node;
2524
import org.tron.common.overlay.discover.node.NodeManager;
@@ -31,15 +30,8 @@ public RefreshTask(NodeManager nodeManager) {
3130
super(nodeManager);
3231
}
3332

34-
public static byte[] getNodeId() {
35-
Random gen = new Random();
36-
byte[] id = new byte[64];
37-
gen.nextBytes(id);
38-
return id;
39-
}
40-
4133
@Override
4234
public void run() {
43-
discover(getNodeId(), 0, new ArrayList<Node>());
35+
discover(Node.getNodeId(), 0, new ArrayList<>());
4436
}
4537
}

src/main/java/org/tron/common/overlay/discover/node/Node.java

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,16 @@
1-
/*
2-
* Copyright (c) [2016] [ <ether.camp> ]
3-
* This file is part of the ethereumJ library.
4-
*
5-
* The ethereumJ library is free software: you can redistribute it and/or modify
6-
* it under the terms of the GNU Lesser General Public License as published by
7-
* the Free Software Foundation, either version 3 of the License, or
8-
* (at your option) any later version.
9-
*
10-
* The ethereumJ library is distributed in the hope that it will be useful,
11-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13-
* GNU Lesser General Public License for more details.
14-
*
15-
* You should have received a copy of the GNU Lesser General Public License
16-
* along with the ethereumJ library. If not, see <http://www.gnu.org/licenses/>.
17-
*/
18-
191
package org.tron.common.overlay.discover.node;
202

21-
import static org.tron.common.crypto.Hash.sha3;
22-
233
import java.io.Serializable;
244
import java.net.URI;
255
import java.net.URISyntaxException;
6+
import java.util.Random;
7+
import lombok.Getter;
8+
import lombok.Setter;
269
import org.apache.commons.lang3.StringUtils;
2710
import org.spongycastle.util.encoders.Hex;
28-
import org.tron.common.crypto.ECKey;
2911
import org.tron.common.utils.ByteArray;
3012
import org.tron.common.utils.Utils;
13+
import org.tron.core.config.args.Args;
3114

3215
public class Node implements Serializable {
3316

@@ -39,6 +22,14 @@ public class Node implements Serializable {
3922

4023
private int port;
4124

25+
@Getter
26+
private int bindPort;
27+
28+
@Setter
29+
private int p2pVersion;
30+
31+
private int reputation = 0;
32+
4233
private boolean isFakeNodeId = false;
4334

4435
public int getReputation() {
@@ -49,8 +40,6 @@ public void setReputation(int reputation) {
4940
this.reputation = reputation;
5041
}
5142

52-
private int reputation = 0;
53-
5443
public static Node instanceOf(String addressOrEnode) {
5544
try {
5645
URI uri = new URI(addressOrEnode);
@@ -61,10 +50,8 @@ public static Node instanceOf(String addressOrEnode) {
6150
// continue
6251
}
6352

64-
final ECKey generatedNodeKey = ECKey.fromPrivate(sha3(addressOrEnode.getBytes()));
65-
final String generatedNodeId = Hex.toHexString(generatedNodeKey.getNodeId());
53+
final String generatedNodeId = Hex.toHexString(getNodeId());
6654
final Node node = new Node("enode://" + generatedNodeId + "@" + addressOrEnode);
67-
node.isFakeNodeId = true;
6855
return node;
6956
}
7057

@@ -84,6 +71,8 @@ public Node(String enodeURL) {
8471
this.id = Hex.decode(uri.getUserInfo());
8572
this.host = uri.getHost();
8673
this.port = uri.getPort();
74+
this.bindPort = uri.getPort();
75+
this.isFakeNodeId = true;
8776
} catch (URISyntaxException e) {
8877
throw new RuntimeException("expecting URL in the format enode://PUBKEY@HOST:PORT", e);
8978
}
@@ -95,6 +84,20 @@ public Node(byte[] id, String host, int port) {
9584
}
9685
this.host = host;
9786
this.port = port;
87+
this.isFakeNodeId = true;
88+
}
89+
90+
public Node(byte[] id, String host, int port, int bindPort) {
91+
if (id != null) {
92+
this.id = id.clone();
93+
}
94+
this.host = host;
95+
this.port = port;
96+
this.bindPort = bindPort;
97+
}
98+
99+
public boolean isConnectible() {
100+
return port == bindPort && p2pVersion == Args.getInstance().getNodeP2pVersion();
98101
}
99102

100103
public String getHexId() {
@@ -110,11 +113,11 @@ public boolean isDiscoveryNode() {
110113
}
111114

112115
public byte[] getId() {
113-
return id == null ? id : id.clone();
116+
return id;
114117
}
115118

116119
public void setId(byte[] id) {
117-
this.id = id == null ? null : id.clone();
120+
this.id = id;
118121
}
119122

120123
public String getHost() {
@@ -136,6 +139,13 @@ public String getIdString() {
136139
return new String(id);
137140
}
138141

142+
public static byte[] getNodeId() {
143+
Random gen = new Random();
144+
byte[] id = new byte[64];
145+
gen.nextBytes(id);
146+
return id;
147+
}
148+
139149
@Override
140150
public String toString() {
141151
return "Node{" + " host='" + host + '\'' + ", port=" + port

src/main/java/org/tron/common/overlay/discover/node/NodeHandler.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ public void handlePing(PingMessage msg) {
191191
if (!nodeManager.getTable().getNode().equals(node)) {
192192
sendPong(msg.getTimestamp());
193193
}
194-
if (msg.getVersion() != Args.getInstance().getNodeP2pVersion()) {
194+
node.setP2pVersion(msg.getVersion());
195+
if (!node.isConnectible()) {
195196
changeState(State.NonActive);
196197
} else if (state.equals(State.NonActive) || state.equals(State.Dead)) {
197198
changeState(State.Discovered);
@@ -204,7 +205,8 @@ public void handlePong(PongMessage msg) {
204205
getNodeStatistics().discoverMessageLatency.add(System.currentTimeMillis() - pingSent);
205206
getNodeStatistics().lastPongReplyTime.set(System.currentTimeMillis());
206207
node.setId(msg.getFrom().getId());
207-
if (msg.getVersion() != Args.getInstance().getNodeP2pVersion()) {
208+
node.setP2pVersion(msg.getVersion());
209+
if (!node.isConnectible()) {
208210
changeState(State.NonActive);
209211
} else {
210212
changeState(State.Alive);

0 commit comments

Comments
 (0)