Package org.klomp.snark
Class WebPeer
- java.lang.Object
- 
- org.klomp.snark.Peer
- 
- org.klomp.snark.WebPeer
 
 
- 
- All Implemented Interfaces:
- Comparable<Peer>,- EepGet.StatusListener
 
 class WebPeer extends Peer implements EepGet.StatusListener BEP 19. Does not have an associated PeerState. All request tracking is done here.- Since:
- 0.9.49
 
- 
- 
Field SummaryFields Modifier and Type Field Description static byte[]IDBytes- 
Fields inherited from class org.klomp.snark.Peer_log, CHECK_PERIOD, magnetState, metainfo, RATE_DEPTH, state
 
- 
 - 
Constructor SummaryConstructors Constructor Description WebPeer(PeerCoordinator coord, URI uri, PeerID peerID, MetaInfo metainfo)Outgoing connection.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidattemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause)voidattempting(String url)voidbytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url)Total length should be == alreadyTransferred + currentWrite + bytesRemaining for all calls(package private) voidcancel(int piece)Tell the other side that we are no longer interested in any of the outstanding requests (if any) for this piece.intcompleted()Return how much the peer has(package private) voiddisconnect()booleanequals(Object o)Two Peers are equal when they have the same PeerID.longgetInactiveTime()longgetMaxInactiveTime()intgetMaxPipeline()StringgetSocket()inthashCode()The hash code of a Peer is the hash code of the peerID.voidhave(int piece)Tell the peer we have another piece.voidheaderReceived(String url, int attemptNum, String key, String val)Note: Headers are not processed, and this is not called, for most error response codes, unless setWriteErrorToOutput() is called before fetch().booleanisChoked()Whether or not the peer choked us.booleanisChoking()Whether or not we are choking the peer.booleanisCompleted()Return if a peer is a seederbooleanisConnected()booleanisInterested()Whether or not the peer is interested in pieces we have.booleanisInteresting()Whether or not the peer has pieces we want from it.booleanisWebPeer()voidkeepAlive()Send keepalive(package private) voidrequest()Update the request queue.voidretransmitRequests()Retransmit outstanding requests if necessaryvoidrunConnection(I2PSnarkUtil util, PeerListener listener, BitField ignore, MagnetState mState, boolean uploadOnly)Runs the connection to the other peer.voidsetChoking(boolean choke)Sets whether or not we are choking the peer.voidsetInteresting(boolean interest)Deprecated.StringtoString()Returns the String representation of the peerID.voidtransferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified)voidtransferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt)- 
Methods inherited from class org.klomp.snark.PeercompareTo, disconnect, downloaded, getDestination, getDownloaded, getDownloadRate, getHandshakeMap, getMagnetState, getPeerID, getTotalCommentsSent, getUploaded, getUploadRate, isIncoming, isRequesting, resetCounters, sendExtension, setHandshakeMap, setMetaInfo, setRateHistory, setTotalCommentsSent, supportsFast, uploaded
 
- 
 
- 
- 
- 
Constructor Detail- 
WebPeerpublic WebPeer(PeerCoordinator coord, URI uri, PeerID peerID, MetaInfo metainfo) Outgoing connection. Creates a disconnected peer given a PeerID, your own id and the relevant MetaInfo.- Parameters:
- uri- must be http with .i2p host
- metainfo- non-null
 
 
- 
 - 
Method Detail- 
toStringpublic String toString() Description copied from class:PeerReturns the String representation of the peerID.
 - 
getSocketpublic String getSocket() 
 - 
hashCodepublic int hashCode() The hash code of a Peer is the hash code of the peerID.
 - 
equalspublic boolean equals(Object o) Two Peers are equal when they have the same PeerID. All other properties are ignored.
 - 
runConnectionpublic void runConnection(I2PSnarkUtil util, PeerListener listener, BitField ignore, MagnetState mState, boolean uploadOnly) Runs the connection to the other peer. This method does not return until the connection is terminated.- Overrides:
- runConnectionin class- Peer
- Parameters:
- ignore- our bitfield, ignore
- uploadOnly- if we are complete with skipped files, i.e. a partial seed
 
 - 
getMaxPipelinepublic int getMaxPipeline() - Overrides:
- getMaxPipelinein class- Peer
- Returns:
- min of PeerState.MIN_PIPELINE, max of PeerState.MAX_PIPELINE
 
 - 
isConnectedpublic boolean isConnected() - Overrides:
- isConnectedin class- Peer
 
 - 
disconnectvoid disconnect() - Overrides:
- disconnectin class- Peer
 
 - 
