interface.go 916 Bytes
Newer Older
1
// Package exchange defines the DMS3 exchange interface
Brian Tiger Chow's avatar
Brian Tiger Chow committed
2
package exchange
3 4

import (
5
	"context"
6 7
	"io"

8 9
	blocks "gitlab.dms3.io/dms3/go-block-format"
	cid "gitlab.dms3.io/dms3/go-cid"
10 11
)

12
// Interface defines the functionality of the DMS3 block exchange protocol.
13
type Interface interface { // type Exchanger interface
14
	Fetcher
Jeromy's avatar
Jeromy committed
15

16 17
	// TODO Should callers be concerned with whether the block was made
	// available on the network?
18
	HasBlock(blocks.Block) error
19

20 21
	IsOnline() bool

22
	io.Closer
23
}
24

Jeromy's avatar
Jeromy committed
25
// Fetcher is an object that can be used to retrieve blocks
26 27
type Fetcher interface {
	// GetBlock returns the block associated with a given key.
28 29
	GetBlock(context.Context, cid.Cid) (blocks.Block, error)
	GetBlocks(context.Context, []cid.Cid) (<-chan blocks.Block, error)
30
}
31 32 33 34 35

// SessionExchange is an exchange.Interface which supports
// sessions.
type SessionExchange interface {
	Interface
Jeromy's avatar
Jeromy committed
36
	NewSession(context.Context) Fetcher
37
}