Skip to content

Commit 1e08815

Browse files
committed
pr fixes
Signed-off-by: elestrias <[email protected]>
1 parent 16b8cd5 commit 1e08815

File tree

7 files changed

+41
-32
lines changed

7 files changed

+41
-32
lines changed

core/api/rpc/wsc.cpp

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ namespace fc::api::rpc {
3737
return connect(ip, port, target, token);
3838
}
3939

40-
outcome::result<void> Client::connect(const std::string &host,
41-
const std::string &port,
42-
const std::string &target,
43-
const std::string &token) {
40+
outcome::result<void> Client::connect(const std::string &host,
41+
const std::string &port,
42+
const std::string &target,
43+
const std::string &token) {
4444
boost::system::error_code ec;
4545
socket->next_layer().connect({boost::asio::ip::make_address(host),
46-
boost::lexical_cast<uint16_t>(port)},
47-
ec);
46+
boost::lexical_cast<uint16_t>(port)},
47+
ec);
4848
if (ec) {
4949
return ec;
5050
}
@@ -92,19 +92,19 @@ namespace fc::api::rpc {
9292
}
9393

9494
void Client::_flush() {
95-
if (!writing && !write_queue.empty() && not reconnecting){
95+
if (!writing && !write_queue.empty() && not reconnecting) {
9696
auto &[id, buffer] = write_queue.front();
9797
writing = true;
9898
socket->async_write(boost::asio::buffer(buffer.data(), buffer.size()),
99-
[=](auto &&ec, auto) {
100-
std::lock_guard lock{mutex};
101-
if (ec) {
102-
return _error(ec);
103-
}
104-
writing = false;
105-
write_queue.pop();
106-
_flush();
107-
});
99+
[=](auto &&ec, auto) {
100+
std::lock_guard lock{mutex};
101+
if (ec) {
102+
return _error(ec);
103+
}
104+
writing = false;
105+
write_queue.pop();
106+
_flush();
107+
});
108108
}
109109
}
110110

@@ -189,23 +189,34 @@ namespace fc::api::rpc {
189189
}
190190

191191
void Client::reconnect(int counter, std::chrono::milliseconds wait) {
192-
if(reconnecting) return;
192+
if (reconnecting) return;
193193
reconnecting = true;
194-
logger_->info("Starting reconnect to {}:{}", client_data.host, client_data.port);
195-
for(int i = 0; i < counter; i++){
194+
bool rec_status{false};
195+
logger_->info(
196+
"Starting reconnect to {}:{}", client_data.host, client_data.port);
197+
for (int i = 0; i < counter; i++) {
196198
std::this_thread::sleep_for(wait);
197199
socket.reset();
198200
socket.emplace(io);
199201
auto res = connect(client_data.host,
200202
client_data.port,
201203
client_data.target,
202204
client_data.token);
203-
if(!res.has_error()) {
205+
if (not res.has_error()) {
206+
rec_status = true;
204207
break;
205208
}
206209
}
207210
reconnecting = false;
208-
logger_->info("Reconnect to {}:{} was successful", client_data.host, client_data.port);
209-
_flush();
211+
if (rec_status) {
212+
logger_->info("Reconnect to {}:{} was successful",
213+
client_data.host,
214+
client_data.port);
215+
_flush();
216+
} else {
217+
logger_->error("Reconnect to {}:{} have been failed",
218+
client_data.host,
219+
client_data.port);
220+
}
210221
}
211222
} // namespace fc::api::rpc

core/sector_storage/impl/local_worker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ namespace fc::sector_storage {
904904

905905
return call_id;
906906
}
907-
void LocalWorker::ping(std::function<void(const bool &resp)> cb) {
907+
void LocalWorker::ping(std::function<void(bool resp)> cb) {
908908
cb(true);
909909
}
910910
} // namespace fc::sector_storage

core/sector_storage/impl/local_worker.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ namespace fc::sector_storage {
9999
outcome::result<std::vector<primitives::StoragePath>> getAccessiblePaths()
100100
override;
101101

102-
void ping(std::function<void(const bool &resp)> cb) override;
102+
void ping(std::function<void(bool resp)> cb) override;
103103

104104
private:
105105
template <typename W, typename R>

core/sector_storage/impl/remote_worker.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,7 @@ namespace fc::sector_storage {
255255
return api_.Fetch(sector, file_type, path_type, mode);
256256
}
257257

258-
void RemoteWorker::ping(std::function<void(const bool &resp)> cb) {
259-
api_.Version([=](auto res){
260-
cb(!res.has_error());
261-
});
258+
void RemoteWorker::ping(std::function<void(bool resp)> cb) {
259+
api_.Version([=](auto res) { cb(!res.has_error()); });
262260
}
263261
} // namespace fc::sector_storage

core/sector_storage/impl/remote_worker.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace fc::sector_storage {
3939
const SectorRef &sector,
4040
const PreCommit1Output &pre_commit_1_output) override;
4141

42-
void ping(std::function<void(const bool &resp)> cb) override;
42+
void ping(std::function<void(bool resp)> cb) override;
4343

4444
outcome::result<CallId> sealCommit1(const SectorRef &sector,
4545
const SealRandomness &ticket,

core/sector_storage/impl/scheduler_impl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,14 @@ namespace fc::sector_storage {
200200
std::future<WorkerID> wid_future = wid_promise.get_future();
201201
auto done = std::make_shared<std::atomic_bool>();
202202
for (const auto &cur : acceptable) {
203-
workers_[cur]->worker->ping([&wid_promise, done, cur](const bool &resp) {
203+
workers_[cur]->worker->ping([&wid_promise, done, cur](bool resp) {
204204
if (resp && !done->exchange(true)) {
205205
wid_promise.set_value(cur);
206206
}
207207
});
208208
}
209209
auto status = wid_future.wait_for(std::chrono::seconds(5));
210-
if(status == std::future_status::timeout){
210+
if (status == std::future_status::timeout) {
211211
return false;
212212
}
213213
WorkerID wid = wid_future.get();

core/sector_storage/worker.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ namespace fc::sector_storage {
143143
virtual outcome::result<std::vector<primitives::StoragePath>>
144144
getAccessiblePaths() = 0;
145145

146-
virtual void ping(std::function<void(const bool &resp)> cb) = 0;
146+
virtual void ping(std::function<void(bool resp)> cb) = 0;
147147
};
148148

149149
enum class CallErrorCode : uint64_t {

0 commit comments

Comments
 (0)