Push failed torrent code as backup before I remove it

This commit is contained in:
2026-01-07 11:03:33 -06:00
parent 8b6801e608
commit 1d5ba40ef0
36 changed files with 2192 additions and 7 deletions

26
apps/printtorrent.cpp Normal file
View File

@@ -0,0 +1,26 @@
#include "TessesFramework/TessesFramework.hpp"
using namespace Tesses::Framework;
using namespace Tesses::Framework::Streams;
using namespace Tesses::Framework::Filesystem;
using namespace Tesses::Framework::Serialization::Bencode;
using namespace Tesses::Framework::TextStreams;
using namespace Tesses::Framework::BitTorrent;
int main(int argc, char** argv)
{
TF_Init();
if(argc < 2)
{
printf("USAGE: %s /path/to/torrent/file\n",argv[0]);
return 1;
}
auto strm = LocalFS->OpenFile((std::string)argv[1],"rb");
auto bencode = Bencode::Load(strm);
if(std::holds_alternative<BeDictionary>(bencode))
{
TorrentFile file(std::get<BeDictionary>(bencode));
file.Print(std::make_shared<ConsoleWriter>());
}
return 0;
}

22
apps/tclearwebseed.cpp Normal file
View File

@@ -0,0 +1,22 @@
#include "TessesFramework/TessesFramework.hpp"
using namespace Tesses::Framework;
using namespace Tesses::Framework::BitTorrent;
using namespace Tesses::Framework::Serialization::Bencode;
using namespace Tesses::Framework::Filesystem;
int main(int argc, char** argv)
{
TF_Init();
if(argc < 2)
{
printf("USAGE: %s torrent_file\n",argv[0]);
return 1;
}
auto strm = LocalFS->OpenFile((std::string)argv[1],"rb");
auto data = Bencode::Load(strm);
if(std::holds_alternative<BeDictionary>(data)){
std::get<BeDictionary>(data).SetValue("url-list",BeUndefined());
}
strm = LocalFS->OpenFile((std::string)argv[1],"wb");
Bencode::Save(strm,data);
return 0;
}

View File

@@ -0,0 +1,51 @@
#include "TessesFramework/TessesFramework.hpp"
using namespace Tesses::Framework;
using namespace Tesses::Framework::Streams;
using namespace Tesses::Framework::Filesystem;
using namespace Tesses::Framework::Serialization::Bencode;
using namespace Tesses::Framework::TextStreams;
using namespace Tesses::Framework::BitTorrent;
int percent(ActiveTorrent& torrent)
{
if(torrent.torrentSize == 0) return 100;
auto left = torrent.getLeft();
return 100-(int)(((double)left / (double)torrent.torrentSize)*100.0);
}
int main(int argc, char** argv)
{
TF_Init();
if(argc < 2)
{
printf("USAGE: %s /path/to/torrent/file\n",argv[0]);
return 1;
}
auto strm = LocalFS->OpenFile((std::string)argv[1],"rb");
auto bencode = Bencode::Load(strm);
if(std::holds_alternative<BeDictionary>(bencode))
{
TorrentFile file(std::get<BeDictionary>(bencode));
VFSPath path;
path.relative=true;
ActiveTorrent active(file,Filesystem::LocalFS,path,GeneratePeerId());
int lastPercent = 0;
std::cout << "0%" << std::endl;
while(TF_IsRunning())
{
active.process();
int cur=percent(active);
if(cur > lastPercent)
{
lastPercent = cur;
std::cout << "\r" << std::to_string(cur) << "%";
}
}
}
TF_Quit();
return 0;
}

36
apps/trng.cpp Normal file
View File

@@ -0,0 +1,36 @@
#include "TessesFramework/TessesFramework.hpp"
int main(int argc, char** argv)
{
if(argc < 2)
{
std::cout << "USAGE: " << argv[0] << " times" << std::endl;
std::cout << "USAGE: " << argv[0] << " times max" << std::endl;
std::cout << "USAGE: " << argv[0] << " times min max" << std::endl;
return 0;
}
Tesses::Framework::Random random;
int times=std::atoi(argv[1]);
if(argc > 2)
{
int32_t min = 0;
int32_t max = std::stoi(argv[2]);
if(argc > 3)
{
min = max;
max = std::stoi(argv[3]);
}
for(int i = 0; i < times; i++)
{
std::cout << random.Next(min,max) << std::endl;
}
}
else {
for(int i = 0; i < times; i++)
{
std::cout << random.Next() << std::endl;
}
}
}

66
apps/ttorrentcreate.cpp Normal file
View File

@@ -0,0 +1,66 @@
#include "TessesFramework/TessesFramework.hpp"
using namespace Tesses::Framework;
using namespace Tesses::Framework::Streams;
using namespace Tesses::Framework::Filesystem;
using namespace Tesses::Framework::Serialization::Bencode;
using namespace Tesses::Framework::TextStreams;
using namespace Tesses::Framework::BitTorrent;
void usage(Args& args)
{
std::cout << "USAGE: " << args.filename << " [options] torrent_contents torrent_file.torrent" << std::endl << std::endl;
std::cout << "OPTIONS:" << std::endl;
std::cout << "tracker: torrent tracker url (require at least one)" << std::endl;
std::cout << "webseed: url for web seeding" << std::endl;
std::cout << "comment: set the comment" << std::endl;
std::cout << "created_by: set the created by field, defaults to TessesFrameworkTorrent" << std::endl;
std::cout << "piece_length: set the piece length, defaults to " + std::to_string(DEFAULT_PIECE_LENGTH) << std::endl << std::endl;
std::cout << "FLAGS:" << std::endl;
std::cout << "help: bring this help message up" << std::endl;
std::cout << "private: enable private tracker flag" << std::endl;
exit(1);
}
int main(int argc, char** argv)
{
TF_Init();
std::vector<BeString> webseeds;
std::vector<BeString> trackers;
bool isPrivate=false;
int64_t pieceLength = DEFAULT_PIECE_LENGTH;
std::string comment="";
std::string created_by = "TessesFrameworkTorrent";
Args args(argc, argv);
if(args.positional.size() < 2)
usage(args);
for(auto& opt : args.options)
{
if(opt.first == "tracker")
trackers.push_back(opt.second);
else if(opt.first == "webseed")
webseeds.push_back(opt.second);
else if(opt.first == "comment")
comment = opt.second;
else if(opt.first == "created_by")
created_by = opt.second;
else if(opt.first == "piece_length")
pieceLength = std::stoll(opt.second);
}
for(auto& flag : args.flags)
{
if(flag == "help")
usage(args);
if(flag == "private")
isPrivate = true;
}
if(trackers.empty())
usage(args);
{
auto torrent_file_stream = LocalFS->OpenFile(args.positional[1],"wb");
TorrentFile::CreateTorrent(torrent_file_stream,trackers,webseeds,LocalFS, args.positional[0], isPrivate, pieceLength, comment, created_by);
}
return 0;
}