mirror of
https://github.com/ChronosX88/Influence-Bootstrap-Node.git
synced 2024-11-21 15:02:17 +00:00
Added creating FreePastry bootstrap node
This commit is contained in:
parent
6f0da1e336
commit
9d53bdd7e6
@ -24,6 +24,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation 'net.tomp2p:tomp2p-all:5.0-Beta8'
|
||||
implementation 'org.slf4j:slf4j-log4j12:+'
|
||||
}
|
||||
|
BIN
libs/FreePastry-2.1.jar
Normal file
BIN
libs/FreePastry-2.1.jar
Normal file
Binary file not shown.
BIN
libs/commons-jxpath-1.1.jar
Normal file
BIN
libs/commons-jxpath-1.1.jar
Normal file
Binary file not shown.
BIN
libs/commons-logging.jar
Normal file
BIN
libs/commons-logging.jar
Normal file
Binary file not shown.
@ -1,6 +1,8 @@
|
||||
package io.github.chronosx88.dhtBootstrap;
|
||||
|
||||
import net.tomp2p.connection.*;
|
||||
import net.tomp2p.connection.ChannelClientConfiguration;
|
||||
import net.tomp2p.connection.ChannelServerConfiguration;
|
||||
import net.tomp2p.connection.RSASignatureFactory;
|
||||
import net.tomp2p.dht.PeerBuilderDHT;
|
||||
import net.tomp2p.dht.PeerDHT;
|
||||
import net.tomp2p.nat.PeerBuilderNAT;
|
||||
@ -9,6 +11,12 @@ import net.tomp2p.peers.Number160;
|
||||
import net.tomp2p.relay.RelayType;
|
||||
import net.tomp2p.relay.tcp.TCPRelayServerConfig;
|
||||
import net.tomp2p.replication.IndirectReplication;
|
||||
import rice.environment.Environment;
|
||||
import rice.pastry.NodeIdFactory;
|
||||
import rice.pastry.PastryNode;
|
||||
import rice.pastry.PastryNodeFactory;
|
||||
import rice.pastry.socket.internet.InternetPastryNodeFactory;
|
||||
import rice.pastry.standard.RandomNodeIdFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@ -20,6 +28,7 @@ import java.util.UUID;
|
||||
|
||||
public class Main {
|
||||
private static PeerDHT peerDHT;
|
||||
private static PastryNode pastryNode;
|
||||
private static Number160 peerID;
|
||||
private static Properties props;
|
||||
private static final String DATA_DIR_PATH = System.getProperty("user.home") + "/.local/share/Influence-Bootstrap/";
|
||||
@ -68,6 +77,7 @@ public class Main {
|
||||
.addRelayServerConfiguration(RelayType.OPENTCP, new TCPRelayServerConfig())
|
||||
.start();
|
||||
new IndirectReplication(peerDHT).start();
|
||||
createNewPastryBootstrapNode();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -84,4 +94,51 @@ public class Main {
|
||||
channelServerConfiguration.signatureFactory(new RSASignatureFactory());
|
||||
return channelServerConfiguration;
|
||||
}
|
||||
|
||||
private static void createNewPastryBootstrapNode() {
|
||||
Environment env = new Environment();
|
||||
env.getParameters().setString("probe_for_external_address","true");
|
||||
env.getParameters().setString("nat_search_policy","never");
|
||||
// Generate the NodeIds Randomly
|
||||
NodeIdFactory nidFactory = new RandomNodeIdFactory(env);
|
||||
|
||||
// construct the PastryNodeFactory, this is how we use rice.pastry.socket
|
||||
PastryNodeFactory factory = null;
|
||||
try {
|
||||
factory = new InternetPastryNodeFactory(nidFactory, 7244, env);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// construct a node, but this does not cause it to boot
|
||||
PastryNode node = null;
|
||||
try {
|
||||
node = factory.newNode();
|
||||
pastryNode = node;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// in later tutorials, we will register applications before calling boot
|
||||
node.boot(new InetSocketAddress(7244));
|
||||
|
||||
// the node may require sending several messages to fully boot into the ring
|
||||
synchronized(node) {
|
||||
while(!node.isReady() && !node.joinFailed()) {
|
||||
// delay so we don't busy-wait
|
||||
try {
|
||||
node.wait(500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// abort if can't join
|
||||
if (node.joinFailed()) {
|
||||
System.out.println("[Pastry] Could not join the FreePastry ring. Reason:"+node.joinFailedReason());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("[Pastry] Finished creating new bootstrap node "+node);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user