9#ifndef SNBMODULES_INCLUDE_SNBMODULES_TRANSFER_CLIENT_HPP_
10#define SNBMODULES_INCLUDE_SNBMODULES_TRANSFER_CLIENT_HPP_
44 const std::string& client_id,
45 const std::filesystem::path& listening_dir,
46 const std::string& connection_prefix =
"snbmodules",
47 int timeout_send = 10,
48 int timeout_receive = 100);
55 bool start(
int timeout);
60 bool do_work(std::atomic<bool>& running_flag);
69 const std::string& protocol,
70 const std::set<std::string>& dest_clients,
71 const std::set<std::filesystem::path>& files,
72 const nlohmann::json& protocol_options = nlohmann::json());
91 const std::filesystem::path& work_dir,
93 const std::set<std::string>& dest_clients = std::set<std::string>());
101 std::filesystem::path folder = std::filesystem::path());
119 std::string file_path_str = listening_dir.string();
120 std::string x =
"./";
124 pos = file_path_str.find(x, pos);
125 if (pos == std::string::npos) {
129 file_path_str.replace(pos, x.length(),
"");
155 std::string
generate_session_id(
const std::string& transferid,
const std::string& dest =
"");
173 void share_available_files(
const std::set<std::filesystem::path>& to_share,
const std::string& dest);
TransferClient class, represent a client that can create session and communicate with Bookkeepers....
const std::vector< TransferSession > & get_sessions() const
void create_new_transfer(const std::string &transfer_id, const std::string &protocol, const std::set< std::string > &dest_clients, const std::set< std::filesystem::path > &files, const nlohmann::json &protocol_options=nlohmann::json())
Create a new transfer.
std::string m_client_id
TransferClient ID, unique identifier of the client.
void cancel_transfer(const std::string &transfer_id)
std::string get_client_id() const
TransferSession & create_session(GroupMetadata transfer_options, e_session_type type, std::string id, const std::filesystem::path &work_dir, IPFormat ip=IPFormat(), const std::set< std::string > &dest_clients=std::set< std::string >())
Create a new session, you can precise the IP address of the session forcing to use a specific network...
void start_transfer(const std::string &transfer_id)
Start, pause, resume or cancel a transfer.
TransferClient(const IPFormat &listening_ip, const std::string &client_id, const std::filesystem::path &listening_dir, const std::string &connection_prefix="snbmodules", int timeout_send=10, int timeout_receive=100)
TransferClient constructor.
std::string get_my_conn()
TransferSession * get_session(std::string transfer_id)
std::filesystem::path m_listening_dir
Listening directory, directory where the client will listen for incoming files and files to share.
void set_ip(const std::string &ip)
void remove_session(const std::string &session_id)
Add a session to the client.
std::map< std::string, std::shared_ptr< TransferMetadata > > m_available_files
Map of available files (key = file path, value = file metadata)
std::filesystem::path get_listening_dir() const
void set_client_id(std::string client_id)
void scan_available_files(std::set< std::filesystem::path > &previous_scan, bool nested=false, std::filesystem::path folder=std::filesystem::path())
Scan available files in the listening directory.
bool start(int timeout)
Start the client in curent thread.
std::string m_my_conn
Connection uuid of the client, retrieved using the notification interface and calling get_my_conn()
std::vector< TransferSession > m_sessions
Map of active sessions (key = session ID, value = session)
void share_available_files(const std::set< std::filesystem::path > &to_share, const std::string &dest)
Share available files (in m_listening_dir)
void set_listening_dir(const std::filesystem::path &listening_dir)
void pause_transfer(const std::string &transfer_id)
std::shared_ptr< TransferMetadata > create_metadata_from_file(const std::filesystem::path &src)
Create a metadata from a file.
std::vector< TransferSession > & get_sessions()
std::string generate_session_id(const std::string &transferid, const std::string &dest="")
Function to generate session ID.
void resume_transfer(const std::string &transfer_id)
IPFormat m_listening_ip
IP address of the client.
bool do_work(std::atomic< bool > &running_flag)
Start function to use in a thread.
bool action_on_receive_notification(NotificationData notif) override
Action to do when the client receive a notification.
TransferSession class contained in a client, is a wrapper for a transfer. extend notification interfa...
e_session_type
Different type of session.
NotificationData class, represent a notification.