libp2p-facade

module
v0.0.61-alpha Latest Latest
Warning

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

Go to latest
Published: Sep 21, 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

More examples available in:

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 startPeer(psk pnet.PSK, priv crypto.PrivKey, peers []peer.AddrInfo) (p2pfacade.LibP2PPeer, error) {
    p := p2pfacade.NewBasePeer(context.Background(),
		p2pfacade.NewConfig(priv, psk, nil),
		p2pfacade.NewDiscoveryConfig(nil),
	)

	conns := p2pfacade.Connect(p, 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 p, nil
}

func main() {
    startPeer(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