org.gudy.azureus2.core3.peer.impl.transport
Class PEPeerTransportProtocol

java.lang.Object
  extended by org.gudy.azureus2.core3.logging.LogRelation
      extended by org.gudy.azureus2.core3.peer.impl.transport.PEPeerTransportProtocol
All Implemented Interfaces:
PEPeerTransport, PEPeer, Taggable

public class PEPeerTransportProtocol
extends LogRelation
implements PEPeerTransport


Nested Class Summary
protected static class PEPeerTransportProtocol.MutableInteger
           
 
Field Summary
protected  boolean choking_other_peer
           
protected  boolean closing
           
protected  int connection_state
           
protected  DiskManager diskManager
           
protected static boolean ENABLE_LAZY_BITFIELD
           
protected  String ip_resolved
           
protected static LogIDs LOGID
           
protected  PEPeerControl manager
           
protected  PeerMessageLimiter message_limiter
           
protected  int nbPieces
           
protected  PEPeerStats peer_stats
           
protected  PiecePicker piecePicker
           
 
Fields inherited from interface org.gudy.azureus2.core3.peer.impl.PEPeerTransport
CONNECTION_CONNECTING, CONNECTION_FULLY_ESTABLISHED, CONNECTION_PENDING, CONNECTION_WAITING_FOR_HANDSHAKE
 
Fields inherited from interface org.gudy.azureus2.core3.peer.PEPeer
CLOSING, CONNECTING, DISCONNECTED, HANDSHAKING, MESSAGING_AZMP, MESSAGING_BT_ONLY, MESSAGING_EXTERN, MESSAGING_LTEP, StateNames, TRANSFERING
 
Fields inherited from interface com.aelitis.azureus.core.tag.Taggable
TT_DOWNLOAD, TT_PEER
 
Constructor Summary
PEPeerTransportProtocol(PEPeerControl _manager, String _peer_source, NetworkConnection _connection, Map _initial_user_data)
           
PEPeerTransportProtocol(PEPeerControl _manager, String _peer_source, String _ip, int _tcp_port, int _udp_port, boolean _use_tcp, boolean _require_crypto_handshake, byte _crypto_level, Map _initial_user_data)
           
 
Method Summary
 void addListener(PEPeerListener listener)
          Add peer listener.
 void addRateLimiter(LimitedRateGroup limiter, boolean upload)
           
 void addReservedPieceNumber(int piece_number)
          adds the reserved piece for piece picking by this peer
protected  void calculatePiecePriorities()
           
protected  void checkFast(BitFlags flags)
           
 void checkInterested()
          Global checkInterested method.
 void clearRequestHint()
           
 void closeConnection(String reason)
          Close the peer connection from the PEPeerControl manager side.
protected  void closeConnectionInternally(String reason)
           
protected  void closeConnectionInternally(String reason, boolean connect_failed, boolean network_failure)
          Close the peer connection from within the PEPeerTransport object.
protected  void decodeAZBadPiece(AZBadPiece bad_piece)
           
protected  void decodeAZHandshake(AZHandshake handshake)
           
protected  void decodeAZHave(AZHave have)
           
protected  void decodeAZRequestHint(AZRequestHint hint)
           
protected  void decodeAZStatsReply(AZStatReply reply)
           
protected  void decodeAZStatsRequest(AZStatRequest request)
           
protected  void decodeBitfield(BTBitfield bitfield)
           
protected  void decodeBTHandshake(BTHandshake handshake)
           
protected  void decodeCancel(BTCancel cancel)
           
protected  void decodeChoke(BTChoke choke)
           
protected  void decodeHave(BTHave have)
           
protected  void decodeHaveAll(BTHaveAll have_all)
           
protected  void decodeHaveNone(BTHaveNone have_none)
           
protected  void decodeInterested(BTInterested interested)
           
protected  void decodeLTHandshake(LTHandshake handshake)
           
protected  void decodeMainlineDHTPort(BTDHTPort port)
           
protected  void decodeMetaData(AZUTMetaData metadata)
           
protected  void decodePeerExchange(AZStylePeerExchange exchange)
           
protected  void decodePiece(BTPiece piece)
           
protected  void decodeRejectRequest(BTRejectRequest reject)
           
protected  void decodeRequest(BTRequest request)
           
protected  void decodeSuggestPiece(BTSuggestPiece hint)
           
protected  void decodeUnchoke(BTUnchoke unchoke)
           
