start writing the reveive part
This commit is contained in:
parent
3e0100efdf
commit
c712afb7b2
@ -30,6 +30,9 @@ add_executable(tox_ngc_ft1_tool
|
||||
./states/send_start_sha1.hpp
|
||||
./states/send_start_sha1.cpp
|
||||
|
||||
./states/receive_start_sha1.hpp
|
||||
./states/receive_start_sha1.cpp
|
||||
|
||||
./states/sha1.hpp
|
||||
./states/sha1.cpp
|
||||
)
|
||||
|
@ -10,8 +10,8 @@
|
||||
struct SHA1Digest {
|
||||
std::array<uint8_t, 20> data;
|
||||
|
||||
SHA1Digest(void) = default;
|
||||
SHA1Digest(const std::vector<uint8_t>& v);
|
||||
|
||||
SHA1Digest(const uint8_t* d, size_t s);
|
||||
|
||||
bool operator==(const SHA1Digest& other) const { return data == other.data; }
|
||||
|
83
src/states/receive_start_sha1.cpp
Normal file
83
src/states/receive_start_sha1.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
#include "./receive_start_sha1.hpp"
|
||||
|
||||
#include "./sha1.hpp"
|
||||
|
||||
#include "../tox_utils.hpp"
|
||||
#include "../ft_sha1_info.hpp"
|
||||
|
||||
#include <mio/mio.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
|
||||
namespace States {
|
||||
|
||||
ReceiveStartSHA1::ReceiveStartSHA1(ToxClient& tcl, const CommandLine& cl) : StateI(tcl) {
|
||||
if (cl.receive_id.empty()) {
|
||||
throw std::runtime_error("receiver missing id");
|
||||
}
|
||||
|
||||
_sha1_info_hash = hex2bin(cl.receive_id);
|
||||
assert(_sha1_info_hash.size() == 20);
|
||||
|
||||
std::cout << "ReceiveStartSHA1 downloading info for " << cl.receive_id << "\n";
|
||||
}
|
||||
|
||||
bool ReceiveStartSHA1::iterate(float delta) {
|
||||
// TODO: return true if done
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<StateI> ReceiveStartSHA1::nextState(void) {
|
||||
std::cout << "ReceiveStartSHA1 switching state to SHA1\n";
|
||||
|
||||
FTInfoSHA1 sha1_info;
|
||||
// from buffer
|
||||
|
||||
// open file for writing (pre allocate?)
|
||||
mio::mmap_sink file_map;
|
||||
|
||||
std::vector<bool> have_chunk(sha1_info.chunks.size(), false);
|
||||
|
||||
return std::make_unique<SHA1>(
|
||||
_tcl,
|
||||
std::move(file_map),
|
||||
std::move(sha1_info),
|
||||
std::move(_sha1_info_data),
|
||||
std::move(_sha1_info_hash),
|
||||
std::move(have_chunk)
|
||||
);
|
||||
}
|
||||
|
||||
// sha1_info
|
||||
void ReceiveStartSHA1::onFT1ReceiveRequestSHA1Info(uint32_t group_number, uint32_t peer_number, const uint8_t* file_id, size_t file_id_size) {
|
||||
}
|
||||
|
||||
bool ReceiveStartSHA1::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) {
|
||||
// accept
|
||||
return true;
|
||||
}
|
||||
|
||||
void ReceiveStartSHA1::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 ReceiveStartSHA1::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 ReceiveStartSHA1::onFT1ReceiveRequestSHA1Chunk(uint32_t, uint32_t, const uint8_t*, size_t) {
|
||||
}
|
||||
|
||||
bool ReceiveStartSHA1::onFT1ReceiveInitSHA1Chunk(uint32_t, uint32_t, const uint8_t*, size_t, const uint8_t, const size_t) {
|
||||
return false; // nope, not interested in chunks yet
|
||||
}
|
||||
|
||||
void ReceiveStartSHA1::onFT1ReceiveDataSHA1Chunk(uint32_t, uint32_t, uint8_t, size_t, const uint8_t*, size_t) {
|
||||
}
|
||||
|
||||
void ReceiveStartSHA1::onFT1SendDataSHA1Chunk(uint32_t, uint32_t, uint8_t, size_t, uint8_t*, size_t) {
|
||||
}
|
||||
|
||||
} // States
|
||||
|
41
src/states/receive_start_sha1.hpp
Normal file
41
src/states/receive_start_sha1.hpp
Normal file
@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include "../state.hpp"
|
||||
|
||||
#include "../command_line.hpp"
|
||||
#include "../ft_sha1_info.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace States {
|
||||
|
||||
// we have the info hash and request the info until we have it
|
||||
struct ReceiveStartSHA1 final : public StateI {
|
||||
public: // general interface
|
||||
ReceiveStartSHA1(ToxClient& tcl, const CommandLine& cl);
|
||||
~ReceiveStartSHA1(void) override = default;
|
||||
|
||||
bool iterate(float delta) 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:
|
||||
//FTInfoSHA1 _sha1_info;
|
||||
std::vector<uint8_t> _sha1_info_data;
|
||||
SHA1Digest _sha1_info_hash; // treat as const
|
||||
};
|
||||
|
||||
} // States
|
||||
|
@ -11,7 +11,8 @@ SHA1::SHA1(
|
||||
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,
|
||||
//const std::vector<uint8_t>&& sha1_info_hash,
|
||||
const SHA1Digest&& sha1_info_hash,
|
||||
std::vector<bool>&& have_chunk
|
||||
) :
|
||||
StateI(tcl),
|
||||
|
@ -20,7 +20,8 @@ struct SHA1 final : public StateI {
|
||||
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,
|
||||
//const std::vector<uint8_t>&& sha1_info_hash,
|
||||
const SHA1Digest&& sha1_info_hash,
|
||||
std::vector<bool>&& have_chunk
|
||||
);
|
||||
~SHA1(void) override = default;
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "./tox_callbacks.hpp"
|
||||
|
||||
#include "./states/send_start_sha1.hpp"
|
||||
#include "./states/receive_start_sha1.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <sodium.h>
|
||||
@ -127,6 +128,7 @@ ToxClient::ToxClient(const CommandLine& cl) :
|
||||
if (!cl.send_path.empty()) {
|
||||
_state = std::make_unique<States::SendStartSHA1>(*this, cl);
|
||||
} else { // receiver
|
||||
_state = std::make_unique<States::ReceiveStartSHA1>(*this, cl);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user