go-graphsync.puml 4.83 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 28
  interface SelectorQuerier {
    Select(Selector, root Node) SelectionTraverser
29 30
    Validate(Selector, root Node, incomingResponses SelectionTraverser) SelectionTraverser
  }
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 49 50 51 52

      Request(p peer.ID, selector Selector, root Node) SelectionTraverser
      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 77 78
      NewLibP2PNetwork(host libp2pHost.Host,
      decodeSelectionResponseFunc: DecodeSelectionResponseFunc,
      decodeSelectorFunc: DecodeSelectorFunc,
      decodeRootNodeFunc: DecodeRootNodeFunc) GraphSyncNetwork
79 80 81 82 83 84 85
    }
    goGraphSyncNetworkPF .. libP2PGraphSyncNetwork 
  }

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

88 89 90
    SendRequest(p peer.ID, selector Selector, node rootNode) SelectionTraverser
    ProcessResponses(responses []GraphSyncResponse)
  }
91
  SelectorQuerier --* RequestManager
92 93 94 95 96 97 98 99 100 101 102 103
  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
104
    selectorQuerier: SelectorQuerier
105 106
    ProcessRequests(p peer.ID, requests []GraphSyncRequests)
  }
107
  SelectorQuerier --* ResponseManager
108 109 110 111 112 113 114 115 116 117 118
  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 {
119 120 121 122
    interface "DecodeSelectionResponseFunc func([]byte) SelectionResponse" as DecodeSelectionResponseFunc
  interface "DecodeSelectorFunc func([]byte) Selector" as DecodeSelectorFunc
  interface "DecodeRootNodeFunc func([]byte) Node" as DecodeRootNodeFunc

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

131 132 133 134 135 136
    interface GraphSyncRequest {
      Selector() Selector
      Root()     Node
      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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
	  }

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

  object "PackagePublicFunctions" as goGraphsyncPf {
    New(ctx context.Context, network GraphSyncNetwork, getBlockFunc GetBlockFunc) GraphSync
  }

}

package "go-filecoin" {
  class "go-filecoin" {
    graphSync : GraphSync
168
    selectorQuerier: SelectorQuerier
169
    host: libp2pHost.Host
170 171 172
    decodeSelectionResponseFunc: DecodeSelectionResponseFunc
    decodeSelectorFunc: DecodeSelectorFunc
    decodeRootNodeFunc: DecodeRootNodeFunc
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