Package org.bitcoinj.net
Interface StreamConnection
- All Known Implementing Classes:
Peer
,PeerSocketHandler
public interface StreamConnection
A generic handler which is used in
NioServer
, NioClient
and BlockingClient
to handle incoming
data streams.
Used to be called StreamParser.-
Method Summary
Modifier and TypeMethodDescriptionvoid
Called when the connection socket is closedvoid
Called when the connection socket is first openedint
Returns the maximum message size of a message on the socket.int
receiveBytes
(ByteBuffer buff) Called when new bytes are available from the remote end.void
setWriteTarget
(MessageWriteTarget writeTarget) Called when this connection is attached to an upstream write target (ie a low-level connection handler).
-
Method Details
-
connectionClosed
void connectionClosed()Called when the connection socket is closed -
connectionOpened
void connectionOpened()Called when the connection socket is first opened -
receiveBytes
Called 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:- buff will start with its limit set to the position we can read to and its position set to the location we will start reading at (always 0)
- May read more than one message (recursively) if there are enough bytes available
- Uses some internal buffering to store message which are larger (incl their length prefix) than buff's capacity(), ie it is up to this method to ensure we don't run out of buffer space to decode the next message.
- buff will end with its limit the same as it was previously, and its position set to the position up to which bytes have been read (the same as its return value)
- buff must be at least the size of a Bitcoin header (incl magic bytes).
- Returns:
- The amount of bytes consumed which should not be provided again
- Throws:
Exception
-
setWriteTarget
Called when this connection is attached to an upstream write target (ie a low-level connection handler). This writeTarget should be stored and used to close the connection or write data to the socket. -
getMaxMessageSize
int getMaxMessageSize()Returns the maximum message size of a message on the socket. This is used in calculating size of buffers to allocate.
-