FileDocCategorySizeDatePackage
Test.javaAPI DocAzureus 3.0.3.47506Thu Jun 28 16:08:28 BST 2007com.aelitis.azureus.core.dht.transport.udp.impl

Test

public class Test extends Object implements DHTTransportRequestHandler
author
parg

Fields Summary
Constructors Summary
protected Test()

		try{
			DHTTransport	udp1 = 
				DHTTransportFactory.createUDP(
					DHTTransportUDP.PROTOCOL_VERSION_MAIN, DHT.NW_MAIN, false,
					null, null, 6881, 5, 3, 5000, 50, 25, false, false, com.aelitis.azureus.core.dht.impl.Test.getLogger());
		
			udp1.setRequestHandler( this );
			
			DHTTransport	udp2 = DHTTransportFactory.createUDP( 
					DHTTransportUDP.PROTOCOL_VERSION_MAIN, DHT.NW_MAIN, false,
					null, null, 6882, 5, 3, 5000, 50, 25, false, false, com.aelitis.azureus.core.dht.impl.Test.getLogger());
		
			udp2.setRequestHandler( this );

			final DHTTransportUDPContact	c1 = (DHTTransportUDPContact)udp1.getLocalContact();
			
			for (int i=0;i<10;i++){
				
				final int f_i = i;
				
				c1.sendPing(
					new DHTTransportReplyHandlerAdapter()
					{
						public void
						pingReply(
							DHTTransportContact contact )
						{
							System.out.println( "ping reply: " + f_i );
						}
						
						public void
						failed(
							DHTTransportContact 	contact,
							Throwable				error )
						{
							System.out.println( "ping failed" );
						}
					});
			}
	
			c1.sendStore(
					new DHTTransportReplyHandlerAdapter()
					{
						public void
						storeReply(
							DHTTransportContact contact,
							byte[]				types )
						{
							System.out.println( "store reply" );
						}
						
						public void
						failed(
							DHTTransportContact 	contact,
							Throwable				error )
						{
							System.out.println( "store failed" );
						}
					},
					new byte[][]{ new byte[23] },
					new DHTTransportValue[][]{{
						new DHTTransportValue()
						{
							public boolean
							isLocal()
							{
								return( false );
							}
							
							public long
							getCreationTime()
							{
								return( 2 );
							}
							
							public byte[]
							getValue()
							{
								return( "sdsd".getBytes());
							}
							
							public int
							getVersion()
							{
								return( 0 );
							}
							
							public DHTTransportContact
							getOriginator()
							{
								return( c1 );
							}
							
							public int
							getFlags()
							{
								return(0);
							}
							
							public String
							getString()
							{
								return( new String(getValue()));
							}
						}
					}});
			
			c1.sendFindNode(
					new DHTTransportReplyHandlerAdapter()
					{
						public void
						findNodeReply(
							DHTTransportContact 	contact,
							DHTTransportContact[] 	contacts )
						{
							System.out.println( "findNode reply" );
						}
						
						public void
						failed(
							DHTTransportContact 	contact,
							Throwable 				e )
						{
							System.out.println( "findNode failed" );
						}
					},
					new byte[12]);
			
			System.out.println( "sending find value" );
			
			c1.sendFindValue(
					new DHTTransportReplyHandlerAdapter()
					{
						public void
						findValueReply(
							DHTTransportContact 	contact,
							DHTTransportContact[] 	contacts )
						{
							System.out.println( "findValue contacts reply" );
						}
						
						public void
						findValueReply(
							DHTTransportContact 	contact,
							DHTTransportValue[]		values,
							byte					diversification_type,
							boolean					more_to_come )
						{
							System.out.println( "findValue value reply" );
						}
						
						public void
						failed(
							DHTTransportContact 	contact,
							Throwable				error )
						{
							System.out.println( "findValue failed" );
						}
					},
					new byte[3], 1, (byte)0 );
			
			System.out.println( "sending complete" );

			Thread.sleep(1000000);
		}catch( Throwable e ){
			
			e.printStackTrace();
		}
	
Methods Summary
public voidcontactImported(DHTTransportContact contact)

		
	
public voidcontactRemoved(DHTTransportContact contact)

	
public DHTTransportContact[]findNodeRequest(DHTTransportContact contact, byte[] id)

		System.out.println( "TransportHandler: findNode" );
		
		return(new DHTTransportContact[]{ contact });
	
public DHTTransportFindValueReplyfindValueRequest(DHTTransportContact contact, byte[] key, int max_values, byte flags)

		System.out.println( "TransportHandler: findValue" );
		
		return( 
				new DHTTransportFindValueReply()
				{
					public boolean
					hit()
					{
						return( false );
					}
					
					public byte
					getDiversificationType()
					{
						return( DHT.DT_NONE );
					}
					
					public DHTTransportValue[]
					getValues()
					{
						return( null );
					}
					
					public DHTTransportContact[]
					getContacts()
					{
						return( new DHTTransportContact[]{ contact } );
					}
					
					public boolean
					blocked()
					{
						return( false );
					}
					
					public byte[]
					getBlockedKey()
					{
						return( null );
					}
					
					public byte[]
					getBlockedSignature()
					{
						return( null );
					}
				});
	
public intgetTransportEstimatedDHTSize()

		return(0);
	
public voidkeyBlockRequest(DHTTransportContact contact, byte[] key_block_request, byte[] key_block_signature)

		System.out.println( "TransportHandler: keyBlockRequest" );
	
public static voidmain(java.lang.String[] args)

		new Test();
	
public voidpingRequest(DHTTransportContact contact)

		System.out.println( "TransportHandler: ping" );
	
public voidsetTransportEstimatedDHTSize(int size)

	
public DHTTransportFullStatsstatsRequest(DHTTransportContact contact)

		return( null );
	
public DHTTransportStoreReplystoreRequest(DHTTransportContact contact, byte[][] keys, DHTTransportValue[][] value_sets)

		System.out.println( "TransportHandler: store" );
		
		return( 
				new DHTTransportStoreReply()
				{
					public byte[]
		        	getDiversificationTypes()
					{
						return( new byte[keys.length] );
					}
		        	
		        	public boolean
		        	blocked()
		        	{
		        		return( false );
		        	}
		        	
		        	public byte[]
		        	getBlockRequest()
		        	{
		        		return( null );
		        	}
		        	
		        	public byte[]
		        	getBlockSignature()
		        	{
		        		return( null );
		        	}
				});