Package com.biglybt.plugin.dht.impl
Class DHTPluginStorageManager
- java.lang.Object
-
- com.biglybt.plugin.dht.impl.DHTPluginStorageManager
-
- All Implemented Interfaces:
DHTStorageAdapter
public class DHTPluginStorageManager extends java.lang.Object implements DHTStorageAdapter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
DHTPluginStorageManager.diversification
protected static class
DHTPluginStorageManager.keyBlock
protected static class
DHTPluginStorageManager.storageKey
-
Field Summary
-
Constructor Summary
Constructors Constructor Description DHTPluginStorageManager(int _network, DHTLogger _log, java.io.File _data_dir)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 keyvoid
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()
-
-
-
Field Detail
-
pub_exp
private static final java.lang.String pub_exp
- See Also:
- Constant Field Values
-
modulus
private static final java.lang.String modulus
- See Also:
- Constant Field Values
-
ADDRESS_EXPIRY
private static final long ADDRESS_EXPIRY
- See Also:
- Constant Field Values
-
DIV_WIDTH
private static final int DIV_WIDTH
- See Also:
- Constant Field Values
-
DIV_FRAG_GET_SIZE
private static final int DIV_FRAG_GET_SIZE
- See Also:
- Constant Field Values
-
DIV_EXPIRY_MIN
private static final long DIV_EXPIRY_MIN
- See Also:
- Constant Field Values
-
DIV_EXPIRY_RAND
private static final long DIV_EXPIRY_RAND
- See Also:
- Constant Field Values
-
KEY_BLOCK_TIMEOUT_SECS
private static final long KEY_BLOCK_TIMEOUT_SECS
- See Also:
- Constant Field Values
-
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
-
network
private int network
-
log
private DHTLogger log
-
data_dir
private java.io.File data_dir
-
address_mon
private AEMonitor address_mon
-
contact_mon
private AEMonitor contact_mon
-
storage_mon
private AEMonitor storage_mon
-
version_mon
private AEMonitor version_mon
-
key_block_mon
private AEMonitor key_block_mon
-
version_map
private java.util.Map version_map
-
recent_addresses
private java.util.Map recent_addresses
-
remote_diversifications
private java.util.Map remote_diversifications
-
local_storage_keys
private java.util.Map local_storage_keys
-
remote_freq_div_count
private int remote_freq_div_count
-
remote_size_div_count
private int remote_size_div_count
-
key_block_map_cow
private volatile ByteArrayHashMap key_block_map_cow
-
key_blocks_direct_cow
private volatile DHTStorageBlock[] key_blocks_direct_cow
-
kb_verify_fail_bloom
private BloomFilter kb_verify_fail_bloom
-
kb_verify_fail_bloom_create_time
private long kb_verify_fail_bloom_create_time
-
suspend_divs_until
private long suspend_divs_until
-
key_block_public_key
private static java.security.interfaces.RSAPublicKey key_block_public_key
-
-
Constructor Detail
-
DHTPluginStorageManager
public DHTPluginStorageManager(int _network, DHTLogger _log, java.io.File _data_dir)
-
-
Method Detail
-
getNetwork
public int getNetwork()
- Specified by:
getNetwork
in interfaceDHTStorageAdapter
-
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 interfaceDHTStorageAdapter
-
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 interfaceDHTStorageAdapter
- Returns:
- null if the key shouldn't be allocated (e.g.out of space)
-
keyDeleted
public void keyDeleted(DHTStorageKey key)
- Specified by:
keyDeleted
in interfaceDHTStorageAdapter
-
getKeyCount
public int getKeyCount()
- Specified by:
getKeyCount
in interfaceDHTStorageAdapter
-
keyRead
public void keyRead(DHTStorageKey key, DHTTransportContact contact)
- Specified by:
keyRead
in interfaceDHTStorageAdapter
-
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 interfaceDHTStorageAdapter
- 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 interfaceDHTStorageAdapter
-
valueUpdated
public void valueUpdated(DHTStorageKey key, DHTTransportValue old_value, DHTTransportValue new_value)
- Specified by:
valueUpdated
in interfaceDHTStorageAdapter
-
valueDeleted
public void valueDeleted(DHTStorageKey key, DHTTransportValue value)
- Specified by:
valueDeleted
in interfaceDHTStorageAdapter
-
isDiversified
public boolean isDiversified(byte[] key)
- Specified by:
isDiversified
in interfaceDHTStorageAdapter
-
getExistingDiversification
public byte[][] getExistingDiversification(byte[] key, boolean put_operation, boolean exhaustive, int max_depth)
- Specified by:
getExistingDiversification
in interfaceDHTStorageAdapter
-
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 interfaceDHTStorageAdapter
-
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 interfaceDHTStorageAdapter
-
getRemoteSizeDivCount
public int getRemoteSizeDivCount()
- Specified by:
getRemoteSizeDivCount
in interfaceDHTStorageAdapter
-
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 interfaceDHTStorageAdapter
-
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 interfaceDHTStorageAdapter
-
getDirectKeyBlocks
public DHTStorageBlock[] getDirectKeyBlocks()
- Specified by:
getDirectKeyBlocks
in interfaceDHTStorageAdapter
-
getKeyForKeyBlock
public byte[] getKeyForKeyBlock(byte[] request)
- Specified by:
getKeyForKeyBlock
in interfaceDHTStorageAdapter
-
purgeDirectKeyBlocks
protected void purgeDirectKeyBlocks()
-
setStorageForKey
public void setStorageForKey(java.lang.String key, byte[] data)
- Specified by:
setStorageForKey
in interfaceDHTStorageAdapter
-
getStorageForKey
public byte[] getStorageForKey(java.lang.String key)
- Specified by:
getStorageForKey
in interfaceDHTStorageAdapter
-
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)
-
-