コード例 #1
0
 private void sendRejectAnswer(
     Agent ag,
     Desire desire,
     CensorComponent cexec,
     SpeechAct action,
     Secret s,
     String answerValue) {
   Answer answer = null;
   String act = null;
   if (action instanceof Update) {
     Update update = (Update) action;
     answer = new Answer(ag, update.getSenderId(), update.getProposition(), AnswerValue.AV_REJECT);
     act = "update";
   } else if (action instanceof Revision) {
     Revision revision = (Revision) action;
     answer =
         new Answer(ag, revision.getSenderId(), revision.getProposition(), AnswerValue.AV_REJECT);
     act = "revision";
   } else if (action instanceof Query) {
     Query query = (Query) action;
     answer = new Answer(ag, query.getSenderId(), query.getQuestion(), AnswerValue.AV_REJECT);
     act = "query";
   }
   Subgoal answerGoal = new Subgoal(ag, desire);
   answerGoal.newStack(answer);
   ag.getPlanComponent().addPlan(answerGoal);
   cexec.report(
       "The reaction '"
           + answerValue
           + "' would reveal secret "
           + s
           + ". Reject the "
           + act
           + ".");
   cexec.report(
       "Add the new action '" + Answer.class.getSimpleName() + "' to the plan",
       ag.getPlanComponent());
 }
