go-graphsync.puml 4.82 KB
Newer Older
1 2
@startuml "GraphSync"

3 4 5 6 7

package "go-ipld-format" {
  interface Node
}

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
note top of "go-selector"
  Is this the right name for this package?
end note

package "go-selector" {

  interface Selector {
  }
  
  interface SelectionResponse {
  }
  
  interface SelectionTraverser {
    Next() SelectionResponse, err
    Cancel()
  }

  interface "GetBlockFunc func(cid) block.Block" as GetBlockFunc

27
  interface SelectorQuerier {
28 29
    Select(Selector, root Cid) SelectionTraverser
    Validate(Selector, root Cid, incomingResponses SelectionTraverser) SelectionTraverser
30
  }
31 32 33 34

  object "Package Public Functions" as goSelectorPF {
    NewSelectorQuerier(getBlockFunc GetBlockFunc) SelectorQuerier
  }
35 36 37

  Node <|-- Selector
  Node <|-- SelectionResponse
38 39 40
}

package "go-graphsync" {
41
  
42 43 44 45
    class GraphSync {
      network : GraphySyncNetwork
      requestManager : RequestManager
      responseManager: ResponseManager
46
      selectorQuerier: SelectorQuerier
47

48
      Request(p peer.ID, selector Selector, root Cid) SelectionTraverser
49 50 51 52
      ReceiveMessage(ctx context.Context, sender peer.ID, incoming GraphSyncMessage)
      ReceiveError(error)
    }
  
53
  GraphSync *-- SelectorQuerier
54 55

  package network {
56
    
57 58 59 60 61 62 63 64 65 66 67 68 69 70
    interface Receiver {
      ReceiveMessage(ctx context.Context, sender peer.ID, incoming GraphSyncMessage)
      ReceiveError(error)
    }

    interface GraphSyncNetwork {
      SendMessage(ctx context.Context, receiver peer.Id, m GraphSyncMessage)
      SetDelegate(receiver Receiver)
    }

    Receiver <|-- GraphSync : receiver for

    class libP2PGraphSyncNetwork {
    }
71

72 73 74
    GraphSyncNetwork <|-- libP2PGraphSyncNetwork
    
    object "Package Public Functions" as goGraphSyncNetworkPF {
75 76
      NewLibP2PNetwork(host libp2pHost.Host,
      decodeSelectionResponseFunc: DecodeSelectionResponseFunc,
77
      decodeSelectorFunc: DecodeSelectorFunc) GraphSyncNetwork
78 79 80 81 82 83 84
    }
    goGraphSyncNetworkPF .. libP2PGraphSyncNetwork 
  }

  package requestmanager {
  class RequestManager {
    network : GraphSyncNetwork
85 86
    selectorQuerier: SelectorQuerier

87
    SendRequest(p peer.ID, selector Selector, root Cid) SelectionTraverser
88 89
    ProcessResponses(responses []GraphSyncResponse)
  }
90
  SelectorQuerier --* RequestManager
91 92 93 94 95 96 97 98 99 100 101 102
  RequestManager *-- GraphSyncNetwork
  GraphSync *-- RequestManager
  note as requestManager
    The ResponseManager uses Validate from go-selector
    to filter incoming Responses based on whether they are valid and produce
    a traverser that only returns valid responses
  end note
  }

  package responsemanager {
  class ResponseManager {
    network : GraphySyncNetwork
103
    selectorQuerier: SelectorQuerier
104 105
    ProcessRequests(p peer.ID, requests []GraphSyncRequests)
  }
106
  SelectorQuerier --* ResponseManager
107 108 109 110 111 112 113 114 115 116 117
  ResponseManager *-- GraphSyncNetwork
  GraphSync *-- ResponseManager
  note as responseManagerNote
    The ResponseManager uses Select from go-selector
    to translate the raw bytes into a selector and then
    traverse the graph to produce a list of blocks

    Question: how to know if response is partial?
  end note
  }
  package message {
118 119 120
    interface "DecodeSelectionResponseFunc func([]byte) SelectionResponse" as DecodeSelectionResponseFunc
  interface "DecodeSelectorFunc func([]byte) Selector" as DecodeSelectorFunc

121
    object "Package Public Functions" as goGraphSyncMessagePF {
122 123
      func FromPBReader(pbr ggio.Reader,
      decodeSelectionResponseFunc: DecodeSelectionResponseFunc,
124
      decodeSelectorFunc: DecodeSelectorFunc) (GraphSyncMessage, error)
125 126 127
      func FromNet(r io.Reader,
      decodeSelectionResponseFunc: DecodeSelectionResponseFunc,
      decodeSelectorFunc: DecodeSelectorFunc) (GraphSyncMessage, error)
128 129 130
    }
    goGraphSyncMessagePF .. libP2PGraphSyncNetwork

131 132
    interface GraphSyncRequest {
      Selector() Selector
133
      Root()     Cid
134 135 136
      Priority() Priority
      ID()       int
      IsCancel() bool
137 138
    }

139 140 141
    interface GraphSyncResponse {
      RequestID() int
      Status() GraphSyncStatus
142 143 144 145 146 147 148 149
    }

    interface GraphSyncMessage {
      Requests() : []GraphSyncRequest
      Responses() : []GraphSyncResponse
    }

    interface Exportable {
150
      ToProto()
151
      ToNet(w io.Writer) error
152 153 154 155 156 157 158 159 160
	  }

    Exportable --|> GraphSyncMessage
    GraphSyncRequest --* GraphSyncMessage
    GraphSyncResponse --* GraphSyncMessage
    
  }

  object "PackagePublicFunctions" as goGraphsyncPf {
hannahhoward's avatar
hannahhoward committed
161
    New(ctx context.Context, network GraphSyncNetwork, selectorQuerier SelectorQuerier) GraphSync
162 163 164 165 166 167 168
  }

}

package "go-filecoin" {
  class "go-filecoin" {
    graphSync : GraphSync
169
    selectorQuerier: SelectorQuerier
170
    host: libp2pHost.Host
171 172
    decodeSelectionResponseFunc: DecodeSelectionResponseFunc
    decodeSelectorFunc: DecodeSelectorFunc
173 174 175 176 177 178
  }

  "go-filecoin" *-- GraphSync
  "go-filecoin" .. goGraphsyncPf
  "go-filecoin" .. goGraphSyncNetworkPF
  "go-filecoin" .. Selector
179 180 181
  "go-filecoin" *-- SelectorQuerier
  "go-filecoin" .. goSelectorPF

182 183 184
}

@enduml