Beispiel #1
0
  @Override
  protected byte[] asBytes(int bitsCount) {
    byte[] bytes = super.asBytes(bitsCount);

    int currentBitIndex = super.getBitsCount();

    ByteUtils.addByteArrayToArrayAtByteIndex(leavingPeerInfo.asBytes(), bytes, currentBitIndex / 8);
    currentBitIndex += leavingPeerInfo.getBitsCount();

    for (ResourceObject currentResource : resources) {
      ByteUtils.addByteArrayToArrayAtByteIndex(
          currentResource.asBytes(), bytes, currentBitIndex / 8);
      currentBitIndex += currentResource.getBitsCount();
    }

    return bytes;
  }
  @Override
  protected byte[] asBytes(int bitsCount) {
    byte[] bytes = super.asBytes(bitsCount);

    int currentIndex = super.getBitsCount() / 8;

    ByteUtils.addByteArrayToArrayAtByteIndex(
        this.originatorPeerInfo.asBytes(), bytes, currentIndex);
    currentIndex += this.originatorPeerInfo.getBitsCount() / 8;

    for (PeerInfo currentPeerInfo : this.vset) {
      if (currentPeerInfo != null) {
        ByteUtils.addByteArrayToArrayAtByteIndex(currentPeerInfo.asBytes(), bytes, currentIndex);
        currentIndex += currentPeerInfo.getBitsCount() / 8;
      }
    }

    return bytes;
  }
  @Override
  public boolean verify() {
    boolean result = true;

    if (this.originatorPeerInfo == null || this.vset == null) {
      result = false;
    } else {
      // must contain peerID
      PeerID peerID = this.originatorPeerInfo.getPeerID();
      if (peerID == null) {
        result = false;
      } else {
        if (peerID.getPeerIDBytes() == null) {
          result = false;
        }
      }
      // not checked if peerID isn't here
      if (result) {
        // must contain unshadedID
        UnhashedID unhashedID = this.originatorPeerInfo.getUnhashedID();
        if (unhashedID == null) {
          result = false;
        } else {
          if (unhashedID.getUnhashedIDValue() == null) {
            result = false;
          }
        }
      }
      // not checked if PeerID or UnhashedID isn't here
      if (result) {
        // has to contain at least one AddressInfo
        Vector<AddressInfo> addressInfos = this.originatorPeerInfo.getAddressInfos();
        if (addressInfos == null) {
          result = false;
        } else if (addressInfos.size() <= 0) {
          result = false;
        }
      }

      if (result) {
        if (ByteUtils.booleanArrayToInt(this.reservedOrResponseCode) == Response.RESPONSE_CODE_OK) {
          int vsetSize = this.vset.size();
          if (vsetSize == 0) {
            result = false;
          } else {
            for (int i = 0; i < vsetSize; i++) {
              PeerInfo currentPeerInfo = this.vset.get(i);
              PeerID currentPeerID = currentPeerInfo.getPeerID();
              if (currentPeerID == null) {
                result = false;
              } else {
                if (currentPeerID.getPeerIDBytes() == null) {
                  result = false;
                } else {
                  Vector<AddressInfo> addressInfos = currentPeerInfo.getAddressInfos();
                  if (addressInfos == null) {
                    result = false;
                  } else if (addressInfos.size() <= 0) {
                    result = false;
                  } else {
                    UnhashedID currentUnhashedID = currentPeerInfo.getUnhashedID();
                    if (currentUnhashedID == null) {
                      result = false;
                    } else {
                      if (currentUnhashedID.getUnhashedIDValue() == null) {
                        result = false;
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }

    return result;
  }