Package com.biglybt.pifimpl.local.peers
Class PeerImpl
- java.lang.Object
-
- com.biglybt.core.logging.LogRelation
-
- com.biglybt.pifimpl.local.peers.PeerImpl
-
- All Implemented Interfaces:
Peer
public class PeerImpl extends LogRelation implements Peer
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
closed
protected PEPeer
delegate
private UtilitiesImpl.PluginLimitedRateGroupListener
down_rg_listener
protected PeerManagerImpl
manager
private java.util.HashMap<PeerListener2,PEPeerListener>
peer_listeners
private UtilitiesImpl.PluginLimitedRateGroupListener
up_rg_listener
-
Fields inherited from interface com.biglybt.pif.peers.Peer
CLOSING, CONNECTING, DISCONNECTED, HANDSHAKING, PR_FORCE_CONNECTION, PR_PRIORITY_CONNECTION, PR_PROTOCOL, PR_PROTOCOL_QUALIFIER, TRANSFERING
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(PeerListener2 l)
Add peer listener.void
addRateLimiter(RateLimiter limiter, boolean is_upload)
boolean
addRequest(PeerReadRequest request)
void
bindConnection(ConnectionStub stub)
void
cancelRequest(PeerReadRequest request)
void
close(java.lang.String reason, boolean closedOnError, boolean attemptReconnect)
protected void
closed()
private void
createRGListeners()
boolean
equals(java.lang.Object other)
boolean[]
getAvailable()
java.lang.String
getClient()
Connection
getConnection()
Get the network connection that backs this peer.PEPeer
getDelegate()
java.util.List
getExpiredRequests()
byte[]
getHandshakeReservedBytes()
byte[]
getId()
java.lang.String
getIp()
Get the peer's local TCP connection port.PeerManager
getManager()
int
getMaximumNumberOfRequests()
int
getNumberOfRequests()
int
getOutgoingRequestCount()
int[]
getOutgoingRequestedPieceNumbers()
PEPeer
getPEPeer()
Core use only.int
getPercentDoneInThousandNotation()
int
getPercentDoneOfCurrentIncomingRequest()
int
getPercentDoneOfCurrentOutgoingRequest()
int
getPort()
int[]
getPriorityOffsets()
java.lang.Object[]
getQueryableInterfaces()
Query this class for a reference to another class that it may holdRateLimiter[]
getRateLimiters(boolean is_upload)
java.lang.String
getRelationText()
A short description of what your class holds that can be printed by the loggerjava.util.List
getRequests()
long
getSnubbedTime()
int
getState()
PeerStats
getStats()
Message[]
getSupportedMessages()
Get the list of messages that this peer and us mutually understand.int
getTCPListenPort()
Get the TCP port this peer is listening for incoming connections on.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 connectionsjava.lang.Object
getUserData(java.lang.Object key)
int
hashCode()
void
initialize()
boolean
isChoked()
boolean
isChoking()
boolean
isDownloadPossible()
This is much list isTransferAvailable(), except is more comprehensive.boolean
isIncoming()
boolean
isInterested()
boolean
isInteresting()
boolean
isLANLocal()
boolean
isMyPeer()
boolean
isOptimisticUnchoke()
boolean
isPieceAvailable(int pieceNumber)
boolean
isPriorityConnection()
boolean
isSeed()
boolean
isSnubbed()
boolean
isTransferAvailable()
int
readBytes(int max)
Rate control - gives the maximum number of bytes that can be read from this connection at this time and returns the actual number readvoid
removeListener(PeerListener2 l)
Remove peer listener.void
removeRateLimiter(RateLimiter limiter, boolean is_upload)
void
requestAllocationComplete()
boolean
requestAllocationStarts(int[] base_priorities)
void
resetLANLocalStatus()
void
setOptimisticUnchoke(boolean is_optimistic)
void
setPriorityConnection(boolean is_priority)
void
setSnubbed(boolean b)
void
setUserData(java.lang.Object key, java.lang.Object value)
boolean
supportsMessaging()
Whether or not this peer supports the advanced messaging API.int
writeBytes(int max)
-
Methods inherited from class com.biglybt.core.logging.LogRelation
propogatedRelationText, queryForClass
-
-
-
-
Field Detail
-
manager
protected PeerManagerImpl manager
-
delegate
protected PEPeer delegate
-
peer_listeners
private java.util.HashMap<PeerListener2,PEPeerListener> peer_listeners
-
up_rg_listener
private UtilitiesImpl.PluginLimitedRateGroupListener up_rg_listener
-
down_rg_listener
private UtilitiesImpl.PluginLimitedRateGroupListener down_rg_listener
-
closed
private volatile boolean closed
-
-
Constructor Detail
-
PeerImpl
protected PeerImpl(PEPeer _delegate)
don't use me, use PeerManagerImpl.getPeerForPEPeer- Parameters:
_delegate
-
-
-
Method Detail
-
bindConnection
public void bindConnection(ConnectionStub stub)
- Specified by:
bindConnection
in interfacePeer
-
getManager
public PeerManager getManager()
- Specified by:
getManager
in interfacePeer
-
getDelegate
public PEPeer getDelegate()
-
getConnection
public Connection getConnection()
Description copied from interface:Peer
Get the network connection that backs this peer.- Specified by:
getConnection
in interfacePeer
- Returns:
- connection
-
supportsMessaging
public boolean supportsMessaging()
Description copied from interface:Peer
Whether or not this peer supports the advanced messaging API.- Specified by:
supportsMessaging
in interfacePeer
- Returns:
- true if extended messaging is supported, false if not
-
getSupportedMessages
public Message[] getSupportedMessages()
Description copied from interface:Peer
Get the list of messages that this peer and us mutually understand.- Specified by:
getSupportedMessages
in interfacePeer
- Returns:
- messages available for use, or null of supported is yet unknown
-
getIp
public java.lang.String getIp()
Description copied from interface:Peer
Get the peer's local TCP connection port.
-
getTCPListenPort
public int getTCPListenPort()
Description copied from interface:Peer
Get the TCP port this peer is listening for incoming connections on.- Specified by:
getTCPListenPort
in interfacePeer
- Returns:
- TCP port, or 0 if port is unknown
-
getUDPListenPort
public int getUDPListenPort()
Description copied from interface:Peer
Get the UDP port this peer is listening for incoming connections on.- Specified by:
getUDPListenPort
in interfacePeer
- Returns:
- UDP port, or 0 if port is unknown
-
getUDPNonDataListenPort
public int getUDPNonDataListenPort()
Description copied from interface:Peer
Get the UDP port this peer is listening on for non-data connections- Specified by:
getUDPNonDataListenPort
in interfacePeer
- Returns:
-
isLANLocal
public boolean isLANLocal()
- Specified by:
isLANLocal
in interfacePeer
-
resetLANLocalStatus
public void resetLANLocalStatus()
- Specified by:
resetLANLocalStatus
in interfacePeer
-
getAvailable
public final boolean[] getAvailable()
- Specified by:
getAvailable
in interfacePeer
-
isPieceAvailable
public boolean isPieceAvailable(int pieceNumber)
- Specified by:
isPieceAvailable
in interfacePeer
- Parameters:
pieceNumber
- int- Returns:
- true if this peers makes this piece available
-
isTransferAvailable
public boolean isTransferAvailable()
- Specified by:
isTransferAvailable
in interfacePeer
-
isDownloadPossible
public boolean isDownloadPossible()
Description copied from interface:Peer
This is much list isTransferAvailable(), except is more comprehensive. That is; it checks a few more factors, within the object for speed, so that a more timely status is considered and the caller doesn't need to try to check each thing on it's own.- Specified by:
isDownloadPossible
in interfacePeer
- Returns:
- true if several factors say downloading can be tried.
-
isInterested
public boolean isInterested()
- Specified by:
isInterested
in interfacePeer
-
isInteresting
public boolean isInteresting()
- Specified by:
isInteresting
in interfacePeer
-
getSnubbedTime
public long getSnubbedTime()
- Specified by:
getSnubbedTime
in interfacePeer
-
setSnubbed
public void setSnubbed(boolean b)
- Specified by:
setSnubbed
in interfacePeer
-
isIncoming
public boolean isIncoming()
- Specified by:
isIncoming
in interfacePeer
-
getOutgoingRequestCount
public int getOutgoingRequestCount()
- Specified by:
getOutgoingRequestCount
in interfacePeer
-
getOutgoingRequestedPieceNumbers
public int[] getOutgoingRequestedPieceNumbers()
- Specified by:
getOutgoingRequestedPieceNumbers
in interfacePeer
-
getPercentDoneInThousandNotation
public int getPercentDoneInThousandNotation()
- Specified by:
getPercentDoneInThousandNotation
in interfacePeer
-
isOptimisticUnchoke
public boolean isOptimisticUnchoke()
- Specified by:
isOptimisticUnchoke
in interfacePeer
-
setOptimisticUnchoke
public void setOptimisticUnchoke(boolean is_optimistic)
- Specified by:
setOptimisticUnchoke
in interfacePeer
-
initialize
public void initialize()
-
getExpiredRequests
public java.util.List getExpiredRequests()
- Specified by:
getExpiredRequests
in interfacePeer
-
getRequests
public java.util.List getRequests()
- Specified by:
getRequests
in interfacePeer
-
getNumberOfRequests
public int getNumberOfRequests()
- Specified by:
getNumberOfRequests
in interfacePeer
-
getMaximumNumberOfRequests
public int getMaximumNumberOfRequests()
- Specified by:
getMaximumNumberOfRequests
in interfacePeer
-
getPriorityOffsets
public int[] getPriorityOffsets()
- Specified by:
getPriorityOffsets
in interfacePeer
-
requestAllocationStarts
public boolean requestAllocationStarts(int[] base_priorities)
- Specified by:
requestAllocationStarts
in interfacePeer
-
requestAllocationComplete
public void requestAllocationComplete()
- Specified by:
requestAllocationComplete
in interfacePeer
-
cancelRequest
public void cancelRequest(PeerReadRequest request)
- Specified by:
cancelRequest
in interfacePeer
-
addRequest
public boolean addRequest(PeerReadRequest request)
- Specified by:
addRequest
in interfacePeer
-
createRGListeners
private void createRGListeners()
-
addRateLimiter
public void addRateLimiter(RateLimiter limiter, boolean is_upload)
- Specified by:
addRateLimiter
in interfacePeer
- Parameters:
limiter
- create via ConnectionManageris_upload
- false -> download limit
-
removeRateLimiter
public void removeRateLimiter(RateLimiter limiter, boolean is_upload)
- Specified by:
removeRateLimiter
in interfacePeer
-
getRateLimiters
public RateLimiter[] getRateLimiters(boolean is_upload)
- Specified by:
getRateLimiters
in interfacePeer
-
close
public void close(java.lang.String reason, boolean closedOnError, boolean attemptReconnect)
-
readBytes
public int readBytes(int max)
Description copied from interface:Peer
Rate control - gives the maximum number of bytes that can be read from this connection at this time and returns the actual number read
-
writeBytes
public int writeBytes(int max)
- Specified by:
writeBytes
in interfacePeer
-
closed
protected void closed()
-
getPercentDoneOfCurrentIncomingRequest
public int getPercentDoneOfCurrentIncomingRequest()
- Specified by:
getPercentDoneOfCurrentIncomingRequest
in interfacePeer
-
getPercentDoneOfCurrentOutgoingRequest
public int getPercentDoneOfCurrentOutgoingRequest()
- Specified by:
getPercentDoneOfCurrentOutgoingRequest
in interfacePeer
-
addListener
public void addListener(PeerListener2 l)
Description copied from interface:Peer
Add peer listener.- Specified by:
addListener
in interfacePeer
-
removeListener
public void removeListener(PeerListener2 l)
Description copied from interface:Peer
Remove peer listener.- Specified by:
removeListener
in interfacePeer
-
isPriorityConnection
public boolean isPriorityConnection()
- Specified by:
isPriorityConnection
in interfacePeer
-
setPriorityConnection
public void setPriorityConnection(boolean is_priority)
- Specified by:
setPriorityConnection
in interfacePeer
-
setUserData
public void setUserData(java.lang.Object key, java.lang.Object value)
- Specified by:
setUserData
in interfacePeer
-
getUserData
public java.lang.Object getUserData(java.lang.Object key)
- Specified by:
getUserData
in interfacePeer
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
getPEPeer
public PEPeer getPEPeer()
Core use only. This is not propogated to the plugin interface- Returns:
- PEPeer object associated with the plugin Peer object
-
getRelationText
public java.lang.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 classLogRelation
- Returns:
-
getQueryableInterfaces
public java.lang.Object[] getQueryableInterfaces()
Description copied from class:LogRelation
Query this class for a reference to another class that it may hold- Overrides:
getQueryableInterfaces
in classLogRelation
- Returns:
- If found, the class desired. Otherwise, null.
-
getHandshakeReservedBytes
public byte[] getHandshakeReservedBytes()
- Specified by:
getHandshakeReservedBytes
in interfacePeer
-
-