public class PeerManager
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
PeerManager.PeerStatusChangeListener
A listener interface that can be used to be notified about peer status change events
|
Modifier and Type | Field and Description |
---|---|
static int |
OUTDATED_MAX_CONNS |
static int |
OUTDATED_MIN_TOO_NEW_DARKNET |
static int |
OUTDATED_MIN_TOO_NEW_TOTAL |
static int |
PEER_NODE_STATUS_BURSTING |
static int |
PEER_NODE_STATUS_CLOCK_PROBLEM |
static int |
PEER_NODE_STATUS_CONN_ERROR |
static int |
PEER_NODE_STATUS_CONNECTED |
static int |
PEER_NODE_STATUS_DISABLED |
static int |
PEER_NODE_STATUS_DISCONNECTED |
static int |
PEER_NODE_STATUS_DISCONNECTING |
static int |
PEER_NODE_STATUS_LISTEN_ONLY |
static int |
PEER_NODE_STATUS_LISTENING |
static int |
PEER_NODE_STATUS_NEVER_CONNECTED |
static int |
PEER_NODE_STATUS_NO_LOAD_STATS |
static int |
PEER_NODE_STATUS_ROUTING_BACKED_OFF |
static int |
PEER_NODE_STATUS_ROUTING_DISABLED |
static int |
PEER_NODE_STATUS_TOO_NEW |
static int |
PEER_NODE_STATUS_TOO_OLD |
Constructor and Description |
---|
PeerManager(Node node,
SemiOrderedShutdownHook shutdownHook)
Create a PeerManager by reading a list of peers from
a file.
|
Modifier and Type | Method and Description |
---|---|
void |
addConnectedPeer(PeerNode pn) |
boolean |
addPeer(PeerNode pn) |
void |
addPeerNodeRoutingBackoffReason(java.lang.String peerNodeRoutingBackoffReason,
PeerNode peerNode,
boolean realTime)
Add a PeerNode routing backoff reason to the map
|
void |
addPeerStatusChangeListener(PeerManager.PeerStatusChangeListener listener)
Registers a listener to be notified when peers' statuses changes
|
boolean |
anyConnectedPeerHasAddress(FreenetInetAddress addr,
PeerNode pn) |
boolean |
anyConnectedPeers() |
boolean |
anyDarknetPeers() |
void |
changePeerNodeStatus(PeerNode peerNode,
int oldPeerNodeStatus,
int peerNodeStatus,
boolean noLog) |
PeerNode |
closerPeer(PeerNode pn,
java.util.Set<PeerNode> routedTo,
double target,
boolean ignoreSelf,
boolean calculateMisrouting,
int minVersion,
java.util.List<java.lang.Double> addUnpickedLocsTo,
double maxDistance,
Key key,
short outgoingHTL,
long ignoreBackoffUnder,
boolean isLocal,
boolean realTime,
RecentlyFailedReturn recentlyFailed,
boolean ignoreTimeout,
long now,
boolean newLoadManagement)
Find the peer, if any, which is closer to the target location than we are, and is not included in the provided set.
|
PeerNode |
closerPeer(PeerNode pn,
java.util.Set<PeerNode> routedTo,
double loc,
boolean ignoreSelf,
boolean calculateMisrouting,
int minVersion,
java.util.List<java.lang.Double> addUnpickedLocsTo,
Key key,
short outgoingHTL,
long ignoreBackoffUnder,
boolean isLocal,
boolean realTime,
boolean excludeMandatoryBackoff) |
void |
connect(SimpleFieldSet noderef,
OutgoingPacketMangler mangler,
DarknetPeerNode.FRIEND_TRUST trust,
DarknetPeerNode.FRIEND_VISIBILITY visibility)
Connect to a node provided the fieldset representing it.
|
PeerNode |
containsPeer(PeerNode pn) |
int |
countAlmostConnectedDarknetPeers() |
int |
countBackedOffPeers(boolean realTime) |
int |
countByStatus(int status)
Count the number of PeerNode's with a given status (right now, not
based on a snapshot).
|
int |
countCompatibleDarknetPeers() |
int |
countCompatibleRealPeers() |
int |
countConnectedDarknetPeers() |
int |
countConnectedOpennetPeers() |
int |
countConnectedPeers() |
int |
countConnectiblePeers()
How many peers do we have that actually may connect? Don't include seednodes, disabled nodes, etc.
|
int |
countNonBackedOffPeers(boolean realTime) |
int |
countSeednodes() |
int |
countValidPeers()
How many peers do we have that actually may connect? Don't include seednodes, disabled nodes, etc.
|
void |
disconnect(PeerNode pn,
boolean sendDisconnectMessage,
boolean waitForAck,
boolean purge,
boolean dumpMessagesNow,
boolean remove,
long timeout)
Disconnect from a specified node
|
void |
disconnectAndRemove(PeerNode pn,
boolean sendDisconnectMessage,
boolean waitForAck,
boolean purge) |
boolean |
disconnected(PeerNode pn) |
java.util.ArrayList<PeerNode> |
getAllConnectedByAddress(FreenetInetAddress a,
boolean strict)
Find nodes with a given IP address.
|
PeerNode |
getByPeer(Peer peer)
Find the node with the given Peer address.
|
PeerNode |
getByPeer(Peer peer,
FNPPacketMangler mangler)
Find the node with the given Peer address, or IP address.
|
PeerNode |
getByPubKeyHash(byte[] pkHash) |
java.util.List<SeedServerPeerNode> |
getConnectedSeedServerPeersVector(java.util.HashSet<ByteArrayWrapper> exclude)
Get the currently connected seednodes.
|
DarknetPeerNodeStatus[] |
getDarknetPeerNodeStatuses(boolean noHeavy) |
DarknetPeerNode[] |
getDarknetPeers()
Get the darknet peers list.
|
protected java.lang.String |
getDarknetPeersString() |
long |
getOldestNeverConnectedDarknetPeerAge() |
protected java.lang.String |
getOldOpennetPeersString(OpennetManager om) |
PeerNode[] |
getOpennetAndSeedServerPeers() |
OpennetPeerNodeStatus[] |
getOpennetPeerNodeStatuses(boolean noHeavy) |
OpennetPeerNode[] |
getOpennetPeers()
Get the opennet peers list.
|
protected java.lang.String |
getOpennetPeersString() |
double[] |
getPeerLocationDoubles(boolean pruneBackedOffPeers) |
java.lang.String[] |
getPeerNodeRoutingBackoffReasons(boolean realTime)
What are the currently tracked PeerNode routing backoff reasons?
|
int |
getPeerNodeRoutingBackoffReasonSize(java.lang.String peerNodeRoutingBackoffReason,
boolean realTime)
How many PeerNodes have a particular routing backoff reason?
|
PeerNodeStatus[] |
getPeerNodeStatuses(boolean noHeavy) |
int |
getPeerNodeStatusSize(int pnStatus,
boolean darknet)
How many PeerNodes have a particular status?
|
PeerNode |
getRandomPeer() |
PeerNode |
getRandomPeer(PeerNode exclude) |
java.util.List<SeedServerPeerNode> |
getSeedServerPeersVector() |
java.lang.String |
getStatus() |
long |
getTimeFirstAnyConnections() |
java.lang.String |
getTMCIPeerList() |
boolean |
isOutdated() |
void |
localBroadcast(Message msg,
boolean ignoreRoutability,
boolean onlyRealConnections,
ByteCounter ctr) |
void |
localBroadcast(Message msg,
boolean ignoreRoutability,
boolean onlyRealConnections,
ByteCounter ctr,
int minVersion,
int maxVersion)
Asynchronously send this message to every connected peer.
|
void |
locallyBroadcastDiffNodeRef(SimpleFieldSet fs,
boolean toDarknetOnly,
boolean toOpennetOnly)
Asynchronously send a differential node reference to every isConnected() peer.
|
void |
maybeLogPeerNodeStatusSummary(long now)
Log the current PeerNode status summary if the timer has expired
|
void |
maybeUpdateOldestNeverConnectedDarknetPeerAge(long now)
Update oldestNeverConnectedPeerAge if the timer has expired
|
void |
maybeUpdatePeerNodeRoutableConnectionStats(long now)
Update hadRoutableConnectionCount/routableConnectionCheckCount on peers if the timer has expired
|
void |
readExtraPeerData()
Ask each PeerNode to read in it's extra peer data
|
boolean |
removeAllPeers() |
void |
removeOpennetPeers() |
void |
removePeerNodeRoutingBackoffReason(java.lang.String peerNodeRoutingBackoffReason,
PeerNode peerNode,
boolean realTime)
Remove a PeerNode routing backoff reason from the map
|
void |
removePeerStatusChangeListener(PeerManager.PeerStatusChangeListener listener)
Removes a listener
|
void |
start() |
void |
updatePMUserAlert()
Update the numbers needed by our PeerManagerUserAlert on the UAM.
|
protected void |
writePeersNow(boolean rotateBackups) |
public static final int PEER_NODE_STATUS_CONNECTED
public static final int PEER_NODE_STATUS_ROUTING_BACKED_OFF
public static final int PEER_NODE_STATUS_TOO_NEW
public static final int PEER_NODE_STATUS_TOO_OLD
public static final int PEER_NODE_STATUS_DISCONNECTED
public static final int PEER_NODE_STATUS_NEVER_CONNECTED
public static final int PEER_NODE_STATUS_DISABLED
public static final int PEER_NODE_STATUS_BURSTING
public static final int PEER_NODE_STATUS_LISTENING
public static final int PEER_NODE_STATUS_LISTEN_ONLY
public static final int PEER_NODE_STATUS_CLOCK_PROBLEM
public static final int PEER_NODE_STATUS_CONN_ERROR
public static final int PEER_NODE_STATUS_DISCONNECTING
public static final int PEER_NODE_STATUS_ROUTING_DISABLED
public static final int PEER_NODE_STATUS_NO_LOAD_STATS
public static final int OUTDATED_MIN_TOO_NEW_TOTAL
public static final int OUTDATED_MIN_TOO_NEW_DARKNET
public static final int OUTDATED_MAX_CONNS
public PeerManager(Node node, SemiOrderedShutdownHook shutdownHook)
node
- shutdownHook
- protected void writePeersNow(boolean rotateBackups)
public boolean addPeer(PeerNode pn)
public boolean removeAllPeers()
public boolean disconnected(PeerNode pn)
public long getTimeFirstAnyConnections()
public void addConnectedPeer(PeerNode pn)
public PeerNode getByPeer(Peer peer)
public PeerNode getByPeer(Peer peer, FNPPacketMangler mangler)
peer
- mangler
- public java.util.ArrayList<PeerNode> getAllConnectedByAddress(FreenetInetAddress a, boolean strict)
public void connect(SimpleFieldSet noderef, OutgoingPacketMangler mangler, DarknetPeerNode.FRIEND_TRUST trust, DarknetPeerNode.FRIEND_VISIBILITY visibility) throws FSParseException, PeerParseException, ReferenceSignatureVerificationException, PeerTooOldException
public void disconnectAndRemove(PeerNode pn, boolean sendDisconnectMessage, boolean waitForAck, boolean purge)
public void disconnect(PeerNode pn, boolean sendDisconnectMessage, boolean waitForAck, boolean purge, boolean dumpMessagesNow, boolean remove, long timeout)
sendDisconnectMessage
- If false, don't send the FNPDisconnected message.waitForAck
- If false, don't wait for the ack for the FNPDisconnected message.purge
- If true, set the purge flag on the disconnect, causing the other peer
to purge this node from e.g. its old opennet peers list.dumpMessagesNow
- If true, dump queued messages immediately, before the
disconnect completes.remove
- If true, remove the node from the routing table and tell the peer to do so.public double[] getPeerLocationDoubles(boolean pruneBackedOffPeers)
public PeerNode getRandomPeer(PeerNode exclude)
public void localBroadcast(Message msg, boolean ignoreRoutability, boolean onlyRealConnections, ByteCounter ctr)
public void localBroadcast(Message msg, boolean ignoreRoutability, boolean onlyRealConnections, ByteCounter ctr, int minVersion, int maxVersion)
maxVersion
- Only send the message if the version >= maxVersion.minVersion
- Only send the message if the version <= minVersion.public void locallyBroadcastDiffNodeRef(SimpleFieldSet fs, boolean toDarknetOnly, boolean toOpennetOnly)
public PeerNode getRandomPeer()
public PeerNode closerPeer(PeerNode pn, java.util.Set<PeerNode> routedTo, double loc, boolean ignoreSelf, boolean calculateMisrouting, int minVersion, java.util.List<java.lang.Double> addUnpickedLocsTo, Key key, short outgoingHTL, long ignoreBackoffUnder, boolean isLocal, boolean realTime, boolean excludeMandatoryBackoff)
public PeerNode closerPeer(PeerNode pn, java.util.Set<PeerNode> routedTo, double target, boolean ignoreSelf, boolean calculateMisrouting, int minVersion, java.util.List<java.lang.Double> addUnpickedLocsTo, double maxDistance, Key key, short outgoingHTL, long ignoreBackoffUnder, boolean isLocal, boolean realTime, RecentlyFailedReturn recentlyFailed, boolean ignoreTimeout, long now, boolean newLoadManagement)
addUnpickedLocsTo
- Add all locations we didn't choose which we could have routed to to
this array. Remove the location of the peer we pick from it.maxDistance
- If a node is further away from the target than this distance, ignore it.key
- The original key, if we have it, and if we want to consult with the FailureTable
to avoid routing to nodes which have recently failed for the same key.isLocal
- We don't just check pn == null because in some cases pn can be null here: If an insert is forked, for
a remote requests, we can route back to the originator, so we set pn to null. Whereas for stats we want to know
accurately whether this was originated remotely.recentlyFailed
- If non-null, we should check for recently failed: If we have routed to, and got
a failed response from, and are still connected to and within the timeout for, our top two routing choices,
*and* the same is true of at least 3 nodes, we fill in this object and return null. This will cause a
RecentlyFailed message to be returned to the originator, allowing them to retry in a little while. Note that the
scheduler is not clever enough to retry immediately when that timeout elapses, and even if it was, it probably
wouldn't be a good idea due to introducing a round-trip-to-request-originator; FIXME consider this.public java.lang.String getStatus()
public java.lang.String getTMCIPeerList()
protected java.lang.String getDarknetPeersString()
protected java.lang.String getOpennetPeersString()
protected java.lang.String getOldOpennetPeersString(OpennetManager om)
public void updatePMUserAlert()
public boolean anyConnectedPeers()
public boolean anyDarknetPeers()
public void readExtraPeerData()
public void start()
public int countNonBackedOffPeers(boolean realTime)
public void maybeUpdateOldestNeverConnectedDarknetPeerAge(long now)
public long getOldestNeverConnectedDarknetPeerAge()
public void maybeLogPeerNodeStatusSummary(long now)
public void changePeerNodeStatus(PeerNode peerNode, int oldPeerNodeStatus, int peerNodeStatus, boolean noLog)
public int getPeerNodeStatusSize(int pnStatus, boolean darknet)
darknet
- If true, only count darknet nodes, if false, count all nodes.public void addPeerNodeRoutingBackoffReason(java.lang.String peerNodeRoutingBackoffReason, PeerNode peerNode, boolean realTime)
public java.lang.String[] getPeerNodeRoutingBackoffReasons(boolean realTime)
public int getPeerNodeRoutingBackoffReasonSize(java.lang.String peerNodeRoutingBackoffReason, boolean realTime)
public void removePeerNodeRoutingBackoffReason(java.lang.String peerNodeRoutingBackoffReason, PeerNode peerNode, boolean realTime)
public PeerNodeStatus[] getPeerNodeStatuses(boolean noHeavy)
public DarknetPeerNodeStatus[] getDarknetPeerNodeStatuses(boolean noHeavy)
public OpennetPeerNodeStatus[] getOpennetPeerNodeStatuses(boolean noHeavy)
public void maybeUpdatePeerNodeRoutableConnectionStats(long now)
public DarknetPeerNode[] getDarknetPeers()
public java.util.List<SeedServerPeerNode> getConnectedSeedServerPeersVector(java.util.HashSet<ByteArrayWrapper> exclude)
exclude
- Set of peer public keys to exclude.public java.util.List<SeedServerPeerNode> getSeedServerPeersVector()
public OpennetPeerNode[] getOpennetPeers()
public PeerNode[] getOpennetAndSeedServerPeers()
public boolean anyConnectedPeerHasAddress(FreenetInetAddress addr, PeerNode pn)
public void removeOpennetPeers()
public int countConnectedDarknetPeers()
public int countConnectedPeers()
public int countAlmostConnectedDarknetPeers()
public int countCompatibleDarknetPeers()
public int countCompatibleRealPeers()
public int countConnectedOpennetPeers()
public int countValidPeers()
public int countConnectiblePeers()
public int countSeednodes()
public int countBackedOffPeers(boolean realTime)
public PeerNode getByPubKeyHash(byte[] pkHash)
public void addPeerStatusChangeListener(PeerManager.PeerStatusChangeListener listener)
listener
- - the listener to be registeredpublic void removePeerStatusChangeListener(PeerManager.PeerStatusChangeListener listener)
listener
- - The listener to be removedpublic int countByStatus(int status)
public boolean isOutdated()