protected  void decodeUninterested(BTUninterested uninterested)
           
protected  void decodeUploadOnly(UTUploadOnly message)
           
 void doKeepAliveCheck()
          Check if we need to send a keep-alive message.
 void doPerformanceTuningCheck()
          Perform checks related to performance optimizations, i.e.
 boolean doTimeoutChecks()
          Check for possible connection timeouts.
 void generateEvidence(IndentWriter writer)
           
protected  List<Integer> generateFastSet(byte[] hash, String ip, int num_pieces, int num_required)
           
protected  List<Integer> generateFastSet(int num)
           
 InetAddress getAlternativeIPv6()
           
 BitFlags getAvailable()
           
protected  long getBytesDownloaded()
           
 long getBytesRemaining()
           
 String getClient()
           
 String getClientNameFromExtensionHandshake()
           
 String getClientNameFromPeerID()
           
 int getConnectionState()
          Get the specific peer connection state.
 int getConsecutiveNoRequestCount()
           
 PEPeerControl getControl()
           
 Object getData(String key)
          To retreive arbitrary objects against a peer.
 int getDownloadRateLimitBytesPerSecond()
           
 String getEncryption()
          Returns name of encryption used by the peer
 List getExpiredRequests()
           
 byte[] getHandshakeReservedBytes()
           
 byte[] getId()
           
 int getIncomingRequestCount()
           
 int[] getIncomingRequestedPieceNumbers()
          get a list of piece numbers the peer has requested
 String getIp()
           
 String getIPHostName()
          Gets the host name for the IP, if possible, IP as string otherwise
 long getLastMessageSentTime()
           
 int getLastPiece()
           
 long getLatency()
           
 PEPeerManager getManager()
           
 int getMaxNbRequests()
          peer-specific request max.
 int getMessagingMode()
           
 int getNbRequests()
           
 String getNetwork()
           
 int getOutboundDataQueueSize()
          amount of data queued for delivery to peer
 int getOutgoingRequestCount()
           
 int[] getOutgoingRequestedPieceNumbers()
          get a list of piece numbers the we have requested from peer
 PeerItem getPeerItemIdentity()
          Get the peer's address + port identification item.
 String getPeerSource()
           
 int getPeerState()
           
 int getPercentDoneInThousandNotation()
          Get the peer's torrent completion percentage in thousand-notation, i.e.
 int getPercentDoneOfCurrentIncomingRequest()
           
 int getPercentDoneOfCurrentOutgoingRequest()
           
 Connection getPluginConnection()
          Get the connection that backs this peer.
 int getPort()
          Get the peer's local TCP connection port.
 int[] getPriorityOffsets()
          Any priority offsets this peer has, or null if none
 String getProtocol()
           
 String getProtocolQualifier()
           
 Object[] getQueryableInterfaces()
          Query this class for a reference to another class that it may hold
 LimitedRateGroup[] getRateLimiters(boolean upload)
           
 String getRelationText()
          A short description of what your class holds that can be printed by the logger
 int[] getRequestHint()
          Get current request hint for a given piece for this peer.
 int getRequestIndex(DiskManagerReadRequest request)
          Returns the index of this request in the peer's queue or -1 if not found
 int[] getReservedPieceNumbers()
          Get the reserved pieces for piece picking by this peer
 long getSnubbedTime()
           
 PEPeerStats getStats()
           
 String getString()
           
 Message[] getSupportedMessages()
          Get the list of messages that this peer and us both understand.
 String getTaggableID()
           
 TaggableResolver getTaggableResolver()
           
 Object getTaggableTransientProperty(String key)
           
 int getTaggableType()
           
 int getTCPListenPort()
          Get the TCP port this peer is listening for incoming connections on.
 long getTimeSinceConnectionEstablished()
          Get the time since this connection was first established.
 long getTimeSinceGoodDataReceived()
          Get the time since the most-recent data that was actually written to disk was received.
 long getTimeSinceLastDataMessageReceived()
          Get the time since the last (most-recent) data (payload) message was received.
 long getTimeSinceLastDataMessageSent()
          Get the time since the last (most-recent) data (payload) message was sent.
 int getUDPListenPort()
          Get the UDP port this peer is listening for incoming connections on.
 int getUDPNonDataListenPort()
          Get the UDP port this peer is listening on for non-data connections
 long getUnchokedForMillis()
           
 int getUniqueAnnounce()
           
 int getUploadHint()
           
 int getUploadRateLimitBytesPerSecond()
           
 Object getUserData(Object key)
          To retreive arbitrary objects against a peer.
 boolean hasReceivedBitField()
           
