make peer discovery work again

This commit is contained in:
romanman 2014-10-23 15:23:26 -05:00
parent 44fe6763d7
commit 2a2f34f7c3
10 changed files with 36 additions and 23 deletions

View File

@ -26,9 +26,9 @@
<property name="artifact.groupId" value="org.ethereum"/> <property name="artifact.groupId" value="org.ethereum"/>
<property name="artifact.id" value="ethereumj"/> <property name="artifact.id" value="ethereumj"/>
<property name="artifact.version" value="0.7.1"/> <property name="artifact.version" value="0.7.2"/>
<property name="artifact.path" value="" /> <property name="artifact.path" value="" />
<property name="artifact.snapshot" value="snapshot" /> <!--<property name="artifact.snapshot" value="snapshot" />-->
<property name="repo.location" value="${user.home}/.m2/repository"/> <property name="repo.location" value="${user.home}/.m2/repository"/>
<property name="artifact.group.path" value="${artifact.groupId}"/> <property name="artifact.group.path" value="${artifact.groupId}"/>

View File

@ -169,7 +169,7 @@ public class Transaction {
public boolean isContractCreation() { public boolean isContractCreation() {
if (!parsed) rlpParse(); if (!parsed) rlpParse();
return this.receiveAddress == null; return this.receiveAddress == null || this.receiveAddress == ByteUtil.EMPTY_BYTE_ARRAY;
} }
/********* /*********

View File

@ -46,12 +46,12 @@ public class PeerClient {
} }
public PeerClient(boolean peerDiscoveryMode){ public PeerClient(boolean peerDiscoveryMode){
super(); this();
this.peerDiscoveryMode = peerDiscoveryMode; this.peerDiscoveryMode = peerDiscoveryMode;
} }
public PeerClient(PeerListener peerListener) { public PeerClient(PeerListener peerListener) {
super(); this();
this.peerListener = peerListener; this.peerListener = peerListener;
} }
@ -63,7 +63,7 @@ public class PeerClient {
peerListener.console("Connecting to: " + host + ":" + port); peerListener.console("Connecting to: " + host + ":" + port);
if (peerDiscoveryMode) if (peerDiscoveryMode)
p2pHandler = new P2pHandler(peerDiscoveryMode); p2pHandler = new P2pHandler(peerDiscoveryMode, msgQueue);
else else
p2pHandler = new P2pHandler(peerListener, msgQueue); p2pHandler = new P2pHandler(peerListener, msgQueue);
p2pHandler.activate(); p2pHandler.activate();
@ -108,11 +108,13 @@ public class PeerClient {
} catch (Exception e) { } catch (Exception e) {
logger.debug("Exception: {} ({})", e.getMessage(), e.getClass().getName()); logger.debug("Exception: {} ({})", e.getMessage(), e.getClass().getName());
throw new Error("Disconnnected");
} finally { } finally {
workerGroup.shutdownGracefully(); workerGroup.shutdownGracefully();
p2pHandler.killTimers(); p2pHandler.killTimers();
/*
final Set<PeerData> peers = WorldManager.getInstance().getPeerDiscovery().getPeers(); final Set<PeerData> peers = WorldManager.getInstance().getPeerDiscovery().getPeers();
synchronized (peers) { synchronized (peers) {
@ -122,6 +124,7 @@ public class PeerClient {
peer.setOnline(false); peer.setOnline(false);
} }
} }
*/
} }
} }

View File

