Class BitTorrentSocket

    • Constructor Detail

      • BitTorrentSocket

        public BitTorrentSocket​(MessageFactory messageFactory,
                                ISocket socket)
        Creates a new bound BitTorrent socket.
        Parameters:
        messageFactory - The factory to create IMessage instances.
        socket - The bound socket.
    • Method Detail

      • enqueueMessage

        public void enqueueMessage​(IMessage message)
        Queues the message to be send
        Parameters:
        message - The message to be added to the queue
      • readMessage

        public IMessage readMessage()
        Converts the buffered message to an IMessage. must only be called when canReadMessage() returns true.
        Returns:
        The next message on the stream.
      • sendMessages

        public void sendMessages()
                          throws IOException
        Sends messages until the operation is no longer blocking. MessageBlock will be send last.
        Throws:
        IOException - When write fails.
      • pollRates

        public void pollRates()
        Polls all the transfer speeds.
      • close

        public void close()
        Closes the connection with the socket
      • canReadMessage

        public boolean canReadMessage()
                               throws IOException
        Buffers the next message for reading.
        Returns:
        Returns true when enough data is buffered to read the next message without blocking.
        Throws:
        IOException - When an IO error occurs during the buffering.
      • getDownloadRate

        public int getDownloadRate()
        Returns the last polled download rate.
        Returns:
        The amount of downloaded bytes
        See Also:
        pollRates()
      • getUploadRate

        public int getUploadRate()
        Returns the last polled upload rate.
        Returns:
        The amount of uploaded bytes
        See Also:
        pollRates()
      • closed

        public boolean closed()
        Checks if the socket is closed
        Returns:
        true if the underlying socket is closed, otherwise false
      • hasOutboundMessages

        public boolean hasOutboundMessages()
        Checks if this socket has messages queued for sending
        Returns:
        true if there is at least one IMessage waiting to be sent.
      • getSocketName

        public String getSocketName()
        Gets the class simple name of the underlying socket.
        Returns:
        The name of the socket or an empty string when no socket is set.
      • getLastActivity

        public LocalDateTime getLastActivity()
        Gets the time at which the last byte has been read or written to the socket.
        Returns:
        The most recent activity time