Methods Summary |
---|
public void | addListener(DHTTransportListener l)
listeners.add(l);
|
public void | exportContact(DHTTransportContact contact, java.io.DataOutputStream os)
os.writeInt( VERSION );
os.writeInt( id_byte_length );
os.write( contact.getID());
|
protected com.aelitis.azureus.core.dht.transport.loopback.DHTTransportLoopbackImpl | findTarget(byte[] id)
try{
class_mon.enter();
return((DHTTransportLoopbackImpl)node_map.get( new HashWrapper( id )));
}finally{
class_mon.exit();
}
|
public DHTTransportContact | getLocalContact()
return( local_contact );
|
public int | getNetwork()
return( DHT.NW_MAIN );
|
public static DHTTransportStats | getOverallStats()
try{
class_mon.enter();
DHTTransportStatsImpl overall_stats = new DHTTransportLoopbackStatsImpl( VERSION );
Iterator it = node_map.values().iterator();
while( it.hasNext()){
overall_stats.add((DHTTransportStatsImpl)((DHTTransportLoopbackImpl)it.next()).getStats());
}
return( overall_stats );
}finally{
class_mon.exit();
}
|
public int | getPort()
return( 0 );
|
public byte | getProtocolVersion()
return( VERSION );
|
public DHTTransportContact[] | getReachableContacts()
return( new DHTTransportContact[0] );
|
protected DHTTransportRequestHandler | getRequestHandler()
return( request_handler );
|
public DHTTransportStats | getStats()
return( stats );
|
public DHTTransportContact | importContact(java.io.DataInputStream is)
int version = is.readInt();
if ( version != VERSION ){
throw( new IOException( "Unsuported version" ));
}
int id_len = is.readInt();
if ( id_len != id_byte_length ){
throw( new IOException( "Imported contact has incorrect ID length" ));
}
byte[] id = new byte[id_byte_length];
is.read( id );
DHTTransportContact contact = new DHTTransportLoopbackContactImpl( this, id );
request_handler.contactImported( contact );
return( contact );
|
public boolean | isReachable()
return( true );
|
public byte[] | readTransfer(DHTTransportProgressListener listener, DHTTransportContact target, byte[] handler_key, byte[] key, long timeout)
throw( new DHTTransportException("not imp"));
|
public void | registerTransferHandler(byte[] handler_key, DHTTransportTransferHandler handler)
|
public void | removeContact(DHTTransportContact contact)
|
public void | removeListener(DHTTransportListener l)
listeners.remove(l);
|
protected void | run(AERunnable r)
try{
class_mon.enter();
dispatch_queue.add( r );
}finally{
class_mon.exit();
}
dispatch_queue_sem.release();
|
public void | sendFindNode(DHTTransportContact contact, DHTTransportReplyHandler handler, byte[] nid)
AERunnable runnable =
new AERunnable()
{
public void
runSupport()
{
sendFindNodeSupport( contact, handler, nid );
}
};
run( runnable );
|
public void | sendFindNodeSupport(DHTTransportContact contact, DHTTransportReplyHandler handler, byte[] nid)
DHTTransportLoopbackImpl target = findTarget( contact.getID());
stats.findNodeSent(null);
if ( target == null || triggerFailure() ){
stats.findNodeFailed();
handler.failed(contact,new Exception( "failed"));
}else{
stats.findNodeOK();
DHTTransportContact temp = new DHTTransportLoopbackContactImpl( target, node_id );
DHTTransportContact[] res =
target.getRequestHandler().findNodeRequest(
temp,
nid );
contact.setRandomID( temp.getRandomID());
DHTTransportContact[] trans_res = new DHTTransportContact[res.length];
for (int i=0;i<res.length;i++){
trans_res[i] = new DHTTransportLoopbackContactImpl( this, res[i].getID());
}
handler.findNodeReply( contact, trans_res );
}
|
public void | sendFindValue(DHTTransportContact contact, DHTTransportReplyHandler handler, byte[] key, int max, byte flags)
AERunnable runnable =
new AERunnable()
{
public void
runSupport()
{
sendFindValueSupport( contact, handler, key, max, flags );
}
};
run( runnable );
|
public void | sendFindValueSupport(DHTTransportContact contact, DHTTransportReplyHandler handler, byte[] key, int max, byte flags)
DHTTransportLoopbackImpl target = findTarget( contact.getID());
stats.findValueSent(null);
if ( target == null || triggerFailure()){
stats.findValueFailed();
handler.failed(contact,new Exception( "failed"));
}else{
stats.findValueOK();
DHTTransportFindValueReply find_res =
target.getRequestHandler().findValueRequest(
new DHTTransportLoopbackContactImpl( target, node_id ),
key, max, flags );
if ( find_res.hit()){
handler.findValueReply( contact, find_res.getValues(), find_res.getDiversificationType(), false );
}else if ( find_res.blocked()){
handler.keyBlockRequest( contact, find_res.getBlockedKey(), find_res.getBlockedSignature() );
handler.failed( contact, new Throwable( "key blocked" ));
}else{
DHTTransportContact[] res = find_res.getContacts();
DHTTransportContact[] trans_res = new DHTTransportContact[res.length];
for (int i=0;i<res.length;i++){
trans_res[i] = new DHTTransportLoopbackContactImpl( this, res[i].getID());
}
handler.findValueReply( contact, trans_res );
}
}
|
public void | sendKeyBlock(DHTTransportContact contact, DHTTransportReplyHandler handler, byte[] request, byte[] sig)
AERunnable runnable =
new AERunnable()
{
public void
runSupport()
{
sendKeyBlockSupport( contact, handler, request, sig );
}
};
run( runnable );
|
public void | sendKeyBlockSupport(DHTTransportContact contact, DHTTransportReplyHandler handler, byte[] request, byte[] sig)
DHTTransportLoopbackImpl target = findTarget( contact.getID());
stats.keyBlockSent(null);
if ( target == null || triggerFailure()){
stats.keyBlockFailed();
handler.failed(contact, new Exception( "failed" ));
}else{
stats.keyBlockOK();
target.getRequestHandler().keyBlockRequest(
new DHTTransportLoopbackContactImpl( target, node_id ),
request, sig );
handler.keyBlockReply(contact);
}
|
public void | sendPing(DHTTransportContact contact, DHTTransportReplyHandler handler)
AERunnable runnable =
new AERunnable()
{
public void
runSupport()
{
sendPingSupport( contact, handler );
}
};
run( runnable );
|
public void | sendPingSupport(DHTTransportContact contact, DHTTransportReplyHandler handler)
DHTTransportLoopbackImpl target = findTarget( contact.getID());
stats.pingSent(null);
if ( target == null || triggerFailure()){
stats.pingFailed();
handler.failed(contact, new Exception( "failed" ));
}else{
stats.pingOK();
target.getRequestHandler().pingRequest( new DHTTransportLoopbackContactImpl( target, node_id ));
handler.pingReply(contact,0);
}
|
public void | sendStats(DHTTransportContact contact, DHTTransportReplyHandler handler)
AERunnable runnable =
new AERunnable()
{
public void
runSupport()
{
sendStatsSupport( contact, handler );
}
};
run( runnable );
|
public void | sendStatsSupport(DHTTransportContact contact, DHTTransportReplyHandler handler)
DHTTransportLoopbackImpl target = findTarget( contact.getID());
stats.statsSent(null);
if ( target == null || triggerFailure()){
stats.statsFailed();
handler.failed(contact, new Exception( "failed"));
}else{
stats.statsOK();
DHTTransportFullStats res = target.getRequestHandler().statsRequest( new DHTTransportLoopbackContactImpl( target, node_id ));
handler.statsReply(contact,res);
}
|
public void | sendStore(DHTTransportContact contact, DHTTransportReplyHandler handler, byte[][] keys, DHTTransportValue[][] value_sets)
AERunnable runnable =
new AERunnable()
{
public void
runSupport()
{
sendStoreSupport( contact, handler, keys, value_sets );
}
};
run( runnable );
|
public void | sendStoreSupport(DHTTransportContact contact, DHTTransportReplyHandler handler, byte[][] keys, DHTTransportValue[][] value_sets)
DHTTransportLoopbackImpl target = findTarget( contact.getID());
stats.storeSent(null);
if ( target == null || triggerFailure()){
stats.storeFailed();
handler.failed(contact,new Exception( "failed"));
}else{
stats.storeOK();
DHTTransportContact temp = new DHTTransportLoopbackContactImpl( target, node_id );
temp.setRandomID( contact.getRandomID());
DHTTransportStoreReply rep =
target.getRequestHandler().storeRequest(
temp,
keys, value_sets );
if ( rep.blocked()){
handler.keyBlockRequest( contact, rep.getBlockRequest(), rep.getBlockSignature());
handler.failed( contact, new Throwable( "key blocked" ));
}else{
handler.storeReply( contact, rep.getDiversificationTypes());
}
}
|
public static void | setFailPercentage(int p)
FAIL_PERCENTAGE = p;
|
public static void | setLatency(int _latency)
LATENCY = _latency;
|
public void | setPort(int port)
|
public void | setRequestHandler(DHTTransportRequestHandler _request_handler)
request_handler = new DHTTransportRequestCounter( _request_handler, stats );
|
public boolean | supportsStorage()
return( true );
|
protected boolean | triggerFailure()
return( Math.random()*100 < FAIL_PERCENTAGE );
|
public byte[] | writeReadTransfer(DHTTransportProgressListener listener, DHTTransportContact target, byte[] handler_key, byte[] data, long timeout)
throw( new DHTTransportException("not imp"));
|
public void | writeTransfer(DHTTransportProgressListener listener, DHTTransportContact target, byte[] handler_key, byte[] key, byte[] data, long timeout)
throw( new DHTTransportException("not imp"));
|