public class StunCandidateHarvest extends AbstractResponseCollector
Modifier and Type | Class and Description |
---|---|
private static class |
StunCandidateHarvest.SendKeepAliveMessageThread
Sends STUN keep-alive Messages to the STUN server associated
with the StunCandidateHarvester of this instance.
|
Modifier and Type | Field and Description |
---|---|
private List<LocalCandidate> |
candidates
The list of Candidates harvested for
hostCandidate by
this harvest. |
private boolean |
completedResolvingCandidate
The indicator which determines whether this StunCandidateHarvest
has completed the harvesting of Candidates for
hostCandidate . |
StunCandidateHarvester |
harvester
The StunCandidateHarvester performing the harvesting of STUN
Candidates for a Component which this harvest is part
of.
|
HostCandidate |
hostCandidate
The HostCandidate the STUN harvesting of which is represented by
this instance.
|
private static Logger |
logger
The Logger used by the StunCandidateHarvest class and
its instances for logging output.
|
private LongTermCredentialSession |
longTermCredentialSession
The LongTermCredential used by this instance.
|
private static LocalCandidate[] |
NO_CANDIDATES
The constant which defines an empty array with LocalCandidate
element type.
|
private Map<TransactionID,Request> |
requests
The STUN Requests which have been sent by this instance, have
not received a STUN Response yet and have not timed out.
|
protected static long |
SEND_KEEP_ALIVE_MESSAGE_INTERVAL_NOT_SPECIFIED
The value of the sendKeepAliveMessage property of
StunCandidateHarvest which specifies that no sending of STUN
keep-alive messages is to performed for the purposes of keeping the
Candidates harvested by the StunCandidateHarvester in
question alive.
|
private long |
sendKeepAliveMessageInterval
The interval in milliseconds at which a new STUN keep-alive message is to
be sent to the STUN server associated with the
StunCandidateHarvester of this instance in order to keep one of
the Candidates harvested by this instance alive.
|
private Object |
sendKeepAliveMessageSyncRoot
The Object used to synchronize access to the members related to
the sending of STUN keep-alive messages to the STUN server associated
with the StunCandidateHarvester of this instance.
|
private Thread |
sendKeepAliveMessageThread
The Thread which sends the STUN keep-alive messages to the STUN
server associated with the StunCandidateHarvester of this
instance in order to keep the Candidates harvested by this
instance alive.
|
private long |
sendKeepAliveMessageTime
The time (stamp) in milliseconds of the last call to
sendKeepAliveMessage() which completed without throwing an
exception. |
Constructor and Description |
---|
StunCandidateHarvest(StunCandidateHarvester harvester,
HostCandidate hostCandidate)
Initializes a new StunCandidateHarvest which is to represent the
harvesting of STUN Candidates for a specific
HostCandidate performed by a specific
StunCandidateHarvester.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
addCandidate(LocalCandidate candidate)
Adds a specific LocalCandidate to the list of
LocalCandidates harvested for
hostCandidate by this
harvest. |
protected boolean |
addShortTermCredentialAttributes(Request request)
Adds the Attributes to a specific Request which support
the STUN short-term credential mechanism if the mechanism in question is
utilized by this StunCandidateHarvest (i.e.
|
void |
close()
Close the harvest.
|
protected boolean |
completedResolvingCandidate(Request request,
Response response)
Completes the harvesting of Candidates for
hostCandidate . |
protected boolean |
containsCandidate(LocalCandidate candidate)
Determines whether a specific LocalCandidate is contained in the
list of LocalCandidates harvested for
hostCandidate by
this harvest. |
protected void |
createCandidates(Response response)
Creates new Candidates determined by a specific STUN
Response.
|
protected Message |
createKeepAliveMessage(LocalCandidate candidate)
Creates a new STUN Message to be sent to the STUN server
associated with the StunCandidateHarvester of this instance in
order to keep a specific LocalCandidate (harvested by this
instance) alive.
|
protected Request |
createRequestToRetry(Request request)
Creates a new Request instance which is to be sent by this
StunCandidateHarvest in order to retry a specific
Request.
|
protected Request |
createRequestToStartResolvingCandidate()
Creates a new Request which is to be sent to
StunCandidateHarvester.stunServer in order to start resolving
hostCandidate . |
private void |
createSendKeepAliveMessageThread()
Creates and starts the
sendKeepAliveMessageThread which is to
send STUN keep-alive Messages to the STUN server associated with
the StunCandidateHarvester of this instance in order to keep the
Candidates harvested by this instance alive. |
protected void |
createServerReflexiveCandidate(Response response)
Creates a ServerReflexiveCandidate using
hostCandidate
as its base and the XOR-MAPPED-ADDRESS attribute in
response for the actual TransportAddress of the new
candidate. |
protected ServerReflexiveCandidate |
createServerReflexiveCandidate(TransportAddress transportAddress)
Creates a new ServerReflexiveCandidate instance which is to
represent a specific TransportAddress harvested through
hostCandidate and the STUN server associated with
harvester . |
private void |
exitSendKeepAliveMessageThread()
Runs in
sendKeepAliveMessageThread to notify this instance that
sendKeepAliveMessageThread is about to exit. |
(package private) int |
getCandidateCount()
Gets the number of Candidates harvested for
hostCandidate during this harvest. |
(package private) LocalCandidate[] |
getCandidates()
Gets the Candidates harvested for
hostCandidate during
this harvest. |
protected TransportAddress |
getMappedAddress(Response response)
Gets the TransportAddress specified in the XOR-MAPPED-ADDRESS
attribute of a specific Response.
|
private boolean |
processChallenge(byte[] realm,
byte[] nonce,
Request request,
TransactionID requestTransactionID)
Notifies this StunCandidateHarvest that a specific STUN
Request has been challenged for a long-term credential (as the
short-term credential mechanism does not utilize challenging) in a
specific realm and with a specific nonce.
|
private boolean |
processChallenge(Response response,
Request request,
TransactionID transactionID)
Notifies this StunCandidateHarvest that a specific STUN
Response has been received and it challenges a specific STUN
Request for a long-term credential (as the short-term credential
mechanism does not utilize challenging).
|
protected boolean |
processErrorOrFailure(Response response,
Request request,
TransactionID transactionID)
Notifies this StunCandidateHarvest that a specific
Request has either received an error Response or has
failed to receive any Response.
|
protected void |
processFailure(BaseStunMessageEvent event)
Notifies this ResponseCollector that a transaction described by
the specified BaseStunMessageEvent has failed.
|
void |
processResponse(StunResponseEvent event)
Notifies this ResponseCollector that a STUN response described
by the specified StunResponseEvent has been received.
|
private boolean |
processStaleNonce(Response response,
Request request,
TransactionID transactionID)
Handles a specific STUN error Response with error code
"438 Stale Nonce" to a specific STUN Request.
|
protected void |
processSuccess(Response response,
Request request,
TransactionID transactionID)
Handles a specific STUN success Response to a specific STUN
Request.
|
private boolean |
processUnauthorized(Response response,
Request request,
TransactionID transactionID)
Handles a specific STUN error Response with error code
"401 Unauthorized" to a specific STUN Request.
|
private boolean |
runInSendKeepAliveMessageThread()
Runs in
sendKeepAliveMessageThread and sends STUN
keep-alive Messages to the STUN server associated with the
StunCandidateHarvester of this instance. |
protected void |
sendKeepAliveMessage()
Sends a new STUN Message to the STUN server associated with the
StunCandidateHarvester of this instance in order to keep a
LocalCandidate harvested by this instance alive.
|
protected boolean |
sendKeepAliveMessage(LocalCandidate candidate)
Sends a new STUN Message to the STUN server associated with the
StunCandidateHarvester of this instance in order to keep a
specific LocalCandidate alive.
|
protected TransactionID |
sendRequest(Request request,
boolean firstRequest,
TransactionID transactionID)
Sends a specific Request to the STUN server associated with this
StunCandidateHarvest.
|
protected void |
setSendKeepAliveMessageInterval(long sendKeepAliveMessageInterval)
Sets the interval in milliseconds at which a new STUN keep-alive message
is to be sent to the STUN server associated with the
StunCandidateHarvester of this instance in order to keep one of
the Candidates harvested by this instance alive.
|
(package private) boolean |
startResolvingCandidate()
Starts the harvesting of Candidates to be performed for
hostCandidate . |
processTimeout, processUnreachable
private static final Logger logger
private static final LocalCandidate[] NO_CANDIDATES
protected static final long SEND_KEEP_ALIVE_MESSAGE_INTERVAL_NOT_SPECIFIED
private final List<LocalCandidate> candidates
hostCandidate
by
this harvest.private boolean completedResolvingCandidate
hostCandidate
.public final StunCandidateHarvester harvester
public final HostCandidate hostCandidate
private LongTermCredentialSession longTermCredentialSession
private final Map<TransactionID,Request> requests
private long sendKeepAliveMessageInterval
private final Object sendKeepAliveMessageSyncRoot
private Thread sendKeepAliveMessageThread
private long sendKeepAliveMessageTime
sendKeepAliveMessage()
which completed without throwing an
exception. Note: It doesn't mean that the keep-alive message was a
STUN Request and it received a success STUN Response.public StunCandidateHarvest(StunCandidateHarvester harvester, HostCandidate hostCandidate)
harvester
- the StunCandidateHarvester which is performing
the STUN harvestinghostCandidate
- the HostCandidate for which STUN
Candidates are to be harvestedprotected boolean addCandidate(LocalCandidate candidate)
hostCandidate
by this
harvest.candidate
- the LocalCandidate to be added to the list of
LocalCandidates harvested for hostCandidate
by this
harvestprotected boolean addShortTermCredentialAttributes(Request request)
request
- the Request to which to add the
Attributes supporting the STUN short-term credential mechanism
if the mechanism in question is utilized by this
StunCandidateHarvestprotected boolean completedResolvingCandidate(Request request, Response response)
hostCandidate
. Notifies harvester
about the completion
of the harvesting of Candidate for hostCandidate
performed by this StunCandidateHarvest.request
- the Request sent by this
StunCandidateHarvest with which the harvesting of
Candidates for hostCandidate has completedresponse
- the Response received by this
StunCandidateHarvest, if any, with which the harvesting of
Candidates for hostCandidate has completedprotected boolean containsCandidate(LocalCandidate candidate)
hostCandidate
by
this harvest.candidate
- the LocalCandidate to look for in the list of
LocalCandidates harvested for hostCandidate
by this
harvestprotected void createCandidates(Response response)
response
- the received STUN Responseprotected Message createKeepAliveMessage(LocalCandidate candidate) throws StunException
candidate
- the LocalCandidate (harvested by this instance)
to create a new keep-alive STUN message forStunException
- if anything goes wrong while creating the new
keep-alive STUN Message for the specified candidate
or the candidate is of an unsupported CandidateTypeprotected Request createRequestToRetry(Request request)
request
- the Request which is to be retried by this
StunCandidateHarvestprotected Request createRequestToStartResolvingCandidate()
StunCandidateHarvester.stunServer
in order to start resolving
hostCandidate
.StunCandidateHarvester.stunServer
in order to start resolving
hostCandidate
private void createSendKeepAliveMessageThread()
sendKeepAliveMessageThread
which is to
send STUN keep-alive Messages to the STUN server associated with
the StunCandidateHarvester of this instance in order to keep the
Candidates harvested by this instance alive.protected void createServerReflexiveCandidate(Response response)
hostCandidate
as its base and the XOR-MAPPED-ADDRESS attribute in
response for the actual TransportAddress of the new
candidate. If the message is malformed and/or does not contain the
corresponding attribute, this method simply has no effect.response
- the STUN Response which is supposed to contain
the address we should use for the new candidateprotected ServerReflexiveCandidate createServerReflexiveCandidate(TransportAddress transportAddress)
hostCandidate
and the STUN server associated with
harvester
.transportAddress
- the TransportAddress to be represented
by the new ServerReflexiveCandidate instancehostCandidate
and the STUN server associated with
harvester
private void exitSendKeepAliveMessageThread()
sendKeepAliveMessageThread
to notify this instance that
sendKeepAliveMessageThread is about to exit.int getCandidateCount()
hostCandidate
during this harvest.hostCandidate
during this harvestLocalCandidate[] getCandidates()
hostCandidate
during
this harvest.hostCandidate
during this harvestprotected TransportAddress getMappedAddress(Response response)
response
- the Response from which the XOR-MAPPED-ADDRESS
attribute is to be retrieved and its TransportAddress value is
to be returnedprivate boolean processChallenge(byte[] realm, byte[] nonce, Request request, TransactionID requestTransactionID) throws StunException
realm
- the realm in which the specified STUN Request has
been challenged for a long-term credentialnonce
- the nonce with which the specified STUN Request has
been challenged for a long-term credentialrequest
- the STUN Request which has been challenged for a
long-term credentialrequestTransactionID
- the TransactionID of
request because request only has it as a byte
array and TransactionID is required for the
applicationData property valueStunException
- if anything goes wrong while processing the
challengeprivate boolean processChallenge(Response response, Request request, TransactionID transactionID) throws StunException
response
- the STUN Response which has been receivedrequest
- the STUN Request to which response
responds and which it challenges for a long-term credentialtransactionID
- the TransactionID of response and
request because response and request only have
it as a byte array and TransactionID is required for
the applicationData property valueStunException
- if anything goes wrong while processing the
challengeprotected boolean processErrorOrFailure(Response response, Request request, TransactionID transactionID)
response
- the error Response which has been received for
requestrequest
- the Request to which Response respondstransactionID
- the TransactionID of response and
request because response and request only have
it as a byte array and TransactionID is required for
the applicationData property valueprotected void processFailure(BaseStunMessageEvent event)
processFailure
in class AbstractResponseCollector
event
- the BaseStunMessageEvent which describes the failed
transaction and the runtime type of which specifies the failure reasonAbstractResponseCollector.processFailure(BaseStunMessageEvent)
public void processResponse(StunResponseEvent event)
event
- the StunResponseEvent which describes the received
STUN responseResponseCollector.processResponse(StunResponseEvent)
private boolean processStaleNonce(Response response, Request request, TransactionID transactionID) throws StunException
response
- the received STUN error Response with error code
"438 Stale Nonce" which is to be handledrequest
- the STUN Request to which response
respondstransactionID
- the TransactionID of response and
request because response and request only have
it as a byte array and TransactionID is required for
the applicationData property valueStunException
- if anything goes wrong while handling the specified
"438 Stale Nonce" error responseprotected void processSuccess(Response response, Request request, TransactionID transactionID)
response
- the received STUN success Response which is to
be handledrequest
- the STUN Request to which response
respondstransactionID
- the TransactionID of response and
request because response and request only have
it as a byte array and TransactionID is required for
the applicationData property valueprivate boolean processUnauthorized(Response response, Request request, TransactionID transactionID) throws StunException
response
- the received STUN error Response with error code
"401 Unauthorized" which is to be handledrequest
- the STUN Request to which response
respondstransactionID
- the TransactionID of response and
request because response and request only have
it as a byte array and TransactionID is required for
the applicationData property valueStunException
- if anything goes wrong while handling the specified
"401 Unauthorized" error responseprivate boolean runInSendKeepAliveMessageThread()
sendKeepAliveMessageThread
and sends STUN
keep-alive Messages to the STUN server associated with the
StunCandidateHarvester of this instance.protected void sendKeepAliveMessage() throws StunException
StunException
- if anything goes wrong while sending a new
keep-alive STUN Messageprotected boolean sendKeepAliveMessage(LocalCandidate candidate) throws StunException
candidate
- the LocalCandidate to send a new keep-alive
STUN Message forStunException
- if anything goes wrong while sending the new
keep-alive STUN Message for the specified candidateprotected TransactionID sendRequest(Request request, boolean firstRequest, TransactionID transactionID) throws StunException
request
- the Request to send to the STUN server associated
with this StunCandidateHarvestfirstRequest
- true if the specified request
should be sent as the first request in the terms of STUN; otherwise,
falsetransactionID
- the TransactionID of request
because request only has it as a byte array and
TransactionID is required for the applicationData
property valueStunException
- if anything goes wrong while sending the specified
Request to the STUN server associated with this
StunCandidateHarvestprotected void setSendKeepAliveMessageInterval(long sendKeepAliveMessageInterval)
sendKeepAliveMessageInterval
- the interval in milliseconds at which
a new STUN keep-alive message is to be sent to the STUN server associated
with the StunCandidateHarvester of this instance in order to
keep one of the Candidates harvested by this instance alive or
SEND_KEEP_ALIVE_MESSAGE_INTERVAL_NOT_SPECIFIED
if the keep-alive
functionality is to not be utilizedboolean startResolvingCandidate() throws Exception
hostCandidate
.hostCandidate
;
otherwise, falseException
- if anything goes wrong while starting the harvesting of
Candidates to be performed for hostCandidate
public void close()
Copyright © 2018. All rights reserved.