Cleanup and put back javadoc after move
This commit is contained in:
parent
e556a04d14
commit
83ea504448
|
@ -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<String> DEFAULT_PROTOCOL_LIST = new ArrayList<>();
|
||||
static { DEFAULT_PROTOCOL_LIST.add("eth"); DEFAULT_PROTOCOL_LIST.add("shh"); }
|
||||
private static List<String> DEFAULT_PROTOCOL_LIST = Arrays.asList("eth", "shh");
|
||||
|
||||
public static SystemProperties CONFIG = new SystemProperties();
|
||||
private Properties prop = new Properties();
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -38,8 +38,10 @@ import static org.ethereum.net.message.StaticMessages.GET_TRANSACTIONS_MESSAGE;
|
|||
*/
|
||||
public class EthHandler extends SimpleChannelInboundHandler<EthMessage> {
|
||||
|
||||
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<EthMessage> {
|
|||
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<EthMessage> {
|
|||
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<EthMessage> {
|
|||
|
||||
// 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<EthMessage> {
|
|||
|
||||
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<EthMessage> {
|
|||
}
|
||||
|
||||
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<EthMessage> {
|
|||
|
||||
private enum SyncSatus{
|
||||
INIT,
|
||||
HASH_RETREIVING,
|
||||
BLOCK_RETREIVING,
|
||||
HASH_RETRIEVING,
|
||||
BLOCK_RETRIEVING,
|
||||
SYNC_DONE;
|
||||
}
|
||||
}
|
|
@ -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, ... ], ... ] <br/>
|
||||
/** [+0x02, [nonce, receiving_address, value, ...], ...] <br/>
|
||||
* 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 ]: <br/>
|
||||
/** [+0x03, [hash : B_32, maxBlocks: P]: <br/>
|
||||
* 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, .... ]: <br/>Gives a series of hashes
|
||||
/** [+0x04, [hash_0: B_32, hash_1: B_32, ....]: <br/>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, .... ]: <br/>Requests a Blocks message
|
||||
/** [+0x05, [hash_0: B_32, hash_1: B_32, ....]: <br/>Requests a Blocks message
|
||||
* detailing a number of blocks to be sent, each referred to by a hash. <br/>
|
||||
* <b>Note:</b> 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], ... ] <br/>
|
||||
/** [+0x06, [block_header, transaction_list, uncle_list], ...] <br/>
|
||||
* 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] <br/>
|
||||
* 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),
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<String> capabilities = Arrays.asList("eth", "shh");
|
||||
int listenPort = 30303;
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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() ),
|
||||
|
|
|
@ -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;
|
|||
* <li>PEERS : Send a list of known peers</li>
|
||||
* <li>PING : Check if another peer is still alive</li>
|
||||
* <li>PONG : Confirm that they themselves are still alive</li>
|
||||
* <li>USER : Announce data about the peer </>
|
||||
* </ul>
|
||||
*/
|
||||
public class P2pHandler extends SimpleChannelInboundHandler<P2pMessage> {
|
||||
|
||||
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<P2pMessage> {
|
|||
|
||||
|
||||
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 {
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -104,7 +104,6 @@ public class UserMessage extends P2pMessage {
|
|||
return P2pMessageCodes.USER;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (!parsed) parse();
|
||||
|
|
|
@ -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<ShhMessage> {
|
||||
|
||||
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<ShhMessage> {
|
|||
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<ShhMessage> {
|
|||
logger.debug("handlerRemoved: ... ");
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -22,10 +22,6 @@ public class MessageEncoder extends MessageToByteEncoder<Message> {
|
|||
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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue