org.ethereum.net.p2p.P2pMessageCodes Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ethereumj-core Show documentation
Show all versions of ethereumj-core Show documentation
Java implementation of the Ethereum protocol adapted to use for Hedera Smart Contract Service
The newest version!
/*
* Copyright (c) [2016] [ ]
* This file is part of the ethereumJ library.
*
* The ethereumJ library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The ethereumJ library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with the ethereumJ library. If not, see .
*/
package org.ethereum.net.p2p;
import java.util.HashMap;
import java.util.Map;
/**
* A list of commands for the Ethereum network protocol.
*
* The codes for these commands are the first byte in every packet.
* ÐΞV
*
* @see
* https://github.com/ethereum/wiki/wiki/ÐΞVp2p-Wire-Protocol
*/
public enum P2pMessageCodes {
/* P2P protocol */
/**
* [0x00, P2P_VERSION, CLIEND_ID, CAPS, LISTEN_PORT, CLIENT_ID]
* First packet sent over the connection, and sent once by both sides.
* No other messages may be sent until a Hello is received.
*/
HELLO(0x00),
/**
* [0x01, REASON]
Inform the peer that a disconnection is imminent;
* if received, a peer should disconnect immediately. When sending,
* well-behaved hosts give their peers a fighting chance (read: wait 2 seconds)
* to disconnect to before disconnecting themselves.
*/
DISCONNECT(0x01),
/**
* [0x02]
Requests an immediate reply of Pong from the peer.
*/
PING(0x02),
/**
* [0x03]
Reply to peer's Ping packet.
*/
PONG(0x03),
/**
* [0x04]
Request the peer to enumerate some known peers
* for us to connect to. This should include the peer itself.
*/
GET_PEERS(0x04),
/**
* [0x05, [IP1, Port1, Id1], [IP2, Port2, Id2], ... ]
* Specifies a number of known peers. IP is a 4-byte array 'ABCD'
* that should be interpreted as the IP address A.B.C.D.
* Port is a 2-byte array that should be interpreted as a
* 16-bit big-endian integer. Id is the 512-bit hash that acts
* as the unique identifier of the node.
*/
PEERS(0x05),
/**
*
*/
USER(0x0F);
private final int cmd;
private static final Map intToTypeMap = new HashMap<>();
static {
for (P2pMessageCodes type : P2pMessageCodes.values()) {
intToTypeMap.put(type.cmd, type);
}
}
private P2pMessageCodes(int cmd) {
this.cmd = cmd;
}
public static P2pMessageCodes fromByte(byte i) {
return intToTypeMap.get((int) i);
}
public static boolean inRange(byte code) {
return code >= HELLO.asByte() && code <= USER.asByte();
}
public byte asByte() {
return (byte) (cmd);
}
}