Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetMetadataHandler ¶
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 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 (BitswapServer) Name ¶ added in v0.3.0
func (BitswapServer) Name() string
type Config ¶ added in v0.3.0
type Config struct { HTTP HTTPConfig Bitswap BitswapConfig }
type HTTPConfig ¶ added in v0.3.0
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
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 Service ¶ added in v0.3.0
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶ added in v0.3.0
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:
Creates an empty Service instance.
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.
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.