bitswap

package module
v0.0.0-...-9232f08 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2023 License: Apache-2.0, MIT Imports: 15 Imported by: 4

README

Selfish Bitswap Client

A minimal retrieve-only bitswap client

This client implements a minimal bitswap session that allows retrieval of CIDs from a single known peer.

Documentation

Usage
import (
	bitswap "github.com/willscott/go-selfish-bitswap-client"
)


session := bitswap.New(libp2p.Host, peer.ID)
defer session.Close()
bytes, err := session.Get(cid.Cid)

Lead Maintainer

willscott

Contributing

Contributions are welcome! This repository is governed by the ipfs contributing guidelines.

License

SPDX-License-Identifier: Apache-2.0 OR MIT

Documentation

Index

Constants

View Source
const (
	// maximum block we'll read is 4mb
	MaxBlockSize = 1024 * 1024 * 4
)

Variables

View Source
var (
	// ProtocolBitswapNoVers is a legacy bitswap protocol id
	ProtocolBitswapNoVers protocol.ID = "/ipfs/bitswap"
	// ProtocolBitswapOneZero is the prefix for the legacy bitswap protocol
	ProtocolBitswapOneZero protocol.ID = "/ipfs/bitswap/1.0.0"
	// ProtocolBitswapOneOne is the the prefix for version 1.1.0
	ProtocolBitswapOneOne protocol.ID = "/ipfs/bitswap/1.1.0"
	// ProtocolBitswap is the current version of the bitswap protocol: 1.2.0
	ProtocolBitswap protocol.ID = "/ipfs/bitswap/1.2.0"
)

Functions

This section is empty.

Types

type Bitswap

type Bitswap interface {
	Get(ctx context.Context, c cid.Cid) ([]byte, error)
	Close() error
}

type Options

type Options struct {
	SessionTimeout          time.Duration
	WriteAggregationQuantum time.Duration
}

type Session

type Session struct {
	host.Host
	// contains filtered or unexported fields
}

Session holds state for a related set of CID requests from a single remote peer

func New

func New(h host.Host, peer peer.ID, opts Options) *Session

New initiates a bitswap retrieval session

func (*Session) Close

func (s *Session) Close() error

Close stops the session.

func (*Session) Get

func (s *Session) Get(ctx context.Context, c cid.Cid) ([]byte, error)

Get a specific block of data in this session. ctx is used to wrap client in timeout logic across a session.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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