Search in sources :

Example 1 with RefreshTTLMessage

use of io.bitsquare.p2p.storage.messages.RefreshTTLMessage in project bitsquare by bitsquare.

the class ProtectedDataStorageTest method testRefreshTTL.

/* //@Test
     public void testRePublish() throws InterruptedException, NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException, CryptoException, SignatureException, InvalidKeyException, NoSuchProviderException {
         mockData.ttl = (int) (P2PDataStorage.CHECK_TTL_INTERVAL_MILLIS * 1.5);
         ProtectedData data = dataStorage1.getDataWithSignedSeqNr(mockData, storageSignatureKeyPair1);
         Assert.assertTrue(dataStorage1.add(data, null));
         Assert.assertEquals(1, dataStorage1.getMap().size());
         Thread.sleep(P2PDataStorage.CHECK_TTL_INTERVAL_MILLIS);
         log.debug("test 1");
         Assert.assertEquals(1, dataStorage1.getMap().size());
 
         data = dataStorage1.getDataWithSignedSeqNr(mockData, storageSignatureKeyPair1);
         Assert.assertTrue(dataStorage1.rePublish(data, null));
         Thread.sleep(P2PDataStorage.CHECK_TTL_INTERVAL_MILLIS);
         log.debug("test 2");
         Assert.assertEquals(1, dataStorage1.getMap().size());
 
         data = dataStorage1.getDataWithSignedSeqNr(mockData, storageSignatureKeyPair1);
         Assert.assertTrue(dataStorage1.rePublish(data, null));
         Thread.sleep(P2PDataStorage.CHECK_TTL_INTERVAL_MILLIS);
         log.debug("test 3");
         Assert.assertEquals(1, dataStorage1.getMap().size());
 
         Thread.sleep(P2PDataStorage.CHECK_TTL_INTERVAL_MILLIS);
         log.debug("test 4");
         Assert.assertEquals(1, dataStorage1.getMap().size());
 
         Thread.sleep(P2PDataStorage.CHECK_TTL_INTERVAL_MILLIS * 2);
         log.debug("test 5 removed");
         Assert.assertEquals(0, dataStorage1.getMap().size());
     }
 */
@Test
public void testRefreshTTL() throws InterruptedException, NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException, CryptoException, SignatureException, InvalidKeyException, NoSuchProviderException {
    mockData.ttl = (int) (P2PDataStorage.CHECK_TTL_INTERVAL_SEC * 1.5);
    ProtectedStorageEntry data = dataStorage1.getProtectedData(mockData, storageSignatureKeyPair1);
    Assert.assertTrue(dataStorage1.add(data, null, null, true));
    Assert.assertEquals(1, dataStorage1.getMap().size());
    Thread.sleep(P2PDataStorage.CHECK_TTL_INTERVAL_SEC);
    log.debug("test 1");
    Assert.assertEquals(1, dataStorage1.getMap().size());
    RefreshTTLMessage refreshTTLMessage = dataStorage1.getRefreshTTLMessage(mockData, storageSignatureKeyPair1);
    Assert.assertTrue(dataStorage1.refreshTTL(refreshTTLMessage, null, true));
    Thread.sleep(P2PDataStorage.CHECK_TTL_INTERVAL_SEC);
    log.debug("test 2");
    Assert.assertEquals(1, dataStorage1.getMap().size());
    refreshTTLMessage = dataStorage1.getRefreshTTLMessage(mockData, storageSignatureKeyPair1);
    Assert.assertTrue(dataStorage1.refreshTTL(refreshTTLMessage, null, true));
    Thread.sleep(P2PDataStorage.CHECK_TTL_INTERVAL_SEC);
    log.debug("test 3");
    Assert.assertEquals(1, dataStorage1.getMap().size());
    Thread.sleep(P2PDataStorage.CHECK_TTL_INTERVAL_SEC);
    log.debug("test 4");
    Assert.assertEquals(1, dataStorage1.getMap().size());
    Thread.sleep(P2PDataStorage.CHECK_TTL_INTERVAL_SEC * 2);
    log.debug("test 5 removed");
    Assert.assertEquals(0, dataStorage1.getMap().size());
}
Also used : RefreshTTLMessage(io.bitsquare.p2p.storage.messages.RefreshTTLMessage) ProtectedStorageEntry(io.bitsquare.p2p.storage.storageentry.ProtectedStorageEntry)

Example 2 with RefreshTTLMessage

use of io.bitsquare.p2p.storage.messages.RefreshTTLMessage in project bitsquare by bitsquare.

the class P2PService method refreshTTL.

public boolean refreshTTL(StoragePayload storagePayload, boolean isDataOwner) {
    Log.traceCall();
    checkArgument(optionalKeyRing.isPresent(), "keyRing not set. Seems that is called on a seed node which must not happen.");
    if (isBootstrapped()) {
        try {
            RefreshTTLMessage refreshTTLMessage = p2PDataStorage.getRefreshTTLMessage(storagePayload, optionalKeyRing.get().getSignatureKeyPair());
            return p2PDataStorage.refreshTTL(refreshTTLMessage, networkNode.getNodeAddress(), isDataOwner);
        } catch (CryptoException e) {
            log.error("Signing at getDataWithSignedSeqNr failed. That should never happen.");
            return false;
        }
    } else {
        throw new NetworkNotReadyException();
    }
}
Also used : RefreshTTLMessage(io.bitsquare.p2p.storage.messages.RefreshTTLMessage) CryptoException(io.bitsquare.common.crypto.CryptoException)

Aggregations

RefreshTTLMessage (io.bitsquare.p2p.storage.messages.RefreshTTLMessage)2 CryptoException (io.bitsquare.common.crypto.CryptoException)1 ProtectedStorageEntry (io.bitsquare.p2p.storage.storageentry.ProtectedStorageEntry)1