contentprovider

package
v0.5.16 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2024 License: Apache-2.0, MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetMetadataHandler

func GetMetadataHandler(c echo.Context, db *gorm.DB) error

GetMetadataHandler is a function that handles HTTP requests to get the metadata of a piece. It takes an Echo context and a Gorm DBNoContext connection as arguments.

The function first parses the piece CID from the URL parameters. If the CID is invalid, it returns a 400 Bad Request response.

Then, it queries the database for the car associated with the CID. If no car is found, it returns a 404 Not Found response.

Next, it retrieves the metadata of the piece. If there's an error, it returns a 500 Internal Server Error response.

Finally, it removes any sensitive information from the metadata and returns it in the response. The format of the response depends on the "Accept" header of the request: if it's "application/cbor", the metadata is encoded as CBOR; otherwise, it's encoded as JSON.

Parameters:

  • c: The Echo context for the HTTP request.
  • dbNoContext: The Gorm DBNoContext connection to use for database queries.

Returns:

  • An error if there was a problem handling the request.

func SetCommonHeaders added in v0.5.1

func SetCommonHeaders(c echo.Context, pieceCid string)

Types

type BitswapConfig added in v0.3.0

type BitswapConfig struct {
	Enable           bool
	IdentityKey      string
	ListenMultiAddrs []string
}

type BitswapServer added in v0.3.0

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

BitswapServer represents a server instance for handling Bitswap protocol interactions. Bitswap is a peer-to-peer data trading protocol in which peers request the data they need, and respond to other peers' requests based on certain policies.

func NewBitswapServer added in v0.5.0

func NewBitswapServer(dbNoContext *gorm.DB, private crypto.PrivKey, addrs ...multiaddr.Multiaddr) (*BitswapServer, error)

func (BitswapServer) Name added in v0.3.0

func (BitswapServer) Name() string

func (BitswapServer) Start added in v0.3.0

func (s BitswapServer) Start(ctx context.Context, exitErr chan<- error) error

Start initializes the Bitswap server with the provided context. It sets up the necessary routing and networking components, and starts serving Bitswap requests. It returns channels that signal when the service has stopped or encountered an error.

type Config added in v0.3.0

type Config struct {
	HTTP    HTTPConfig
	Bitswap BitswapConfig
}

type HTTPConfig added in v0.3.0

type HTTPConfig struct {
	EnablePiece         bool
	EnablePieceMetadata bool
	Bind                string
}

type HTTPServer added in v0.3.0

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

func (*HTTPServer) Name added in v0.3.0

func (*HTTPServer) Name() string

func (*HTTPServer) Start added in v0.3.0

func (s *HTTPServer) Start(ctx context.Context, exitErr chan<- error) error

Start is a method on the HTTPServer struct that starts the HTTP server.

It sets up the Echo framework with various middleware for gzip compression, request logging, and panic recovery. It also sets up routes for getting piece metadata and the piece itself.

The server runs in its own goroutine until the provided context is cancelled. When the context is cancelled, the server is shut down gracefully.

The method returns two channels: a Done channel that is closed when the server has stopped, and a Fail channel that receives an error if the server fails to start or stop.

Parameters:

  • ctx: The context for the server. This can be used to cancel the server or set a deadline.

Returns:

  • A Done channel slice that are closed when the server has stopped.
  • A Fail channel that receives an error if the server fails to start or stop.
  • An error if the server fails to start.

type PieceMetadata

type PieceMetadata struct {
	Car       model.Car        `cbor:"1,keyasint,omitempty" json:"car"`
	Storage   model.Storage    `cbor:"2,keyasint,omitempty" json:"storage"`
	CarBlocks []model.CarBlock `cbor:"3,keyasint,omitempty" json:"carBlocks"`
	Files     []model.File     `cbor:"4,keyasint,omitempty" json:"files"`
}

type Service added in v0.3.0

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

func NewService added in v0.3.0

func NewService(db *gorm.DB, config Config) (*Service, error)

NewService creates a new Service instance with the provided database and configuration.

The NewService function takes the following parameters:

  • db: The gorm.DB instance for database operations.
  • config: The Config struct containing the service configuration.

The function performs the following steps:

  1. Creates an empty Service instance.

  2. If the HTTP server is enabled in the configuration, creates an HTTPServer instance and adds it to the servers slice. - The HTTPServer is configured with the bind address, database without context, and a DefaultHandlerResolver.

  3. If the Bitswap server is enabled in the configuration, initializes the identity key based on the configuration. - If the identity key is not provided, generates a new peer identity key. - If the identity key is provided, decodes it from base64. - Unmarshals the private key from the identity key bytes. - If no listen multiaddresses are provided, sets a default listen multiaddress. - Converts each listen multiaddress string to a Multiaddr instance. - Initializes a libp2p host with the identity key and listen multiaddresses. - Logs the libp2p listening addresses and peer ID. - Creates a BitswapServer instance with the libp2p host and database without context, and adds it to the servers slice.

4. Returns the created Service instance and nil for the error if all steps are executed successfully.

func (*Service) Start added in v0.3.0

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

Jump to

Keyboard shortcuts

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