Skip to content

Commit

Permalink
catching up with latest changes from main
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumemichel committed Jul 6, 2023
2 parents b6da7ee + 05632ce commit c0b9440
Show file tree
Hide file tree
Showing 23 changed files with 297 additions and 102 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/automerge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# File managed by web3-bot. DO NOT EDIT.
# See https://github.com/protocol/.github/ for details.

name: Automerge
on: [ pull_request ]

jobs:
automerge:
uses: protocol/.github/.github/workflows/automerge.yml@master
with:
job: 'automerge'
67 changes: 67 additions & 0 deletions .github/workflows/go-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# 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
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- id: config
uses: protocol/.github/.github/actions/read-config@master
- uses: actions/setup-go@v3
with:
go-version: 1.20.x
- name: Run repo-specific setup
uses: ./.github/actions/go-check-setup
if: hashFiles('./.github/actions/go-check-setup') != ''
- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@4970552d932f48b71485287748246cf3237cebdf # 2023.1 (v0.4.0)
- 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()) && fromJSON(steps.config.outputs.json).gogenerate == true
with:
run: |
git clean -fd # make sure there aren't untracked files / directories
go generate -x ./...
# 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
76 changes: 76 additions & 0 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# 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.19.x","1.20.x"]
env:
COVERAGES: ""
runs-on: ${{ fromJSON(vars[format('UCI_GO_TEST_RUNNER_{0}', matrix.os)] || format('"{0}-latest"', matrix.os)) }}
name: ${{ matrix.os }} (go ${{ matrix.go }})
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- id: config
uses: protocol/.github/.github/actions/read-config@master
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- name: Go information
run: |
go version
go env
- name: Use msys2 on windows
if: matrix.os == 'windows'
shell: bash
# The executable for msys2 is also called bash.cmd
# https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md#shells
# If we prepend its location to the PATH
# subsequent 'shell: bash' steps will use msys2 instead of gitbash
run: echo "C:/msys64/usr/bin" >> $GITHUB_PATH
- name: Run repo-specific setup
uses: ./.github/actions/go-test-setup
if: hashFiles('./.github/actions/go-test-setup') != ''
- name: Run tests
if: contains(fromJSON(steps.config.outputs.json).skipOSes, matrix.os) == false
uses: protocol/[email protected]
with:
# Use -coverpkg=./..., so that we include cross-package coverage.
# If package ./A imports ./B, and ./A's tests also cover ./B,
# this means ./B's coverage will be significantly higher than 0%.
run: go test -v -shuffle=on -coverprofile=module-coverage.txt -coverpkg=./... ./...
- name: Run tests (32 bit)
# can't run 32 bit tests on OSX.
if: matrix.os != 'macos' &&
fromJSON(steps.config.outputs.json).skip32bit != true &&
contains(fromJSON(steps.config.outputs.json).skipOSes, matrix.os) == false
uses: protocol/[email protected]
env:
GOARCH: 386
with:
run: |
export "PATH=$PATH_386:$PATH"
go test -v -shuffle=on ./...
- name: Run tests with race detector
# speed things up. Windows and OSX VMs are slow
if: matrix.os == 'ubuntu' &&
contains(fromJSON(steps.config.outputs.json).skipOSes, matrix.os) == false
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@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1
with:
files: '${{ env.COVERAGES }}'
env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }}
13 changes: 13 additions & 0 deletions .github/workflows/release-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# File managed by web3-bot. DO NOT EDIT.
# See https://github.com/protocol/.github/ for details.

name: Release Checker
on:
pull_request_target:
paths: [ 'version.json' ]

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

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

jobs:
releaser:
uses: protocol/.github/.github/workflows/releaser.yml@master
9 changes: 0 additions & 9 deletions .github/workflows/stale.yml

This file was deleted.

12 changes: 12 additions & 0 deletions .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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ go-kademlia

> A Generic Go Kademlia Implementation
Generic Kademlia implementation in Go that can be used to build DHT Protocols.
Generic Kademlia implementation in Go that can be used to build DHT Protocols. This repository is **NOT** meant to be the home of the Go IPFS DHT implementation, it is meant to provide generic Kademlia building blocks that could be used in multiple Kademlia implementations and simulations. This Kademlia implementation was built to be reproducible: most of the modules are single threaded, allowing sequential execution. This repository enables deterministic testing, and stable simulations.

## Documentation

Expand Down
11 changes: 5 additions & 6 deletions examples/connect/findpeer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ import (
"github.com/plprobelab/go-kademlia/network/message"
"github.com/plprobelab/go-kademlia/network/message/ipfsv1"
"github.com/plprobelab/go-kademlia/query/simplequery"
"github.com/plprobelab/go-kademlia/routingtable/simplert"
"github.com/plprobelab/go-kademlia/routing/simplert"
"github.com/plprobelab/go-kademlia/util"
)

var (
protocolID address.ProtocolID = "/ipfs/kad/1.0.0" // IPFS DHT network protocol ID
)
var protocolID address.ProtocolID = "/ipfs/kad/1.0.0" // IPFS DHT network protocol ID

