Package net.tomp2p.dht

Examples of net.tomp2p.dht.FutureGet


        FuturePut futurePut = peers[peerStore1].put(key1).requestP2PConfiguration(REQUEST_3)
                .data(new Data("Test 2")).start();
        futurePut.awaitUninterruptibly();
        System.out.println("stored [Test 2] on " + futurePut.rawResult().keySet());

        FutureGet futureGet = peers[peerGet].get(key1).all().start();
        futureGet.awaitUninterruptibly();
        System.out.println("peer[" + peerGet + "] got [" + futureGet.data().object() + "] should be [Test 2]");
        // peer 11 and 8 joins again
        peers[peerOffline1] = new PeerBuilderDHT(new PeerBuilder(peers[peerOffline1].peerID()).masterPeer(peers[0].peer()).start()).start();
        peers[peerOffline2] = new PeerBuilderDHT(new PeerBuilder(peers[peerOffline2].peerID()).masterPeer(peers[0].peer()).start()).start();
        peers[peerOffline3] = new PeerBuilderDHT(new PeerBuilder(peers[peerOffline3].peerID()).masterPeer(peers[0].peer()).start()).start();
        peers[peerOffline1].peer().bootstrap().peerAddress(peers[0].peerAddress()).start().awaitUninterruptibly();
        peers[peerOffline2].peer().bootstrap().peerAddress(peers[0].peerAddress()).start().awaitUninterruptibly();
        peers[peerOffline3].peer().bootstrap().peerAddress(peers[0].peerAddress()).start().awaitUninterruptibly();
        // load old data
        System.out.println("The 3 peers are now onlyne again, with the old data");
        Number640 key = new Number640(key1, Number160.ZERO, Number160.ZERO, Number160.ZERO);
        peers[peerOffline1].storageLayer()
                .put(key, new Data("Test 1"), null, false, false);
        peers[peerOffline2].storageLayer()
                .put(key, new Data("Test 1"), null, false, false);
        peers[peerOffline3].storageLayer()
                .put(key, new Data("Test 1"), null, false, false);
        // we got Test 1
        FutureGet futureGet2 = peers[0].get(key1).requestP2PConfiguration(REQUEST_3).all().start();
        futureGet2.awaitUninterruptibly();
        System.out.println("peer[0] got [" + futureGet2.data().object() + "] should be [Test 2]");
        // we got Test 1!
        FutureGet futureGet3 = peers[peerGet].get(key1).requestP2PConfiguration(REQUEST_3).all().start();
        futureGet3.awaitUninterruptibly();
        System.out.println("peer[" + peerGet + "] got [" + futureGet3.data().object() + "] should be [Test 2]");
    }
View Full Code Here


       
        //wait for mainenance pings
        Thread.sleep(3000);
       
        // we got attack!
        FutureGet futureGet = peers[0].get(key1).all().requestP2PConfiguration(REQUEST_3).start();
        futureGet.awaitUninterruptibly();
        System.out.println("peer[0] got " + futureGet.data().object());
        for (Entry<PeerAddress, Map<Number640, Data>> entry : futureGet.rawData().entrySet()) {
            System.out.print("got from (3)" + entry.getKey());
            System.out.println(entry.getValue());
        }
        // increase the replicas we fetch
        FutureGet futureGet1 = peers[0].get(key1).all().requestP2PConfiguration(REQUEST_6).start();
        futureGet1.awaitUninterruptibly();
        System.out.println("peer[0] got " + futureGet1.data().object());

        // countermeasure - statistics, pick not closest, but random peer that has the data - freshness vs. load
        // also, check distances!
        Statistics statistics = new Statistics(peers[0].peerBean().peerMap());
        System.out.println("average distance: "+statistics.avgGap());
        for (Entry<PeerAddress, Map<Number640, Data>> entry : futureGet1.rawData().entrySet()) {
            System.out.print("got from (6)" + entry.getKey());
            System.out.print(" distance: "+key1.xor(entry.getKey().peerId()).doubleValue());
            System.out.println(" "+entry.getValue());
        }
    }
View Full Code Here

    private static void examplePutGet(final PeerDHT[] peers, final Number160 nr)
            throws IOException, ClassNotFoundException {
        FuturePut futurePut = peers[PEER_NR_1].put(nr).data(new Data("hallo")).start();
        futurePut.awaitUninterruptibly();
        System.out.println("peer " + PEER_NR_1 + " stored [key: " + nr + ", value: \"hallo\"]");
        FutureGet futureGet = peers[PEER_NR_2].get(nr).start();
        futureGet.awaitUninterruptibly();
        System.out.println("peer " + PEER_NR_2 + " got: \"" + futureGet.data().object() + "\" for the key " + nr);
        // the output should look like this:
        // peer 30 stored [key: 0xba419d350dfe8af7aee7bbe10c45c0284f083ce4, value: "hallo"]
        // peer 77 got: "hallo" for the key 0xba419d350dfe8af7aee7bbe10c45c0284f083ce4
    }
