p2p

package
v1.8.4 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2024 License: MIT Imports: 2 Imported by: 0

README

Introduction

This repo contains the Colonies P2P network stack based in libp2p.

Colonies uses it own DHT (Kademlia) implementation. Here is example code how to setup a DHT network constisting of two nodes.

dht1, err := dht.CreateDHT(4001, "dht1")
dht2, err := dht.CreateDHT(4002, "dht2")

Register dht2 with dht1.

err = dht2.RegisterNetworkWithAddr(c.Node.Addr, c.ID.String(), ctx)

When using libp2p, the adresses will look like this: /ip4/10.0.0.201/tcp/4001/p2p/12D3KooWMkeo4JoJkf2e5CQgkZy55EkD4gXR8M2oW9WtvMDBS17K

To publish key-value pair in the network, we must have a valid ECDSA private key.

crypto := crypto.CreateCrypto()
prvKey, err := crypto.GeneratePrivateKey()
id, err := crypto.GenerateID(prvKey)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	ID      string
	From    Node
	To      Node
	Type    int
	Payload []byte
}

type Messenger

type Messenger interface {
	Send(msg Message, ctx context.Context) error
	ListenForever(msgChan chan Message, ctx context.Context) error
}

type Node

type Node struct {
	Name string `json:"name"`
	Addr string `json:"addr"`
}

func ConvertJSONToNode

func ConvertJSONToNode(jsonStr string) (Node, error)

func CreateNode

func CreateNode(name string, addr string) Node

func (*Node) Equals

func (n *Node) Equals(other Node) bool

func (*Node) String

func (n *Node) String() string

func (*Node) ToJSON

func (n *Node) ToJSON() (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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