protected  void initializeConnection()
           
 boolean isChokedByMe()
          Am I choking the peer.
 boolean isChokingMe()
          Is the peer choking me.
 boolean isClosed()
           
 boolean isDownloadDisabled()
           
 boolean isDownloadDisabled(Object key)
           
 boolean isDownloadPossible()
          checks several factors within the object so the caller wouldn't need to for convienience and speed.
 boolean isIncoming()
           
 boolean isInterested()
          Is the peer Interested in me.
 boolean isInteresting()
          Am I Interested in the peer.
 boolean isLANLocal()
          Is the connection within the local LAN network.
 boolean isOptimisticUnchoke()
           
 boolean isPieceAvailable(int pieceNumber)
           
 boolean isPriorityConnection()
           
 boolean isRelativeSeed()
           
 boolean isSafeForReconnect()
          This method is called to check if it is safe to reconnect to a peer, i.e.
 boolean isSeed()
           
 boolean isSnubbed()
           
 boolean isStalledPendingLoad()
          is peer waiting for a disk read with no network writes queued
 boolean isTCP()
           
 boolean isUnchokeOverride()
           
 boolean isUploadDisabled()
           
 boolean isUploadDisabled(Object key)
           
 PEPeerTransport reconnect(boolean tryUDP, boolean tryIPv6)
          Attempts to reconnect to the same peer
 void removeListener(PEPeerListener listener)
          Remove peer listener.
 void removeRateLimiter(LimitedRateGroup limiter, boolean upload)
           
protected  void removeRequest(DiskManagerReadRequest request)
           
 void removeReservedPieceNumber(int piece_number)
           
 DiskManagerReadRequest request(int pieceNumber, int pieceOffset, int pieceLength, boolean return_duplicates)
           
 void requestAllocationComplete()
           
 boolean requestAllocationStarts(int[] base_priorities)
          Two methods that allow a peer to aggregate the individual requests generated during an allocation cycle if so desired
 void sendBadPiece(int piece_number)
           
protected  void sendBTHandshake()
           
 void sendCancel(DiskManagerReadRequest request)
           
 void sendChoke()
           
 void sendHave(int pieceNumber)
           
protected  void sendLazyHaves(int[] lazy_haves, boolean immediate)
           
 void sendRejectRequest(DiskManagerReadRequest request)
           
 boolean sendRequestHint(int piece_number, int offset, int length, int life)
          Send a request hint to the peer.
 void sendStatsReply(Map reply)
           
 void sendStatsRequest(Map request)
           
 void sendUnChoke()
           
 void setConsecutiveNoRequestCount(int num)
           
 void setData(String key, Object value)
          To store arbitrary objects against a peer.
 void setDownloadDisabled(Object key, boolean disabled)
           
 void setDownloadRateLimitBytesPerSecond(int bytes)
           
 void setHaveAggregationEnabled(boolean enabled)
           
 void setLastPiece(int pieceNumber)
           
 void setOptimisticUnchoke(boolean is_optimistic)
           
 void setPriorityConnection(boolean is_priority)
           
 void setSnubbed(boolean b)
           
 void setSuspendedLazyBitFieldEnabled(boolean enable)
          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
 void setTaggableTransientProperty(String key, Object value)
           
 void setUniqueAnnounce(int _uniquePiece)
           
 void setUploadDisabled(Object key, boolean disabled)
           
 void setUploadHint(int spreadTime)
           
 void setUploadRateLimitBytesPerSecond(int bytes)
           
 void setUserData(Object key, Object value)
          To store arbitrary objects against a peer.
 void start()
          Start message processing for the peer
 boolean supportsMessaging()
          Whether or not this peer supports the advanced messaging API.
 String toString()
           
 boolean transferAvailable()
           
 void updateAutoUploadPriority(Object key, boolean inc)
           
 void updatePeerExchange()
          Do any peer exchange processing/updating.
 
Methods inherited from class org.gudy.azureus2.core3.logging.LogRelation
propogatedRelationText, queryForClass, queryForClass
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOGID

protected static final LogIDs LOGID

manager

protected final PEPeerControl manager

diskManager

protected final DiskManager diskManager

piecePicker

