FileDocCategorySizeDatePackage
TorrentSessionManager.javaAPI DocAzureus 3.0.3.44993Sun Mar 04 21:08:16 GMT 2007com.aelitis.azureus.core.peermanager.download.session

TorrentSessionManager

public class TorrentSessionManager extends Object

Fields Summary
private static final TorrentSessionManager
instance
private final HashMap
hashes
private final AEMonitor
hashes_mon
Constructors Summary
private TorrentSessionManager()

    /*nothing*/
  
Methods Summary
public voidderegisterForSessionManagement(com.aelitis.azureus.core.peermanager.download.TorrentDownload download)
Deregister the given download from torrent session management.

param
download to remove

    try{ hashes_mon.enter();
      hashes.remove( new HashWrapper( download.getInfoHash() ) );
    }
    finally{ hashes_mon.exit();  }
  
public static com.aelitis.azureus.core.peermanager.download.session.TorrentSessionManagergetSingleton()

  

       return instance;  
public voidinit()

    //register for new peer connection creation notification, so that we can catch torrent session syn messages
    PeerConnectionFactory.getSingleton().registerCreationListener( new PeerConnectionFactory.CreationListener() {
      public void connectionCreated( final AZPeerConnection connection ) {
        connection.getNetworkConnection().getIncomingMessageQueue().registerQueueListener( new IncomingMessageQueue.MessageQueueListener() {
          public boolean messageReceived( Message message ) {
            if( message.getID().equals( AZMessage.ID_AZ_SESSION_SYN ) ) {
              AZSessionSyn syn = (AZSessionSyn)message;

              byte[] hash = syn.getInfoHash();

              //check for valid session infohash
              TorrentDownload download = null;
                
              try{ hashes_mon.enter();
                download = (TorrentDownload)hashes.get( new HashWrapper( hash ) );
              }
              finally{ hashes_mon.exit();  }
                
              if( download == null ) {
                System.out.println( "unknown session infohash " +ByteFormatter.nicePrint( hash, true ) );
                AZSessionEnd end = new AZSessionEnd( hash, "unknown session infohash", (byte)1 );
                connection.getNetworkConnection().getOutgoingMessageQueue().addMessage( end, false );
              }
              else { //success
                //TODO
                //TorrentSession session = TorrentSessionFactory.getSingleton().createIncomingSession( download, connection, syn.getSessionID() );
                //session.authenticate( syn.getSessionInfo() );  //init processing //TODO
              }
               
              syn.destroy();
              return true;
            }
            
            return false;
          }

          public void protocolBytesReceived( int byte_count ){}
          public void dataBytesReceived( int byte_count ){}
        });
      }
    });
  
public voidregisterForSessionManagement(com.aelitis.azureus.core.peermanager.download.TorrentDownload download)
Register the given download for torrent session management.

param
download to add

    try{ hashes_mon.enter();
      hashes.put( new HashWrapper( download.getInfoHash() ), download );
    }
    finally{ hashes_mon.exit();  }
  
public voidrequestTorrentSession(com.aelitis.azureus.core.peermanager.download.TorrentDownload download, AZPeerConnection connection)
Initiate a torrent session for the given download with the given peer connection.

param
download for session
param
connection to send request to

    //TorrentSession session = TorrentSessionFactory.getSingleton().createOutgoingSession( download, connection );
    //session.authenticate( null );  //init processing  //TODO