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

    Receiver <|-- GraphSync : receiver for

    class libP2PGraphSyncNetwork {
    }
79

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

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

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

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

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

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

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

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

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

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

}

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

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

190 191 192
}

@enduml