Documentation
¶
Index ¶
- Variables
- type CallbackContentResolver
- type ContentResolver
- type DoubleCacheContentResolver
- type DoubleCacheContentResolverOptions
- type InMemTable
- func (table *InMemTable) AddExpiry(peerID id.Signatory, duration time.Duration)
- func (table *InMemTable) AddPeer(peerID id.Signatory, peerAddr wire.Address)
- func (table *InMemTable) AddSubnet(signatories []id.Signatory) id.Hash
- func (table *InMemTable) DeleteExpiry(peerID id.Signatory)
- func (table *InMemTable) DeletePeer(peerID id.Signatory)
- func (table *InMemTable) DeleteSubnet(hash id.Hash)
- func (table *InMemTable) HandleExpired(peerID id.Signatory) bool
- func (table *InMemTable) NumPeers() int
- func (table *InMemTable) PeerAddress(peerID id.Signatory) (wire.Address, bool)
- func (table *InMemTable) Peers(n int) []id.Signatory
- func (table *InMemTable) RandomPeers(n int) []id.Signatory
- func (table *InMemTable) Subnet(hash id.Hash) []id.Signatory
- type Table
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultDoubleCacheContentResolverCapacity defines the default in-memory // cache capacity (in bytes) for the double-cache content resolver. DefaultDoubleCacheContentResolverCapacity = 16 * 1024 * 1024 // 16 MB )
Functions ¶
This section is empty.
Types ¶
type CallbackContentResolver ¶ added in v0.5.3
type CallbackContentResolver struct {
InsertContentCallback func([]byte, []byte)
QueryContentCallback func([]byte) ([]byte, bool)
}
CallbackContentResolver implements the ContentResolve interface by delegating all logic to callback functions. This is useful when defining an implementation inline.
func (CallbackContentResolver) InsertContent ¶ added in v0.5.3
func (r CallbackContentResolver) InsertContent(id, content []byte)
InsertContent will delegate the implementation to the InsertContentCallback. If the callback is nil, then this method will do nothing.
func (CallbackContentResolver) QueryContent ¶ added in v0.5.3
func (r CallbackContentResolver) QueryContent(id []byte) ([]byte, bool)
QueryContent will delegate the implementation to the QueryContentCallback. If the callback is nil, then this method will return false.
type ContentResolver ¶ added in v0.5.3
type ContentResolver interface {
// Insert content with a specific content ID. Usually, the content ID will
// stores information about the type and the hash of the content.
InsertContent(contentID, content []byte)
// QueryContent returns the content associated with a content ID. If there
// is no associated content, it returns false. Otherwise, it returns true.
QueryContent(contentID []byte) (content []byte, contentOk bool)
}
The ContentResolver interface is used to insert and query content.
type DoubleCacheContentResolver ¶ added in v0.5.3
type DoubleCacheContentResolver struct {
// contains filtered or unexported fields
}
The DoubleCacheContentResolver uses the double-cache technique to implement a fast in-memory cache. The cache can optionally wrap around another content-resolver (which can be responsible for more persistent content resolution).
func NewDoubleCacheContentResolver ¶ added in v0.5.3
func NewDoubleCacheContentResolver(opts DoubleCacheContentResolverOptions, next ContentResolver) *DoubleCacheContentResolver
NewDoubleCacheContentResolver returns a new double-cache content resolver that is wrapped around another content-resolver.
func (*DoubleCacheContentResolver) InsertContent ¶ added in v0.5.3
func (r *DoubleCacheContentResolver) InsertContent(id, content []byte)
InsertContent into the double-cache content resolver. If the front cache is full, it will be rotated to the back, the current back cache will be dropped, and a new front cache will be created. This method will also insert the content to the next content resovler (if one exists).
func (*DoubleCacheContentResolver) QueryContent ¶ added in v0.5.3
func (r *DoubleCacheContentResolver) QueryContent(id []byte) ([]byte, bool)
QueryContent returns the content associated with the given content ID. If the content is not found in the double-cache content resolver, the next content resolver will be checked (if one exists).
type DoubleCacheContentResolverOptions ¶ added in v0.5.3
type DoubleCacheContentResolverOptions struct {
Capacity int
}
DoubleCacheContentResolverOptions for parameterising the behaviour of the DoubleCacheContentResolver.
func DefaultDoubleCacheContentResolverOptions ¶ added in v0.5.3
func DefaultDoubleCacheContentResolverOptions() DoubleCacheContentResolverOptions
DefaultDoubleCacheContentResolverOptions returns the default DoubleCacheContentResolverOptions.
func (DoubleCacheContentResolverOptions) WithCapacity ¶ added in v0.5.3
func (opts DoubleCacheContentResolverOptions) WithCapacity(capacity int) DoubleCacheContentResolverOptions
WithCapacity sets the maximum in-memory cache capacity (in bytes). This capacity accounts for the fact that the double-cache content resolver has two in-memory buffers. For example, if the capacity is set to 2 MB, then the double-cache content resolver is guaranteeed to consume, at most, 2 MB of memory, but will only be able to cache 1 MB of data.
type InMemTable ¶ added in v0.5.3
type InMemTable struct {
// contains filtered or unexported fields
}
InMemTable implements the Table using in-memory storage.
func NewInMemTable ¶ added in v0.5.3
func NewInMemTable(self id.Signatory) *InMemTable
func (*InMemTable) AddExpiry ¶ added in v0.5.3
func (table *InMemTable) AddExpiry(peerID id.Signatory, duration time.Duration)
func (*InMemTable) AddPeer ¶ added in v0.5.3
func (table *InMemTable) AddPeer(peerID id.Signatory, peerAddr wire.Address)
func (*InMemTable) AddSubnet ¶ added in v0.5.3
func (table *InMemTable) AddSubnet(signatories []id.Signatory) id.Hash
func (*InMemTable) DeleteExpiry ¶ added in v0.5.3
func (table *InMemTable) DeleteExpiry(peerID id.Signatory)
func (*InMemTable) DeletePeer ¶ added in v0.5.3
func (table *InMemTable) DeletePeer(peerID id.Signatory)
func (*InMemTable) DeleteSubnet ¶ added in v0.5.3
func (table *InMemTable) DeleteSubnet(hash id.Hash)
func (*InMemTable) HandleExpired ¶ added in v0.5.3
func (table *InMemTable) HandleExpired(peerID id.Signatory) bool
func (*InMemTable) NumPeers ¶ added in v0.5.3
func (table *InMemTable) NumPeers() int
func (*InMemTable) PeerAddress ¶ added in v0.5.3
func (*InMemTable) Peers ¶ added in v0.5.3
func (table *InMemTable) Peers(n int) []id.Signatory
Peers returns the n closest peer IDs.
func (*InMemTable) RandomPeers ¶ added in v0.5.3
func (table *InMemTable) RandomPeers(n int) []id.Signatory
RandomPeers returns n random peer IDs
type Table ¶ added in v0.5.3
type Table interface {
// AddPeer to the table with an associate network address.
AddPeer(id.Signatory, wire.Address)
// DeletePeer from the table.
DeletePeer(id.Signatory)
// PeerAddress returns the network address associated with the given peer.
PeerAddress(id.Signatory) (wire.Address, bool)
// Peers returns the n closest peers to the local peer, using XORing as the
// measure of distance between two peers.
Peers(int) []id.Signatory
// RandomPeers returns n random peer IDs, using either partial permutation
// or Floyd's sampling algorithm.
RandomPeers(int) []id.Signatory
// NumPeers returns the total number of peers with associated network
// addresses in the table.
NumPeers() int
// HandleExpired returns whether a signatory has expired. It checks whether
// an Expiry exists for the signatory, and if it does, has it expired?
// If found expired, it deletes the peer from the table
HandleExpired(id.Signatory) bool
// AddExpiry to the table with given duration if no existing expiry is found
AddExpiry(id.Signatory, time.Duration)
// DeleteExpiry from the table
DeleteExpiry(id.Signatory)
// AddSubnet to the table. This returns a subnet hash that can be used to
// read/delete the subnet. It is the merkle root hash of the peers in the
// subnet.
AddSubnet([]id.Signatory) id.Hash
// DeleteSubnet from the table. If the subnet was in the table, then the
// peers are returned.
DeleteSubnet(id.Hash)
// Subnet returns the peers from the table.
Subnet(id.Hash) []id.Signatory
}
A Table is responsible for keeping tack of peers, their network addresses, and the subnet to which they belong.