- All Known Implementing Classes:
PeerCoordinator
interface PeerListener
Listener for Peer events.
Method Summary
All MethodsModifier and TypeMethodDescriptionvoidBan the given hash.voidCalled when the connection to the peer has started and the handshake was successful.voiddisconnected(Peer peer) Called when the connection to the peer was terminated or the connection handshake failed.getPartialPiece(Peer peer, int piece) Called when the peer suggests a specific piece via a BEP 6 suggest message.getPartialPiece(Peer peer, BitField havePieces) Called when a peer has connected and there may be a partially downloaded piece that the coordinatorator can give the peer task.getPartialPiece(Peer peer, BitField havePieces, Set<Integer> allowed) Called when a peer has connected and there may be a partially downloaded piece that the coordinator can give the peer task.getUtil()Retrieves the shared torrent utility.booleangotBitField(Peer peer, BitField bitfield) Called when a bitmap message is received.voidCalled when a choke message is received.voidgotCommentReq(Peer peer, int num) Called when comments are requested via ut_comment.voidgotComments(Peer peer, List<Comment> comments) Called when comments are received via ut_comment.voidgotExtension(Peer peer, int id, byte[] bs) Called when an extension message is received.booleanCalled when a have piece message is received.voidgotInterest(Peer peer, boolean interest) Called when an interested message is received.voidCalled when peers are received via PEX.booleangotPiece(Peer peer, PartialPiece piece) Called when a piece is received from the peer.voidCalled when a DHT port message is received.gotRequest(Peer peer, int piece, int off, int len) Called when the peer wants (part of) a piece from us.booleanIs the given hash banned?booleanCalled when we are downloading from the peer and may need to ask for a new piece.voidsavePartialPieces(Peer peer, List<Request> pcs) Called when the peer has disconnected and the peer task may have a partially downloaded piece that the PeerCoordinator can save.
Method Details
connected
Called when the connection to the peer has started and the handshake was successful.- Parameters:
peer- the Peer that just got connected.
disconnected
Called when the connection to the peer was terminated or the connection handshake failed.- Parameters:
peer- the Peer that just got disconnected.
gotChoke
Called when a choke message is received.- Parameters:
peer- the Peer that got the message.choke- true when the peer got a choke message, false when the peer got an unchoke message.
gotInterest
Called when an interested message is received.- Parameters:
peer- the Peer that got the message.interest- true when the peer got a interested message, false when the peer got an uninterested message.
gotHave
Called when a have piece message is received. If the method returns true and the peer has not yet received a interested message or we indicated earlier to be not interested then an interested message will be send.- Parameters:
peer- the Peer that got the message.piece- the piece number that the per just got.- Returns:
- true when it is a piece that we want, false if the piece is already known.
gotBitField
Called when a bitmap message is received. If this method returns true a interested message will be send back to the peer.- Parameters:
peer- the Peer that got the message.bitfield- a BitField containing the pieces that the other side has.- Returns:
- true when the BitField contains pieces we want, false if the piece is already known.
gotPiece
Called when a piece is received from the peer. The piece must be requested byPeer.request()first. If this method returns false that means the Peer provided a corrupted piece and the connection will be closed.- Parameters:
peer- the Peer that got the piece.piece- the piece received.- Returns:
- true when the bytes represent the piece, false otherwise.
gotRequest
Called when the peer wants (part of) a piece from us. Only called when the peer is not choked by us (peer.choke(false)was called).- Parameters:
peer- the Peer that wants the piece.piece- the piece number requested.off- byte offset into the piece.len- length of the chunk requested.- Returns:
- a byte array containing the piece or null when the piece is not available (which is a protocol error).
needPiece
Called when we are downloading from the peer and may need to ask for a new piece. Returns true if wantPiece() or getPartialPiece() would return a piece.- Parameters:
peer- the Peer that will be asked to provide the piece.bitfield- a BitField containing the pieces that the other side has.- Returns:
- if we want any of what the peer has
savePartialPieces
Called when the peer has disconnected and the peer task may have a partially downloaded piece that the PeerCoordinator can save.- Parameters:
peer- the peer that just disconnectedpcs- the still-outstanding piece requests whose partial data can be salvaged
getPartialPiece
Called when a peer has connected and there may be a partially downloaded piece that the coordinatorator can give the peer task.- Parameters:
peer- the peer that just connectedhavePieces- the have-pieces bitmask for the peer- Returns:
- request (contains the partial data and valid length)
getPartialPiece
Called when a peer has connected and there may be a partially downloaded piece that the coordinator can give the peer task. May be called while the peer chokes us, to request a BEP 6 allowed fast piece.- Parameters:
peer- the peer that just connectedhavePieces- the have-pieces bitmask for the peerallowed- the pieces servable while choked, or null for no restriction- Returns:
- request (contains the partial data and valid length)
getPartialPiece
Called when the peer suggests a specific piece via a BEP 6 suggest message. Returns a PartialPiece for that piece if we want it and it is not already being fetched from another peer, null otherwise.- Parameters:
peer- the Peer that got the message.piece- the suggested piece number- Returns:
- request (contains the partial data and valid length), or null if not wanted
gotExtension
Called when an extension message is received.- Parameters:
peer- the Peer that got the message.id- the message IDbs- the message payload
gotPort
Called when a DHT port message is received.- Parameters:
peer- the Peer that got the message.port- the query portrport- the response port
gotPeers
getUtil
I2PSnarkUtil getUtil()Retrieves the shared torrent utility.- Returns:
- the shared
I2PSnarkUtilfor this torrent, used to reach the context and the peer banning and comment settings
gotCommentReq
Called when comments are requested via ut_comment.- Parameters:
peer- the Peer that got the message.num- the number of comments asked for
gotComments
isBanned
Is the given hash banned?- Parameters:
h- the torrent's info hash, checked against the ban list- Returns:
- true if banned
ban