bitswap

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2018 License: MIT Imports: 33 Imported by: 0

README

go-bitswap

Coverage Status Travis CI

An implementation of the bitswap protocol in go!

Table of Contents

Install

TODO

Contribute

PRs are welcome!

Small note: If editing the Readme, please conform to the standard-readme specification.

License

MIT © Juan Batiz-Benet

Documentation

Overview

package bitswap implements the IPFS exchange interface with the BitSwap bilateral exchange protocol.

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyHaveBlock = errors.New("already have block")
View Source
var (
	HasBlockBufferSize = 256
)
View Source
var TaskWorkerCount = 8

Functions

func New

New initializes a BitSwap instance that communicates over the provided BitSwapNetwork. This function registers the returned instance as the network delegate. Runs until context is cancelled.

Types

type Bitswap

type Bitswap struct {
	// contains filtered or unexported fields
}

Bitswap instances implement the bitswap protocol.

func (*Bitswap) CancelWants

func (bs *Bitswap) CancelWants(cids []*cid.Cid, ses uint64)

CancelWant removes a given key from the wantlist

func (*Bitswap) Close

func (bs *Bitswap) Close() error

func (*Bitswap) GetBlock

func (bs *Bitswap) GetBlock(parent context.Context, k *cid.Cid) (blocks.Block, error)

GetBlock attempts to retrieve a particular block from peers within the deadline enforced by the context.

func (*Bitswap) GetBlocks

func (bs *Bitswap) GetBlocks(ctx context.Context, keys []*cid.Cid) (<-chan blocks.Block, error)

GetBlocks returns a channel where the caller may receive blocks that correspond to the provided |keys|. Returns an error if BitSwap is unable to begin this request within the deadline enforced by the context.

NB: Your request remains open until the context expires. To conserve resources, provide a context with a reasonably short deadline (ie. not one that lasts throughout the lifetime of the server)

func (*Bitswap) GetWantlist

func (bs *Bitswap) GetWantlist() []*cid.Cid

func (*Bitswap) HasBlock

func (bs *Bitswap) HasBlock(blk blocks.Block) error

HasBlock announces the existence of a block to this bitswap service. The service will potentially notify its peers.

func (*Bitswap) IsOnline

func (bs *Bitswap) IsOnline() bool

func (*Bitswap) LedgerForPeer

func (bs *Bitswap) LedgerForPeer(p peer.ID) *decision.Receipt

func (*Bitswap) NewSession

func (bs *Bitswap) NewSession(ctx context.Context) *Session

NewSession creates a new bitswap session whose lifetime is bounded by the given context

func (*Bitswap) PeerConnected

func (bs *Bitswap) PeerConnected(p peer.ID)

Connected/Disconnected warns bitswap about peer connections

func (*Bitswap) PeerDisconnected

func (bs *Bitswap) PeerDisconnected(p peer.ID)

Connected/Disconnected warns bitswap about peer connections

func (*Bitswap) ReceiveError

func (bs *Bitswap) ReceiveError(err error)

func (*Bitswap) ReceiveMessage

func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg.BitSwapMessage)

func (*Bitswap) SessionsForBlock

func (bs *Bitswap) SessionsForBlock(c *cid.Cid) []*Session

SessionsForBlock returns a slice of all sessions that may be interested in the given cid

func (*Bitswap) Stat

func (bs *Bitswap) Stat() (*Stat, error)

func (*Bitswap) WantlistForPeer

func (bs *Bitswap) WantlistForPeer(p peer.ID) []*cid.Cid

type Instance

type Instance struct {
	Peer     peer.ID
	Exchange *Bitswap
	// contains filtered or unexported fields
}

func MkSession

func MkSession(ctx context.Context, net tn.Network, p testutil.Identity) Instance

session creates a test bitswap session.

NB: It's easy make mistakes by providing the same peer ID to two different sessions. To safeguard, use the SessionGenerator to generate sessions. It's just a much better idea.

func (*Instance) Blockstore

func (i *Instance) Blockstore() blockstore.Blockstore

func (*Instance) SetBlockstoreLatency

func (i *Instance) SetBlockstoreLatency(t time.Duration) time.Duration

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session holds state for an individual bitswap transfer operation. This allows bitswap to make smarter decisions about who to send wantlist info to, and who to request blocks from

func (*Session) GetBlock

func (s *Session) GetBlock(parent context.Context, k *cid.Cid) (blocks.Block, error)

GetBlock fetches a single block

func (*Session) GetBlocks

func (s *Session) GetBlocks(ctx context.Context, keys []*cid.Cid) (<-chan blocks.Block, error)

GetBlocks fetches a set of blocks within the context of this session and returns a channel that found blocks will be returned on. No order is guaranteed on the returned blocks.

type SessionGenerator

type SessionGenerator struct {
	// contains filtered or unexported fields
}

TODO move this SessionGenerator to the core package and export it as the core generator

func NewTestSessionGenerator

func NewTestSessionGenerator(
	net tn.Network) SessionGenerator

WARNING: this uses RandTestBogusIdentity DO NOT USE for NON TESTS!

func (*SessionGenerator) Close

func (g *SessionGenerator) Close() error

func (*SessionGenerator) Instances

func (g *SessionGenerator) Instances(n int) []Instance

func (*SessionGenerator) Next

func (g *SessionGenerator) Next() Instance

type Stat

type Stat struct {
	ProvideBufLen   int
	Wantlist        []*cid.Cid
	Peers           []string
	BlocksReceived  uint64
	DataReceived    uint64
	BlocksSent      uint64
	DataSent        uint64
	DupBlksReceived uint64
	DupDataReceived uint64
}

type WantManager

type WantManager struct {
	// contains filtered or unexported fields
}

func NewWantManager

func NewWantManager(ctx context.Context, network bsnet.BitSwapNetwork) *WantManager

func (*WantManager) CancelWants

func (pm *WantManager) CancelWants(ctx context.Context, ks []*cid.Cid, peers []peer.ID, ses uint64)

CancelWants removes the given cids from the wantlist, tracked by the given session

func (*WantManager) Connected

func (pm *WantManager) Connected(p peer.ID)

func (*WantManager) ConnectedPeers

func (pm *WantManager) ConnectedPeers() []peer.ID

func (*WantManager) Disconnected

func (pm *WantManager) Disconnected(p peer.ID)

func (*WantManager) Run

func (pm *WantManager) Run()

TODO: use goprocess here once i trust it

func (*WantManager) SendBlock

func (pm *WantManager) SendBlock(ctx context.Context, env *engine.Envelope)

func (*WantManager) WantBlocks

func (pm *WantManager) WantBlocks(ctx context.Context, ks []*cid.Cid, peers []peer.ID, ses uint64)

WantBlocks adds the given cids to the wantlist, tracked by the given session

Directories

Path Synopsis
package decision implements the decision engine for the bitswap service.
package decision implements the decision engine for the bitswap service.
pb
Package bitswap_message_pb is a generated protocol buffer package.
Package bitswap_message_pb is a generated protocol buffer package.
package wantlist implements an object for bitswap that contains the keys that a given peer wants.
package wantlist implements an object for bitswap that contains the keys that a given peer wants.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL