Brunet.Connections.LinkProtocolState.SetAndCheckLinkReply C# (CSharp) Method

SetAndCheckLinkReply() protected method

protected SetAndCheckLinkReply ( LinkMessage lm ) : void
lm LinkMessage
return void
    protected void SetAndCheckLinkReply(LinkMessage lm) {
      /* Check that the everything matches up 
       * Make sure the link message is Kosher.
       * This are critical errors.  This Link fails if these occur
       */
      if( lm.Local == null) {
        throw new LinkException("Bad response");
      }
      if( _node.Address.Equals( lm.Local.Address ) ) {
        //Somehow, we got a response from someone claiming to be us.
        throw new LinkException("Got a LinkMessage response from our address");
      }
      if( lm.ConTypeString != _contype ) {
        throw new LinkException("Link type mismatch: " + _contype + " != " + lm.ConTypeString );
      }
      if( !lm.Realm.Equals( _node.Realm ) ) {
        throw new LinkException("Realm mismatch: " +
                                _node.Realm + " != " + lm.Realm );
      }
      if( lm.Local.Address == null ) {
        throw new LinkException("LinkMessage response has null Address");
      }
      if( (_linker.Target != null) && (!lm.Local.Address.Equals( _linker.Target )) ) {
        /*
         * This is super goofy.  Somehow we got a response from some node
         * we didn't mean to connect to.
         * This can happen in some cases with NATs since nodes behind NATs are
         * guessing which ports are correct, their guess may be incorrect, and
         * the NAT may send the packet to a different node.
         * In this case, we have a critical error, this TA is not correct, we
         * must move on to the next TA.
         */
        throw new LinkException(String.Format("Target mismatch: {0} != {1}",
                                              _linker.Target, lm.Local.Address), true, null );
      }
      /*
       * Okay, this lm looks good, we'll accept it.  This can only be done
       * once, and once it happens a future attempt will throw an exception
       */
      _lm_reply.Value = lm;
    }