Skip to content

Commit 05233b7

Browse files
committed
chore(ipld): ipld.Node -> datamodel.Node
1 parent 1649e55 commit 05233b7

26 files changed

+83
-77
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (vl *myValidator) ValidatePush(
8585
sender peer.ID,
8686
voucher datatransfer.Voucher,
8787
baseCid cid.Cid,
88-
selector ipld.Node) error {
88+
selector datamodel.Node) error {
8989
9090
v := voucher.(*myVoucher)
9191
if v.data == "" || v.data != "validpush" {
@@ -99,7 +99,7 @@ func (vl *myValidator) ValidatePull(
9999
receiver peer.ID,
100100
voucher datatransfer.Voucher,
101101
baseCid cid.Cid,
102-
selector ipld.Node) error {
102+
selector datamodel.Node) error {
103103
104104
v := voucher.(*myVoucher)
105105
if v.data == "" || v.data != "validpull" {
@@ -135,7 +135,7 @@ must be sent with the request. Using the trivial examples above:
135135
For more detail, please see the [unit tests](https://github.com/filecoin-project/go-data-transfer/blob/master/impl/impl_test.go).
136136

137137
### Open a Push or Pull Request
138-
For a push or pull request, provide a context, a `datatransfer.Voucher`, a host recipient `peer.ID`, a baseCID `cid.CID` and a selector `ipld.Node`. These
138+
For a push or pull request, provide a context, a `datatransfer.Voucher`, a host recipient `peer.ID`, a baseCID `cid.CID` and a selector `datamodel.Node`. These
139139
calls return a `datatransfer.ChannelID` and any error:
140140
```go
141141
channelID, err := dtm.OpenPullDataChannel(ctx, recipient, voucher, baseCid, selector)

channels/channel_state.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"bytes"
55

66
"github.com/ipfs/go-cid"
7-
"github.com/ipld/go-ipld-prime"
87
"github.com/ipld/go-ipld-prime/codec/dagcbor"
8+
"github.com/ipld/go-ipld-prime/datamodel"
99
basicnode "github.com/ipld/go-ipld-prime/node/basic"
1010
peer "github.com/libp2p/go-libp2p-core/peer"
1111

@@ -42,7 +42,7 @@ func (c channelState) BaseCID() cid.Cid { return c.ic.BaseCid }
4242

4343
// Selector returns the IPLD selector for this data transfer (represented as
4444
// an IPLD node)
45-
func (c channelState) Selector() ipld.Node {
45+
func (c channelState) Selector() datamodel.Node {
4646
builder := basicnode.Prototype.Any.NewBuilder()
4747
reader := bytes.NewReader(c.ic.Selector.Raw)
4848
err := dagcbor.Decode(builder, reader)

channels/channels.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
"github.com/ipfs/go-cid"
99
"github.com/ipfs/go-datastore"
10-
"github.com/ipld/go-ipld-prime"
10+
"github.com/ipld/go-ipld-prime/datamodel"
1111
peer "github.com/libp2p/go-libp2p-core/peer"
1212
cbg "github.com/whyrusleeping/cbor-gen"
1313
"golang.org/x/xerrors"
@@ -111,7 +111,7 @@ func (c *Channels) dispatch(eventName fsm.EventName, channel fsm.StateType) {
111111

112112
// CreateNew creates a new channel id and channel state and saves to channels.
113113
// returns error if the channel exists already.
114-
func (c *Channels) CreateNew(selfPeer peer.ID, tid datatransfer.TransferID, baseCid cid.Cid, selector ipld.Node, voucher datatransfer.TypedVoucher, initiator, dataSender, dataReceiver peer.ID) (datatransfer.ChannelID, error) {
114+
func (c *Channels) CreateNew(selfPeer peer.ID, tid datatransfer.TransferID, baseCid cid.Cid, selector datamodel.Node, voucher datatransfer.TypedVoucher, initiator, dataSender, dataReceiver peer.ID) (datatransfer.ChannelID, error) {
115115
var responder peer.ID
116116
if dataSender == initiator {
117117
responder = dataReceiver

impl/impl.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/ipfs/go-cid"
1111
"github.com/ipfs/go-datastore"
1212
logging "github.com/ipfs/go-log/v2"
13-
"github.com/ipld/go-ipld-prime"
13+
"github.com/ipld/go-ipld-prime/datamodel"
1414
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
1515
"github.com/libp2p/go-libp2p-core/peer"
1616
"go.opentelemetry.io/otel"
@@ -178,7 +178,7 @@ func (m *manager) RegisterVoucherType(voucherType datatransfer.TypeIdentifier, v
178178

179179
// OpenPushDataChannel opens a data transfer that will send data to the recipient peer and
180180
// transfer parts of the piece that match the selector
181-
func (m *manager) OpenPushDataChannel(ctx context.Context, requestTo peer.ID, voucher datatransfer.TypedVoucher, baseCid cid.Cid, selector ipld.Node) (datatransfer.ChannelID, error) {
181+
func (m *manager) OpenPushDataChannel(ctx context.Context, requestTo peer.ID, voucher datatransfer.TypedVoucher, baseCid cid.Cid, selector datamodel.Node) (datatransfer.ChannelID, error) {
182182
log.Infof("open push channel to %s with base cid %s", requestTo, baseCid)
183183

184184
req, err := m.newRequest(ctx, selector, false, voucher, baseCid, requestTo)
@@ -219,7 +219,7 @@ func (m *manager) OpenPushDataChannel(ctx context.Context, requestTo peer.ID, vo
219219

220220
// OpenPullDataChannel opens a data transfer that will request data from the sending peer and
221221
// transfer parts of the piece that match the selector
222-
func (m *manager) OpenPullDataChannel(ctx context.Context, requestTo peer.ID, voucher datatransfer.TypedVoucher, baseCid cid.Cid, selector ipld.Node) (datatransfer.ChannelID, error) {
222+
func (m *manager) OpenPullDataChannel(ctx context.Context, requestTo peer.ID, voucher datatransfer.TypedVoucher, baseCid cid.Cid, selector datamodel.Node) (datatransfer.ChannelID, error) {
223223
log.Infof("open pull channel to %s with base cid %s", requestTo, baseCid)
224224

225225
req, err := m.newRequest(ctx, selector, true, voucher, baseCid, requestTo)

impl/initiating_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/ipfs/go-cid"
1010
"github.com/ipfs/go-datastore"
1111
dss "github.com/ipfs/go-datastore/sync"
12-
"github.com/ipld/go-ipld-prime"
12+
"github.com/ipld/go-ipld-prime/datamodel"
1313
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
1414
"github.com/libp2p/go-libp2p-core/peer"
1515
"github.com/stretchr/testify/require"
@@ -629,7 +629,7 @@ type harness struct {
629629
ds datastore.Batching
630630
dt datatransfer.Manager
631631
voucherValidator *testutil.StubbedValidator
632-
stor ipld.Node
632+
stor datamodel.Node
633633
voucher datatransfer.TypedVoucher
634634
voucherResult datatransfer.TypedVoucher
635635
baseCid cid.Cid

impl/integration_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/ipfs/go-unixfs/importer/balanced"
2828
ihelper "github.com/ipfs/go-unixfs/importer/helpers"
2929
"github.com/ipld/go-ipld-prime"
30+
"github.com/ipld/go-ipld-prime/datamodel"
3031
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
3132
"github.com/libp2p/go-libp2p-core/host"
3233
"github.com/libp2p/go-libp2p-core/peer"
@@ -1187,9 +1188,9 @@ type retrievalRevalidator struct {
11871188
func (r *retrievalRevalidator) ValidatePush(
11881189
chid datatransfer.ChannelID,
11891190
sender peer.ID,
1190-
voucher ipld.Node,
1191+
voucher datamodel.Node,
11911192
baseCid cid.Cid,
1192-
selector ipld.Node) (datatransfer.ValidationResult, error) {
1193+
selector datamodel.Node) (datatransfer.ValidationResult, error) {
11931194
vr := datatransfer.ValidationResult{
11941195
Accepted: true,
11951196
RequiresFinalization: r.requiresFinalization,
@@ -1209,9 +1210,9 @@ func (r *retrievalRevalidator) ValidatePush(
12091210
func (r *retrievalRevalidator) ValidatePull(
12101211
chid datatransfer.ChannelID,
12111212
sender peer.ID,
1212-
voucher ipld.Node,
1213+
voucher datamodel.Node,
12131214
baseCid cid.Cid,
1214-
selector ipld.Node) (datatransfer.ValidationResult, error) {
1215+
selector datamodel.Node) (datatransfer.ValidationResult, error) {
12151216
vr := datatransfer.ValidationResult{
12161217
Accepted: true,
12171218
RequiresFinalization: r.requiresFinalization,

impl/receiving_requests.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55

66
"github.com/ipfs/go-cid"
7-
"github.com/ipld/go-ipld-prime"
7+
"github.com/ipld/go-ipld-prime/datamodel"
88
"github.com/libp2p/go-libp2p-core/peer"
99
"golang.org/x/xerrors"
1010

@@ -50,7 +50,7 @@ func (m *manager) acceptRequest(chid datatransfer.ChannelID, incoming datatransf
5050
return datatransfer.ValidationResult{}, xerrors.Errorf("unknown voucher type: %s", voucher.Type)
5151
}
5252

53-
var validatorFunc func(datatransfer.ChannelID, peer.ID, ipld.Node, cid.Cid, ipld.Node) (datatransfer.ValidationResult, error)
53+
var validatorFunc func(datatransfer.ChannelID, peer.ID, datamodel.Node, cid.Cid, datamodel.Node) (datatransfer.ValidationResult, error)
5454
validator := processor.(datatransfer.RequestValidator)
5555
if incoming.IsPull() {
5656
validatorFunc = validator.ValidatePull

impl/responding_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/ipfs/go-datastore"
1212
dss "github.com/ipfs/go-datastore/sync"
1313
"github.com/ipld/go-ipld-prime"
14+
"github.com/ipld/go-ipld-prime/datamodel"
1415
cidlink "github.com/ipld/go-ipld-prime/linking/cid"
1516
"github.com/libp2p/go-libp2p-core/peer"
1617
"github.com/stretchr/testify/assert"
@@ -1152,7 +1153,7 @@ type receiverHarness struct {
11521153
sv *testutil.StubbedValidator
11531154
ds datastore.Batching
11541155
dt datatransfer.Manager
1155-
stor ipld.Node
1156+
stor datamodel.Node
11561157
voucher datatransfer.TypedVoucher
11571158
baseCid cid.Cid
11581159
}

impl/utils.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55

66
"github.com/ipfs/go-cid"
7-
"github.com/ipld/go-ipld-prime"
7+
"github.com/ipld/go-ipld-prime/datamodel"
88
"github.com/libp2p/go-libp2p-core/peer"
99

1010
datatransfer "github.com/filecoin-project/go-data-transfer/v2"
@@ -29,7 +29,7 @@ var resumeTransportStatesResponder = statusList{
2929
}
3030

3131
// newRequest encapsulates message creation
32-
func (m *manager) newRequest(ctx context.Context, selector ipld.Node, isPull bool, voucher datatransfer.TypedVoucher, baseCid cid.Cid, to peer.ID) (datatransfer.Request, error) {
32+
func (m *manager) newRequest(ctx context.Context, selector datamodel.Node, isPull bool, voucher datatransfer.TypedVoucher, baseCid cid.Cid, to peer.ID) (datatransfer.Request, error) {
3333
// Generate a new transfer ID for the request
3434
tid := datatransfer.TransferID(m.transferIDGen.next())
3535
return message.NewRequest(tid, false, isPull, &voucher, baseCid, selector)

ipldutils/ipldutils.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/ipld/go-ipld-prime"
1010
"github.com/ipld/go-ipld-prime/codec/dagcbor"
11+
"github.com/ipld/go-ipld-prime/datamodel"
1112
"github.com/ipld/go-ipld-prime/node/bindnode"
1213
"github.com/ipld/go-ipld-prime/schema"
1314
cbg "github.com/whyrusleeping/cbor-gen"
@@ -99,9 +100,9 @@ func FromReader(r io.Reader, ptrValue interface{}) (interface{}, error) {
99100
return typ, nil
100101
}
101102

102-
// FromNode converts an ipld.Node into an appropriate Go type that's provided as
103+
// FromNode converts an datamodel.Node into an appropriate Go type that's provided as
103104
// a pointer via the ptrValue argument
104-
func FromNode(node ipld.Node, ptrValue interface{}) (interface{}, error) {
105+
func FromNode(node datamodel.Node, ptrValue interface{}) (interface{}, error) {
105106
name := typeName(ptrValue)
106107
proto, err := prototypeFor(name, ptrValue)
107108
if err != nil {
@@ -126,7 +127,7 @@ func FromNode(node ipld.Node, ptrValue interface{}) (interface{}, error) {
126127
}
127128

128129
// ToNode converts a Go type that's provided as a pointer via the ptrValue
129-
// argument to an ipld.Node.
130+
// argument to an datamodel.Node.
130131
func ToNode(ptrValue interface{}) (schema.TypedNode, error) {
131132
name := typeName(ptrValue)
132133
proto, err := prototypeFor(name, ptrValue)
@@ -136,15 +137,15 @@ func ToNode(ptrValue interface{}) (schema.TypedNode, error) {
136137
return bindnode.Wrap(ptrValue, proto.Type(), bindnodeOptions...), err
137138
}
138139

139-
// NodeToWriter is a utility method that serializes an ipld.Node as DAG-CBOR to
140+
// NodeToWriter is a utility method that serializes an datamodel.Node as DAG-CBOR to
140141
// a Writer
141-
func NodeToWriter(node ipld.Node, w io.Writer) error {
142+
func NodeToWriter(node datamodel.Node, w io.Writer) error {
142143
return ipld.EncodeStreaming(w, node, dagcbor.Encode)
143144
}
144145

145-
// NodeToBytes is a utility method that serializes an ipld.Node as DAG-CBOR to
146+
// NodeToBytes is a utility method that serializes an datamodel.Node as DAG-CBOR to
146147
// a []byte
147-
func NodeToBytes(node ipld.Node) ([]byte, error) {
148+
func NodeToBytes(node datamodel.Node) ([]byte, error) {
148149
var buf bytes.Buffer
149150
err := NodeToWriter(node, &buf)
150151
if err != nil {
@@ -153,9 +154,9 @@ func NodeToBytes(node ipld.Node) ([]byte, error) {
153154
return buf.Bytes(), nil
154155
}
155156

156-
// NodeFromBytes is a utility method that deserializes an untyped ipld.Node
157+
// NodeFromBytes is a utility method that deserializes an untyped datamodel.Node
157158
// from DAG-CBOR format bytes
158-
func NodeFromBytes(b []byte) (ipld.Node, error) {
159+
func NodeFromBytes(b []byte) (datamodel.Node, error) {
159160
return ipld.Decode(b, dagcbor.Decode)
160161
}
161162

@@ -169,14 +170,14 @@ func TypeToWriter(ptrValue interface{}, w io.Writer) error {
169170
return ipld.EncodeStreaming(w, node, dagcbor.Encode)
170171
}
171172

172-
func NodeToDeferred(node ipld.Node) (*cbg.Deferred, error) {
173+
func NodeToDeferred(node datamodel.Node) (*cbg.Deferred, error) {
173174
byts, err := NodeToBytes(node)
174175
if err != nil {
175176
return nil, err
176177
}
177178
return &cbg.Deferred{Raw: byts}, nil
178179
}
179180

180-
func DeferredToNode(def *cbg.Deferred) (ipld.Node, error) {
181+
func DeferredToNode(def *cbg.Deferred) (datamodel.Node, error) {
181182
return NodeFromBytes(def.Raw)
182183
}

manager.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"context"
55

66
"github.com/ipfs/go-cid"
7-
"github.com/ipld/go-ipld-prime"
7+
"github.com/ipld/go-ipld-prime/datamodel"
88
"github.com/libp2p/go-libp2p-core/peer"
99
)
1010

@@ -66,9 +66,9 @@ type RequestValidator interface {
6666
ValidatePush(
6767
chid ChannelID,
6868
sender peer.ID,
69-
voucher ipld.Node,
69+
voucher datamodel.Node,
7070
baseCid cid.Cid,
71-
selector ipld.Node) (ValidationResult, error)
71+
selector datamodel.Node) (ValidationResult, error)
7272
// ValidatePull validates a pull request received from the peer that will receive data
7373
// -- All information about the validation operation is contained in ValidationResult,
7474
// including if it was rejected. Information about why a rejection occurred should be embedded
@@ -77,9 +77,9 @@ type RequestValidator interface {
7777
ValidatePull(
7878
chid ChannelID,
7979
receiver peer.ID,
80-
voucher ipld.Node,
80+
voucher datamodel.Node,
8181
baseCid cid.Cid,
82-
selector ipld.Node) (ValidationResult, error)
82+
selector datamodel.Node) (ValidationResult, error)
8383

8484
// ValidateRestart validates restarting a request
8585
// -- All information about the validation operation is contained in ValidationResult,
@@ -123,11 +123,11 @@ type Manager interface {
123123

124124
// open a data transfer that will send data to the recipient peer and
125125
// transfer parts of the piece that match the selector
126-
OpenPushDataChannel(ctx context.Context, to peer.ID, voucher TypedVoucher, baseCid cid.Cid, selector ipld.Node) (ChannelID, error)
126+
OpenPushDataChannel(ctx context.Context, to peer.ID, voucher TypedVoucher, baseCid cid.Cid, selector datamodel.Node) (ChannelID, error)
127127

128128
// open a data transfer that will request data from the sending peer and
129129
// transfer parts of the piece that match the selector
130-
OpenPullDataChannel(ctx context.Context, to peer.ID, voucher TypedVoucher, baseCid cid.Cid, selector ipld.Node) (ChannelID, error)
130+
OpenPullDataChannel(ctx context.Context, to peer.ID, voucher TypedVoucher, baseCid cid.Cid, selector datamodel.Node) (ChannelID, error)
131131

132132
// send an intermediate voucher as needed when the receiver sends a request for revalidation
133133
SendVoucher(ctx context.Context, chid ChannelID, voucher TypedVoucher) error

message.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"io"
55

66
"github.com/ipfs/go-cid"
7-
"github.com/ipld/go-ipld-prime"
87
"github.com/ipld/go-ipld-prime/datamodel"
98
"github.com/libp2p/go-libp2p-core/protocol"
109
)
@@ -36,10 +35,10 @@ type Request interface {
3635
IsPull() bool
3736
IsVoucher() bool
3837
VoucherType() TypeIdentifier
39-
Voucher() (ipld.Node, error)
38+
Voucher() (datamodel.Node, error)
4039
TypedVoucher() (TypedVoucher, error)
4140
BaseCid() cid.Cid
42-
Selector() (ipld.Node, error)
41+
Selector() (datamodel.Node, error)
4342
IsRestartExistingChannelRequest() bool
4443
RestartChannelId() (ChannelID, error)
4544
}
@@ -51,6 +50,6 @@ type Response interface {
5150
IsComplete() bool
5251
Accepted() bool
5352
VoucherResultType() TypeIdentifier
54-
VoucherResult() (ipld.Node, error)
53+
VoucherResult() (datamodel.Node, error)
5554
EmptyVoucherResult() bool
5655
}

message/message1_1prime/message.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/ipfs/go-cid"
77
"github.com/ipld/go-ipld-prime"
8+
"github.com/ipld/go-ipld-prime/datamodel"
89
"github.com/ipld/go-ipld-prime/schema"
910
xerrors "golang.org/x/xerrors"
1011

@@ -19,7 +20,7 @@ var emptyTypedVoucher = datatransfer.TypedVoucher{
1920
}
2021

2122
// NewRequest generates a new request for the data transfer protocol
22-
func NewRequest(id datatransfer.TransferID, isRestart bool, isPull bool, voucher *datatransfer.TypedVoucher, baseCid cid.Cid, selector ipld.Node) (datatransfer.Request, error) {
23+
func NewRequest(id datatransfer.TransferID, isRestart bool, isPull bool, voucher *datatransfer.TypedVoucher, baseCid cid.Cid, selector datamodel.Node) (datatransfer.Request, error) {
2324
if voucher == nil {
2425
voucher = &emptyTypedVoucher
2526
}
@@ -208,7 +209,7 @@ func FromNet(r io.Reader) (datatransfer.Message, error) {
208209
}
209210

210211
// FromNet can read a network stream to deserialize a GraphSyncMessage
211-
func FromIPLD(node ipld.Node) (datatransfer.Message, error) {
212+
func FromIPLD(node datamodel.Node) (datatransfer.Message, error) {
212213
if tn, ok := node.(schema.TypedNode); ok { // shouldn't need this if from Graphsync
213214
node = tn.Representation()
214215
}

message/message1_1prime/transfer_message.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
_ "embed"
55
"io"
66

7-
"github.com/ipld/go-ipld-prime"
7+
"github.com/ipld/go-ipld-prime/datamodel"
88
"github.com/ipld/go-ipld-prime/schema"
99

1010
datatransfer "github.com/filecoin-project/go-data-transfer/v2"
@@ -41,7 +41,7 @@ func (tm *TransferMessage1_1) toIPLD() (schema.TypedNode, error) {
4141
}
4242

4343
// ToIPLD converts a transfer message type to an ipld Node
44-
func (tm *TransferMessage1_1) ToIPLD() (ipld.Node, error) {
44+
func (tm *TransferMessage1_1) ToIPLD() (datamodel.Node, error) {
4545
node, err := tm.toIPLD()
4646
if err != nil {
4747
return nil, err

0 commit comments

Comments
 (0)