com.aelitis.azureus.plugins.dht.impl
Class DHTPluginStorageManager

java.lang.Object
  extended by com.aelitis.azureus.plugins.dht.impl.DHTPluginStorageManager
All Implemented Interfaces:
DHTStorageAdapter

public class DHTPluginStorageManager
extends java.lang.Object
implements DHTStorageAdapter

Author:
parg

Nested Class Summary
protected static class DHTPluginStorageManager.diversification
           
protected static class DHTPluginStorageManager.keyBlock
           
protected static class DHTPluginStorageManager.storageKey
           
 
Field Summary
static int LOCAL_DIVERSIFICATION_ENTRIES_LIMIT
           
static int LOCAL_DIVERSIFICATION_READS_PER_MIN
           
static int LOCAL_DIVERSIFICATION_READS_PER_MIN_SAMPLES
           
static int LOCAL_DIVERSIFICATION_SIZE_LIMIT
           
static int MAX_STORAGE_KEYS
           
 
Constructor Summary
DHTPluginStorageManager(int _network, DHTLogger _log, java.io.File _data_dir)
           
 
Method Summary
protected  DHTStorageBlock[] buildKeyBlockDetails(ByteArrayHashMap map)
           
protected  DHTPluginStorageManager.diversification createDiversification(HashWrapper wrapper, byte type)
           
 byte[][] createNewDiversification(java.lang.String description, DHTTransportContact cause, byte[] key, boolean put_operation, byte diversification_type, boolean exhaustive, int max_depth)
           
static DHTStorageKeyStats decodeStats(java.io.DataInputStream is)
           
protected  void deleteStorageKey(DHTPluginStorageManager.storageKey key)
           
 DHTStorageKeyStats deserialiseStats(java.io.DataInputStream is)
           
protected  void divAdded(DHTPluginStorageManager.diversification div)
           
static byte[] diversifyKey(byte[] key_in, int offset)
           
static HashWrapper diversifyKey(HashWrapper key_in, int offset)
           
static byte[] diversifyKeyLocal(byte[] key_in, int offset)
           
protected  void divRemoved(DHTPluginStorageManager.diversification div)
           
 void exportContacts(DHT dht)
           
protected  byte[][] followDivChain(HashWrapper wrapper, boolean put_operation, boolean exhaustive, int max_depth)
           
protected  java.util.List followDivChainSupport(java.util.List list_in, boolean put_operation, int depth, boolean exhaustive, java.util.List keys_done, int max_depth)
           
protected static java.lang.String formatExpiry(long l)
           
 DHTStorageBlock[] getDirectKeyBlocks()
           
 byte[][] getExistingDiversification(byte[] key, boolean put_operation, boolean exhaustive, int max_depth)
           
 DHTStorageBlock getKeyBlockDetails(byte[] key)
           
 int getKeyCount()
           
 byte[] getKeyForKeyBlock(byte[] request)
           
protected  java.lang.String getMostRecentAddress()
           
 int getNetwork()
           
 int getNextValueVersions(int num)
           
 int getRemoteFreqDivCount()
           
 int getRemoteSizeDivCount()
           
 byte[] getStorageForKey(java.lang.String key)
           
protected  DHTPluginStorageManager.storageKey getStorageKey(HashWrapper key)
           
 void importContacts(DHT dht)
           
 boolean isDiversified(byte[] key)
           
protected  boolean isRecentAddress(java.lang.String address)
           
 DHTStorageBlock keyBlockRequest(DHTTransportContact originating_contact, byte[] request, byte[] signature)
           
 DHTStorageKey keyCreated(HashWrapper key, boolean local)
          Create a new storage key for a given key
 void keyDeleted(DHTStorageKey key)
           
 void keyRead(DHTStorageKey key, DHTTransportContact contact)
           
protected  void localContactChanged(DHTTransportContact contact)
           
protected  DHTPluginStorageManager.diversification lookupDiversification(HashWrapper wrapper)
           
protected  void purgeDirectKeyBlocks()
           
protected  void readDiversifications()
           
protected  void readKeyBlocks()
           
protected  java.util.Map readMapFromFile(java.lang.String file_prefix)
           
protected  void readRecentAddresses()
           
protected  void readVersionData()
           
