Update to latest TomP2P master

This commit is contained in:
Manfred Karrer 2014-10-27 15:09:52 +01:00
parent 2a78e194bd
commit 9c8b76d2b6
5 changed files with 33 additions and 66 deletions

View file

@ -1,87 +0,0 @@
/*
* This file is part of Bitsquare.
*
* Bitsquare is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
package io.bitsquare.msg;
import java.io.IOException;
import net.tomp2p.dht.PeerBuilderDHT;
import net.tomp2p.nat.PeerBuilderNAT;
import net.tomp2p.p2p.Peer;
import net.tomp2p.p2p.PeerBuilder;
import net.tomp2p.peers.Number160;
import net.tomp2p.peers.PeerAddress;
import net.tomp2p.peers.PeerMapChangeListener;
import net.tomp2p.peers.PeerStatatistic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SeedNode extends Thread {
private static final Logger log = LoggerFactory.getLogger(SeedNode.class);
public static void main(String[] args) {
Peer peer = null;
SeedNodeAddress.StaticSeedNodeAddresses seedNodeAddress = SeedNodeAddress.StaticSeedNodeAddresses
.DIGITAL_OCEAN1;
try {
peer = new PeerBuilder(Number160.createHash(seedNodeAddress.getId())).ports(seedNodeAddress.getPort())
.start();
new PeerBuilderDHT(peer).start();
new PeerBuilderNAT(peer).start();
log.debug("peer listening at port: {}", seedNodeAddress.getPort());
peer.peerBean().peerMap().addPeerMapChangeListener(new PeerMapChangeListener() {
@Override
public void peerInserted(PeerAddress peerAddress, boolean verified) {
log.debug("Peer inserted: peerAddress=" + peerAddress + ", verified=" + verified);
}
@Override
public void peerRemoved(PeerAddress peerAddress, PeerStatatistic peerStatistics) {
log.debug("Peer removed: peerAddress=" + peerAddress + ", peerStatistics=" + peerStatistics);
}
@Override
public void peerUpdated(PeerAddress peerAddress, PeerStatatistic peerStatistics) {
// log.debug("Peer updated: peerAddress=" + peerAddress + ",
// peerStatistics=" + peerStatistics);
}
});
final Peer _peer = peer;
Thread seedNodeThread = new Thread(() -> {
while (true) {
try {
for (PeerAddress pa : _peer.peerBean().peerMap().all()) {
System.out.println("peer online (TCP):" + pa);
}
Thread.sleep(2000L);
} catch (InterruptedException e) {
}
}
});
seedNodeThread.start();
} catch (IOException e) {
e.printStackTrace();
if (peer != null)
peer.shutdown().awaitUninterruptibly();
}
}
}

View file

@ -1,20 +1,3 @@
/*
* This file is part of Bitsquare.
*
* Bitsquare is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Copyright 2012 Thomas Bocek
*
@ -63,7 +46,7 @@ import net.tomp2p.peers.PeerSocketAddress;
public class UtilsDHT2 {
/**
* Used to make the testcases predictable. Used as an input for {@link java.util.Random}.
* Used to make the testcases predictable. Used as an input for {@link Random}.
*/
public static final long THE_ANSWER = 42L;
@ -137,7 +120,7 @@ public class UtilsDHT2 {
/**
* 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
@ -161,16 +144,16 @@ public class UtilsDHT2 {
PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
master = new PeerBuilder(peerId)
.ports(port).enableMaintenance(maintenance)
.externalBindings(bindings).peerMap(peerMap).start().addAutomaticFuture(automaticFuture);
.bindings(bindings).peerMap(peerMap).start().addAutomaticFuture(automaticFuture);
peers[0] = new PeerBuilderDHT(master).start();
}
else {
Number160 peerId = new Number160(rnd);
PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
master = new PeerBuilder(peerId).enableMaintenance(maintenance).externalBindings(bindings)
master = new PeerBuilder(peerId).enableMaintenance(maintenance).bindings(bindings)
.peerMap(peerMap).ports(port).start();
peers[0] = new PeerBuilderDHT(master).start();
peers[0] = new PeerBuilderDHT(master).start();
}
for (int i = 1; i < nrOfPeers; i++) {
@ -179,17 +162,16 @@ public class UtilsDHT2 {
PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId));
Peer peer = new PeerBuilder(peerId)
.masterPeer(master)
.enableMaintenance(maintenance).enableMaintenance(maintenance).peerMap(peerMap)
.externalBindings(bindings).start().addAutomaticFuture(automaticFuture);
.enableMaintenance(maintenance).enableMaintenance(maintenance).peerMap(peerMap).bindings(bindings).start().addAutomaticFuture(automaticFuture);
peers[i] = new PeerBuilderDHT(peer).start();
}
else {
Number160 peerId = new Number160(rnd);
PeerMap peerMap = new PeerMap(new PeerMapConfiguration(peerId).peerNoVerification());
Peer peer = new PeerBuilder(peerId).enableMaintenance(maintenance)
.externalBindings(bindings).peerMap(peerMap).masterPeer(master)
.bindings(bindings).peerMap(peerMap).masterPeer(master)
.start();
peers[i] = new PeerBuilderDHT(peer).start();
peers[i] = new PeerBuilderDHT(peer).start();
}
}
System.err.println("peers created.");
@ -227,7 +209,7 @@ public class UtilsDHT2 {
/**
* Perfect routing, where each neighbor has contacted each other. This means that for small number of peers, every
* peer knows every other peer.
*
*
* @param peers
* The peers taking part in the p2p network.
*/