14 buffer.write<int64_t>(offset);
15 buffer.write<int64_t>(offset + int64_t(size));
19 lock->read(
buffer.data, 9);
22 const int64_t until =
buffer.read<int64_t>();
24 if (until < offset || until > offset + int64_t(size))
27 const size_t returned_size = size_t(until - offset);
29 lock->read(data, returned_size);
63 log(
"checking hash, from = " + std::to_string(from) +
", until = " + std::to_string(until));
70 buffer.write<int64_t>(from);
71 buffer.write<int64_t>(until);
83 lock->read(
buffer.data, 1);
86 log(std::string(
"hash result: ") +
buffer.data[0]);
99 std::chrono::milliseconds wait
104 const char pull_type = char(
'D' +
int(lock_action) + 2*
int(data_transfer));
106 log(
"pulling, lock = " + std::to_string(
int(lock_action)) +
107 ", data = " + std::to_string(
int(data_transfer)) +
108 ", wait = " + std::to_string(
double(wait.count()) * 0.001) +
's');
111 buffer.write<
char>(pull_type);
112 buffer.write<int64_t>(wait.count());
113 buffer.write<int64_t>(client_journal.get_checkpoint());
117 lock->read(
buffer.data, 9);
119 const char reply =
buffer.read<
char>();
121 throw Disconnection(
"pull error: server is pull-only, cannot lock");
122 else if (reply != pull_type)
127 if (
bool(data_transfer))
131 Async_Writer writer = client_journal.get_async_tail_writer();
133 client_journal.soft_checkpoint_at(writer.
get_position());
136 log(
"!data_transfer");
153 const char push_type = char(
'N' +
int(unlock_action));
155 buffer.write<
char>(push_type);
156 buffer.write<int64_t>(from);
157 buffer.write<int64_t>(until);
160 Async_Reader reader = client_journal.get_async_reader(from, until);
164 std::string(
"pushing(") + push_type +
165 ")... from = " + std::to_string(from) +
166 ", until = " + std::to_string(until)
171 size_t offset =
buffer.index;
175 const size_t size = reader.
read(
buffer.data + offset,
buffer.size - offset);
178 lock->write(
buffer.data, size + offset);
184 lock->read(
buffer.data, 1);
186 if (
buffer.data[0] ==
'R')
188 else if (
buffer.data[0] ==
'C')
190 else if (
buffer.data[0] ==
't')
192 else if (
buffer.data[0] != push_type)
204 log(
"joedb::Server_Connection::unlock");
209 lock->write(
buffer.data, 1);
210 lock->read(
buffer.data, 1);
215 if (
buffer.data[0] !=
'M')
int64_t get_remaining() const
size_t read(char *buffer, size_t capacity)
bool is_end_of_file() const
int64_t get_position() const
static void content_mismatch()
Called by handshake when the file and the connection do not match.
joedb::Robust_Connection does not try to reconnect when thrown
bool print_remaining(int64_t remaining)
int64_t server_checkpoint
void log(beman::cstring_view message) noexcept override
Thread_Safe< Channel & > channel
void download(Async_Writer &writer, Lock< Channel & > &lock, int64_t size) const
int64_t pull(Lock_Action lock_action, Data_Transfer data_transfer, Writable_Journal &client_journal, std::chrono::milliseconds wait=std::chrono::milliseconds(0)) override
Pull from the connection.
void unlock() override
Unlock the connection.
int64_t handshake(const Readonly_Journal &client_journal, Content_Check content_check) override
Called during Client construction.
size_t pread(char *data, size_t size, int64_t offset) const
int64_t push(const Readonly_Journal &client_journal, int64_t from, int64_t until, Unlock_Action unlock_action) override
Push new data to the connection.
void check_matching_content(const Readonly_Journal &client_journal, Content_Check content_check, int64_t from, int64_t until) override
Compare content of file and connection. Throw if mismatch.
SHA_256::Hash get_full_hash(const Abstract_File &file, int64_t from, int64_t until)
SHA_256::Hash get_fast_hash(const Abstract_File &file, int64_t from, int64_t until)