schema

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: Apache-2.0, MIT Imports: 16 Imported by: 0

Documentation

Overview

Package schema defines the makeup of an advertisement. An advertisement is used to inform an indexer that there are updates to a provider's content. The IsRm and Entries fields determine how the indexer handles the advertisement. The following table describes this:

IsRm    Entries    Action

------+-----------+------------------------------------ false | NoEntries | Update metadata false | data | Update metadata and index entries true | NoEntries | Delete content with context ID true | data | Delete specific multihash indexes *

* Deleting entries still requires a context ID, because a multihash can map to multiple contextID/metadata values.

When removing content (IsRm true) the metadata is ignored.

All advertisements update the provider's addresses. To create an advertisement that only updates a provider's address, create an advertisement to remove content using a context ID that is not used.

Index

Constants

View Source
const (
	// MaxContextIDLen specifies the maximum number of bytes accepted as Advertisement.ContextID.
	MaxContextIDLen = 64
	// MaxMetadataLen specifies the maximum number of bytes an advertisement metadata can contain.
	MaxMetadataLen = 1024 // 1KiB
)

Variables

View Source
var (
	// NoEntries is a special value used to explicitly indicate that an
	// advertisement does not have any entries. When isRm is true it and serves to
	// remove content by context ID, and when isRm is false it serves to update
	// metadata only.
	NoEntries cidlink.Link

	// Linkproto is the ipld.LinkProtocol used for the ingestion protocol.
	// Refer to it if you have encoding questions.
	Linkproto = cidlink.LinkPrototype{
		Prefix: cid.Prefix{
			Version:  1,
			Codec:    uint64(multicodec.DagJson),
			MhType:   uint64(multicodec.Sha2_256),
			MhLength: -1,
		},
	}

	// AdvertisementPrototype represents the IPLD node prototype of Advertisement.
	//
	// See: bindnode.Prototype.
	AdvertisementPrototype schema.TypedPrototype

	// EntryChunkPrototype represents the IPLD node prototype of EntryChunk.
	//
	// See: bindnode.Prototype.
	EntryChunkPrototype schema.TypedPrototype
)

Functions

This section is empty.

Types

type Advertisement struct {
	PreviousID       ipld.Link
	Provider         string
	Addresses        []string
	Signature        []byte
	Entries          ipld.Link
	ContextID        []byte
	Metadata         []byte
	IsRm             bool
	ExtendedProvider *ExtendedProvider
}

func UnwrapAdvertisement added in v0.4.0

func UnwrapAdvertisement(node ipld.Node) (*Advertisement, error)

UnwrapAdvertisement unwraps the given node as an advertisement.

Note that the node is reassigned to AdvertisementPrototype if its prototype is different. Therefore, it is recommended to load the node using the correct prototype initially function to avoid unnecessary node assignment.

func (*Advertisement) Sign added in v0.4.0

func (ad *Advertisement) Sign(key crypto.PrivKey) error

Sign signs an advertisement using the given private key. This function will return an error if used to sign an ad with extended providers.

func (*Advertisement) SignWithExtendedProviders added in v0.5.0

func (ad *Advertisement) SignWithExtendedProviders(key crypto.PrivKey, extendedProviderKeyFetcher func(string) (crypto.PrivKey, error)) error

SignWithExtendedProviders signs an advertisement by the main provider as well as by all extended providers if they are present.

func (Advertisement) ToNode added in v0.4.0

func (a Advertisement) ToNode() (n ipld.Node, err error)

ToNode converts this advertisement to its representation as an IPLD typed node.

See: bindnode.Wrap.

func (Advertisement) Validate added in v0.4.0

func (a Advertisement) Validate() error

func (*Advertisement) VerifySignature added in v0.4.0

func (ad *Advertisement) VerifySignature() (peer.ID, error)

VerifySignature verifies that the advertisement has been signed and generated correctly. Returns the peer ID of the signer.

The signer may be different than the provider ID in the advertisement, so the caller will need to check if the signer is allowed to sign this advertisement.

Extended providers signatures are also verified.

type EntryChunk

type EntryChunk struct {
	Entries []multihash.Multihash
	Next    ipld.Link
}

func UnwrapEntryChunk added in v0.4.0

func UnwrapEntryChunk(node ipld.Node) (*EntryChunk, error)

UnwrapEntryChunk unwraps the given node as an entry chunk.

Note that the node is reassigned to EntryChunkPrototype if its prototype is different. Therefore, it is recommended to load the node using the correct prototype initially function to avoid unnecessary node assignment.

func (EntryChunk) ToNode added in v0.4.0

func (e EntryChunk) ToNode() (n ipld.Node, err error)

ToNode converts this entry chunk to its representation as an IPLD typed node.

See: bindnode.Wrap.

type ExtendedProvider added in v0.5.0

type ExtendedProvider struct {
	Providers []Provider
	Override  bool
}

type Provider added in v0.5.0

type Provider struct {
	ID        string
	Addresses []string
	Metadata  []byte
	Signature []byte
}

Jump to

Keyboard shortcuts

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