Skip to content

Commit

Permalink
clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
John-LittleBearLabs committed Oct 10, 2024
1 parent 7bd0a3f commit 0e710d5
Showing 39 changed files with 563 additions and 366 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -8,3 +8,4 @@ gotit.json
.kdev4/ipfs-chromium.kdev4
*.autosave.*
*.autosave
compile_commands.json
5 changes: 3 additions & 2 deletions cmake/patch.py
Original file line number Diff line number Diff line change
@@ -189,7 +189,8 @@ def apply(self):
verbose(f"{to_path} already copied")
verbose("Done patching")

def edit_evidence(text):
@staticmethod
def edit_evidence(text: str):
for tok in ['ipfs', 'ReadTagContent', 'SetTag(']:
if tok in text:
return True
@@ -519,7 +520,7 @@ def list_ood(self, to_check: list[str], sense: bool, both: bool = False):


if __name__ == "__main__":
chromium_src_dir = join(os.environ['CHROMIUM_SOURCE_TREE'], 'src')
chromium_src_dir = os.environ['CHROMIUM_SOURCE_TREE']
if len(argv) < 2:
print("Give an argument to indicate what you'd like to do.")
elif argv[1] == "apply":
53 changes: 14 additions & 39 deletions library/.clang-tidy
Original file line number Diff line number Diff line change
@@ -1,41 +1,14 @@
Checks: '-*,
bugprone-a*,
bugprone-b*,
bugprone-dangling-handle,
bugprone-forward-declaration-namespace,
bugprone-inaccurate-erase,
bugprone-string-constructor,
bugprone-string-integer-assignment,
bugprone-undefined-memory-manipulation,
bugprone-unique-ptr-array-mismatch,
bugprone-unused-raii,
bugprone-use-after-move,
bugprone-virtual-near-miss,
google-build-explicit-make-pair,
google-default-arguments,
google-explicit-constructor,
google-objc-avoid-nsobject-new,
google-upgrade-googletest-case,
misc-misleading-identifier,
misc-homoglyph,
modernize-avoid-bind,
modernize-concat-nested-namespaces,
modernize-loop-convert,
modernize-make-shared,
modernize-make-unique,
modernize-redundant-void-arg,
modernize-replace-random-shuffle,
modernize-shrink-to-fit,
modernize-use-bool-literals,
modernize-use-default-member-init,
modernize-use-emplace,
modernize-use-equals-default,
modernize-use-equals-delete,
modernize-use-noexcept,
modernize-use-nullptr,
modernize-use-override,
modernize-use-transparent-functors,
readability-redundant-member-init'
Checks: 'bu*,
-bugprone-reserved-identifier,
mi*,
-misc-const-correctness,
-misc-header-include-cycle,
-misc-no-recursion,
mo*,
re*,
-readability-container-size-empty,
-readability-else-after-return,
-readability-named-parameter'
CheckOptions:
- key: bugprone-assert-side-effect.AssertMacros
value: assert,DCHECK
@@ -54,5 +27,7 @@
# https://groups.google.com/a/chromium.org/g/cxx/c/noMMTNYiM0w .
- key: modernize-use-emplace.IgnoreImplicitConstructors
value: 1
WarningsAsErrors: '*'
CompileFlags:
Add: -Wno-unknown-warning-option
Remove: -fprofile-abs-path
...
1 change: 0 additions & 1 deletion library/include/ipfs_client/ctx/dns_txt_lookup.cc

This file was deleted.

2 changes: 1 addition & 1 deletion library/include/ipfs_client/ctx/dns_txt_lookup.h
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ class DnsTxtLookup {
DnsTextResultsCallback,
DnsTextCompleteCallback) = 0;

virtual ~DnsTxtLookup() noexcept {}
virtual ~DnsTxtLookup() noexcept;
};
} // namespace ipfs::ctx

8 changes: 4 additions & 4 deletions library/include/ipfs_client/gw/gateway_request.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#ifndef IPFS_TRUSTLESS_REQUEST_H_
#define IPFS_TRUSTLESS_REQUEST_H_

#include <ipfs_client/ipld/block_source.h>
#include "gateway_request_type.h"

#include <ipfs_client/ipld/block_source.h>
#include <ipfs_client/cid.h>
#include <ipfs_client/client.h>

#include <vocab/flat_mapset.h>
#include <vocab/slash_delimited.h>

#include <iosfwd>
#include <memory>
#include <optional>
#include <string>
#include "gateway_request_type.h"
#include <unordered_set>

