Package com.biglybt.core.dht.router.impl
Class DHTRouterImpl
- java.lang.Object
-
- com.biglybt.core.dht.router.impl.DHTRouterImpl
-
-
Field Summary
-
Constructor Summary
Constructors Constructor Description DHTRouterImpl(int _K, int _B, int _max_rep_per_node, byte[] _router_node_id, DHTRouterContactAttachment _attachment, DHTLogger _logger)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addContact(byte[] node_id, DHTRouterContactAttachment attachment, boolean known_to_be_alive)
private DHTRouterContact
addContactSupport(byte[] node_id, DHTRouterContactAttachment attachment, boolean known_to_be_alive)
boolean
addObserver(DHTRouterObserver rto)
Adds a routing table observer if it is not already observing.void
contactAlive(byte[] node_id, DHTRouterContactAttachment attachment)
Adds a contact to the router and marks it as "known to be alive"DHTRouterContact
contactDead(byte[] node_id, boolean force)
Informs the router that an attempt to interact with the contact failedprivate void
contactDeadSupport(DHTRouterNodeImpl node, DHTRouterContactImpl contact, boolean force)
void
contactKnown(byte[] node_id, DHTRouterContactAttachment attachment, boolean force)
Adds a contact to the router.void
contactRemoved(byte[] node_id)
boolean
containsObserver(DHTRouterObserver rto)
Returns whether the given observer is already observing.void
destroy()
protected void
dispatchNodeAdds()
protected void
dispatchPings()
protected void
findAllContacts(java.util.List list, DHTRouterNodeImpl node)
protected void
findAllContacts(java.util.Set set, DHTRouterNodeImpl node)
java.util.List
findBestContacts(int max)
returns a list of best contacts in terms of uptime, best firstjava.util.List
findClosestContacts(byte[] node_id, int num_to_return, boolean live_only)
Returns num_to_return or a few more closest contacts, unorderedprotected void
findClosestContacts(byte[] node_id, int num_to_return, int depth, DHTRouterNodeImpl current_node, boolean live_only, java.util.List res)
DHTRouterContact
findContact(byte[] node_id)
protected java.lang.Object[]
findContactSupport(byte[] node_id)
protected DHTRouterNodeImpl
findNode(byte[] node_id)
java.util.List
getAllContacts()
Returns a list of DHTRouterContact objectsprotected long
getContactCount()
protected long
getContactCount(DHTRouterNodeImpl node)
byte[]
getID()
int
getK()
DHTRouterContact
getLocalContact()
protected long
getNodeCount()
protected long
getNodeCount(DHTRouterNodeImpl node)
protected DHTRouterNodeImpl
getSmallestSubtree()
DHTRouterStats
getStats()
protected long[]
getStatsSupport()
protected void
getStatsSupport(long[] stats_array, DHTRouterNodeImpl node)
boolean
isID(byte[] id)
protected void
log(java.lang.String str)
protected void
notifyAdded(DHTRouterContact contact)
protected void
notifyDead()
protected void
notifyLocationChanged(DHTRouterContact contact)
protected void
notifyNowAlive(DHTRouterContact contact)
protected void
notifyNowFailing(DHTRouterContact contact)
protected void
notifyRemoved(DHTRouterContact contact)
protected void
pingeroonies()
void
print()
void
recordLookup(byte[] node_id)
void
refreshIdleLeaves(long idle_max)
protected void
refreshNode(java.util.List nodes_to_refresh, DHTRouterNodeImpl node, byte[] path)
protected void
refreshNodes(java.util.List nodes_to_refresh, DHTRouterNodeImpl node, byte[] path, boolean seeding, long max_permitted_idle)
byte[]
refreshRandom()
boolean
removeObserver(DHTRouterObserver rto)
Removes the observer if it is already observing.protected void
requestLookup(byte[] id, java.lang.String description)
protected void
requestNodeAdd(DHTRouterContactImpl contact)
boolean
requestPing(byte[] node_id)
protected void
requestPing(DHTRouterContactImpl contact)
void
seed()
Tells the router to perform its "start of day" functions required to integrate it into the DHT (search for itself, refresh buckets)protected void
seedSupport()
void
setAdapter(DHTRouterAdapter _adapter)
void
setSleeping(boolean _sleeping)
void
setSuspended(boolean _suspended)
-
-
-
Field Detail
-
SMALLEST_SUBTREE_MAX_EXCESS
private static final int SMALLEST_SUBTREE_MAX_EXCESS
- See Also:
- Constant Field Values
-
is_bootstrap_proxy
private boolean is_bootstrap_proxy
-
K
private int K
-
B
private int B
-
max_rep_per_node
private int max_rep_per_node
-
logger
private DHTLogger logger
-
smallest_subtree_max
private int smallest_subtree_max
-
adapter
private DHTRouterAdapter adapter
-
local_contact
private DHTRouterContactImpl local_contact
-
router_node_id
private byte[] router_node_id
-
root
private DHTRouterNodeImpl root
-
smallest_subtree
private DHTRouterNodeImpl smallest_subtree
-
consecutive_dead
private int consecutive_dead
-
random_seed
private static long random_seed
-
random
private java.util.Random random
-
outstanding_pings
private java.util.List<DHTRouterContactImpl> outstanding_pings
-
outstanding_adds
private java.util.List<DHTRouterContactImpl> outstanding_adds
-
stats
private final DHTRouterStatsImpl stats
-
this_mon
private final AEMonitor this_mon
-
class_mon
private static final AEMonitor class_mon
-
observers
private final CopyOnWriteList<DHTRouterObserver> observers
-
sleeping
private boolean sleeping
-
suspended
boolean suspended
-
recent_contact_bloom
private final BloomFilter recent_contact_bloom
-
timer_event
private TimerEventPeriodic timer_event
-
seed_in_ticks
volatile int seed_in_ticks
-
TICK_PERIOD
private static final int TICK_PERIOD
- See Also:
- Constant Field Values
-
SEED_DELAY_PERIOD
private static final int SEED_DELAY_PERIOD
- See Also:
- Constant Field Values
-
SEED_DELAY_TICKS
private static final int SEED_DELAY_TICKS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DHTRouterImpl
public DHTRouterImpl(int _K, int _B, int _max_rep_per_node, byte[] _router_node_id, DHTRouterContactAttachment _attachment, DHTLogger _logger)
-
-
Method Detail
-
notifyAdded
protected void notifyAdded(DHTRouterContact contact)
-
notifyRemoved
protected void notifyRemoved(DHTRouterContact contact)
-
notifyLocationChanged
protected void notifyLocationChanged(DHTRouterContact contact)
-
notifyNowAlive
protected void notifyNowAlive(DHTRouterContact contact)
-
notifyNowFailing
protected void notifyNowFailing(DHTRouterContact contact)
-
notifyDead
protected void notifyDead()
-
addObserver
public boolean addObserver(DHTRouterObserver rto)
Description copied from interface:DHTRouter
Adds a routing table observer if it is not already observing.- Specified by:
addObserver
in interfaceDHTRouter
- Parameters:
rto
- the observer to add- Returns:
true
if now observing,false
otherwise
-
containsObserver
public boolean containsObserver(DHTRouterObserver rto)
Description copied from interface:DHTRouter
Returns whether the given observer is already observing.- Specified by:
containsObserver
in interfaceDHTRouter
- Parameters:
rto
- the observer to query as observing- Returns:
true
if observing,false
otherwise
-
removeObserver
public boolean removeObserver(DHTRouterObserver rto)
Description copied from interface:DHTRouter
Removes the observer if it is already observing.- Specified by:
removeObserver
in interfaceDHTRouter
- Parameters:
rto
- the observer to remove- Returns:
true
if no longer observing,false
otherwise
-
getStats
public DHTRouterStats getStats()
-
getLocalContact
public DHTRouterContact getLocalContact()
- Specified by:
getLocalContact
in interfaceDHTRouter
-
setAdapter
public void setAdapter(DHTRouterAdapter _adapter)
- Specified by:
setAdapter
in interfaceDHTRouter
-
setSleeping
public void setSleeping(boolean _sleeping)
- Specified by:
setSleeping
in interfaceDHTRouter
-
setSuspended
public void setSuspended(boolean _suspended)
- Specified by:
setSuspended
in interfaceDHTRouter
-
contactKnown
public void contactKnown(byte[] node_id, DHTRouterContactAttachment attachment, boolean force)
Description copied from interface:DHTRouter
Adds a contact to the router. The contact is not known to be alive (e.g. we've been returned the contact by someone but we've not either got a reply from it, nor has it invoked us.- Specified by:
contactKnown
in interfaceDHTRouter
-
contactAlive
public void contactAlive(byte[] node_id, DHTRouterContactAttachment attachment)
Description copied from interface:DHTRouter
Adds a contact to the router and marks it as "known to be alive"- Specified by:
contactAlive
in interfaceDHTRouter
-
contactDead
public DHTRouterContact contactDead(byte[] node_id, boolean force)
Description copied from interface:DHTRouter
Informs the router that an attempt to interact with the contact failed- Specified by:
contactDead
in interfaceDHTRouter
- Returns:
-
contactDeadSupport
private void contactDeadSupport(DHTRouterNodeImpl node, DHTRouterContactImpl contact, boolean force)
-
contactRemoved
public void contactRemoved(byte[] node_id)
-
addContact
public void addContact(byte[] node_id, DHTRouterContactAttachment attachment, boolean known_to_be_alive)
-
addContactSupport
private DHTRouterContact addContactSupport(byte[] node_id, DHTRouterContactAttachment attachment, boolean known_to_be_alive)
-
findClosestContacts
public java.util.List findClosestContacts(byte[] node_id, int num_to_return, boolean live_only)
Description copied from interface:DHTRouter
Returns num_to_return or a few more closest contacts, unordered- Specified by:
findClosestContacts
in interfaceDHTRouter
-
findClosestContacts
protected void findClosestContacts(byte[] node_id, int num_to_return, int depth, DHTRouterNodeImpl current_node, boolean live_only, java.util.List res)
-
findContact
public DHTRouterContact findContact(byte[] node_id)
- Specified by:
findContact
in interfaceDHTRouter
-
findNode
protected DHTRouterNodeImpl findNode(byte[] node_id)
-
findContactSupport
protected java.lang.Object[] findContactSupport(byte[] node_id)
-
getNodeCount
protected long getNodeCount()
-
getNodeCount
protected long getNodeCount(DHTRouterNodeImpl node)
-
getContactCount
protected long getContactCount()
-
getContactCount
protected long getContactCount(DHTRouterNodeImpl node)
-
findBestContacts
public java.util.List findBestContacts(int max)
Description copied from interface:DHTRouter
returns a list of best contacts in terms of uptime, best first- Specified by:
findBestContacts
in interfaceDHTRouter
- Returns:
-
getAllContacts
public java.util.List getAllContacts()
Description copied from interface:DHTRouter
Returns a list of DHTRouterContact objects- Specified by:
getAllContacts
in interfaceDHTRouter
- Returns:
-
findAllContacts
protected void findAllContacts(java.util.Set set, DHTRouterNodeImpl node)
-
findAllContacts
protected void findAllContacts(java.util.List list, DHTRouterNodeImpl node)
-
seed
public void seed()
Description copied from interface:DHTRouter
Tells the router to perform its "start of day" functions required to integrate it into the DHT (search for itself, refresh buckets)
-
seedSupport
protected void seedSupport()
-
refreshNodes
protected void refreshNodes(java.util.List nodes_to_refresh, DHTRouterNodeImpl node, byte[] path, boolean seeding, long max_permitted_idle)
-
refreshNode
protected void refreshNode(java.util.List nodes_to_refresh, DHTRouterNodeImpl node, byte[] path)
-
getSmallestSubtree
protected DHTRouterNodeImpl getSmallestSubtree()
-
recordLookup
public void recordLookup(byte[] node_id)
- Specified by:
recordLookup
in interfaceDHTRouter
-
refreshIdleLeaves
public void refreshIdleLeaves(long idle_max)
- Specified by:
refreshIdleLeaves
in interfaceDHTRouter
-
requestPing
public boolean requestPing(byte[] node_id)
- Specified by:
requestPing
in interfaceDHTRouter
-
requestPing
protected void requestPing(DHTRouterContactImpl contact)
-
dispatchPings
protected void dispatchPings()
-
pingeroonies
protected void pingeroonies()
-
requestNodeAdd
protected void requestNodeAdd(DHTRouterContactImpl contact)
-
dispatchNodeAdds
protected void dispatchNodeAdds()
-
refreshRandom
public byte[] refreshRandom()
- Specified by:
refreshRandom
in interfaceDHTRouter
-
requestLookup
protected void requestLookup(byte[] id, java.lang.String description)
-
getStatsSupport
protected void getStatsSupport(long[] stats_array, DHTRouterNodeImpl node)
-
getStatsSupport
protected long[] getStatsSupport()
-
log
protected void log(java.lang.String str)
-
-