mirror of
https://github.com/Qortal/qortal.git
synced 2025-05-10 11:47:51 +00:00
a few fixes to the mesh functionality
This commit is contained in:
parent
a445fdc8f2
commit
185f3f515b
@ -167,7 +167,20 @@ public class RNSNetwork {
|
|||||||
//rnsNetworkEPC.start();
|
//rnsNetworkEPC.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
//@Synchronized
|
private void initConfig(String configDir) throws IOException {
|
||||||
|
File configDir1 = new File(defaultConfigPath);
|
||||||
|
if (!configDir1.exists()) {
|
||||||
|
configDir1.mkdir();
|
||||||
|
}
|
||||||
|
var configPath = Path.of(configDir1.getAbsolutePath());
|
||||||
|
Path configFile = configPath.resolve(CONFIG_FILE_NAME);
|
||||||
|
|
||||||
|
if (Files.notExists(configFile)) {
|
||||||
|
var defaultConfig = this.getClass().getClassLoader().getResourceAsStream("reticulum_default_config.yml");
|
||||||
|
Files.copy(defaultConfig, configFile, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
isShuttingDown = true;
|
isShuttingDown = true;
|
||||||
log.info("shutting down Reticulum");
|
log.info("shutting down Reticulum");
|
||||||
@ -194,28 +207,21 @@ public class RNSNetwork {
|
|||||||
}
|
}
|
||||||
// gracefully close links of peers that point to us
|
// gracefully close links of peers that point to us
|
||||||
for (Link l: incomingLinks) {
|
for (Link l: incomingLinks) {
|
||||||
var data = concatArrays("close::".getBytes(UTF_8),l.getDestination().getHash());
|
sendCloseToRemote(l);
|
||||||
Packet closePacket = new Packet(l, data);
|
|
||||||
var packetReceipt = closePacket.send();
|
|
||||||
packetReceipt.setTimeout(3L);
|
|
||||||
packetReceipt.setDeliveryCallback(this::closePacketDelivered);
|
|
||||||
packetReceipt.setTimeoutCallback(this::packetTimedOut);
|
|
||||||
}
|
}
|
||||||
// Note: we still need to get the packet timeout callback to work...
|
// Note: we still need to get the packet timeout callback to work...
|
||||||
reticulum.exitHandler();
|
reticulum.exitHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initConfig(String configDir) throws IOException {
|
public void sendCloseToRemote(Link link) {
|
||||||
File configDir1 = new File(defaultConfigPath);
|
if (nonNull(link)) {
|
||||||
if (!configDir1.exists()) {
|
var data = concatArrays("close::".getBytes(UTF_8),link.getDestination().getHash());
|
||||||
configDir1.mkdir();
|
Packet closePacket = new Packet(link, data);
|
||||||
}
|
var packetReceipt = closePacket.send();
|
||||||
var configPath = Path.of(configDir1.getAbsolutePath());
|
packetReceipt.setDeliveryCallback(this::closePacketDelivered);
|
||||||
Path configFile = configPath.resolve(CONFIG_FILE_NAME);
|
packetReceipt.setTimeoutCallback(this::packetTimedOut);
|
||||||
|
} else {
|
||||||
if (Files.notExists(configFile)) {
|
log.debug("can't send to null link");
|
||||||
var defaultConfig = this.getClass().getClassLoader().getResourceAsStream("reticulum_default_config.yml");
|
|
||||||
Files.copy(defaultConfig, configFile, StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -507,7 +513,22 @@ public class RNSNetwork {
|
|||||||
}
|
}
|
||||||
//removeExpiredPeers(this.linkedPeers);
|
//removeExpiredPeers(this.linkedPeers);
|
||||||
log.info("number of links (linkedPeers) after prunig: {}", peerList.size());
|
log.info("number of links (linkedPeers) after prunig: {}", peerList.size());
|
||||||
log.info("we have {} non-initiator links, list: {}", incomingLinks.size(), incomingLinks);
|
//log.info("we have {} non-initiator links, list: {}", incomingLinks.size(), incomingLinks);
|
||||||
|
var activePeerCount = 0;
|
||||||
|
var lps = RNSNetwork.getInstance().getLinkedPeers();
|
||||||
|
for (RNSPeer p: lps) {
|
||||||
|
pLink = p.getPeerLink();
|
||||||
|
p.pingRemote();
|
||||||
|
try {
|
||||||
|
TimeUnit.SECONDS.sleep(2); // allow for peers to disconnect gracefully
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
log.error("exception: {}", e);
|
||||||
|
}
|
||||||
|
if ((nonNull(pLink) && (pLink.getStatus() == ACTIVE))) {
|
||||||
|
activePeerCount = activePeerCount + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.info("we have {} active peers", activePeerCount);
|
||||||
maybeAnnounce(getBaseDestination());
|
maybeAnnounce(getBaseDestination());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,6 +194,7 @@ public class RNSPeer {
|
|||||||
log.info("packet timed out, receipt status: {}", receipt.getStatus());
|
log.info("packet timed out, receipt status: {}", receipt.getStatus());
|
||||||
if (receipt.getStatus() == PacketReceiptStatus.FAILED) {
|
if (receipt.getStatus() == PacketReceiptStatus.FAILED) {
|
||||||
this.peerTimedOut = true;
|
this.peerTimedOut = true;
|
||||||
|
this.peerLink.teardown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +235,7 @@ public class RNSPeer {
|
|||||||
link.setPacketCallback(this::linkPacketReceived);
|
link.setPacketCallback(this::linkPacketReceived);
|
||||||
Packet pingPacket = new Packet(link, data);
|
Packet pingPacket = new Packet(link, data);
|
||||||
PacketReceipt packetReceipt = pingPacket.send();
|
PacketReceipt packetReceipt = pingPacket.send();
|
||||||
packetReceipt.setTimeout(3L);
|
// Note: don't setTimeout, we want it to timeout with FAIL if not deliverable
|
||||||
packetReceipt.setTimeoutCallback(this::packetTimedOut);
|
packetReceipt.setTimeoutCallback(this::packetTimedOut);
|
||||||
packetReceipt.setDeliveryCallback(this::packetDelivered);
|
packetReceipt.setDeliveryCallback(this::packetDelivered);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user