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

[Feature] UUIDs, protocol versioning, v2 protocol w/ dag-cbor messaging #332

Merged
merged 32 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f330fe8
feat(net): initial dag-cbor protocol support
mvdan Dec 17, 2021
480fcf5
feat(requestid): use uuids for requestids
rvagg Dec 13, 2021
cf6009a
fix(requestmanager): make collect test requests with uuids sortable
rvagg Dec 14, 2021
af9dd52
fix(requestid): print requestids as string uuids in logs
rvagg Dec 14, 2021
a2a87fe
fix(requestid): use string as base type for RequestId
rvagg Dec 15, 2021
d25c6ef
chore(requestid): wrap requestid string in a struct
rvagg Dec 16, 2021
901b2c0
feat(libp2p): add v1.0.0 network compatibility
rvagg Jan 11, 2022
caa4b58
chore(net): resolve most cbor + uuid merge problems
rvagg Jan 13, 2022
8ef2008
feat(net): to/from ipld bindnode types, more cbor protoc improvements
mvdan Jan 13, 2022
ea4a06a
feat(net): introduce 2.0.0 protocol for dag-cbor
rvagg Jan 14, 2022
45b87ff
fix(net): more bindnode dag-cbor protocol fixes
rvagg Jan 14, 2022
c3649f3
chore(metadata): convert metadata to bindnode
rvagg Jan 24, 2022
cb45833
chore(net,extensions): wire up IPLD extensions, expose as Node instea…
rvagg Jan 25, 2022
9c08dd0
fix(src): fix imports
rvagg Jan 25, 2022
989cf66
fix(mod): clean up go.mod
rvagg Jan 25, 2022
fc58e23
fix(net): refactor message version format code to separate packages
rvagg Jan 25, 2022
161a577
feat(net): activate v2 network as default
rvagg Jan 25, 2022
e997ff3
fix(src): build error
rvagg Jan 25, 2022
4e57d92
chore: remove GraphSyncMessage#Loggable
rvagg Jan 31, 2022
6b86c3c
chore: remove intermediate v1.1 pb protocol message type
rvagg Jan 31, 2022
eb16b27
fix: clarify comments re dag-cbor extension data
rvagg Feb 2, 2022
83c3860
feat: new LinkMetadata iface, integrate metadata into Response type (…
rvagg Feb 4, 2022
21a4546
fix: avoid double-encode for extension size estimation
rvagg Feb 2, 2022
ff4d7ad
feat(requesttype): introduce RequestType enum to replace cancel&updat…
rvagg Feb 4, 2022
586931b
fix(metadata): extend round-trip tests to byte representation (#350)
rvagg Feb 4, 2022
259905a
feat!(messagev2): tweak dag-cbor message schema (#354)
rvagg Feb 11, 2022
e66b39d
feat(graphsync): unify req & resp Pause, Unpause & Cancel by RequestI…
rvagg Feb 16, 2022
e27c827
feat: SendUpdates() API to send only extension data to via existing r…
rvagg Feb 14, 2022
8106555
fix(responsemanager): send update while completing
hannahhoward Feb 16, 2022
db297c1
fix(requestmanager): revert change to pointer type
hannahhoward Feb 17, 2022
f6a08b5
Refactor async loading for simplicity and correctness (#356)
hannahhoward Feb 18, 2022
c938c6b
fix(requestmanager): update test for rebase
hannahhoward Feb 18, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion benchmarks/testnet/virtual.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"google.golang.org/protobuf/proto"

gsmsg "github.com/ipfs/go-graphsync/message"
gsmsgv1 "github.com/ipfs/go-graphsync/message/v1"
gsnet "github.com/ipfs/go-graphsync/network"
)

Expand Down Expand Up @@ -137,7 +138,7 @@ func (n *network) SendMessage(
rateLimiters[to] = rateLimiter
}

pbMsg, err := mes.ToProto()
pbMsg, err := gsmsgv1.NewMessageHandler().ToProto(peer.ID("foo"), mes)
if err != nil {
return err
}
Expand Down
16 changes: 7 additions & 9 deletions cidset/cidset.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,30 @@ import (
"errors"

"github.com/ipfs/go-cid"
"github.com/ipld/go-ipld-prime/datamodel"
"github.com/ipld/go-ipld-prime/fluent"
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
"github.com/ipld/go-ipld-prime/node/basicnode"

"github.com/ipfs/go-graphsync/ipldutil"
)

// EncodeCidSet encodes a cid set into bytes for the do-no-send-cids extension
func EncodeCidSet(cids *cid.Set) ([]byte, error) {
func EncodeCidSet(cids *cid.Set) datamodel.Node {
list := fluent.MustBuildList(basicnode.Prototype.List, int64(cids.Len()), func(la fluent.ListAssembler) {
_ = cids.ForEach(func(c cid.Cid) error {
la.AssembleValue().AssignLink(cidlink.Link{Cid: c})
return nil
})
})
return ipldutil.EncodeNode(list)
return list
}

// DecodeCidSet decode a cid set from data for the do-no-send-cids extension
func DecodeCidSet(data []byte) (*cid.Set, error) {
list, err := ipldutil.DecodeNode(data)
if err != nil {
return nil, err
func DecodeCidSet(data datamodel.Node) (*cid.Set, error) {
if data.Kind() != datamodel.Kind_List {
return nil, errors.New("did not receive a list of CIDs")
}
set := cid.NewSet()
iter := list.ListIterator()
iter := data.ListIterator()
for !iter.Done() {
_, next, err := iter.Next()
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions cidset/cidset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ func TestDecodeEncodeCidSet(t *testing.T) {
for _, c := range cids {
set.Add(c)
}
encoded, err := EncodeCidSet(set)
require.NoError(t, err, "encode errored")
encoded := EncodeCidSet(set)
decodedCidSet, err := DecodeCidSet(encoded)
require.NoError(t, err, "decode errored")
require.Equal(t, decodedCidSet.Len(), set.Len())
Expand Down
16 changes: 5 additions & 11 deletions dedupkey/dedupkey.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
package dedupkey

import (
"github.com/ipld/go-ipld-prime/datamodel"
"github.com/ipld/go-ipld-prime/node/basicnode"

"github.com/ipfs/go-graphsync/ipldutil"
)

// EncodeDedupKey returns encoded cbor data for string key
func EncodeDedupKey(key string) ([]byte, error) {
func EncodeDedupKey(key string) (datamodel.Node, error) {
nb := basicnode.Prototype.String.NewBuilder()
err := nb.AssignString(key)
if err != nil {
return nil, err
}
nd := nb.Build()
return ipldutil.EncodeNode(nd)
return nb.Build(), nil
}

// DecodeDedupKey returns a string key decoded from cbor data
func DecodeDedupKey(data []byte) (string, error) {
nd, err := ipldutil.DecodeNode(data)
if err != nil {
return "", err
}
return nd.AsString()
func DecodeDedupKey(data datamodel.Node) (string, error) {
return data.AsString()
}
16 changes: 5 additions & 11 deletions donotsendfirstblocks/donotsendfirstblocks.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
package donotsendfirstblocks

import (
"github.com/ipld/go-ipld-prime/datamodel"
"github.com/ipld/go-ipld-prime/node/basicnode"

"github.com/ipfs/go-graphsync/ipldutil"
)

// EncodeDoNotSendFirstBlocks returns encoded cbor data for the given number
// of blocks to skip
func EncodeDoNotSendFirstBlocks(skipBlockCount int64) ([]byte, error) {
nd := basicnode.NewInt(skipBlockCount)
return ipldutil.EncodeNode(nd)
func EncodeDoNotSendFirstBlocks(skipBlockCount int64) datamodel.Node {
return basicnode.NewInt(skipBlockCount)
}

// DecodeDoNotSendFirstBlocks returns the number of blocks to skip
func DecodeDoNotSendFirstBlocks(data []byte) (int64, error) {
nd, err := ipldutil.DecodeNode(data)
if err != nil {
return 0, err
}
return nd.AsInt()
func DecodeDoNotSendFirstBlocks(data datamodel.Node) (int64, error) {
return data.AsInt()
}
8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module github.com/ipfs/go-graphsync
go 1.16

require (
github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c // indirect
github.com/google/go-cmp v0.5.6
github.com/google/uuid v1.3.0
github.com/hannahhoward/cbor-gen-for v0.0.0-20200817222906-ea96cece81f1
github.com/hannahhoward/go-pubsub v0.0.0-20200423002714-8d62886cc36e
github.com/ipfs/go-block-format v0.0.3
Expand All @@ -27,7 +28,7 @@ require (
github.com/ipfs/go-unixfs v0.3.1
github.com/ipfs/go-unixfsnode v1.2.0
github.com/ipld/go-codec-dagpb v1.3.0
github.com/ipld/go-ipld-prime v0.14.4
github.com/ipld/go-ipld-prime v0.14.5-0.20220121142026-257b06219831
github.com/jbenet/go-random v0.0.0-20190219211222-123a90aedc0c
github.com/libp2p/go-buffer-pool v0.0.2
github.com/libp2p/go-libp2p v0.16.0
Expand All @@ -37,13 +38,10 @@ require (
github.com/libp2p/go-msgio v0.1.0
github.com/multiformats/go-multiaddr v0.4.0
github.com/multiformats/go-multihash v0.1.0
github.com/smartystreets/assertions v1.0.0 // indirect
github.com/stretchr/testify v1.7.0
github.com/whyrusleeping/cbor-gen v0.0.0-20210219115102-f37d292932f2
go.opentelemetry.io/otel v1.2.0
go.opentelemetry.io/otel/sdk v1.2.0
go.opentelemetry.io/otel/trace v1.2.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
google.golang.org/protobuf v1.27.1
)
12 changes: 5 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,8 @@ github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk
github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg=
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c h1:7lF+Vz0LqiRidnzC1Oq86fpX1q/iEv2KJdrCtttYjT4=
github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
Expand Down Expand Up @@ -454,8 +453,9 @@ github.com/ipld/go-codec-dagpb v1.3.0/go.mod h1:ga4JTU3abYApDC3pZ00BC2RSvC3qfBb9
github.com/ipld/go-ipld-prime v0.9.1-0.20210324083106-dc342a9917db/go.mod h1:KvBLMr4PX1gWptgkzRjVZCrLmSGcZCb/jioOQwCqZN8=
github.com/ipld/go-ipld-prime v0.11.0/go.mod h1:+WIAkokurHmZ/KwzDOMUuoeJgaRQktHtEaLglS3ZeV8=
github.com/ipld/go-ipld-prime v0.14.0/go.mod h1:9ASQLwUFLptCov6lIYc70GRB4V7UTyLD0IJtrDJe6ZM=
github.com/ipld/go-ipld-prime v0.14.4 h1:bqhmume8+nbNsX4/+J6eohktfZHAI8GKrF3rQ0xgOyc=
github.com/ipld/go-ipld-prime v0.14.4/go.mod h1:QcE4Y9n/ZZr8Ijg5bGPT0GqYWgZ1704nH0RDcQtgTP0=
github.com/ipld/go-ipld-prime v0.14.5-0.20220121142026-257b06219831 h1:hHLYeedwqakiOMaGI6HWF84geJu2VL6OZ1DrrhyY70s=
github.com/ipld/go-ipld-prime v0.14.5-0.20220121142026-257b06219831/go.mod h1:QcE4Y9n/ZZr8Ijg5bGPT0GqYWgZ1704nH0RDcQtgTP0=
github.com/ipld/go-ipld-prime/storage/bsadapter v0.0.0-20211210234204-ce2a1c70cd73/go.mod h1:2PJ0JgxyB08t0b2WKrcuqI3di0V+5n6RS/LTUJhkoxY=
github.com/jackpal/gateway v1.0.5/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA=
github.com/jackpal/go-nat-pmp v1.0.1/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
Expand Down Expand Up @@ -1023,9 +1023,8 @@ github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPx
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/assertions v1.0.0 h1:UVQPSSmc3qtTi+zPPkCXvZX9VvW/xT/NsRvKfwY81a8=
github.com/smartystreets/assertions v1.0.0/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM=
github.com/smartystreets/goconvey v0.0.0-20190222223459-a17d461953aa/go.mod h1:2RVY1rIf+2J2o/IM9+vPq9RzmHDSseB7FoXiSNIUsoU=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
Expand Down Expand Up @@ -1080,9 +1079,8 @@ github.com/warpfork/go-wish v0.0.0-20200122115046-b9ea61034e4a/go.mod h1:x6AKhvS
github.com/whyrusleeping/cbor v0.0.0-20171005072247-63513f603b11 h1:5HZfQkwe0mIfyDmc1Em5GqlNRzcdtlv4HTNmdpt7XH0=
github.com/whyrusleeping/cbor v0.0.0-20171005072247-63513f603b11/go.mod h1:Wlo/SzPmxVp6vXpGt/zaXhHH0fn4IxgqZc82aKg6bpQ=
github.com/whyrusleeping/cbor-gen v0.0.0-20200123233031-1cdf64d27158/go.mod h1:Xj/M2wWU+QdTdRbu/L/1dIZY8/Wb2K9pAhtroQuxJJI=
github.com/whyrusleeping/cbor-gen v0.0.0-20200710004633-5379fc63235d h1:wSxKhvbN7kUoP0sfRS+w2tWr45qlU8409i94hHLOT8w=
github.com/whyrusleeping/cbor-gen v0.0.0-20200710004633-5379fc63235d/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ=
github.com/whyrusleeping/cbor-gen v0.0.0-20210219115102-f37d292932f2 h1:bsUlNhdmbtlfdLVXAVfuvKQ01RnWAM09TVrJkI7NZs4=
github.com/whyrusleeping/cbor-gen v0.0.0-20210219115102-f37d292932f2/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ=
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f h1:jQa4QT2UP9WYv2nzyawpKMOCl+Z/jW7djv2/J50lj9E=
github.com/whyrusleeping/chunker v0.0.0-20181014151217-fe64bd25879f/go.mod h1:p9UJB6dDgdPgMJZs7UjUOdulKyRr9fqkS+6JKAInPy8=
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc=
Expand Down
37 changes: 32 additions & 5 deletions graphsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,45 @@ import (
"errors"
"fmt"

"github.com/google/uuid"
"github.com/ipfs/go-cid"
"github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/datamodel"
"github.com/ipld/go-ipld-prime/traversal"
"github.com/libp2p/go-libp2p-core/peer"
)

// RequestID is a unique identifier for a GraphSync request.
type RequestID int32
rvagg marked this conversation as resolved.
Show resolved Hide resolved
type RequestID struct{ string }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed this -- there a reason for a request ID to be a struct { string } as opposed to just a string? I noticed we aren't particularly uniform with this actually. CID is struct{string} while filecoin's Address and libp2p's peer.ID. I'm wonder about the tradeoffs... anyway, just food for thought.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I experimented with a few things here but landed on this after copying cid.CID's pattern with the main reasoning being that this is really a byte string, I don't want users to consider it reasonable to cast this to a user-readable string (knowing it's a UUID and seeing it's a typed string, that would be a reasonable API assumption I reckon), they really should .String() it to get the string form of a UUID. The same thing holds for CID (and probably should for other types that are not utf8 strings IMO).

And, I didn't use []byte because it needs to be used for map keys (I learnt my Go lesson about that while trying it!).

Happy to change it if you think it should be a simple string though.


// Tag returns an easy way to identify this request id as a graphsync request (for libp2p connections)
func (r RequestID) Tag() string {
return fmt.Sprintf("graphsync-request-%d", r)
return r.String()
}

// String form of a RequestID (should be a well-formed UUIDv4 string)
func (r RequestID) String() string {
return uuid.Must(uuid.FromBytes([]byte(r.string))).String()
}

// Byte form of a RequestID
func (r RequestID) Bytes() []byte {
return []byte(r.string)
}

// Create a new, random RequestID (should be a UUIDv4)
func NewRequestID() RequestID {
u := uuid.New()
return RequestID{string(u[:])}
}

// Create a RequestID from a byte slice
func ParseRequestID(b []byte) (RequestID, error) {
_, err := uuid.FromBytes(b)
if err != nil {
return RequestID{}, err
}
return RequestID{string(b)}, nil
}

// Priority a priority for a GraphSync request.
Expand All @@ -28,7 +55,7 @@ type ExtensionName string
// ExtensionData is a name/data pair for a graphsync extension
type ExtensionData struct {
Name ExtensionName
Data []byte
Data datamodel.Node
}

const (
Expand Down Expand Up @@ -146,7 +173,7 @@ type RequestData interface {

// Extension returns the content for an extension on a response, or errors
// if extension is not present
Extension(name ExtensionName) ([]byte, bool)
Extension(name ExtensionName) (datamodel.Node, bool)

// IsCancel returns true if this particular request is being cancelled
IsCancel() bool
Expand All @@ -162,7 +189,7 @@ type ResponseData interface {

// Extension returns the content for an extension on a response, or errors
// if extension is not present
Extension(name ExtensionName) ([]byte, bool)
Extension(name ExtensionName) (datamodel.Node, bool)
}

// BlockData gives information about a block included in a graphsync response
Expand Down
Loading