ipfsproxy

package
v0.0.0-...-8c384fb Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2023 License: Apache-2.0, MIT, Apache-2.0, + 1 more Imports: 35 Imported by: 0

Documentation

Overview

Package ipfsproxy implements the Cluster API interface by providing an IPFS HTTP interface as exposed by the go-ipfs daemon.

In this API, select endpoints like pin*, add*, and repo* endpoints are used to instead perform cluster operations. Requests for any other endpoints are passed to the underlying IPFS daemon.

Index

Constants

View Source
const (
	DefaultNodeAddr           = "/ip4/127.0.0.1/tcp/5001"
	DefaultNodeHTTPS          = false
	DefaultReadTimeout        = 0
	DefaultReadHeaderTimeout  = 5 * time.Second
	DefaultWriteTimeout       = 0
	DefaultIdleTimeout        = 60 * time.Second
	DefaultExtractHeadersPath = "/api/v0/version"
	DefaultExtractHeadersTTL  = 5 * time.Minute
	DefaultMaxHeaderBytes     = minMaxHeaderBytes
)

Default values for Config.

Variables

View Source
var DNSTimeout = 5 * time.Second

DNSTimeout is used when resolving DNS multiaddresses in this module

View Source
var DefaultListenAddrs = []string{
	"/ip4/127.0.0.1/tcp/9095",
}

DefaultListenAddrs contains the default listeners for the proxy.

Functions

This section is empty.

Types

type Config

type Config struct {
	config.Saver

	// Listen parameters for the IPFS Proxy.
	ListenAddr []ma.Multiaddr

	// Host/Port for the IPFS daemon.
	NodeAddr ma.Multiaddr

	// Should we talk to the IPFS API over HTTPS? (experimental, untested)
	NodeHTTPS bool

	// LogFile is path of the file that would save Proxy API logs. If this
	// path is empty, logs would be sent to standard output. This path
	// should either be absolute or relative to cluster base directory. Its
	// default value is empty.
	LogFile string

	// Maximum duration before timing out reading a full request
	ReadTimeout time.Duration

	// Maximum duration before timing out reading the headers of a request
	ReadHeaderTimeout time.Duration

	// Maximum duration before timing out write of the response
	WriteTimeout time.Duration

	// Maximum cumulative size of HTTP request headers in bytes
	// accepted by the server
	MaxHeaderBytes int

	// Server-side amount of time a Keep-Alive connection will be
	// kept idle before being reused
	IdleTimeout time.Duration

	// A list of custom headers that should be extracted from
	// IPFS daemon responses and re-used in responses from hijacked paths.
	// This is only useful if the user has configured custom headers
	// in the IPFS daemon. CORS-related headers are already
	// taken care of by the proxy.
	ExtractHeadersExtra []string

	// If the user wants to extract some extra custom headers configured
	// on the IPFS daemon so that they are used in hijacked responses,
	// this request path will be used. Defaults to /version. This will
	// trigger a single request to extract those headers and remember them
	// for future requests (until TTL expires).
	ExtractHeadersPath string

	// Establishes how long we should remember extracted headers before we
	// refresh them with a new request. 0 means always.
	ExtractHeadersTTL time.Duration

	// Tracing flag used to skip tracing specific paths when not enabled.
	Tracing bool
}

Config allows to customize behavior of IPFSProxy. It implements the config.ComponentConfig interface.

func (*Config) ApplyEnvVars

func (cfg *Config) ApplyEnvVars() error

ApplyEnvVars fills in any Config fields found as environment variables.

func (*Config) ConfigKey

func (cfg *Config) ConfigKey() string

ConfigKey provides a human-friendly identifier for this type of Config.

func (*Config) Default

func (cfg *Config) Default() error

Default sets the fields of this Config to sensible default values.

func (*Config) LoadJSON

func (cfg *Config) LoadJSON(raw []byte) error

LoadJSON parses a JSON representation of this Config as generated by ToJSON.

func (*Config) ToDisplayJSON

func (cfg *Config) ToDisplayJSON() ([]byte, error)

ToDisplayJSON returns JSON config as a string.

func (*Config) ToJSON

func (cfg *Config) ToJSON() (raw []byte, err error)

ToJSON generates a human-friendly JSON representation of this Config.

func (*Config) Validate

func (cfg *Config) Validate() error

Validate checks that the fields of this Config have sensible values, at least in appearance.

type Server

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

Server offers an IPFS API, hijacking some interesting requests and forwarding the rest to the ipfs daemon it proxies HTTP requests to the configured IPFS daemon. It is able to intercept these requests though, and perform extra operations on them.

func New

func New(cfg *Config) (*Server, error)

New returns and ipfs Proxy component

func (*Server) SetClient

func (proxy *Server) SetClient(c *rpc.Client)

SetClient makes the component ready to perform RPC requests.

func (*Server) Shutdown

func (proxy *Server) Shutdown(ctx context.Context) error

Shutdown stops any listeners and stops the component from taking any requests.

Jump to

Keyboard shortcuts

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