public class BitTorrentSocket extends Object
| Constructor and Description |
|---|
BitTorrentSocket(MessageFactory messageFactory)
Creates a new unbound BitTorrent socket.
|
BitTorrentSocket(MessageFactory messageFactory,
ISocket socket)
Creates a new bound BitTorrent socket.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
canReadMessage()
Buffers the next message for reading.
|
void |
close()
Closes the connection with the socket
|
boolean |
closed()
Checks if the socket is closed
|
void |
connect(ConnectionDegradation degradation,
InetSocketAddress address)
Attempts to connect to the given endpoint in a blocking manner.
|
void |
enqueueMessage(IMessage message)
Queues the message to be send
|
int |
getDownloadRate()
Returns the last polled download rate.
|
LocalDateTime |
getLastActivity()
Gets the time at which the last byte has been read or written to the socket.
|
boolean |
getPassedHandshake()
Gets if this socket has completed the BitTorrent handshake
|
String |
getSocketName()
Gets the class simple name of the underlying socket.
|
int |
getUploadRate()
Returns the last polled upload rate.
|
boolean |
hasOutboundMessages()
Checks if this socket has messages queued for sending
|
void |
pollRates()
Polls all the transfer speeds.
|
BitTorrentHandshake |
readHandshake()
Reads the handshake information from the peer
|
IMessage |
readMessage() |
void |
sendHandshake(byte[] extensionBytes,
byte[] peerId,
byte[] torrentHash)
Writes the handshake onto the output stream
|
void |
sendMessage()
Sends at most 1 pending message.
|
void |
setPassedHandshake()
Marks that this socket has passed the BitTorrent handshake and therefor is a valid BitTorrent socket.
|
String |
toString() |
public BitTorrentSocket(MessageFactory messageFactory)
messageFactory - The factory to create IMessage instances.public BitTorrentSocket(MessageFactory messageFactory, ISocket socket) throws IOException
messageFactory - The factory to create IMessage instances.socket - The bound socket.IOException - When the IO streams can not be wrapped.public void connect(ConnectionDegradation degradation, InetSocketAddress address) throws IOException
degradation - The socket degradation order.address - The address to connect toIOException - When an IO error occur during the establishing of a connection.public void enqueueMessage(IMessage message)
message - The message to be added to the queuepublic IMessage readMessage()
public void sendMessage()
throws IOException
MessageBlock will be send lastIOExceptionpublic void sendHandshake(byte[] extensionBytes,
byte[] peerId,
byte[] torrentHash)
throws IOException
extensionBytes - The bytes indicating which extensions we supportpeerId - The peer ID which this peer will send out.torrentHash - The hash of the torrent on which we wish to interact on with this peer.IOExceptionpublic BitTorrentHandshake readHandshake() throws IOException
IOException - when either an io error occurs, a protocol error occurs or the peer doesn't respond within 5 seconds.public void pollRates()
public void close()
public boolean canReadMessage()
throws IOException
true when enough data is buffered to read the next message without blocking.IOException - When an IO error occurs during the buffering.public int getDownloadRate()
pollRates()public int getUploadRate()
pollRates()public boolean closed()
true if the underlying socket is closed, otherwise falsepublic boolean getPassedHandshake()
true if the handshake was completedpublic void setPassedHandshake()
public boolean hasOutboundMessages()
true if there is at least one IMessage waiting to be sent.public String getSocketName()
public LocalDateTime getLastActivity()
Copyright © 2016. All rights reserved.