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

3

4

5 6
package "go-ipld-prime" {
  interface Node {
7 8 9 10 11
  }
  interface NodeBuilder {
  }
  interface Path {
  }
12
  interface Link
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
  package traversal {
    package selector {
      interface Selector {
      }
      object "PackagePublicFunctions" as goSelectorPF {
        ReifySelector(cidRootedSelector Node) (Selector, error)
      }
    }
    interface AdvVisitFn {
    }
    class TraversalConfig {
    }
    class TraversalProgress {
      TraverseInformatively(Node, Selector, AdvVisitFn)
    }
28

29
    TraversalProgress *-- TraversalConfig
30
  }
31

hannahhoward's avatar
hannahhoward committed
32 33 34
  interface Loader {

  }
35 36 37
}

package "go-graphsync" {
38
  
39 40 41 42 43
    class ResponseProgress {
      Node ipld.Node
      Path ipld.Path
      LastBlock struct {
        ipld.Node
hannahhoward's avatar
hannahhoward committed
44
        ipld.Link }
45 46 47 48 49
    }
    
    interface Cid2BlockFn {

    }
50
    class GraphSync {
51 52 53
      Request(ctx context.Context, p peer.ID, rootedSelector Node) (chan ResponseProgress, chan error)
      GetBlocks(ctx context.Context, p peer.ID, rootedSelector Node) (chan blocks.Block, chan error)
      ReceiveMessage(ctx context.Context, sender peer.ID, incoming GraphSyncMessage)     
54 55 56
      ReceiveError(error)
    }

57
    GraphSync *-- Loader
58

59
  package network {
60
    
61 62 63 64 65 66 67 68
    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)
69
      ConnectTo(ctx context.Context, peer.ID) error
70 71 72 73 74 75 76
      NewMessageSender(context.Context, peer.ID) (MessageSender, error)
    }
    
    interface MessageSender {
	    SendMsg(context.Context, GraphSyncMessage) error
	    Close() error
	    Reset() error
77 78 79 80 81 82
    }

    Receiver <|-- GraphSync : receiver for

    class libP2PGraphSyncNetwork {
    }
83

84 85 86
    GraphSyncNetwork <|-- libP2PGraphSyncNetwork
    
    object "Package Public Functions" as goGraphSyncNetworkPF {
87
      NewLibP2PNetwork(host libp2pHost.Host) GraphSyncNetwork
88 89 90 91
    }
    goGraphSyncNetworkPF .. libP2PGraphSyncNetwork 
  }

92 93
  package messagequeue {
    class MessageQueue {
94
      AddRequest(GraphSyncRequest)
95
      AddResponses([]GraphSyncResponse, []Block) <-chan struct{}
96 97 98 99 100 101 102 103 104 105 106
      Startup()
      Shutdown()
    }

    object "PackagePublicFunctions" as goMessageQueuePF {
      New(context.Context, peer.ID, GraphSyncNetwork) *MessageQueue
    }
    GraphSync .. goMessageQueuePF
    MessageQueue *-- GraphSyncNetwork
  }

107
  package peermanager {
108 109 110 111
    class PeerManager {
      Connected(p peer.ID)
      Disconnected(p peer.ID)
      ConnectedPeers() []peer.ID
112 113 114 115
      GetProcess(peer.ID) PeerProcess
    }

    class PeerMessageManager {
116
      SendRequest(peer.ID, GraphSyncRequest)
117
      SendResponses(peer.ID, []GraphSyncResponse, []Block)
118 119 120
    }

    object "Package Public Functions" as goPeerManagerPF {
121 122
      New(ctx context.Context, createPeerProcess func(context, peer.ID) PeerProcess)
      NewMessageManager(ctx context.Context, createPeerQueue func(context, peer.ID) MessageQueue)
123 124
    }
    GraphSync .. goPeerManagerPF
125 126
    PeerManager <|-- PeerMessageManager
    PeerMessageManager *-- MessageQueue
127 128
  }

129
  package requestmanager {
130 131 132 133
    interface ResponseProgress {

    }
    interface ResponseError {
134

135
    }
136 137 138 139 140 141 142
    class RequestManager {
      SetDelegate(peerHandler PeerMessageManager)
      SendRequest(ctx context.Context, p peer.ID, cidRootedSelector Node) chan Block
      ProcessResponses(message GraphSyncMessage)
    }
    RequestManager *-- PeerMessageManager
    GraphSync *-- RequestManager
143 144
  }