protected final PiecePicker piecePicker

nbPieces

protected final int nbPieces

ip_resolved

protected String ip_resolved

peer_stats

protected PEPeerStats peer_stats

choking_other_peer

protected boolean choking_other_peer

closing

protected volatile boolean closing

connection_state

protected int connection_state

ENABLE_LAZY_BITFIELD

protected static boolean ENABLE_LAZY_BITFIELD

message_limiter

protected PeerMessageLimiter message_limiter
Constructor Detail

PEPeerTransportProtocol

public PEPeerTransportProtocol(PEPeerControl _manager,
                               String _peer_source,
                               NetworkConnection _connection,
                               Map _initial_user_data)

PEPeerTransportProtocol

public PEPeerTransportProtocol(PEPeerControl _manager,
                               String _peer_source,
                               String _ip,
                               int _tcp_port,
                               int _udp_port,
                               boolean _use_tcp,
                               boolean _require_crypto_handshake,
                               byte _crypto_level,
                               Map _initial_user_data)
Method Detail

start

public void start()
Description copied from interface: PEPeerTransport
Start message processing for the peer

Specified by:
start in interface PEPeerTransport

initializeConnection

protected void initializeConnection()

getPeerSource

public String getPeerSource()
Specified by:
getPeerSource in interface PEPeer

closeConnectionInternally

protected void closeConnectionInternally(String reason,
                                         boolean connect_failed,
                                         boolean network_failure)
Close the peer connection from within the PEPeerTransport object.

Parameters:
reason -

closeConnectionInternally

protected void closeConnectionInternally(String reason)

closeConnection

public void closeConnection(String reason)
Close the peer connection from the PEPeerControl manager side. NOTE: This method assumes PEPeerControl already knows about the close. This method is inteded to be only invoked by select administrative methods. You probably should not invoke this directly.

Specified by:
closeConnection in interface PEPeerTransport
Parameters:
reason - for closure

isClosed

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

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

sendBTHandshake

protected void sendBTHandshake()

getPeerState

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

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

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

transferAvailable

public boolean transferAvailable()
Specified by:
transferAvailable in interface PEPeerTransport
Specified by:
transferAvailable in interface PEPeer

request

public DiskManagerReadRequest request(int pieceNumber,
                                      int pieceOffset,
                                      int pieceLength,
                                      boolean return_duplicates)
Specified by:
request in interface PEPeerTransport
return_duplicates - - if true and request already exists it will be returned, if false -> null
Returns:
request if actually requested, null otherwise

getRequestIndex

public int getRequestIndex(DiskManagerReadRequest request)
Description copied from interface: PEPeerTransport
Returns the index of this request in the peer's queue or -1 if not found

Specified by:
getRequestIndex in interface PEPeerTransport
Returns:

sendCancel

public void sendCancel(DiskManagerReadRequest request)
Specified by:
sendCancel in interface PEPeerTransport

sendHave

public void sendHave(int pieceNumber)
Specified by:
sendHave in interface PEPeerTransport

sendChoke

public void sendChoke()
Specified by:
sendChoke in interface PEPeerTransport
Specified by:
sendChoke in interface PEPeer

sendUnChoke

public void sendUnChoke()
Specified by:
sendUnChoke in interface PEPeerTransport
Specified by:
sendUnChoke in interface PEPeer

checkInterested

public void checkInterested()
Global checkInterested method. Early-out scan of pieces to determine if the peer is interesting or not. They're interesting if they have a piece that we Need and isn't Done

Specified by:
checkInterested in interface PEPeerTransport

sendLazyHaves

protected void sendLazyHaves(int[] lazy_haves,
                             boolean immediate)

getId

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

getIp

public String getIp()
Specified by:
getIp in interface PEPeer

getAlternativeIPv6

public 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

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:

getClient

public String getClient()
Specified by:
getClient in interface PEPeer

isIncoming

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

isOptimisticUnchoke

public boolean isOptimisticUnchoke()
Specified by:
isOptimisticUnchoke in interface PEPeer

setOptimisticUnchoke

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

getControl

public PEPeerControl getControl()
Specified by:
getControl in interface PEPeerTransport

getManager

public PEPeerManager getManager()
Specified by:
getManager in interface PEPeer

getStats

public PEPeerStats getStats()
Specified by:
getStats in interface PEPeer

getPriorityOffsets

public int[] getPriorityOffsets()
Description copied from interface: PEPeerTransport
Any priority offsets this peer has, or null if none

