Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve IPNS publish time #7

Merged
merged 14 commits into from
May 3, 2022
4 changes: 2 additions & 2 deletions .github/workflows/build-aar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ jobs:

- name: Desktop builds
run: |
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o agregore-ipfs-daemon_linux_amd64${{ steps.commit-tag.outputs.ver }}
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o agregore-ipfs-daemon_linux_amd64${{ steps.commit-tag.outputs.ver }}
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o agregore-ipfs-daemon_windows_amd64${{ steps.commit-tag.outputs.ver }}.exe
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o agregore-ipfs-daemon_macos_amd64${{ steps.commit-tag.outputs.ver }}
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o agregore-ipfs-daemon_macos_amd64${{ steps.commit-tag.outputs.ver }}

- name: Upload artifact
if: "!startsWith(github.ref, 'refs/tags/')"
Expand Down
1 change: 1 addition & 0 deletions gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func setupConfig(cfg *config.Config) {
// https://github.com/ipfs/go-ipfs/blob/master/docs/experimental-features.md

// Enable pubsub for better IPNS
cfg.Pubsub.Enabled = config.True
cfg.Ipns.UsePubsub = config.True
// Disable API to prevent malicious apps from using
cfg.Addresses.API = []string{}
Expand Down
2 changes: 1 addition & 1 deletion go-ipfs/core/coreapi/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"time"

"github.com/ipfs/go-ipfs-keystore"
keystore "github.com/ipfs/go-ipfs-keystore"
"github.com/ipfs/go-namesys"

ipath "github.com/ipfs/go-path"
Expand Down
33 changes: 26 additions & 7 deletions go-ipfs/core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1330,13 +1330,15 @@ func (i *gatewayHandler) ipnsPostHandler(w http.ResponseWriter, r *http.Request)
}

