go-graphsync.puml 5.02 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
    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)
65 66 67 68 69 70 71
      NewMessageSender(context.Context, peer.ID) (MessageSender, error)
    }
    
    interface MessageSender {
	    SendMsg(context.Context, GraphSyncMessage) error
	    Close() error
	    Reset() error
72 73 74 75 76 77
    }

    Receiver <|-- GraphSync : receiver for

    class libP2PGraphSyncNetwork {
    }
78

79 80 81
    GraphSyncNetwork <|-- libP2PGraphSyncNetwork
    
    object "Package Public Functions" as goGraphSyncNetworkPF {
82 83
      NewLibP2PNetwork(host libp2pHost.Host,
      decodeSelectionResponseFunc: DecodeSelectionResponseFunc,
84
      decodeSelectorFunc: DecodeSelectorFunc) GraphSyncNetwork
85 86 87 88 89 90 91
    }
    goGraphSyncNetworkPF .. libP2PGraphSyncNetwork 
  }

  package requestmanager {
  class RequestManager {
    network : GraphSyncNetwork
92 93
    selectorQuerier: SelectorQuerier

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

128
    object "Package Public Functions" as goGraphSyncMessagePF {
129 130
      func FromPBReader(pbr ggio.Reader,
      decodeSelectionResponseFunc: DecodeSelectionResponseFunc,
131
      decodeSelectorFunc: DecodeSelectorFunc) (GraphSyncMessage, error)
132 133 134
      func FromNet(r io.Reader,
      decodeSelectionResponseFunc: DecodeSelectionResponseFunc,
      decodeSelectorFunc: DecodeSelectorFunc) (GraphSyncMessage, error)
135 136 137
    }
    goGraphSyncMessagePF .. libP2PGraphSyncNetwork

138 139
    interface GraphSyncRequest {
      Selector() Selector
140
      Root()     Cid
141 142 143
      Priority() Priority
      ID()       int
      IsCancel() bool
144 145
    }

146 147 148
    interface GraphSyncResponse {
      RequestID() int
      Status() GraphSyncStatus
149 150 151 152 153 154 155 156
    }

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

    interface Exportable {
157
      ToProto()
158
      ToNet(w io.Writer) error
159 160 161 162 163 164 165 166 167
	  }

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

  object "PackagePublicFunctions" as goGraphsyncPf {
hannahhoward's avatar
hannahhoward committed
168
    New(ctx context.Context, network GraphSyncNetwork, selectorQuerier SelectorQuerier) GraphSync
169 170 171 172 173 174 175
  }

}

package "go-filecoin" {
  class "go-filecoin" {
    graphSync : GraphSync
176
    selectorQuerier: SelectorQuerier
177
    host: libp2pHost.Host
178 179
    decodeSelectionResponseFunc: DecodeSelectionResponseFunc
    decodeSelectorFunc: DecodeSelectorFunc
180 181 182 183 184 185
  }

  "go-filecoin" *-- GraphSync
  "go-filecoin" .. goGraphsyncPf
  "go-filecoin" .. goGraphSyncNetworkPF
  "go-filecoin" .. Selector
186 187 188
  "go-filecoin" *-- SelectorQuerier
  "go-filecoin" .. goSelectorPF

189 190 191
}

@enduml