com.aelitis.azureus.core.dht.db.impl
Class DHTDBImpl

java.lang.Object
  extended by com.aelitis.azureus.core.dht.db.impl.DHTDBImpl
All Implemented Interfaces:
DHTDB, DHTDBStats

public class DHTDBImpl
extends Object
implements DHTDB, DHTDBStats

Author:
parg

Nested Class Summary
protected  class DHTDBImpl.adapterFacade
           
protected static class DHTDBImpl.SurveyContactState
           
 
Field Summary
static int ORIGINAL_REPUBLISH_INTERVAL_GRACE
           
protected static int QUERY_STORE_REPLY_ENTRY_SIZE
           
protected static int QUERY_STORE_REQUEST_ENTRY_SIZE
           
 
Fields inherited from interface com.aelitis.azureus.core.dht.db.DHTDBStats
VD_DIRECT_SIZE, VD_DIV_FREQ, VD_DIV_SIZE, VD_INDIRECT_SIZE, VD_LOCAL_SIZE, VD_VALUE_COUNT
 
Constructor Summary
DHTDBImpl(DHTStorageAdapter _adapter, int _original_republish_interval, int _cache_republish_interval, byte _protocol_version, DHTLogger _logger)
           
 
Method Summary
protected  void addToPrefixMap(DHTDBMapping mapping)
           
protected  boolean applyRF(DHTDBMapping mapping)
           
protected  void banContact(DHTTransportContact contact, String reason)
           
protected  void checkCacheExpiration(boolean force)
           
protected  void checkPreciousStuff()
           
protected  void decrementValueAdds(DHTTransportContact contact)
           
 void destroy()
           
protected  void doQuery(byte[] survey_my_id, int total, Map<DHTDBMapping,List<DHTTransportContact>> mapping_to_node_map, LinkedList<Map.Entry<DHTTransportContact,ByteArrayHashMap<List<DHTDBMapping>>>> to_do, Map<DHTTransportContact,Object[]> replies, DHTTransportContact done_contact, List<DHTDBMapping> done_mappings, List<byte[]> done_reply)
           
 DHTDBLookupResult get(DHTTransportContact reader, HashWrapper key, int max_values, short flags, boolean external_request)
           
 DHTDBValue get(HashWrapper key)
          Internal lookup for locally originated values
protected  DHTStorageAdapter getAdapter()
           
 List<DHTDBValue> getAllValues(HashWrapper key)
           
 DHTDBValue getAnyValue(HashWrapper key)
          Returns a value for the given key (local or remote) if found
 DHTStorageBlock[] getDirectKeyBlocks()
           
 int getKeyBlockCount()
           
 DHTStorageBlock getKeyBlockDetails(byte[] key)
           
 int getKeyCount()
           
 Iterator<HashWrapper> getKeys()
          Returns an iterator over HashWrapper values denoting the snapshot of keys Thus by the time a key is used the entry may no longer exist
protected  DHTTransportContact getLocalContact()
           
 int getLocalKeyCount()
           
protected  int getNextValueVersion()
           
 int getSize()
           
 DHTDBStats getStats()
           
 int getValueCount()
           
 int[] getValueDetails()
          returned values indexed by above VD_ constants for meaning
 boolean hasKey(HashWrapper key)
           
protected  void incrementValueAdds(DHTTransportContact contact)
           
 boolean isEmpty()
           
 boolean isKeyBlocked(byte[] key)
           
 DHTStorageBlock keyBlockRequest(DHTTransportContact direct_sender, byte[] request, byte[] signature)
           
protected  void log(String str)
           
 void print(boolean full)
           
protected  void processSurvey(byte[] survey_my_id, List<HashWrapper> applicable_keys, ByteArrayHashMap<DHTTransportContact> survey)
           
