From 83ea504448497c6cae0749cccf4b4db48314fd94 Mon Sep 17 00:00:00 2001 From: nicksavers Date: Sat, 18 Oct 2014 09:51:51 +0200 Subject: [PATCH] Cleanup and put back javadoc after move --- .../org/ethereum/config/SystemProperties.java | 7 ++--- .../org/ethereum/net/client/PeerClient.java | 3 -- .../ethereum/net/eth/BlockHashesMessage.java | 1 + .../org/ethereum/net/eth/BlocksMessage.java | 3 +- .../java/org/ethereum/net/eth/EthHandler.java | 22 +++++++------- .../org/ethereum/net/eth/EthMessageCodes.java | 18 ++++++----- .../net/eth/GetBlockHashesMessage.java | 4 +-- .../ethereum/net/eth/GetBlocksMessage.java | 4 +-- .../net/eth/GetTransactionsMessage.java | 5 ++-- .../org/ethereum/net/eth/NewBlockMessage.java | 9 ++++-- .../org/ethereum/net/eth/StatusMessage.java | 4 +-- .../ethereum/net/eth/TransactionsMessage.java | 3 +- .../org/ethereum/net/message/Message.java | 4 --- .../ethereum/net/message/StaticMessages.java | 3 +- .../ethereum/net/p2p/DisconnectMessage.java | 3 +- .../org/ethereum/net/p2p/GetPeersMessage.java | 2 ++ .../org/ethereum/net/p2p/HelloMessage.java | 7 +++-- .../java/org/ethereum/net/p2p/P2pHandler.java | 14 +++------ .../org/ethereum/net/p2p/PeersMessage.java | 6 ++-- .../org/ethereum/net/p2p/PingMessage.java | 3 +- .../org/ethereum/net/p2p/PongMessage.java | 3 +- .../org/ethereum/net/p2p/UserMessage.java | 1 - .../java/org/ethereum/net/shh/ShhHandler.java | 9 ++---- .../org/ethereum/net/wire/MessageDecoder.java | 4 --- .../org/ethereum/net/wire/MessageEncoder.java | 4 --- .../org/ethereum/net/NewBlockMessageTest.java | 30 +++++-------------- .../src/main/resources/log4j.properties | 1 + 27 files changed, 75 insertions(+), 102 deletions(-) diff --git a/ethereumj-core/src/main/java/org/ethereum/config/SystemProperties.java b/ethereumj-core/src/main/java/org/ethereum/config/SystemProperties.java index f0e47e0c..dfb921e4 100644 --- a/ethereumj-core/src/main/java/org/ethereum/config/SystemProperties.java +++ b/ethereumj-core/src/main/java/org/ethereum/config/SystemProperties.java @@ -20,8 +20,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 = "poc-6.ethdev.com:30303"; - private static String DEFAULT_ACTIVE_PEER_IP = "poc-6.ethdev.com"; + private static String DEFAULT_DISCOVERY_PEER_LIST = "poc-7.ethdev.com:30303"; + private static String DEFAULT_ACTIVE_PEER_IP = "poc-7.ethdev.com"; private static int DEFAULT_ACTIVE_PORT = 30303; private static String DEFAULT_SAMPLES_DIR = "samples"; private static String DEFAULT_COINBASE_SECRET = "monkey"; @@ -42,8 +42,7 @@ public class SystemProperties { private static String DEFAULT_PROJECT_VERSION = ""; private static String DEFAULT_HELLO_PHRASE = "Dev"; - private static List DEFAULT_PROTOCOL_LIST = new ArrayList<>(); - static { DEFAULT_PROTOCOL_LIST.add("eth"); DEFAULT_PROTOCOL_LIST.add("shh"); } + private static List DEFAULT_PROTOCOL_LIST = Arrays.asList("eth", "shh"); public static SystemProperties CONFIG = new SystemProperties(); private Properties prop = new Properties(); 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 f2b080ee..268a9e66 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 @@ -7,7 +7,6 @@ import io.netty.channel.socket.nio.NioSocketChannel; import io.netty.handler.timeout.ReadTimeoutHandler; import org.ethereum.manager.WorldManager; -import org.ethereum.net.MessageQueue; import org.ethereum.net.PeerListener; import org.ethereum.net.wire.MessageDecoder; import org.ethereum.net.wire.MessageEncoder; @@ -32,8 +31,6 @@ public class PeerClient { private PeerListener peerListener; private P2pHandler p2pHandler; - private MessageQueue queue; - private boolean peerDiscoveryMode = false; public PeerClient() { diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/BlockHashesMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/BlockHashesMessage.java index 85f1013f..a817272b 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/BlockHashesMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/BlockHashesMessage.java @@ -14,6 +14,7 @@ import org.ethereum.util.Utils; /** * Wrapper around an Ethereum BlockHashes message on the network * + * @see {@link org.ethereum.net.eth.EthMessageCodes#BLOCK_HASHES} */ public class BlockHashesMessage extends EthMessage { diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/BlocksMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/BlocksMessage.java index 2369ce9a..56126730 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/BlocksMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/BlocksMessage.java @@ -3,8 +3,6 @@ package org.ethereum.net.eth; import java.util.ArrayList; import java.util.List; -import static org.ethereum.net.eth.EthMessageCodes.BLOCK_HASHES; - import org.ethereum.core.Block; import org.ethereum.net.eth.EthMessage; import org.ethereum.util.RLP; @@ -13,6 +11,7 @@ import org.ethereum.util.RLPList; /** * Wrapper around an Ethereum Blocks message on the network * + * @see {@link org.ethereum.net.eth.EthMessageCodes#BLOCKS} */ public class BlocksMessage extends EthMessage { 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 fa9029bd..b2a75850 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 @@ -38,8 +38,10 @@ import static org.ethereum.net.message.StaticMessages.GET_TRANSACTIONS_MESSAGE; */ public class EthHandler extends SimpleChannelInboundHandler { + public final static byte VERSION = 0x23; + public final static byte NETWORK_ID = 0x0; + private final static Logger logger = LoggerFactory.getLogger("net"); - public static byte version = 0x23; private String peerId; private PeerListener peerListener; @@ -151,11 +153,11 @@ public class EthHandler extends SimpleChannelInboundHandler { Blockchain blockchain = WorldManager.getInstance().getBlockchain(); if (!Arrays.equals(msg.getGenesisHash(), Blockchain.GENESIS_HASH) - || msg.getProtocolVersion() != EthHandler.version) { + || msg.getProtocolVersion() != EthHandler.VERSION) { logger.info("Removing EthHandler for {} due to protocol incompatibility", ctx.channel().remoteAddress()); // msgQueue.sendMessage(new DisconnectMessage(ReasonCode.INCOMPATIBLE_NETWORK)); ctx.pipeline().remove(this); // Peer is not compatible for the 'eth' sub-protocol - } else if (msg.getNetworkId() != 0) + } else if (msg.getNetworkId() != EthHandler.NETWORK_ID) msgQueue.sendMessage(new DisconnectMessage(ReasonCode.INCOMPATIBLE_NETWORK)); else { BlockQueue chainQueue = blockchain.getQueue(); @@ -166,7 +168,7 @@ public class EthHandler extends SimpleChannelInboundHandler { hashRetrievalLock = this.peerId; chainQueue.setHighestTotalDifficulty(peerTotalDifficulty); chainQueue.setBestHash(msg.getBestHash()); - syncStatus = SyncSatus.HASH_RETREIVING; + syncStatus = SyncSatus.HASH_RETRIEVING; sendGetBlockHashes(); } else startGetBlockTimer(); @@ -236,14 +238,14 @@ public class EthHandler extends SimpleChannelInboundHandler { // If the hashes still being downloaded ignore the NEW_BLOCKs // that block hash will be retrieved by the others and letter the block itself - if (syncStatus == SyncSatus.INIT || syncStatus == SyncSatus.HASH_RETREIVING) { + if (syncStatus == SyncSatus.INIT || syncStatus == SyncSatus.HASH_RETRIEVING) { logger.debug("Sync status INIT or HASH_RETREIVING ignore new block.index: [{}]", newBlock.getNumber()); return; } // If the GET_BLOCKs stage started add hash to the end of the hash list // then the block will be retrieved in it's turn; - if (syncStatus == SyncSatus.BLOCK_RETREIVING){ + if (syncStatus == SyncSatus.BLOCK_RETRIEVING){ logger.debug("Sync status BLOCK_RETREIVING add to the end of hash list: block.index: [{}]", newBlock.getNumber()); blockchain.getQueue().addNewBlockHash(newBlockMessage.getBlock().getHash()); return; @@ -257,7 +259,7 @@ public class EthHandler extends SimpleChannelInboundHandler { private void sendStatus(){ Blockchain blockChain= WorldManager.getInstance().getBlockchain(); - byte protocolVersion = EthHandler.version, networkId = 0; + byte protocolVersion = EthHandler.VERSION, networkId = EthHandler.NETWORK_ID; BigInteger totalDifficulty = blockChain.getTotalDifficulty(); byte[] bestHash = blockChain.getLatestBlockHash(); StatusMessage msg = new StatusMessage(protocolVersion, networkId, @@ -327,7 +329,7 @@ public class EthHandler extends SimpleChannelInboundHandler { } public void startGetBlockTimer() { - syncStatus = SyncSatus.BLOCK_RETREIVING; + syncStatus = SyncSatus.BLOCK_RETRIEVING; getBlocksTimer.scheduleAtFixedRate(new TimerTask() { public void run() { BlockQueue blockQueue = WorldManager.getInstance().getBlockchain().getQueue(); @@ -358,8 +360,8 @@ public class EthHandler extends SimpleChannelInboundHandler { private enum SyncSatus{ INIT, - HASH_RETREIVING, - BLOCK_RETREIVING, + HASH_RETRIEVING, + BLOCK_RETRIEVING, SYNC_DONE; } } \ No newline at end of file diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/EthMessageCodes.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/EthMessageCodes.java index 56822cbc..3eab0fb2 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/EthMessageCodes.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/EthMessageCodes.java @@ -22,43 +22,45 @@ public enum EthMessageCodes { /* Ethereum */ - /** [+0x01] * Request the peer to send all transactions + /** [+0x01] Request the peer to send all transactions * currently in the queue. */ GET_TRANSACTIONS(0x01), - /** [+0x02, [nonce, receiving_address, value, ... ], ... ]
+ /** [+0x02, [nonce, receiving_address, value, ...], ...]
* Specify (a) transaction(s) that the peer should make sure is included * on its transaction queue. The items in the list (following the first item 0x12) * are transactions in the format described in the main Ethereum specification. */ TRANSACTIONS(0x02), - /** [+0x03, [ hash : B_32, maxBlocks: P ]:
+ /** [+0x03, [hash : B_32, maxBlocks: P]:
* Requests a BlockHashes message of at most maxBlocks entries, * of block hashes from the blockchain, starting at the parent of block hash. * Does not require the peer to give maxBlocks hashes - * they could give somewhat fewer. */ GET_BLOCK_HASHES(0x03), - /** [+0x04, [ hash_0: B_32, hash_1: B_32, .... ]:
Gives a series of hashes + /** [+0x04, [hash_0: B_32, hash_1: B_32, ....]:
Gives a series of hashes * of blocks (each the child of the next). This implies that the blocks * are ordered from youngest to oldest. */ BLOCK_HASHES(0x04), - /** [+0x05, [ hash_0: B_32, hash_1: B_32, .... ]:
Requests a Blocks message + /** [+0x05, [hash_0: B_32, hash_1: B_32, ....]:
Requests a Blocks message * detailing a number of blocks to be sent, each referred to by a hash.
* Note: Don't expect that the peer necessarily give you all these blocks * in a single message - you might have to re-request them. */ GET_BLOCKS(0x05), - /** [+0x06, [block_header, transaction_list, uncle_list], ... ]
+ /** [+0x06, [block_header, transaction_list, uncle_list], ...]
* Specify (a) block(s) that the peer should know about. * The items in the list (following the first item, 0x13) * are blocks in the format described in the main Ethereum specification. */ BLOCKS(0x06), /** - * [+0x07 - */ + * [+0x07 [blockHeader, transactionList, uncleList], totalDifficulty]
+ * Specify a single block that the peer should know about. The composite item + * in the list (following the message ID) is a block in the format described + * in the main Ethereum specification. */ NEW_BLOCK(0x07), /** diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/GetBlockHashesMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/GetBlockHashesMessage.java index 8f61a5b4..7a1240ea 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/GetBlockHashesMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/GetBlockHashesMessage.java @@ -4,13 +4,13 @@ import static org.ethereum.net.eth.EthMessageCodes.GET_BLOCK_HASHES; import org.ethereum.util.ByteUtil; import org.ethereum.util.RLP; -import org.ethereum.util.RLPItem; import org.ethereum.util.RLPList; import org.spongycastle.util.encoders.Hex; /** * Wrapper around an Ethereum GetBlockHashes message on the network - * + * + * @see {@link org.ethereum.net.eth.EthMessageCodes#GET_BLOCK_HASHES} */ public class GetBlockHashesMessage extends EthMessage { diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/GetBlocksMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/GetBlocksMessage.java index 6576219f..53439a73 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/GetBlocksMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/GetBlocksMessage.java @@ -1,6 +1,5 @@ package org.ethereum.net.eth; - import java.util.ArrayList; import java.util.List; @@ -13,7 +12,8 @@ import static org.ethereum.net.eth.EthMessageCodes.GET_BLOCKS; /** * Wrapper around an Ethereum GetBlocks message on the network - * + * + * @see {@link org.ethereum.net.eth.EthMessageCodes#GET_BLOCKS} */ public class GetBlocksMessage extends EthMessage { diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/GetTransactionsMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/GetTransactionsMessage.java index 3d777671..3aa941c7 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/GetTransactionsMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/GetTransactionsMessage.java @@ -5,8 +5,9 @@ import org.ethereum.net.eth.TransactionsMessage; import org.spongycastle.util.encoders.Hex; /** - * Wrapper around an Ethereum GetTransactions message on the network - * + * Wrapper around an Ethereum GetTransactions message on the network + * + * @see {@link org.ethereum.net.eth.EthMessageCodes#GET_TRANSACTIONS} * */ public class GetTransactionsMessage extends EthMessage { diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/NewBlockMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/NewBlockMessage.java index b27337e1..838c200e 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/NewBlockMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/NewBlockMessage.java @@ -1,13 +1,13 @@ package org.ethereum.net.eth; import org.ethereum.core.Block; -import org.ethereum.core.BlockHeader; import org.ethereum.util.RLP; -import org.ethereum.util.RLPItem; import org.ethereum.util.RLPList; /** * Wrapper around an Ethereum Blocks message on the network + * + * @see {@link org.ethereum.net.eth.EthMessageCodes#NEW_BLOCK} */ public class NewBlockMessage extends EthMessage { @@ -32,6 +32,11 @@ public class NewBlockMessage extends EthMessage { if (!parsed) parse(); return block; } + + public byte[] getDifficulty(){ + if (!parsed) parse(); + return difficulty; + } @Override public byte[] getEncoded() { diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/StatusMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/StatusMessage.java index e96c413c..11142bdc 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/StatusMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/StatusMessage.java @@ -8,10 +8,10 @@ import org.spongycastle.util.encoders.Hex; import static org.ethereum.net.eth.EthMessageCodes.STATUS; - /** * Wrapper around an Ethereum Status message on the network - * + * + * @see {@link org.ethereum.net.eth.EthMessageCodes#STATUS} */ public class StatusMessage extends EthMessage { diff --git a/ethereumj-core/src/main/java/org/ethereum/net/eth/TransactionsMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/eth/TransactionsMessage.java index c226da7a..46021b3c 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/eth/TransactionsMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/eth/TransactionsMessage.java @@ -14,7 +14,8 @@ import java.util.Set; /** * Wrapper around an Ethereum Transactions message on the network - * + * + * @see {@link org.ethereum.net.eth.EthMessageCodes#TRANSACTIONS} */ public class TransactionsMessage extends EthMessage { diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/Message.java b/ethereumj-core/src/main/java/org/ethereum/net/message/Message.java index ec63c122..8d649a38 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/message/Message.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/Message.java @@ -1,8 +1,5 @@ package org.ethereum.net.message; -import org.ethereum.util.RLPItem; -import org.ethereum.util.RLPList; - /** * Abstract message class for all messages on the Ethereum network * @@ -21,7 +18,6 @@ public abstract class Message { this.encoded = encoded; parsed = false; } - /** * Gets the RLP encoded byte array of this message diff --git a/ethereumj-core/src/main/java/org/ethereum/net/message/StaticMessages.java b/ethereumj-core/src/main/java/org/ethereum/net/message/StaticMessages.java index 1bb3b019..3299a159 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/message/StaticMessages.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/message/StaticMessages.java @@ -8,6 +8,7 @@ import org.ethereum.crypto.HashUtil; import org.ethereum.net.eth.GetTransactionsMessage; import org.ethereum.net.p2p.GetPeersMessage; import org.ethereum.net.p2p.HelloMessage; +import org.ethereum.net.p2p.P2pHandler; import org.ethereum.net.p2p.PingMessage; import org.ethereum.net.p2p.PongMessage; import org.spongycastle.util.encoders.Hex; @@ -33,7 +34,7 @@ public class StaticMessages { private static HelloMessage generateHelloMessage() { String helloAnnouncement = buildHelloAnnouncement(); - byte p2pVersion = 0x02; + byte p2pVersion = P2pHandler.VERSION; List capabilities = Arrays.asList("eth", "shh"); int listenPort = 30303; diff --git a/ethereumj-core/src/main/java/org/ethereum/net/p2p/DisconnectMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/p2p/DisconnectMessage.java index fb153023..dfbab058 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/p2p/DisconnectMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/p2p/DisconnectMessage.java @@ -11,7 +11,8 @@ import static org.ethereum.net.message.ReasonCode.REQUESTED; /** * Wrapper around an Ethereum Disconnect message on the network - * + * + * @see {@link org.ethereum.net.p2p.P2pMessageCodes#DISCONNECT} */ public class DisconnectMessage extends P2pMessage { diff --git a/ethereumj-core/src/main/java/org/ethereum/net/p2p/GetPeersMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/p2p/GetPeersMessage.java index c2cb8c08..3002cad6 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/p2p/GetPeersMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/p2p/GetPeersMessage.java @@ -4,6 +4,8 @@ import org.spongycastle.util.encoders.Hex; /** * Wrapper around an Ethereum GetPeers message on the network + * + * @see {@link org.ethereum.net.p2p.P2pMessageCodes#GET_PEERS} */ public class GetPeersMessage extends P2pMessage { diff --git a/ethereumj-core/src/main/java/org/ethereum/net/p2p/HelloMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/p2p/HelloMessage.java index ab73f019..919abd35 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/p2p/HelloMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/p2p/HelloMessage.java @@ -16,7 +16,8 @@ import java.util.List; /** * Wrapper around an Ethereum HelloMessage on the network - * + * + * @see {@link org.ethereum.net.p2p.P2pMessageCodes#HELLO} */ public class HelloMessage extends P2pMessage { @@ -84,8 +85,8 @@ public class HelloMessage extends P2pMessage { String capability = this.capabilities.get(i); byte version = 0; - if (capability.equals("eth")) version = EthHandler.version; - if (capability.equals("shh")) version = ShhHandler.version; + if (capability.equals("eth")) version = EthHandler.VERSION; + if (capability.equals("shh")) version = ShhHandler.VERSION; capabilities[i] = RLP.encodeList( RLP.encodeElement( capability.getBytes() ), 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 39ee4df9..8359e0e8 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 @@ -1,12 +1,9 @@ package org.ethereum.net.p2p; -import static org.ethereum.config.SystemProperties.CONFIG; import static org.ethereum.net.message.StaticMessages.PING_MESSAGE; import static org.ethereum.net.message.StaticMessages.PONG_MESSAGE; import static org.ethereum.net.message.StaticMessages.HELLO_MESSAGE; -import static org.ethereum.net.message.StaticMessages.GET_PEERS_MESSAGE; -import java.math.BigInteger; import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.List; @@ -14,22 +11,18 @@ import java.util.Set; import java.util.Timer; import java.util.TimerTask; -import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; -import org.ethereum.facade.Blockchain; import org.ethereum.manager.WorldManager; import org.ethereum.net.MessageQueue; import org.ethereum.net.PeerListener; import org.ethereum.net.eth.EthHandler; import org.ethereum.net.eth.EthMessageCodes; -import org.ethereum.net.eth.StatusMessage; import org.ethereum.net.shh.ShhHandler; import org.ethereum.net.message.*; import org.ethereum.net.peerdiscovery.PeerData; import org.ethereum.net.shh.ShhMessageCodes; -import org.ethereum.util.ByteUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,18 +37,19 @@ import org.slf4j.LoggerFactory; *
  • PEERS : Send a list of known peers
  • *
  • PING : Check if another peer is still alive
  • *
  • PONG : Confirm that they themselves are still alive
  • - *
  • USER : Announce data about the peer * */ public class P2pHandler extends SimpleChannelInboundHandler { + public final static byte VERSION = 0x2; + private final static Logger logger = LoggerFactory.getLogger("net"); private final Timer timer = new Timer("MessageTimer"); private PeerListener peerListener; - private MessageQueue msgQueue = null; + private MessageQueue msgQueue;; private boolean tearDown = false; private boolean peerDiscoveryMode = false; @@ -157,7 +151,7 @@ public class P2pHandler extends SimpleChannelInboundHandler { private void setHandshake(HelloMessage msg, ChannelHandlerContext ctx) { - if (msg.getP2PVersion() != HELLO_MESSAGE.getP2PVersion()) + if (msg.getP2PVersion() != P2pHandler.VERSION) msgQueue.sendMessage(new DisconnectMessage(ReasonCode.INCOMPATIBLE_PROTOCOL)); else { diff --git a/ethereumj-core/src/main/java/org/ethereum/net/p2p/PeersMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/p2p/PeersMessage.java index 38ddbb14..fa2cb1b9 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/p2p/PeersMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/p2p/PeersMessage.java @@ -1,7 +1,5 @@ package org.ethereum.net.p2p; -import static org.ethereum.net.p2p.P2pMessageCodes.PEERS; - import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; @@ -18,7 +16,8 @@ import org.spongycastle.util.encoders.Hex; /** * Wrapper around an Ethereum Peers message on the network - * + * + * @see {@link org.ethereum.net.p2p.P2pMessageCodes#PEERS} */ public class PeersMessage extends P2pMessage { @@ -85,7 +84,6 @@ public class PeersMessage extends P2pMessage { return P2pMessageCodes.PEERS; } - @Override public Class getAnswerMessage() { return null; diff --git a/ethereumj-core/src/main/java/org/ethereum/net/p2p/PingMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/p2p/PingMessage.java index e8347723..6c94a134 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/p2p/PingMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/p2p/PingMessage.java @@ -4,7 +4,8 @@ import org.spongycastle.util.encoders.Hex; /** * Wrapper around an Ethereum Ping message on the network - * + * + * @see {@link org.ethereum.net.p2p.P2pMessageCodes#PING} */ public class PingMessage extends P2pMessage { diff --git a/ethereumj-core/src/main/java/org/ethereum/net/p2p/PongMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/p2p/PongMessage.java index a6306ad6..8ad6a37c 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/p2p/PongMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/p2p/PongMessage.java @@ -5,7 +5,8 @@ import org.spongycastle.util.encoders.Hex; /** * Wrapper around an Ethereum Pong message on the network - * + * + * @see {@link org.ethereum.net.p2p.P2pMessageCodes#PONG} */ public class PongMessage extends P2pMessage { diff --git a/ethereumj-core/src/main/java/org/ethereum/net/p2p/UserMessage.java b/ethereumj-core/src/main/java/org/ethereum/net/p2p/UserMessage.java index 6748ecd4..30a0084d 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/p2p/UserMessage.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/p2p/UserMessage.java @@ -104,7 +104,6 @@ public class UserMessage extends P2pMessage { return P2pMessageCodes.USER; } - @Override public String toString() { if (!parsed) parse(); 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 f41d4ad2..f4f2f21b 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 @@ -3,7 +3,6 @@ package org.ethereum.net.shh; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import org.ethereum.net.PeerListener; -import org.ethereum.net.eth.EthMessageCodes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -16,12 +15,11 @@ import org.slf4j.LoggerFactory; */ public class ShhHandler extends SimpleChannelInboundHandler { + public final static byte VERSION = 0x1; + private final static Logger logger = LoggerFactory.getLogger("net"); - public static byte version = 0x1; - public ShhHandler() { - } public ShhHandler(String peerId, PeerListener peerListener) { @@ -33,7 +31,6 @@ public class ShhHandler extends SimpleChannelInboundHandler { logger.info("SHH protocol activated"); } - @Override public void channelRead0(final ChannelHandlerContext ctx, ShhMessage msg) throws InterruptedException { @@ -68,6 +65,4 @@ public class ShhHandler extends SimpleChannelInboundHandler { logger.debug("handlerRemoved: ... "); } - - } \ 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 f149cc6d..f5b93dbc 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 @@ -35,10 +35,6 @@ public class MessageDecoder extends ByteToMessageDecoder { Message msg = MessageFactory.createMessage(encoded); if (logger.isInfoEnabled()) -// && msg.getCommand() != Command.PING -// && msg.getCommand() != Command.PONG -// && msg.getCommand() != Command.PEERS -// && msg.getCommand() != Command.GET_PEERS) logger.info("From: \t{} \tRecv: \t{}", ctx.channel().remoteAddress(), msg); out.add(msg); diff --git a/ethereumj-core/src/main/java/org/ethereum/net/wire/MessageEncoder.java b/ethereumj-core/src/main/java/org/ethereum/net/wire/MessageEncoder.java index cda9b660..a3c874d8 100644 --- a/ethereumj-core/src/main/java/org/ethereum/net/wire/MessageEncoder.java +++ b/ethereumj-core/src/main/java/org/ethereum/net/wire/MessageEncoder.java @@ -22,10 +22,6 @@ public class MessageEncoder extends MessageToByteEncoder { protected void encode(ChannelHandlerContext ctx, Message msg, ByteBuf out) throws Exception { if (logger.isInfoEnabled()) -// && msg.getCommand() != Command.PING -// && msg.getCommand() != Command.PONG -// && msg.getCommand() != Command.PEERS -// && msg.getCommand() != Command.GET_PEERS) logger.info("To: \t{} \tSend: \t{}", ctx.channel().remoteAddress(), msg); byte[] encoded = msg.getEncoded(); diff --git a/ethereumj-core/src/test/java/org/ethereum/net/NewBlockMessageTest.java b/ethereumj-core/src/test/java/org/ethereum/net/NewBlockMessageTest.java index 40ebe1e8..a141ff64 100644 --- a/ethereumj-core/src/test/java/org/ethereum/net/NewBlockMessageTest.java +++ b/ethereumj-core/src/test/java/org/ethereum/net/NewBlockMessageTest.java @@ -1,38 +1,22 @@ package org.ethereum.net; -import org.ethereum.core.Block; -import org.ethereum.net.eth.BlocksMessage; import org.ethereum.net.eth.NewBlockMessage; -import org.junit.Ignore; import org.junit.Test; import org.spongycastle.util.encoders.Hex; -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.file.Files; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - public class NewBlockMessageTest { /* NEW_BLOCK */ - @Test - public void test_1() { + @Test + public void test_1() { - String blocksRaw = "f8c017f8b7f8b3a0d8faffbc4c4213d35db9007de41cece45d95db7fd6c0f129e158baa888c48eefa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794baedba0480e1b882b606cd302d8c4f5701cabac7a0c7d4565fb7b3d98e54a0dec8b76f8c001a784a5689954ce0aedcc1bbe8d130958083063477825fc88609184e72a0008301e8488084543ffee680a00de0b9d4a0f0c23546d31f1f70db00d25cf6a7af79365b4e058e4a6a3b69527bc0c0850177ddbebe"; + String newBlockRaw = "f8c017f8b7f8b3a0d8faffbc4c4213d35db9007de41cece45d95db7fd6c0f129e158baa888c48eefa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d4934794baedba0480e1b882b606cd302d8c4f5701cabac7a0c7d4565fb7b3d98e54a0dec8b76f8c001a784a5689954ce0aedcc1bbe8d130958083063477825fc88609184e72a0008301e8488084543ffee680a00de0b9d4a0f0c23546d31f1f70db00d25cf6a7af79365b4e058e4a6a3b69527bc0c0850177ddbebe"; - byte[] payload = Hex.decode(blocksRaw); + byte[] payload = Hex.decode(newBlockRaw); - NewBlockMessage newBlockMessage = new NewBlockMessage(payload); - newBlockMessage.toString(); - - - } + NewBlockMessage newBlockMessage = new NewBlockMessage(payload); + newBlockMessage.toString(); + } } - diff --git a/ethereumj-studio/src/main/resources/log4j.properties b/ethereumj-studio/src/main/resources/log4j.properties index cebba2c7..23678e3d 100644 --- a/ethereumj-studio/src/main/resources/log4j.properties +++ b/ethereumj-studio/src/main/resources/log4j.properties @@ -36,6 +36,7 @@ log4j.logger.trie = ERROR log4j.logger.state = INFO log4j.logger.repository = INFO log4j.logger.blockchain = INFO +log4j.logger.blockqueue = ERROR log4j.logger.txs = ERROR log4j.logger.ui = ERROR log4j.logger.gas = ERROR