AZTorrentSessionpublic class AZTorrentSession extends Object implements TorrentSession
Fields Summary |
---|
private static int | next_session_id | private static final AEMonitor | session_mon | private int | local_session_id | private int | remote_session_id | private final com.aelitis.azureus.core.peermanager.download.TorrentDownload | download | private final com.aelitis.azureus.core.peermanager.connection.AZPeerConnection | peer | private final TorrentSessionListener | listener | private TimerEvent | syn_timeout_timer | private final IncomingMessageQueue.MessageQueueListener | incoming_q_listener | private final OutgoingMessageQueue.MessageQueueListener | sent_message_listener |
Methods Summary |
---|
private void | authenticate(java.util.Map incoming_syn)
if( incoming_syn == null ) { //outgoing session
//send out the session request
AZSessionSyn syn = new AZSessionSyn( download.getInfoHash(), local_session_id, download.getSessionAuthenticator().createSessionSyn( peer ), (byte)1 );
peer.getNetworkConnection().getOutgoingMessageQueue().addMessage( syn, false );
//set a timeout timer in case the other peer forgets to send an ACK or END reply
syn_timeout_timer = SimpleTimer.addEvent( "AZTorrentSession:SynTImer", SystemTime.getCurrentTime() + 60*1000, new TimerEventPerformer() {
public void perform( TimerEvent event ) {
end( "No session ACK received after 60sec, request timed out.", true );
}
});
}
else { //incoming session
try{
Map ack_reply = download.getSessionAuthenticator().verifySessionSyn( peer, incoming_syn );
//send out the session acceptance
AZSessionAck ack = new AZSessionAck( download.getInfoHash(), local_session_id, ack_reply, (byte)1 );
peer.getNetworkConnection().getOutgoingMessageQueue().addMessage( ack, false );
listener.sessionIsEstablished(); //notify of readiness
}
catch( AuthenticatorException ae ) { //on syn authentication error
end( "AuthenticatorException:: " +ae.getMessage(), true ); //send end message
}
}
| private void | destroy()
if( syn_timeout_timer != null ) syn_timeout_timer.cancel(); //abort timeout check if running
peer.getNetworkConnection().getIncomingMessageQueue().cancelQueueListener( incoming_q_listener );
peer.getNetworkConnection().getOutgoingMessageQueue().cancelQueueListener( sent_message_listener );
| private void | end(java.lang.String end_reason, boolean notify_listener)
System.out.println( "endSession:: " +end_reason );
//send end notice to remote peer
AZSessionEnd end = new AZSessionEnd( download.getInfoHash(), end_reason, (byte)1 );
peer.getNetworkConnection().getOutgoingMessageQueue().addMessage( end, false );
if( notify_listener ) {
listener.sessionIsEnded( end_reason ); //notify listener of termination
}
destroy();
| public void | endSession(java.lang.String reason)
end( reason, false );
| public void | sendSessionBitfield(DirectByteBuffer bitfield)
AZSessionBitfield bitf = new AZSessionBitfield( remote_session_id, bitfield, (byte)1 );
peer.getNetworkConnection().getOutgoingMessageQueue().addMessage( bitf, false );
| public void | sendSessionCancel(int piece_number, int piece_offset, int length)
AZSessionCancel can = new AZSessionCancel( remote_session_id, piece_number, piece_offset, length, (byte)1 );
peer.getNetworkConnection().getOutgoingMessageQueue().addMessage( can, false );
| public void | sendSessionHave(int[] piece_numbers)
AZSessionHave have = new AZSessionHave( remote_session_id, piece_numbers, (byte)1 );
peer.getNetworkConnection().getOutgoingMessageQueue().addMessage( have, false );
| public java.lang.Object | sendSessionPiece(int piece_number, int piece_offset, DirectByteBuffer data)
try{
DirectByteBuffer encoded = download.getSessionAuthenticator().encodeSessionData( peer, data );
AZSessionPiece piece = new AZSessionPiece( remote_session_id, piece_number, piece_offset, encoded, (byte)1 );
peer.getNetworkConnection().getOutgoingMessageQueue().addMessage( piece, false );
return piece;
}
catch( AuthenticatorException ae ) {
data.returnToPool();
end( "AuthenticatorException:: " +ae.getMessage(), true ); //send end message
return null;
}
| public void | sendSessionRequest(byte unchoke_id, int piece_number, int piece_offset, int length)
AZSessionRequest req = new AZSessionRequest( remote_session_id, unchoke_id, piece_number, piece_offset, length, (byte)1 );
peer.getNetworkConnection().getOutgoingMessageQueue().addMessage( req, false );
|
|