protected  void queriesComplete(byte[] survey_my_id, Map<DHTDBMapping,List<DHTTransportContact>> mapping_to_node_map, Map<DHTTransportContact,Object[]> replies)
           
 DHTTransportQueryStoreReply queryStore(DHTTransportContact originating_contact, int header_len, List<Object[]> keys)
           
protected  void rebuildIPBloomFilter(boolean increase_size)
           
 DHTDBValue remove(DHTTransportContact originator, HashWrapper key)
          Local remove - returns a value suitable for putting in the DHT
protected  void removeFromPrefixMap(DHTDBMapping mapping)
           
protected  void reportSizes(String op)
           
protected  int[] republishCachedMappings()
           
protected  int republishOriginalMappings()
           
 void setControl(DHTControl _control)
           
 void setSleeping(boolean asleep)
           
 void setSuspended(boolean susp)
           
 byte store(DHTTransportContact sender, HashWrapper key, DHTTransportValue[] values)
          Remote store
 DHTDBValue store(HashWrapper key, byte[] value, short flags, byte life_hours, byte replication_control)
          Local store
protected  void survey()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ORIGINAL_REPUBLISH_INTERVAL_GRACE

public static int ORIGINAL_REPUBLISH_INTERVAL_GRACE

QUERY_STORE_REQUEST_ENTRY_SIZE

protected static final int QUERY_STORE_REQUEST_ENTRY_SIZE
See Also:
Constant Field Values

QUERY_STORE_REPLY_ENTRY_SIZE

protected static final int QUERY_STORE_REPLY_ENTRY_SIZE
See Also:
Constant Field Values
Constructor Detail

DHTDBImpl

public DHTDBImpl(DHTStorageAdapter _adapter,
                 int _original_republish_interval,
                 int _cache_republish_interval,
                 byte _protocol_version,
                 DHTLogger _logger)
Method Detail

setControl

public void setControl(DHTControl _control)
Specified by:
setControl in interface DHTDB

store

public DHTDBValue store(HashWrapper key,
                        byte[] value,
                        short flags,
                        byte life_hours,
                        byte replication_control)
Description copied from interface: DHTDB
Local store

Specified by:
store in interface DHTDB
Returns:

store

public byte store(DHTTransportContact sender,
                  HashWrapper key,
                  DHTTransportValue[] values)
Description copied from interface: DHTDB
Remote store

Specified by:
store in interface DHTDB
Returns:
diversification state

get

public DHTDBLookupResult get(DHTTransportContact reader,
                             HashWrapper key,
                             int max_values,
                             short flags,
                             boolean external_request)
Specified by:
get in interface DHTDB

get

public DHTDBValue get(HashWrapper key)
Description copied from interface: DHTDB
Internal lookup for locally originated values

Specified by:
get in interface DHTDB
Returns:

getAnyValue

public DHTDBValue getAnyValue(HashWrapper key)
Description copied from interface: DHTDB
Returns a value for the given key (local or remote) if found

Specified by:
getAnyValue in interface DHTDB
Returns:

getAllValues

public List<DHTDBValue> getAllValues(HashWrapper key)
Specified by:
getAllValues in interface DHTDB

hasKey

public boolean hasKey(HashWrapper key)
Specified by:
hasKey in interface DHTDB

remove

public DHTDBValue remove(DHTTransportContact originator,
                         HashWrapper key)
Description copied from interface: DHTDB
Local remove - returns a value suitable for putting in the DHT

Specified by:
remove in interface DHTDB
Returns:

keyBlockRequest

public DHTStorageBlock keyBlockRequest(DHTTransportContact direct_sender,
                                       byte[] request,
                                       byte[] signature)
Specified by:
keyBlockRequest in interface DHTDB

getKeyBlockDetails

public DHTStorageBlock getKeyBlockDetails(byte[] key)
Specified by:
getKeyBlockDetails in interface DHTDB

isKeyBlocked

public boolean isKeyBlocked(byte[] key)
Specified by:
isKeyBlocked in interface DHTDB

