Skip to content

Commit

Permalink
Start saving throttles
Browse files Browse the repository at this point in the history
As if they're preferences
Persist feedback loop
  • Loading branch information
John-LittleBearLabs committed Jan 29, 2024
1 parent c536783 commit 6c5a726
Show file tree
Hide file tree
Showing 157 changed files with 23,599 additions and 1,944 deletions.
81 changes: 81 additions & 0 deletions .github/tour.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash -ex
echo Clone tester repo.
git clone https://github.com/John-LittleBearLabs/ipfs_client_clitester.git

echo Install dependencies.
sudo apt-get update
sudo apt-get install --yes cmake ninja-build binutils libc6{,-dev}
pip3 install conan
conan profile detect || echo "Profile detection failed. Perhaps the default profile already existed - perhaps this user has already done some conan-based builds."

echo Build conan library
conan create --build=missing ipfs_chromium/library/

echo Configure clitester
mkdir tester_build
cmake \
-G Ninja \
-S ipfs_client_clitester \
-B tester_build \
-D CMAKE_BUILD_TYPE=Release

echo Build clitester
cmake --build tester_build --config Release

echo Start test server
( timeout 3600 python3 ./ipfs_chromium/test_data/test_server.py 8080 2>&1 | tee server.log & ) &
for t in 1{0..9}
do
if grep -n . server.log
then
break
elif curl -m $t 'http://localhost:8080/ping'
then
sleep 1
else
sleep ${t}
fi
done

