[Change] Added some DataSync Output to the verbose logging (#41)

This commit is contained in:
Frank 2022-10-13 20:27:15 +02:00
parent 5c10c01bd7
commit b03c314ecf
5 changed files with 59 additions and 34 deletions

View file

@ -5,6 +5,7 @@ import org.betterx.bclib.api.v2.dataexchange.handler.DataExchange;
import org.betterx.bclib.api.v2.dataexchange.handler.autosync.AutoSync;
import org.betterx.bclib.api.v2.dataexchange.handler.autosync.AutoSyncID;
import org.betterx.bclib.config.Config;
import org.betterx.bclib.config.Configs;
import org.betterx.worlds.together.util.ModUtil;
import net.minecraft.network.FriendlyByteBuf;
@ -55,6 +56,7 @@ public class DataExchangeAPI extends DataExchange {
if (ModUtil.getModInfo(modID, false) != null && !"0.0.0".equals(ModUtil.getModVersion(modID))) {
registerMod(modID);
} else {
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.info("Mod Dependency '" + modID + "' not found. This is probably OK.");
}
}

View file

@ -129,6 +129,7 @@ public class HelloClient extends DataHandler.FromServer {
modID));
buf.writeBoolean(canDownload);
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.info(" - Listing Mod " + modID + " v" + ver + " (size: " + PathUtil.humanReadableFileSize(
size) + ", download=" + canDownload + ")");
}
@ -149,6 +150,7 @@ public class HelloClient extends DataHandler.FromServer {
buf.writeInt(existingAutoSyncFiles.size());
for (AutoFileSyncEntry entry : existingAutoSyncFiles) {
entry.serialize(buf);
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.info(" - Offering " + (entry.isConfigFile() ? "Config " : "File ") + entry);
}
} else {
@ -159,6 +161,7 @@ public class HelloClient extends DataHandler.FromServer {
if (Configs.SERVER_CONFIG.isOfferingFiles()) {
buf.writeInt(AutoSync.syncFolderDescriptions.size());
AutoSync.syncFolderDescriptions.forEach(desc -> {
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.info(" - Offering Folder " + desc.localFolder + " (allowDelete=" + desc.removeAdditionalFiles + ")");
desc.serialize(buf);
});
@ -230,6 +233,7 @@ public class HelloClient extends DataHandler.FromServer {
}
if (autoSynFolders.size() > 0) {
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.info("Folders offered by Server:");
}
@ -237,12 +241,14 @@ public class HelloClient extends DataHandler.FromServer {
//desc contains the fileCache sent from the server, load the local version to get hold of the actual file cache on the client
SyncFolderDescriptor localDescriptor = AutoSync.getSyncFolderDescriptor(desc.folderID);
if (localDescriptor != null) {
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.info(" - " + desc.folderID + " (" + desc.localFolder + ", allowRemove=" + desc.removeAdditionalFiles + ")");
localDescriptor.invalidateCache();
desc.relativeFilesStream()
.filter(desc::discardChildElements)
.forEach(subFile -> {
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.warning(" * " + subFile.relPath + " (REJECTED)");
});
@ -259,6 +265,7 @@ public class HelloClient extends DataHandler.FromServer {
))
.collect(Collectors.toList());
if (Configs.MAIN_CONFIG.verboseLogging())
additionalFiles.forEach(aid -> BCLib.LOGGER.info(" * " + desc.localFolder.relativize(aid.relFile.toPath()) + " (missing on server)"));
filesToRemove.addAll(additionalFiles);
}
@ -270,16 +277,19 @@ public class HelloClient extends DataHandler.FromServer {
if (localSubFile != null) {
//the file exists locally, check if the hashes match
if (!localSubFile.hash.equals(subFile.hash)) {
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.info(" * " + subFile.relPath + " (changed)");
filesToRequest.add(new AutoSyncID.ForDirectFileRequest(
desc.folderID,
new File(subFile.relPath)
));
} else {
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.info(" * " + subFile.relPath);
}
} else {
//the file is missing locally
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.info(" * " + subFile.relPath + " (missing on client)");
filesToRequest.add(new AutoSyncID.ForDirectFileRequest(
desc.folderID,
@ -291,6 +301,7 @@ public class HelloClient extends DataHandler.FromServer {
//free some memory
localDescriptor.invalidateCache();
} else {
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.info(" - " + desc.folderID + " (Failed to find)");
}
});
@ -301,6 +312,7 @@ public class HelloClient extends DataHandler.FromServer {
final boolean debugHashes = Configs.CLIENT_CONFIG.shouldPrintDebugHashes();
if (autoSyncedFiles.size() > 0) {
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.info("Files offered by Server:");
}
@ -328,7 +340,7 @@ public class HelloClient extends DataHandler.FromServer {
));
}
}
if (Configs.MAIN_CONFIG.verboseLogging()) {
BCLib.LOGGER.info(" - " + e + ": " + actionString);
if (debugHashes) {
BCLib.LOGGER.info(" * " + e.serverHash + " (Server)");
@ -337,6 +349,7 @@ public class HelloClient extends DataHandler.FromServer {
}
}
}
}
@Environment(EnvType.CLIENT)
@ -349,6 +362,7 @@ public class HelloClient extends DataHandler.FromServer {
final boolean clientOnly = nfo != null && nfo.metadata.getEnvironment() == ModEnvironment.CLIENT;
final boolean requestMod = !clientOnly && !serverInfo.version.equals(localVersion) && serverInfo.size > 0 && serverInfo.canDownload;
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.info(" - " + e.getKey() + " (client=" + localVersion + ", server=" + serverInfo.version + ", size=" + PathUtil.humanReadableFileSize(
serverInfo.size) + (requestMod ? ", requesting" : "") + (serverInfo.canDownload
? ""

View file

@ -73,10 +73,12 @@ public class RequestFiles extends DataHandler.FromClient {
int size = buf.readInt();
files = new ArrayList<>(size);
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.info("Client requested " + size + " Files:");
for (int i = 0; i < size; i++) {
AutoSyncID asid = AutoSyncID.deserializeData(buf);
files.add(asid);
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.info(" - " + asid);
}

View file

@ -81,9 +81,11 @@ public class SendFiles extends DataHandler.FromServer {
writeString(buf, token);
buf.writeInt(existingFiles.size());
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.info("Sending " + existingFiles.size() + " Files to Client:");
for (AutoFileSyncEntry entry : existingFiles) {
int length = entry.serializeContent(buf);
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.info(" - " + entry + " (" + PathUtil.humanReadableFileSize(length) + ")");
}
}
@ -105,6 +107,7 @@ public class SendFiles extends DataHandler.FromServer {
int size = buf.readInt();
receivedFiles = new ArrayList<>(size);
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.info("Server sent " + size + " Files:");
for (int i = 0; i < size; i++) {
Triple<AutoFileSyncEntry, byte[], AutoSyncID> p = AutoFileSyncEntry.deserializeContent(buf);
@ -122,8 +125,10 @@ public class SendFiles extends DataHandler.FromServer {
} else {
type = "Ignoring ";
}
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.info(" - " + type + p.first + " (" + PathUtil.humanReadableFileSize(p.second.length) + ")");
} else {
if (Configs.MAIN_CONFIG.verboseLogging())
BCLib.LOGGER.error(" - Failed to receive File " + p.third + ", possibly sent from a Mod that is not installed on the client.");
}
}

View file

@ -131,10 +131,12 @@ public class SyncFolderDescriptor {
buf.writeBoolean(removeAdditionalFiles);
buf.writeInt(fileCache.size());
fileCache.forEach(fl -> {
if (Configs.MAIN_CONFIG.verboseLogging()) {
BCLib.LOGGER.info(" - " + fl.relPath);
if (debugHashes) {
BCLib.LOGGER.info(" " + fl.hash);
}
}
fl.serialize(buf);
});
}