Specified by:
getPriorityOffsets 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

requestAllocationComplete

public void requestAllocationComplete()
Specified by:
requestAllocationComplete in interface PEPeerTransport

getAvailable

public BitFlags getAvailable()
Specified by:
getAvailable in interface PEPeer
Returns:
null if no bitfield has been recieved yet else returns BitFlags indicating what pieces the peer has

isPieceAvailable

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

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

isUnchokeOverride

public boolean isUnchokeOverride()
Specified by:
isUnchokeOverride in interface PEPeer

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 the peer is interesting to us

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 what we're offering

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

getSnubbedTime

public long getSnubbedTime()
Specified by:
getSnubbedTime in interface PEPeer

setSnubbed

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

setUploadHint

public void setUploadHint(int spreadTime)
Specified by:
setUploadHint in interface PEPeer

getUploadHint

public int getUploadHint()
Specified by:
getUploadHint in interface PEPeer

setUniqueAnnounce

public void setUniqueAnnounce(int _uniquePiece)
Specified by:
setUniqueAnnounce in interface PEPeer

getUniqueAnnounce

public int getUniqueAnnounce()
Specified by:
getUniqueAnnounce in interface PEPeer

getData

public Object getData(String key)
Description copied from interface: PEPeer
To retreive arbitrary objects against a peer.

Specified by:
getData in interface PEPeer

setData

public void setData(String key,
                    Object value)
Description copied from interface: PEPeer
To store arbitrary objects against a peer.

Specified by:
setData in interface PEPeer

getUserData

public Object getUserData(Object key)
To retreive arbitrary objects against a peer.

Specified by:
getUserData in interface PEPeer

setUserData

public void setUserData(Object key,
                        Object value)
To store arbitrary objects against a peer.

Specified by:
setUserData in interface PEPeer

getIPHostName

public 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

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:

getNbRequests

public int getNbRequests()
Specified by:
getNbRequests in interface PEPeerTransport

getExpiredRequests

public List getExpiredRequests()
Specified by:
getExpiredRequests in interface PEPeerTransport
Returns:
may be null for performance purposes

removeRequest

protected void removeRequest(DiskManagerReadRequest request)

toString

public String toString()
Overrides:
toString in class Object

getString

public String getString()

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

updateAutoUploadPriority

public void updateAutoUploadPriority(Object key,
                                     boolean inc)
Specified by:
updateAutoUploadPriority in interface PEPeer

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

getConnectionState

public int getConnectionState()
Description copied from interface: PEPeerTransport
Get the specific peer connection state.

Specified by:
getConnectionState in interface PEPeerTransport
Returns:
connection state

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

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

getConsecutiveNoRequestCount

public int getConsecutiveNoRequestCount()
Specified by:
getConsecutiveNoRequestCount in interface PEPeer

setConsecutiveNoRequestCount

public void setConsecutiveNoRequestCount(int num)
Specified by:
setConsecutiveNoRequestCount in interface PEPeer

decodeBTHandshake

protected void decodeBTHandshake(BTHandshake handshake)

decodeLTHandshake

protected void decodeLTHandshake(LTHandshake handshake)

decodeAZHandshake

protected void decodeAZHandshake(AZHandshake handshake)

decodeHaveAll

protected void decodeHaveAll(BTHaveAll have_all)

decodeHaveNone

protected void decodeHaveNone(BTHaveNone have_none)

decodeBitfield

protected void decodeBitfield(BTBitfield bitfield)

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

decodeMainlineDHTPort

protected void decodeMainlineDHTPort(BTDHTPort port)

decodeChoke

protected void decodeChoke(BTChoke choke)

decodeUnchoke

protected void decodeUnchoke(BTUnchoke unchoke)

decodeInterested

protected void decodeInterested(BTInterested interested)

decodeUninterested

protected void decodeUninterested(BTUninterested uninterested)

decodeHave

protected void decodeHave(BTHave have)

decodeAZHave

protected void decodeAZHave(AZHave have)

getBytesDownloaded

protected long getBytesDownloaded()

getBytesRemaining

public long getBytesRemaining()
Specified by:
getBytesRemaining in interface PEPeer

sendBadPiece

public void sendBadPiece(int piece_number)
Specified by:
sendBadPiece in interface PEPeerTransport

decodeAZBadPiece

protected void decodeAZBadPiece(AZBadPiece bad_piece)

