Use configured peers only once to set up a connection

This commit is contained in:
nicksavers 2014-09-29 13:20:00 +02:00
parent acbd3a7032
commit 8cb7f3e594
4 changed files with 9 additions and 12 deletions

View File

@ -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(":");

View File

@ -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) +
"]";
}
}

View File

@ -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() + "]";
}

View File

@ -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);