|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectme.edwards.des.Node
public class Node
A Miner Node is the most complex autonomous unit that operates on the DES
Network. This class handles all of the higher-level processes for a Miner
Node, including processing of packets received by the Node, generation of new
Blocks, handling of broadcasted Ballots, and validation of data generated by
other Nodes.
When this Node is placed on a network with additional Nodes running the same
software, they are able to "mine" ballots broadcast by Election Applications
using the Decentralized Election System. This is the step in the process that
ensures the validity of each individual's vote and causes them to be
immutably and permanently inserted into the public
BlockChain
, preventing corruption in
a democratic voting system.
Created on: Oct 16, 2015 at 9:35:54 PM
Field Summary | |
---|---|
protected java.util.ArrayList<Ballot> |
ballots
This Node's private list of all known, unmined ballots. |
static int |
BLOCK_THRESHOLD
Threshold number of Ballots required to begin mining a Block. |
static int |
BLOCK_TIME
Minimum amount of time (in seconds) to begin mining a Block |
protected BlockChain |
blockChain
This Node's private version of the BlockChain. |
private java.lang.Thread |
blockGen
This thread is used to attempt generation of new Blocks (mine a proof of work for a new Block). |
protected java.lang.String |
blockGenHash
Hash of the parent of the Block currently being generated by the Node. |
private java.lang.Thread |
blockGenTimer
This thread initiates Block generation if the time threshold has been reached. |
static int |
BUFFER_SIZE
Default Packet Buffer Size |
private java.util.ArrayList<java.lang.String> |
dataRequests
A list of the hashes of all the data objects requested by this Node. |
protected boolean |
demo
Demonstration mode flag used to indicate if this Node is currently in demonstration mode. |
private java.lang.Thread |
handshake
This thread accepts handshakes from new, previously unknown peers on the network. |
protected java.net.InetAddress |
ip
This Node's IP Address as an InetAddress instance. |
protected java.util.logging.Logger |
logger
Logger instance to be used by this Node. |
protected java.lang.String |
name
This Node's human readable name. |
protected java.util.ArrayList<java.lang.String> |
peerList
List of initial peers to be contacted during the bootstrapping process. |
protected java.util.ArrayList<Connection> |
peers
List of connections containing all of this Node's current peers. |
protected int |
port
This Node's current listening socket port. |
protected boolean |
running
Running flag used to indicate if this Node is presently accepting and sending packets over connections on the network. |
protected java.net.ServerSocket |
socket
This Node's current listening socket as a ServerSocket instance. |
static Version |
VERSION
Node's software version. |
Constructor Summary | |
---|---|
Node()
|
Method Summary | |
---|---|
void |
addDataRequest(java.lang.String hash)
Adds a hash to the data requests list. |
Connection |
connect(java.net.InetAddress address,
int port)
Connects this Node to a peer Node via the specified IP Address and port. |
void |
generateBlock()
Attempts to generate a new Block from a limited number of known, validated Ballots. |
Connection |
getConnection(java.lang.String hostname)
Returns the connection with the specified name from
the current list of peers of this Node. |
java.util.ArrayList<Connection> |
getPeers()
Returns a list of this Node's known peers. |
boolean |
isRunning()
Returns the running status of this Node. |
void |
parse(byte[] data,
Connection connection)
Parses a packet received by a connection to this Node
into a Packet Type and processes the received data in
the packet.Packet Type Process Category Description of Process Ping
Connection Status
Sends a Pong response to the Ping sender,
incrementing the payload by one.
Pong
Connection Status
Notifies the corresponding connection that a
response has been received from the peer Node.
Version
Handshake
Validates the version of the
sender Node and sends a VerAck . |
void |
removeConnection(Connection c)
Disconnects the specified peer and removes its connection from the list of this Node's peers. |
void |
sendToAll(Packet p)
Sends the specified packet to all known peers. |
void |
start()
Initializes the Node's networking processes and threads, starting the Node on a specific IP Address and Port (specified by the Launcher ). |
void |
stop()
Stops the Node's running processes, including the Handshake Thread (preventing other Nodes from connecting to this Node)
and the Block Generation Thread (stopping the
generation of any new Blocks or Blocks currently being generated). |
void |
stopBlockGeneration()
Stops any current Block generation by this Node. |
private static boolean |
validateVersion(Version v)
Checks if the version of another Node is compatible with the version of this Node. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Version VERSION
public static final int BUFFER_SIZE
public static final int BLOCK_THRESHOLD
public static final int BLOCK_TIME
protected java.util.logging.Logger logger
protected java.util.ArrayList<java.lang.String> peerList
protected BlockChain blockChain
protected java.lang.String blockGenHash
protected java.util.ArrayList<Connection> peers
protected java.util.ArrayList<Ballot> ballots
protected java.net.InetAddress ip
protected java.net.ServerSocket socket
protected int port
protected java.lang.String name
protected boolean demo
protected boolean running
private java.util.ArrayList<java.lang.String> dataRequests
private java.lang.Thread handshake
private java.lang.Thread blockGenTimer
time
threshold has been reached.
private java.lang.Thread blockGen
Constructor Detail |
---|
public Node()
Method Detail |
---|
public void start()
Launcher
). This method creates and starts
the Handshake Thread
, allowing other Nodes to
connect to this Node. This method will also go through the "Peer List"
and attempt to connect to any initial peers, allowing the bootstrapping
process to take place. After this method is completed, the
running
flag should be set to True.
public void stop()
Handshake Thread
(preventing other Nodes from connecting to this Node)
and the Block Generation Thread
(stopping the
generation of any new Blocks or Blocks currently being generated). This
method also closes all networking sockets currently open. After this
method is completed, the running
flag should be set
to False.
public void parse(byte[] data, Connection connection)
connection
to this Node
into a Packet Type
and processes the received data in
the packet.Packet Type | Process Category | Description of Process |
Ping |
Connection Status | Sends a Pong response to the Ping sender,
incrementing the payload by one. |
Pong |
Connection Status | Notifies the corresponding connection that a
response has been received from the peer Node. |
Version |
Handshake | Validates the version of the
sender Node and sends a VerAck . Updates the
connection status and requests
Ballot, Block, and Address Cache data from the sender Node. Reception
completes the Handshake for the Node requesting the connection initially.
|
VerAck |
Handshake | Updates the connection
status and requests Ballot, Block, and Address Cache data from the
sender Node. Reception completes the Handshake for the Node that did not
request the connection initially. |
GetAddr |
Bootstrapping | Sends the requesting Node a copy of all of this Node's current peers. |
Addr |
Bootstrapping | Parses address cache information and attempts to connect to previously unknown peers. |
Inv |
Inventory Transfer | Sends requests using a GetData packet to the
advertising Node for data objects that this Node does not possess. |
NotFound |
Inventory Transfer | Notifies the Node that a requested resources was not found. |
GetData |
Inventory Transfer | Sends requested data objects to the requesting Node using
Ballot data packets or Block data
packets . |
Ballot |
Inventory Transfer | Validates Ballot and adds it to this Node's list of
known Ballots. If this Ballot was not requested, or is invalid, it is
discarded. A valid Ballot is propagated to all known peer Nodes with
Inventory Packets . |
Block |
Inventory Transfer | Validates Block and adds it to this Node's
BlockChain . If this Block was not requested, or is
invalid, it is discarded. A valid Ballot is propagated to all known peer
Nodes with Inventory Packets . |
GetBlocks |
Inventory Transfer | Sends Inventory packet containing all Blocks after the Block specified in the GetBlocks request. |
data
- Packet data received by the connection as a byte array.connection
- Connection object through which the packet was received.Packet
,
PacketAddr
,
PacketBallot
,
PacketBlock
,
PacketGetAddr
,
PacketGetBlocks
,
PacketGetData
,
PacketInv
,
PacketNotFound
,
PacketPing
,
PacketPong
,
PacketVerack
,
PacketVersion
,
Connection
public Connection connect(java.net.InetAddress address, int port)
address
- IP Address of the peer Nodeport
- Port of the peer Node
connection
object if the connection
to the peer was successful. If the connection was unsuccessful,
null is returned.public void removeConnection(Connection c)
connection
from the list of this Node's peers.
c
- Connection of the peer to removeConnection
public Connection getConnection(java.lang.String hostname)
connection
with the specified name from
the current list of peers of this Node.
hostname
- Name of this connection in the format "/ipaddress:port", or
the human readable name of the peer.
Connection
,
Connection.getHostName()
public void sendToAll(Packet p)
packet
to all known peers.
p
- Packet to send to all known peers.Packet
,
Connection
public boolean isRunning()
running
flag)
public java.util.ArrayList<Connection> getPeers()
public void generateBlock()
Block
Generation Thread
initialized by this method is interrupted and stopped.Stop Block
Generation
method must be called first, and then this method.
public void stopBlockGeneration()
Block Generation Thread
and resets the
Block Generation Hash
variable.
public void addDataRequest(java.lang.String hash)
data requests
list.
hash
- Hash to add to the data requests listprivate static boolean validateVersion(Version v)
version
of this Node.
v
- Version to compare with this Node's version.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |