go-graphsync.puml 12.8 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

32 33 34
  interface Storer {

  }
hannahhoward's avatar
hannahhoward committed
35 36 37
  interface Loader {

  }
38 39 40
}

package "go-graphsync" {
41 42 43 44
    
    interface Cid2BlockFn {

    }
45
    class GraphSync {
46 47 48
      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)     
49 50 51
      ReceiveError(error)
    }

52
    GraphSync *-- Loader
53

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
      NewLibP2PNetwork(host libp2pHost.Host) GraphSyncNetwork
84 85 86 87
    }
    goGraphSyncNetworkPF .. libP2PGraphSyncNetwork 
  }

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

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

103
  package peermanager {
104 105 106 107
    class PeerManager {
      Connected(p peer.ID)
      Disconnected(p peer.ID)
      ConnectedPeers() []peer.ID
108 109 110 111
      GetProcess(peer.ID) PeerProcess
    }

    class PeerMessageManager {
112
      SendRequest(peer.ID, GraphSyncRequest)
113
      SendResponses(peer.ID, []GraphSyncResponse, []Block)
114 115 116
    }

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

125 126 127 128 129 130 131 132 133 134 135
    package linktracker {
      class LinkTracker {
        ShouldSendBlockFor(Link) bool
        RecordLinkTraversal(GraphSyncRequestID, Link, bool)
        FinishRequest(GraphSyncRequestID) bool
      }
      object "Package Public Functions" as goLinkTrackerPF {
        New() *LinkTracker
      }
    }

136
  package requestmanager {
137 138 139 140 141 142
    package types {
      interface ResponseProgress {
      }
      interface AsyncLoadResult {
      }
    }
143

144 145 146 147 148 149
    package "loader" as reqLoader {
      interface AsyncLoadFn {
      }
      object "Package Public Functions" as goRequestLoaderPF {
        WrapAsyncLoader(context.Context, AsyncLoadFn, GraphSyncRequestID, chan error)
      }
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
    package asyncloader {
      package loadattempqueue {
        interface LoadRequest {

        }
        interface LoadAttempter {
          func(GraphSyncRequestID, ipld.Link) ([]byte, error)
        }

        class LoadAttemptQueue {
          AttemptLoad(LoadRequest, bool)
          ClearRequest(GraphSyncRequestID)
          RetryLoads()
        }
        object "Package Public Functions" as goLoadAttemptQueuePF {
          NewLoadRequest(GraphSyncRequestID, ipld.Link, chan AsyncLoadResult) LoadRequest
          New(LoadAttempter) *LoadAttemptQueue
        }
      }
      package unverifiedblockstore {
        class UnverifiedBlockStore {
          AddUnverifiedBlock(ipld.Link, []byte)
          PruneBlocks(func(ipld.Link) bool)
          VerifyBlock(ipld.Link) ([]byte, error)
        }
        object "Package Public Functions" as goUnverifiedBlockStore {
          New(Storer) *UnverifiedBlockStore
        }
      }
      package responsecache {
        class ResponseCache {
          FinishRequest(GraphSyncRequestID)
          AttemptLoad(GraphSyncRequestID, ipld.Link) ([]byte, error)
          ProcessResponse(map[GraphSyncRequestID]Metadata, []blocks.Block)       
        }
        object "Package Public Functions" as goResponseCachePF {
          New(UnverifiedBlockStore) *ResponseCache
        }
        ResponseCache *-- LinkTracker
        ResponseCache *-- UnverifiedBlockStore
        ResponseCache .. goLinkTrackerPF
      }

      class AsyncLoader {
        StartRequest(GraphSyncRequestID)
        ProcessResponse(map[gsmsg.GraphSyncRequestID]metadata.Metadata, []blocks.Block)
        AsyncLoad(requestID gsmsg.GraphSyncRequestID, link ipld.Link) AsyncLoadResult
        CompleteResponsesFor(GraphSyncRequestID)
        CleanupRequest(GraphSyncRequestID)
      }
      
      object "Package Public Functions" as goAsyncLoaderPF {
        New(context.Context, ipld.Loader, ipld.Storer) *AsyncLoader
      }
      AsyncLoader *-- LoadAttemptQueue
      AsyncLoader *-- ResponseCache
      AsyncLoader *-- Loader
      AsyncLoader *-- Storer
      AsyncLoader .. goUnverifiedBlockStore
      AsyncLoader .. goResponseCachePF
      AsyncLoader .. goLoadAttemptQueuePF
213
    }
214 215

    
216 217
    class RequestManager {
      SetDelegate(peerHandler PeerMessageManager)
218 219 220 221 222
      SendRequest(ctx context.Context, p peer.ID, cidRootedSelector Node) chan ResponseProgress, chan error
      ProcessResponses(peer.ID, []GraphSyncResponse, []blocks.Block)
    }
    object "Package Public Functions" as goRequestManagerPF {
      New(ctx context.Context, asyncLoader AsyncLoader, ipldBridge ipldbridge.IPLDBridge) *RequestManager
223
    }
224 225 226
    RequestManager *-- AsyncLoader
    RequestManager *-- PeerManager
    RequestManager .. goRequestLoaderPF
227
    GraphSync *-- RequestManager
228
    GraphSync .. goRequestManagerPF
229 230
  }

231
  
232
  package responsemanager {
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 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
    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     
    }

292
    package "loader" as resLoader {
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
      object "Package Public Functions" as goResponseLoaderPF {
        WrapLoader(Loader,GraphSyncRequestID, PeerResponseSender) Loader
      }
    }

    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 .. 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 *-- PeerResponseManager
    ResponseManager *-- PeerTaskQueue
    ResponseManager .. goResponseLoaderPF
    GraphSync .. goResponseManagerPF
350
  }
351

352 353
  package message {
    object "Package Public Functions" as goGraphSyncMessagePF {
354 355
      func FromPBReader(pbr ggio.Reader) (GraphSyncMessage, error)
      func FromNet(r io.Reader) (GraphSyncMessage, error)
356 357 358 359
      func New() GraphSyncMessage
      func NewRequest(GraphSyncRequestID, []byte, GraphSyncPriority) GraphSyncRequest
      func CancelRequest(GraphSyncRequestID) GraphSyncRequest
      func NewResponse(GraphSyncRequestID, GraphSyncResponseStatusCode, []byte) GraphSyncResponse
360 361 362
    }
    goGraphSyncMessagePF .. libP2PGraphSyncNetwork

363
    class GraphSyncRequest {
364
      Selector() []bytes
365 366 367
      Priority() Priority
      ID()       int
      IsCancel() bool
368 369
    }

370
    class GraphSyncResponse {
371 372
      RequestID() int
      Status() GraphSyncStatus
373
      Extra() []bytes
374 375 376 377 378
    }

    interface GraphSyncMessage {
      Requests() : []GraphSyncRequest
      Responses() : []GraphSyncResponse
379
      Blocks() : []Blocks
380 381 382
      AddRequest(GraphSyncRequest)
      AddResponse(GraphSyncResponse)
      AddBlock(Block)
383 384 385
    }

    interface Exportable {
386
      ToProto()
387
      ToNet(w io.Writer) error
388 389 390 391 392 393 394 395
	  }

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

396 397
  package ipldbridge {
    interface IPLDBridge {
398
      BuildNode(func(NodeBuilder) ipld.Node) (ipld.Node, error)
399
	    ValidateSelectorSpec(rootedSelector ipld.Node) []error
400 401 402
	    EncodeNode(ipld.Node) ([]byte, error)
	    DecodeNode([]byte) (ipld.Node, error)
	    DecodeSelectorSpec(cidRootedSelector ipld.Node) (ipld.Node, Selector, error)
403
	    Traverse(ctx context.Context, loader Loader, root ipld.Node, s Selector, fn AdvVisitFn) error
404 405 406 407 408
    }

    GraphSync *-- IPLDBridge
    RequestManager *-- IPLDBridge
    ResponseManager *-- IPLDBridge
409 410
    PeerResponseSender *-- IPLDBridge

411 412 413 414
    class ipldBridge {
    }

    object "PackagePublicFunctions" as goIPLDBridge {
415
      NewIPLDBridge() IPLDBridge
416 417 418 419 420 421 422 423 424 425
    }

    IPLDBridge <|-- ipldBridge
    goIPLDBridge .. ipldBridge 
    ipldBridge *-- MulticodecDecodeTable
    ipldBridge *-- NodeBuilderChooser
    ipldBridge .. TraversalProgress
    ipldBridge .. goSelectorPF
    ipldBridge .. goIPLDReposePf
  }
426
  object "PackagePublicFunctions" as goGraphsyncPf {
427
    New(ctx context.Context, network GraphSyncNetwork, ipldBridge IPLDBridge, loader Loader) GraphSync
428 429
    LoaderFromCid2BlockFn(cid2BlockFn Cid2BlockFn) Loader
    SelectorSpecFromCidAndPath(lnk cid.Cid, pathSegments []string) (ipld.Node, error) 
430 431 432 433 434 435 436 437 438 439
  }
}

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

  "go-filecoin" *-- GraphSync
  "go-filecoin" .. goGraphsyncPf
  "go-filecoin" .. goGraphSyncNetworkPF
440 441 442 443
  "go-filecoin" .. goIPLDBridge
  "go-filecoin" *-- RawLoader
  "go-filecoin" *-- MulticodecDecodeTable
  "go-filecoin" *-- NodeBuilderChooser
444

445 446
}

447
@enduml