sha1 info running state

This commit is contained in:
Green Sky 2023-01-15 02:26:23 +01:00
parent 1dee83b01f
commit 0606db457b
No known key found for this signature in database
6 changed files with 128 additions and 10 deletions

View File

@ -24,8 +24,11 @@ add_executable(tox_ngc_ft1_tool
./state.hpp ./state.hpp
./states/state_send_start_sha1.hpp ./states/send_start_sha1.hpp
./states/state_send_start_sha1.cpp ./states/send_start_sha1.cpp
./states/sha1.hpp
./states/sha1.cpp
) )
target_compile_features(tox_ngc_ft1_tool PUBLIC cxx_std_17) target_compile_features(tox_ngc_ft1_tool PUBLIC cxx_std_17)

View File

@ -1,10 +1,13 @@
#include "./state_send_start_sha1.hpp" #include "./send_start_sha1.hpp"
#include "../tox_client.hpp" #include "../tox_client.hpp"
#include "../tox_utils.hpp" #include "../tox_utils.hpp"
#include "../hash_utils.hpp" #include "../hash_utils.hpp"
#include "../ft_sha1_info.hpp" #include "../ft_sha1_info.hpp"
#include "./sha1.hpp"
#include <memory>
#include <mio/mio.hpp> #include <mio/mio.hpp>
#include <iostream> #include <iostream>
@ -41,24 +44,31 @@ SendStartSHA1::SendStartSHA1(ToxClient& tcl, const CommandLine& cl) : StateI(tcl
_file_map = mio::make_mmap_source(cl.send_path, 0, mio::map_entire_file, err); _file_map = mio::make_mmap_source(cl.send_path, 0, mio::map_entire_file, err);
} }
std::cout << "SHA1Start chunks: " << _sha1_info.chunks.size() << "\n"; std::cout << "SendStartSHA1 chunks: " << _sha1_info.chunks.size() << "\n";
_sha1_info_data = _sha1_info.toBuffer(); _sha1_info_data = _sha1_info.toBuffer();
std::cout << "SHA1Start sha1_info size: " << _sha1_info_data.size() << "\n"; std::cout << "SendStartSHA1 sha1_info size: " << _sha1_info_data.size() << "\n";
_sha1_info_hash = hash_sha1(_sha1_info_data.data(), _sha1_info_data.size()); _sha1_info_hash = hash_sha1(_sha1_info_data.data(), _sha1_info_data.size());
std::cout << "SHA1Start sha1_info_hash: " << bin2hex(_sha1_info_hash) << "\n"; std::cout << "SendStartSHA1 sha1_info_hash: " << bin2hex(_sha1_info_hash) << "\n";
} }
bool SendStartSHA1::iterate(void) { bool SendStartSHA1::iterate(void) {
(void)_tcl._tox; return true; // TODO: change hashing to async
return false;
} }
std::unique_ptr<StateI> SendStartSHA1::nextState(void) { std::unique_ptr<StateI> SendStartSHA1::nextState(void) {
return nullptr; std::cout << "SendStartSHA1 switching state to SHA1\n";
// we are done setting up
return std::make_unique<SHA1>(
_tcl,
std::move(_file_map),
std::move(_sha1_info),
std::move(_sha1_info_data),
std::move(_sha1_info_hash)
);
} }
// sha1_info // sha1_info

57
src/states/sha1.cpp Normal file
View File

@ -0,0 +1,57 @@
#include "./sha1.hpp"
namespace States {
SHA1::SHA1(
ToxClient& tcl,
mio::mmap_source&& file_map,
const FTInfoSHA1&& sha1_info,
const std::vector<uint8_t>&& sha1_info_data,
const std::vector<uint8_t>&& sha1_info_hash
) :
StateI(tcl),
_file_map(std::move(file_map)),
_sha1_info(std::move(sha1_info)),
_sha1_info_data(std::move(sha1_info_data)),
_sha1_info_hash(std::move(sha1_info_hash))
{
}
bool SHA1::iterate(void) {
return false;
}
std::unique_ptr<StateI> SHA1::nextState(void) {
return nullptr;
}
// sha1_info
void SHA1::onFT1ReceiveRequestSHA1Info(uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size) {
}
bool SHA1::onFT1ReceiveInitSHA1Info(uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size, const uint8_t transfer_id, const size_t file_size) {
return false;
}
void SHA1::onFT1ReceiveDataSHA1Info(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, const uint8_t* data, size_t data_size) {
}
void SHA1::onFT1SendDataSHA1Info(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, uint8_t* data, size_t data_size) {
}
// sha1_chunk
void SHA1::onFT1ReceiveRequestSHA1Chunk(uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size) {
}
bool SHA1::onFT1ReceiveInitSHA1Chunk(uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size, const uint8_t transfer_id, const size_t file_size) {
return false;
}
void SHA1::onFT1ReceiveDataSHA1Chunk(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, const uint8_t* data, size_t data_size) {
}
void SHA1::onFT1SendDataSHA1Chunk(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, uint8_t* data, size_t data_size) {
}
} // States

48
src/states/sha1.hpp Normal file
View File

@ -0,0 +1,48 @@
#pragma once
#include "../state.hpp"
#include "../ft_sha1_info.hpp"
#include <mio/mio.hpp>
namespace States {
// we are either sending or receiving
// we have full info
struct SHA1 final : public StateI {
public: // general interface
SHA1(
ToxClient& tcl,
mio::mmap_source&& file_map,
const FTInfoSHA1&& sha1_info,
const std::vector<uint8_t>&& sha1_info_data,
const std::vector<uint8_t>&& sha1_info_hash
);
~SHA1(void) override = default;
bool iterate(void) override;
std::unique_ptr<StateI> nextState(void) override;
public: // callbacks
// sha1_info
void onFT1ReceiveRequestSHA1Info(uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size) override;
bool onFT1ReceiveInitSHA1Info(uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size, const uint8_t transfer_id, const size_t file_size) override;
void onFT1ReceiveDataSHA1Info(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, const uint8_t* data, size_t data_size) override;
void onFT1SendDataSHA1Info(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, uint8_t* data, size_t data_size) override;
// sha1_chunk
void onFT1ReceiveRequestSHA1Chunk(uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size) override;
bool onFT1ReceiveInitSHA1Chunk(uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size, const uint8_t transfer_id, const size_t file_size) override;
void onFT1ReceiveDataSHA1Chunk(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, const uint8_t* data, size_t data_size) override;
void onFT1SendDataSHA1Chunk(uint32_t group_number, uint32_t peer_number, uint8_t transfer_id, size_t data_offset, uint8_t* data, size_t data_size) override;
private:
mio::mmap_source _file_map;
const FTInfoSHA1 _sha1_info;
const std::vector<uint8_t> _sha1_info_data;
const std::vector<uint8_t> _sha1_info_hash;
};
} // States

View File

@ -3,7 +3,7 @@
#include "./tox_utils.hpp" #include "./tox_utils.hpp"
#include "./tox_callbacks.hpp" #include "./tox_callbacks.hpp"
#include "./states/state_send_start_sha1.hpp" #include "./states/send_start_sha1.hpp"
#include <memory> #include <memory>
#include <sodium.h> #include <sodium.h>