schema

package
v0.0.0-...-403c8b4 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 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
}

func UnwrapAdvertisement

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

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

Sign signs an advertisement using the given private key.

func (Advertisement) ToNode

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

func (a Advertisement) Validate() error

func (*Advertisement) VerifySignature

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.

type EntryChunk

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

func UnwrapEntryChunk

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

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.

Jump to

Keyboard shortcuts

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