havepublic void have(int piece) Description copied from class:PeerTell the peer we have another piece.
 - 
cancelvoid cancel(int piece) Description copied from class:PeerTell the other side that we are no longer interested in any of the outstanding requests (if any) for this piece.
 - 
requestvoid request() Description copied from class:PeerUpdate the request queue. Call after adding wanted pieces.
 - 
isInterestedpublic boolean isInterested() Description copied from class:PeerWhether or not the peer is interested in pieces we have. Returns false if not connected.- Overrides:
- isInterestedin class- Peer
 
 - 
setInteresting@Deprecated public void setInteresting(boolean interest) Deprecated.Description copied from class:PeerSets whether or not we are interested in pieces from this peer. Defaults to false. When interest is true and this peer unchokes us then we start downloading from it. Has no effect when not connected.- Overrides:
- setInterestingin class- Peer
 
 - 
isInterestingpublic boolean isInteresting() Description copied from class:PeerWhether or not the peer has pieces we want from it. Returns false if not connected.- Overrides:
- isInterestingin class- Peer
 
 - 
setChokingpublic void setChoking(boolean choke) Description copied from class:PeerSets whether or not we are choking the peer. Defaults to true. When choke is false and the peer requests some pieces we upload them, otherwise requests of this peer are ignored.- Overrides:
- setChokingin class- Peer
 
 - 
isChokingpublic boolean isChoking() Description copied from class:PeerWhether or not we are choking the peer. Returns true when not connected.
 - 
isChokedpublic boolean isChoked() Description copied from class:PeerWhether or not the peer choked us. Returns true when not connected.
 - 
getInactiveTimepublic long getInactiveTime() - Overrides:
- getInactiveTimein class- Peer
 
 - 
getMaxInactiveTimepublic long getMaxInactiveTime() - Overrides:
- getMaxInactiveTimein class- Peer
 
 - 
keepAlivepublic void keepAlive() Description copied from class:PeerSend keepalive
 - 
retransmitRequestspublic void retransmitRequests() Description copied from class:PeerRetransmit outstanding requests if necessary- Overrides:
- retransmitRequestsin class- Peer
 
 - 
completedpublic int completed() Description copied from class:PeerReturn how much the peer has
 - 
isCompletedpublic boolean isCompleted() Description copied from class:PeerReturn if a peer is a seeder- Overrides:
- isCompletedin class- Peer
 
 - 
bytesTransferredpublic void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url)Description copied from interface:EepGet.StatusListenerTotal length should be == alreadyTransferred + currentWrite + bytesRemaining for all calls- Specified by:
- bytesTransferredin interface- EepGet.StatusListener
- Parameters:
- alreadyTransferred- total of all attempts, not including currentWrite If nonzero on the first call, a partial file of that length was found, _and_ the server supports resume. If zero on a subsequent call after some bytes are transferred (and presumably after an attemptFailed), the server does _not_ support resume and we had to start over. To track _actual_ transfer if the output file could already exist, the listener should keep its own counter, or subtract the initial alreadyTransferred value. And watch out for alreadyTransferred resetting if a resume failed...
- currentWrite- since last call to the listener
- bytesTransferred- includes headers, retries, redirects, discarded partial downloads, ...
- bytesRemaining- on this attempt only, currentWrite already subtracted - or -1 if chunked encoding or server does not return a length
 
 - 
attemptFailedpublic void attemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause) - Specified by:
- attemptFailedin interface- EepGet.StatusListener
- See Also:
- EepGet.StatusListener.bytesTransferred(long, int, long, long, java.lang.String)
 
 - 
transferCompletepublic void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified)- Specified by:
- transferCompletein interface- EepGet.StatusListener
- outputFile- null if unknown (output stream constructor)
- See Also:
- EepGet.StatusListener.bytesTransferred(long, int, long, long, java.lang.String)
 
 - 
transferFailedpublic void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt) - Specified by:
- transferFailedin interface- EepGet.StatusListener
- See Also:
- EepGet.StatusListener.bytesTransferred(long, int, long, long, java.lang.String)
 
 - 
headerReceivedpublic void headerReceived(String url, int attemptNum, String key, String val) Description copied from interface:EepGet.StatusListenerNote: Headers are not processed, and this is not called, for most error response codes, unless setWriteErrorToOutput() is called before fetch(). To be changed?- Specified by:
- headerReceivedin interface- EepGet.StatusListener
 
 - 
attemptingpublic void attempting(String url) - Specified by:
- attemptingin interface- EepGet.StatusListener
 
 
- 
 
-