本文整理汇总了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;
}
示例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();
}
}
示例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;
}
示例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();
}
}
}
示例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();
}
}
}
示例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();
}
}
}
示例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();
}
}
}
示例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);
}
}
示例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();
}
}
}
示例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();
}
}
}
示例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);
}
示例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();
}
}
示例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";
}
} );
}
}
示例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();
}
}
}
示例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();
}
}
}