Search in sources :

Example 1 with Inventory

use of org.structr.net.protocol.Inventory in project structr by structr.

the class Peer method onPeerDiscovery.

public void onPeerDiscovery(final PeerInfo newPeer, final byte[] hash) {
    if (newPeer != null && !newPeer.getUuid().equals(getUuid())) {
        final boolean isNew = addPeer(newPeer);
        final byte[] contentHash = getContentHash();
        final boolean hasChanged = !Arrays.equals(hash, contentHash);
        if (isNew || hasChanged) {
            if (isNew) {
                System.out.println("Peer is new, sending inventory..");
            }
            if (hasChanged) {
                System.out.println("Peer has different content hash, sending inventory..");
                System.out.println(printHash(hash) + " / " + printHash(contentHash));
            }
            // send inventory
            for (final RepositoryObject obj : repository.getObjects()) {
                log("Inventory(", obj.getUuid(), ", ", obj.getUserId(), ")");
                send(newPeer, new Inventory(repository.getUuid(), obj.getUuid(), obj.getDeviceId(), obj.getLastModificationTime()));
            }
        }
    }
}
Also used : RepositoryObject(org.structr.net.repository.RepositoryObject) DefaultRepositoryObject(org.structr.net.repository.DefaultRepositoryObject) Inventory(org.structr.net.protocol.Inventory)

Aggregations

Inventory (org.structr.net.protocol.Inventory)1 DefaultRepositoryObject (org.structr.net.repository.DefaultRepositoryObject)1 RepositoryObject (org.structr.net.repository.RepositoryObject)1