Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/01-echo/libp2p_echo_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) {
// Additional logging config for application
logger_config));
auto r = logging_system->configure();
if (not r.message.empty()) {
if (!r.message.empty()) {
(r.has_error ? std::cerr : std::cout) << r.message << std::endl;
}
if (r.has_error) {
Expand Down
2 changes: 1 addition & 1 deletion example/01-echo/libp2p_echo_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ int main(int argc, char **argv) {
// Additional logging config for application
logger_config));
auto r = logging_system->configure();
if (not r.message.empty()) {
if (!r.message.empty()) {
(r.has_error ? std::cerr : std::cout) << r.message << std::endl;
}
if (r.has_error) {
Expand Down
14 changes: 7 additions & 7 deletions example/02-kademlia/rendezvous_chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class Session : public std::enable_shared_from_this<Session> {
stream_->readSome(
*incoming_,
[self = shared_from_this()](outcome::result<size_t> result) {
if (not result) {
if (!result) {
self->close();
std::cout << self->stream_->remotePeerId().value().toBase58()
<< " - closed at reading" << std::endl;
Expand All @@ -74,7 +74,7 @@ class Session : public std::enable_shared_from_this<Session> {
stream_,
*buffer,
[self = shared_from_this(), buffer](outcome::result<void> result) {
if (not result) {
if (!result) {
self->close();
std::cout << self->stream_->remotePeerId().value().toBase58()
<< " - closed at writting" << std::endl;
Expand Down Expand Up @@ -128,7 +128,7 @@ void handleIncomingStream(libp2p::StreamAndProtocol stream_and_protocol) {
}

void handleOutgoingStream(libp2p::StreamAndProtocolOrError stream_res) {
if (not stream_res) {
if (!stream_res) {
fmt::println(
std::cerr, " ! outgoing connection failed: {}", stream_res.error());
return;
Expand Down Expand Up @@ -178,7 +178,7 @@ int main(int argc, char *argv[]) {
// Additional logging config for application
logger_config));
auto r = logging_system->configure();
if (not r.message.empty()) {
if (!r.message.empty()) {
(r.has_error ? std::cerr : std::cout) << r.message << std::endl;
}
if (r.has_error) {
Expand Down Expand Up @@ -295,7 +295,7 @@ int main(int argc, char *argv[]) {
scheduler.schedule(std::function{find_providers},
kademlia_config.randomWalk.interval);

if (not res) {
if (!res) {
fmt::println(std::cerr, "Cannot find providers: {}", res.error());
return;
}
Expand All @@ -309,15 +309,15 @@ int main(int argc, char *argv[]) {

std::function<void()> provide = [&, content_id] {
[[maybe_unused]] auto res =
kademlia->provide(content_id, not kademlia_config.passiveMode);
kademlia->provide(content_id, !kademlia_config.passiveMode);

scheduler.schedule(std::function{provide},
kademlia_config.randomWalk.interval);
};

post(*io, [&] {
auto listen = host->listen(ma);
if (not listen) {
if (!listen) {
fmt::println(std::cerr,
"Cannot listen address {}. Error: {}",
ma.getStringAddress(),
Expand Down
2 changes: 1 addition & 1 deletion example/03-gossip/gossip_chat_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ int main(int argc, char *argv[]) {
// Additional logging config for application
logger_config));
auto r = logging_system->configure();
if (not r.message.empty()) {
if (!r.message.empty()) {
(r.has_error ? std::cerr : std::cout) << r.message << std::endl;
}
if (r.has_error) {
Expand Down
2 changes: 1 addition & 1 deletion example/04-dnstxt/ares_resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int main(int argc, char *argv[]) {
// Additional logging config for application
logger_config));
auto r = logging_system->configure();
if (not r.message.empty()) {
if (!r.message.empty()) {
(r.has_error ? std::cerr : std::cout) << r.message << std::endl;
}
if (r.has_error) {
Expand Down
2 changes: 1 addition & 1 deletion include/libp2p/basic/read.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace libp2p {
}
// read remaining bytes
auto reader = weak.lock();
if (not reader) {
if (!reader) {
return cb(make_error_code(boost::asio::error::operation_aborted));
}
read(reader, out.subspan(n), std::move(cb));
Expand Down
4 changes: 2 additions & 2 deletions include/libp2p/basic/scheduler/manual_scheduler_backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ namespace libp2p::basic {
* @return true if no more events scheduled
*/
bool empty() const {
return deferred_callbacks_.empty() and not timer_expires_;
return deferred_callbacks_.empty() and !timer_expires_;
}

void run() {
while (not empty()) {
while (!empty()) {
shiftToTimer();
}
}
Expand Down
2 changes: 1 addition & 1 deletion include/libp2p/basic/write.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace libp2p {
}
// write remaining bytes
auto writer = weak.lock();
if (not writer) {
if (!writer) {
return cb(make_error_code(boost::asio::error::operation_aborted));
}
write(writer, in.subspan(n), std::move(cb));
Expand Down
2 changes: 1 addition & 1 deletion include/libp2p/common/outcome_macro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define _IF_ERROR_CB_RETURN(tmp, r) \
({ \
auto &&_r = r; \
if (not _r.has_value()) { \
if (!_r.has_value()) { \
return cb(_r.error()); \
} \
_r.value(); \
Expand Down
2 changes: 1 addition & 1 deletion include/libp2p/injector/network_injector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ namespace libp2p::injector {
*/
inline auto useWssPem(std::string_view pem) {
layer::WssCertificate cert;
if (not pem.empty()) {
if (!pem.empty()) {
if (auto cert_res = layer::WssCertificate::make(pem)) {
cert = std::move(cert_res.value());
} else {
Expand Down
3 changes: 1 addition & 2 deletions include/libp2p/log/sublogger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ namespace libp2p::log {
private:
template <typename T>
auto makePrefix(std::string_view prefix, T instance) {
if constexpr (std::is_pointer_v<T>
and not std::is_same_v<T, const char *>) {
if constexpr (std::is_pointer_v<T> and !std::is_same_v<T, const char *>) {
auto ptr_as_int = reinterpret_cast<std::intptr_t>(instance); // NOLINT
return fmt::format("{}({:x}): ", prefix, ptr_as_int);
} else if constexpr (std::is_integral_v<T> and sizeof(T) > 1) {
Expand Down
6 changes: 3 additions & 3 deletions include/libp2p/transport/tcp/tcp_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace libp2p::transport::detail {
template <typename T>
outcome::result<T> as(bool udp) const {
auto ip = std::get_if<boost::asio::ip::address>(&this->ip);
if (this->udp != udp or not ip) {
if (this->udp != udp or !ip) {
return std::errc::protocol_not_supported;
}
return T{*ip, port};
Expand Down Expand Up @@ -128,7 +128,7 @@ namespace libp2p::transport::detail {
auto v = ma.getProtocolsWithValues();
auto it = v.begin();
OUTCOME_TRY(addr, readTcpOrUdp(it, v.end()));
if (not addr.udp) {
if (!addr.udp) {
return std::errc::protocol_not_supported;
}
if (it == v.end()) {
Expand Down Expand Up @@ -185,7 +185,7 @@ namespace libp2p::transport::detail {
const boost::asio::ip::tcp::endpoint &endpoint,
const ProtoAddrVec &layers) {
OUTCOME_TRY(s, toMultiaddr(endpoint));
if (not layers.empty()) {
if (!layers.empty()) {
auto &protocol = layers.at(0).first.code;
if (protocol == P::WS) {
s += "/ws";
Expand Down
2 changes: 1 addition & 1 deletion src/basic/scheduler/manual_scheduler_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace libp2p::basic {
}

void ManualSchedulerBackend::callDeferred() {
while (not deferred_callbacks_.empty()) {
while (!deferred_callbacks_.empty()) {
auto cb = std::move(deferred_callbacks_.front());
deferred_callbacks_.pop_front();
cb();
Expand Down
22 changes: 11 additions & 11 deletions src/basic/scheduler/scheduler_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ namespace libp2p::basic {
Callback &&cb,
std::chrono::milliseconds delay_from_now,
bool make_handle) {
if (not cb) {
if (!cb) {
throw std::logic_error{"SchedulerImpl::scheduleImpl empty cb arg"};
}

auto abs = Time::zero();
if (Time::zero() < delay_from_now) {
abs = backend_->now() + delay_from_now;
}
if (not make_handle) {
if (!make_handle) {
backend_->post(
[weak_self{weak_from_this()}, cb{std::move(cb)}, abs]() mutable {
auto self = weak_self.lock();
if (not self) {
if (!self) {
return;
}
self->callbacks_.emplace(abs, std::move(cb));
Expand All @@ -45,7 +45,7 @@ namespace libp2p::basic {
backend_->post(
[weak_self{weak_from_this()}, abs, cancel{std::move(cancel)}] {
auto self = weak_self.lock();
if (not self) {
if (!self) {
return;
}
if (cancel->cancelled.test()) {
Expand All @@ -57,26 +57,26 @@ namespace libp2p::basic {
return cancelFn(
[weak_self{weak_from_this()}, weak_cancel{std::move(weak_cancel)}] {
auto cancel = weak_cancel.lock();
if (not cancel) {
if (!cancel) {
return;
}
if (cancel->cancelled.test_and_set()) {
return;
}
auto self = weak_self.lock();
if (not self) {
if (!self) {
return;
}
self->backend_->post([weak_self, weak_cancel] {
auto cancel = weak_cancel.lock();
if (not cancel) {
if (!cancel) {
return;
}
if (not cancel->it) {
if (!cancel->it) {
return;
}
auto self = weak_self.lock();
if (not self) {
if (!self) {
return;
}
self->callbacks_.erase(*cancel->it);
Expand All @@ -86,7 +86,7 @@ namespace libp2p::basic {

void SchedulerImpl::pulse() {
callReady(Time::zero());
while (not callbacks_.empty()) {
while (!callbacks_.empty()) {
auto now = backend_->now();
if (callReady(now) != 0) {
continue;
Expand All @@ -103,7 +103,7 @@ namespace libp2p::basic {

size_t SchedulerImpl::callReady(Time now) {
size_t removed = 0;
while (not callbacks_.empty() and callbacks_.begin()->first <= now) {
while (!callbacks_.empty() and callbacks_.begin()->first <= now) {
auto node = callbacks_.extract(callbacks_.begin());
++removed;
if (auto cb = std::get_if<Callback>(&node.mapped())) {
Expand Down
4 changes: 2 additions & 2 deletions src/connection/loopback_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace libp2p::connection {
boost::asio::post(
ctx,
[wptr{std::move(wptr)}, cb{std::move(cb)}, arg{std::move(arg)}]() {
if (not wptr.expired()) {
if (!wptr.expired()) {
cb(arg);
}
});
Expand Down Expand Up @@ -154,7 +154,7 @@ namespace libp2p::connection {
}

// subscribe to new data updates
if (not data_notifyee_) {
if (!data_notifyee_) {
data_notifyee_ = std::move(read_lambda);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/hmac_provider/hmac_provider_ctr_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace libp2p::crypto::hmac {
}

outcome::result<void> HmacProviderCtrImpl::write(BytesIn data) {
if (not initialized_) {
if (!initialized_) {
return HmacProviderError::FAILED_INITIALIZE_CONTEXT;
}
if (1 != HMAC_Update(hmac_ctx_, data.data(), data.size())) {
Expand All @@ -62,7 +62,7 @@ namespace libp2p::crypto::hmac {
}

outcome::result<void> HmacProviderCtrImpl::digestOut(BytesOut out) const {
if (not initialized_) {
if (!initialized_) {
return HmacProviderError::FAILED_INITIALIZE_CONTEXT;
}
if (out.size() != digestSize()) {
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/sha/sha1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace libp2p::crypto {
}

outcome::result<void> Sha1::write(BytesIn data) {
if (not initialized_) {
if (!initialized_) {
return HmacProviderError::FAILED_INITIALIZE_CONTEXT;
}
if (1 != SHA1_Update(&ctx_, data.data(), data.size())) {
Expand All @@ -29,7 +29,7 @@ namespace libp2p::crypto {
}

outcome::result<void> Sha1::digestOut(BytesOut out) const {
if (not initialized_) {
if (!initialized_) {
return HmacProviderError::FAILED_INITIALIZE_CONTEXT;
}
if (out.size() != digestSize()) {
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/sha/sha256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace libp2p::crypto {
}

outcome::result<void> Sha256::write(BytesIn data) {
if (not initialized_) {
if (!initialized_) {
return HmacProviderError::FAILED_INITIALIZE_CONTEXT;
}
if (1 != SHA256_Update(&ctx_, data.data(), data.size())) {
Expand All @@ -31,7 +31,7 @@ namespace libp2p::crypto {
}

outcome::result<void> Sha256::digestOut(BytesOut out) const {
if (not initialized_) {
if (!initialized_) {
return HmacProviderError::FAILED_INITIALIZE_CONTEXT;
}
if (out.size() != digestSize()) {
Expand Down
4 changes: 2 additions & 2 deletions src/crypto/sha/sha512.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace libp2p::crypto {
}

outcome::result<void> Sha512::write(BytesIn data) {
if (not initialized_) {
if (!initialized_) {
return HmacProviderError::FAILED_INITIALIZE_CONTEXT;
}
if (1 != SHA512_Update(&ctx_, data.data(), data.size())) {
Expand All @@ -31,7 +31,7 @@ namespace libp2p::crypto {
}

outcome::result<void> Sha512::digestOut(BytesOut out) const {
if (not initialized_) {
if (!initialized_) {
return HmacProviderError::FAILED_INITIALIZE_CONTEXT;
}
if (out.size() != digestSize()) {
Expand Down
2 changes: 1 addition & 1 deletion src/host/basic_host/basic_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace libp2p::host {
}
}
}
if (not is_good_addr) {
if (!is_good_addr) {
i = unique_addresses.erase(i);
} else {
++i;
Expand Down
2 changes: 1 addition & 1 deletion src/layer/websocket/ws_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace libp2p::connection {
}

void WsConnection::stop() {
if (not started_) {
if (!started_) {
log_->error("already stopped (double stop)");
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/layer/websocket/wss_adaptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace libp2p::layer {
void WssAdaptor::upgradeInbound(
std::shared_ptr<connection::LayerConnection> conn,
LayerAdaptor::LayerConnCallbackFunc cb) const {
if (not server_certificate_.context) {
if (!server_certificate_.context) {
return cb(std::errc::address_family_not_supported);
}
auto ssl = std::make_shared<connection::SslConnection>(
Expand Down
Loading
Loading