class WebPeer extends Peer implements EepGet.StatusListener
| Modifier and Type | Field and Description |
|---|---|
static byte[] | IDBytesIDBytes. |
_log, CHECK_PERIOD, magnetState, metainfo, RATE_DEPTH, state| Constructor and Description |
|---|
WebPeer(PeerCoordinator coord,
URI uri,
PeerID peerID,
MetaInfo metainfo)Outgoing connection. |
| Modifier and Type | Method and Description |
|---|---|
void | attemptFailed(String url,
long bytesTransferred,
long bytesRemaining,
int currentAttempt,
int numRetries,
Exception cause)Attempt failed notification. |
void | attempting(String url)Called when a new attempt to fetch the URL is starting. |
void | bytesTransferred(long alreadyTransferred,
int currentWrite,
long bytesTransferred,
long bytesRemaining,
String url)Total length should be == alreadyTransferred + currentWrite + bytesRemaining for all calls. |
(package private) void | cancel(int piece)Tell the other side that we are no longer interested in any of the outstanding requests (if
any) for this piece. |
int | completed()completed. |
(package private) void | disconnect()Disconnects this peer, closing the socket and cleaning up state. |
void | downloaded(int size)Increments the download counter for this peer. |
boolean | equals(Object o)Two Peers are equal when they have the same PeerID. |
long | getInactiveTime()Returns the time in milliseconds since the last activity on either
the incoming or outgoing connection. |
long | getMaxInactiveTime() |
int | getMaxPipeline()Returns the maximum request pipeline depth negotiated with the peer. |
String | getSocket() |
int | hashCode()The hash code of a Peer is the hash code of the peerID. |
void | have(int piece)have. |
void | headerReceived(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(). |
boolean | isChoked()Whether or not the peer choked us. |
boolean | isChoking()Whether or not we are choking the peer. |
boolean | isCompleted()Return if a peer is a seeder. |
boolean | isConnected()Returns whether the peer is in active communication. |
boolean | isInterested()Whether or not the peer is interested in pieces we have. |
boolean | isInteresting()Whether or not the peer has pieces we want from it. |
boolean | isWebPeer()Returns whether this is a web peer. |
void | keepAlive()keepAlive. |
(package private) void | request()Update the request queue. |
void | retransmitRequests()retransmitRequests. |
void | runConnection(I2PSnarkUtil util,
PeerListener listener,
BandwidthListener bwl,
BitField ignore,
MagnetState mState,
boolean uploadOnly)Runs the connection to the other peer. |
void | setChoking(boolean choke)setChoking. |
boolean | shouldRequest(int size)Should we request this many bytes? |
String | toString()toString. |
void | transferComplete(long alreadyTransferred,
long bytesTransferred,
long bytesRemaining,
String url,
String outputFile,
boolean notModified)Transfer complete notification. |
void | transferFailed(String url,
long bytesTransferred,
long bytesRemaining,
int currentAttempt)Transfer failed notification. |
compareTo, disconnect, getDestination, getDownBWLimit, getDownloaded, getDownloadRate, getHandshakeMap, getMagnetState, getPeerID, getPexLastSent, getTotalCommentsSent, getUpBWLimit, getUploaded, getUploadRate, getWhenConnected, isIncoming, overDownBWLimit, overUpBWLimit, sendExtension, setHandshakeMap, setMetaInfo, setPexLastSent, setRateHistory, setTotalCommentsSent, shouldRequest, shouldSend, supportsFast, uploadedpublic WebPeer(PeerCoordinator coord, URI uri, PeerID peerID, MetaInfo metainfo)
uri - must be http with .i2p hostmetainfo - non-nullpublic void attemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause)
attemptFailed in interface EepGet.StatusListenerurl - the URLbytesTransferred - total transferredbytesRemaining - remainingcurrentAttempt - attempt indexnumRetries - retry limitcause - failure causeEepGet.StatusListener.bytesTransferred(long, int, long, long, java.lang.String)public void attempting(String url)
attempting in interface EepGet.StatusListenerurl - the URL being attemptedpublic void bytesTransferred(long alreadyTransferred,
int currentWrite,
long bytesTransferred,
long bytesRemaining,
String url)bytesTransferred in interface EepGet.StatusListeneralreadyTransferred - 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 listenerbytesTransferred - 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 lengthurl - the URL being fetchedvoid cancel(int piece)
Peerpublic int completed()
void disconnect()
Peerdisconnect in class Peerpublic void downloaded(int size)
downloaded in interface BandwidthListenerdownloaded in class Peersize - the number of bytes downloadedpublic boolean equals(Object o)
public long getInactiveTime()
PeergetInactiveTime in class Peerpublic long getMaxInactiveTime()
getMaxInactiveTime in class Peerpublic int getMaxPipeline()
PeergetMaxPipeline in class Peerpublic String getSocket()
public int hashCode()
public void headerReceived(String url, int attemptNum, String key, String val)
headerReceived in interface EepGet.StatusListenerurl - the URLattemptNum - attempt indexkey - header keyval - header valuepublic boolean isChoked()
Peerpublic boolean isChoking()
Peerpublic boolean isCompleted()
PeerisCompleted in class Peerpublic boolean isConnected()
PeerisConnected in class Peerpublic boolean isInterested()
PeerisInterested in class Peerpublic boolean isInteresting()
PeerisInteresting in class Peerpublic boolean isWebPeer()
void request()
Peerpublic void retransmitRequests()
retransmitRequests in class Peerpublic void runConnection(I2PSnarkUtil util, PeerListener listener, BandwidthListener bwl, BitField ignore, MagnetState mState, boolean uploadOnly)
runConnection in class Peerignore - our bitfield, ignoreuploadOnly - if we are complete with skipped files, i.e. a partial seedpublic void setChoking(boolean choke)
setChoking in class Peerchoke - true to choke (stop uploading), false to unchoke (allow uploads)public boolean shouldRequest(int size)
shouldRequest in class Peerpublic void transferComplete(long alreadyTransferred,
long bytesTransferred,
long bytesRemaining,
String url,
String outputFile,
boolean notModified)transferComplete in interface EepGet.StatusListeneralreadyTransferred - total bytes transferredbytesTransferred - total incl headersbytesRemaining - remaining bytesurl - the URLoutputFile - null if unknown (output stream constructor)notModified - whether 304EepGet.StatusListener.bytesTransferred(long, int, long, long, java.lang.String)public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt)
transferFailed in interface EepGet.StatusListenerurl - the URLbytesTransferred - total transferredbytesRemaining - remainingcurrentAttempt - attempt indexEepGet.StatusListener.bytesTransferred(long, int, long, long, java.lang.String)