145
  
146
  package responsemanager {
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
    package peertaskqueue {
      package peertask {
        class Task {
        }
        class TaskBlock {
          MarkPrunable(Identifier)
          PruneTasks()
          Index()
          SetIndex(int)
        }

        interface Identifier {
        }
        object "Package Public Functions" as goPeerTaskPF {
          FIFOCompare(a, b *TaskBlock) bool
          PriorityCompare(a, b *TaskBlock) bool
          WrapCompare(func(a, b *TaskBlock) bool) func(a, b pq.Elem) bool
          NewTaskBlock([]Task, int, peer.ID, func([]Task)) *TaskBlock
        }
      }

      package peertracker {
        class PeerTracker {
          StartTask(Identifier)
          TaskDone(Identifier)
          Index()
          SetIndex(int)
          PushBlock(peer.ID, []Task, func([]Task))
          PopBlock() *TaskBlock
          Remove(Identifier)
          Freeze()
          Thaw() bool
          FullThaw()
          IsFrozen() bool
        }
        object "Package Public Functions" as goPeerTrackerPF {
          New() *PeerTracker
          PeerCompare(a, b pq.Elem) bool
        }
        PeerTracker *-- TaskBlock
        PeerTracker .. goPeerTaskPF
      }

      class PeerTaskQueue {
        PushBlock(to peer.ID, tasks ...Task)
	      PopBlock() *TaskBlock
	      Remove(identifier Identifier, p peer.ID)
	      ThawRound()
        FullThaw()
      }
      PeerTaskQueue *-- PeerTracker
      PeerTaskQueue .. goPeerTrackerPF

      object "Package Public Functions" as goPeerTaskQueuePF {
        New() *PeerTaskQueue
      }
      GraphSync .. goPeerTaskQueuePF     
    }

    package loader {
      object "Package Public Functions" as goResponseLoaderPF {
        WrapLoader(Loader,GraphSyncRequestID, PeerResponseSender) Loader
      }
    }
    package linktracker {
      class LinkTracker {
        ShouldSendBlockFor(Link) bool
        RecordLinkTraversal(GraphSyncRequestID, Link, bool)
        FinishRequest(GraphSyncRequestID) bool
      }
      object "Package Public Functions" as goLinkTrackerPF {
        New() *LinkTracker
      }
    }

    package responsebuilder {
      class ResponseBuilder {
        AddBlock(Block)
        AddLink(GraphSyncRequestID, Link, bool)
        AddCompletedRequest(GraphSyncRequestID, GraphSyncResponseStatusCode)
        Empty() bool
        Build(IPLDBridge) ([]GraphSyncResponse, []Block, error)    
      }
      object "Package Public Functions" as goResponseBuilderPF {
        New() *ResponseBuilder
      }
    }
    
    package peerresponsemanager {
      class PeerResponseManager {
        SenderForPeer(p peer.ID) PeerResponseSender
      }
      class PeerResponseSender {
        Startup()
        Shutdown()
        SendResponse(GraphSyncRequestID,Link,[]byte)
	      FinishRequest(GraphSyncRequestID)
	      FinishWithError(GraphSyncRequestID, GraphSyncResponseStatusCode)
      }

      object "Package Public Functions" as goPeerResponseManagerPF {
        New(Context, func(Context, peer.ID) PeerResponseSender) *PeerResponseManager
        NewResponseSender(Context, peer.ID, PeerMessageManager, IPLDBridge) PeerResponseSender  
      }

      PeerResponseManager *-- PeerResponseSender
      PeerResponseSender *-- LinkTracker
      PeerResponseSender *-- ResponseBuilder
      PeerResponseSender *-- PeerMessageManager
      PeerResponseSender *-- IPLDBridge
      PeerResponseSender .. goLinkTrackerPF
      PeerResponseSender .. goResponseBuilderPF
      GraphSync .. goPeerResponseManagerPF     
    }

    class ResponseManager {
      ProcessRequests(context, peer.ID, []GraphSyncRequests)
    }

    object "Package Public Functions" as goResponseManagerPF {
      New(Context, Loader, IPLDBridge, PeerResponseManager, PeerTaskQueue) *ResponseManager
    }
    GraphSync *-- ResponseManager
    ResponseManager *-- Loader
    ResponseManager *-- IPLDBridge
    ResponseManager *-- PeerResponseManager
    ResponseManager *-- PeerTaskQueue
    ResponseManager .. goResponseLoaderPF
    GraphSync .. goResponseManagerPF
276
  }
