if ( registered ){
return;
}
registered = true;
PRUDPPacketReplyDecoder reply_decoder =
new PRUDPPacketReplyDecoder()
{
public PRUDPPacketReply
decode(
PRUDPPacketHandler handler,
DataInputStream is,
int action,
int transaction_id )
throws IOException
{
switch( action ){
case PRUDPPacketTracker.ACT_REPLY_CONNECT:
{
return( new PRUDPPacketReplyConnect(is, transaction_id));
}
case PRUDPPacketTracker.ACT_REPLY_ANNOUNCE:
{
if ( PRUDPPacketTracker.VERSION == 1 ){
return( new PRUDPPacketReplyAnnounce(is, transaction_id));
}else{
return( new PRUDPPacketReplyAnnounce2(is, transaction_id));
}
}
case PRUDPPacketTracker.ACT_REPLY_SCRAPE:
{
if ( PRUDPPacketTracker.VERSION == 1 ){
return( new PRUDPPacketReplyScrape(is, transaction_id));
}else{
return( new PRUDPPacketReplyScrape2(is, transaction_id));
}
}
case PRUDPPacketTracker.ACT_REPLY_ERROR:
{
return( new PRUDPPacketReplyError(is, transaction_id));
}
default:
{
throw( new IOException( "Unrecognised action '" + action + "'" ));
}
}
}
};
Map reply_decoders = new HashMap();
reply_decoders.put( new Integer( PRUDPPacketTracker.ACT_REPLY_CONNECT ), reply_decoder );
reply_decoders.put( new Integer( PRUDPPacketTracker.ACT_REPLY_ANNOUNCE ), reply_decoder );
reply_decoders.put( new Integer( PRUDPPacketTracker.ACT_REPLY_SCRAPE ), reply_decoder );
reply_decoders.put( new Integer( PRUDPPacketTracker.ACT_REPLY_ERROR ), reply_decoder );
PRUDPPacketReply.registerDecoders( reply_decoders );
PRUDPPacketRequestDecoder request_decoder =
new PRUDPPacketRequestDecoder()
{
public PRUDPPacketRequest
decode(
PRUDPPacketHandler handler,
DataInputStream is,
long connection_id,
int action,
int transaction_id )
throws IOException
{
switch( action ){
case PRUDPPacketTracker.ACT_REQUEST_CONNECT:
{
return( new PRUDPPacketRequestConnect(is, connection_id,transaction_id));
}
case PRUDPPacketTracker.ACT_REQUEST_ANNOUNCE:
{
if ( PRUDPPacketTracker.VERSION == 1 ){
return( new PRUDPPacketRequestAnnounce(is, connection_id,transaction_id));
}else{
return( new PRUDPPacketRequestAnnounce2(is, connection_id,transaction_id));
}
}
case PRUDPPacketTracker.ACT_REQUEST_SCRAPE:
{
return( new PRUDPPacketRequestScrape(is, connection_id,transaction_id));
}
default:
{
throw( new IOException( "unsupported request type"));
}
}
}
};
Map request_decoders = new HashMap();
request_decoders.put( new Integer( PRUDPPacketTracker.ACT_REQUEST_CONNECT ), request_decoder );
request_decoders.put( new Integer( PRUDPPacketTracker.ACT_REQUEST_ANNOUNCE ), request_decoder );
request_decoders.put( new Integer( PRUDPPacketTracker.ACT_REQUEST_SCRAPE ), request_decoder );
PRUDPPacketRequest.registerDecoders( request_decoders );