public void testGetBulletinChunkTypo() throws Exception {
    final String authorAccountId = "a";
    final String bulletinLocalId = "b";
    final int offset = 123;
    final int maxChunkSize = 456;

    supplier.returnResultTag = NetworkInterfaceConstants.CHUNK_OK;
    supplier.authorizedCaller = callerAccountId;
    String returnZipData = StreamableBase64.encode("zip data");
    UniversalId uid = UniversalId.createFromAccountAndLocalId(authorAccountId, bulletinLocalId);
    supplier.addZipData(uid, returnZipData);

    Vector parameters = new Vector();
    parameters.add(MirroringInterface.CMD_MIRRORING_GET_BULLETIN_CHUNK_TYPO);
    parameters.add(authorAccountId);
    parameters.add(bulletinLocalId);
    parameters.add(new Integer(offset));
    parameters.add(new Integer(maxChunkSize));
    String sig = callerSecurity.createSignatureOfVectorOfStrings(parameters);
    Vector result = handler.request(callerAccountId, parameters, sig);

    assertEquals(authorAccountId, supplier.gotAccount);
    assertEquals(bulletinLocalId, supplier.gotLocalId);
    assertEquals(offset, supplier.gotChunkOffset);
    assertEquals(maxChunkSize, supplier.gotMaxChunkSize);

    assertEquals(2, result.size());
    assertEquals(NetworkInterfaceConstants.CHUNK_OK, result.get(0));
    Object[] details = (Object[]) result.get(1);
    assertEquals(new Integer(supplier.getChunkSize(uid) * 3), details[0]);
    assertEquals(new Integer(supplier.getChunkSize(uid)), details[1]);
    assertEquals(returnZipData, details[2]);
  }
  public void testGetBulletinUploadRecordSealedOld() throws Exception {
    supplier.authorizedCaller = callerAccountId;

    UniversalId uid = UniversalIdForTesting.createDummyUniversalId();
    String bur = "This pretends to be a BUR";
    supplier.addBur(uid, bur, BulletinConstants.STATUSSEALED);
    Vector parameters = new Vector();
    parameters.add(MirroringInterface.CMD_MIRRORING_GET_BULLETIN_UPLOAD_RECORD);
    parameters.add(uid.getAccountId());
    parameters.add(uid.getLocalId());
    String sig = callerSecurity.createSignatureOfVectorOfStrings(parameters);
    Vector result = handler.request(callerAccountId, parameters, sig);
    assertEquals(NetworkInterfaceConstants.OK, result.get(0));
    assertEquals(2, result.size());
    assertEquals(bur, ((Object[]) result.get(1))[0]);
  }
  protected Vector listOnlyPacketsThatWeWantUsingLocalIds(
      String accountId, Vector listWithLocalIds) {
    Vector mirroringInfo = new Vector();
    for (int i = 0; i < listWithLocalIds.size(); ++i) {
      UniversalId uid =
          UniversalId.createFromAccountAndLocalId(
              accountId, (String) ((Vector) listWithLocalIds.get(i)).get(0));
      BulletinMirroringInformation mirroringData = new BulletinMirroringInformation(uid);
      mirroringInfo.add(mirroringData.getInfoWithLocalId());
    }

    return listOnlyPacketsThatWeWantUsingBulletinMirroringInformation(accountId, mirroringInfo);
  }
  public void processNextBulletin() {
    if (isSleeping()) return;

    BulletinMirroringInformation item = getNextItemToRetrieve();
    if (item == null) {
      scheduleSleep();
      return;
    }

    // TODO handle delete requests when we are propagating deletes.

    try {
      UniversalId uid = item.getUid();
      String publicCode = MartusCrypto.getFormattedPublicCode(uid.getAccountId());
      logNotice("Getting bulletin: " + publicCode + "->" + uid.getLocalId());
      String bur = retrieveBurFromMirror(uid);
      File zip = File.createTempFile("$$$MirroringRetriever", null);
      try {
        zip.deleteOnExit();
        retrieveOneBulletin(zip, uid);
        long zipSize = zip.length();
        long mTime = item.getmTime();
        BulletinHeaderPacket bhp = store.saveZipFileToDatabase(zip, uid.getAccountId(), mTime);
        store.writeBur(bhp, bur);
        store.deleteDel(bhp.getUniversalId());
        logNotice(
            "Stored bulletin:  " + publicCode + "->" + uid.getLocalId() + " Size: " + zipSize);
      } finally {
        zip.delete();
      }
    } catch (ServerErrorException e) {
      logError("Supplier server:", e);
    } catch (ServerNotAvailableException e) {
      // TODO: Notify once per hour that something is wrong
    } catch (Exception e) {
      logError(e);
    }
  }
예제 #5
0
  public Bulletin(
      MartusCrypto securityToUse,
      UniversalId headerUid,
      UniversalId publicDataUid,
      UniversalId privateDataUid,
      FieldSpecCollection publicFieldSpecs,
      FieldSpecCollection privateFieldSpecs)
      throws Exception {
    security = securityToUse;
    isNonAttachmentDataValidFlag = true;

    header = createHeaderPacket(headerUid);

    fieldData = createPublicFieldDataPacket(publicDataUid, publicFieldSpecs);
    fieldData.setEncrypted(true);
    header.setFieldDataPacketId(publicDataUid.getLocalId());

    privateFieldData = createPrivateFieldDataPacket(privateDataUid, privateFieldSpecs);
    privateFieldData.setEncrypted(true);
    header.setPrivateFieldDataPacketId(privateDataUid.getLocalId());

    clearAllUserData();
  }
  public static void writeAttachmentsToZip(
      ReadableDatabase db,
      Bulletin b,
      ZipOutputStream zipOut,
      AttachmentProxy[] attachments,
      MartusCrypto sigVerifier)
      throws IOException, CryptoException {
    for (int i = 0; i < attachments.length; ++i) {
      UniversalId uid = attachments[i].getUniversalId();
      ZipEntry attachmentEntry = new ZipEntry(uid.getLocalId());
      zipOut.putNextEntry(attachmentEntry);
      DatabaseKey key = b.getDatabaseKeyForLocalId(uid.getLocalId());
      InputStream in = new BufferedInputStream(db.openInputStream(key, sigVerifier));

      byte[] bytes = new byte[MartusConstants.streamBufferCopySize];
      int got;
      while ((got = in.read(bytes)) != -1) {
        zipOut.write(bytes, 0, got);
      }
      in.close();
      zipOut.flush();
    }
  }
예제 #7
0
 public DatabaseKey getDatabaseKeyForLocalId(String localId) {
   UniversalId uid = UniversalId.createFromAccountAndLocalId(getAccount(), localId);
   return getBulletinHeaderPacket().createKeyWithHeaderStatus(uid);
 }