use of io.bitsquare.p2p.peers.Broadcaster in project bitsquare by bitsquare.
the class P2PService method init.
private void init(boolean useLocalhost, int networkId, File storageDir, String seedNodes, String myAddress, String banList) {
if (!useLocalhost)
FileUtil.rollingBackup(new File(Paths.get(torDir.getAbsolutePath(), "hiddenservice").toString()), "private_key", 20);
if (banList != null && !banList.isEmpty())
BanList.setList(Arrays.asList(banList.replace(" ", "").split(",")).stream().map(NodeAddress::new).collect(Collectors.toList()));
if (myAddress != null && !myAddress.isEmpty())
seedNodesRepository.setNodeAddressToExclude(new NodeAddress(myAddress));
networkNode = useLocalhost ? new LocalhostNetworkNode(port) : new TorNetworkNode(port, torDir);
networkNode.addConnectionListener(this);
networkNode.addMessageListener(this);
Set<NodeAddress> seedNodeAddresses;
if (seedNodes != null && !seedNodes.isEmpty())
seedNodeAddresses = Arrays.asList(seedNodes.replace(" ", "").split(",")).stream().map(NodeAddress::new).collect(Collectors.toSet());
else
seedNodeAddresses = seedNodesRepository.getSeedNodeAddresses(useLocalhost, networkId);
peerManager = new PeerManager(networkNode, maxConnections, seedNodeAddresses, storageDir, clock);
broadcaster = new Broadcaster(networkNode, peerManager);
p2PDataStorage = new P2PDataStorage(broadcaster, networkNode, storageDir);
p2PDataStorage.addHashMapChangedListener(this);
requestDataManager = new RequestDataManager(networkNode, p2PDataStorage, peerManager, seedNodeAddresses, this);
peerExchangeManager = new PeerExchangeManager(networkNode, peerManager, seedNodeAddresses);
keepAliveManager = new KeepAliveManager(networkNode, peerManager);
// We need to have both the initial data delivered and the hidden service published
networkReadyBinding = EasyBind.combine(hiddenServicePublished, preliminaryDataReceived, (hiddenServicePublished, preliminaryDataReceived) -> hiddenServicePublished && preliminaryDataReceived);
networkReadySubscription = networkReadyBinding.subscribe((observable, oldValue, newValue) -> {
if (newValue)
onNetworkReady();
});
}
Aggregations