function url_case() {
echo "url_case(" "${@}" ")"
if timeout 360 ./tester_build/clitester warning "${1}://${2}"
then
echo clitester exited with successful status
else
echo "Directly reported error code from clitester run - usually means timeout killed it. " "${@}"
exit 7
fi
n=`sed 's,[^A-Za-z0-9\.],_,g' <<< ${2}`
if cat "_${1}_${n}" | md5sum | cut -d ' ' -f 1 > actual
then
ls -lrth _ip?s_*
if [ $# -ge 3 ]
then
echo "${3}" > expected
if diff actual expected
then
echo good
else
echo "Got wrong result: " "${@}"
exit 8
fi
fi
else
grep -n . server.log || sleep 1
ls -lrth _ip?s_*
echo "Failure: ${*}"
exit 9
fi
}
url_case ipfs bafkqacdjmrsw45djor4q ff483d1ff591898a9942916050d2ca3f 'Identity (inlined) CID'
url_case ipfs baguqeerah2nswg7r2pvlpbnsz5y4c4pr4wsgbzixdl632w5qxvedqzryf54q 7750fd7b0928f007e1d181763c0dbdb5 'A DAG-JSON document. The block itself md5s to b92348005af4ae4795e6f312844fb359, but the response we are hashing here is an HTML preview page. This does mean this test breaks if you make the preview less ugly.'
url_case ipns en.wikipedia-on-ipfs.org/I/HFE_Too_Slow_1.JPG.webp 09c09b2654e8529740b5a7625e39e0c8 'An image fetched through DNSLink and HAMT sharded directories.'
url_case ipfs bafybeieb33pqideyl5ncd33kho622thym5rqv6sujrmelcuhkjlf2hdpu4/Big%20Buck%20Bunny.webm 06d51286e56badb4455594ebed6daba2 'A large UnixFS file - several hundred blocks.'
url_case ipns k51qzi5uqu5dijv526o4z2z10ejylnel0bfvrtw53itcmsecffo8yf0zb4g9gi/symlinks/relative_link.txt cfe9b69523140b5b5e63874a8e4997e4 'A relative symlink resolves successfully to the file pointed to.'
echo Stop test server.
killall python3 2>/dev/null || true
19 changes: 19 additions & 0 deletions .github/ut.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash -ex

echo Install dependencies
sudo apt-get update
sudo apt-get install --yes cmake ninja-build lcov binutils doxygen graphviz libc6{,-dev} valgrind
npm install -g @marp-team/marp-cli

echo Configure
mkdir build
cmake \
-G Ninja \
-S ipfs_chromium \
-B build \
-D CMAKE_BUILD_TYPE=Debug

echo Run Tests
cmake --build build --config Debug --target run_tests
echo Generate Coverage Report
cmake --build build --config Debug --target cov
23 changes: 17 additions & 6 deletions .github/workflows/library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,32 @@ on:
release:
types: [created]
jobs:
test:
uses: little-bear-labs/ipfs-chromium/.github/workflows/ut.yml@flows
tour:
uses: little-bear-labs/ipfs-chromium/.github/workflows/tour.yml@flows
prechecks:
runs-on: ubuntu-latest
steps:
- name: Checkout ipfs_chromium
uses: actions/checkout@v4
with:
path: 'ipfs_chromium'
- name: Run Unit Tests
run: ./ipfs_chromium/.github/ut.sh
- name: Tour de IPFS
run: ./ipfs_chromium/.github/tour.sh
- name: Upload coverage reports to Codecov.com
uses: codecov/codecov-action@v3
with:
files: build/library/cov.info
build:
name: ${{ matrix.config.name }}
needs: [test, tour]
needs: [prechecks]
runs-on: ${{ matrix.config.os }}
strategy:
fail-fast: true
matrix:
config:
- {
name: "macOS",
os: macos-12,
os: macos-latest,
build_type: "Release",
cc: "clang",
cxx: "clang++",
Expand Down
72 changes: 2 additions & 70 deletions .github/workflows/tour.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,74 +11,6 @@ jobs:
uses: actions/checkout@v4
with:
path: 'ipfs_chromium'
- name: Checkout ipfs_client_clitester
uses: actions/checkout@v4
with:
path: 'ipfs_client_clitester'
repository: 'John-LittleBearLabs/ipfs_client_clitester'
- name: Install dependencies
shell: bash
run: |
sudo apt-get update
sudo apt-get install --yes cmake ninja-build binutils libc6{,-dev}
pip3 install conan
conan profile detect
- name: Build conan_lib
run: |
conan create ipfs_chromium/library/
- name: Configure clitester
shell: bash
run: |
mkdir tester_build
set +e
cmake \
-G Ninja \
-S ipfs_client_clitester \
-B tester_build \
-D CMAKE_BUILD_TYPE=Release
- name: Build clitester
shell: bash
run: cmake --build tester_build --config Release
- name: Runit
shell: bash
run: |
set -ex
( timeout 3600 python3 ./ipfs_chromium/test_data/test_server.py 8080 2>&1 | tee server.log & ) &
for t in 1{0..9}
do
if grep -n . server.log
then
break
elif curl -m $t 'http://localhost:8080/ping'
then
sleep 1
else
sleep ${t}
fi
done
function url_case() {
echo "url_case(" "${@}" ")"
timeout 360 ./tester_build/clitester note "${1}://${2}"
n=`sed 's,[^A-Za-z0-9\.],_,g' <<< ${2}`
if cat "_${1}_${n}" | md5sum | cut -d ' ' -f 1 > actual
then
ls -lrth _ip?s_*
if [ $# -ge 3 ]
then
echo "${3}" > expected
diff actual expected
fi
else
grep -n . server.log || sleep 1
ls -lrth _ip?s_*
exit 9
fi
}
url_case ipfs bafkqacdjmrsw45djor4q ff483d1ff591898a9942916050d2ca3f
- name: Run committed script
run: ./ipfs_chromium/.github/tour.sh

true the block itself md5s to b92348005af4ae4795e6f312844fb359, but the response is an HTML preview page
url_case ipfs baguqeerah2nswg7r2pvlpbnsz5y4c4pr4wsgbzixdl632w5qxvedqzryf54q 7750fd7b0928f007e1d181763c0dbdb5
url_case ipns en.wikipedia-on-ipfs.org/I/HFE_Too_Slow_1.JPG.webp 8238a73ddb12e56f8f3879cc91d2739e
url_case ipfs bafybeieb33pqideyl5ncd33kho622thym5rqv6sujrmelcuhkjlf2hdpu4/Big%20Buck%20Bunny.webm 06d51286e56badb4455594ebed6daba2
killall python3 2>/dev/null || true
23 changes: 4 additions & 19 deletions .github/workflows/ut.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,11 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install --yes cmake ninja-build lcov binutils doxygen graphviz libc6{,-dev} valgrind
npm install -g @marp-team/marp-cli
- name: Configure
shell: bash
run: |
mkdir build
cmake \
-G Ninja \
-S . \
-B build \
-D CMAKE_BUILD_TYPE=Debug
- name: Run Tests
shell: bash
run: cmake --build build --config Debug --target run_tests
- name: Generate Coverage Report
with:
path: 'ipfs_chromium'
- name: Run versioned script
shell: bash
run: cmake --build build --config Debug --target cov
run: ./ipfs_chromium/.github/ut.sh
- name: Upload coverage reports to Codecov.com
uses: codecov/codecov-action@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions chromium_edits/120.0.6099.71/url/url_util.cc.patch

This file was deleted.

10 changes: 10 additions & 0 deletions chromium_edits/122.0.6170.3/chrome/browser/ipfs_extra_parts.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "ipfs_extra_parts.h"

#include "profiles/profile.h"

#include <components/ipfs/inter_request_state.h>

void IpfsExtraParts::PostProfileInit(Profile* profile, bool /* is_initial_profile */ ) {
DCHECK(profile);
ipfs::InterRequestState::CreateForBrowserContext(profile, profile->GetPrefs());
}
10 changes: 10 additions & 0 deletions chromium_edits/122.0.6170.3/chrome/browser/ipfs_extra_parts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ifndef IPFS_EXTRA_PART_H_
#define IPFS_EXTRA_PART_H_

#include <chrome/browser/chrome_browser_main_extra_parts.h>

class IpfsExtraParts : public ChromeBrowserMainExtraParts {
void PostProfileInit(Profile* profile, bool is_initial_profile) override;
};

#endif // IPFS_EXTRA_PART_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
diff --git a/chrome/browser/prefs/browser_prefs.cc b/chrome/browser/prefs/browser_prefs.cc
index fc9fcf1ff478a..800961b3c8767 100644
--- a/chrome/browser/prefs/browser_prefs.cc
+++ b/chrome/browser/prefs/browser_prefs.cc
@@ -190,6 +190,7 @@
#include "printing/buildflags/buildflags.h"
#include "rlz/buildflags/buildflags.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
+#include "third_party/ipfs_client/ipfs_buildflags.h"

#if BUILDFLAG(ENABLE_BACKGROUND_MODE)
#include "chrome/browser/background/background_mode_manager.h"
@@ -241,6 +242,11 @@
#include "chrome/browser/pdf/pdf_pref_names.h"
#endif // BUILDFLAG(ENABLE_PDF)

+#if BUILDFLAG(ENABLE_IPFS)
+#include "components/ipfs/ipfs_features.h"
+#include "components/ipfs/preferences.h"
+#endif
+
#if BUILDFLAG(ENABLE_SCREEN_AI_SERVICE)
#include "chrome/browser/screen_ai/pref_names.h"
#endif
@@ -1658,6 +1664,11 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
IncognitoModePrefs::RegisterProfilePrefs(registry);
invalidation::PerUserTopicSubscriptionManager::RegisterProfilePrefs(registry);
invalidation::InvalidatorRegistrarWithMemory::RegisterProfilePrefs(registry);
+#if BUILDFLAG(ENABLE_IPFS)
+ if (base::FeatureList::IsEnabled(ipfs::kEnableIpfs)) {
+ ipfs::RegisterPreferences(registry);
+ }
+#endif
language::LanguagePrefs::RegisterProfilePrefs(registry);
login_detection::prefs::RegisterProfilePrefs(registry);
lookalikes::RegisterProfilePrefs(registry);
33 changes: 8 additions & 25 deletions chromium_edits/122.0.6170.3/url/url_canon_ipfs.cc
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
#include "url_canon_internal.h"

#include <libp2p/multi/content_identifier_codec.hpp>
#include <ipfs_client/cid.h>
#include <ipfs_client/identity_cid.h>

#include <sstream>

namespace m = libp2p::multi;
using Cid = m::ContentIdentifier;
using CidCodec = m::ContentIdentifierCodec;

bool url::CanonicalizeIpfsURL(const char* spec,
int spec_len,
const Parsed& parsed,
Expand All @@ -22,30 +18,17 @@ bool url::CanonicalizeIpfsURL(const char* spec,
if ( parsed.host.len < 1 ) {
return false;
}
std::string cid_str{ spec + parsed.host.begin, static_cast<std::size_t>(parsed.host.len) };
auto maybe_cid = CidCodec::fromString(cid_str);
if ( !maybe_cid.has_value() ) {
auto e = libp2p::multi::Stringify(maybe_cid.error());
std::ostringstream err;
err << e << ' '
<< std::string_view{spec,static_cast<std::size_t>(spec_len)};
maybe_cid = ipfs::id_cid::forText( err.str() );
}
auto cid = maybe_cid.value();
if ( cid.version == Cid::Version::V0 ) {
//TODO dcheck content_type == DAG_PB && content_address.getType() == sha256
cid = Cid{
Cid::Version::V1,
cid.content_type,
cid.content_address
};
std::string_view cid_str{ spec + parsed.host.begin, static_cast<std::size_t>(parsed.host.len) };
auto cid = ipfs::Cid(cid_str);
if ( !cid.valid() ) {
cid = ipfs::id_cid::forText( std::string{cid_str} + " is not a valid CID." );
}
auto as_str = CidCodec::toString(cid);
if ( !as_str.has_value() ) {
auto as_str = cid.to_string();
if ( as_str.empty() ) {
return false;
}
std::string stdurl{ spec, static_cast<std::size_t>(parsed.host.begin) };
stdurl.append( as_str.value() );
stdurl.append( as_str );
stdurl.append( spec + parsed.host.end(), spec_len - parsed.host.end() );
spec = stdurl.data();
spec_len = static_cast<int>(stdurl.size());
Expand Down
Loading

0 comments on commit 6c5a726

Please sign in to comment.