Skip to content

Commit

Permalink
Move IPFS pinning related code behind local node build flag
Browse files Browse the repository at this point in the history
  • Loading branch information
kylehickinson committed Jan 25, 2023
1 parent 0db68db commit 2d5f62e
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
10 changes: 8 additions & 2 deletions components/brave_wallet/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ static_library("browser") {
"brave_wallet_p3a.h",
"brave_wallet_p3a_private.cc",
"brave_wallet_p3a_private.h",
"brave_wallet_pin_service.cc",
"brave_wallet_pin_service.h",
"brave_wallet_prefs.cc",
"brave_wallet_prefs.h",
"brave_wallet_provider_delegate.cc",
Expand Down Expand Up @@ -159,6 +157,14 @@ static_library("browser") {
"wallet_data_files_installer.cc",
"wallet_data_files_installer.h",
]

if (enable_ipfs_local_node) {
sources += [
"brave_wallet_pin_service.cc",
"brave_wallet_pin_service.h",
]
}

deps = [
":constants",
":generated_json_rpc_responses",
Expand Down
2 changes: 2 additions & 0 deletions components/ipfs/ipfs_json_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ bool RemoveValueFromList(base::Value::List* root, const T& value_to_remove) {

} // namespace

#if BUILDFLAG(ENABLE_IPFS_LOCAL_NODE)
// static
// Response format /api/v0/pin/add
// {
Expand Down Expand Up @@ -158,6 +159,7 @@ absl::optional<ipfs::GetPinsResult> IPFSJSONParser::GetGetPinsResultFromJSON(

return result;
}
#endif // BUILDFLAG(ENABLE_IPFS_LOCAL_NODE)

// static
// Response Format for /api/v0/swarm/peers
Expand Down
8 changes: 7 additions & 1 deletion components/ipfs/ipfs_json_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@

#include "base/values.h"
#include "brave/components/ipfs/addresses_config.h"
#include "brave/components/ipfs/buildflags/buildflags.h"
#include "brave/components/ipfs/import/imported_data.h"
#include "brave/components/ipfs/node_info.h"
#include "brave/components/ipfs/pin/ipfs_pin_rpc_types.h"
#include "brave/components/ipfs/repo_stats.h"

#if BUILDFLAG(ENABLE_IPFS_LOCAL_NODE)
#include "brave/components/ipfs/pin/ipfs_pin_rpc_types.h"
#endif

class IPFSJSONParser {
public:
static bool GetPeersFromJSON(const base::Value& json_value,
Expand Down Expand Up @@ -47,13 +51,15 @@ class IPFSJSONParser {
static std::string RemovePeerFromConfigJSON(const std::string& json,
const std::string& peer_id,
const std::string& address);
#if BUILDFLAG(ENABLE_IPFS_LOCAL_NODE)
// Local pins
static absl::optional<ipfs::AddPinResult> GetAddPinsResultFromJSON(
const base::Value& value);
static absl::optional<ipfs::GetPinsResult> GetGetPinsResultFromJSON(
const base::Value& value);
static absl::optional<ipfs::RemovePinResult> GetRemovePinsResultFromJSON(
const base::Value& value);
#endif
};

#endif // BRAVE_COMPONENTS_IPFS_IPFS_JSON_PARSER_H_
2 changes: 2 additions & 0 deletions components/ipfs/ipfs_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,7 @@ void IpfsService::OnPreWarmComplete(
std::move(prewarm_callback_for_testing_).Run();
}

#if BUILDFLAG(ENABLE_IPFS_LOCAL_NODE)
//{
// "PinLsList": {
// "Keys": {
Expand Down Expand Up @@ -1052,6 +1053,7 @@ void IpfsService::OnPinRemoveResult(

std::move(callback).Run(std::move(parse_result));
}
#endif // BUILDFLAG(ENABLE_IPFS_LOCAL_NODE)

void IpfsService::ValidateGateway(const GURL& url, BoolCallback callback) {
GURL::Replacements replacements;
Expand Down
10 changes: 9 additions & 1 deletion components/ipfs/ipfs_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "brave/components/ipfs/ipfs_dns_resolver.h"
#include "brave/components/ipfs/ipfs_p3a.h"
#include "brave/components/ipfs/node_info.h"
#include "brave/components/ipfs/pin/ipfs_pin_rpc_types.h"
#include "brave/components/ipfs/repo_stats.h"
#include "brave/components/services/ipfs/public/mojom/ipfs_service.mojom.h"
#include "components/keyed_service/core/keyed_service.h"
Expand All @@ -36,6 +35,10 @@
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "url/gurl.h"

#if BUILDFLAG(ENABLE_IPFS_LOCAL_NODE)
#include "brave/components/ipfs/pin/ipfs_pin_rpc_types.h"
#endif

namespace base {
class CommandLine;
class Process;
Expand Down Expand Up @@ -82,12 +85,15 @@ class IpfsService : public KeyedService,
base::OnceCallback<void(bool, const ipfs::NodeInfo&)>;
using GarbageCollectionCallback =
base::OnceCallback<void(bool, const std::string&)>;

#if BUILDFLAG(ENABLE_IPFS_LOCAL_NODE)
// Local pins
using AddPinCallback = base::OnceCallback<void(absl::optional<AddPinResult>)>;
using RemovePinCallback =
base::OnceCallback<void(absl::optional<RemovePinResult>)>;
using GetPinsCallback =
base::OnceCallback<void(absl::optional<GetPinsResult>)>;
#endif

using BoolCallback = base::OnceCallback<void(bool)>;
using GetConfigCallback = base::OnceCallback<void(bool, const std::string&)>;
Expand Down Expand Up @@ -209,6 +215,7 @@ class IpfsService : public KeyedService,
#endif
base::TimeDelta CalculatePeersRetryTime();

#if BUILDFLAG(ENABLE_IPFS_LOCAL_NODE)
// Local pins
void OnGetPinsResult(APIRequestList::iterator iter,
GetPinsCallback callback,
Expand All @@ -219,6 +226,7 @@ class IpfsService : public KeyedService,
void OnPinRemoveResult(APIRequestList::iterator iter,
RemovePinCallback callback,
api_request_helper::APIRequestResult response);
#endif

void OnGatewayValidationComplete(SimpleURLLoaderList::iterator iter,
BoolCallback callback,
Expand Down
1 change: 1 addition & 0 deletions components/ipfs/pin/ipfs_local_pin_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include "brave/components/ipfs/ipfs_service.h"
#include "brave/components/ipfs/pin/ipfs_base_pin_service.h"
#include "brave/components/ipfs/pin/ipfs_pin_rpc_types.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

using ipfs::IpfsService;
Expand Down

0 comments on commit 2d5f62e

Please sign in to comment.