protected  void recordCurrentAddress(java.lang.String address)
           
 void serialiseStats(DHTPluginStorageManager.storageKey key, java.io.DataOutputStream dos)
           
 void setStorageForKey(java.lang.String key, byte[] data)
           
protected  boolean suspendDivs()
           
 void valueAdded(DHTStorageKey key, DHTTransportValue value)
           
 void valueDeleted(DHTStorageKey key, DHTTransportValue value)
           
 void valueUpdated(DHTStorageKey key, DHTTransportValue old_value, DHTTransportValue new_value)
           
static boolean verifyKeyBlock(byte[] request, byte[] signature)
           
protected  boolean verifyKeyBlock(DHTPluginStorageManager.keyBlock kb, DHTTransportContact originator)
           
protected  void writeDiversifications()
           
protected  void writeKeyBlocks()
           
protected  void writeMapToFile(java.util.Map map, java.lang.String file_prefix)
           
protected  void writeRecentAddresses()
           
protected  void writeVersionData()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOCAL_DIVERSIFICATION_SIZE_LIMIT

public static final int LOCAL_DIVERSIFICATION_SIZE_LIMIT
See Also:
Constant Field Values

LOCAL_DIVERSIFICATION_ENTRIES_LIMIT

public static final int LOCAL_DIVERSIFICATION_ENTRIES_LIMIT
See Also:
Constant Field Values

LOCAL_DIVERSIFICATION_READS_PER_MIN_SAMPLES

public static final int LOCAL_DIVERSIFICATION_READS_PER_MIN_SAMPLES
See Also:
Constant Field Values

LOCAL_DIVERSIFICATION_READS_PER_MIN

public static final int LOCAL_DIVERSIFICATION_READS_PER_MIN
See Also:
Constant Field Values

MAX_STORAGE_KEYS

public static final int MAX_STORAGE_KEYS
See Also:
Constant Field Values
Constructor Detail

DHTPluginStorageManager

public DHTPluginStorageManager(int _network,
                               DHTLogger _log,
                               java.io.File _data_dir)
Method Detail

getNetwork

public int getNetwork()
Specified by:
getNetwork in interface DHTStorageAdapter

importContacts

public void importContacts(DHT dht)

exportContacts

public void exportContacts(DHT dht)

readRecentAddresses

protected void readRecentAddresses()

writeRecentAddresses

protected void writeRecentAddresses()

recordCurrentAddress

protected void recordCurrentAddress(java.lang.String address)

getMostRecentAddress

protected java.lang.String getMostRecentAddress()

isRecentAddress

protected boolean isRecentAddress(java.lang.String address)

localContactChanged

protected void localContactChanged(DHTTransportContact contact)

readMapFromFile

protected java.util.Map readMapFromFile(java.lang.String file_prefix)

writeMapToFile

protected void writeMapToFile(java.util.Map map,
                              java.lang.String file_prefix)

readVersionData

protected void readVersionData()

writeVersionData

protected void writeVersionData()

getNextValueVersions

public int getNextValueVersions(int num)
Specified by:
getNextValueVersions in interface DHTStorageAdapter

keyCreated

public DHTStorageKey keyCreated(HashWrapper key,
                                boolean local)
Description copied from interface: DHTStorageAdapter
Create a new storage key for a given key

Specified by:
keyCreated in interface DHTStorageAdapter
Returns:
null if the key shouldn't be allocated (e.g.out of space)

keyDeleted

public void keyDeleted(DHTStorageKey key)
Specified by:
keyDeleted in interface DHTStorageAdapter

getKeyCount

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

keyRead

public void keyRead(DHTStorageKey key,
                    DHTTransportContact contact)
Specified by:
keyRead in interface DHTStorageAdapter

serialiseStats

public void serialiseStats(DHTPluginStorageManager.storageKey key,
                           java.io.DataOutputStream dos)
                    throws java.io.IOException
Throws:
java.io.IOException

deserialiseStats

public DHTStorageKeyStats deserialiseStats(java.io.DataInputStream is)
                                    throws java.io.IOException
Specified by:
deserialiseStats in interface DHTStorageAdapter
Throws:
java.io.IOException

decodeStats

public static DHTStorageKeyStats decodeStats(java.io.DataInputStream is)
                                      throws java.io.IOException
