diff --git a/go.mod b/go.mod index f64e64c..71d0505 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,6 @@ go 1.17 require ( github.com/btcsuite/btcd/btcec/v2 v2.1.3 - github.com/coreos/go-semver v0.3.0 github.com/gogo/protobuf v1.3.1 github.com/ipfs/go-cid v0.2.0 github.com/ipfs/go-log/v2 v2.5.1 diff --git a/go.sum b/go.sum index b799050..578b185 100644 --- a/go.sum +++ b/go.sum @@ -5,8 +5,6 @@ github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJ github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= -github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= -github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/helpers/match.go b/helpers/match.go deleted file mode 100644 index 2e24667..0000000 --- a/helpers/match.go +++ /dev/null @@ -1,42 +0,0 @@ -package helpers - -import ( - "strings" - - "github.com/coreos/go-semver/semver" - "github.com/libp2p/go-libp2p-core/protocol" -) - -// MultistreamSemverMatcher returns a matcher function for a given base protocol. -// The matcher function will return a boolean indicating whether a protocol ID -// matches the base protocol. A given protocol ID matches the base protocol if -// the IDs are the same and if the semantic version of the base protocol is the -// same or higher than that of the protocol ID provided. -// TODO -func MultistreamSemverMatcher(base protocol.ID) (func(string) bool, error) { - parts := strings.Split(string(base), "/") - vers, err := semver.NewVersion(parts[len(parts)-1]) - if err != nil { - return nil, err - } - - return func(check string) bool { - chparts := strings.Split(check, "/") - if len(chparts) != len(parts) { - return false - } - - for i, v := range chparts[:len(chparts)-1] { - if parts[i] != v { - return false - } - } - - chvers, err := semver.NewVersion(chparts[len(chparts)-1]) - if err != nil { - return false - } - - return vers.Major == chvers.Major && vers.Minor >= chvers.Minor - }, nil -} diff --git a/helpers/match_test.go b/helpers/match_test.go deleted file mode 100644 index 8a6e4b6..0000000 --- a/helpers/match_test.go +++ /dev/null @@ -1,33 +0,0 @@ -package helpers - -import ( - "testing" -) - -func TestSemverMatching(t *testing.T) { - m, err := MultistreamSemverMatcher("/testing/4.3.5") - if err != nil { - t.Fatal(err) - } - - cases := map[string]bool{ - "/testing/4.3.0": true, - "/testing/4.3.7": true, - "/testing/4.3.5": true, - "/testing/4.2.7": true, - "/testing/4.0.0": true, - "/testing/5.0.0": false, - "/cars/dogs/4.3.5": false, - "/foo/1.0.0": false, - "": false, - "dogs": false, - "/foo": false, - "/foo/1.1.1.1": false, - } - - for p, ok := range cases { - if m(p) != ok { - t.Fatalf("expected %s to be %t", p, ok) - } - } -}