getDirectKeyBlocks

public DHTStorageBlock[] getDirectKeyBlocks()
Specified by:
getDirectKeyBlocks in interface DHTDB

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface DHTDB

getKeyCount

public int getKeyCount()
Specified by:
getKeyCount in interface DHTDBStats

getLocalKeyCount

public int getLocalKeyCount()
Specified by:
getLocalKeyCount in interface DHTDBStats

getValueCount

public int getValueCount()
Specified by:
getValueCount in interface DHTDBStats

getSize

public int getSize()
Specified by:
getSize in interface DHTDBStats

getValueDetails

public int[] getValueDetails()
Description copied from interface: DHTDBStats
returned values indexed by above VD_ constants for meaning

Specified by:
getValueDetails in interface DHTDBStats
Returns:

getKeyBlockCount

public int getKeyBlockCount()
Specified by:
getKeyBlockCount in interface DHTDBStats

getKeys

public Iterator<HashWrapper> getKeys()
Description copied from interface: DHTDB
Returns an iterator over HashWrapper values denoting the snapshot of keys Thus by the time a key is used the entry may no longer exist

Specified by:
getKeys in interface DHTDB
Returns:

republishOriginalMappings

protected int republishOriginalMappings()

republishCachedMappings

protected int[] republishCachedMappings()

checkCacheExpiration

protected void checkCacheExpiration(boolean force)

addToPrefixMap

protected void addToPrefixMap(DHTDBMapping mapping)

removeFromPrefixMap

protected void removeFromPrefixMap(DHTDBMapping mapping)

checkPreciousStuff

protected void checkPreciousStuff()

getLocalContact

protected DHTTransportContact getLocalContact()

getAdapter

protected DHTStorageAdapter getAdapter()

log

protected void log(String str)

getStats

public DHTDBStats getStats()
Specified by:
getStats in interface DHTDB

survey

protected void survey()

processSurvey

protected void processSurvey(byte[] survey_my_id,
                             List<HashWrapper> applicable_keys,
                             ByteArrayHashMap<DHTTransportContact> survey)

applyRF

protected boolean applyRF(DHTDBMapping mapping)

doQuery

protected void doQuery(byte[] survey_my_id,
                       int total,
                       Map<DHTDBMapping,List<DHTTransportContact>> mapping_to_node_map,
                       LinkedList<Map.Entry<DHTTransportContact,ByteArrayHashMap<List<DHTDBMapping>>>> to_do,
                       Map<DHTTransportContact,Object[]> replies,
                       DHTTransportContact done_contact,
                       List<DHTDBMapping> done_mappings,
                       List<byte[]> done_reply)

queriesComplete

protected void queriesComplete(byte[] survey_my_id,
                               Map<DHTDBMapping,List<DHTTransportContact>> mapping_to_node_map,
                               Map<DHTTransportContact,Object[]> replies)

setSleeping

public void setSleeping(boolean asleep)
Specified by:
setSleeping in interface DHTDB

setSuspended

public void setSuspended(boolean susp)
Specified by:
setSuspended in interface DHTDB

queryStore

public DHTTransportQueryStoreReply queryStore(DHTTransportContact originating_contact,
                                              int header_len,
                                              List<Object[]> keys)
Specified by:
queryStore in interface DHTDB

print

public void print(boolean full)
Specified by:
print in interface DHTDB

banContact

protected void banContact(DHTTransportContact contact,
                          String reason)

incrementValueAdds

protected void incrementValueAdds(DHTTransportContact contact)

decrementValueAdds

protected void decrementValueAdds(DHTTransportContact contact)

rebuildIPBloomFilter

protected void rebuildIPBloomFilter(boolean increase_size)

reportSizes

protected void reportSizes(String op)

getNextValueVersion

protected int getNextValueVersion()

destroy

public void destroy()
Specified by:
destroy in interface DHTDB