@@ -3,7 +3,6 @@ package message
33import (
44 "bytes"
55 "fmt"
6- "io"
76 "strings"
87
98 blocks "github.com/ipfs/go-block-format"
@@ -12,37 +11,8 @@ import (
1211 "github.com/ipld/go-ipld-prime/codec/dagjson"
1312
1413 "github.com/ipfs/go-graphsync"
15- "github.com/ipfs/go-graphsync/message/ipldbind"
16- pb "github.com/ipfs/go-graphsync/message/pb"
1714)
1815
19- // IsTerminalSuccessCode returns true if the response code indicates the
20- // request terminated successfully.
21- // DEPRECATED: use status.IsSuccess()
22- func IsTerminalSuccessCode (status graphsync.ResponseStatusCode ) bool {
23- return status .IsSuccess ()
24- }
25-
26- // IsTerminalFailureCode returns true if the response code indicates the
27- // request terminated in failure.
28- // DEPRECATED: use status.IsFailure()
29- func IsTerminalFailureCode (status graphsync.ResponseStatusCode ) bool {
30- return status .IsFailure ()
31- }
32-
33- // IsTerminalResponseCode returns true if the response code signals
34- // the end of the request
35- // DEPRECATED: use status.IsTerminal()
36- func IsTerminalResponseCode (status graphsync.ResponseStatusCode ) bool {
37- return status .IsTerminal ()
38- }
39-
40- // Exportable is an interface that can serialize to a protobuf
41- type Exportable interface {
42- ToProto () (* pb.Message , error )
43- ToNet (w io.Writer ) error
44- }
45-
4616// GraphSyncRequest is a struct to capture data on a request contained in a
4717// GraphSyncMessage.
4818type GraphSyncRequest struct {
@@ -57,11 +27,15 @@ type GraphSyncRequest struct {
5727
5828// String returns a human-readable form of a GraphSyncRequest
5929func (gsr GraphSyncRequest ) String () string {
60- var buf bytes.Buffer
61- dagjson .Encode (gsr .selector , & buf )
30+ sel := "nil"
31+ if gsr .selector != nil {
32+ var buf bytes.Buffer
33+ dagjson .Encode (gsr .selector , & buf )
34+ sel = buf .String ()
35+ }
6236 return fmt .Sprintf ("GraphSyncRequest<root=%s, selector=%s, priority=%d, id=%s, cancel=%v, update=%v, exts=%s>" ,
6337 gsr .root .String (),
64- buf . String () ,
38+ sel ,
6539 gsr .priority ,
6640 gsr .id .String (),
6741 gsr .isCancel ,
@@ -99,7 +73,8 @@ type GraphSyncMessage struct {
9973// its contents
10074func (gsm GraphSyncMessage ) String () string {
10175 cts := make ([]string , 0 )
102- for _ , req := range gsm .requests {
76+ for i , req := range gsm .requests {
77+ fmt .Printf ("req.String(%v)\n " , i )
10378 cts = append (cts , req .String ())
10479 }
10580 for _ , resp := range gsm .responses {
@@ -213,87 +188,6 @@ func (gsm GraphSyncMessage) Blocks() []blocks.Block {
213188 return bs
214189}
215190
216- func (gsm GraphSyncMessage ) ToIPLD () (* ipldbind.GraphSyncMessage , error ) {
217- ibm := new (ipldbind.GraphSyncMessage )
218- ibm .Requests = make ([]ipldbind.GraphSyncRequest , 0 , len (gsm .requests ))
219- for _ , request := range gsm .requests {
220- ibm .Requests = append (ibm .Requests , ipldbind.GraphSyncRequest {
221- Id : request .id .Bytes (),
222- Root : request .root ,
223- Selector : request .selector ,
224- Priority : request .priority ,
225- Cancel : request .isCancel ,
226- Update : request .isUpdate ,
227- // Extensions: request.extensions,
228- })
229- }
230-
231- ibm .Responses = make ([]ipldbind.GraphSyncResponse , 0 , len (gsm .responses ))
232- for _ , response := range gsm .responses {
233- ibm .Responses = append (ibm .Responses , ipldbind.GraphSyncResponse {
234- Id : response .requestID .Bytes (),
235- Status : response .status ,
236- // Extensions: response.extensions,
237- })
238- }
239-
240- blocks := gsm .Blocks ()
241- ibm .Blocks = make ([]ipldbind.GraphSyncBlock , 0 , len (blocks ))
242- for _ , b := range blocks {
243- ibm .Blocks = append (ibm .Blocks , ipldbind.GraphSyncBlock {
244- Data : b .RawData (),
245- Prefix : b .Cid ().Prefix ().Bytes (),
246- })
247- }
248- return ibm , nil
249- }
250-
251- func messageFromIPLD (ibm * ipldbind.GraphSyncMessage ) (GraphSyncMessage , error ) {
252- requests := make (map [graphsync.RequestID ]GraphSyncRequest , len (ibm .Requests ))
253- for _ , req := range ibm .Requests {
254- // exts := req.Extensions
255- id , err := graphsync .ParseRequestID (req .Id )
256- if err != nil {
257- return GraphSyncMessage {}, err
258- }
259- requests [id ] = newRequest (id , req .Root , req .Selector , graphsync .Priority (req .Priority ), req .Cancel , req .Update , nil )
260- }
261-
262- responses := make (map [graphsync.RequestID ]GraphSyncResponse , len (ibm .Responses ))
263- for _ , res := range ibm .Responses {
264- // exts := res.Extensions
265- id , err := graphsync .ParseRequestID (res .Id )
266- if err != nil {
267- return GraphSyncMessage {}, err
268- }
269- responses [id ] = newResponse (id , graphsync .ResponseStatusCode (res .Status ), nil )
270- }
271-
272- blks := make (map [cid.Cid ]blocks.Block , len (ibm .Blocks ))
273- for _ , b := range ibm .Blocks {
274- pref , err := cid .PrefixFromBytes (b .Prefix )
275- if err != nil {
276- return GraphSyncMessage {}, err
277- }
278-
279- c , err := pref .Sum (b .Data )
280- if err != nil {
281- return GraphSyncMessage {}, err
282- }
283-
284- blk , err := blocks .NewBlockWithCid (b .Data , c )
285- if err != nil {
286- return GraphSyncMessage {}, err
287- }
288-
289- blks [blk .Cid ()] = blk
290- }
291-
292- return GraphSyncMessage {
293- requests , responses , blks ,
294- }, nil
295- }
296-
297191func (gsm GraphSyncMessage ) Loggable () map [string ]interface {} {
298192 requests := make ([]string , 0 , len (gsm .requests ))
299193 for _ , request := range gsm .requests {
0 commit comments