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


Java Peer类代码示例

本文整理汇总了Java中net.tomp2p.p2p.Peer的典型用法代码示例。如果您正苦于以下问题:Java Peer类的具体用法?Java Peer怎么用?Java Peer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: createPeer

import net.tomp2p.p2p.Peer; //导入依赖的package包/类
public static Peer createPeer(int port){
    KeyPairGenerator generator = null;
    try {
        generator = KeyPairGenerator.getInstance("RSA");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    assert generator != null;
    KeyPair keyPair = generator.generateKeyPair();

    try {
        return new PeerMaker(keyPair).setPorts(port).makeAndListen();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:GDCN,项目名称:GDCN,代码行数:18,代码来源:DeceitfulNetworkUtils.java

示例2: bootstrap

import net.tomp2p.p2p.Peer; //导入依赖的package包/类
public static void bootstrap(final Peer peer, String address, final int port, final OnReplyCommand finished){
    try {
        final InetAddress inetAddress = InetAddress.getByName(address);

        DiscoverBuilder discoverBuilder = peer.discover().setInetAddress(inetAddress).setPorts(port);
        discoverBuilder.start().addListener(new BaseFutureAdapter<FutureDiscover>() {
            @Override
            public void operationComplete(FutureDiscover future) throws Exception {
                if (!future.isSuccess()) {
                    System.out.println("Bootstrap insuccessful");
                    finished.execute(null);
                    return;
                }

                finished.execute(future.getReporter());
            }
        });
    } catch (UnknownHostException e) {
        e.printStackTrace();
    }
}
 
开发者ID:GDCN,项目名称:GDCN,代码行数:22,代码来源:DeceitfulNetworkUtils.java

示例3: createAndAttachNodes

import net.tomp2p.p2p.Peer; //导入依赖的package包/类
/**
 * Create peers with a port and attach it to the first peer in the array.
 * 
 * @param nr The number of peers to be created
 * @param port The port that all the peer listens to. The multiplexing is done via the peer Id
 * @return The created peers
 * @throws IOException IOException
 */
public static Peer[] createAndAttachNodes( int nr, int port ) throws IOException
{
    Peer[] peers = new Peer[nr];
    for ( int i = 0; i < nr; i++ )
    {
        if ( i == 0 )
        {
            peers[0] = new PeerMaker( new Number160( RND ) ).setPorts( port ).makeAndListen();
        }
        else
        {
            peers[i] = new PeerMaker( new Number160( RND ) ).setMasterPeer( peers[0] ).makeAndListen();
        }
    }
    return peers;
}
 
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:25,代码来源:ExampleUtils.java

示例4: main

import net.tomp2p.p2p.Peer; //导入依赖的package包/类
/**
 * Start the examples.
 * 
 * @param args
 *            Empty
 * @throws Exception .
 */
public static void main(final String[] args) throws Exception {
    Peer[] peers = null;
    try {
        final int peerNr = 100;
        final int port = 4001;
        peers = ExampleUtils.createAndAttachNodes(peerNr, port);
        ExampleUtils.bootstrap(peers);
        MyPeer[] myPeers = wrap(peers);
        example(myPeers);
    } finally {
        // 0 is the master
        if (peers != null && peers[0] != null) {
            peers[0].halt();
        }
    }
}
 
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:24,代码来源:ExampleDHT.java

示例5: main

import net.tomp2p.p2p.Peer; //导入依赖的package包/类
/**
 * Start the examples.
 * 
 * @param args
 *            Empty
 * @throws Exception .
 */
public static void main(final String[] args) throws Exception {
    final int peerNr = 100;
    final int port = 4001;
    Peer[] peers = null;
    try {
        peers = ExampleUtils.createAndAttachNodes(peerNr, port);
        ExampleUtils.bootstrap(peers);

        exampleDST(peers);
    } finally {
        // 0 is the master
        if (peers != null && peers[0] != null) {
            peers[0].halt();
        }
    }
}
 
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:24,代码来源:ExampleDST.java

示例6: main

import net.tomp2p.p2p.Peer; //导入依赖的package包/类
/**
 * Starts to run the examples.
 * @param args No arguments necessary
 * @throws Exception .
 */
public static void main(final String[] args) throws Exception {
    Peer master = null;
    final int nrPeers = 100;
    final int port = 4001;
    final int waitingTime = 250;
    try {
        Peer[] peers = ExampleUtils.createAndAttachNodes(nrPeers, port);
        ExampleUtils.bootstrap(peers);
        master = peers[0];
        Number160 nr = new Number160(RND);
        examplePutGet(peers, nr);
        examplePutGetConfig(peers, nr);
        exampleGetBlocking(peers, nr);
        exampleGetNonBlocking(peers, nr);
        Thread.sleep(waitingTime);
        exampleAddGet(peers);
    } finally {
        if (master != null) {
            master.halt();
        }
    }
}
 
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:28,代码来源:ExamplePutGet.java

示例7: main

import net.tomp2p.p2p.Peer; //导入依赖的package包/类
/**
 * Start the examples.
 * 
 * @param args
 *            Empty
 * @throws Exception .
 */
public static void main(final String[] args) throws Exception {
    Peer master = null;
    try {
        final int peerNr = 100;
        final int port = 4001;
        Peer[] peers = ExampleUtils.createAndAttachNodes(peerNr, port);
        master = peers[0];
        ExampleUtils.bootstrap(peers);
        exampleMultiColumn(peers);
    } finally {
        if (master != null) {
            master.halt();
        }
    }
}
 
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:23,代码来源:ExampleMultiColumn.java

示例8: routing

import net.tomp2p.p2p.Peer; //导入依赖的package包/类
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,代码行数:22,代码来源:Utils2.java

示例9: main

import net.tomp2p.p2p.Peer; //导入依赖的package包/类
/**
 * Start the examples.
 * 
 * @param args
 *            Empty
 * @throws Exception .
 */
public static void main(final String[] args) throws Exception {
    final int peerNr = 100;
    final int port = 4001;
    bloomFilterBasics();
    Peer[] peers = null;
    try {
        peers = ExampleUtils.createAndAttachNodes(peerNr, port);
        ExampleUtils.bootstrap(peers);
        exampleBloomFilter(peers);
    } finally {
        // 0 is the master
        if (peers != null && peers[0] != null) {
            peers[0].halt();
        }
    }
}
 
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:24,代码来源:ExampleBloomFilter.java

示例10: main

import net.tomp2p.p2p.Peer; //导入依赖的package包/类
/**
 * Create 100 peers and start the map reduce example.
 * 
 * @param args
 *            Empty
 * @throws Exception .
 */
public static void main(final String[] args) throws Exception {
    Peer master = null;
    try {
        final int peerNr = 100;
        final int port = 4001;
        Peer[] peers = ExampleUtils.createAndAttachNodes(peerNr, port);
        master = peers[0];
        ExampleUtils.bootstrap(peers);
        exampleMapReduce(peers);
    } finally {
        if (master != null) {
            master.halt();
        }
    }
}
 
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:23,代码来源:ExampleMapReduce.java

示例11: startSender

import net.tomp2p.p2p.Peer; //导入依赖的package包/类
/**
 * Start the sender and wait forever.
 * 
 * @throws InterruptedException .
 * @throws IOException .
 */
@Test
public void startSender() throws IOException, InterruptedException {

    final int maxPeers = 10;
    Peer[] peers = createPeers(PORT, maxPeers, "sender");
    for (Peer peer : peers) {
        peer.bootstrap().setInetAddress(InetAddress.getByName(ADDR)).setPorts(PORT).start().awaitUninterruptibly();
        peer.setObjectDataReply(new ObjectDataReply() {
            @Override
            public Object reply(final PeerAddress sender, final Object request) throws Exception {
                System.out.println("wrong!!!!");
                return "wrong!!!!";
            }
        });
    }
    Number160 keyForID = Number160.createHash("key");
    Msg message = new Msg();

    System.out.println(String.format("Sending message '%s' to key '%s' converted to '%s'", message.getType(),
            "key", keyForID.toString()));
    FutureDirect futureDHT = peers[0].send(keyForID).setObject(message).setRequestP2PConfiguration(REQ).start();
    futureDHT.awaitUninterruptibly();
    System.out.println("got: " + futureDHT.getObject());
    Thread.sleep(Long.MAX_VALUE);
}
 
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:32,代码来源:TestSend.java

示例12: main

import net.tomp2p.p2p.Peer; //导入依赖的package包/类
public static void main( String[] args )
    throws Exception
{
    Peer master = null;
    try
    {
        Peer[] peers = ExampleUtils.createAndAttachNodes( 100, 4001 );
        ExampleUtils.bootstrap( peers );
        master = peers[0];
        setupReplyHandler( peers );
        System.err.println(" ---- query 3 - 6 close peers -----");
        exampleSendRedundant(peers[34]);
        System.err.println(" ---- now we want to query only the closest one -----");
        exampleSendOne(peers[14]);
        Thread.sleep( 60000 );
    }
    catch (Exception e) 
    {
        e.printStackTrace();
    }
    finally
    {
        master.halt();
    }
}
 
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:26,代码来源:ExampleSend.java

示例13: setupReplyHandler

import net.tomp2p.p2p.Peer; //导入依赖的package包/类
private static void setupReplyHandler( Peer[] peers)
{
    for(final Peer peer:peers) 
    {
        peer.setObjectDataReply( new ObjectDataReply()
        {             
            @Override
            public Object reply( PeerAddress sender, Object request )
                throws Exception
            {                
                System.err.println("I'm "+peer.getPeerID()+" and I just got the message ["+request+"] from "+sender.getPeerId());
                return "world";
            }
        } );
    }
}
 
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:17,代码来源:ExampleSend.java

示例14: main

import net.tomp2p.p2p.Peer; //导入依赖的package包/类
/**
 * Start the examples.
 * 
 * @param args
 *            Empty
 * @throws Exception .
 */
public static void main(final String[] args) throws Exception {
    Peer master = null;
    try {
        final int peerNr = 100;
        final int port = 4001;
        Peer[] peers = ExampleUtils.createAndAttachNodes(peerNr, port);
        master = peers[0];
        ExampleUtils.bootstrap(peers);
        Number160 key1 = new Number160(RND);
        exampleConsistency(key1, peers);
        exampleAttack(key1, peers);
    } catch (Throwable e) {
        e.printStackTrace();
    } finally {
        if (master != null) {
            master.halt();
        }
    }
}
 
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:27,代码来源:ExampleConsistency.java

示例15: main

import net.tomp2p.p2p.Peer; //导入依赖的package包/类
/**
 * Start the examples.
 * 
 * @param args
 *            Empty
 * @throws Exception .
 */
public static void main(final String[] args) throws Exception {
    final int peerNr = 100;
    final int port = 4001;
    Peer[] peers = null;
    try {
        peers = ExampleUtils.createAndAttachNodes(peerNr, port);
        ExampleUtils.bootstrap(peers);
        exampleSearch(peers);
        exampleKeywordSearch(peers);
    } finally {
        // 0 is the master
        if (peers != null && peers[0] != null) {
            peers[0].halt();
        }
    }
}
 
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:24,代码来源:ExampleSearch.java


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