Package nxt.peer
Class NetworkHandler
java.lang.Object
nxt.peer.NetworkHandler
- All Implemented Interfaces:
Runnable
The network handler creates outbound connections and adds them to the
network selector. A new outbound connection will be created whenever
the number of outbound connections is less than the maximum number of
outbound connections.
The network handler opens a local port and listens for incoming connections.
When a connection is received, it creates a socket channel and accepts the
connection as long as the maximum number of inbound connections has not been reached.
The socket is then added to the network selector.
When a message is received from a peer node, it is processed by a message
handler executing on a separate thread. The message handler processes the
message and then creates a response message to be returned to the originating node.
The network handler terminates when its shutdown() method is called.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intPeer read timeout (seconds)static final intTestnet peer port -
Method Summary
Modifier and TypeMethodDescriptionstatic intbroadcastMessage(NetworkMessage message) Broadcast a message to all connected peersstatic intbroadcastMessage(Peer sender, NetworkMessage message) Broadcast a message to all connected peersstatic intGet the connected peer countstatic intGet the default peer portstatic intGet the number of inbound connectionsstatic intReturn the maximum number of inbound connectionsstatic intReturn the maximum number of outbound connectionsstatic intGet the number of outbound connectionsstatic voidinit()Initialize the network handlerstatic booleanCheck if the network has finished initializationvoidrun()Network listenerstatic voidshutdown()Shutdown the network handler
-
Field Details
-
TESTNET_PEER_PORT
public static final int TESTNET_PEER_PORTTestnet peer port -
peerReadTimeout
public static final int peerReadTimeoutPeer read timeout (seconds)
-
-
Method Details
-
init
public static void init()Initialize the network handler -
shutdown
public static void shutdown()Shutdown the network handler -
run
public void run()Network listener -
isNetworkStarted
public static boolean isNetworkStarted()Check if the network has finished initialization- Returns:
- TRUE if the network is available
-
broadcastMessage
Broadcast a message to all connected peers- Parameters:
message- Message to send- Returns:
- number of peers to which message was sent
-
broadcastMessage
Broadcast a message to all connected peers- Parameters:
sender- Message sender or null if our messagemessage- Message to send- Returns:
- number of peers to which message was sent
-
getDefaultPeerPort
public static int getDefaultPeerPort()Get the default peer port- Returns:
- Default peer port
-
getConnectionCount
public static int getConnectionCount()Get the connected peer count- Returns:
- Connected peer count
-
getInboundCount
public static int getInboundCount()Get the number of inbound connections- Returns:
- Number of inbound connections
-
getMaxInboundConnections
public static int getMaxInboundConnections()Return the maximum number of inbound connections- Returns:
- Number of inbound connections
-
getOutboundCount
public static int getOutboundCount()Get the number of outbound connections- Returns:
- Number of outbound connections
-
getMaxOutboundConnections
public static int getMaxOutboundConnections()Return the maximum number of outbound connections- Returns:
- Number of outbound connections
-