public abstract class PeerNode extends java.lang.Object implements USKRetrieverCallback, BasePeerNode
Modifier and Type | Class and Description |
---|---|
class |
PeerNode.IncomingLoadSummaryStats |
static class |
PeerNode.SlotWaiter |
Modifier and Type | Field and Description |
---|---|
RunningAverage |
backedOffPercent |
RunningAverage |
backedOffPercentBulk |
RunningAverage |
backedOffPercentRT |
static double |
BLACK_MAGIC_BACKOFF_PRUNING_PERCENTAGE |
static long |
BLACK_MAGIC_BACKOFF_PRUNING_TIME
Some alchemy we use in PeerNode.shouldBeExcludedFromPeerList()
|
protected NodeCrypto |
crypto |
protected boolean |
disableRouting |
protected boolean |
disableRoutingHasBeenSetLocally |
protected boolean |
disableRoutingHasBeenSetRemotely |
protected SimpleFieldSet |
fullFieldSet |
protected byte[] |
hmacKey |
protected byte[] |
incommingKey |
protected byte[] |
ivKey |
protected byte[] |
ivNonce |
protected long |
jfkContextLifetime |
protected byte[] |
jfkKa |
protected byte[] |
jfkKe |
protected byte[] |
jfkMyRef |
protected java.util.LinkedList<byte[]> |
jfkNoncesSent
For FNP link setup:
The initiator has to ensure that nonces send back by the
responder in message2 match what was chosen in message 1
|
protected boolean |
neverConnected
True if we have never connected to this peer since it was added to this node
|
protected java.util.List<Peer> |
nominalPeer
Advertised addresses
|
protected int |
ourInitialMsgID |
protected int |
ourInitialSeqNum |
protected byte[] |
outgoingKey |
protected long |
peerAddedTime
When this peer was added to this node.
|
java.security.interfaces.ECPublicKey |
peerECDSAPubKey
Peer node public key; changing this means new noderef
|
byte[] |
peerECDSAPubKeyHash |
int |
peerNodeStatus
The status of this peer node in terms of Node.PEER_NODE_STATUS_*
|
ByteCounter |
resendByteCounter |
static int |
SELECTION_MAX_SAMPLES |
static int |
SELECTION_MIN_PEERS |
static int |
SELECTION_PERCENTAGE_WARNING |
static long |
SELECTION_SAMPLING_PERIOD |
protected long |
sendHandshakeTime
Time at which we should send the next handshake request
|
protected boolean |
sendingUOMLegacyExtJar
Whether we are sending the ext jar (legacy) to this peer
|
protected boolean |
sendingUOMMainJar
Whether we are sending the main jar to this peer
|
boolean |
testnetEnabled
Is this a testnet node?
|
protected int |
theirInitialMsgID |
protected int |
theirInitialSeqNum |
protected boolean |
unroutableNewerVersion
True if this peer reports that our build number is before their last-known-good build number.
|
protected boolean |
unroutableOlderVersion
True if this peer has a build number older than our last-known-good build number.
|
Constructor and Description |
---|
PeerNode(SimpleFieldSet fs,
Node node2,
NodeCrypto crypto,
boolean fromLocal)
Create a PeerNode from a SimpleFieldSet containing a
node reference for one.
|
Modifier and Type | Method and Description |
---|---|
void |
acceptedAny(boolean realTimeFlag)
Accepting a request, even if it was not GUARANTEED, resets the counters
for consecutive guaranteed rejections.
|
void |
addToLocalNodeReceivedMessagesFromStatistic(Message m) |
void |
addToLocalNodeSentMessagesToStatistic(Message m) |
boolean |
allowLocalAddresses()
Is this peer allowed local addresses? If false, we will never connect to this peer via
a local address even if it advertises them.
|
double |
averagePingTime() |
double |
averagePingTimeCorrected()
Calculated as per RFC 2988
|
void |
backoffOnResend()
Double the RTT when we resend a packet.
|
protected void |
calcNextHandshake(boolean successfulHandshakeSend,
boolean dontFetchARK,
boolean notRegistered) |
int |
calculateMaxTransfersOut(int timeout,
double nonOverheadFraction)
Calculate the maximum number of outgoing transfers to this peer that we
will accept in requests and inserts.
|
abstract boolean |
canAcceptAnnouncements()
Can we accept announcements from this node?
|
void |
changedIP(Peer newPeer)
IP on the other side appears to have changed...
|
void |
checkForLostPackets() |
void |
checkRoutableConnectionStatus() |
boolean |
completedAnnounce(long uid) |
long |
completedHandshake(long thisBootID,
byte[] data,
int offset,
int length,
BlockCipher outgoingCipher,
byte[] outgoingKey,
BlockCipher incommingCipher,
byte[] incommingKey,
Peer replyTo,
boolean unverified,
int negType,
long trackerID,
boolean isJFK4,
boolean jfk4SameAsOld,
byte[] hmacKey,
BlockCipher ivCipher,
byte[] ivNonce,
int ourInitialSeqNum,
int theirInitialSeqNum,
int ourInitialMsgID,
int theirInitialMsgID)
Called when we have completed a handshake, and have a new session key.
|
void |
couldNotSendHandshake(boolean notRegistered)
Call this method when a handshake request could not be sent (i.e.
|
int |
countFailedRevocationTransfers() |
static PeerNode |
create(SimpleFieldSet fs,
Node node2,
NodeCrypto crypto,
OpennetManager opennet,
PeerManager manager)
Create a DarknetPeerNode or an OpennetPeerNode as appropriate
|
short |
decrementHTL(short htl)
Decrement the HTL (or not), in accordance with our
probabilistic HTL rules.
|
void |
decrementUOMSends() |
boolean |
disconnected(boolean dumpMessageQueue,
boolean dumpTrackers)
Disconnected e.g.
|
boolean |
dontRoute() |
void |
dumpTracker(SessionKey brokenKey)
Only called for new format connections, for which we don't care about PacketTracker
|
void |
enterMandatoryBackoff(java.lang.String reason,
boolean realTime)
When load management predicts that a peer will definitely accept the request, both
before it was sent and after we got the rejected, we go into mandatory backoff.
|
boolean |
equals(java.lang.Object o) |
SimpleFieldSet |
exportDiskFieldSet()
(both metadata + normal fieldset but atomically)
|
SimpleFieldSet |
exportFieldSet()
Export the peer's noderef as a SimpleFieldSet
|
SimpleFieldSet |
exportMetadataFieldSet(long now)
Export metadata about the node as a SimpleFieldSet
|
SimpleFieldSet |
exportVolatileFieldSet()
Export volatile data about the node as a SimpleFieldSet
|
void |
failedRevocationTransfer() |
abstract void |
fatalTimeout()
After a fatal timeout - that is, a timeout that we reasonably believe originated
on the node rather than downstream - we do not know whether or not the node thinks
the request is still running.
|
void |
fatalTimeout(UIDTag tag,
boolean offeredKey)
A fatal timeout occurred, and we don't know whether the peer is still running the
request we passed in for us.
|
void |
finishedSendingUOMJar(boolean isExt) |
void |
forceCancelDisconnecting()
Called to cancel a delayed disconnect.
|
void |
forceDisconnect()
Force the peer to disconnect.
|
protected boolean |
fromAnonymousInitiator() |
boolean |
fullPacketQueued() |
OpennetManager.ConnectionType |
getAddedReason() |
long |
getBootID()
Get the current boot ID.
|
long |
getClockDelta() |
double |
getClosestPeerLocation(double l,
java.util.Set<java.lang.Double> exclude)
Finds the closest non-excluded peer.
|
SessionKey |
getCurrentKeyTracker() |
int |
getDegree()
Determines the degree of the peer via the locations of its peers it provides.
|
SimpleFieldSet |
getFullNoderef() |
int |
getHandshakeCount() |
Peer |
getHandshakeIP()
Get a single address to send a handshake to.
|
protected Peer[] |
getHandshakeIPs()
Returns an array with the advertised addresses and the detected one
|
int |
getIdentityHash()
Returns a unique node identifier (usefull to compare two peernodes).
|
java.lang.String |
getIdentityString() |
PeerNode.IncomingLoadSummaryStats |
getIncomingLoadStats(boolean realTime) |
protected byte[] |
getJFKBuffer() |
KeyAgreementSchemeContext |
getKeyAgreementSchemeContext() |
java.lang.String |
getLastBackoffReason(boolean realTime) |
java.util.Hashtable<java.lang.String,java.lang.Long> |
getLocalNodeReceivedMessagesFromStatistic() |
protected SimpleFieldSet |
getLocalNoderef()
Return the relevant local node reference related to this peer's type
|
java.util.Hashtable<java.lang.String,java.lang.Long> |
getLocalNodeSentMessagesToStatistic() |
double |
getLocation()
Returns this peer's current keyspace location, or -1 if it is unknown.
|
long |
getLocSetTime() |
long |
getMainJarOfferedVersion() |
int |
getMaxPacketSize() |
PeerMessageQueue |
getMessageQueue() |
long |
getMessageQueueLengthBytes() |
long |
getNextUrgentTime(long now) |
long |
getOutgoingBootID()
Get the boot ID for purposes of the other node.
|
OutgoingPacketMangler |
getOutgoingMangler()
Get the OutgoingPacketMangler which encrypts outgoing packets to this node
|
Peer |
getPeer()
Get my low-level address.
|
long |
getPeerAddedTime() |
int |
getPeerNodeStatus() |
protected int |
getPeerNodeStatus(long now,
long routingBackedOffUntilRT,
long localRoutingBackedOffUntilBulk,
boolean overPingTime,
boolean noLoadStats) |
java.lang.String |
getPeerNodeStatusCSSClassName() |
static java.lang.String |
getPeerNodeStatusCSSClassName(int status) |
java.lang.String |
getPeerNodeStatusString() |
static java.lang.String |
getPeerNodeStatusString(int status) |
double |
getPercentTimeRoutableConnection() |
short |
getPollingPriorityNormal()
Priority at which the polling should run normally.
|
short |
getPollingPriorityProgress()
Priority at which the polling should run when starting, or immediately after making some progress.
|
double |
getPRejected() |
java.lang.String |
getPreviousBackoffReason(boolean realTime) |
SessionKey |
getPreviousKeyTracker() |
long |
getProbableSendQueueTime()
Returns the number of milliseconds that it is estimated to take to transmit the currently queued packets.
|
protected byte[] |
getPubKeyHash() |
Peer |
getRemoteDetectedPeer() |
long |
getResendBytesSent() |
long |
getReusableTrackerID() |
long |
getRoutingBackedOffUntil(boolean realTime) |
long |
getRoutingBackedOffUntilBulk() |
long |
getRoutingBackedOffUntilMax() |
long |
getRoutingBackedOffUntilRT() |
long |
getRoutingBackoffLength(boolean realTime) |
int |
getSimpleVersion() |
SocketHandler |
getSocketHandler()
Get the SocketHandler which handles incoming packets from this node
|
abstract PeerNodeStatus |
getStatus(boolean noHeavy)
Get a PeerNodeStatus for this node.
|
PacketThrottle |
getThrottle()
Get the PacketThrottle for the node's current address for the standard packet size (if the
address changes then we get a new throttle).
|
int |
getThrottleWindowSize() |
java.lang.String |
getTMCIPeerInfo() |
long |
getTotalInputBytes() |
long |
getTotalInputSinceStartup() |
long |
getTotalOutputBytes() |
long |
getTotalOutputSinceStartup() |
SessionKey |
getUnverifiedKeyTracker() |
short |
getUptime() |
java.lang.String |
getVersion() |
int |
getVersionNumber()
Peer version, if this is supported, else -1
|
java.lang.ref.WeakReference<PeerNode> |
getWeakRef()
Get a WeakReference to this context.
|
void |
gotARK(SimpleFieldSet fs,
long fetchedEdition) |
MessageItem[] |
grabQueuedMessageItems()
Grab all queued Message's.
|
boolean |
grabSendLoadStatsASAP(boolean realtime) |
void |
handleMessage(Message m) |
boolean |
handleReceivedPacket(byte[] buf,
int offset,
int length,
long now,
Peer replyTo) |
int |
handshakeSetupType() |
boolean |
handshakeUnknownInitiator() |
boolean |
hasFullNoderef() |
int |
hashCode() |
boolean |
hasLiveHandshake(long now)
Does the node have a live handshake in progress?
|
protected boolean |
ignoreLastGoodVersion() |
void |
incrementNumberOfSelections(long time) |
void |
incrementUOMSends() |
protected boolean |
innerCalcNextHandshake(boolean successfulHandshakeSend,
boolean dontFetchARK,
long now)
Set sendHandshakeTime, and return whether to fetch the ARK.
|
protected boolean |
innerProcessNewNoderef(SimpleFieldSet fs,
boolean forARK,
boolean forDiffNodeRef,
boolean forFullNodeRef)
The synchronized part of processNewNoderef
|
boolean |
isBurstOnly() |
boolean |
isConnected()
Is the peer connected? Have we established the session link?
|
abstract boolean |
isDarknet() |
boolean |
isDisabled()
Is this peer disabled? I.e.
|
boolean |
isDisconnecting() |
boolean |
isFetchingARK() |
boolean |
isIgnoreSource()
Is this peer set to ignore source address? If so, we will always reply to the peer's official
address, even if we get packets from somewhere else.
|
boolean |
isLowCapacity(boolean isRealtime) |
boolean |
isLowUptime() |
abstract boolean |
isOpennet() |
abstract boolean |
isOpennetForNoderef() |
abstract boolean |
isRealConnection()
Does this peernode want to be returned by for example PeerManager.getByPeer() ?
False = seednode etc, never going to be routable.
|
boolean |
isRoutable()
Returns true if requests can be routed through this peer.
|
boolean |
isRoutingBackedOff(boolean realTime) |
boolean |
isRoutingBackedOff(long ignoreBackoffUnder,
boolean realTime) |
boolean |
isRoutingBackedOffEither() |
boolean |
isRoutingCompatible()
Returns true if (apart from actually knowing the peer's location), it is presumed that this peer could route requests.
|
abstract boolean |
isSeed() |
boolean |
isSignatureVerificationSuccessfull() |
boolean |
isUnroutableNewerVersion()
Returns true if this (or another) peer has reported to us that our build number is too old for data to be routed
to us.
|
boolean |
isUnroutableOlderVersion()
Returns true if the last-known build number for this peer is to old to allow traffic to be routed to it.
|
long |
lastReceivedAckTime() |
long |
lastReceivedDataPacketTime() |
long |
lastReceivedPacketTime() |
long |
lastSentPacketTime() |
freenet.node.PeerNode.LoadSender |
loadSender(boolean realtime) |
void |
localRejectedOverload(java.lang.String reason,
boolean realTime)
Got a local RejectedOverload.
|
MessageItem |
makeLoadStats(boolean realtime,
boolean boostPriority,
boolean noRemember)
Make a load stats message.
|
boolean |
matchesIP(FreenetInetAddress addr,
boolean strict)
Does this PeerNode match the given IP address?
|
boolean |
matchesPeerAndPort(Peer peer) |
long |
maxTimeBetweenReceivedAcks() |
long |
maxTimeBetweenReceivedPackets() |
protected abstract void |
maybeClearPeerAddedTimeOnConnect() |
protected abstract void |
maybeClearPeerAddedTimeOnRestart(long now) |
void |
maybeOnConnect() |
void |
maybeRekey() |
boolean |
maybeSendPacket(long now,
boolean ackOnly)
Maybe send something.
|
void |
maybeUpdateHandshakeIPs(boolean ignoreHostnames)
Do occasional DNS requests, but ignoreHostnames should be true
on PeerNode construction
|
boolean |
neverConnected() |
boolean |
noContactDetails() |
boolean |
noLongerRoutable()
Will return true if routing to this node is either explictly disabled, or disabled due to
noted incompatiblity in build-version numbers.
|
void |
noLongerRoutingTo(UIDTag tag,
boolean offeredKey) |
boolean |
notifyDisconnecting(boolean dumpMessageQueue)
Called when a delayed disconnect is occurring.
|
void |
offer(Key key)
Offer a key to this node
|
protected void |
onConnect()
A method to be called once at the beginning of every time isConnected() is true
|
void |
onFound(USK origUSK,
long edition,
FetchResult result)
Called when a new edition is found and downloaded.
|
void |
onNotificationOnlyPacketSent(int length) |
void |
onRemove()
Called when the peer is removed from the PeerManager
|
void |
onSetMaxOutputTransfers(boolean realTime,
int maxOutputTransfers) |
void |
onSetMaxOutputTransfersPeerLimit(boolean realTime,
int maxOutputTransfers) |
void |
onSetPeerAllocation(boolean input,
int thisAllocation,
int transfersPerInsert,
int maxOutputTransfers,
boolean realTime) |
abstract void |
onSuccess(boolean insert,
boolean ssk)
Called when a request or insert succeeds.
|
freenet.node.PeerNode.OutputLoadTracker |
outputLoadTracker(boolean realTime) |
java.util.Random |
paddingGen() |
boolean |
ping(int pingID)
Low-level ping this node.
|
void |
postUnlock(UIDTag tag) |
void |
processDiffNoderef(SimpleFieldSet fs)
Process a differential node reference
The identity must not change, or we throw.
|
protected void |
processNewNoderef(SimpleFieldSet fs,
boolean forARK,
boolean forDiffNodeRef,
boolean forFullNodeRef)
Process a new nodereference, as a SimpleFieldSet.
|
boolean |
publicInvalidVersion()
The same as isUnroutableOlderVersion, but not synchronized.
|
boolean |
publicReverseInvalidVersion()
The same as inUnroutableNewerVersion.
|
int |
queueN2NM(SimpleFieldSet fs)
A method to queue an N2NM in a extra peer data file, only implemented by DarknetPeerNode.
|
void |
receivedAck(long now)
Report when a packet was acked.
|
void |
receivedPacket(boolean dontLog,
boolean dataPacket)
Update timeLastReceivedPacket
|
abstract boolean |
recordStatus() |
void |
registerPeerNodeStatusChangeListener(PeerManager.PeerStatusChangeListener listener)
Registers a listener that will be notified when status changes.
|
void |
rejectedGuaranteed(boolean realTimeFlag)
After 5 consecutive GUARANTEED soft rejections, we enter mandatory backoff.
|
void |
reportIncomingBytes(int length) |
void |
reportLoadStatus(NodeStats.PeerLoadStats stat) |
void |
reportOutgoingBytes(int length) |
void |
reportPing(long t) |
void |
reportRoutedTo(double target,
boolean isLocal,
boolean realTime,
PeerNode prev,
java.util.Set<PeerNode> routedTo,
int htl) |
void |
reportThrottledPacketSendTime(long timeDiff,
boolean realTime) |
void |
resentBytes(int length) |
void |
resetMandatoryBackoff(boolean realTime)
Called when a request is accepted.
|
double |
selectionRate() |
int |
selectNegType(OutgoingPacketMangler mangler)
Select the most appropriate negType, taking the user's preference into account
order matters
|
MessageItem |
sendAsync(Message msg,
AsyncMessageCallback cb,
ByteCounter ctr)
Send a message, off-thread, to this node.
|
protected void |
sendConnectedDiffNoderef()
A method to be called after completing a handshake to send the
newly connected peer, as a differential node reference, the
parts of our node reference not needed for handshake.
|
void |
sendEncryptedPacket(byte[] data) |
boolean |
sendingUOMJar(boolean isExt)
Start sending a UOM jar to this peer.
|
protected void |
sendInitialMessages()
Send any high level messages that need to be sent on connect.
|
void |
sendNodeToNodeMessage(SimpleFieldSet fs,
int n2nType,
boolean includeSentTime,
long now,
boolean queueOnNotConnected) |
void |
sendSync(Message req,
ByteCounter ctr,
boolean realTime)
Enqueue a message to be sent to this node and wait up to a minute for it to be transmitted
and acknowledged.
|
void |
sentHandshake(boolean notRegistered)
Call this method when a handshake request has been
sent.
|
void |
sentPacket()
Update timeLastSentPacket
|
void |
sentThrottledBytes(int count) |
void |
setAddedReason(OpennetManager.ConnectionType connectionType) |
protected void |
setJFKBuffer(byte[] bufferJFK) |
void |
setKeyAgreementSchemeContext(KeyAgreementSchemeContext ctx2) |
void |
setLastBackoffReason(java.lang.String s,
boolean realTime) |
void |
setMainJarOfferedVersion(long mainJarVersion) |
int |
setPeerNodeStatus(long now) |
int |
setPeerNodeStatus(long now,
boolean noLog) |
void |
setRemoteDetectedPeer(Peer p) |
void |
setSendLoadStatsASAP(boolean realtime)
Set the load stats to be sent asap.
|
void |
setTimeDelta(long delta) |
void |
setUptime(byte uptime2) |
abstract boolean |
shallWeRouteAccordingToOurPeersLocation(int htl) |
java.lang.String |
shortToString()
Compact toString()
|
boolean |
shouldAcceptAnnounce(long uid) |
boolean |
shouldBeExcludedFromPeerList() |
boolean |
shouldDisconnectAndRemoveNow()
Should this peer be disconnected and removed immediately?
|
protected abstract boolean |
shouldExportPeerAddedTime() |
boolean |
shouldPadDataPackets() |
boolean |
shouldRejectProbeRequest()
Should we reject a swap request?
|
boolean |
shouldRejectSwapRequest()
Should we reject a swap request?
|
boolean |
shouldSendHandshake() |
boolean |
shouldThrottle() |
static boolean |
shouldThrottle(Peer peer,
Node node) |
DecodingMessageGroup |
startProcessingDecryptedMessages(int size) |
void |
startRekeying() |
protected void |
stopARKFetcher() |
void |
successNotOverload(boolean realTime)
Didn't get RejectedOverload.
|
boolean |
throttleRekey() |
long |
timeCheckForLostPackets() |
long |
timeLastConnected(long now) |
long |
timeLastConnectionCompleted() |
long |
timeLastDisconnect() |
long |
timeLastRoutable() |
long |
timeSendAcks() |
long |
timeSendHandshake(long now) |
long |
timeSinceAddedOrRestarted() |
protected long |
timeSinceSentUOM() |
java.lang.String |
toString() |
void |
transferFailed(java.lang.String reason,
boolean realTime)
A transfer failed.
|
void |
transferSuccess(boolean realTime)
A transfer succeeded.
|
boolean |
unqueueMessage(MessageItem message) |
void |
updateLocation(double newLoc,
double[] newLocs) |
java.lang.String |
userToString() |
void |
verified(SessionKey tracker)
Called when a packet is successfully decrypted on a given
SessionKey for this node.
|
void |
wakeUpSender() |
void |
write(java.io.Writer w)
Write the peer's noderef to disk
|
protected abstract void |
writePeers()
Write the peers list affecting this node.
|
protected boolean unroutableOlderVersion
protected boolean unroutableNewerVersion
protected boolean disableRouting
protected boolean disableRoutingHasBeenSetLocally
protected boolean disableRoutingHasBeenSetRemotely
protected byte[] jfkKa
protected byte[] incommingKey
protected byte[] jfkKe
protected byte[] outgoingKey
protected byte[] jfkMyRef
protected byte[] hmacKey
protected byte[] ivKey
protected byte[] ivNonce
protected int ourInitialSeqNum
protected int theirInitialSeqNum
protected int ourInitialMsgID
protected int theirInitialMsgID
protected long jfkContextLifetime
protected java.util.List<Peer> nominalPeer
public final boolean testnetEnabled
public static final long SELECTION_SAMPLING_PERIOD
public static final int SELECTION_PERCENTAGE_WARNING
public static final int SELECTION_MIN_PEERS
public static final int SELECTION_MAX_SAMPLES
protected long sendHandshakeTime
public final java.security.interfaces.ECPublicKey peerECDSAPubKey
public final byte[] peerECDSAPubKeyHash
public int peerNodeStatus
protected boolean neverConnected
protected long peerAddedTime
protected final NodeCrypto crypto
public static final long BLACK_MAGIC_BACKOFF_PRUNING_TIME
public static final double BLACK_MAGIC_BACKOFF_PRUNING_PERCENTAGE
protected final java.util.LinkedList<byte[]> jfkNoncesSent
protected SimpleFieldSet fullFieldSet
public final RunningAverage backedOffPercent
public final RunningAverage backedOffPercentRT
public final RunningAverage backedOffPercentBulk
public final ByteCounter resendByteCounter
protected boolean sendingUOMMainJar
protected boolean sendingUOMLegacyExtJar
public PeerNode(SimpleFieldSet fs, Node node2, NodeCrypto crypto, boolean fromLocal) throws FSParseException, PeerParseException, ReferenceSignatureVerificationException, PeerTooOldException
fs
- The node reference to parse.node2
- The running Node we are part of.fromLocal
- True if the noderef was read from the stored peers file and can contain
local metadata, and won't be signed. Otherwise, it is a new node reference from elsewhere,
should not contain metadata, and will be signed.PeerTooOldException
- If the peer is so old that it can no longer be parsed, e.g.
because it hasn't been connected since the last major crypto change.FSParseException
PeerParseException
ReferenceSignatureVerificationException
protected boolean ignoreLastGoodVersion()
protected boolean fromAnonymousInitiator()
protected abstract void maybeClearPeerAddedTimeOnRestart(long now)
public Peer getPeer()
getPeer
in interface PeerContext
protected Peer[] getHandshakeIPs()
public void maybeUpdateHandshakeIPs(boolean ignoreHostnames)
public double getLocation()
public boolean shouldBeExcludedFromPeerList()
public double getClosestPeerLocation(double l, java.util.Set<java.lang.Double> exclude)
exclude
- the set of locations to exclude, may be nullpublic long getLocSetTime()
public int getIdentityHash()
public boolean isUnroutableOlderVersion()
public boolean isUnroutableNewerVersion()
public boolean isRoutable()
isRoutable
in interface PeerContext
public boolean isRoutingCompatible()
public boolean isConnected()
PeerContext
isConnected
in interface PeerContext
public MessageItem sendAsync(Message msg, AsyncMessageCallback cb, ByteCounter ctr) throws NotConnectedException
sendAsync
in interface PeerContext
msg
- The message to be sent.cb
- The callback to be called when the packet has been sent, or null.ctr
- A callback to tell how many bytes were used to send this message.NotConnectedException
public void wakeUpSender()
wakeUpSender
in interface BasePeerNode
public boolean unqueueMessage(MessageItem message)
unqueueMessage
in interface PeerContext
public long getMessageQueueLengthBytes()
public long getProbableSendQueueTime()
public long lastReceivedPacketTime()
public long lastReceivedDataPacketTime()
public long lastReceivedAckTime()
public long timeLastConnected(long now)
public long timeLastRoutable()
public void maybeRekey()
maybeRekey
in interface BasePeerNode
public void startRekeying()
startRekeying
in interface BasePeerNode
public long getPeerAddedTime()
public long timeSinceAddedOrRestarted()
public boolean disconnected(boolean dumpMessageQueue, boolean dumpTrackers)
dumpMessageQueue
- If true, clear the messages-to-send queue, and
change the bootID so even if we reconnect the other side will know that
a disconnect happened. If false, don't clear the messages yet. They
will be cleared after an hour if the peer is disconnected at that point.dumpTrackers
- If true, dump the SessionKey's (i.e. dump the
cryptographic data so we don't understand any packets they send us).
public void forceDisconnect()
PeerContext
forceDisconnect
in interface PeerContext
public MessageItem[] grabQueuedMessageItems()
public long getNextUrgentTime(long now)
public long lastSentPacketTime()
public boolean shouldSendHandshake()
public long timeSendHandshake(long now)
public boolean hasLiveHandshake(long now)
now
- The current time.protected boolean innerCalcNextHandshake(boolean successfulHandshakeSend, boolean dontFetchARK, long now)
protected void calcNextHandshake(boolean successfulHandshakeSend, boolean dontFetchARK, boolean notRegistered)
public boolean isBurstOnly()
public void sentHandshake(boolean notRegistered)
public void couldNotSendHandshake(boolean notRegistered)
public long maxTimeBetweenReceivedPackets()
public long maxTimeBetweenReceivedAcks()
public boolean ping(int pingID) throws NotConnectedException
NotConnectedException
public short decrementHTL(short htl)
htl
- The old HTL.public void sendSync(Message req, ByteCounter ctr, boolean realTime) throws NotConnectedException, SyncSendWaitedTooLongException
public int getDegree()
public void updateLocation(double newLoc, double[] newLocs)
protected abstract void writePeers()
public boolean shouldRejectSwapRequest()
public boolean shouldRejectProbeRequest()
public void changedIP(Peer newPeer)
newPeer
- The new address of the peer.public SessionKey getCurrentKeyTracker()
getCurrentKeyTracker
in interface BasePeerNode
public SessionKey getPreviousKeyTracker()
getPreviousKeyTracker
in interface BasePeerNode
public SessionKey getUnverifiedKeyTracker()
getUnverifiedKeyTracker
in interface BasePeerNode
public java.lang.String shortToString()
PeerContext
shortToString
in interface PeerContext
public java.lang.String toString()
toString
in class java.lang.Object
public void receivedPacket(boolean dontLog, boolean dataPacket)
receivedPacket
in interface BasePeerNode
dontLog
- If true, don't log an error or throw an exception if we are not connected. This
can be used in handshaking when the connection hasn't been verified yet.dataPacket
- If this is a real packet, as opposed to a handshake packet.NotConnectedException
public void receivedAck(long now)
BasePeerNode
receivedAck
in interface BasePeerNode
public void sentPacket()
sentPacket
in interface BasePeerNode
public KeyAgreementSchemeContext getKeyAgreementSchemeContext()
public void setKeyAgreementSchemeContext(KeyAgreementSchemeContext ctx2)
public long completedHandshake(long thisBootID, byte[] data, int offset, int length, BlockCipher outgoingCipher, byte[] outgoingKey, BlockCipher incommingCipher, byte[] incommingKey, Peer replyTo, boolean unverified, int negType, long trackerID, boolean isJFK4, boolean jfk4SameAsOld, byte[] hmacKey, BlockCipher ivCipher, byte[] ivNonce, int ourInitialSeqNum, int theirInitialSeqNum, int ourInitialMsgID, int theirInitialMsgID)
thisBootID
- The boot ID of the peer we have just connected to.
This is simply a random number regenerated on every startup of the node.
We use it to determine whether the node has restarted since we last saw
it.data
- Byte array from which to read the new noderef.offset
- Offset to start reading at.length
- Number of bytes to read.encKey
- The new session key.replyTo
- The IP the handshake came in on.trackerID
- The tracker ID proposed by the other side. If -1, create a new tracker. If any
other value, check whether we have it, and if we do, return that, otherwise return the ID of the
new tracker.isJFK4
- If true, we are processing a JFK(4) and must respect the tracker ID chosen by the
responder. If false, we are processing a JFK(3) and we can either reuse the suggested tracker ID,
which the other side is able to reuse, or we can create a new tracker ID.jfk4SameAsOld
- If true, the responder chose to use the tracker ID that we provided. If
we don't have it now the connection fails.protected abstract void maybeClearPeerAddedTimeOnConnect()
public long getBootID()
PeerContext
getBootID
in interface PeerContext
protected void stopARKFetcher()
public short getPollingPriorityNormal()
USKRetrieverCallback
RequestStarter
.getPollingPriorityNormal
in interface USKRetrieverCallback
public short getPollingPriorityProgress()
USKRetrieverCallback
RequestStarter
.getPollingPriorityProgress
in interface USKRetrieverCallback
protected void sendInitialMessages()
public void verified(SessionKey tracker)
verified
in interface BasePeerNode
public boolean publicInvalidVersion()
public boolean publicReverseInvalidVersion()
public boolean dontRoute()
public void processDiffNoderef(SimpleFieldSet fs) throws FSParseException
FSParseException
protected void processNewNoderef(SimpleFieldSet fs, boolean forARK, boolean forDiffNodeRef, boolean forFullNodeRef) throws FSParseException
FSParseException
protected boolean innerProcessNewNoderef(SimpleFieldSet fs, boolean forARK, boolean forDiffNodeRef, boolean forFullNodeRef) throws FSParseException
FSParseException
public abstract PeerNodeStatus getStatus(boolean noHeavy)
noHeavy
- If true, avoid any expensive operations e.g. the message count hashtables.public java.lang.String getTMCIPeerInfo()
public java.lang.String getVersion()
public int getSimpleVersion()
public void write(java.io.Writer w) throws java.io.IOException
java.io.IOException
public SimpleFieldSet exportDiskFieldSet()
public SimpleFieldSet exportMetadataFieldSet(long now)
protected abstract boolean shouldExportPeerAddedTime()
public SimpleFieldSet exportVolatileFieldSet()
public SimpleFieldSet exportFieldSet()
public abstract boolean isDarknet()
public abstract boolean isOpennet()
public abstract boolean isOpennetForNoderef()
public abstract boolean isSeed()
public long timeLastConnectionCompleted()
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public final int hashCode()
hashCode
in class java.lang.Object
public boolean isRoutingBackedOff(long ignoreBackoffUnder, boolean realTime)
public boolean isRoutingBackedOff(boolean realTime)
public boolean isRoutingBackedOffEither()
public void enterMandatoryBackoff(java.lang.String reason, boolean realTime)
public void resetMandatoryBackoff(boolean realTime)
public void localRejectedOverload(java.lang.String reason, boolean realTime)
public void successNotOverload(boolean realTime)
public void transferFailed(java.lang.String reason, boolean realTime)
transferFailed
in interface PeerContext
public void transferSuccess(boolean realTime)
public double getPRejected()
public double averagePingTime()
averagePingTime
in interface BasePeerNode
public double averagePingTimeCorrected()
averagePingTimeCorrected
in interface BasePeerNode
public void reportThrottledPacketSendTime(long timeDiff, boolean realTime)
reportThrottledPacketSendTime
in interface PeerContext
public void setRemoteDetectedPeer(Peer p)
public Peer getRemoteDetectedPeer()
public long getRoutingBackoffLength(boolean realTime)
public long getRoutingBackedOffUntil(boolean realTime)
public long getRoutingBackedOffUntilMax()
public long getRoutingBackedOffUntilRT()
public long getRoutingBackedOffUntilBulk()
public java.lang.String getLastBackoffReason(boolean realTime)
public java.lang.String getPreviousBackoffReason(boolean realTime)
public void setLastBackoffReason(java.lang.String s, boolean realTime)
public void addToLocalNodeSentMessagesToStatistic(Message m)
public void addToLocalNodeReceivedMessagesFromStatistic(Message m)
public java.util.Hashtable<java.lang.String,java.lang.Long> getLocalNodeSentMessagesToStatistic()
public java.util.Hashtable<java.lang.String,java.lang.Long> getLocalNodeReceivedMessagesFromStatistic()
public void gotARK(SimpleFieldSet fs, long fetchedEdition)
public int getPeerNodeStatus()
public java.lang.String getPeerNodeStatusString()
public static java.lang.String getPeerNodeStatusString(int status)
public java.lang.String getPeerNodeStatusCSSClassName()
public static java.lang.String getPeerNodeStatusCSSClassName(int status)
protected int getPeerNodeStatus(long now, long routingBackedOffUntilRT, long localRoutingBackedOffUntilBulk, boolean overPingTime, boolean noLoadStats)
public int setPeerNodeStatus(long now)
public int setPeerNodeStatus(long now, boolean noLog)
public abstract boolean recordStatus()
public java.lang.String getIdentityString()
public boolean isFetchingARK()
public int getHandshakeCount()
public boolean noLongerRoutable()
public void maybeOnConnect()
protected void onConnect()
public void onFound(USK origUSK, long edition, FetchResult result)
USKRetrieverCallback
onFound
in interface USKRetrieverCallback
edition
- The USK edition number.result
- The retrieved data.public boolean noContactDetails()
public void reportIncomingBytes(int length)
reportIncomingBytes
in interface BasePeerNode
public void reportOutgoingBytes(int length)
reportOutgoingBytes
in interface BasePeerNode
public long getTotalInputBytes()
public long getTotalOutputBytes()
public long getTotalInputSinceStartup()
public long getTotalOutputSinceStartup()
public boolean isSignatureVerificationSuccessfull()
public void checkRoutableConnectionStatus()
public double getPercentTimeRoutableConnection()
public int getVersionNumber()
PeerContext
getVersionNumber
in interface PeerContext
public PacketThrottle getThrottle()
PeerContext
getThrottle
in interface PeerContext
public int selectNegType(OutgoingPacketMangler mangler)
mangler
- public java.lang.String userToString()
public void setTimeDelta(long delta)
public long getClockDelta()
public void offer(Key key)
public OutgoingPacketMangler getOutgoingMangler()
PeerContext
getOutgoingMangler
in interface PeerContext
public SocketHandler getSocketHandler()
PeerContext
getSocketHandler
in interface PeerContext
public boolean isDisabled()
public boolean allowLocalAddresses()
public boolean isIgnoreSource()
public static PeerNode create(SimpleFieldSet fs, Node node2, NodeCrypto crypto, OpennetManager opennet, PeerManager manager) throws FSParseException, PeerParseException, ReferenceSignatureVerificationException, PeerTooOldException
public boolean neverConnected()
public abstract void onSuccess(boolean insert, boolean ssk)
public boolean notifyDisconnecting(boolean dumpMessageQueue)
dumpMessageQueue
- If true, immediately dump the message queue, since we are
closing the connection due to some low level trouble e.g. not acknowledging.
We will continue to try to send anything already in flight, and it is possible to
send more messages after this point, for instance the message telling it we are
disconnecting, but see above - no requests will be routed across this connection.public void forceCancelDisconnecting()
public void onRemove()
public boolean isDisconnecting()
protected byte[] getJFKBuffer()
protected void setJFKBuffer(byte[] bufferJFK)
public boolean shouldAcceptAnnounce(long uid)
public boolean completedAnnounce(long uid)
public long timeLastDisconnect()
public abstract boolean isRealConnection()
public abstract boolean canAcceptAnnouncements()
public boolean handshakeUnknownInitiator()
public int handshakeSetupType()
public java.lang.ref.WeakReference<PeerNode> getWeakRef()
PeerContext
getWeakRef
in interface PeerContext
public Peer getHandshakeIP()
public void sendNodeToNodeMessage(SimpleFieldSet fs, int n2nType, boolean includeSentTime, long now, boolean queueOnNotConnected)
public int queueN2NM(SimpleFieldSet fs)
protected SimpleFieldSet getLocalNoderef()
protected void sendConnectedDiffNoderef()
public boolean shouldThrottle()
shouldThrottle
in interface BasePeerNode
public void reportPing(long t)
reportPing
in interface BasePeerNode
public void backoffOnResend()
BasePeerNode
backoffOnResend
in interface BasePeerNode
public long getResendBytesSent()
public boolean shouldDisconnectAndRemoveNow()
public void setUptime(byte uptime2)
public short getUptime()
public void incrementNumberOfSelections(long time)
public double selectionRate()
public void setMainJarOfferedVersion(long mainJarVersion)
public long getMainJarOfferedVersion()
public boolean maybeSendPacket(long now, boolean ackOnly) throws BlockedTooLongException
now
- ackOnly
- BlockedTooLongException
public long getReusableTrackerID()
public void failedRevocationTransfer()
public int countFailedRevocationTransfers()
public void registerPeerNodeStatusChangeListener(PeerManager.PeerStatusChangeListener listener)
listener
- - The listener to be registeredpublic boolean isLowUptime()
public void setAddedReason(OpennetManager.ConnectionType connectionType)
public OpennetManager.ConnectionType getAddedReason()
public void onSetMaxOutputTransfers(boolean realTime, int maxOutputTransfers)
public void onSetMaxOutputTransfersPeerLimit(boolean realTime, int maxOutputTransfers)
public void onSetPeerAllocation(boolean input, int thisAllocation, int transfersPerInsert, int maxOutputTransfers, boolean realTime)
public freenet.node.PeerNode.OutputLoadTracker outputLoadTracker(boolean realTime)
public void reportLoadStatus(NodeStats.PeerLoadStats stat)
public void noLongerRoutingTo(UIDTag tag, boolean offeredKey)
public void postUnlock(UIDTag tag)
public PeerNode.IncomingLoadSummaryStats getIncomingLoadStats(boolean realTime)
public freenet.node.PeerNode.LoadSender loadSender(boolean realtime)
public void fatalTimeout(UIDTag tag, boolean offeredKey)
tag
- The request which we routed to this peer. It may or may not still be
running.public abstract void fatalTimeout()
public abstract boolean shallWeRouteAccordingToOurPeersLocation(int htl)
public PeerMessageQueue getMessageQueue()
getMessageQueue
in interface BasePeerNode
public boolean handleReceivedPacket(byte[] buf, int offset, int length, long now, Peer replyTo)
public void checkForLostPackets()
public long timeCheckForLostPackets()
public void dumpTracker(SessionKey brokenKey)
public void handleMessage(Message m)
handleMessage
in interface BasePeerNode
public void sendEncryptedPacket(byte[] data) throws Peer.LocalAddressException
sendEncryptedPacket
in interface BasePeerNode
Peer.LocalAddressException
public int getMaxPacketSize()
getMaxPacketSize
in interface BasePeerNode
public boolean shouldPadDataPackets()
shouldPadDataPackets
in interface BasePeerNode
public void sentThrottledBytes(int count)
sentThrottledBytes
in interface BasePeerNode
public void onNotificationOnlyPacketSent(int length)
onNotificationOnlyPacketSent
in interface BasePeerNode
public void resentBytes(int length)
resentBytes
in interface BasePeerNode
public java.util.Random paddingGen()
paddingGen
in interface BasePeerNode
public boolean matchesPeerAndPort(Peer peer)
public boolean matchesIP(FreenetInetAddress addr, boolean strict)
strict
- If true, only match if the IP is actually in use. If false,
also match from nominal IP addresses and domain names etc.public MessageItem makeLoadStats(boolean realtime, boolean boostPriority, boolean noRemember)
BasePeerNode
makeLoadStats
in interface BasePeerNode
realtime
- True for the realtime load stats, false for the bulk load stats.boostPriority
- If true, boost the priority so it gets sent fast.noRemember
- If true, generating it for a lossy message in a packet; don't
remember that we sent it, since it might be lost, and generate it even if the last
one was the same, since the last one might be delayed.public boolean grabSendLoadStatsASAP(boolean realtime)
grabSendLoadStatsASAP
in interface BasePeerNode
public void setSendLoadStatsASAP(boolean realtime)
BasePeerNode
setSendLoadStatsASAP
in interface BasePeerNode
public DecodingMessageGroup startProcessingDecryptedMessages(int size)
startProcessingDecryptedMessages
in interface BasePeerNode
public boolean isLowCapacity(boolean isRealtime)
public void reportRoutedTo(double target, boolean isLocal, boolean realTime, PeerNode prev, java.util.Set<PeerNode> routedTo, int htl)
public boolean sendingUOMJar(boolean isExt)
public void finishedSendingUOMJar(boolean isExt)
protected long timeSinceSentUOM()
public void incrementUOMSends()
public void decrementUOMSends()
public long getOutgoingBootID()
public boolean throttleRekey()
public boolean fullPacketQueued()
public long timeSendAcks()
public int calculateMaxTransfersOut(int timeout, double nonOverheadFraction)
public boolean hasFullNoderef()
public SimpleFieldSet getFullNoderef()
public void rejectedGuaranteed(boolean realTimeFlag)
public void acceptedAny(boolean realTimeFlag)
public int getThrottleWindowSize()
getThrottleWindowSize
in interface PeerContext
protected final byte[] getPubKeyHash()