DirectoryDeltaTransfer Plugin¶
The DirectoryDeltaTransfer plugin synchronizes directory contents between systems by only transferring files that differ. It computes file hashes to identify changes and transfers only modified or new files.
Basic Usage¶
Server-side (file host):
#include "mafianet/DirectoryDeltaTransfer.h"
MafiaNet::DirectoryDeltaTransfer ddt;
MafiaNet::FileListTransfer flt;
peer->AttachPlugin(&ddt);
peer->AttachPlugin(&flt);
// Set the directory to serve
ddt.SetFileListTransferPlugin(&flt);
ddt.SetApplicationDirectory("./game_assets");
// Add subdirectories to sync
ddt.AddUploadsFromSubdirectory("textures");
ddt.AddUploadsFromSubdirectory("models");
ddt.AddUploadsFromSubdirectory("sounds");
Client-side (receiver):
class MySyncCallback : public MafiaNet::FileListTransferCBInterface {
public:
bool OnFile(OnFileStruct* ofs) override {
printf("Synced: %s (%d bytes)\n",
ofs->fileName, ofs->byteLengthOfThisFile);
return true;
}
void OnFileProgress(FileProgressStruct* fps) override {
float percent = (float)fps->partCount /
(float)fps->partTotal * 100.0f;
printf("Downloading: %.1f%%\n", percent);
}
};
MySyncCallback callback;
ddt.SetFileListTransferPlugin(&flt);
ddt.SetApplicationDirectory("./local_assets");
// Request sync from server
ddt.DownloadFromSubdirectory("textures", "./local_assets/textures",
true, serverAddress, &callback,
MafiaNet::Priority::High, 0, false);
Key Features¶
Hash-based file comparison (only transfers changed files)
Recursive directory synchronization
Support for file additions, modifications, and deletions
Bandwidth-efficient incremental updates
Progress tracking for each file
Configurable file filtering
Configuration Options¶
SetApplicationDirectory()- Set base directory pathAddUploadsFromSubdirectory()- Add directory to serveDownloadFromSubdirectory()- Request directory syncClearUploads()- Remove all upload directoriesGenerateHashes()- Pre-compute file hashes
Ordering Channel¶
The downloading side passes the channel to DownloadFromSubdirectory(); the serving side sets it with SetUploadSendParameters(), which otherwise uploads on channel 0. Use a channel nothing else sends on: a transfer is ReliableOrdered, and a lost chunk holds back every later message on its channel until it is retransmitted. See Ordering Channels.
See Also¶
FileListTransfer Plugin - Underlying file transfer
Autopatcher Plugin - Full patching solution
StringCompressor - Data compression