mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-08-21 21:19:36 -04:00
Remove common module, rename net to bootstrap
This commit is contained in:
parent
c95ad02f29
commit
3a90fcd022
7 changed files with 7 additions and 30 deletions
|
@ -1,117 +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.app.bootstrap;
|
||||
|
||||
import io.bitsquare.network.Node;
|
||||
|
||||
import net.tomp2p.connection.ChannelClientConfiguration;
|
||||
import net.tomp2p.connection.ChannelServerConfiguration;
|
||||
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.PeerStatistic;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.netty.util.concurrent.DefaultEventExecutorGroup;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
public class BootstrapNode {
|
||||
private static final Logger log = LoggerFactory.getLogger(BootstrapNode.class);
|
||||
|
||||
private static Peer peer = null;
|
||||
private static boolean running = true;
|
||||
|
||||
private final Environment env;
|
||||
|
||||
public BootstrapNode(Environment env) {
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
String name = env.getRequiredProperty(Node.NAME_KEY);
|
||||
int port = env.getProperty(Node.PORT_KEY, Integer.class, Node.DEFAULT_PORT);
|
||||
|
||||
try {
|
||||
Number160 peerId = Number160.createHash(name);
|
||||
|
||||
DefaultEventExecutorGroup eventExecutorGroup = new DefaultEventExecutorGroup(250);
|
||||
ChannelClientConfiguration clientConf = PeerBuilder.createDefaultChannelClientConfiguration();
|
||||
clientConf.pipelineFilter(new PeerBuilder.EventExecutorGroupFilter(eventExecutorGroup));
|
||||
|
||||
ChannelServerConfiguration serverConf = PeerBuilder.createDefaultChannelServerConfiguration();
|
||||
serverConf.pipelineFilter(new PeerBuilder.EventExecutorGroupFilter(eventExecutorGroup));
|
||||
serverConf.connectionTimeoutTCPMillis(5000);
|
||||
|
||||
peer = new PeerBuilder(peerId)
|
||||
.ports(port)
|
||||
.channelClientConfiguration(clientConf)
|
||||
.channelServerConfiguration(serverConf)
|
||||
.start();
|
||||
|
||||
/*peer.objectDataReply((sender, request) -> {
|
||||
log.trace("received request: " + request.toString());
|
||||
return "pong";
|
||||
});*/
|
||||
|
||||
new PeerBuilderDHT(peer).start();
|
||||
new PeerBuilderNAT(peer).start();
|
||||
|
||||
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, PeerStatistic peerStatistics) {
|
||||
log.debug("Peer removed: peerAddress=" + peerAddress + ", peerStatistics=" + peerStatistics);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void peerUpdated(PeerAddress peerAddress, PeerStatistic peerStatistics) {
|
||||
// log.debug("Peer updated: peerAddress=" + peerAddress + ", peerStatistics=" + peerStatistics);
|
||||
}
|
||||
});
|
||||
|
||||
log.info("Bootstrap node started with name " + name + " and port " + port);
|
||||
new Thread(() -> {
|
||||
while (running) {
|
||||
log.info("List of all peers online ----------------------------");
|
||||
for (PeerAddress peerAddress : peer.peerBean().peerMap().all()) {
|
||||
log.info(peerAddress.toString());
|
||||
}
|
||||
try {
|
||||
Thread.sleep(60000);
|
||||
} catch (InterruptedException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
|
||||
} catch (Exception e) {
|
||||
if (peer != null)
|
||||
peer.shutdown().awaitUninterruptibly();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,45 +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.app.bootstrap;
|
||||
|
||||
import io.bitsquare.app.BitsquareEnvironment;
|
||||
import io.bitsquare.app.BitsquareExecutable;
|
||||
import io.bitsquare.network.Node;
|
||||
|
||||
import joptsimple.OptionParser;
|
||||
import joptsimple.OptionSet;
|
||||
|
||||
public class BootstrapNodeMain extends BitsquareExecutable {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
new BootstrapNodeMain().execute(args);
|
||||
}
|
||||
|
||||
protected void customizeOptionParsing(OptionParser parser) {
|
||||
parser.accepts(Node.NAME_KEY, description("Name of this node", null))
|
||||
.withRequiredArg()
|
||||
.isRequired();
|
||||
parser.accepts(Node.PORT_KEY, description("Port to listen on", Node.DEFAULT_PORT))
|
||||
.withRequiredArg()
|
||||
.ofType(int.class);
|
||||
}
|
||||
|
||||
protected void doExecute(OptionSet options) {
|
||||
new BootstrapNode(new BitsquareEnvironment(options)).start();
|
||||
}
|
||||
}
|
|
@ -1,27 +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.util.tasks;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class TaskInterception {
|
||||
private static final Logger log = LoggerFactory.getLogger(TaskInterception.class);
|
||||
public static Class<? extends Task> taskToInterceptBeforeRun;
|
||||
public static Class<? extends Task> taskToInterceptAfterRun;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue