示例#1
0
 /**
  * Creates a new STUN <tt>Message</tt> to be sent to the STUN server associated with the
  * <tt>StunCandidateHarvester</tt> of this instance in order to keep a specific
  * <tt>LocalCandidate</tt> (harvested by this instance) alive.
  *
  * @param candidate the <tt>LocalCandidate</tt> (harvested by this instance) to create a new
  *     keep-alive STUN message for
  * @return a new keep-alive STUN <tt>Message</tt> for the specified <tt>candidate</tt> or
  *     <tt>null</tt> if no keep-alive sending is to occur
  * @throws StunException if anything goes wrong while creating the new keep-alive STUN
  *     <tt>Message</tt> for the specified <tt>candidate</tt> or the candidate is of an unsupported
  *     <tt>CandidateType</tt>
  */
 protected Message createKeepAliveMessage(LocalCandidate candidate) throws StunException {
   /*
    * We'll not be keeping a STUN Binding alive for now. If we decide to in
    * the future, we'll have to create a Binding Indication and add support
    * for sending it.
    */
   if (CandidateType.SERVER_REFLEXIVE_CANDIDATE.equals(candidate.getType())) return null;
   else {
     throw new StunException(StunException.ILLEGAL_ARGUMENT, "candidate");
   }
 }
示例#2
0
  /**
   * Determines whether a specific <tt>LocalCandidate</tt> is contained in the list of
   * <tt>LocalCandidate</tt>s harvested for {@link #hostCandidate} by this harvest.
   *
   * @param candidate the <tt>LocalCandidate</tt> to look for in the list of
   *     <tt>LocalCandidate</tt>s harvested for {@link #hostCandidate} by this harvest
   * @return <tt>true</tt> if the list of <tt>LocalCandidate</tt>s contains the specified
   *     <tt>candidate</tt>; otherwise, <tt>false</tt>
   */
  protected boolean containsCandidate(LocalCandidate candidate) {
    if (candidate != null) {
      LocalCandidate[] candidates = getCandidates();

      if ((candidates != null) && (candidates.length != 0)) {
        for (LocalCandidate c : candidates) {
          if (candidate.equals(c)) return true;
        }
      }
    }
    return false;
  }