Move exception logging to PeerClient
This commit is contained in:
parent
2ec44a6166
commit
b26676f211
|
@ -21,8 +21,8 @@ public class SystemProperties {
|
|||
private static Logger logger = LoggerFactory.getLogger(SystemProperties.class);
|
||||
|
||||
private static int DEFAULT_TX_APPROVE_TIMEOUT = 10;
|
||||
private static String DEFAULT_DISCOVERY_PEER_LIST = "54.201.28.117:30303";
|
||||
private static String DEFAULT_ACTIVE_PEER_IP = "54.201.28.117";
|
||||
private static String DEFAULT_DISCOVERY_PEER_LIST = "poc-6.ethdev.com:30303";
|
||||
private static String DEFAULT_ACTIVE_PEER_IP = "poc-6.ethdev.com";
|
||||
private static int DEFAULT_ACTIVE_PORT = 30303;
|
||||
private static String DEFAULT_SAMPLES_DIR = "samples";
|
||||
private static String DEFAULT_COINBASE_SECRET = "monkey";
|
||||
|
|
|
@ -55,7 +55,7 @@ public class MessageQueue {
|
|||
|
||||
if (listener != null)
|
||||
listener.console("[Recv: " + msg + "]");
|
||||
if (logger.isInfoEnabled()
|
||||
if (logger.isInfoEnabled()
|
||||
&& msg.getCommand() != Command.PING
|
||||
&& msg.getCommand() != Command.PONG
|
||||
&& msg.getCommand() != Command.PEERS
|
||||
|
|
|
@ -26,7 +26,6 @@ public class PeerClient {
|
|||
|
||||
private Logger logger = LoggerFactory.getLogger("wire");
|
||||
|
||||
private PeerDiscovery peerDiscovery;
|
||||
private PeerListener peerListener;
|
||||
private ProtocolHandler handler;
|
||||
|
||||
|
@ -37,15 +36,15 @@ public class PeerClient {
|
|||
this.peerListener = peerListener;
|
||||
}
|
||||
|
||||
public void connect(String host, int port) {
|
||||
public void connect(String host, int port) {
|
||||
|
||||
EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||
EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||
|
||||
if (peerListener != null) {
|
||||
peerListener.console("Connecting to: " + host + ":" + port);
|
||||
handler = new ProtocolHandler(peerListener);
|
||||
} else
|
||||
handler = new ProtocolHandler();
|
||||
if (peerListener != null) {
|
||||
peerListener.console("Connecting to: " + host + ":" + port);
|
||||
handler = new ProtocolHandler(peerListener);
|
||||
} else
|
||||
handler = new ProtocolHandler();
|
||||
|
||||
try {
|
||||
Bootstrap b = new Bootstrap();
|
||||
|
@ -74,19 +73,18 @@ public class PeerClient {
|
|||
f.channel().closeFuture().sync();
|
||||
logger.debug("Connection is closed");
|
||||
|
||||
} catch (InterruptedException ie) {
|
||||
logger.error("-- ClientPeer: catch (InterruptedException ie) --", ie);
|
||||
} finally {
|
||||
try {
|
||||
workerGroup.shutdownGracefully().sync();
|
||||
} catch (InterruptedException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.debug("Exception: {} ({})", e.getMessage(), e.getClass().getName());
|
||||
} finally {
|
||||
try {
|
||||
workerGroup.shutdownGracefully().sync();
|
||||
} catch (InterruptedException e) {
|
||||
logger.warn(e.getMessage(), e);
|
||||
}
|
||||
|
||||
handler.killTimers();
|
||||
handler.killTimers();
|
||||
|
||||
final Set<Peer> peers = WorldManager.getInstance()
|
||||
.getPeerDiscovery().getPeers();
|
||||
final Set<Peer> peers = WorldManager.getInstance().getPeerDiscovery().getPeers();
|
||||
|
||||
synchronized (peers) {
|
||||
for (Peer peer : peers) {
|
||||
|
@ -96,14 +94,14 @@ public class PeerClient {
|
|||
}
|
||||
}
|
||||
|
||||
EthereumListener listener = WorldManager.getInstance().getListener();
|
||||
if (listener != null) listener.onPeerDisconnect(host, port);
|
||||
}
|
||||
}
|
||||
EthereumListener listener = WorldManager.getInstance().getListener();
|
||||
if (listener != null) listener.onPeerDisconnect(host, port);
|
||||
}
|
||||
}
|
||||
|
||||
public void setPeerListener(PeerListener peerListener) {
|
||||
this.peerListener = peerListener;
|
||||
}
|
||||
public void setPeerListener(PeerListener peerListener) {
|
||||
this.peerListener = peerListener;
|
||||
}
|
||||
|
||||
public ProtocolHandler getHandler() {
|
||||
return handler;
|
||||
|
|
|
@ -23,7 +23,6 @@ import io.netty.channel.ChannelOption;
|
|||
import io.netty.channel.FixedRecvByteBufAllocator;
|
||||
|
||||
import org.ethereum.core.Block;
|
||||
import org.ethereum.core.BlockQueue;
|
||||
import org.ethereum.core.Transaction;
|
||||
import org.ethereum.facade.Blockchain;
|
||||
import org.ethereum.listener.EthereumListener;
|
||||
|
@ -125,7 +124,7 @@ public class ProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
msgQueue.receivedMessage(statusMessage);
|
||||
|
||||
processStatus(statusMessage);
|
||||
|
||||
|
||||
if (listener != null) listener.onRecvMessage(statusMessage);
|
||||
break;
|
||||
case DISCONNECT:
|
||||
|
@ -220,15 +219,9 @@ public class ProtocolHandler extends ChannelInboundHandlerAdapter {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws InterruptedException {
|
||||
tearDown = true;
|
||||
logger.warn("Lost connection to {}", ctx.channel().remoteAddress());
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
cause.printStackTrace();
|
||||
logger.info("Reason: {} ({})", cause.getMessage(), cause.getClass().getName());
|
||||
logger.debug("Stacktrace", cause);
|
||||
ctx.close().sync();
|
||||
ctx.disconnect().sync();
|
||||
killTimers();
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -35,8 +35,7 @@ public class WorkerThread implements Runnable {
|
|||
|
||||
try {
|
||||
clientPeer = new PeerClient();
|
||||
clientPeer.connect(peer.getAddress().getHostAddress(),
|
||||
peer.getPort());
|
||||
clientPeer.connect(peer.getAddress().getHostAddress(), peer.getPort());
|
||||
|
||||
peer.setOnline(true);
|
||||
peer.setHandshake(clientPeer.getHandler().getHandshake());
|
||||
|
|
Loading…
Reference in New Issue