public abstract class PeerSocketHandler extends AbstractTimeoutHandler implements StreamConnection
org.bitcoinj.net classes and Peer.| Modifier and Type | Field and Description |
|---|---|
protected PeerAddress |
peerAddress |
protected MessageWriteTarget |
writeTarget |
| Constructor and Description |
|---|
PeerSocketHandler(NetworkParameters params,
java.net.InetSocketAddress remoteIp) |
PeerSocketHandler(NetworkParameters params,
PeerAddress peerAddress) |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the connection to the peer if one exists, or immediately closes the connection as soon as it opens
|
PeerAddress |
getAddress() |
int |
getMaxMessageSize()
Returns the maximum message size of a message on the socket.
|
protected abstract void |
processMessage(Message m)
Called every time a message is received from the network
|
int |
receiveBytes(java.nio.ByteBuffer buff)
Called when new bytes are available from the remote end.
|
com.google.common.util.concurrent.ListenableFuture |
sendMessage(Message message)
Sends the given message to the peer.
|
void |
setWriteTarget(MessageWriteTarget writeTarget)
Sets the
MessageWriteTarget used to write messages to the peer. |
protected void |
timeoutOccurred() |
resetTimeout, setSocketTimeout, setTimeoutEnabledclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitconnectionClosed, connectionOpenedprotected PeerAddress peerAddress
protected MessageWriteTarget writeTarget
public PeerSocketHandler(NetworkParameters params, java.net.InetSocketAddress remoteIp)
public PeerSocketHandler(NetworkParameters params, PeerAddress peerAddress)
public com.google.common.util.concurrent.ListenableFuture sendMessage(Message message) throws java.nio.channels.NotYetConnectedException
java.nio.channels.NotYetConnectedExceptionpublic void close()
protected void timeoutOccurred()
timeoutOccurred in class AbstractTimeoutHandlerprotected abstract void processMessage(Message m) throws java.lang.Exception
java.lang.Exceptionpublic int receiveBytes(java.nio.ByteBuffer buff)
StreamConnectionCalled when new bytes are available from the remote end. This should only ever be called by the single writeTarget associated with any given StreamConnection, multiple callers will likely confuse implementations.
Implementers/callers must follow the following conventions exactly:receiveBytes in interface StreamConnectionpublic void setWriteTarget(MessageWriteTarget writeTarget)
MessageWriteTarget used to write messages to the peer. This should almost never be called, it is
called automatically by NioClient or
NioClientManager once the socket finishes initialization.setWriteTarget in interface StreamConnectionpublic int getMaxMessageSize()
StreamConnectiongetMaxMessageSize in interface StreamConnectionpublic PeerAddress getAddress()