Use configured peers only once to set up a connection
This commit is contained in:
parent
acbd3a7032
commit
8cb7f3e594
|
@ -51,10 +51,10 @@ public class WorldManager {
|
|||
this.blockchain = new BlockchainImpl(repository);
|
||||
|
||||
// Initialize PeerData
|
||||
List<Peer> peerDataList = parsePeerDiscoveryIpList(CONFIG.peerDiscoveryIPList());
|
||||
peers.addAll(peerDataList);
|
||||
Set<Peer> peerDataList = parsePeerDiscoveryIpList(CONFIG.peerDiscoveryIPList());
|
||||
// peers.addAll(peerDataList);
|
||||
|
||||
peerDiscovery = new PeerDiscovery(peers);
|
||||
peerDiscovery = new PeerDiscovery(peerDataList);
|
||||
}
|
||||
|
||||
// used for testing
|
||||
|
@ -89,13 +89,11 @@ public class WorldManager {
|
|||
|
||||
synchronized (peers) {
|
||||
for (final Peer peer : newPeers) {
|
||||
if (peerDiscovery.isStarted() && !peers.contains(peer)) {
|
||||
if (peerDiscovery.isStarted() && !peers.contains(peer))
|
||||
peerDiscovery.addNewPeerData(peer);
|
||||
}
|
||||
peers.add(peer);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void startPeerDiscovery() {
|
||||
|
@ -116,10 +114,10 @@ public class WorldManager {
|
|||
return listener;
|
||||
}
|
||||
|
||||
public List<Peer> parsePeerDiscoveryIpList(final String peerDiscoveryIpList) {
|
||||
public Set<Peer> parsePeerDiscoveryIpList(final String peerDiscoveryIpList) {
|
||||
|
||||
final List<String> ipList = Arrays.asList(peerDiscoveryIpList.split(","));
|
||||
final List<Peer> peers = new ArrayList<>();
|
||||
final Set<Peer> peers = new HashSet<>();
|
||||
|
||||
for (String ip : ipList){
|
||||
String[] addr = ip.trim().split(":");
|
||||
|
|
|
@ -143,8 +143,8 @@ public class HelloMessage extends Message {
|
|||
" p2pVersion=" + this.p2pVersion +
|
||||
" clientId=" + this.clientId +
|
||||
" capabilities=[" + Joiner.on(" ").join(this.capabilities) + "]" +
|
||||
" peerPort=" + this.listenPort + " " +
|
||||
" peerId=" + Hex.toHexString(this.peerId) + " " +
|
||||
" peerPort=" + this.listenPort +
|
||||
" peerId=" + Hex.toHexString(this.peerId) +
|
||||
"]";
|
||||
}
|
||||
}
|
|
@ -97,7 +97,7 @@ public class PeersMessage extends Message {
|
|||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (Peer peerData : peers) {
|
||||
sb.append("\n [").append(peerData).append("]");
|
||||
sb.append("\n ").append(peerData);
|
||||
}
|
||||
return "[command=" + this.getCommand().name() + sb.toString() + "]";
|
||||
}
|
||||
|
|
|
@ -104,7 +104,6 @@ public class PeerProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
handshake = helloMessage;
|
||||
if (listener != null)
|
||||
listener.onRecvMessage(helloMessage);
|
||||
sendGetPeers();
|
||||
break;
|
||||
case STATUS:
|
||||
StatusMessage statusMessage = new StatusMessage(payload);
|
||||
|
|
Loading…
Reference in New Issue