View Full Code Here

        FuturePut futurePut =
            peers[30].put( nr ).data( new Number160( 11 ), new Data( "hallo" ) ).domainKey( Number160.createHash( "my_domain" ) ).start();
        futurePut.awaitUninterruptibly();
        System.out.println( "peer 30 stored [key: " + nr + ", value: \"hallo\"]" );
        // this will fail, since we did not specify the domain
        FutureGet futureGet = peers[77].get( nr ).all().start();
        futureGet.awaitUninterruptibly();
        System.out.println( "peer 77 got: \"" + futureGet.data() + "\" for the key " + nr );
        // this will succeed, since we specify the domain
        futureGet =
            peers[77].get( nr ).all().domainKey( Number160.createHash( "my_domain" ) ).start().awaitUninterruptibly();
        System.out.println( "peer 77 got: \"" + futureGet.data().object() + "\" for the key " + nr );
        // the output should look like this:
        // peer 30 stored [key: 0x8992a603029824e810fd7416d729ef2eb9ad3cfc, value: "hallo"]
        // peer 77 got: "hallo" for the key 0x8992a603029824e810fd7416d729ef2eb9ad3cfc
    }
View Full Code Here

        futurePut.awaitUninterruptibly();
        System.out.println( "added: " + toStore1 + " (" + futurePut.isSuccess() + ")" );
        futurePut = peers[50].add( nr ).data( data2 ).start();
        futurePut.awaitUninterruptibly();
        System.out.println( "added: " + toStore2 + " (" + futurePut.isSuccess() + ")" );
        FutureGet futureGet = peers[77].get( nr ).all().start();
        futureGet.awaitUninterruptibly();
        System.out.println( "size" + futureGet.dataMap().size() );
        Iterator<Data> iterator = futureGet.dataMap().values().iterator();
        System.out.println( "got: " + iterator.next().object() + " (" + futureGet.isSuccess() + ")" );
        System.out.println( "got: " + iterator.next().object() + " (" + futureGet.isSuccess() + ")" );
    }
View Full Code Here

     * @throws ClassNotFoundException .
     * @throws IOException .
     */
    private static void exampleGetBlocking(final PeerDHT[] peers, final Number160 nr)
        throws ClassNotFoundException, IOException {
        FutureGet futureGet = peers[PEER_NR_2].get(nr).start();
        // blocking operation
        futureGet.awaitUninterruptibly();
        System.out.println("result blocking: " + futureGet.data().object());
        System.out.println("this may *not* happen before printing the result");
    }
View Full Code Here

     * Example of a non-blocking operation and what happens after.
     * @param peers The peers in this P2P network
     * @param nr The number where the data is stored
     */
    private static void exampleGetNonBlocking(final PeerDHT[] peers, final Number160 nr) {
        FutureGet futureGet = peers[PEER_NR_2].get(nr).start();
        // non-blocking operation
        futureGet.addListener(new BaseFutureAdapter<FutureGet>() {
          @Override
      public void operationComplete(FutureGet future) throws Exception {
            System.out.println("result non-blocking: " + future.data().object());
            }
           
View Full Code Here

        Number160 key = Number160.createHash(TERM);

        FuturePut futurePut = peers[peer60].put(key).object(TERM).start();
        futurePut.awaitUninterruptibly();

        FutureGet futureGet = peers[peer30].get(key).start();
        futureGet.awaitUninterruptibly();

        System.out.println("got: " + key + " = " + futureGet.data().object());

    }
View Full Code Here

        // search for a keyword
        Number160 termKey = findReference(peers[peer20], "Communication");
        // this will return a reference to the term stored in the method exampleSearch(), next, we have to search for
        // that.
        FutureGet futureGet = peers[peer10].get(termKey).start();
        futureGet.awaitUninterruptibly();
        System.out.println("searched for [Communication], found " + futureGet.data().object());
    }
View Full Code Here

     * @throws IOException .
     */
    private static Number160 findReference(final PeerDHT peer, final String keyword) throws ClassNotFoundException,
            IOException {
        Number160 keyKeyword = Number160.createHash(keyword);
        FutureGet futureGet = peer.get(keyKeyword).start();
        futureGet.awaitUninterruptibly();
        Number160 termKey = (Number160) futureGet.data().object();
        return termKey;
    }
View Full Code Here

TOP

Related Classes of net.tomp2p.dht.FutureGet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.