Search in sources :

Example 1 with Hash

use of io.bitsquare.common.crypto.Hash in project bitsquare by bitsquare.

the class P2PDataStorage method printData.

private void printData(String info) {
    if (LoggerFactory.getLogger(Log.class).isInfoEnabled() || LoggerFactory.getLogger(Log.class).isDebugEnabled()) {
        StringBuilder sb = new StringBuilder("\n\n------------------------------------------------------------\n");
        sb.append("Data set ").append(info).append(" operation");
        // We print the items sorted by hash with the payload class name and id
        List<Tuple2<String, ProtectedStorageEntry>> tempList = map.values().stream().map(e -> new Tuple2<>(org.bitcoinj.core.Utils.HEX.encode(getHashAsByteArray(e.getStoragePayload()).bytes), e)).collect(Collectors.toList());
        tempList.sort((o1, o2) -> o1.first.compareTo(o2.first));
        tempList.stream().forEach(e -> {
            final ProtectedStorageEntry storageEntry = e.second;
            final StoragePayload storagePayload = storageEntry.getStoragePayload();
            final MapValue mapValue = sequenceNumberMap.get(getHashAsByteArray(storagePayload));
            sb.append("\n").append("Hash=").append(e.first).append("; Class=").append(storagePayload.getClass().getSimpleName()).append("; SequenceNumbers (Object/Stored)=").append(storageEntry.sequenceNumber).append(" / ").append(mapValue != null ? mapValue.sequenceNr : "null").append("; TimeStamp (Object/Stored)=").append(storageEntry.creationTimeStamp).append(" / ").append(mapValue != null ? mapValue.timeStamp : "null").append("; Payload=").append(Utilities.toTruncatedString(storagePayload));
        });
        sb.append("\n------------------------------------------------------------\n");
        log.debug(sb.toString());
        log.debug("Data set " + info + " operation: size=" + map.values().size());
    }
}
Also used : Version(io.bitsquare.app.Version) KeyPair(java.security.KeyPair) java.util(java.util) io.bitsquare.p2p.storage.payload(io.bitsquare.p2p.storage.payload) ProtectedStorageEntry(io.bitsquare.p2p.storage.storageentry.ProtectedStorageEntry) Hex(org.spongycastle.util.encoders.Hex) LoggerFactory(org.slf4j.LoggerFactory) Timer(io.bitsquare.common.Timer) Tuple2(io.bitsquare.common.util.Tuple2) CryptoException(io.bitsquare.common.crypto.CryptoException) StringUtils(org.apache.commons.lang3.StringUtils) io.bitsquare.p2p.network(io.bitsquare.p2p.network) ResourceNotFoundException(io.bitsquare.storage.ResourceNotFoundException) Nullable(javax.annotation.Nullable) Log(io.bitsquare.app.Log) Hash(io.bitsquare.common.crypto.Hash) BroadcastHandler(io.bitsquare.p2p.peers.BroadcastHandler) Utilities(io.bitsquare.common.util.Utilities) FileUtil(io.bitsquare.storage.FileUtil) Logger(org.slf4j.Logger) ProtectedMailboxStorageEntry(io.bitsquare.p2p.storage.storageentry.ProtectedMailboxStorageEntry) UserThread(io.bitsquare.common.UserThread) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Message(io.bitsquare.p2p.Message) NodeAddress(io.bitsquare.p2p.NodeAddress) IOException(java.io.IOException) PublicKey(java.security.PublicKey) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Collectors(java.util.stream.Collectors) File(java.io.File) Sig(io.bitsquare.common.crypto.Sig) Serializable(java.io.Serializable) io.bitsquare.p2p.storage.messages(io.bitsquare.p2p.storage.messages) TimeUnit(java.util.concurrent.TimeUnit) Payload(io.bitsquare.common.wire.Payload) Broadcaster(io.bitsquare.p2p.peers.Broadcaster) Paths(java.nio.file.Paths) Storage(io.bitsquare.storage.Storage) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Persistable(io.bitsquare.common.persistance.Persistable) Tuple2(io.bitsquare.common.util.Tuple2) ProtectedStorageEntry(io.bitsquare.p2p.storage.storageentry.ProtectedStorageEntry)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Log (io.bitsquare.app.Log)1 Version (io.bitsquare.app.Version)1 Timer (io.bitsquare.common.Timer)1 UserThread (io.bitsquare.common.UserThread)1 CryptoException (io.bitsquare.common.crypto.CryptoException)1 Hash (io.bitsquare.common.crypto.Hash)1 Sig (io.bitsquare.common.crypto.Sig)1 Persistable (io.bitsquare.common.persistance.Persistable)1 Tuple2 (io.bitsquare.common.util.Tuple2)1 Utilities (io.bitsquare.common.util.Utilities)1 Payload (io.bitsquare.common.wire.Payload)1 Message (io.bitsquare.p2p.Message)1 NodeAddress (io.bitsquare.p2p.NodeAddress)1 io.bitsquare.p2p.network (io.bitsquare.p2p.network)1 BroadcastHandler (io.bitsquare.p2p.peers.BroadcastHandler)1 Broadcaster (io.bitsquare.p2p.peers.Broadcaster)1 io.bitsquare.p2p.storage.messages (io.bitsquare.p2p.storage.messages)1 io.bitsquare.p2p.storage.payload (io.bitsquare.p2p.storage.payload)1 ProtectedMailboxStorageEntry (io.bitsquare.p2p.storage.storageentry.ProtectedMailboxStorageEntry)1