mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Make seednode working with current TomP2P implementation
This commit is contained in:
parent
0d048de7fc
commit
a8a3378268
@ -17,15 +17,21 @@
|
|||||||
|
|
||||||
package io.bitsquare.msg.actor;
|
package io.bitsquare.msg.actor;
|
||||||
|
|
||||||
|
import io.bitsquare.msg.SeedNodeAddress;
|
||||||
import io.bitsquare.msg.actor.command.InitializePeer;
|
import io.bitsquare.msg.actor.command.InitializePeer;
|
||||||
import io.bitsquare.msg.actor.event.PeerInitialized;
|
import io.bitsquare.msg.actor.event.PeerInitialized;
|
||||||
|
|
||||||
import net.tomp2p.connection.Ports;
|
import java.util.List;
|
||||||
|
|
||||||
import net.tomp2p.dht.PeerBuilderDHT;
|
import net.tomp2p.dht.PeerBuilderDHT;
|
||||||
import net.tomp2p.dht.PeerDHT;
|
import net.tomp2p.dht.PeerDHT;
|
||||||
import net.tomp2p.futures.FutureBootstrap;
|
import net.tomp2p.nat.PeerBuilderNAT;
|
||||||
|
import net.tomp2p.nat.PeerNAT;
|
||||||
import net.tomp2p.p2p.Peer;
|
import net.tomp2p.p2p.Peer;
|
||||||
import net.tomp2p.p2p.PeerBuilder;
|
import net.tomp2p.p2p.PeerBuilder;
|
||||||
|
import net.tomp2p.peers.Number160;
|
||||||
|
import net.tomp2p.relay.FutureRelay;
|
||||||
|
import net.tomp2p.relay.RelayRPC;
|
||||||
|
|
||||||
import akka.actor.AbstractActor;
|
import akka.actor.AbstractActor;
|
||||||
import akka.actor.Props;
|
import akka.actor.Props;
|
||||||
@ -52,25 +58,46 @@ public class DHTManager extends AbstractActor {
|
|||||||
private PeerDHT peerDHT;
|
private PeerDHT peerDHT;
|
||||||
|
|
||||||
public DHTManager() {
|
public DHTManager() {
|
||||||
|
|
||||||
receive(ReceiveBuilder
|
receive(ReceiveBuilder
|
||||||
.match(InitializePeer.class, ip -> {
|
.match(InitializePeer.class, ip -> {
|
||||||
log.debug("Received message: {}", ip);
|
log.debug("Received message: {}", ip);
|
||||||
|
|
||||||
peer = new PeerBuilder(ip.getPeerId())
|
try {
|
||||||
.ports(ip.getPort() != null ? ip.getPort() : new Ports().tcpPort()).start();
|
List<SeedNodeAddress.StaticSeedNodeAddresses> staticSedNodeAddresses = SeedNodeAddress
|
||||||
peerDHT = new PeerBuilderDHT(peer).start();
|
.StaticSeedNodeAddresses.getAllSeedNodeAddresses();
|
||||||
|
SeedNodeAddress seedNodeAddress = new SeedNodeAddress(staticSedNodeAddresses.get(0));
|
||||||
|
|
||||||
// TODO add code to discover non-local peers
|
peer = new PeerBuilder(
|
||||||
// FutureDiscover futureDiscover = peer.discover().peerAddress(bootstrapPeers.).start();
|
Number160.createHash(seedNodeAddress.getId())).ports(seedNodeAddress.getPort
|
||||||
// futureDiscover.awaitUninterruptibly();
|
()).start();
|
||||||
|
|
||||||
if (ip.getBootstrapPeers() != null) {
|
// Need to add all features the clients will use (otherwise msg type is UNKNOWN_ID)
|
||||||
FutureBootstrap futureBootstrap = peer.bootstrap()
|
new PeerBuilderDHT(peer).start();
|
||||||
.bootstrapTo(ip.getBootstrapPeers()).start();
|
PeerNAT nodeBehindNat = new PeerBuilderNAT(peer).start();
|
||||||
futureBootstrap.awaitUninterruptibly(bootstrapTimeout);
|
new RelayRPC(peer);
|
||||||
|
//new PeerBuilderTracker(peer);
|
||||||
|
nodeBehindNat.startSetupRelay(new FutureRelay());
|
||||||
|
|
||||||
|
|
||||||
|
/* peer = new PeerBuilder(ip.getPeerId())
|
||||||
|
.ports(ip.getPort() != null ? ip.getPort() : new Ports().tcpPort()).start();
|
||||||
|
peerDHT = new PeerBuilderDHT(peer).start();*/
|
||||||
|
|
||||||
|
// TODO add code to discover non-local peers
|
||||||
|
// FutureDiscover futureDiscover = peer.discover().peerAddress(bootstrapPeers.).start();
|
||||||
|
// futureDiscover.awaitUninterruptibly();
|
||||||
|
|
||||||
|
/* if (ip.getBootstrapPeers() != null) {
|
||||||
|
FutureBootstrap futureBootstrap = peer.bootstrap()
|
||||||
|
.bootstrapTo(ip.getBootstrapPeers()).start();
|
||||||
|
futureBootstrap.awaitUninterruptibly(bootstrapTimeout);
|
||||||
|
}*/
|
||||||
|
sender().tell(new PeerInitialized(peer.peerID()), self());
|
||||||
|
} catch (Throwable t) {
|
||||||
|
log.info("The second instance has been started. If that happens at the first instance" +
|
||||||
|
" we are in trouble... " + t.getMessage());
|
||||||
|
sender().tell(new PeerInitialized(null), self());
|
||||||
}
|
}
|
||||||
sender().tell(new PeerInitialized(peer.peerID()), self());
|
|
||||||
})
|
})
|
||||||
.matchAny(o -> log.info("received unknown message")).build()
|
.matchAny(o -> log.info("received unknown message")).build()
|
||||||
);
|
);
|
||||||
@ -79,7 +106,8 @@ public class DHTManager extends AbstractActor {
|
|||||||
@Override
|
@Override
|
||||||
public void postStop() throws Exception {
|
public void postStop() throws Exception {
|
||||||
log.debug("postStop");
|
log.debug("postStop");
|
||||||
peerDHT.shutdown();
|
if (peerDHT != null)
|
||||||
|
peerDHT.shutdown();
|
||||||
super.postStop();
|
super.postStop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user