peer discovery fixes

This commit is contained in:
romanman 2014-10-24 23:17:04 -05:00
parent b70315532e
commit e9bbc95ee5
9 changed files with 31 additions and 21 deletions

View File

@ -210,7 +210,7 @@ public class P2pHandler extends SimpleChannelInboundHandler<P2pMessage> {
InetAddress address = ((InetSocketAddress) ctx.channel().remoteAddress()).getAddress();
int port = msg.getListenPort();
PeerInfo confirmedPeer = new PeerInfo(address, port, msg.getPeerId());
confirmedPeer.setOnline(true);
confirmedPeer.setOnline(false);
confirmedPeer.getCapabilities().addAll(msg.getCapabilities());
//todo calculate the Offsets

View File

@ -49,7 +49,7 @@ public class PeerDiscovery {
// Initialize PeerData
List<PeerInfo> peerDataList = parsePeerDiscoveryIpList(CONFIG.peerDiscoveryIPList());
peers.addAll(peerDataList);
addPeers(peerDataList);
for (PeerInfo peerData : this.peers) {
executorPool.execute(new WorkerThread(peerData, executorPool));
@ -91,6 +91,13 @@ public class PeerDiscovery {
}
}
public void addPeers(Collection<PeerInfo> newPeers) {
synchronized (peers) {
peers.addAll(newPeers);
}
}
private void startWorker(PeerInfo peer) {
logger.debug("Add new peer for discovery: {}", peer);
executorPool.execute(new WorkerThread(peer, executorPool));

View File

@ -86,13 +86,15 @@ public class PeerInfo {
public boolean equals(Object obj) {
if (obj == null) return false;
PeerInfo peerData = (PeerInfo) obj;
return peerData.peerId.equals(this.peerId)
|| this.getAddress().equals(peerData.getAddress());
return peerData.hashCode() == this.hashCode();
}
@Override
public int hashCode() {
return -1; // override for equals function
int result = address.hashCode();
result = 31 * result + port;
return result;
}
public HelloMessage getHandshakeHelloMessage() {

View File

@ -17,6 +17,7 @@ public class WorkerThread implements Runnable {
private PeerInfo peerInfo;
private PeerClient clientPeer;
private ThreadPoolExecutor poolExecutor;
private boolean running = true;
public WorkerThread(PeerInfo peer, ThreadPoolExecutor poolExecutor) {
this.peerInfo = peer;
@ -44,6 +45,7 @@ public class WorkerThread implements Runnable {
logger.info("Peer is online: [{}] ", peerInfo);
} catch (Throwable e) {
if (peerInfo.isOnline())
logger.info("Peer: [{}] went offline, due to: [{}]", peerInfo

View File

@ -25,9 +25,10 @@ log4j.logger.block = ERROR
log4j.logger.blockqueue = TRACE
log4j.logger.wallet = ERROR
log4j.logger.general = DEBUG
log4j.logger.net = TRACE
log4j.logger.net = ERROR
log4j.logger.db = ERROR
log4j.logger.peerdiscovery = TRACE
log4j.logger.peerdiscovery = ERROR
log4j.logger.peermonitor = ERROR
log4j.logger.java.nio = ERROR
log4j.logger.io.netty = ERROR
log4j.logger.wire = ERROR

View File

@ -45,11 +45,11 @@ peer.discovery = true
# number of workers that
# tastes the peers for being
# online [1..10]
peer.discovery.workers = 10
peer.discovery.workers = 4
# connection timeout for trying to
# connect to a peer [seconds]
peer.connection.timeout = 10
peer.connection.timeout = 2
# the time we wait to the network
# to approve the transaction, the
@ -72,7 +72,7 @@ samples.dir = samples
# the existing database will be
# destroyed and all the data will be
# downloaded from peers again
database.reset = true
database.reset = false
# place to save physical storage files
database.dir = database

View File

@ -71,11 +71,9 @@
<dependency>
<groupId>org.ethereum</groupId>
<artifactId>ethereumj</artifactId>
<version>0.7.2.20141024.1409</version>
<type>jar</type>
<version>0.7.2.20141024.2310</version>
</dependency>
<dependency>
<groupId>com.maxmind.geoip</groupId>
<artifactId>geoip-api</artifactId>

View File

@ -27,7 +27,7 @@ log4j.logger.net = ERROR
log4j.logger.wire = ERROR
log4j.logger.db = ERROR
log4j.logger.peerdiscovery = TRACE
log4j.logger.peermonitor = ERROR
log4j.logger.peermonitor = TRACE
log4j.logger.java.nio = ERROR
log4j.logger.io.netty = ERROR
log4j.logger.VM = ERROR

View File

@ -6,7 +6,7 @@ server.acceptConnections = false
# the search of the online peers
# values: [ip:port, ip:port, ip:port ...]
peer.discovery.ip.list = poc-7.ethdev.com:30303,\
54.204.10.41:30303
185.43.109.23:30303
# Peer Server Zero (poc-7.ethdev.com)
#peer.active.ip = 207.12.89.180
@ -44,12 +44,12 @@ protocol.version = 33
# the peer window will show
# only what retrieved by active
# peer [true/false]
peer.discovery = false
peer.discovery = true
# number of workers that
# tastes the peers for being
# online [1..10]
peer.discovery.workers = 10
peer.discovery.workers = 1
# connection timeout for trying to
# connect to a peer [seconds]