From 31037d2bcd240c56d1e375b13ba50d01ec3a0fb5 Mon Sep 17 00:00:00 2001 From: romanman Date: Tue, 4 Nov 2014 16:42:22 -0500 Subject: [PATCH] minor fixes: + studio console back to work + onRecvMsg/onSendMsg listener fixed --- .../java/org/ethereum/facade/EthereumImpl.java | 6 +++++- .../java/org/ethereum/net/MessageQueue.java | 5 +++++ .../org/ethereum/net/client/PeerClient.java | 17 +++++++++++++++++ .../java/org/ethereum/net/eth/EthHandler.java | 11 +++++++++++ .../java/org/ethereum/net/p2p/P2pHandler.java | 12 ++++++++++-- .../java/org/ethereum/net/shh/ShhHandler.java | 13 +++++++++++++ .../org/ethereum/net/wire/MessageDecoder.java | 5 +++++ ethereumj-studio/pom.xml | 2 +- .../src/main/resources/system.properties | 4 ++-- 9 files changed, 69 insertions(+), 6 deletions(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/facade/EthereumImpl.java b/ethereumj-core/src/main/java/org/ethereum/facade/EthereumImpl.java index 545b77ac..a7bba10c 100644 --- a/ethereumj-core/src/main/java/org/ethereum/facade/EthereumImpl.java +++ b/ethereumj-core/src/main/java/org/ethereum/facade/EthereumImpl.java @@ -113,8 +113,12 @@ public class EthereumImpl implements Ethereum { @Override public void connect(String ip, int port) { logger.info("Connecting to: {}:{}", ip, port); - PeerClient peerClient = new PeerClient(); + + PeerClient peerClient = WorldManager.getInstance().getActivePeer(); + if (peerClient == null) + peerClient = new PeerClient(); WorldManager.getInstance().setActivePeer(peerClient); + peerClient.connect(ip, port); } diff --git a/ethereumj-core/src/main/java/org/ethereum/net/MessageQueue.java b/ethereumj-core/src/main/java/org/ethereum/net/MessageQueue.java index 8e9bcc16..f440f8e3 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/MessageQueue.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/MessageQueue.java @@ -2,6 +2,8 @@ package org.ethereum.net; import io.netty.channel.ChannelHandlerContext; +import org.ethereum.listener.EthereumListener; +import org.ethereum.manager.WorldManager; import org.ethereum.net.message.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -87,6 +89,9 @@ public class MessageQueue { Message msg = messageRoundtrip.getMsg(); + EthereumListener listener = WorldManager.getInstance().getListener(); + if (listener != null) listener.onSendMessage(msg); + ctx.writeAndFlush(msg); if (msg.getAnswerMessage() == null) diff --git a/ethereumj-core/src/main/java/org/ethereum/net/client/PeerClient.java b/ethereumj-core/src/main/java/org/ethereum/net/client/PeerClient.java index 5e97258e..f3233672 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/client/PeerClient.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/client/PeerClient.java @@ -125,12 +125,29 @@ public class PeerClient { public void setPeerListener(PeerListener peerListener) { this.peerListener = peerListener; + + if (p2pHandler != null) + p2pHandler.setPeerListener(peerListener); + + if (ethHandler != null) + ethHandler.setPeerListener(peerListener); + + if (shhHandler != null) + shhHandler.setPeerListener(peerListener); } public P2pHandler getP2pHandler() { return p2pHandler; } + public EthHandler getEthHandler() { + return ethHandler; + } + + public ShhHandler getShhHandler() { + return shhHandler; + } + public boolean isSyncDone(){ return ethHandler.isActive() && ethHandler.getSyncStatus() == EthHandler.SyncSatus.SYNC_DONE; diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/EthHandler.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/EthHandler.java index b1b290cd..2aa4c27f 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/EthHandler.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/EthHandler.java @@ -5,6 +5,7 @@ import io.netty.channel.SimpleChannelInboundHandler; import org.ethereum.core.Block; import org.ethereum.core.Transaction; import org.ethereum.facade.Blockchain; +import org.ethereum.listener.EthereumListener; import org.ethereum.manager.WorldManager; import org.ethereum.net.BlockQueue; import org.ethereum.net.MessageQueue; @@ -67,6 +68,9 @@ public class EthHandler extends SimpleChannelInboundHandler { public void activate(){ logger.info("ETH protocol activated"); + if (peerListener != null) + peerListener.console("ETH protocol activated"); + active = true; sendStatus(); } @@ -83,6 +87,9 @@ public class EthHandler extends SimpleChannelInboundHandler { if (EthMessageCodes.inRange(msg.getCommand().asByte())) logger.info("EthHandler invoke: [{}]", msg.getCommand()); + if (peerListener != null) + peerListener.console(String.format("EthHandler invoke: [%s]", msg.getCommand())); + switch (msg.getCommand()) { case STATUS: msgQueue.receivedMessage(msg); @@ -427,6 +434,10 @@ public class EthHandler extends SimpleChannelInboundHandler { this.peerId = peerId; } + public void setPeerListener(PeerListener peerListener) { + this.peerListener = peerListener; + } + public enum SyncSatus{ INIT, HASH_RETRIEVING, diff --git a/ethereumj-core/src/main/java/org/ethereum/net/p2p/P2pHandler.java b/ethereumj-core/src/main/java/org/ethereum/net/p2p/P2pHandler.java index 5041f1be..1757b7fd 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/p2p/P2pHandler.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/p2p/P2pHandler.java @@ -12,6 +12,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import org.ethereum.core.Transaction; +import org.ethereum.listener.EthereumListener; import org.ethereum.manager.WorldManager; import org.ethereum.net.MessageQueue; import org.ethereum.net.PeerListener; @@ -77,6 +78,9 @@ public class P2pHandler extends SimpleChannelInboundHandler { public void activate(){ logger.info("P2P protocol activated"); + if (peerListener != null) + peerListener.console("P2P protocol activated"); + active = true; } @@ -92,6 +96,9 @@ public class P2pHandler extends SimpleChannelInboundHandler { if (P2pMessageCodes.inRange(msg.getCommand().asByte())) logger.info("P2PHandler invoke: [{}]", msg.getCommand()); + if (peerListener != null) + peerListener.console(String.format( "P2PHandler invoke: [%s]", msg.getCommand())); + switch (msg.getCommand()) { case HELLO: msgQueue.receivedMessage(msg); @@ -275,6 +282,7 @@ public class P2pHandler extends SimpleChannelInboundHandler { } - - + public void setPeerListener(PeerListener peerListener) { + this.peerListener = peerListener; + } } \ No newline at end of file diff --git a/ethereumj-core/src/main/java/org/ethereum/net/shh/ShhHandler.java b/ethereumj-core/src/main/java/org/ethereum/net/shh/ShhHandler.java index a21354a8..c8266723 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/shh/ShhHandler.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/shh/ShhHandler.java @@ -2,6 +2,8 @@ package org.ethereum.net.shh; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; +import org.ethereum.listener.EthereumListener; +import org.ethereum.manager.WorldManager; import org.ethereum.net.MessageQueue; import org.ethereum.net.PeerListener; import org.slf4j.Logger; @@ -22,12 +24,14 @@ public class ShhHandler extends SimpleChannelInboundHandler { private boolean active = false; private final static Logger logger = LoggerFactory.getLogger("net"); + private PeerListener peerListener; public ShhHandler(){ } public ShhHandler(MessageQueue msgQueue, PeerListener peerListener) { this.msgQueue = msgQueue; + this.peerListener = peerListener; } @Override @@ -38,6 +42,9 @@ public class ShhHandler extends SimpleChannelInboundHandler { if (ShhMessageCodes.inRange(msg.getCommand().asByte())) logger.info("ShhHandler invoke: [{}]", msg.getCommand()); + if (peerListener != null) + peerListener.console(String.format( "ShhHandler invoke: [%s]", msg.getCommand())); + switch (msg.getCommand()) { case STATUS: break; @@ -69,10 +76,16 @@ public class ShhHandler extends SimpleChannelInboundHandler { public void activate(){ logger.info("SHH protocol activated"); + if (peerListener != null) + peerListener.console("SHH protocol activated"); this.active = true; } public boolean isActive() { return active; } + + public void setPeerListener(PeerListener peerListener) { + this.peerListener = peerListener; + } } \ No newline at end of file diff --git a/ethereumj-core/src/main/java/org/ethereum/net/wire/MessageDecoder.java b/ethereumj-core/src/main/java/org/ethereum/net/wire/MessageDecoder.java index b4532735..94992ee6 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/wire/MessageDecoder.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/wire/MessageDecoder.java @@ -4,6 +4,8 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ByteToMessageDecoder; +import org.ethereum.listener.EthereumListener; +import org.ethereum.manager.WorldManager; import org.ethereum.net.message.Message; import org.ethereum.net.message.MessageFactory; import org.slf4j.Logger; @@ -38,6 +40,9 @@ public class MessageDecoder extends ByteToMessageDecoder { if (loggerNet.isInfoEnabled()) loggerNet.info("From: \t{} \tRecv: \t{}", ctx.channel().remoteAddress(), msg); + EthereumListener listener = WorldManager.getInstance().getListener(); + if (listener != null) listener.onRecvMessage(msg); + out.add(msg); in.markReaderIndex(); } diff --git a/ethereumj-studio/pom.xml b/ethereumj-studio/pom.xml index 2c98af46..0276d358 100644 --- a/ethereumj-studio/pom.xml +++ b/ethereumj-studio/pom.xml @@ -71,7 +71,7 @@ org.ethereum ethereumj - 0.7.8.20141103.1355 + 0.7.8.20141104.1640 diff --git a/ethereumj-studio/src/main/resources/system.properties b/ethereumj-studio/src/main/resources/system.properties index c81f5ea9..68f54982 100644 --- a/ethereumj-studio/src/main/resources/system.properties +++ b/ethereumj-studio/src/main/resources/system.properties @@ -9,8 +9,8 @@ peer.discovery.ip.list = poc-7.ethdev.com:30303,\ 185.43.109.23:30303 # Peer Server Zero (poc-7.ethdev.com) -peer.active.ip = 127.0.0.1 -peer.active.port = 10101 +peer.active.ip = 23.22.211.45 +peer.active.port = 11111 # ZeroGox