Class PeerForeignDelegate

    • Field Detail

      • _lastPiece

        protected volatile int _lastPiece
      • foreign

        private Peer foreign
      • create_time

        private long create_time
      • last_data_received_time

        private long last_data_received_time
      • last_data_message_received_time

        private long last_data_message_received_time
      • reserved_pieces

        private int[] reserved_pieces
      • consecutive_no_requests

        private int consecutive_no_requests
      • priority_connection

        private boolean priority_connection
      • data

        private java.util.Map data
      • download_disabled_set

        private java.util.Set<java.lang.Object> download_disabled_set
      • is_download_disabled

        private boolean is_download_disabled
      • closed

        private volatile boolean closed
    • Constructor Detail

      • PeerForeignDelegate

        protected PeerForeignDelegate​(PeerManagerImpl _manager,
                                      Peer _foreign)
    • Method Detail

      • isMyPeer

        public boolean isMyPeer()
        Description copied from interface: PEPeer
        Whether or not this is a 'dummy' peer that represents our presence in a swarm
        Specified by:
        isMyPeer in interface PEPeer
        Returns:
      • stop

        protected void stop()
      • sendHave

        public void sendHave​(int piece)
        Nothing to do if called
        Specified by:
        sendHave in interface PEPeerTransport
      • getAlternativeIPv6

        public java.net.InetAddress getAlternativeIPv6()
        Specified by:
        getAlternativeIPv6 in interface PEPeer
        Returns:
        an ipv6 address under which the peer should be connectable if it announced one, null otherwise
      • isDownloadPossible

        public boolean isDownloadPossible()
        Description copied from interface: PEPeer
        checks several factors within the object so the caller wouldn't need to for convienience and speed.
        Specified by:
        isDownloadPossible in interface PEPeer
        Returns:
        true if none of several criteria indicate a request can't be made of the peer
      • request

        public DiskManagerReadRequest request​(int pieceNumber,
                                              int pieceOffset,
                                              int pieceLength,
                                              boolean return_duplicates)
        Specified by:
        request in interface PEPeerTransport
        Parameters:
        pieceNumber -
        pieceOffset -
        pieceLength -
        return_duplicates - - if true and request already exists it will be returned, if false -> null
        Returns:
        true is the piece is really requested
      • dataReceived

        protected void dataReceived()
      • closeConnection

        public void closeConnection​(java.lang.String reason)
        Description copied from interface: PEPeerTransport
        Close the peer connection
        Specified by:
        closeConnection in interface PEPeerTransport
        Parameters:
        reason - for closure
      • isClosed

        public boolean isClosed()
        Specified by:
        isClosed in interface PEPeer
      • getMaxNbRequests

        public int getMaxNbRequests()
        Description copied from interface: PEPeerTransport
        peer-specific request max. return -1 to use the default piece-picker allocation method
        Specified by:
        getMaxNbRequests in interface PEPeerTransport
        Returns:
      • requestAllocationStarts

        public boolean requestAllocationStarts​(int[] base_priorities)
        Description copied from interface: PEPeerTransport
        Two methods that allow a peer to aggregate the individual requests generated during an allocation cycle if so desired
        Specified by:
        requestAllocationStarts in interface PEPeerTransport
        Returns:
        true if the peer is managing request priorities and doesn't want end-game random allocation behaviour
      • doKeepAliveCheck

        public void doKeepAliveCheck()
        Description copied from interface: PEPeerTransport
        Check if we need to send a keep-alive message. A keep-alive is sent if no other message has been sent within the last 2min.
        Specified by:
        doKeepAliveCheck in interface PEPeerTransport
      • doTimeoutChecks

        public boolean doTimeoutChecks()
        Description copied from interface: PEPeerTransport
        Check for possible connection timeouts.
        Specified by:
        doTimeoutChecks in interface PEPeerTransport
        Returns:
        true if the connection has been timed-out, false if not
      • doPerformanceTuningCheck

        public void doPerformanceTuningCheck()
        Description copied from interface: PEPeerTransport
        Perform checks related to performance optimizations, i.e. tune buffering related to send/receive speed.
        Specified by:
        doPerformanceTuningCheck in interface PEPeerTransport
      • setSuspendedLazyBitFieldEnabled

        public void setSuspendedLazyBitFieldEnabled​(boolean enable)
        Description copied from interface: PEPeer
        Enable suspended lazy bitfield for this peer - we will appear incomplete until this is disabled, at which point (well, fairly soon after) the bitfield will be completed
        Specified by:
        setSuspendedLazyBitFieldEnabled in interface PEPeer
      • getTimeSinceConnectionEstablished

        public long getTimeSinceConnectionEstablished()
        Description copied from interface: PEPeer
        Get the time since this connection was first established. NOTE: This method will always return 0 at any time before the underlying transport is fully connected, i.e. before handshaking begins.
        Specified by:
        getTimeSinceConnectionEstablished in interface PEPeer
        Returns:
        time count in ms
      • getTimeSinceLastDataMessageReceived

        public long getTimeSinceLastDataMessageReceived()
        Description copied from interface: PEPeerTransport
        Get the time since the last (most-recent) data (payload) message was received.
        Specified by:
        getTimeSinceLastDataMessageReceived in interface PEPeerTransport
        Returns:
        time count in ms, or -1 if we've never received a data message from them
      • getTimeSinceGoodDataReceived

        public long getTimeSinceGoodDataReceived()
        Description copied from interface: PEPeerTransport
        Get the time since the most-recent data that was actually written to disk was received.
        Specified by:
        getTimeSinceGoodDataReceived in interface PEPeerTransport
        Returns:
        time count in ms, or -1 if we've never received usefull data from them
      • getTimeSinceLastDataMessageSent

        public long getTimeSinceLastDataMessageSent()
        Description copied from interface: PEPeerTransport
        Get the time since the last (most-recent) data (payload) message was sent.
        Specified by:
        getTimeSinceLastDataMessageSent in interface PEPeerTransport
        Returns:
        time count in ms, or -1 if we've never sent them a data message
      • getPeerSource

        public java.lang.String getPeerSource()
        Specified by:
        getPeerSource in interface PEPeer
      • getPeerState

        public int getPeerState()
        Specified by:
        getPeerState in interface PEPeer
      • getId

        public byte[] getId()
        Specified by:
        getId in interface PEPeer
      • getIp

        public java.lang.String getIp()
        Specified by:
        getIp in interface PEPeer
      • getIPHostName

        public java.lang.String getIPHostName()
        Description copied from interface: PEPeer
        Gets the host name for the IP, if possible, IP as string otherwise
        Specified by:
        getIPHostName in interface PEPeer
        Returns:
        hostname or IP
      • getPort

        public int getPort()
        Description copied from interface: PEPeer
        Get the peer's local TCP connection port.
        Specified by:
        getPort in interface PEPeer
        Returns:
        local port
      • getTCPListenPort

        public int getTCPListenPort()
        Description copied from interface: PEPeer
        Get the TCP port this peer is listening for incoming connections on.
        Specified by:
        getTCPListenPort in interface PEPeer
        Returns:
        TCP port, or 0 if port is unknown
      • getUDPListenPort

        public int getUDPListenPort()
        Description copied from interface: PEPeer
        Get the UDP port this peer is listening for incoming connections on.
        Specified by:
        getUDPListenPort in interface PEPeer
        Returns:
        UDP port, or 0 if port is unknown
      • getUDPNonDataListenPort

        public int getUDPNonDataListenPort()
        Description copied from interface: PEPeer
        Get the UDP port this peer is listening on for non-data connections
        Specified by:
        getUDPNonDataListenPort in interface PEPeer
        Returns:
      • isPieceAvailable

        public boolean isPieceAvailable​(int pieceNumber)
        Specified by:
        isPieceAvailable in interface PEPeer
        Parameters:
        pieceNumber - int
        Returns:
        true if this peers makes this piece available
      • setSnubbed

        public void setSnubbed​(boolean b)
        Specified by:
        setSnubbed in interface PEPeer
      • isChokingMe

        public boolean isChokingMe()
        Description copied from interface: PEPeer
        Is the peer choking me.
        Specified by:
        isChokingMe in interface PEPeer
        Returns:
        true if I am choked by the peer, false if not
      • isChokedByMe

        public boolean isChokedByMe()
        Description copied from interface: PEPeer
        Am I choking the peer.
        Specified by:
        isChokedByMe in interface PEPeer
        Returns:
        true if the peer is choked, false if not
      • isInteresting

        public boolean isInteresting()
        Description copied from interface: PEPeer
        Am I Interested in the peer.
        Specified by:
        isInteresting in interface PEPeer
        Returns:
        true if peer is interesting, false if not
      • isInterested

        public boolean isInterested()
        Description copied from interface: PEPeer
        Is the peer Interested in me.
        Specified by:
        isInterested in interface PEPeer
        Returns:
        true if the peer is interested in me, false if not
      • isSeed

        public boolean isSeed()
        Specified by:
        isSeed in interface PEPeer
      • isRelativeSeed

        public boolean isRelativeSeed()
        Specified by:
        isRelativeSeed in interface PEPeer
        Returns:
        true if the peer is only uploading and can't use the data we have to offer (we're seeding) or we can't use the data he has to offer (we're downloading)
      • isSnubbed

        public boolean isSnubbed()
        Specified by:
        isSnubbed in interface PEPeer
      • isLANLocal

        public boolean isLANLocal()
        Description copied from interface: PEPeerTransport
        Is the connection within the local LAN network.
        Specified by:
        isLANLocal in interface PEPeer
        Specified by:
        isLANLocal in interface PEPeerTransport
        Returns:
        true if within LAN, false of outside the LAN segment
      • sendRequestHint

        public boolean sendRequestHint​(int piece_number,
                                       int offset,
                                       int length,
                                       int life)
        Description copied from interface: PEPeer
        Send a request hint to the peer.
        Specified by:
        sendRequestHint in interface PEPeer
        Returns:
        true if sent, false otherwise
      • getRequestHint

        public int[] getRequestHint()
        Description copied from interface: PEPeer
        Get current request hint for a given piece for this peer.
        Specified by:
        getRequestHint in interface PEPeer
        Returns:
        null if no hint int[]{ piece_number, offset, length } if hint found
      • isIncoming

        public boolean isIncoming()
        Specified by:
        isIncoming in interface PEPeer
      • getPercentDoneInThousandNotation

        public int getPercentDoneInThousandNotation()
        Description copied from interface: PEPeer
        Get the peer's torrent completion percentage in thousand-notation, i.e. 53.7% is returned as the value 0537.
        Specified by:
        getPercentDoneInThousandNotation in interface PEPeer
        Returns:
        the percentage the peer has complete
      • getClient

        public java.lang.String getClient()
        Specified by:
        getClient in interface PEPeer
      • setOptimisticUnchoke

        public void setOptimisticUnchoke​(boolean is_optimistic)
        Specified by:
        setOptimisticUnchoke in interface PEPeer
      • setUniqueAnnounce

        public void setUniqueAnnounce​(int uniquePieceNumber)
        Specified by:
        setUniqueAnnounce in interface PEPeer
      • setUploadHint

        public void setUploadHint​(int timeToSpread)
        Specified by:
        setUploadHint in interface PEPeer
      • isStalledPendingLoad

        public boolean isStalledPendingLoad()
        Description copied from interface: PEPeerTransport
        is peer waiting for a disk read with no network writes queued
        Specified by:
        isStalledPendingLoad in interface PEPeerTransport
        Returns:
      • getPluginConnection

        public Connection getPluginConnection()
        Description copied from interface: PEPeer
        Get the connection that backs this peer.
        Specified by:
        getPluginConnection in interface PEPeer
        Returns:
        connection
      • supportsMessaging

        public boolean supportsMessaging()
        Description copied from interface: PEPeer
        Whether or not this peer supports the advanced messaging API.
        Specified by:
        supportsMessaging in interface PEPeer
        Returns:
        true if extended messaging is supported, false if not
      • getEncryption

        public java.lang.String getEncryption()
        Description copied from interface: PEPeer
        Returns name of encryption used by the peer
        Specified by:
        getEncryption in interface PEPeer
        Returns:
      • getProtocol

        public java.lang.String getProtocol()
        Specified by:
        getProtocol in interface PEPeer
      • getSupportedMessages

        public Message[] getSupportedMessages()
        Description copied from interface: PEPeer
        Get the list of messages that this peer and us both understand.
        Specified by:
        getSupportedMessages in interface PEPeer
        Returns:
        messages available for use, or null of supported is yet unknown or unavailable
      • getData

        public java.lang.Object getData​(java.lang.String key)
        Description copied from interface: PEPeer
        To retreive arbitrary objects against a peer.
        Specified by:
        getData in interface PEPeer
      • setData

        public void setData​(java.lang.String key,
                            java.lang.Object value)
        Description copied from interface: PEPeer
        To store arbitrary objects against a peer.
        Specified by:
        setData in interface PEPeer
      • getUserData

        public java.lang.Object getUserData​(java.lang.Object key)
        To retreive arbitrary objects against a peer.
        Specified by:
        getUserData in interface PEPeer
      • setUserData

        public void setUserData​(java.lang.Object key,
                                java.lang.Object value)
        To store arbitrary objects against a peer.
        Specified by:
        setUserData in interface PEPeer
      • equals

        public boolean equals​(java.lang.Object other)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • getReservedPieceNumbers

        public int[] getReservedPieceNumbers()
        Description copied from interface: PEPeer
        Get the reserved pieces for piece picking by this peer
        Specified by:
        getReservedPieceNumbers in interface PEPeer
      • addReservedPieceNumber

        public void addReservedPieceNumber​(int piece_number)
        Description copied from interface: PEPeer
        adds the reserved piece for piece picking by this peer
        Specified by:
        addReservedPieceNumber in interface PEPeer
      • getIncomingRequestedPieceNumbers

        public int[] getIncomingRequestedPieceNumbers()
        Description copied from interface: PEPeer
        get a list of piece numbers the peer has requested
        Specified by:
        getIncomingRequestedPieceNumbers in interface PEPeer
        Returns:
        list of Long() representing the piece number requested, in order
      • getOutgoingRequestedPieceNumbers

        public int[] getOutgoingRequestedPieceNumbers()
        Description copied from interface: PEPeer
        get a list of piece numbers the we have requested from peer
        Specified by:
        getOutgoingRequestedPieceNumbers in interface PEPeer
        Returns:
        list of Long() representing the piece number requested, oldest to newest
      • getLastPiece

        public int getLastPiece()
        Specified by:
        getLastPiece in interface PEPeer
      • setLastPiece

        public void setLastPiece​(int pieceNumber)
        Specified by:
        setLastPiece in interface PEPeer
      • isAvailabilityAdded

        public boolean isAvailabilityAdded()
        Apaprently nothing significant to do if called
      • clearAvailabilityAdded

        public void clearAvailabilityAdded()
        Nothing to do if called
      • reconnect

        public PEPeerTransport reconnect​(boolean tryUDP,
                                         boolean tryIPv6)
        Description copied from interface: PEPeerTransport
        Attempts to reconnect to the same peer
        Specified by:
        reconnect in interface PEPeerTransport
        Parameters:
        tryUDP - try to initate a UDP connection if true, just reestablish the previous state otherwise
        tryIPv6 - TODO
        Returns:
        null if reconnect not possible, reconnected peer otherwise
      • isSafeForReconnect

        public boolean isSafeForReconnect()
        Description copied from interface: PEPeerTransport
        This method is called to check if it is safe to reconnect to a peer, i.e. avoid hammering exchanging data with a peer should work as it takes time to setup the connection and negotiate things before that happens
        Specified by:
        isSafeForReconnect in interface PEPeerTransport
        Returns:
        true if we exchanged payload data with the peer during the current connection
      • updateAutoUploadPriority

        public void updateAutoUploadPriority​(java.lang.Object key,
                                             boolean inc)
        Specified by:
        updateAutoUploadPriority in interface PEPeer
      • setUploadDisabled

        public void setUploadDisabled​(java.lang.Object key,
                                      boolean disabled)
        Specified by:
        setUploadDisabled in interface PEPeer
      • setDownloadDisabled

        public void setDownloadDisabled​(java.lang.Object key,
                                        boolean disabled)
        Specified by:
        setDownloadDisabled in interface PEPeer
      • setPriorityConnection

        public void setPriorityConnection​(boolean is_priority)
        Specified by:
        setPriorityConnection in interface PEPeer
      • getTaggableID

        public java.lang.String getTaggableID()
        Specified by:
        getTaggableID in interface Taggable
      • getTaggableName

        public java.lang.String getTaggableName()
        Specified by:
        getTaggableName in interface Taggable
      • setTaggableTransientProperty

        public void setTaggableTransientProperty​(java.lang.String key,
                                                 java.lang.Object value)
        Specified by:
        setTaggableTransientProperty in interface Taggable