Throws:
java.io.IOException

valueAdded

public void valueAdded(DHTStorageKey key,
                       DHTTransportValue value)
Specified by:
valueAdded in interface DHTStorageAdapter

valueUpdated

public void valueUpdated(DHTStorageKey key,
                         DHTTransportValue old_value,
                         DHTTransportValue new_value)
Specified by:
valueUpdated in interface DHTStorageAdapter

valueDeleted

public void valueDeleted(DHTStorageKey key,
                         DHTTransportValue value)
Specified by:
valueDeleted in interface DHTStorageAdapter

isDiversified

public boolean isDiversified(byte[] key)
Specified by:
isDiversified in interface DHTStorageAdapter

getExistingDiversification

public byte[][] getExistingDiversification(byte[] key,
                                           boolean put_operation,
                                           boolean exhaustive,
                                           int max_depth)
Specified by:
getExistingDiversification in interface DHTStorageAdapter

createNewDiversification

public byte[][] createNewDiversification(java.lang.String description,
                                         DHTTransportContact cause,
                                         byte[] key,
                                         boolean put_operation,
                                         byte diversification_type,
                                         boolean exhaustive,
                                         int max_depth)
Specified by:
createNewDiversification in interface DHTStorageAdapter

followDivChain

protected byte[][] followDivChain(HashWrapper wrapper,
                                  boolean put_operation,
                                  boolean exhaustive,
                                  int max_depth)

followDivChainSupport

protected java.util.List followDivChainSupport(java.util.List list_in,
                                               boolean put_operation,
                                               int depth,
                                               boolean exhaustive,
                                               java.util.List keys_done,
                                               int max_depth)

getStorageKey

protected DHTPluginStorageManager.storageKey getStorageKey(HashWrapper key)

deleteStorageKey

protected void deleteStorageKey(DHTPluginStorageManager.storageKey key)

suspendDivs

protected boolean suspendDivs()

readDiversifications

protected void readDiversifications()

writeDiversifications

protected void writeDiversifications()

lookupDiversification

protected DHTPluginStorageManager.diversification lookupDiversification(HashWrapper wrapper)

createDiversification

protected DHTPluginStorageManager.diversification createDiversification(HashWrapper wrapper,
                                                                        byte type)

divAdded

protected void divAdded(DHTPluginStorageManager.diversification div)

divRemoved

protected void divRemoved(DHTPluginStorageManager.diversification div)

getRemoteFreqDivCount

public int getRemoteFreqDivCount()
Specified by:
getRemoteFreqDivCount in interface DHTStorageAdapter

getRemoteSizeDivCount

public int getRemoteSizeDivCount()
Specified by:
getRemoteSizeDivCount in interface DHTStorageAdapter

formatExpiry

protected static java.lang.String formatExpiry(long l)

readKeyBlocks

protected void readKeyBlocks()

buildKeyBlockDetails

protected DHTStorageBlock[] buildKeyBlockDetails(ByteArrayHashMap map)

writeKeyBlocks

protected void writeKeyBlocks()

keyBlockRequest

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

verifyKeyBlock

protected boolean verifyKeyBlock(DHTPluginStorageManager.keyBlock kb,
                                 DHTTransportContact originator)

verifyKeyBlock

public static boolean verifyKeyBlock(byte[] request,
                                     byte[] signature)

getKeyBlockDetails

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

getDirectKeyBlocks

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

getKeyForKeyBlock

public byte[] getKeyForKeyBlock(byte[] request)
Specified by:
getKeyForKeyBlock in interface DHTStorageAdapter

purgeDirectKeyBlocks

protected void purgeDirectKeyBlocks()

setStorageForKey

public void setStorageForKey(java.lang.String key,
                             byte[] data)
Specified by:
setStorageForKey in interface DHTStorageAdapter

getStorageForKey

public byte[] getStorageForKey(java.lang.String key)
Specified by:
getStorageForKey in interface DHTStorageAdapter

diversifyKey

public static HashWrapper diversifyKey(HashWrapper key_in,
                                       int offset)

diversifyKey

public static byte[] diversifyKey(byte[] key_in,
                                  int offset)

diversifyKeyLocal

public static byte[] diversifyKeyLocal(byte[] key_in,
                                       int offset)