xedni

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: Apache-2.0, MIT Imports: 24 Imported by: 1

README

xedni

IPNI Reverse Index

Go

xedni is an IPNI index store wrapper designed to deterministically sample multihashes advertised by a provider using context ID.

Install

go get github.com/ipni/xedni@latest

Usage

Xedni wraps with any existing implementation of IPNI index backing store, Indexer.Interface, and exposes one additional interface that can sample multihashes from a provider using a context ID.

A random beacon may be optionally specified to deterministically sample the multihashes from the provider along with a maximum sample size.

In addition to the core sampling logic implementation, the package also provides a simple HTTP API to expose the sampling capability documented here.

The example below illustrates how Xedni can be used to wrap an existing indexer store implementation and expose the sampling API:

package main

import (
	"github.com/ipni/go-indexer-core"
	"github.com/ipni/go-indexer-core/engine"
	"github.com/ipni/xedni"
)

func main() {
	// The delegate indexer store backend may be any one of the stores currently supported by go-indexer-core.
	// See: https://github.com/ipni/go-indexer-core/tree/main/store
	var delegate indexer.Interface
	rx, err := xedni.New(
		xedni.WithStorePath(".store"), xedni.WithDelegateIndexer(delegate))
	if err != nil {
		//...
	}
	// Start the indexer engine as usual, _but_ with the warapped xedni store.
	eng := engine.New(rx.Store())
	// pass engine to storetheindex ingester or any other ingestion implementation...
	
	// Start Xedni to expose samling HTTP API.
	if err:= rx.Start(context.Background); err != nil {
	//...
	}
}

You can then use the HTTP API to sample multihashes from the provider using a context ID:

$ curl http://localhost:40080/ipni/v0/sample/<provider-id>/<context-id>?max=3&beacon=5865646e690a

Example response:

{
    "samples": [
        "QmNrkWz2DFy2MKKpK84B4MJQhLM8GptkttQFonBXrHBr68",
        "QmQt3QgrXrnEsJDDFWfwoXgp1CYusTdACGCd7mxnU1H9Zc",
        "QmbuvjR4kZroSvADmEMh3tqdw88eovBeACZUBR4djbdX39"
    ]
}

See options for further configurable fields.

License

SPDX-License-Identifier: Apache-2.0 OR MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Error string `json:"error"`
}

type Option

type Option func(*options) error

func WithDelegateIndexer

func WithDelegateIndexer(indexer indexer.Interface) Option

func WithHTTPServerListenAddr

func WithHTTPServerListenAddr(addr string) Option

func WithStorePath

func WithStorePath(path string) Option

type ParquetRecord

type ParquetRecord struct {
	Multihash multihash.Multihash
}

type Population

type Population struct {
	ProviderID      peer.ID
	ContextID       []byte
	Beacon          []byte
	MaxSamples      int
	FederationEpoch uint64
}

type SampleResponse

type SampleResponse struct {
	Samples []string `json:"samples"`
}

type Sampler

type Sampler interface {
	Sample(context.Context, Population) ([]multihash.Multihash, error)
}

type Store

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

func NewStore

func NewStore(home string, delegate indexer.Interface) (*Store, error)

func (*Store) Close

func (s *Store) Close() error

func (*Store) Flush

func (s *Store) Flush() error

func (*Store) Get

func (s *Store) Get(multihash multihash.Multihash) ([]indexer.Value, bool, error)

func (*Store) Put

func (s *Store) Put(value indexer.Value, mhs ...multihash.Multihash) error

func (*Store) Remove

func (s *Store) Remove(value indexer.Value, multihash ...multihash.Multihash) error

func (*Store) RemoveProvider

func (s *Store) RemoveProvider(ctx context.Context, id peer.ID) error

func (*Store) RemoveProviderContext

func (s *Store) RemoveProviderContext(id peer.ID, ctx []byte) error

func (*Store) Sample

func (s *Store) Sample(ctx context.Context, population Population) ([]multihash.Multihash, error)

func (*Store) Size

func (s *Store) Size() (int64, error)

func (*Store) Stats

func (s *Store) Stats() (*indexer.Stats, error)

type Xedni

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

func New

func New(o ...Option) (*Xedni, error)

func (*Xedni) ServeMux

func (x *Xedni) ServeMux() *http.ServeMux

func (*Xedni) Shutdown

func (x *Xedni) Shutdown(ctx context.Context) (_err error)

func (*Xedni) Start

func (x *Xedni) Start(context.Context) error

func (*Xedni) Store

func (x *Xedni) Store() *Store

Jump to

Keyboard shortcuts

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