diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..d72a1851 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,34 @@ +name: CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + - name: Build + run: make build + + + unittest: + name: Unit Tests + strategy: + fail-fast: false + matrix: + go-version: + - 1.16 + runs-on: ubuntu-latest + steps: + - name: Check Go Version + uses: actions/setup-go@v2 + with: + go-version: ${{matrix.go-version}} + - name: Checkout repo + uses: actions/checkout@v2 + - name: Run tests + run: make test diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..c4ead52a --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +test: + GO111MODULE=on go test ./... +build: + go build -v ./... + diff --git a/go.mod b/go.mod index 231497f1..fbcdac26 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/libp2p/go-libp2p-pubsub +module github.com/yhassanzadeh13/go-libp2p-pubsub go 1.17 @@ -7,6 +7,7 @@ require ( github.com/gogo/protobuf v1.3.2 github.com/ipfs/go-log v1.0.5 github.com/libp2p/go-libp2p v0.22.0 + github.com/libp2p/go-libp2p-pubsub v0.8.1-0.20220908052023-8866ca88a105 github.com/libp2p/go-libp2p-testing v0.12.0 github.com/libp2p/go-msgio v0.2.0 github.com/multiformats/go-multiaddr v0.6.0 @@ -36,6 +37,7 @@ require ( github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect github.com/klauspost/compress v1.15.1 // indirect github.com/klauspost/cpuid/v2 v2.1.0 // indirect + github.com/kr/pretty v0.2.1 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-flow-metrics v0.1.0 // indirect github.com/libp2p/go-netroute v0.2.0 // indirect @@ -86,7 +88,6 @@ require ( golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect golang.org/x/tools v0.1.12 // indirect google.golang.org/protobuf v1.28.1 // indirect - gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/blake3 v1.1.7 // indirect diff --git a/go.sum b/go.sum index 84d10209..e72143d4 100644 --- a/go.sum +++ b/go.sum @@ -317,6 +317,8 @@ github.com/libp2p/go-libp2p v0.22.0 h1:2Tce0kHOp5zASFKJbNzRElvh0iZwdtG5uZheNW8ch github.com/libp2p/go-libp2p v0.22.0/go.mod h1:UDolmweypBSjQb2f7xutPnwZ/fxioLbMBxSjRksxxU4= github.com/libp2p/go-libp2p-asn-util v0.2.0/go.mod h1:WoaWxbHKBymSN41hWSq/lGKJEca7TNm58+gGJi2WsLI= github.com/libp2p/go-libp2p-core v0.19.0/go.mod h1:AkA+FUKQfYt1FLNef5fOPlo/naAWjKy/RCjkcPjqzYg= +github.com/libp2p/go-libp2p-pubsub v0.8.1-0.20220908052023-8866ca88a105 h1:EAAgUl0EnSk4Z/ct1xsHTYSy9JYDdcTazrC6phSdlIY= +github.com/libp2p/go-libp2p-pubsub v0.8.1-0.20220908052023-8866ca88a105/go.mod h1:e4kT+DYjzPUYGZeWk4I+oxCSYTXizzXii5LDRRhjKSw= github.com/libp2p/go-libp2p-testing v0.11.0/go.mod h1:qG4sF27dfKFoK9KlVzK2y52LQKhp0VEmLjV5aDqr1Hg= github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA= github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg= diff --git a/gossipsub.go b/gossipsub.go index e4c238bd..575e6ad7 100644 --- a/gossipsub.go +++ b/gossipsub.go @@ -1829,6 +1829,12 @@ func (gs *GossipSubRouter) pushControl(p peer.ID, ctl *pb.ControlMessage) { } } +// SendControl dispatches the given set of control messages to the given peer. +func (gs *GossipSubRouter) SendControl(p peer.ID, ctl *pb.ControlMessage) { + out := rpcWithControl(nil, ctl.Ihave, ctl.Iwant, ctl.Graft, ctl.Prune) + gs.sendRPC(p, out) +} + func (gs *GossipSubRouter) piggybackControl(p peer.ID, out *RPC, ctl *pb.ControlMessage) { // check control message for staleness first var tograft []*pb.ControlGraft @@ -1941,11 +1947,7 @@ func (gs *GossipSubRouter) getPeers(topic string, count int, filter func(peer.ID return peers } -// WithDefaultTagTracer returns the tag tracer of the GossipSubRouter as a PubSub option. -// This is useful for cases where the GossipSubRouter is instantiated externally, and is -// injected into the GossipSub constructor as a dependency. This allows the tag tracer to be -// also injected into the GossipSub constructor as a PubSub option dependency. -func (gs *GossipSubRouter) WithDefaultTagTracer() Option { +func (gs *GossipSubRouter) WithTagTracerPubsubOption() Option { return WithRawTracer(gs.tagTracer) }