コード例 #1
0
  /**
   * Internal function to format the bundle flags so they can be stored in one byte.
   *
   * @param bundle Bundle to get the flags values
   * @return Formatted value of the flags
   */
  protected static int format_bundle_flags(final Bundle bundle) {

    int flags = 0;

    if (bundle.is_fragment()) {
      flags |= bundle_processing_flag_t.BUNDLE_IS_FRAGMENT.getCode();
    }

    if (bundle.is_admin()) {
      flags |= bundle_processing_flag_t.BUNDLE_IS_ADMIN.getCode();
    }

    if (bundle.do_not_fragment()) {
      flags |= bundle_processing_flag_t.BUNDLE_DO_NOT_FRAGMENT.getCode();
    }

    if (bundle.custody_requested()) {
      flags |= bundle_processing_flag_t.BUNDLE_CUSTODY_XFER_REQUESTED.getCode();
    }

    if (bundle.singleton_dest()) {
      flags |= bundle_processing_flag_t.BUNDLE_SINGLETON_DESTINATION.getCode();
    }

    if (bundle.app_acked_rcpt()) {
      flags |= bundle_processing_flag_t.BUNDLE_ACK_BY_APP.getCode();
    }
    return flags;
  }
コード例 #2
0
  /**
   * Check the validity of the Primary block
   *
   * @param bundle Bundle to check the generic validity of block
   * @param block_list List of Blocks
   * @param block Block to check if it's valid or not
   * @param reception_reason If block is not valid then reception reason
   * @param deletion_reason If block is not balid then deletion reason
   * @return True if the block is valid else false
   */
  public boolean validate(
      final Bundle bundle,
      BlockInfoVec block_list,
      BlockInfo block,
      status_report_reason_t[] reception_reason,
      status_report_reason_t[] deletion_reason) {
    // Make sure all four EIDs are valid.
    boolean eids_valid = true;
    eids_valid &= bundle.source().valid();
    eids_valid &= bundle.dest().valid();
    eids_valid &= bundle.custodian().valid();
    eids_valid &= bundle.replyto().valid();

    if (!eids_valid) {
      Log.e(TAG, "bad value for one or more EIDs");
      deletion_reason[0] = status_report_reason_t.REASON_BLOCK_UNINTELLIGIBLE;
      return false;
    }

    // According to BP section 3.3, there are certain things that a bundle
    // with a null source EID should not try to do. Check for these cases
    // and reject the bundle if any is true.

    Log.d(TAG, "Going to check null eid");
    if (bundle.source().equals(EndpointID.NULL_EID())) {
      Log.d(TAG, "Inside of Going to check null eid");
      if (bundle.receipt_requested() || bundle.app_acked_rcpt()) {
        Log.e(TAG, "bundle with null source eid has requested a report; reject it");
        deletion_reason[0] = status_report_reason_t.REASON_BLOCK_UNINTELLIGIBLE;
        return false;
      }

      if (bundle.custody_requested()) {
        Log.e(TAG, "bundle with null source eid has requested custody transfer; reject it");
        deletion_reason[0] = status_report_reason_t.REASON_BLOCK_UNINTELLIGIBLE;
        return false;
      }

      if (!bundle.do_not_fragment()) {
        Log.e(
            TAG, "bundle with null source eid has not set " + "'do-not-fragment' flag; reject it");
        deletion_reason[0] = status_report_reason_t.REASON_BLOCK_UNINTELLIGIBLE;
        return false;
      }
    }

    Log.d(TAG, "Out of Going to check null eid");
    // Admin bundles cannot request custody transfer.
    if (bundle.is_admin()) {
      if (bundle.custody_requested()) {
        Log.e(TAG, "admin bundle requested custody transfer; reject it");
        deletion_reason[0] = status_report_reason_t.REASON_BLOCK_UNINTELLIGIBLE;
        return false;
      }

      if (bundle.receive_rcpt()
          || bundle.custody_rcpt()
          || bundle.forward_rcpt()
          || bundle.delivery_rcpt()
          || bundle.deletion_rcpt()
          || bundle.app_acked_rcpt()) {
        Log.e(TAG, "admin bundle has requested a report; reject it");
        deletion_reason[0] = status_report_reason_t.REASON_BLOCK_UNINTELLIGIBLE;
        return false;
      }
    }

    return true;
  }