libp2p-facade

module
v0.0.6-alpha Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2020 License: MIT

README

libp2p-facade

WIP

This module consists of libp2p peer abstraction, utilities, configurations and setup. The idea is to encapsulate libp2p's common components (pubsub, dht, ipld, etc...) using the same API cross-project.

Inspired by ipfs-lite, which is an alternative to a full IPFS, and comes by default with IPLD (DAGService).

This package makes it easy to configure several types of libp2p peers:

  • LibP2PPeer (./core/node.go) is the most minimal interface
    • local datastore, DHT, pubsub
    • a circuit-relay peer for example, doesn't need more than that (see ./core/circuit-relay)
  • StoragePeer (./storage/peer.go) - a peer with distributed storage for IPLD data
    • similar to ipfs-lite
    • ipld.DAGService
    • crdt could be configured easily to provide state consistency, see ./storage/crdt.go

Install

As a library:

go get github.com/amirylm/libp2p-facade

Usage

See tests for more examples.

package main

import (
    "log"

	p2pfacade "github.com/amirylm/libp2p-facade/core"
	
	"github.com/libp2p/go-libp2p-core/crypto"
	"github.com/libp2p/go-libp2p-core/peer"
	"github.com/libp2p/go-libp2p-core/pnet"
)

func startNode(psk pnet.PSK, priv crypto.PrivKey, peers []peer.AddrInfo) (p2pfacade.LibP2PNode, error) {
    node := p2pfacade.NewBaseNode(context.Background(),
		p2pfacade.NewConfig(priv, psk, nil),
		p2pfacade.NewDiscoveryConfig(nil),
	)

	conns := p2pfacade.Connect(node, peers, true)
	for conn := range conns {
		if conn.Error != nil {
			log.Printf("could not connect to %s", conn.Info.ID)
		} else {
			log.Printf("connected to %s", conn.Info.ID)
		}
	}

	return node, nil
}

func main() {
    startNode(nil, nil, []peer.AddrInfo{})
    // ...
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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