sendStatsRequest

public void sendStatsRequest(Map request)
Specified by:
sendStatsRequest in interface PEPeerTransport
Specified by:
sendStatsRequest in interface PEPeer

decodeAZStatsRequest

protected void decodeAZStatsRequest(AZStatRequest request)

sendStatsReply

public void sendStatsReply(Map reply)
Specified by:
sendStatsReply in interface PEPeerTransport

decodeAZStatsReply

protected void decodeAZStatsReply(AZStatReply reply)

decodeRequest

protected void decodeRequest(BTRequest request)

sendRejectRequest

public void sendRejectRequest(DiskManagerReadRequest request)
Specified by:
sendRejectRequest in interface PEPeer

decodePiece

protected void decodePiece(BTPiece piece)

decodeCancel

protected void decodeCancel(BTCancel cancel)

decodeRejectRequest

protected void decodeRejectRequest(BTRejectRequest reject)

calculatePiecePriorities

protected void calculatePiecePriorities()

checkFast

protected void checkFast(BitFlags flags)

addRateLimiter

public void addRateLimiter(LimitedRateGroup limiter,
                           boolean upload)
Specified by:
addRateLimiter in interface PEPeer

getRateLimiters

public LimitedRateGroup[] getRateLimiters(boolean upload)
Specified by:
getRateLimiters in interface PEPeer

removeRateLimiter

public void removeRateLimiter(LimitedRateGroup limiter,
                              boolean upload)
Specified by:
removeRateLimiter in interface PEPeer

setUploadDisabled

public void setUploadDisabled(Object key,
                              boolean disabled)
Specified by:
setUploadDisabled in interface PEPeer

setDownloadDisabled

public void setDownloadDisabled(Object key,
                                boolean disabled)
Specified by:
setDownloadDisabled in interface PEPeer

isUploadDisabled

public boolean isUploadDisabled()
Specified by:
isUploadDisabled in interface PEPeer

isUploadDisabled

public boolean isUploadDisabled(Object key)

isDownloadDisabled

public boolean isDownloadDisabled()
Specified by:
isDownloadDisabled in interface PEPeer

isDownloadDisabled

public boolean isDownloadDisabled(Object key)

getPluginConnection

public Connection getPluginConnection()
Description copied from interface: PEPeer
Get the connection that backs this peer.

Specified by:
getPluginConnection in interface PEPeer
Returns:
connection

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

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

getMessagingMode

public int getMessagingMode()
Specified by:
getMessagingMode in interface PEPeer

getHandshakeReservedBytes

public byte[] getHandshakeReservedBytes()
Specified by:
getHandshakeReservedBytes in interface PEPeer

setHaveAggregationEnabled

public void setHaveAggregationEnabled(boolean enabled)
Specified by:
setHaveAggregationEnabled in interface PEPeer

hasReceivedBitField

public boolean hasReceivedBitField()
Specified by:
hasReceivedBitField in interface PEPeer

getUnchokedForMillis

public long getUnchokedForMillis()
Specified by:
getUnchokedForMillis in interface PEPeerTransport

getLatency

public long getLatency()
Specified by:
getLatency in interface PEPeerTransport

getEncryption

public String getEncryption()
Description copied from interface: PEPeer
Returns name of encryption used by the peer

Specified by:
getEncryption in interface PEPeer
Returns:

getProtocol

public String getProtocol()
Specified by:
getProtocol in interface PEPeer

getProtocolQualifier

public String getProtocolQualifier()
Specified by:
getProtocolQualifier in interface PEPeer

addListener

public void addListener(PEPeerListener listener)
Description copied from interface: PEPeer
Add peer listener.

Specified by:
addListener in interface PEPeer

removeListener

public void removeListener(PEPeerListener listener)
Description copied from interface: PEPeer
Remove peer listener.

Specified by:
removeListener in interface PEPeer

updatePeerExchange

public void updatePeerExchange()
Description copied from interface: PEPeerTransport
Do any peer exchange processing/updating.

Specified by:
updatePeerExchange in interface PEPeerTransport

decodePeerExchange

protected void decodePeerExchange(AZStylePeerExchange exchange)

decodeMetaData

protected void decodeMetaData(AZUTMetaData metadata)

decodeUploadOnly

protected void decodeUploadOnly(UTUploadOnly message)

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

decodeSuggestPiece

protected void decodeSuggestPiece(BTSuggestPiece hint)

