diff --git a/library/include/ipfs_client/gw/requestor.h b/library/include/ipfs_client/gw/requestor.h index 634c3673..0aba88b5 100644 --- a/library/include/ipfs_client/gw/requestor.h +++ b/library/include/ipfs_client/gw/requestor.h @@ -18,10 +18,7 @@ class GatewayRequest; using RequestPtr = std::shared_ptr; class Requestor : public std::enable_shared_from_this { - protected: - Requestor() {} - - friend class RequestorPool; + public: enum class HandleOutcome : char { NOT_HANDLED = 'N', PENDING = 'P', @@ -29,6 +26,10 @@ class Requestor : public std::enable_shared_from_this { PARALLEL = 'L', MAYBE_LATER = 'M' }; + + protected: + Requestor() {} + virtual HandleOutcome handle(RequestPtr) = 0; void definitive_failure(RequestPtr) const; diff --git a/library/src/ipfs_client/gw/multi_gateway_requestor.cc b/library/src/ipfs_client/gw/multi_gateway_requestor.cc index e1de2464..6d3c12a9 100644 --- a/library/src/ipfs_client/gw/multi_gateway_requestor.cc +++ b/library/src/ipfs_client/gw/multi_gateway_requestor.cc @@ -15,6 +15,9 @@ std::string_view Self::name() const { return "multi-gateway requestor"; } auto Self::handle(RequestPtr r) -> HandleOutcome { + if (!r || !api_) { + return HandleOutcome::DONE; + } if (!r->is_http()) { LOG(INFO) << r->debug_string() << " is not an HTTP request."; return HandleOutcome::NOT_HANDLED; diff --git a/library/src/ipfs_client/gw/multi_gateway_requestor_unittest.cc b/library/src/ipfs_client/gw/multi_gateway_requestor_unittest.cc new file mode 100644 index 00000000..c57140db --- /dev/null +++ b/library/src/ipfs_client/gw/multi_gateway_requestor_unittest.cc @@ -0,0 +1,21 @@ +#include "multi_gateway_requestor.h" + +#include + +#include + +namespace { +ig::RequestPtr block_req() { + auto rv = std::make_shared(); + rv->type = ig::Type::Block; + rv->main_param = + "bafybeid4dzlxm6h4r6kfvx6jp6vj4nteplmbve224lx2s3lgjubyufsuo4"; + return rv; +} +} // namespace + +TEST(MultiGatewayRequestor, FailsWithoutApi) { + ig::MultiGatewayRequestor t; + auto o = t.handle(block_req()); + EXPECT_TRUE(o == ig::Requestor::HandleOutcome::DONE); +} \ No newline at end of file diff --git a/test_data/blocks/QmU9HH6fsfUiy7isXZ8J6YEkkw3M1u11rD7TxjyY35keF1 b/test_data/blocks/QmU9HH6fsfUiy7isXZ8J6YEkkw3M1u11rD7TxjyY35keF1 deleted file mode 100644 index 7eb16a2d..00000000 --- a/test_data/blocks/QmU9HH6fsfUiy7isXZ8J6YEkkw3M1u11rD7TxjyY35keF1 +++ /dev/null @@ -1,2 +0,0 @@ - -Lu0 Lu1 Lu2 Lu3 Lu4 Lu5 Lu6 Lu7 Lu8 Lu9 Lv0 Lv1 Lv2 Lv3 Lv4 Lv5 Lv6 Lv7 Lv8 Lv9 Lw0 Lw1 Lw2 Lw3 Lw4 Lw5 Lw6 Lw7 Lw8 Lw9 Lx0 Lx1 Lx2 Lx3 Lx4 Lx5  \ No newline at end of file diff --git a/test_data/blocks/QmU9pWH3wBhM9RWMTpAqYj73NfJLK9ugTZMMy6VVUwAzQf b/test_data/blocks/QmU9pWH3wBhM9RWMTpAqYj73NfJLK9ugTZMMy6VVUwAzQf deleted file mode 100644 index a2fa4e06..00000000 Binary files a/test_data/blocks/QmU9pWH3wBhM9RWMTpAqYj73NfJLK9ugTZMMy6VVUwAzQf and /dev/null differ diff --git a/test_data/blocks/bafkreibthyfb4j4blugo5zk4i476hxet2vwghy564kz3jlxi53lnoamrum b/test_data/blocks/bafkreibthyfb4j4blugo5zk4i476hxet2vwghy564kz3jlxi53lnoamrum deleted file mode 100644 index 4fc3fe1c..00000000 --- a/test_data/blocks/bafkreibthyfb4j4blugo5zk4i476hxet2vwghy564kz3jlxi53lnoamrum +++ /dev/null @@ -1 +0,0 @@ -G \ No newline at end of file