minor fixes:

+ studio console back to work
+ onRecvMsg/onSendMsg listener fixed
This commit is contained in:
romanman 2014-11-04 16:42:22 -05:00
parent 555cbb8bbe
commit 31037d2bcd
9 changed files with 69 additions and 6 deletions

View File

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

View File

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

View File

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

View File

@ -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<EthMessage> {
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<EthMessage> {
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<EthMessage> {
this.peerId = peerId;
}
public void setPeerListener(PeerListener peerListener) {
this.peerListener = peerListener;
}
public enum SyncSatus{
INIT,
HASH_RETRIEVING,

View File

@ -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<P2pMessage> {
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<P2pMessage> {
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<P2pMessage> {
}
public void setPeerListener(PeerListener peerListener) {
this.peerListener = peerListener;
}
}

View File

@ -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<ShhMessage> {
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<ShhMessage> {
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<ShhMessage> {
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;
}
}

View File

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

View File

@ -71,7 +71,7 @@
<dependency>
<groupId>org.ethereum</groupId>
<artifactId>ethereumj</artifactId>
<version>0.7.8.20141103.1355</version>
<version>0.7.8.20141104.1640</version>
</dependency>

View File

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