本文整理汇总了Java中net.tomp2p.p2p.Peer类的典型用法代码示例。如果您正苦于以下问题:Java Peer类的具体用法?Java Peer怎么用?Java Peer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Peer类属于net.tomp2p.p2p包,在下文中一共展示了Peer类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: startReiver
import net.tomp2p.p2p.Peer; //导入依赖的package包/类
/**
* Start the recipient and wait forever.
*
* @throws InterruptedException .
* @throws IOException .
*/
@Test
public void startReiver() throws IOException, InterruptedException {
final int maxPeers = 10;
Peer[] peers = createPeers(PORT, maxPeers, "receiver");
for (int i = 1; i < maxPeers; i++) {
Peer peer = peers[i];
peer.bootstrap().setPeerAddress(peers[0].getPeerAddress()).start().awaitUninterruptibly();
peer.setObjectDataReply(new ObjectDataReply() {
@Override
public Object reply(final PeerAddress sender, final Object request) throws Exception {
System.out.println("got it!");
return "recipient got it";
}
});
}
Thread.sleep(Long.MAX_VALUE);
}
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:25,代码来源:TestSend.java
示例17: createNodes
import net.tomp2p.p2p.Peer; //导入依赖的package包/类
/**
* Creates peers for testing. The first peer (peer[0]) will be used as the master. This means that shutting down
* peer[0] will shut down all other peers
*
* @param nrOfPeers
* The number of peers to create including the master
* @param rnd
* The random object to create random peer IDs
* @param port
* The port where the master peer will listen to
* @return All the peers, with the master peer at position 0 -> peer[0]
* @throws Exception
* If the creation of nodes fail.
*/
public static Peer[] createNodes(int nrOfPeers, Random rnd, int port, AutomaticFuture automaticFuture) throws Exception {
if (nrOfPeers < 1) {
throw new IllegalArgumentException("Cannot create less than 1 peer");
}
Peer[] peers = new Peer[nrOfPeers];
if (automaticFuture!=null) {
peers[0] = new PeerMaker(new Number160(rnd))
.addAutomaticFuture(automaticFuture).ports(port)
.makeAndListen();
} else {
peers[0] = new PeerMaker(new Number160(rnd)).ports(port).makeAndListen();
}
for (int i = 1; i < nrOfPeers; i++) {
if (automaticFuture!=null) {
peers[i] = new PeerMaker(new Number160(rnd))
.addAutomaticFuture(automaticFuture).masterPeer(peers[0])
.makeAndListen();
} else {
peers[i] = new PeerMaker(new Number160(rnd)).masterPeer(peers[0]).makeAndListen();
}
}
System.err.println("peers created.");
return peers;
}
开发者ID:maxatp,项目名称:tomp2p_5,代码行数:40,代码来源:Utils2.java
示例18: getTomP2PVersion
import net.tomp2p.p2p.Peer; //导入依赖的package包/类
/**
* Get version of TomP2P.
*
* @return tomp2p version string (core) or null.
*/
public static String getTomP2PVersion() {
String pomProperties = "/META-INF/maven/net.tomp2p/tomp2p-core/pom.properties";
Class<Peer> clazz = Peer.class;
String version = readVersionFromPom(clazz, pomProperties);
return version;
}
开发者ID:PeerWasp,项目名称:PeerWasp,代码行数:12,代码来源:VersionUtils.java
示例19: reAttackTest
import net.tomp2p.p2p.Peer; //导入依赖的package包/类
public void reAttackTest(){
Peer peer = DeceitfulNetworkUtils.createPeer(17677);
TaskPasserDOS taskPasserDOS = new TaskPasserDOS(peer);
final int messages = 500;
try {
DeceitfulNetworkUtils.bootstrap(peer, "narrens.olf.sgsnet.se", 4001, bootstrapDone);
// boots.acquireUninterruptibly();
Thread.sleep(100);
final PeerAddress jobOwner = peer.getPeerBean().getPeerMap().getAll().get(0);
Date beforePeer = new Date();
for(int i=0; i<messages; ++i){
taskPasserDOS.requestChallenge(jobOwner, challengeReceived);
}
Date afterPeer = new Date();
final long peerDiff = afterPeer.getTime()-beforePeer.getTime();
System.out.println("\tSend messages: "+peerDiff);
Date beforeChallenge = new Date();
challenges.acquireUninterruptibly(messages);
Date afterChallenge = new Date();
final long challengeDiff = afterChallenge.getTime()-beforeChallenge.getTime();
System.out.println("\tReceive challenges: "+challengeDiff);
} catch (Exception e) {
e.printStackTrace();
} finally {
peer.shutdown();
}
}
开发者ID:GDCN,项目名称:GDCN,代码行数:37,代码来源:DOSAttackTest.java
示例20: Passer
import net.tomp2p.p2p.Peer; //导入依赖的package包/类
protected Passer(final Peer peer) {
this.peer = peer;
peer.setObjectDataReply(new ObjectDataReply() {
@Override
public Object reply(PeerAddress sender, Object request) throws Exception {
if(peer.getPeerAddress().equals(sender)){
//Disabled for demo
//System.out.println("in Passer: ERROR! sender is myself!!!");
}
NetworkMessage message = NetworkMessage.decrypt( request);
if(message == null){
//Error has occurred in decrypt
System.out.println("Decrypt returned NULL!");
return "Decrypt was NULL";
}
//Disabled for demo
//System.out.println("ObjectDataReply received: " + message.toString());
switch (message.getType()){
case REQUEST:
return handleRequest(sender, message.getObject());
case NO_REPLY:
handleNoReply(sender, message.getObject());
return "Message was Handled in some way...";
}
return "Message was read but not Handled! Type: "+message.getType().name();
}
});
}
开发者ID:GDCN,项目名称:GDCN,代码行数:32,代码来源:Passer.java
注:本文中的net.tomp2p.p2p.Peer类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论