httptransport

package
v1.7.5 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2023 License: Apache-2.0, MIT Imports: 32 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTokenNotFound = errors.New("auth token not found")

ErrTokenNotFound is returned when an auth token is not found in the database

View Source
var ErrTransferNotFound = errors.New("transfer not found")

Functions

func BasicAuth

func BasicAuth(username, password string) string

Copied from https://github.com/golang/go/blob/16d6a5233a183be7264295c66167d35c689f9372/src/net/http/client.go#L413-L421

See 2 (end of page 4) https://www.ietf.org/rfc/rfc2617.txt "To receive authorization, the client sends the userid and password, separated by a single colon (":") character, within a base64 encoded string in the credentials." It is not meant to be urlencoded.

func BasicAuthHeader

func BasicAuthHeader(username, password string) string

func GenerateAuthToken

func GenerateAuthToken() (string, error)

func New

func New(host host.Host, dealLogger *logs.DealLogger, opts ...Option) *httpTransport

Types

type AuthTokenDB

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

AuthTokenDB keeps a database of auth tokens with associated data

func NewAuthTokenDB

func NewAuthTokenDB(ds datastore.Batching) *AuthTokenDB

func (*AuthTokenDB) Delete

func (db *AuthTokenDB) Delete(ctx context.Context, authToken string) error

Delete auth token from the datastore

func (*AuthTokenDB) DeleteExpired

func (db *AuthTokenDB) DeleteExpired(ctx context.Context, before time.Time) ([]AuthValue, error)

Delete expired auth tokens and return the values for expired tokens

func (*AuthTokenDB) Get

func (db *AuthTokenDB) Get(ctx context.Context, authToken string) (*AuthValue, error)

Get data by auth token

func (*AuthTokenDB) Put

func (db *AuthTokenDB) Put(ctx context.Context, authToken string, val AuthValue) error

Put adds the auth values to the DB by auth token

type AuthValue

type AuthValue struct {
	ID          string
	ProposalCid cid.Cid
	PayloadCid  cid.Cid
	Size        uint64
}

AuthValue is the data associated with an auth token in the auth token DB

type EventListenerFn

type EventListenerFn func(id string, st types.TransferState)

type Libp2pCarServer

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

Libp2pCarServer serves deal data by matching an auth token to the root CID of a DAG in a blockstore, and serving the data as a CAR

func NewLibp2pCarServer

func NewLibp2pCarServer(h host.Host, auth *AuthTokenDB, bstore blockstore.Blockstore, cfg ServerConfig) *Libp2pCarServer

func (Libp2pCarServer) CancelTransfer

func (m Libp2pCarServer) CancelTransfer(ctx context.Context, id string) (*types.TransferState, error)

CancelTransfer cancels the transfer with the given id (closing its read / write pipe), and waits for the error or completed event to be fired before returning. It returns the state that the transfer is in after being canceled (either completed or errored out).

func (Libp2pCarServer) Get

func (m Libp2pCarServer) Get(id string) (*Libp2pTransfer, error)

Get gets a transfer by id. Returns ErrTransferNotFound if there is no active transfer with that id.

func (*Libp2pCarServer) ID

func (s *Libp2pCarServer) ID() peer.ID

func (Libp2pCarServer) Matching

func (m Libp2pCarServer) Matching(match MatchFn) ([]*Libp2pTransfer, error)

Matching returns all transfers selected by the match function

func (*Libp2pCarServer) Start

func (s *Libp2pCarServer) Start(ctx context.Context) error

func (*Libp2pCarServer) Stop

func (s *Libp2pCarServer) Stop(ctx context.Context) error

func (Libp2pCarServer) Subscribe

func (m Libp2pCarServer) Subscribe(cb EventListenerFn) UnsubFn

type Libp2pTransfer

type Libp2pTransfer struct {
	ID          string
	PayloadCid  cid.Cid
	ProposalCid cid.Cid
	CreatedAt   time.Time
	AuthToken   string
	LocalAddr   string
	RemoteAddr  string
	// contains filtered or unexported fields
}

Libp2pTransfer keeps track of a data transfer

func (*Libp2pTransfer) State

func (t *Libp2pTransfer) State() types.TransferState

type MatchFn

type MatchFn func(xfer *Libp2pTransfer) (bool, error)

type Option

type Option func(*httpTransport)

func BackOffRetryOpt

func BackOffRetryOpt(minBackoff, maxBackoff time.Duration, factor, maxReconnectAttempts float64) Option

type ServerConfig

type ServerConfig struct {
	BlockInfoCacheManager car.BlockInfoCacheManager
	ThrottleLimit         uint
}

type UnsubFn

type UnsubFn func()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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