コード例 #2
0
  /**
   * Process an incoming query request from an attacking agent. Using the censor component, this
   * method first checks if a secret might be revealed by the actual query handling. Based on this
   * preprocessing, it either generates a Refusal-SpeechAct or starts the query handling and
   * generates an appropriate answer.
   *
   * @param desire
   * @param pp
   * @param ag
   */
  public boolean processQuery(Desire desire, PlanParameter pp, Agent ag) {
    pp.report("Generate new subgoal to process query request");

    CensorComponent cexec = ag.getComponent(CensorComponent.class);

    Query query = (Query) desire.getPerception();

    GeneralView v = ag.getComponent(ViewDataComponent.class).getView(query.getSenderId());
    SecrecyKnowledge conf = ag.getComponent(SecrecyKnowledge.class);
    GeneralHistory history = null;

    pp.report("Invoke censor to check all possible answers for meta inferences");
    if (v instanceof View) {
      View view = (View) v;
      // check for all possible answers to the query, whether this answer would
      // potentially reveal a secret and in that case, refuse to answer.
      for (Secret a : conf.getSecrets()) {
        // ans := true
        if (cexec.poss(view.RefineViewByQuery(query.getQuestion(), AnswerValue.AV_TRUE))
            && cexec.scepticalInference(
                view.RefineViewByQuery(query.getQuestion(), AnswerValue.AV_TRUE),
                a.getInformation())) {
          this.sendRejectAnswer(ag, desire, cexec, query, a, "true");
          return true;
        }
        // ans := false
        if (cexec.poss(view.RefineViewByQuery(query.getQuestion(), AnswerValue.AV_FALSE))
            && cexec.scepticalInference(
                view.RefineViewByQuery(query.getQuestion(), AnswerValue.AV_FALSE),
                a.getInformation())) {
          this.sendRejectAnswer(ag, desire, cexec, query, a, "false");
          return true;
        }
        // ans := undef
        if (cexec.poss(view.RefineViewByQuery(query.getQuestion(), AnswerValue.AV_UNKNOWN))
            && cexec.scepticalInference(
                view.RefineViewByQuery(query.getQuestion(), AnswerValue.AV_UNKNOWN),
                a.getInformation())) {
          this.sendRejectAnswer(ag, desire, cexec, query, a, "unknown");
          return true;
        }
      }
    } else if (v instanceof ViewWithCompressedHistory) {
      ViewWithCompressedHistory view = (ViewWithCompressedHistory) v;
      history = ag.getComponent(HistoryComponent.class).getHistories().get(query.getSenderId());
      if (history == null) {
        history = new CompressedHistory();
        ag.getComponent(HistoryComponent.class).getHistories().put(query.getSenderId(), history);
      }
      for (Secret a : conf.getSecrets()) {
        // ans := true
        ViewWithCompressedHistory copyView = new ViewWithCompressedHistory(view);
        CompressedHistory refinedHistory = new CompressedHistory((CompressedHistory) history);
        refinedHistory.putAction(query, AnswerValue.AV_TRUE);
        if (cexec.scepticalInference(copyView, a.getInformation(), refinedHistory)) {
          this.sendRejectAnswer(ag, desire, cexec, query, a, "true");
          history.putAction(query, AnswerValue.AV_REJECT);
          ag.getComponent(HistoryComponent.class).getHistories().put(query.getSenderId(), history);
          return true;
        }

        // ans := false
        copyView = new ViewWithCompressedHistory(view);
        refinedHistory = new CompressedHistory((CompressedHistory) history);
        refinedHistory.putAction(query, AnswerValue.AV_FALSE);
        if (cexec.scepticalInference(copyView, a.getInformation(), refinedHistory)) {
          this.sendRejectAnswer(ag, desire, cexec, query, a, "false");
          history.putAction(query, AnswerValue.AV_REJECT);
          ag.getComponent(HistoryComponent.class).getHistories().put(query.getSenderId(), history);
          return true;
        }

        // ans := undef
        copyView = new ViewWithCompressedHistory(view);
        refinedHistory = new CompressedHistory((CompressedHistory) history);
        refinedHistory.putAction(query, AnswerValue.AV_UNKNOWN);
        if (cexec.scepticalInference(copyView, a.getInformation(), refinedHistory)) {
          this.sendRejectAnswer(ag, desire, cexec, query, a, "unknown");
          history.putAction(query, AnswerValue.AV_REJECT);
          ag.getComponent(HistoryComponent.class).getHistories().put(query.getSenderId(), history);
          return true;
        }
      }
    } else if (v instanceof ViewWithHistory) {
      ViewWithHistory view = (ViewWithHistory) v;
      history = ag.getComponent(HistoryComponent.class).getHistories().get(query.getSenderId());
      if (history == null) {
        history = new History();
        ag.getComponent(HistoryComponent.class).getHistories().put(query.getSenderId(), history);
      }
      // check for all possible answers to the query, whether this answer would
      // potentially reveal a secret and in that case, refuse to answer.
      for (Secret a : conf.getSecrets()) {
        // ans := true
        if (cexec.scepticalInference(
            view.RefineViewByQuery(query.getQuestion(), AnswerValue.AV_TRUE), a.getInformation())) {
          this.sendRejectAnswer(ag, desire, cexec, query, a, "true");
          history.putAction(query, AnswerValue.AV_REJECT);
          ag.getComponent(HistoryComponent.class).getHistories().put(query.getSenderId(), history);
          return true;
        }
        // ans := false
        if (cexec.scepticalInference(
            view.RefineViewByQuery(query.getQuestion(), AnswerValue.AV_FALSE),
            a.getInformation())) {
          this.sendRejectAnswer(ag, desire, cexec, query, a, "false");
          history.putAction(query, AnswerValue.AV_REJECT);
          ag.getComponent(HistoryComponent.class).getHistories().put(query.getSenderId(), history);
          return true;
        }
        // ans := undef
        if (cexec.scepticalInference(
            view.RefineViewByQuery(query.getQuestion(), AnswerValue.AV_UNKNOWN),
            a.getInformation())) {
          this.sendRejectAnswer(ag, desire, cexec, query, a, "unknown");
          history.putAction(query, AnswerValue.AV_REJECT);
          ag.getComponent(HistoryComponent.class).getHistories().put(query.getSenderId(), history);
          return true;
        }
      }
    } else if (v instanceof BetterView) {
      BetterView view = (BetterView) v;

      // check for all possible answers to the query, whether this answer would
      // potentially reveal a secret and in that case, refuse to answer.
      for (Secret a : conf.getSecrets()) {
        // ans := true
        if (cexec.scepticalInference(
            view.MentalRefineViewByQuery(query.getQuestion(), AnswerValue.AV_TRUE),
            a.getInformation())) {
          this.sendRejectAnswer(ag, desire, cexec, query, a, "true");
          return true;
        }
        // ans := false
        if (cexec.scepticalInference(
            view.MentalRefineViewByQuery(query.getQuestion(), AnswerValue.AV_FALSE),
            a.getInformation())) {
          this.sendRejectAnswer(ag, desire, cexec, query, a, "false");
          return true;
        }
        // ans := undef
        if (cexec.scepticalInference(
            view.MentalRefineViewByQuery(query.getQuestion(), AnswerValue.AV_UNKNOWN),
            a.getInformation())) {
          this.sendRejectAnswer(ag, desire, cexec, query, a, "unknown");
          return true;
        }
      }
    }
    cexec.report(
        "No answer to query '"
            + query.getQuestion()
            + " would reveal a secret. Start actual handling.");

    // no secret will be revealed by any possible answer to the query.
    // handle the query and create an appropriate answer action.
    AngeronaAnswer answer = ag.getBeliefs().getWorldKnowledge().reason(query.getQuestion());
    if (history != null) {
      history.putAction(query, answer.getAnswerValue());
      ag.getComponent(HistoryComponent.class).getHistories().put(query.getSenderId(), history);
    }
    ag.getBeliefs()
        .getWorldKnowledge()
        .report("Actual answer to query: " + answer.getAnswerValue());
    Answer answerSpeechAct =
        new Answer(ag, query.getSenderId(), query.getQuestion(), answer.getAnswerValue());
    Subgoal answerGoal = new Subgoal(ag, desire);
    answerGoal.newStack(answerSpeechAct);
    ag.getPlanComponent().addPlan(answerGoal);

    pp.report(
        "Add the new action '" + Answer.class.getSimpleName() + "' to the plan",
        ag.getPlanComponent());
    return true;
  }