mirror of
https://git.tesses.org/tesses50/tessesframework.git
synced 2026-06-01 18:15:31 +00:00
Overhaul cmake configuration, add console api, fix http code that caused issues with cgi-bin
This commit is contained in:
@@ -1,70 +1,98 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "../Serialization/Bencode.hpp"
|
||||
#include "TorrentStream.hpp"
|
||||
namespace Tesses::Framework::BitTorrent
|
||||
{
|
||||
constexpr int DEFAULT_PIECE_LENGTH = 524288;
|
||||
|
||||
class TorrentFileInfo {
|
||||
|
||||
Serialization::Bencode::BeDictionary info;
|
||||
public:
|
||||
TorrentFileInfo();
|
||||
TorrentFileInfo(const Serialization::Bencode::BeDictionary& tkn);
|
||||
|
||||
|
||||
int64_t piece_length=DEFAULT_PIECE_LENGTH;
|
||||
Serialization::Bencode::BeString pieces;
|
||||
int64_t isPrivate=0;
|
||||
Serialization::Bencode::BeString name;
|
||||
std::variant<int64_t, std::vector<TorrentFileEntry>> fileListOrLength;
|
||||
int64_t GetTorrentFileSize();
|
||||
/// @brief Generate the info
|
||||
/// @return the dictionary containing the info
|
||||
Serialization::Bencode::BeDictionary& GenerateInfoDictionary();
|
||||
/// @brief Get the info hash for info (if you are filling out the fields, you need to call GenerateInfoDictionary first)
|
||||
/// @return the 20 byte info hash
|
||||
Serialization::Bencode::BeString GetInfoHash();
|
||||
/// @brief Get the info (does not regenerate info from the fields)
|
||||
/// @return the dictionary containing the info
|
||||
Serialization::Bencode::BeDictionary& GetInfoDictionary();
|
||||
namespace Tesses::Framework::BitTorrent {
|
||||
constexpr int DEFAULT_PIECE_LENGTH = 524288;
|
||||
|
||||
/// @brief Used to load a dictionary in, will overwrite all the fields
|
||||
/// @param dict the dictionary to load
|
||||
void Load(const Serialization::Bencode::BeDictionary& dict);
|
||||
/// @brief Gets a read write based on this info object
|
||||
/// @param vfs the vfs object
|
||||
/// @param path file or directory inside vfs
|
||||
/// @return The read write at object
|
||||
std::shared_ptr<ReadWriteAt> GetStreamFromFilesystem(std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs, const Tesses::Framework::Filesystem::VFSPath& path);
|
||||
class TorrentFileInfo {
|
||||
|
||||
/// @brief Create info from file/directory
|
||||
/// @param vfs the vfs object
|
||||
/// @param path file or directory inside vfs
|
||||
/// @param isPrivate whether you use private trackers
|
||||
/// @param pieceLength length of pieces
|
||||
void CreateFromFilesystem(std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs, const Tesses::Framework::Filesystem::VFSPath& path, bool isPrivate=false, int64_t pieceLength=DEFAULT_PIECE_LENGTH);
|
||||
};
|
||||
class TorrentFile {
|
||||
public:
|
||||
TorrentFile();
|
||||
TorrentFile(const Serialization::Bencode::BeDictionary& tkn);
|
||||
Serialization::Bencode::BeDictionary info;
|
||||
|
||||
public:
|
||||
TorrentFileInfo();
|
||||
TorrentFileInfo(const Serialization::Bencode::BeDictionary &tkn);
|
||||
|
||||
Serialization::Bencode::BeString announce;
|
||||
std::vector<Serialization::Bencode::BeString> announce_list;
|
||||
std::vector<Serialization::Bencode::BeString> url_list;
|
||||
Serialization::Bencode::BeString comment;
|
||||
Serialization::Bencode::BeString created_by;
|
||||
int64_t creation_date=0;
|
||||
TorrentFileInfo info;
|
||||
int64_t piece_length = DEFAULT_PIECE_LENGTH;
|
||||
Serialization::Bencode::BeString pieces;
|
||||
int64_t isPrivate = 0;
|
||||
Serialization::Bencode::BeString name;
|
||||
std::variant<int64_t, std::vector<TorrentFileEntry>> fileListOrLength;
|
||||
int64_t GetTorrentFileSize();
|
||||
/// @brief Generate the info
|
||||
/// @return the dictionary containing the info
|
||||
Serialization::Bencode::BeDictionary &GenerateInfoDictionary();
|
||||
/// @brief Get the info hash for info (if you are filling out the fields,
|
||||
/// you need to call GenerateInfoDictionary first)
|
||||
/// @return the 20 byte info hash
|
||||
Serialization::Bencode::BeString GetInfoHash();
|
||||
/// @brief Get the info (does not regenerate info from the fields)
|
||||
/// @return the dictionary containing the info
|
||||
Serialization::Bencode::BeDictionary &GetInfoDictionary();
|
||||
|
||||
/// @brief Used to load a dictionary in, will overwrite all the fields
|
||||
/// @param dict the dictionary to load
|
||||
void Load(const Serialization::Bencode::BeDictionary &dict);
|
||||
/// @brief Gets a read write based on this info object
|
||||
/// @param vfs the vfs object
|
||||
/// @param path file or directory inside vfs
|
||||
/// @return The read write at object
|
||||
std::shared_ptr<ReadWriteAt> GetStreamFromFilesystem(
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs,
|
||||
const Tesses::Framework::Filesystem::VFSPath &path);
|
||||
|
||||
Serialization::Bencode::BeDictionary ToDictionary();
|
||||
/// @brief Create info from file/directory
|
||||
/// @param vfs the vfs object
|
||||
/// @param path file or directory inside vfs
|
||||
/// @param isPrivate whether you use private trackers
|
||||
/// @param pieceLength length of pieces
|
||||
void CreateFromFilesystem(
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs,
|
||||
const Tesses::Framework::Filesystem::VFSPath &path,
|
||||
bool isPrivate = false, int64_t pieceLength = DEFAULT_PIECE_LENGTH);
|
||||
};
|
||||
class TorrentFile {
|
||||
public:
|
||||
TorrentFile();
|
||||
TorrentFile(const Serialization::Bencode::BeDictionary &tkn);
|
||||
|
||||
void Print(std::shared_ptr<TextStreams::TextWriter> writer);
|
||||
Serialization::Bencode::BeString announce;
|
||||
std::vector<Serialization::Bencode::BeString> announce_list;
|
||||
std::vector<Serialization::Bencode::BeString> url_list;
|
||||
Serialization::Bencode::BeString comment;
|
||||
Serialization::Bencode::BeString created_by;
|
||||
int64_t creation_date = 0;
|
||||
TorrentFileInfo info;
|
||||
|
||||
static void CreateTorrent(std::shared_ptr<Tesses::Framework::Streams::Stream> torrent_file_stream,const std::vector<Serialization::Bencode::BeString>& trackers,const std::vector<Serialization::Bencode::BeString>& webseeds, std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs, const Tesses::Framework::Filesystem::VFSPath& path, bool isPrivate=false, int64_t pieceLength=DEFAULT_PIECE_LENGTH, Serialization::Bencode::BeString comment="", Serialization::Bencode::BeString created_by = "TessesFrameworkTorrent");
|
||||
|
||||
};
|
||||
}
|
||||
Serialization::Bencode::BeDictionary ToDictionary();
|
||||
|
||||
void Print(std::shared_ptr<TextStreams::TextWriter> writer);
|
||||
|
||||
static void CreateTorrent(
|
||||
std::shared_ptr<Tesses::Framework::Streams::Stream> torrent_file_stream,
|
||||
const std::vector<Serialization::Bencode::BeString> &trackers,
|
||||
const std::vector<Serialization::Bencode::BeString> &webseeds,
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs,
|
||||
const Tesses::Framework::Filesystem::VFSPath &path,
|
||||
bool isPrivate = false, int64_t pieceLength = DEFAULT_PIECE_LENGTH,
|
||||
Serialization::Bencode::BeString comment = "",
|
||||
Serialization::Bencode::BeString created_by = "TessesFrameworkTorrent");
|
||||
};
|
||||
} // namespace Tesses::Framework::BitTorrent
|
||||
@@ -1,46 +1,68 @@
|
||||
/*
|
||||
TessesFramework a library to make C++ easier for me, used in CrossLang:
|
||||
https://git.tesses.org/tesses50/crosslang Copyright (C) 2026 Mike Nolan
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "TessesFramework/Http/HttpClient.hpp"
|
||||
#include "TessesFramework/Streams/NetworkStream.hpp"
|
||||
namespace Tesses::Framework::BitTorrent
|
||||
{
|
||||
class TorrentFileEntry {
|
||||
public:
|
||||
TorrentFileEntry();
|
||||
TorrentFileEntry(Tesses::Framework::Filesystem::VFSPath path, int64_t length);
|
||||
Tesses::Framework::Filesystem::VFSPath path;
|
||||
int64_t length=0;
|
||||
};
|
||||
class ReadWriteAt {
|
||||
public:
|
||||
virtual bool ReadBlockAt(uint64_t offset, uint8_t* data, size_t len)=0;
|
||||
virtual void WriteBlockAt(uint64_t offset, const uint8_t* data, size_t len)=0;
|
||||
virtual ~ReadWriteAt();
|
||||
namespace Tesses::Framework::BitTorrent {
|
||||
class TorrentFileEntry {
|
||||
public:
|
||||
TorrentFileEntry();
|
||||
TorrentFileEntry(Tesses::Framework::Filesystem::VFSPath path,
|
||||
int64_t length);
|
||||
Tesses::Framework::Filesystem::VFSPath path;
|
||||
int64_t length = 0;
|
||||
};
|
||||
class ReadWriteAt {
|
||||
public:
|
||||
virtual bool ReadBlockAt(uint64_t offset, uint8_t *data, size_t len) = 0;
|
||||
virtual void WriteBlockAt(uint64_t offset, const uint8_t *data,
|
||||
size_t len) = 0;
|
||||
virtual ~ReadWriteAt();
|
||||
};
|
||||
|
||||
};
|
||||
class TorrentFileStream : public ReadWriteAt {
|
||||
Tesses::Framework::Threading::Mutex mtx;
|
||||
|
||||
class TorrentFileStream : public ReadWriteAt
|
||||
{
|
||||
Tesses::Framework::Threading::Mutex mtx;
|
||||
public:
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||
Tesses::Framework::Filesystem::VFSPath path;
|
||||
uint64_t length;
|
||||
TorrentFileStream(std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs, Tesses::Framework::Filesystem::VFSPath path, uint64_t length);
|
||||
bool ReadBlockAt(uint64_t offset, uint8_t* data, size_t len);
|
||||
void WriteBlockAt(uint64_t offset, const uint8_t* data, size_t len);
|
||||
public:
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||
Tesses::Framework::Filesystem::VFSPath path;
|
||||
uint64_t length;
|
||||
TorrentFileStream(std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs,
|
||||
Tesses::Framework::Filesystem::VFSPath path,
|
||||
uint64_t length);
|
||||
bool ReadBlockAt(uint64_t offset, uint8_t *data, size_t len);
|
||||
void WriteBlockAt(uint64_t offset, const uint8_t *data, size_t len);
|
||||
};
|
||||
class TorrentDirectoryStream : public ReadWriteAt {
|
||||
|
||||
};
|
||||
class TorrentDirectoryStream : public ReadWriteAt
|
||||
{
|
||||
std::vector<Tesses::Framework::Threading::Mutex> mtxs;
|
||||
|
||||
std::vector<Tesses::Framework::Threading::Mutex> mtxs;
|
||||
public:
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||
Tesses::Framework::Filesystem::VFSPath path;
|
||||
std::vector<TorrentFileEntry> entries;
|
||||
TorrentDirectoryStream(std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs, Tesses::Framework::Filesystem::VFSPath path,std::vector<TorrentFileEntry> entries);
|
||||
bool ReadBlockAt(uint64_t offset, uint8_t* data, size_t len);
|
||||
void WriteBlockAt(uint64_t offset, const uint8_t* data, size_t len);
|
||||
};
|
||||
}
|
||||
public:
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs;
|
||||
Tesses::Framework::Filesystem::VFSPath path;
|
||||
std::vector<TorrentFileEntry> entries;
|
||||
TorrentDirectoryStream(
|
||||
std::shared_ptr<Tesses::Framework::Filesystem::VFS> vfs,
|
||||
Tesses::Framework::Filesystem::VFSPath path,
|
||||
std::vector<TorrentFileEntry> entries);
|
||||
bool ReadBlockAt(uint64_t offset, uint8_t *data, size_t len);
|
||||
void WriteBlockAt(uint64_t offset, const uint8_t *data, size_t len);
|
||||
};
|
||||
} // namespace Tesses::Framework::BitTorrent
|
||||
Reference in New Issue
Block a user