func FindPeer(ctx context.Context) {
ctx, span := util.StartSpan(ctx, "FindPeer Test")
Expand All @@ -44,7 +42,7 @@ func FindPeer(ctx context.Context) {
kadid := pid.Key()

// create a simple routing table, with bucket size 20
rt := simplert.NewSimpleRT(kadid, 20)
rt := simplert.New(kadid, 20)
// create a scheduler using real time
sched := simplescheduler.NewSimpleScheduler(clk)
// create a message endpoint is used to communicate with other peers
Expand Down Expand Up @@ -87,7 +85,8 @@ func FindPeer(ctx context.Context) {
// endCond is used to terminate the simulation once the query is done
endCond := false
handleResultsFn := func(ctx context.Context, id address.NodeID,
resp message.MinKadResponseMessage) (bool, []address.NodeID) {
resp message.MinKadResponseMessage,
) (bool, []address.NodeID) {
// parse response to ipfs dht message
msg, ok := resp.(*ipfsv1.Message)
if !ok {
Expand Down
12 changes: 5 additions & 7 deletions examples/dispatchquery/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/plprobelab/go-kademlia/network/message"
"github.com/plprobelab/go-kademlia/network/message/ipfsv1"
sq "github.com/plprobelab/go-kademlia/query/simplequery"
"github.com/plprobelab/go-kademlia/routingtable/simplert"
"github.com/plprobelab/go-kademlia/routing/simplert"
"github.com/plprobelab/go-kademlia/server/basicserver"
"github.com/plprobelab/go-kademlia/util"

Expand All @@ -37,9 +37,7 @@ const (
protoID = "/ipfs/kad/1.0.0"
)

var (
targetBytesID = "mACQIARIgp9PBu+JuU8aicuW8xT+Oa08OntMyqdLbfQtOplAHlME"
)
var targetBytesID = "mACQIARIgp9PBu+JuU8aicuW8xT+Oa08OntMyqdLbfQtOplAHlME"

func queryTest(ctx context.Context) {
ctx, span := util.StartSpan(ctx, "queryTest")
Expand All @@ -58,7 +56,7 @@ func queryTest(ctx context.Context) {
addrA := multiaddr.StringCast("/ip4/1.1.1.1/tcp/4001/")
var naddrA address.NodeAddr = addrinfo.NewAddrInfo(peer.AddrInfo{ID: selfA.ID,
Addrs: []multiaddr.Multiaddr{addrA}})
rtA := simplert.NewSimpleRT(selfA.Key(), 2)
rtA := simplert.New(selfA.Key(), 2)
schedA := ss.NewSimpleScheduler(clk)
endpointA := fakeendpoint.NewFakeEndpoint(selfA, schedA, router)
servA := basicserver.NewBasicServer(rtA, endpointA)
Expand All @@ -76,7 +74,7 @@ func queryTest(ctx context.Context) {
addrB := multiaddr.StringCast("/ip4/2.2.2.2/tcp/4001/")
var naddrB address.NodeAddr = addrinfo.NewAddrInfo(peer.AddrInfo{ID: selfB.ID,
Addrs: []multiaddr.Multiaddr{addrB}})
rtB := simplert.NewSimpleRT(selfB.Key(), 2)
rtB := simplert.New(selfB.Key(), 2)
schedB := ss.NewSimpleScheduler(clk)
endpointB := fakeendpoint.NewFakeEndpoint(selfB, schedB, router)
servB := basicserver.NewBasicServer(rtB, endpointB)
Expand All @@ -94,7 +92,7 @@ func queryTest(ctx context.Context) {
addrC := multiaddr.StringCast("/ip4/3.3.3.3/tcp/4001/")
var naddrC address.NodeAddr = addrinfo.NewAddrInfo(peer.AddrInfo{ID: selfC.ID,
Addrs: []multiaddr.Multiaddr{addrC}})
rtC := simplert.NewSimpleRT(selfC.Key(), 2)
rtC := simplert.New(selfC.Key(), 2)
schedC := ss.NewSimpleScheduler(clk)
endpointC := fakeendpoint.NewFakeEndpoint(selfC, schedC, router)
servC := basicserver.NewBasicServer(rtC, endpointC)
Expand Down
11 changes: 6 additions & 5 deletions examples/fullsim/findnode.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/plprobelab/go-kademlia/network/message"
"github.com/plprobelab/go-kademlia/network/message/simmessage"
sq "github.com/plprobelab/go-kademlia/query/simplequery"
"github.com/plprobelab/go-kademlia/routingtable"
"github.com/plprobelab/go-kademlia/routingtable/simplert"
"github.com/plprobelab/go-kademlia/routing"
"github.com/plprobelab/go-kademlia/routing/simplert"
"github.com/plprobelab/go-kademlia/server"
"github.com/plprobelab/go-kademlia/server/basicserver"
"github.com/plprobelab/go-kademlia/util"
Expand All @@ -34,7 +34,7 @@ const (

// connectNodes adds nodes to each other's peerstores and routing tables
func connectNodes(ctx context.Context, n0, n1 address.NodeAddr, ep0, ep1 endpoint.Endpoint,
rt0, rt1 routingtable.RoutingTable) {
rt0, rt1 routing.Table) {
// add n1 to n0's peerstore and routing table
ep0.MaybeAddToPeerstore(ctx, n1, peerstoreTTL)
rt0.AddPeer(ctx, n1.NodeID())
Expand Down Expand Up @@ -73,7 +73,7 @@ func findNode(ctx context.Context) {

for i := 0; i < len(ids); i++ {
// create a routing table, with bucket size 2
rts[i] = simplert.NewSimpleRT(ids[i].KadKey, 2)
rts[i] = simplert.New(ids[i].KadKey, 2)
// create a scheduler based on the mock clock
schedulers[i] = ss.NewSimpleScheduler(clk)
// create a fake endpoint for the node, communicating through the router
Expand Down Expand Up @@ -103,7 +103,8 @@ func findNode(ctx context.Context) {

// handleResFn is called when a response is received during the query process
handleResFn := func(_ context.Context, id address.NodeID,
msg message.MinKadResponseMessage) (bool, []address.NodeID) {
msg message.MinKadResponseMessage,
) (bool, []address.NodeID) {
resp := msg.(*simmessage.SimMessage)
fmt.Println("got a response from", id, "with", resp.CloserNodes())

Expand Down
Loading

0 comments on commit c0b9440

Please sign in to comment.