decodeAZRequestHint

protected void decodeAZRequestHint(AZRequestHint hint)

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

clearRequestHint

public void clearRequestHint()
Specified by:
clearRequestHint in interface PEPeer

getPeerItemIdentity

public PeerItem getPeerItemIdentity()
Description copied from interface: PEPeerTransport
Get the peer's address + port identification item.

Specified by:
getPeerItemIdentity in interface PEPeerTransport
Returns:
id

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

removeReservedPieceNumber

public void removeReservedPieceNumber(int piece_number)
Specified by:
removeReservedPieceNumber in interface PEPeer

getIncomingRequestCount

public int getIncomingRequestCount()
Specified by:
getIncomingRequestCount in interface PEPeer

getOutgoingRequestCount

public int getOutgoingRequestCount()
Specified by:
getOutgoingRequestCount in interface PEPeer

getOutboundDataQueueSize

public int getOutboundDataQueueSize()
Description copied from interface: PEPeer
amount of data queued for delivery to peer

Specified by:
getOutboundDataQueueSize in interface PEPeer
Returns:

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:

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

getPercentDoneOfCurrentIncomingRequest

public int getPercentDoneOfCurrentIncomingRequest()
Specified by:
getPercentDoneOfCurrentIncomingRequest in interface PEPeer

getPercentDoneOfCurrentOutgoingRequest

public int getPercentDoneOfCurrentOutgoingRequest()
Specified by:
getPercentDoneOfCurrentOutgoingRequest in interface PEPeer

getLastMessageSentTime

public long getLastMessageSentTime()
Specified by:
getLastMessageSentTime in interface PEPeerTransport

getRelationText

public String getRelationText()
Description copied from class: LogRelation
A short description of what your class holds that can be printed by the logger

Overrides:
getRelationText in class LogRelation
Returns:

getQueryableInterfaces

public Object[] getQueryableInterfaces()
Description copied from class: LogRelation
Query this class for a reference to another class that it may hold

Overrides:
getQueryableInterfaces in class LogRelation
Returns:
If found, the class desired. Otherwise, null.

getLastPiece

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

setLastPiece

public void setLastPiece(int pieceNumber)
Specified by:
setLastPiece 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 PEPeerTransport
Specified by:
isLANLocal in interface PEPeer
Returns:
true if within LAN, false of outside the LAN segment

isTCP

public boolean isTCP()
Specified by:
isTCP in interface PEPeerTransport

getNetwork

public String getNetwork()
Specified by:
getNetwork in interface PEPeerTransport

setUploadRateLimitBytesPerSecond

public void setUploadRateLimitBytesPerSecond(int bytes)
Specified by:
setUploadRateLimitBytesPerSecond in interface PEPeer

getUploadRateLimitBytesPerSecond

public int getUploadRateLimitBytesPerSecond()
Specified by:
getUploadRateLimitBytesPerSecond in interface PEPeer

setDownloadRateLimitBytesPerSecond

public void setDownloadRateLimitBytesPerSecond(int bytes)
Specified by:
setDownloadRateLimitBytesPerSecond in interface PEPeer

getDownloadRateLimitBytesPerSecond

public int getDownloadRateLimitBytesPerSecond()
Specified by:
getDownloadRateLimitBytesPerSecond in interface PEPeer

getClientNameFromPeerID

public String getClientNameFromPeerID()
Specified by:
getClientNameFromPeerID in interface PEPeer

getClientNameFromExtensionHandshake

public String getClientNameFromExtensionHandshake()
Specified by:
getClientNameFromExtensionHandshake in interface PEPeer

setPriorityConnection

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

isPriorityConnection

public boolean isPriorityConnection()
Specified by:
isPriorityConnection in interface PEPeer

generateFastSet

protected List<Integer> generateFastSet(byte[] hash,
                                        String ip,
                                        int num_pieces,
                                        int num_required)

generateFastSet

protected List<Integer> generateFastSet(int num)

getTaggableType

public int getTaggableType()

getTaggableID

public String getTaggableID()

getTaggableResolver

public TaggableResolver getTaggableResolver()

getTaggableTransientProperty

public Object getTaggableTransientProperty(String key)

setTaggableTransientProperty

public void setTaggableTransientProperty(String key,
                                         Object value)

generateEvidence

public void generateEvidence(IndentWriter writer)
Specified by:
generateEvidence in interface PEPeerTransport