PeerDHT peer3 = new PeerBuilderDHT(new PeerBuilder( pair3 ).ports( 4003 ).start()).start();
PeerDHT[] peers = new PeerDHT[] { peer1, peer2, peer3 };
ExampleUtils.bootstrap( peers );
setProtection( peers, ProtectionEnable.NONE, ProtectionMode.MASTER_PUBLIC_KEY );
// peer 1 stores "test" in the domain key of owner peer 2
FuturePut futurePut =
peer1.put( Number160.ONE ).data( new Data( "test" ) ).protectDomain().domainKey( peer2Owner ).start();
futurePut.awaitUninterruptibly();
// peer 2 did not claim this domain, so we stored it
System.out.println( "stored: " + futurePut.isSuccess()
+ " -> because no one can claim domains except the owner, storage ok but no protection" );
// peer 3 want to store something
futurePut =
peer3.put( Number160.ONE ).data( new Data( "hello" ) ).protectDomain().domainKey( peer2Owner ).start();
futurePut.awaitUninterruptibly();
System.out.println( "stored: " + futurePut.isSuccess()
+ " -> because no one can claim domains except the owner, storage ok but no protection" );
// peer 2 claims this domain
futurePut =
peer2.put( Number160.ONE ).data( new Data( "MINE!" ) ).protectDomain().domainKey( peer2Owner ).start();
futurePut.awaitUninterruptibly();
System.out.println( "stored: " + futurePut.isSuccess() + " -> becaues peer2 is the owner" );
// get the data!
FutureGet futureGet = peer1.get( Number160.ONE ).domainKey( peer2Owner ).start();
futureGet.awaitUninterruptibly();
System.out.println( "we got " + futureGet.data().object() );
futurePut = peer3.put( Number160.ONE ).domainKey( peer2Owner ).data( new Data( "hello" ) ).start();
futurePut.awaitUninterruptibly();
System.out.println( "stored: " + futurePut.isSuccess() + " -> because this domain is claimed by peer2" );
shutdown( peers );
}