Skip to content

Commit

Permalink
Update default kubo config
Browse files Browse the repository at this point in the history
  • Loading branch information
cypt4 committed Mar 2, 2023
1 parent 6f0d206 commit 95b33ef
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 34 deletions.
1 change: 0 additions & 1 deletion components/services/ipfs/ipfs_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ void IpfsServiceImpl::Launch(mojom::IpfsConfigPtr config,
args.AppendArg("daemon");
args.AppendArg("--migrate=true");
args.AppendArg("--enable-gc");
args.AppendArg("--routing=dhtclient");

auto version = ipfs::GetVersionFromNodeFilename(
config->binary_path.BaseName().MaybeAsASCII());
Expand Down
14 changes: 11 additions & 3 deletions components/services/ipfs/ipfs_service_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ bool UpdateConfigJSON(const std::string& source,
"Addresses.Gateway",
base::StrCat({"/ip4/127.0.0.1/tcp/", config->gateway_port}));
dict->SetByDottedPath("Datastore.GCPeriod", "1h");
dict->SetByDottedPath("Swarm.ConnMgr.GracePeriod", "20s");
dict->SetByDottedPath("Swarm.ConnMgr.LowWater", 20);
dict->SetByDottedPath("Swarm.ConnMgr.HighWater", 40);
dict->SetByDottedPath("Datastore.StorageMax", config->storage_max);

base::Value::Dict localhost_gateway_settings;
Expand Down Expand Up @@ -79,8 +76,19 @@ bool UpdateConfigJSON(const std::string& source,

base::Value::List list;
list.Append(base::StrCat({"/ip4/0.0.0.0/tcp/", config->swarm_port}));
list.Append(base::ReplaceStringPlaceholders(
"/ip4/0.0.0.0/udp/$1/quic-v1/webtransport", {config->swarm_port},
nullptr));
list.Append(base::ReplaceStringPlaceholders("/ip4/0.0.0.0/udp/$1/quic-v1",
{config->swarm_port}, nullptr));
list.Append(base::ReplaceStringPlaceholders("/ip6/::/udp/$1/quic-v1",
{config->swarm_port}, nullptr));
list.Append(base::ReplaceStringPlaceholders(
"/ip6/::/udp/$1/quic-v1/webtransport", {config->swarm_port}, nullptr));
list.Append(base::StrCat({"/ip6/::/tcp/", config->swarm_port}));

dict->SetByDottedPath("Addresses.Swarm", std::move(list));
dict->RemoveByDottedPath("Swarm.ConnMgr");

std::string json_string;
if (!base::JSONWriter::Write(records_v.value(), &json_string) ||
Expand Down
69 changes: 39 additions & 30 deletions components/services/ipfs/ipfs_service_utils_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ TEST_F(IPFSServiceUtils, UpdateConfigJSONTest) {

std::string expect =
"{\"Addresses\":{\"API\":\"/ip4/127.0.0.1/tcp/APIPort\","
"\"Gateway\":\"/ip4/127.0.0.1/tcp/GatewayPort\",\"Swarm\":"
"[\"/ip4/0.0.0.0/tcp/SwarmPort\",\"/ip6/::/tcp/SwarmPort\""
"]},\"Datastore\":{\"GCPeriod\":\"1h\",\"StorageMax\":"
"\"Gateway\":\"/ip4/127.0.0.1/tcp/GatewayPort\","
"\"Swarm\":[\"/ip4/0.0.0.0/tcp/SwarmPort\",\"/ip4/0.0.0.0/udp/SwarmPort/"
"quic-v1/webtransport\","
"\"/ip4/0.0.0.0/udp/SwarmPort/quic-v1\",\"/ip6/::/udp/SwarmPort/"
"quic-v1\",\"/ip6/::/udp/SwarmPort/quic-v1/webtransport\",\"/ip6/::/tcp/"
"SwarmPort\"]},"
"\"Datastore\":{\"GCPeriod\":\"1h\",\"StorageMax\":"
"\"StorageSize\"},"
"\"Gateway\":{\"PublicGateways\":{\"localhost\":{\"InlineDNSLink\":true,"
"\"Paths\":[\"/ipfs\",\"/ipns\",\"/api\"],\"UseSubdomains\":true}}},"
"\"Swarm\":{\"ConnMgr\":{\"GracePeriod\":\"20s\","
"\"HighWater\":40,\"LowWater\":20}}}";
"\"Paths\":[\"/ipfs\",\"/ipns\",\"/api\"],\"UseSubdomains\":true}}}}";
ASSERT_TRUE(UpdateConfigJSON(json, config.get(), &updated));
EXPECT_EQ(updated, expect);
updated.clear();
Expand Down Expand Up @@ -80,17 +82,19 @@ TEST_F(IPFSServiceUtils, DNSResolversRemove) {

std::string expect =
"{\"Addresses\":{\"API\":\"/ip4/127.0.0.1/tcp/APIPort\","
"\"Gateway\":\"/ip4/127.0.0.1/tcp/GatewayPort\",\"Swarm\":"
"[\"/ip4/0.0.0.0/tcp/SwarmPort\",\"/ip6/::/tcp/SwarmPort\""
"]},\"DNS\":{\"Resolvers\":{\".\":\"https://cloudflare.com/"
"\"Gateway\":\"/ip4/127.0.0.1/tcp/GatewayPort\","
"\"Swarm\":[\"/ip4/0.0.0.0/tcp/SwarmPort\",\"/ip4/0.0.0.0/udp/"
"SwarmPort/quic-v1/webtransport\","
"\"/ip4/0.0.0.0/udp/SwarmPort/quic-v1\",\"/ip6/::/udp/SwarmPort/"
"quic-v1\",\"/ip6/::/udp/SwarmPort/quic-v1/webtransport\",\"/ip6/::/"
"tcp/SwarmPort\"]},"
"\"DNS\":{\"Resolvers\":{\".\":\"https://cloudflare.com/"
"dns-query\"}},"
"\"Datastore\":{\"GCPeriod\":\"1h\",\"StorageMax\":"
"\"StorageSize\"},"
"\"Gateway\":{\"PublicGateways\":{\"localhost\":{\"InlineDNSLink\":"
"true,\"Paths\":[\"/ipfs\",\"/ipns\",\"/"
"api\"],\"UseSubdomains\":true}}},"
"\"Swarm\":{\"ConnMgr\":{\"GracePeriod\":\"20s\","
"\"HighWater\":40,\"LowWater\":20}}}";
"api\"],\"UseSubdomains\":true}}}}";

EXPECT_TRUE(UpdateConfigJSON(json, config.get(), &updated));
EXPECT_EQ(updated, expect);
Expand All @@ -104,15 +108,16 @@ TEST_F(IPFSServiceUtils, DNSResolversRemove) {

std::string expect =
"{\"Addresses\":{\"API\":\"/ip4/127.0.0.1/tcp/APIPort\","
"\"Gateway\":\"/ip4/127.0.0.1/tcp/GatewayPort\",\"Swarm\":"
"[\"/ip4/0.0.0.0/tcp/SwarmPort\",\"/ip6/::/tcp/SwarmPort\""
"]},"
"\"Gateway\":\"/ip4/127.0.0.1/tcp/GatewayPort\","
"\"Swarm\":[\"/ip4/0.0.0.0/tcp/SwarmPort\",\"/ip4/0.0.0.0/udp/SwarmPort/"
"quic-v1/webtransport\","
"\"/ip4/0.0.0.0/udp/SwarmPort/quic-v1\",\"/ip6/::/udp/SwarmPort/"
"quic-v1\",\"/ip6/::/udp/SwarmPort/quic-v1/webtransport\",\"/ip6/::/tcp/"
"SwarmPort\"]},"
"\"Datastore\":{\"GCPeriod\":\"1h\",\"StorageMax\":"
"\"StorageSize\"},\"Gateway\":{\"PublicGateways\":{\"localhost\":{"
"\"InlineDNSLink\":true,\"Paths\":[\"/ipfs\",\"/ipns\",\"/"
"api\"],\"UseSubdomains\":true}}},"
"\"Swarm\":{\"ConnMgr\":{\"GracePeriod\":\"20s\","
"\"HighWater\":40,\"LowWater\":20}}}";
"api\"],\"UseSubdomains\":true}}}}";

EXPECT_TRUE(UpdateConfigJSON(json, config.get(), &updated));
ASSERT_EQ(updated, expect);
Expand All @@ -128,15 +133,17 @@ TEST_F(IPFSServiceUtils, DNSResolversUpdate) {

std::string expect =
"{\"Addresses\":{\"API\":\"/ip4/127.0.0.1/tcp/APIPort\","
"\"Gateway\":\"/ip4/127.0.0.1/tcp/GatewayPort\",\"Swarm\":"
"[\"/ip4/0.0.0.0/tcp/SwarmPort\",\"/ip6/::/tcp/SwarmPort\""
"]},\"DNS\":{\"Resolvers\":{\".\":\"https://cloudflare.com/dns-query\"}},"
"\"Gateway\":\"/ip4/127.0.0.1/tcp/GatewayPort\","
"\"Swarm\":[\"/ip4/0.0.0.0/tcp/SwarmPort\",\"/ip4/0.0.0.0/udp/SwarmPort/"
"quic-v1/webtransport\","
"\"/ip4/0.0.0.0/udp/SwarmPort/quic-v1\",\"/ip6/::/udp/SwarmPort/"
"quic-v1\",\"/ip6/::/udp/SwarmPort/quic-v1/webtransport\",\"/ip6/::/tcp/"
"SwarmPort\"]},"
"\"DNS\":{\"Resolvers\":{\".\":\"https://cloudflare.com/dns-query\"}},"
"\"Datastore\":{\"GCPeriod\":\"1h\",\"StorageMax\":"
"\"StorageSize\"},\"Gateway\":{\"PublicGateways\":{\"localhost\":{"
"\"InlineDNSLink\":true,\"Paths\":[\"/ipfs\",\"/ipns\",\"/"
"api\"],\"UseSubdomains\":true}}},"
"\"Swarm\":{\"ConnMgr\":{\"GracePeriod\":\"20s\","
"\"HighWater\":40,\"LowWater\":20}}}";
"api\"],\"UseSubdomains\":true}}}}";
ASSERT_TRUE(UpdateConfigJSON(json, config.get(), &updated));
EXPECT_EQ(updated, expect);
}
Expand All @@ -151,15 +158,17 @@ TEST_F(IPFSServiceUtils, DNSResolversUpdate_DnsHasRFC8484Template) {

std::string expect =
"{\"Addresses\":{\"API\":\"/ip4/127.0.0.1/tcp/APIPort\","
"\"Gateway\":\"/ip4/127.0.0.1/tcp/GatewayPort\",\"Swarm\":"
"[\"/ip4/0.0.0.0/tcp/SwarmPort\",\"/ip6/::/tcp/SwarmPort\""
"]},\"DNS\":{\"Resolvers\":{\".\":\"https://cloudflare.com/dns-query\"}},"
"\"Gateway\":\"/ip4/127.0.0.1/tcp/GatewayPort\","
"\"Swarm\":[\"/ip4/0.0.0.0/tcp/SwarmPort\",\"/ip4/0.0.0.0/udp/SwarmPort/"
"quic-v1/webtransport\","
"\"/ip4/0.0.0.0/udp/SwarmPort/quic-v1\",\"/ip6/::/udp/SwarmPort/"
"quic-v1\",\"/ip6/::/udp/SwarmPort/quic-v1/webtransport\",\"/ip6/::/tcp/"
"SwarmPort\"]},"
"\"DNS\":{\"Resolvers\":{\".\":\"https://cloudflare.com/dns-query\"}},"
"\"Datastore\":{\"GCPeriod\":\"1h\",\"StorageMax\":"
"\"StorageSize\"},"
"\"Gateway\":{\"PublicGateways\":{\"localhost\":{\"InlineDNSLink\":true,"
"\"Paths\":[\"/ipfs\",\"/ipns\",\"/api\"],\"UseSubdomains\":true}}},"
"\"Swarm\":{\"ConnMgr\":{\"GracePeriod\":\"20s\","
"\"HighWater\":40,\"LowWater\":20}}}";
"\"Paths\":[\"/ipfs\",\"/ipns\",\"/api\"],\"UseSubdomains\":true}}}}";
ASSERT_TRUE(UpdateConfigJSON(json, config.get(), &updated));
EXPECT_EQ(updated, expect);
}
Expand Down

0 comments on commit 95b33ef

Please sign in to comment.