@ -61,17 +61,17 @@ public class P2pHandler extends SimpleChannelInboundHandler<P2pMessage> {
private boolean peerDiscoveryMode = false; private boolean peerDiscoveryMode = false;
public P2pHandler() { public P2pHandler(MessageQueue msgQueue) {
this.msgQueue = msgQueue;
} }
public P2pHandler(boolean peerDiscoveryMode) { public P2pHandler(boolean peerDiscoveryMode, MessageQueue msgQueue) {
super(); this(msgQueue);
this.peerDiscoveryMode = peerDiscoveryMode; this.peerDiscoveryMode = peerDiscoveryMode;
} }
public P2pHandler(PeerListener peerListener, MessageQueue msgQueue) { public P2pHandler(PeerListener peerListener, MessageQueue msgQueue) {
this(); this(msgQueue);
this.msgQueue = msgQueue;
this.peerListener = peerListener; this.peerListener = peerListener;
} }
@ -104,7 +104,8 @@ public class P2pHandler extends SimpleChannelInboundHandler<P2pMessage> {
case HELLO: case HELLO:
msgQueue.receivedMessage(msg); msgQueue.receivedMessage(msg);
if (!peerDiscoveryMode) if (!peerDiscoveryMode)
setHandshake((HelloMessage) msg, ctx); setHandshake((HelloMessage) msg, ctx);
sendGetPeers();
break; break;
case DISCONNECT: case DISCONNECT:
msgQueue.receivedMessage(msg); msgQueue.receivedMessage(msg);
@ -161,6 +162,10 @@ public class P2pHandler extends SimpleChannelInboundHandler<P2pMessage> {
WorldManager.getInstance().getPeerDiscovery().addPeers(peersMessage.getPeers()); WorldManager.getInstance().getPeerDiscovery().addPeers(peersMessage.getPeers());
} }
private void sendGetPeers(){
msgQueue.sendMessage( StaticMessages.GET_PEERS_MESSAGE );
}
private void sendPeers() { private void sendPeers() {
Set<PeerData> peers = WorldManager.getInstance().getPeerDiscovery().getPeers(); Set<PeerData> peers = WorldManager.getInstance().getPeerDiscovery().getPeers();
PeersMessage msg = new PeersMessage(peers); PeersMessage msg = new PeersMessage(peers);

View File

@ -38,7 +38,10 @@ public class WorkerThread implements Runnable {
try { try {
clientPeer = new PeerClient(true); clientPeer = new PeerClient(true);
clientPeer.connect(peer.getAddress().getHostAddress(), peer.getPort()); clientPeer.connect(peer.getAddress().getHostAddress(), peer.getPort());
peer.setOnline(true); peer.setOnline(true);
logger.info("Peer is online: [{}] ", peer
.getAddress().getHostAddress());
} catch (Throwable e) { } catch (Throwable e) {
if (peer.isOnline()) if (peer.isOnline())
logger.info("Peer: [{}] went offline, due to: [{}]", peer logger.info("Peer: [{}] went offline, due to: [{}]", peer

View File

@ -5,8 +5,8 @@ server.acceptConnections = false
# List of the peers to start # List of the peers to start
# the search of the online peers # the search of the online peers
# values: [ip:port, ip:port, ip:port ...] # values: [ip:port, ip:port, ip:port ...]
peer.discovery.ip.list = poc-6.ethdev.com:30303,\ peer.discovery.ip.list = poc-7.ethdev.com:30303,\
54.204.10.41:30303 188.25.236.246:30303
# Peer Server Zero (poc-6.ethdev.com) # Peer Server Zero (poc-6.ethdev.com)
peer.active.ip = 188.25.236.246 peer.active.ip = 188.25.236.246
@ -49,7 +49,7 @@ peer.discovery.workers = 10
# connection timeout for trying to # connection timeout for trying to
# connect to a peer [seconds] # connect to a peer [seconds]
peer.connection.timeout = 3 peer.connection.timeout = 10
# the time we wait to the network # the time we wait to the network
# to approve the transaction, the # to approve the transaction, the
@ -72,7 +72,7 @@ samples.dir = samples
# the existing database will be # the existing database will be
# destroyed and all the data will be # destroyed and all the data will be
# downloaded from peers again # downloaded from peers again
database.reset = true database.reset = false
# place to save physical storage files # place to save physical storage files
database.dir = database database.dir = database

View File

@ -95,7 +95,7 @@ public class AdaptiveMessageIdsTest {
@Test @Test
public void test4(){ public void test4(){
P2pHandler p2pHandler = new P2pHandler(); P2pHandler p2pHandler = new P2pHandler(null);
List<Capability> capabilities = Arrays.asList( List<Capability> capabilities = Arrays.asList(
new Capability(Capability.ETH, EthHandler.VERSION), new Capability(Capability.ETH, EthHandler.VERSION),
@ -122,7 +122,7 @@ public class AdaptiveMessageIdsTest {
@Test // Capabilities should be read in alphabetical order @Test // Capabilities should be read in alphabetical order
public void test5(){ public void test5(){
P2pHandler p2pHandler = new P2pHandler(); P2pHandler p2pHandler = new P2pHandler(null);
List<Capability> capabilities = Arrays.asList( List<Capability> capabilities = Arrays.asList(
new Capability(Capability.SHH, ShhHandler.VERSION), new Capability(Capability.SHH, ShhHandler.VERSION),

View File

@ -421,7 +421,6 @@ class ContractCallDialog extends JDialog implements MessageAwareDialog {
logger.info("tx.data: {}", Hex.toHexString(data)); logger.info("tx.data: {}", Hex.toHexString(data));
} }
Transaction tx = UIEthereumManager.ethereum.createTransaction(account.getNonce(), Transaction tx = UIEthereumManager.ethereum.createTransaction(account.getNonce(),
gasPrice, gasBI, gasPrice, gasBI,
contractAddress, endowment, data); contractAddress, endowment, data);

View File

@ -285,6 +285,8 @@ class ContractSubmitDialog extends JDialog implements MessageAwareDialog {
byte[] zeroAddress = null; byte[] zeroAddress = null;
// UIEthereumManager.ethereum.createTransaction();
Transaction tx = new Transaction(nonce, gasPrice, gasValue, Transaction tx = new Transaction(nonce, gasPrice, gasValue,
zeroAddress, endowment, initByteCode); zeroAddress, endowment, initByteCode);

View File

@ -5,13 +5,14 @@ server.acceptConnections = false
# List of the peers to start # List of the peers to start
# the search of the online peers # the search of the online peers
# values: [ip:port, ip:port, ip:port ...] # values: [ip:port, ip:port, ip:port ...]
peer.discovery.ip.list = poc-6.ethdev.com:30303,\ peer.discovery.ip.list = poc-7.ethdev.com:30303,\
54.204.10.41:30303 54.204.10.41:30303
# Peer Server Zero (poc-6.ethdev.com) # Peer Server Zero (poc-6.ethdev.com)
peer.active.ip = 185.43.109.23 peer.active.ip = 185.43.109.23
peer.active.port = 30303 peer.active.port = 30303
# ZeroGox # ZeroGox
#peer.active.ip = 54.204.10.41 #peer.active.ip = 54.204.10.41
#peer.active.port = 30303 #peer.active.port = 30303
@ -43,7 +44,7 @@ protocol.version = 33
# the peer window will show # the peer window will show
# only what retrieved by active # only what retrieved by active
# peer [true/false] # peer [true/false]
peer.discovery = false peer.discovery = true
# number of workers that # number of workers that
# tastes the peers for being # tastes the peers for being
@ -52,7 +53,7 @@ peer.discovery.workers = 10
# connection timeout for trying to # connection timeout for trying to
# connect to a peer [seconds] # connect to a peer [seconds]
peer.connection.timeout = 3 peer.connection.timeout = 10
# the time we wait to the network # the time we wait to the network
# to approve the transaction, the # to approve the transaction, the