// Create key if needed
hadKey := true
if keyFromPath == "" {
has, err := i.keystore.Has(keyName)
if err != nil {
internalWebError(w, err)
return
}
if !has {
hadKey = false
// Generate key with name
_, err = i.api.Key().Generate(r.Context(), keyName)
if err != nil {
Expand Down Expand Up @@ -1377,16 +1379,28 @@ func (i *gatewayHandler) ipnsPostHandler(w http.ResponseWriter, r *http.Request)
keyStr = keyEnc.FormatID(pid)
}

start := time.Now()

// Get current IPFS path and CID
resolvedPath, err := i.api.Name().Resolve(r.Context(), "/ipns/"+keyStr)
var resolvedCid cid.Cid
if err == nil {
segs := strings.Split(resolvedPath.String(), "/")
resolvedCid = cidMustDecode(segs[2])
if hadKey {
// Key already existed, try to resolve

resolvedPath, err := i.api.Name().Resolve(r.Context(), "/ipns/"+keyStr)

golog.Println("name resolve time", time.Since(start))

if err == nil {
segs := strings.Split(resolvedPath.String(), "/")
resolvedCid = cidMustDecode(segs[2])
} else {
// Path couldn't be resolved
// This probably means that it doesn't exist
// So create it, using the empty dir CID
resolvedCid = emptyDirCid
}
} else {
// Path couldn't be resolved
// This probably means that it doesn't exist
// So create it, using the empty dir CID
// Key was just created, don't waste time trying to resolve
resolvedCid = emptyDirCid
}

Expand All @@ -1396,6 +1410,8 @@ func (i *gatewayHandler) ipnsPostHandler(w http.ResponseWriter, r *http.Request)
if ipnsPath == "" {
// Root is being replaced, so the provided /ipfs/ path can just be published

start = time.Now()

ipnsEntry, err = i.api.Name().Publish(
r.Context(), ipath.New(bodyPath),
options.Name.AllowOffline(true), options.Name.Key(keyOpt),
Expand All @@ -1404,6 +1420,9 @@ func (i *gatewayHandler) ipnsPostHandler(w http.ResponseWriter, r *http.Request)
webError(w, "WritableGateway: failed to publish path", err, http.StatusInternalServerError)
return
}

golog.Println("name publish time", time.Since(start))

newCid = inCid
} else {
// A subpath of the IPNS dir is being replaced
Expand Down
53 changes: 53 additions & 0 deletions go-libp2p-kad-dht/.github/workflows/automerge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# File managed by web3-bot. DO NOT EDIT.
# See https://github.com/protocol/.github/ for details.

# Automatically merge pull requests opened by web3-bot, as soon as (and only if) all tests pass.
# This reduces the friction associated with updating with our workflows.

on: [ pull_request ]
name: Automerge

jobs:
automerge-check:
if: github.event.pull_request.user.login == 'web3-bot'
runs-on: ubuntu-latest
outputs:
status: ${{ steps.should-automerge.outputs.status }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Check if we should automerge
id: should-automerge
run: |
for commit in $(git rev-list --first-parent origin/${{ github.event.pull_request.base.ref }}..${{ github.event.pull_request.head.sha }}); do
committer=$(git show --format=$'%ce' -s $commit)
echo "Committer: $committer"
if [[ "$committer" != "[email protected]" ]]; then
echo "Commit $commit wasn't committed by web3-bot, but by $committer."
echo "::set-output name=status::false"
exit
fi
done
echo "::set-output name=status::true"
automerge:
needs: automerge-check
runs-on: ubuntu-latest
# The check for the user is redundant here, as this job depends on the automerge-check job,
# but it prevents this job from spinning up, just to be skipped shortly after.
if: github.event.pull_request.user.login == 'web3-bot' && needs.automerge-check.outputs.status == 'true'
steps:
- name: Wait on tests
uses: lewagon/wait-on-check-action@bafe56a6863672c681c3cf671f5e10b20abf2eaa # v0.2
with:
ref: ${{ github.event.pull_request.head.sha }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
wait-interval: 10
running-workflow-name: 'automerge' # the name of this job
- name: Merge PR
uses: pascalgn/automerge-action@741c311a47881be9625932b0a0de1b0937aab1ae # v0.13.1
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
MERGE_LABELS: ""
MERGE_METHOD: "squash"
MERGE_DELETE_BRANCH: true
74 changes: 74 additions & 0 deletions go-libp2p-kad-dht/.github/workflows/go-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# File managed by web3-bot. DO NOT EDIT.
# See https://github.com/protocol/.github/ for details.

on: [push, pull_request]
name: Go Checks

jobs:
unit:
runs-on: ubuntu-latest
name: All
env:
RUNGOGENERATE: false
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: actions/setup-go@v2
with:
go-version: "1.17.x"
- name: Run repo-specific setup
uses: ./.github/actions/go-check-setup
if: hashFiles('./.github/actions/go-check-setup') != ''
- name: Read config
if: hashFiles('./.github/workflows/go-check-config.json') != ''
run: |
if jq -re .gogenerate ./.github/workflows/go-check-config.json; then
echo "RUNGOGENERATE=true" >> $GITHUB_ENV
fi
- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@df71e5d0e0ed317ebf43e6e59cf919430fa4b8f2 # 2021.1.1 (v0.2.1)
- name: Check that go.mod is tidy
uses: protocol/[email protected]
with:
run: |
go mod tidy
if [[ -n $(git ls-files --other --exclude-standard --directory -- go.sum) ]]; then
echo "go.sum was added by go mod tidy"
exit 1
fi
git diff --exit-code -- go.sum go.mod
- name: gofmt
if: ${{ success() || failure() }} # run this step even if the previous one failed
run: |
out=$(gofmt -s -l .)
if [[ -n "$out" ]]; then
echo $out | awk '{print "::error file=" $0 ",line=0,col=0::File is not gofmt-ed."}'
exit 1
fi
- name: go vet
if: ${{ success() || failure() }} # run this step even if the previous one failed
uses: protocol/[email protected]
with:
run: go vet ./...
- name: staticcheck
if: ${{ success() || failure() }} # run this step even if the previous one failed
uses: protocol/[email protected]
with:
run: |
set -o pipefail
staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g'
- name: go generate
uses: protocol/[email protected]
if: (success() || failure()) && env.RUNGOGENERATE == 'true'
with:
run: |
git clean -fd # make sure there aren't untracked files / directories
go generate ./...
# check if go generate modified or added any files
if ! $(git add . && git diff-index HEAD --exit-code --quiet); then
echo "go generated caused changes to the repository:"
git status --short
exit 1
fi

55 changes: 55 additions & 0 deletions go-libp2p-kad-dht/.github/workflows/go-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# File managed by web3-bot. DO NOT EDIT.
# See https://github.com/protocol/.github/ for details.

on: [push, pull_request]
name: Go Test

jobs:
unit:
strategy:
fail-fast: false
matrix:
os: [ "ubuntu", "windows", "macos" ]
go: [ "1.16.x", "1.17.x" ]
env:
COVERAGES: ""
runs-on: ${{ matrix.os }}-latest
name: ${{ matrix.os}} (go ${{ matrix.go }})
steps:
- uses: actions/checkout@v2
with:
submodules: recursive
- uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- name: Go information
run: |
go version
go env
- name: Run repo-specific setup
uses: ./.github/actions/go-test-setup
if: hashFiles('./.github/actions/go-test-setup') != ''
- name: Run tests
uses: protocol/[email protected]
with:
run: go test -v -coverprofile module-coverage.txt ./...
- name: Run tests (32 bit)
if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX.
uses: protocol/[email protected]
env:
GOARCH: 386
with:
run: go test -v ./...
- name: Run tests with race detector
if: ${{ matrix.os == 'ubuntu' }} # speed things up. Windows and OSX VMs are slow
uses: protocol/[email protected]
with:
run: go test -v -race ./...
- name: Collect coverage files
shell: bash
run: echo "COVERAGES=$(find . -type f -name 'module-coverage.txt' | tr -s '\n' ',' | sed 's/,$//')" >> $GITHUB_ENV
- name: Upload coverage to Codecov
uses: codecov/codecov-action@51d810878be5422784e86451c0e7c14e5860ec47 # v2.0.2
with:
files: '${{ env.COVERAGES }}'
env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }}
12 changes: 12 additions & 0 deletions go-libp2p-kad-dht/.github/workflows/release-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# File managed by web3-bot. DO NOT EDIT.
# See https://github.com/protocol/.github/ for details.

name: Release Checker
on:
pull_request:
paths: [ 'version.json' ]
branches: [ master ]

jobs:
release-check:
uses: protocol/.github/.github/workflows/release-check.yml@master
12 changes: 12 additions & 0 deletions go-libp2p-kad-dht/.github/workflows/releaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# File managed by web3-bot. DO NOT EDIT.
# See https://github.com/protocol/.github/ for details.

name: Releaser
on:
push:
paths: [ 'version.json' ]
branches: [ master ]

jobs:
releaser:
uses: protocol/.github/.github/workflows/releaser.yml@master
12 changes: 12 additions & 0 deletions go-libp2p-kad-dht/.github/workflows/tagpush.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# File managed by web3-bot. DO NOT EDIT.
# See https://github.com/protocol/.github/ for details.

name: Tag Push Checker
on:
push:
tags:
- v*

jobs:
releaser:
uses: protocol/.github/.github/workflows/tagpush.yml@master
21 changes: 21 additions & 0 deletions go-libp2p-kad-dht/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Protocol Labs, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
43 changes: 43 additions & 0 deletions go-libp2p-kad-dht/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# go-libp2p-kad-dht

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](https://protocol.ai)
[![](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](https://libp2p.io)
[![](https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23yellow)
[![GoDoc](https://godoc.org/github.com/libp2p/go-libp2p-kad-dht?status.svg)](https://godoc.org/github.com/libp2p/go-libp2p-kad-dht)
[![Build Status](https://travis-ci.org/libp2p/go-libp2p-kad-dht.svg?branch=master)](https://travis-ci.org/libp2p/go-libp2p-kad-dht)
[![Discourse posts](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg)](https://discuss.libp2p.io)

> A Kademlia DHT implementation on go-libp2p

## Table of Contents

- [Install](#install)
- [Usage](#usage)
- [Contribute](#contribute)
- [License](#license)

## Install

```sh
go get github.com/libp2p/go-libp2p-kad-dht
```

## Usage

Go to https://godoc.org/github.com/libp2p/go-libp2p-kad-dht.

## Contribute

Contributions welcome. Please check out [the issues](https://github.com/libp2p/go-libp2p-kad-dht/issues).

Check out our [contributing document](https://github.com/libp2p/community/blob/master/CONTRIBUTE.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to libp2p are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).

Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.

## License

[MIT](LICENSE) © Protocol Labs Inc.

---

The last gx published version of this module was: 4.4.34: QmXuNFLZc6Nb5akB4sZsxK3doShsFKT1sZFvxLXJvZQwAW
Loading