namespace ipfs {
class IpfsRequest;
@@ -62,7 +62,7 @@ class GatewayRequest : public std::enable_shared_from_this<GatewayRequest> {
std::optional<Cid> cid;
short parallel = 0;
std::string affinity;
flat_set<std::string> failures;
std::unordered_set<std::string> failures;

std::string url_suffix() const;
std::string_view accept() const;
2 changes: 1 addition & 1 deletion library/include/ipfs_client/gw/requestor.h
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ class Requestor : public std::enable_shared_from_this<Requestor> {

virtual HandleOutcome handle(RequestPtr) = 0;

void definitive_failure(RequestPtr) const;
static void definitive_failure(RequestPtr) ;
void forward(RequestPtr) const;

std::shared_ptr<Client> api_;
21 changes: 15 additions & 6 deletions library/src/ipfs_client/car.cc
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
#include "car.h"

#include <ipfs_client/client.h>
#include "ipfs_client/ctx/cbor_parser.h"

#include <libp2p/multi/uvarint.hpp>
#include <vocab/byte.h>
#include "vocab/byte_view.h"

#include "log_macros.h"

#include <cassert>
#include <cstdint>

#include <numeric>
#include <utility>
#include <optional>

using Self = ipfs::Car;
using Byte = ipfs::Byte;
using ByteView = ipfs::ByteView;
using VarInt = libp2p::multi::UVarint;

namespace {
short ReadHeader(ByteView&, ipfs::ctx::CborParser&);
std::pair<std::uint64_t, std::uint64_t> GetV1PayloadPos(ByteView);
auto ReadHeader(ByteView& /*bytes*/, ipfs::ctx::CborParser& /*cbor_parser*/) -> short;
auto GetV1PayloadPos(ByteView /*bytes*/) -> std::pair<std::uint64_t, std::uint64_t>;
} // namespace

Self::Car(ByteView bytes, ctx::CborParser& cbor_parser) {
@@ -71,7 +79,7 @@ auto Self::NextBlock() -> std::optional<Block> {

namespace {
// https://ipld.io/specs/transport/car/carv2/
short ReadHeader(ByteView& bytes, ipfs::ctx::CborParser& cbor_parser) {
auto ReadHeader(ByteView& bytes, ipfs::ctx::CborParser& cbor_parser) -> short {
auto header_len = VarInt::create(bytes);
if (!header_len ||
header_len->toUInt64() + header_len->size() > bytes.size()) {
@@ -90,19 +98,20 @@ short ReadHeader(ByteView& bytes, ipfs::ctx::CborParser& cbor_parser) {
auto version = version_node->as_unsigned();
if (version) {
bytes = bytes.subspan(header_len->toUInt64());
return version.value();
assert(version.value() < 0x8000U);
return static_cast<short>(version.value());
}
return 0;
}
std::uint64_t read_le_u64(ByteView bytes, unsigned& off) {
auto read_le_u64(ByteView bytes, unsigned& off) -> std::uint64_t {
auto b = bytes.subspan(off, off + 8);
off += 8U;
auto shift_in = [](std::uint64_t i, Byte y) {
return (i << 8) | static_cast<unsigned>(y);
};
return std::accumulate(b.rbegin(), b.rend(), 0UL, shift_in);
}
std::pair<std::uint64_t, std::uint64_t> GetV1PayloadPos(ByteView bytes) {
auto GetV1PayloadPos(ByteView bytes) -> std::pair<std::uint64_t, std::uint64_t> {
// Following the 11 byte pragma, the CARv2 [header] is a fixed-length sequence
// of 40 bytes, broken into the following sections:
if (bytes.size() < 40) {
53 changes: 35 additions & 18 deletions library/src/ipfs_client/client.cc
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
#include <ipfs_client/client.h>
#include <memory>
#include <openssl/evp.h>
#include <optional>
#include <vector>
#include <string>
#include <string_view>
#include <utility>

#include "crypto/openssl_sha2_256.h"
#include "ipfs_client/crypto/openssl_signature_verifier.h"
#include "ipfs_client/crypto/identity_hasher.h"
#include "ipfs_client/ctx/boost_beast_http.h"
#include "ipfs_client/crypto/signing_key_type.h"
#include "ipfs_client/crypto/signature_verifier.h"
#include "ipfs_client/ctx/http_api.h"
#include "ipfs_client/ctx/dns_txt_lookup.h"
#include "ipfs_client/ctx/gateway_config.h"
#include "ipfs_client/ctx/json_parser.h"
#include "ipfs_client/ctx/cbor_parser.h"
#include "ipfs_client/ctx/nlohmann_cbor_parser.h"
#include "ipfs_client/ctx/nlohmann_json_parser.h"
#include "ipfs_client/ctx/null_dns_txt_lookup.h"
#include "ipfs_client/ctx/null_http_provider.h"
#include "ipfs_client/ctx/transitory_gateway_config.h"
#include "ipfs_client/gw/default_requestor.h"

#include "ipfs_client/multi_hash.h"
#include "ipfs_client/json_cbor_adapter.h"
#include "ipfs_client/gw/requestor.h"
#include "ipfs_client/partition.h"
#include "ipfs_client/web_util.h"

#include "log_macros.h"
#include "vocab/byte.h"

using Self = ipfs::Client;

@@ -40,10 +57,10 @@ auto Self::Hash(HashType ht, ByteView data)
}
return it->second->hash(data);
}
bool Self::VerifyKeySignature(SigningKeyType typ,
auto Self::VerifyKeySignature(SigningKeyType typ,
ByteView signature,
ByteView data,
ByteView key_bytes) const {
ByteView key_bytes) const -> bool {
auto it = verifiers_.find(typ);
if (verifiers_.end() == it || !(it->second)) {
LOG(ERROR)
@@ -53,25 +70,25 @@ bool Self::VerifyKeySignature(SigningKeyType typ,
}
return it->second->VerifySignature(signature, data, key_bytes);
}
std::string Self::MimeType(std::string extension,
auto Self::MimeType(std::string extension,
std::string_view content,
std::string const& url) {
std::string const& url) -> std::string {
if (!deduce_mime_type_) {
LOG(WARNING) << "No mime-type deduction algo provided. Will do something "
"trivial/inaccurate.";
deduce_mime_type_ = util::TrivialMimeGuess;
}
return deduce_mime_type_(extension, content, url);
}
std::string Self::UnescapeUrlComponent(std::string_view url_comp) {
auto Self::UnescapeUrlComponent(std::string_view url_comp) -> std::string {
if (!unescape_) {
LOG(WARNING)
<< "No URL (un)escaping algo provided. Will do something simple/wrong.";
unescape_ = util::RoughlyUnescapeUrlComponent;
}
return unescape_(url_comp);
}
bool Self::DnslinkFallback() const {
auto Self::DnslinkFallback() const -> bool {
if (dns_fb_) {
return dns_fb_();
}
@@ -134,48 +151,48 @@ auto Self::requestor() -> std::shared_ptr<gw::Requestor> {
}
return rtor_;
}
Self& Self::with(std::unique_ptr<ctx::JsonParser> p) {
auto Self::with(std::unique_ptr<ctx::JsonParser> p) -> Self& {
json_parser_ = std::move(p);
return *this;
}
Self& Self::with(std::unique_ptr<ctx::CborParser> p) {
auto Self::with(std::unique_ptr<ctx::CborParser> p) -> Self& {
cbor_parser_ = std::move(p);
return *this;
}
Self& Self::with(std::unique_ptr<ctx::HttpApi> p) {
auto Self::with(std::unique_ptr<ctx::HttpApi> p) -> Self& {
http_api_ = std::move(p);
return *this;
}
Self& Self::with(std::unique_ptr<ctx::DnsTxtLookup> p) {
auto Self::with(std::unique_ptr<ctx::DnsTxtLookup> p) -> Self& {
dns_txt_ = std::move(p);
return *this;
}
Self& Self::with(SigningKeyType t,
std::unique_ptr<crypto::SignatureVerifier> p) {
auto Self::with(SigningKeyType t,
std::unique_ptr<crypto::SignatureVerifier> p) -> Self& {
if (p) {
verifiers_[t] = std::move(p);
} else {
verifiers_.erase(t);
}
return *this;
}
Self& Self::with(ipfs::Client::MimeTypeDeduction deduce_mime_type) {
auto Self::with(ipfs::Client::MimeTypeDeduction deduce_mime_type) -> Self& {
deduce_mime_type_ = deduce_mime_type;
return *this;
}
Self& Self::with(ipfs::Client::UrlUnescaping unescape) {
auto Self::with(ipfs::Client::UrlUnescaping unescape) -> Self& {
unescape_ = unescape;
return *this;
}
Self& Self::with(std::unique_ptr<ctx::GatewayConfig> p) {
auto Self::with(std::unique_ptr<ctx::GatewayConfig> p) -> Self& {
gateway_config_ = std::move(p);
return *this;
}
Self& Self::with(std::shared_ptr<gw::Requestor> p) {
auto Self::with(std::shared_ptr<gw::Requestor> p) -> Self& {
rtor_ = p;
return *this;
}
Self& Self::with(DnslinkFallbackSwitch sw) {
auto Self::with(DnslinkFallbackSwitch sw) -> Self& {
dns_fb_ = sw;
return *this;
}
Loading

0 comments on commit 0e710d5

Please sign in to comment.