예제 #1
0
  /** Delete any fragments that are no longer needed given the incoming (non-fragment) bundle. */
  public void delete_obsoleted_fragments(Bundle bundle) {

    FragmentState state;

    // cons up the key to do the table lookup and look for reassembly state
    String[] hash_key = new String[1];
    hash_key[0] = "";

    get_hash_key(bundle, hash_key);
    state = fragment_table_.get(hash_key);

    Logger.getInstance()
        .debug(
            TAG,
            String.format(
                "checking for obsolete fragments id=%s hash=%s...",
                bundle.bundleid(), hash_key[0]));

    if (state == null) {
      Logger.getInstance().error(TAG, String.format("no reassembly state for key %s", hash_key[0]));
      return;
    }

    Logger.getInstance()
        .debug(
            TAG,
            String.format(
                "found reassembly state... deleting %d fragments", state.num_fragments()));

    state.fragment_list().get_lock().lock();
    try {

      while (state.fragment_list().size() > 0) {
        BundleDaemon.getInstance()
            .post(
                new BundleDeleteRequest(
                    state.fragment_list().pop_back(false),
                    status_report_reason_t.REASON_NO_ADDTL_INFO));
      }

      assert (state.fragment_list().size() == 0)
          : TAG + ": delete_obsoleted_fragments Size not 0"; // moved into
      // events

    } finally {
      state.fragment_list().get_lock().unlock();
    }

    fragment_table_.remove(hash_key);
  }
예제 #2
0
  /**
   * Given a newly arrived bundle fragment, append it to the table of fragments and see if it allows
   * us to reassemble the bundle. If it does, a ReassemblyCompletedEvent will be posted.
   *
   * @param fragment Newly received fragment
   */
  public void process_for_reassembly(Bundle fragment) {
    FragmentState state;

    assert (fragment.is_fragment()) : TAG + ": process_for_reassembly() not a fragment";

    String[] hash_key = new String[1];
    get_hash_key(fragment, hash_key);

    FragmentState iter = fragment_table_.get(hash_key);

    Logger.getInstance()
        .debug(
            TAG,
            String.format(
                "processing bundle fragment id=%s hash=%s %s",
                fragment.bundleid(), hash_key, fragment.is_fragment()));

    if (iter == null) {

      state = new FragmentState();

      fragment.copy_metadata(state.bundle());
      state.bundle().set_is_fragment(false);
      state.bundle().payload().set_length(fragment.orig_length());
      fragment_table_.put(hash_key[0], state);
    } else {
      state = iter;
      Logger.getInstance()
          .debug(
              TAG,
              String.format(
                  "found reassembly state for key %s (%s fragments)",
                  hash_key, state.fragment_list().size()));
    }

    // stick the fragment on the reassembly list
    state.add_fragment(fragment);

    // store the fragment data in the partially reassembled bundle file
    int fraglen = fragment.payload().length();

    Logger.getInstance()
        .debug(
            TAG,
            String.format(
                "write_data: length_=%s src_offset=%s dst_offset=%s len %s",
                state.bundle().payload().length(), 0, fragment.frag_offset(), fraglen));

    state.bundle().payload().write_data(fragment.payload(), 0, fraglen, fragment.frag_offset());

    // reassembled bundle, but eventually reassembly will have to do much
    // more
    if (fragment.frag_offset() == 0 && state.bundle().recv_blocks().size() > 0) {
      BlockInfo block_i;

      ListIterator<BlockInfo> entry = fragment.recv_blocks().listIterator();

      while (entry.hasNext()) {
        block_i = entry.next();
        state.bundle().recv_blocks().add(block_i);
      }
    }

    // check see if we're done
    if (state.check_completed()) {
      return;
    }

    BundleDaemon.getInstance()
        .post_at_head(new ReassemblyCompletedEvent(state.bundle(), state.fragment_list()));
    assert (state.fragment_list().size() == 0)
        : TAG + ": process_for_reassembly size not 0"; // moved into the event
    fragment_table_.remove(hash_key);
  }