277

278 279
  package message {
    object "Package Public Functions" as goGraphSyncMessagePF {
280 281
      func FromPBReader(pbr ggio.Reader) (GraphSyncMessage, error)
      func FromNet(r io.Reader) (GraphSyncMessage, error)
282 283 284 285
      func New() GraphSyncMessage
      func NewRequest(GraphSyncRequestID, []byte, GraphSyncPriority) GraphSyncRequest
      func CancelRequest(GraphSyncRequestID) GraphSyncRequest
      func NewResponse(GraphSyncRequestID, GraphSyncResponseStatusCode, []byte) GraphSyncResponse
286 287 288
    }
    goGraphSyncMessagePF .. libP2PGraphSyncNetwork

289
    class GraphSyncRequest {
290
      Selector() []bytes
291 292 293
      Priority() Priority
      ID()       int
      IsCancel() bool
294 295
    }

296
    class GraphSyncResponse {
297 298
      RequestID() int
      Status() GraphSyncStatus
299
      Extra() []bytes
300 301 302 303 304
    }

    interface GraphSyncMessage {
      Requests() : []GraphSyncRequest
      Responses() : []GraphSyncResponse
305
      Blocks() : []Blocks
306 307 308
      AddRequest(GraphSyncRequest)
      AddResponse(GraphSyncResponse)
      AddBlock(Block)
309 310 311
    }

    interface Exportable {
312
      ToProto()
313
      ToNet(w io.Writer) error
314 315 316 317 318 319 320 321
	  }

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

322 323
  package ipldbridge {
    interface IPLDBridge {
324
      BuildNode(func(NodeBuilder) ipld.Node) (ipld.Node, error)
325
	    ValidateSelectorSpec(rootedSelector ipld.Node) []error
326 327 328
	    EncodeNode(ipld.Node) ([]byte, error)
	    DecodeNode([]byte) (ipld.Node, error)
	    DecodeSelectorSpec(cidRootedSelector ipld.Node) (ipld.Node, Selector, error)
329
	    Traverse(ctx context.Context, loader Loader, root ipld.Node, s Selector, fn AdvVisitFn) error
330 331 332 333 334 335 336 337 338 339
    }

    GraphSync *-- IPLDBridge
    RequestManager *-- IPLDBridge
    ResponseManager *-- IPLDBridge
  
    class ipldBridge {
    }

    object "PackagePublicFunctions" as goIPLDBridge {
340
      NewIPLDBridge() IPLDBridge
341 342 343 344 345 346 347 348 349 350
    }

    IPLDBridge <|-- ipldBridge
    goIPLDBridge .. ipldBridge 
    ipldBridge *-- MulticodecDecodeTable
    ipldBridge *-- NodeBuilderChooser
    ipldBridge .. TraversalProgress
    ipldBridge .. goSelectorPF
    ipldBridge .. goIPLDReposePf
  }
351
  object "PackagePublicFunctions" as goGraphsyncPf {
352
    New(ctx context.Context, network GraphSyncNetwork, ipldBridge IPLDBridge, loader Loader) GraphSync
353 354
    LoaderFromCid2BlockFn(cid2BlockFn Cid2BlockFn) Loader
    SelectorSpecFromCidAndPath(lnk cid.Cid, pathSegments []string) (ipld.Node, error) 
355 356 357 358 359 360 361 362 363 364
  }
}

package "go-filecoin" {
  class "go-filecoin" {
  }

  "go-filecoin" *-- GraphSync
  "go-filecoin" .. goGraphsyncPf
  "go-filecoin" .. goGraphSyncNetworkPF
365 366 367 368
  "go-filecoin" .. goIPLDBridge
  "go-filecoin" *-- RawLoader
  "go-filecoin" *-- MulticodecDecodeTable
  "go-filecoin" *-- NodeBuilderChooser
369

370 371
}

372
@enduml