class WebPeer extends Peer implements EepGet.StatusListener
Modifier and Type | Field and Description |
---|---|
static byte[] |
IDBytes |
_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) |
void |
attempting(String url) |
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()
Return how much the peer has
|
(package private) void |
disconnect() |
boolean |
equals(Object o)
Two Peers are equal when they have the same PeerID.
|
long |
getInactiveTime() |
long |
getMaxInactiveTime() |
int |
getMaxPipeline() |
String |
getSocket() |
int |
hashCode()
The hash code of a Peer is the hash code of the peerID.
|
void |
have(int piece)
Tell the peer we have another piece.
|
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() |
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() |
void |
keepAlive()
Send keepalive
|
(package private) void |
request()
Update the request queue.
|
void |
retransmitRequests()
Retransmit outstanding requests if necessary
|
void |
runConnection(I2PSnarkUtil util,
PeerListener listener,
BitField ignore,
MagnetState mState,
boolean uploadOnly)
Runs the connection to the other peer.
|
void |
setChoking(boolean choke)
Sets whether or not we are choking the peer.
|
void |
setInteresting(boolean interest)
Deprecated.
|
String |
toString()
Returns the String representation of the peerID.
|
void |
transferComplete(long alreadyTransferred,
long bytesTransferred,
long bytesRemaining,
String url,
String outputFile,
boolean notModified) |
void |
transferFailed(String url,
long bytesTransferred,
long bytesRemaining,
int currentAttempt) |
compareTo, disconnect, downloaded, getDestination, getDownloaded, getDownloadRate, getHandshakeMap, getMagnetState, getPeerID, getTotalCommentsSent, getUploaded, getUploadRate, isIncoming, isRequesting, resetCounters, sendExtension, setHandshakeMap, setMetaInfo, setRateHistory, setTotalCommentsSent, supportsFast, uploaded
public WebPeer(PeerCoordinator coord, URI uri, PeerID peerID, MetaInfo metainfo)
uri
- must be http with .i2p hostmetainfo
- non-nullpublic String toString()
Peer
public String getSocket()
public int hashCode()
public boolean equals(Object o)
public void runConnection(I2PSnarkUtil util, PeerListener listener, BitField ignore, MagnetState mState, boolean uploadOnly)
runConnection
in class Peer
ignore
- our bitfield, ignoreuploadOnly
- if we are complete with skipped files, i.e. a partial seedpublic int getMaxPipeline()
getMaxPipeline
in class Peer
public boolean isConnected()
isConnected
in class Peer
void disconnect()
disconnect
in class Peer
public void have(int piece)
Peer
void cancel(int piece)
Peer
void request()
Peer
public boolean isInterested()
Peer
isInterested
in class Peer
@Deprecated public void setInteresting(boolean interest)
Peer
setInteresting
in class Peer
public boolean isInteresting()
Peer
isInteresting
in class Peer
public void setChoking(boolean choke)
Peer
setChoking
in class Peer
public boolean isChoking()
Peer
public boolean isChoked()
Peer
public long getInactiveTime()
getInactiveTime
in class Peer
public long getMaxInactiveTime()
getMaxInactiveTime
in class Peer
public void keepAlive()
Peer
public void retransmitRequests()
Peer
retransmitRequests
in class Peer
public int completed()
Peer
public boolean isCompleted()
Peer
isCompleted
in class Peer
public void bytesTransferred(long alreadyTransferred, int currentWrite, long bytesTransferred, long bytesRemaining, String url)
EepGet.StatusListener
bytesTransferred
in interface EepGet.StatusListener
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 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 lengthpublic void attemptFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt, int numRetries, Exception cause)
attemptFailed
in interface EepGet.StatusListener
EepGet.StatusListener.bytesTransferred(long, int, long, long, java.lang.String)
public void transferComplete(long alreadyTransferred, long bytesTransferred, long bytesRemaining, String url, String outputFile, boolean notModified)
transferComplete
in interface EepGet.StatusListener
outputFile
- null if unknown (output stream constructor)EepGet.StatusListener.bytesTransferred(long, int, long, long, java.lang.String)
public void transferFailed(String url, long bytesTransferred, long bytesRemaining, int currentAttempt)
transferFailed
in interface EepGet.StatusListener
EepGet.StatusListener.bytesTransferred(long, int, long, long, java.lang.String)
public void headerReceived(String url, int attemptNum, String key, String val)
EepGet.StatusListener
headerReceived
in interface EepGet.StatusListener
public void attempting(String url)
attempting
in interface EepGet.StatusListener