当前位置: 首页>>代码示例>>Java>>正文


Java Number160.ZERO属性代码示例

本文整理汇总了Java中net.tomp2p.peers.Number160.ZERO属性的典型用法代码示例。如果您正苦于以下问题:Java Number160.ZERO属性的具体用法?Java Number160.ZERO怎么用?Java Number160.ZERO使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在net.tomp2p.peers.Number160的用法示例。


在下文中一共展示了Number160.ZERO属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setup

@Before
public void setup() {
    //setup logging to console
    //org.apache.log4j.BasicConfigurator.configure();


    try {
        //initialize network
        peers = createAndAttachPeersDHT(nr, port);
        bootstrap(peers);

        //initialize controller with a peer
        controller = new TreeController(peers[local]);


        //create a root node
        Directory rootDir = new Directory(Number160.ZERO, rootName);
        //upload root into DHT
        Data data = new Data(rootDir);
        FutureDHT futureDHT = peers[3].put(Number160.ZERO).data(data).start();
        futureDHT.awaitUninterruptibly();
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
开发者ID:lisgie,项目名称:ChallengeTask_Group2,代码行数:26,代码来源:TreeControllerTest.java

示例2: startClientNAT

public static void startClientNAT( String ip )
    throws Exception
{
    Random r = new Random( 43L );
    Peer peer = new PeerMaker( new Number160( r ) ).setPorts( 4000 ).makeAndListen();
    peer.getConfiguration().setBehindFirewall( true );
    PeerAddress pa = new PeerAddress( Number160.ZERO, InetAddress.getByName( ip ), 4000, 4000 );
    FutureDiscover fd = peer.discover().setPeerAddress( pa ).start();
    fd.awaitUninterruptibly();
    if ( fd.isSuccess() )
    {
        System.out.println( "found that my outside address is " + fd.getPeerAddress() );
    }
    else
    {
        System.out.println( "failed " + fd.getFailedReason() );
    }
    peer.halt();
}
 
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:19,代码来源:ExampleNAT.java

示例3: routing

public static void routing(Number160 key, Peer[] peers, int start) {
    System.out.println("routing: searching for key " + key);
    NavigableSet<PeerAddress> pa1 = new TreeSet<PeerAddress>(PeerMap.createComparator(key));
    NavigableSet<PeerAddress> queried = new TreeSet<PeerAddress>(PeerMap.createComparator(key));
    Number160 result = Number160.ZERO;
    Number160 resultPeer = new Number160("0xd75d1a3d57841fbc9e2a3d175d6a35dc2e15b9f");
    int round = 0;
    while (!resultPeer.equals(result)) {
        System.out.println("round " + round);
        round++;
        pa1.addAll(peers[start].getPeerBean().peerMap().getAll());
        queried.add(peers[start].getPeerAddress());
        System.out.println("closest so far: " + queried.first());
        PeerAddress next = pa1.pollFirst();
        while (queried.contains(next)) {
            next = pa1.pollFirst();
        }
        result = next.getPeerId();
        start = findNr(next.getPeerId().toString(), peers);
    }
}
 
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:21,代码来源:Utils2.java

示例4: createRoot

private static void createRoot() throws IOException {
    //create a root node
    Directory rootDir = new Directory(Number160.ZERO, "root");
    //upload root into DHT
    Data data = new Data(rootDir);
    FutureDHT futureDHT = peerDHT.put(Number160.ZERO).data(data).start();
    futureDHT.awaitUninterruptibly();
}
 
开发者ID:lisgie,项目名称:ChallengeTask_Group2,代码行数:8,代码来源:FSPeer.java

示例5: startClient

public static void startClient(String ipAddress, int port) throws Exception {
    Random rnd = new Random();
    Bindings b = new Bindings().addProtocol(StandardProtocolFamily.INET).addAddress(InetAddress.getByName("127.0.0.1"));

    peerDHT = new PeerBuilderDHT(new PeerBuilder(new Number160(rnd)).ports(port).start()).start();
   // new IndirectReplication(peerDHT).replicationFactor(3).start();
    System.out.println("Client started and Listening to: " + DiscoverNetworks.discoverInterfaces(b));
    System.out.println("address visible to outside is " + peerDHT.peerAddress());

    InetAddress address = Inet4Address.getByName(ipAddress);

    int masterPort = 4000;
    PeerAddress pa = new PeerAddress(Number160.ZERO, address, masterPort, masterPort);

    System.out.println("PeerAddress: " + pa);

    // Future Discover
    FutureDiscover futureDiscover = peerDHT.peer().discover().inetAddress(address).ports(masterPort).start();
    futureDiscover.awaitUninterruptibly();

    // Future Bootstrap - slave
    FutureBootstrap futureBootstrap = peerDHT.peer().bootstrap().inetAddress(address).ports(masterPort).start();
    futureBootstrap.awaitUninterruptibly();

    Collection<PeerAddress> addressList = peerDHT.peerBean().peerMap().all();
    System.out.println(addressList.size());

    if (futureDiscover.isSuccess()) {
        System.out.println("found that my outside address is " + futureDiscover.peerAddress());
    } else {
        System.err.println("failed " + futureDiscover.failedReason());
        //throw new P2PException("can not connect");
    }
}
 
开发者ID:lisgie,项目名称:ChallengeTask_Group2,代码行数:34,代码来源:FSPeer.java

示例6: process

/**
 * Calculates the digest.
 */
private void process() {
    Number160 hashKey = Number160.ZERO;
    Number160 hashContent = Number160.ZERO;
    for (Map.Entry<Number480, Number160> entry : mapDigests.entrySet()) {
        hashKey = hashKey.xor(entry.getKey().getLocationKey());
        hashKey = hashKey.xor(entry.getKey().getDomainKey());
        hashKey = hashKey.xor(entry.getKey().getContentKey());
        hashContent = hashContent.xor(entry.getValue());
    }
    keyDigest = hashKey;
    contentDigest = hashContent;
}
 
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:15,代码来源:DigestInfo.java

示例7: start

public FutureRemove start() {

        preBuild("remove-builder");
        if (all) {
            contentKeys = null;
        } else if (contentKeys == null && !all) {
            contentKeys = new ArrayList<Number160>(1);
            if (contentKey == null) {
                contentKey = Number160.ZERO;
            }
            contentKeys.add(contentKey);
        }

        return peer.getDistributedHashMap().remove(this);
    }
 
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:15,代码来源:RemoveBuilder.java

示例8: sendPingTCP

/**
 * Test regular ping.
 * 
 * @throws InterruptedException .
 * 
 * @throws IOException .
 */
@Ignore
@Test
public void sendPingTCP() throws IOException, InterruptedException {
    Peer sender = null;
    ChannelCreator cc = null;
    try {
        PeerAddress pa = new PeerAddress(Number160.ZERO, Inet4Address.getByName(IP), PORT, PORT);
        sender = new PeerMaker(new Number160("0x9876")).ports(PORT).setEnableMaintenance(false)
                .makeAndListen();
        PingRPC handshake = new PingRPC(sender.getPeerBean(), sender.getConnectionBean());
        FutureChannelCreator fcc = sender.getConnectionBean().reservation().create(0, 1);
        fcc.awaitUninterruptibly();
        cc = fcc.getChannelCreator();
        FutureResponse fr = handshake.pingTCP(pa, cc, new DefaultConnectionConfiguration());
        fr.awaitUninterruptibly();
        Assert.assertEquals(true, fr.isSuccess());
        Thread.sleep(WAIT);
    } finally {
        if (cc != null) {
            cc.shutdown().await();
        }
        if (sender != null) {
            sender.shutdown().await();
        }
    }
}
 
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:33,代码来源:TestRealPing.java

示例9: sendPingTCPDiscover

/**
 * Test discover ping.
 * 
 * @throws InterruptedException .
 * 
 * @throws IOException .
 */
@Ignore
@Test
public void sendPingTCPDiscover() throws IOException, InterruptedException {
    Peer sender = null;
    ChannelCreator cc = null;
    try {
        PeerAddress pa = new PeerAddress(Number160.ZERO, Inet4Address.getByName(IP), PORT, PORT);
        sender = new PeerMaker(new Number160("0x9876")).ports(PORT).setEnableMaintenance(false)
                .makeAndListen();
        PingRPC handshake = new PingRPC(sender.getPeerBean(), sender.getConnectionBean());
        FutureChannelCreator fcc = sender.getConnectionBean().reservation().create(0, 1);
        fcc.awaitUninterruptibly();
        cc = fcc.getChannelCreator();
        FutureResponse fr = handshake.pingTCPDiscover(pa, cc, new DefaultConnectionConfiguration());
        fr.awaitUninterruptibly();
        Assert.assertEquals(true, fr.isSuccess());
        Thread.sleep(WAIT);
    } finally {
        if (cc != null) {
            cc.shutdown().await();
        }
        if (sender != null) {
            sender.shutdown().await();
        }
    }
}
 
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:33,代码来源:TestRealPing.java

示例10: sendPingTCPProbe

/**
 * Test probe ping.
 * 
 * @throws InterruptedException .
 * 
 * @throws IOException .
 */
@Ignore
@Test
public void sendPingTCPProbe() throws IOException, InterruptedException {
    Peer sender = null;
    ChannelCreator cc = null;
    try {
        PeerAddress pa = new PeerAddress(Number160.ZERO, Inet4Address.getByName(IP), PORT, PORT);
        sender = new PeerMaker(new Number160("0x9876")).ports(PORT).setEnableMaintenance(false)
                .makeAndListen();
        PingRPC handshake = new PingRPC(sender.getPeerBean(), sender.getConnectionBean());
        FutureChannelCreator fcc = sender.getConnectionBean().reservation().create(0, 1);
        fcc.awaitUninterruptibly();
        cc = fcc.getChannelCreator();
        FutureResponse fr = handshake.pingTCPProbe(pa, cc, new DefaultConnectionConfiguration());
        fr.awaitUninterruptibly();
        Assert.assertEquals(true, fr.isSuccess());
        Thread.sleep(WAIT);
    } finally {
        if (cc != null) {
            cc.shutdown().await();
        }
        if (sender != null) {
            sender.shutdown().await();
        }
    }
}
 
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:33,代码来源:TestRealPing.java

示例11: startClient

/**
 * Starts the client peer.
 * 
 * @throws IOException
 *             PeerMaker may throw and IOException
 * @throws ClassNotFoundException
 *             If the data object contained a class we did not expect
 * @throws InterruptedException .
 */
@Test
@Ignore
public void startClient() throws IOException, ClassNotFoundException, InterruptedException {
    Peer myPeer = new PeerMaker(Number160.createHash("client peer")).setBehindFirewall(true).
            ports(port).setEnableMaintenance(false).makeAndListen();
    PeerAddress bootstrapServerPeerAddress = new PeerAddress(Number160.ZERO, new InetSocketAddress(
            InetAddress.getByName(ipSuperPeer), port));

    FutureDiscover discovery = myPeer.discover().setPeerAddress(bootstrapServerPeerAddress).start();
    discovery.awaitUninterruptibly();
    if (!discovery.isSuccess()) {
        System.err.println("no success!");
    }
    System.err.println("Peer: " + discovery.getReporter() + " told us about our address.");
    InetSocketAddress myInetSocketAddress = new InetSocketAddress(myPeer.getPeerAddress().getInetAddress(), port);

    bootstrapServerPeerAddress = discovery.getReporter();
    FutureBootstrap bootstrap = myPeer.bootstrap().setPeerAddress(bootstrapServerPeerAddress).start();
    bootstrap.awaitUninterruptibly();

    if (!bootstrap.isSuccess()) {
        System.err.println("no success!");
    }

    FuturePut putFuture = myPeer.put(Number160.createHash("key")).setData(new Data(myInetSocketAddress)).start();
    putFuture.awaitUninterruptibly();
    FutureGet futureDHT = myPeer.get(Number160.createHash("key")).start();
    futureDHT.awaitUninterruptibly();
    futureDHT.getFutureRequests().awaitUninterruptibly();
    Data data = futureDHT.getData();
    if (data == null) {
        throw new RuntimeException("Address not available in DHT.");
    }
    InetSocketAddress inetSocketAddress = (InetSocketAddress) data.object();
    System.err.println("returned " + inetSocketAddress);
    myPeer.shutdown();
    // Thread.sleep( Long.MAX_VALUE );
}
 
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:47,代码来源:TestRealNetwork.java

示例12: testCache

@Test
public void testCache() {
    SimpleCache<Directory> cache = new SimpleCache<>(1);

    Directory dir = new Directory(Number160.ZERO, "test");

    assertEquals(null, cache.get("/test"));

    cache.put("/test", dir);


    System.out.println(cache.get("/test").getEntryName());

    dir.setEntryName("lalalalalal refereeeence");
    System.out.println(cache.get("/test").getEntryName());

    Directory lala = cache.get("/test");

    lala.setEntryName("kajshbdfkjashbdfk");

    System.out.println(cache.get("/test").getEntryName());

    assertEquals(dir, cache.get("/test"));

}
 
开发者ID:lisgie,项目名称:ChallengeTask_Group2,代码行数:25,代码来源:SimpleCacheTest.java

示例13: listen

public void listen(String ipAddress) throws Exception
{
    this.serverAddress = ipAddress;

    // TODO: Listen to Master Peer for new data and do stuff
    this.peer = new PeerMaker(new Number160(new Random(43L))).makeAndListen();
    PeerAddress supernode = new PeerAddress(Number160.ZERO, InetAddress.getByName(ipAddress), serverPort, serverPort);
    FutureDiscover fd = peer.discover().setPeerAddress(supernode).start();
    fd.awaitUninterruptibly();

    if (fd.isSuccess()) {
        //FutureBootstrap fb = peer.bootstrap().setPeerAddress(supernode).start();
        //fb.awaitUninterruptibly();

        System.out.println("Bootstrap complete (" + peer.getPeerAddress() + "). Waiting for work...");
    } else {
        System.out.println("Discover failed: " + fd.getFailedReason());

        return;
    }

    // Setup request handler
    peer.setObjectDataReply(new ObjectDataReply() {
        @Override
        public Object reply(PeerAddress sender, Object request) throws Exception
        {
            System.out.println("Received task from network. Looking for song...");

            String[] rData = (String[])request;
            
            if (previousTasks.contains(rData[0])) {
                System.out.println("Had this request before. Dropping it...");
                return null;
            } else {
                previousTasks.add(rData[0]);
                // Trim it
                if (previousTasks.size() > 100)
                    previousTasks.remove();
            }
            
            findSong(rData[0], rData[1]);

            // We don't care about the return
            return null;
        }
    });
}
 
开发者ID:SH4DY,项目名称:swazam,代码行数:47,代码来源:PeerConnector.java

示例14: getFromToTest1

@Test
public void getFromToTest1() throws IOException, ClassNotFoundException, InterruptedException {
	PeerDHT p1 = new PeerBuilderDHT(new PeerBuilder(Number160.createHash(1)).ports(4838).start()).start();
	PeerDHT p2 = new PeerBuilderDHT(new PeerBuilder(Number160.createHash(2)).masterPeer(p1.peer()).start()).start();

	p2.peer().bootstrap().peerAddress(p1.peerAddress()).start().awaitUninterruptibly();
	p1.peer().bootstrap().peerAddress(p2.peerAddress()).start().awaitUninterruptibly();

	Number160 locationKey = Number160.createHash("location");
	Number160 contentKey = Number160.createHash("content");

	try {
		List<H2HTestData> contents = new ArrayList<H2HTestData>();
		int numberOfContent = 3;
		for (int i = 0; i < numberOfContent; i++) {
			H2HTestData data = new H2HTestData(randomString());
			contents.add(data);

			Data object = new Data(data);
			if (i == 0) {
				object.addBasedOn(Number160.ZERO);
			} else {
				object.addBasedOn(contents.get(i - 1).getVersionKey());
			}
			p2.put(locationKey).data(contentKey, object).versionKey(new Number160(i)).start().awaitUninterruptibly();
		}

		// get the last version
		Number640 from = new Number640(locationKey, Number160.ZERO, contentKey, Number160.ZERO);
		Number640 to = new Number640(locationKey, Number160.ZERO, contentKey, Number160.MAX_VALUE);
		System.err.println("from: " + from);
		System.err.println("to:   " + to);
		FutureGet future = p1.get(locationKey).from(from).to(to).descending().returnNr(1).start();
		future.awaitUninterruptibly();

		assertEquals(contents.get(numberOfContent - 1).getTestString(),
				((H2HTestData) future.data().object()).getTestString());
	} finally {
		p1.shutdown().awaitUninterruptibly();
		p2.shutdown().awaitUninterruptibly();
	}
}
 
开发者ID:Hive2Hive,项目名称:Hive2Hive,代码行数:42,代码来源:FromToTest.java

示例15: testTTLDecrement

@Test
public void testTTLDecrement() throws IOException, ClassNotFoundException, NoSuchAlgorithmException,
		InvalidKeyException, SignatureException, InterruptedException {
	KeyPairGenerator gen = KeyPairGenerator.getInstance("DSA");

	KeyPair keyPairPeer1 = gen.generateKeyPair();
	PeerDHT p1 = new PeerBuilderDHT(new PeerBuilder(Number160.createHash(1)).ports(5000).keyPair(keyPairPeer1).start())
			.storage(new StorageMemory(100)).start();
	KeyPair keyPairPeer2 = gen.generateKeyPair();
	PeerDHT p2 = new PeerBuilderDHT(new PeerBuilder(Number160.createHash(2)).masterPeer(p1.peer()).keyPair(keyPairPeer2)
			.start()).storage(new StorageMemory(100)).start();

	p2.peer().bootstrap().peerAddress(p1.peerAddress()).start().awaitUninterruptibly();
	p1.peer().bootstrap().peerAddress(p2.peerAddress()).start().awaitUninterruptibly();

	KeyPair keyPair1 = gen.generateKeyPair();

	Number160 lKey = Number160.createHash("location");
	Number160 dKey = Number160.createHash("domain");
	Number160 cKey = Number160.createHash("content");
	Number160 vKey = Number160.createHash("version");
	Number160 bKey = Number160.ZERO;

	int ttl = 3;

	String testData = "data";
	Data data = new Data(testData).protectEntry(keyPair1);
	data.ttlSeconds(ttl).addBasedOn(bKey);

	try {
		// initial put
		FuturePut futurePut = p1.put(lKey).domainKey(dKey).data(cKey, data).versionKey(vKey).keyPair(keyPair1).start();
		futurePut.awaitUninterruptibly();
		Assert.assertTrue(futurePut.isSuccess());

		// wait a moment, so that the ttl decrements
		Thread.sleep(2000);

		// check decrement of ttl through a normal get
		FutureGet futureGet = p1.get(lKey).domainKey(dKey).contentKey(cKey).versionKey(vKey).start();
		futureGet.awaitUninterruptibly();
		Assert.assertTrue(futureGet.isSuccess());
		Assert.assertTrue(ttl > futureGet.data().ttlSeconds());

		// check decrement of ttl through a get meta
		FutureDigest futureDigest = p1.digest(lKey).domainKey(dKey).contentKey(cKey).versionKey(vKey).returnMetaValues()
				.start();
		futureDigest.awaitUninterruptibly();
		Assert.assertTrue(futureDigest.isSuccess());
		Data dataMeta = futureDigest.digest().dataMap().values().iterator().next();
		Assert.assertTrue(ttl > dataMeta.ttlSeconds());

		// wait again a moment, till data gets expired
		Thread.sleep(2000);

		// check if data has been removed
		Data retData = p2.get(lKey).domainKey(dKey).contentKey(cKey).versionKey(vKey).start().awaitUninterruptibly()
				.data();
		Assert.assertNull(retData);
	} finally {
		p1.shutdown().awaitUninterruptibly();
		p2.shutdown().awaitUninterruptibly();
	}
}
 
开发者ID:Hive2Hive,项目名称:Hive2Hive,代码行数:64,代码来源:TTLTest.java


注:本文中的net.tomp2p.peers.Number160.ZERO属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。