mesh256

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2022 License: GPL-3.0 Imports: 25 Imported by: 1

README

Mesh256

Mesh256 is the reference implementation of an inet256.Service. Mesh256 is built as a mesh network using a distributed routing algorithm.

Any suitable routing algorithm can be used to route packets and drive the network. The interface to implement is mesh256.Network, defined in network.go. There is a package including tests for mesh256.Network implementations in mesh256test.

Mesh256 is built around Swarms from the go-p2p library.

Networks (routing algorithms) are given a private key, a Swarm and a PeerSet.

The PeerSet is just a list of peers that are accessible through the swarm. These are the one-hop peers. It is the job the Network to figure out how to route messages to more peers than just those in this set.

Stack

An mesh256 Node's stack looks like this, implemented as layered Swarms

                Application Data :-)
|-----------------------------------------------|
|             Encryption Layer (P2PKE)          |
|-----------------------------------------------|
|           Network Routing Algorithm           |
|-----------------------------------------------|
|        Packet Fragmentation & Assembly        |
|-----------------------------------------------|
|                 Multihoming                   |
|-----------------------------------------------|
| Transports:                                   |
|     (QUIC)   |    (QUIC)      |               |
|      UDP     |    ETHERNET    |  MEMORY       |
|-----------------------------------------------|                   ...
                        NODE 1                                      NODE 2
                        |                                           |
                        |___________________________________________|


The life of a message through the stack starting as application data:

  1. All traffic from client applications is encrypted immeditately, and only readable at its intended destination.
  2. The applicaiton ciphertext is passed to the network routing algorithm, which creates a network message.
  3. The network message may need to be broken up and reassembled if it is larger than the transport MTU.
  4. The best transport for a peer is selected.
  5. The network message is encrypted if it has to leave the process.
  6. The network message ciphertext, is sent out using one of the transport swarms.

All data leaving the node is encrypted until the next hop. All data traveling through a network is encrypted until it reaches it's destination.

There is no fragmentation at the network layer, only at the one hop layer if the MTU is less than 2^16-1. If a message is fragmented, it is reassembled at the next hop, before the network algorithms see it. Application data is never fragmented, and then passed to the networks.

Documentation

Overview

package mesh256 implements an INET256 Service in terms of a distributed routing algorithm and a dynamic set of one hop connections to peers.

Index

Constants

View Source
const (
	TransportMTU = (1 << 16) - 1

	MinMTU = inet256.MinMTU
	MaxMTU = inet256.MaxMTU
)

Variables

This section is empty.

Functions

func NewAddrSchema

func NewAddrSchema(swarms map[string]multiswarm.DynSwarm) multiswarm.AddrSchema

func NewPeerStore

func NewPeerStore() peers.Store[TransportAddr]

func NewTestServers

func NewTestServers(t testing.TB, nf NetworkFactory, xs []inet256.Service)

func SecureDynSwarm added in v0.0.5

func SecureDynSwarm(protoName string, s multiswarm.DynSwarm, privateKey p2p.PrivateKey) (string, multiswarm.DynSecureSwarm)

SecureDynSwarm

func SecureProtocolName added in v0.0.5

func SecureProtocolName(x string) string

SecureProtocolName returns the name of the protocol after securing an insecure swarm It will match what is returned by Server.TransportAddrs()

Types

type Addr

type Addr = inet256.Addr

type FindAddrFunc

type FindAddrFunc = func(ctx context.Context, prefix []byte, nbits int) (inet256.Addr, error)

type Network

type Network interface {
	p2p.Teller[inet256.Addr]
	LocalAddr() inet256.Addr
	MTU(context.Context, inet256.Addr) int
	Close() error

	LookupPublicKey(context.Context, inet256.Addr) (inet256.PublicKey, error)
	PublicKey() inet256.PublicKey

	FindAddr(ctx context.Context, prefix []byte, nbits int) (inet256.Addr, error)
}

Network is an instantiated network routing algorithm

This interface is not described in the spec, and is incidental to the implementation.

func NetworkFromSwarm

func NetworkFromSwarm(x Swarm, findAddr FindAddrFunc) Network

NetworkFromSwarm creates a Network from a Swarm

type NetworkFactory

type NetworkFactory func(NetworkParams) Network

NetworkFactory is a constructor for a network

type NetworkParams

type NetworkParams struct {
	// PrivateKey is the private signing key used for proving identity on the network.
	PrivateKey inet256.PrivateKey
	// Swarm facillitates communication with adjacent Nodes.
	Swarm Swarm
	// Peers is the set of peers to communicate with.
	Peers PeerSet
	// Background is the context that should be used for background operations.
	// It enables instrumentation through the stdctx/logctx package.
	Background context.Context
}

Params are passed to a NetworkFactory to create a Network. This type really defines the problem domain quite well. Essentially it is a set of one-hop peers and a means to send messages to them.

type Node

type Node = inet256.Node

func NewNode

func NewNode(params NodeParams) Node

type NodeParams added in v0.0.7

type NodeParams struct {
	PrivateKey inet256.PrivateKey
	Swarms     map[string]multiswarm.DynSwarm
	Peers      peers.Store[TransportAddr]
	NewNetwork NetworkFactory
}

NodeParams configure a Node

type Params

type Params NodeParams

type PeerSet

type PeerSet = peers.Set

type PeerStatus

type PeerStatus struct {
	Addr       Addr
	LastSeen   map[string]time.Time
	Uploaded   uint64
	Downloaded uint64
}

type Server

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

func NewServer

func NewServer(params Params) *Server

func NewTestServer

func NewTestServer(t testing.TB, nf NetworkFactory) *Server

func (*Server) Close

func (s *Server) Close() error

func (*Server) Drop added in v0.0.5

func (s *Server) Drop(ctx context.Context, privateKey inet256.PrivateKey) error

func (*Server) FindAddr

func (s *Server) FindAddr(ctx context.Context, prefix []byte, nbits int) (Addr, error)

func (*Server) LocalAddr

func (s *Server) LocalAddr() Addr

func (*Server) LookupPublicKey

func (s *Server) LookupPublicKey(ctx context.Context, target Addr) (inet256.PublicKey, error)

func (*Server) MTU

func (s *Server) MTU(ctx context.Context, target Addr) int

func (*Server) MainAddr

func (s *Server) MainAddr() (Addr, error)

func (*Server) MainNode

func (s *Server) MainNode() Node

func (*Server) Open

func (s *Server) Open(ctx context.Context, privateKey inet256.PrivateKey, opts ...inet256.NodeOption) (Node, error)

func (*Server) PeerStatus

func (s *Server) PeerStatus() ([]PeerStatus, error)

func (*Server) TransportAddrs

func (s *Server) TransportAddrs() ([]multiswarm.Addr, error)

type Service

type Service interface {
	inet256.Service

	MainAddr() (Addr, error)
	TransportAddrs() ([]p2p.Addr, error)
	PeerStatus() ([]PeerStatus, error)
}

type Swarm

type Swarm interface {
	p2p.Teller[inet256.Addr]

	LookupPublicKey(context.Context, inet256.Addr) (inet256.PublicKey, error)
	PublicKey() inet256.PublicKey

	LocalAddr() Addr
	MTU(ctx context.Context, addr Addr) int
	Close() error
}

Swarm is similar to a p2p.Swarm, but uses inet256.Addrs instead of p2p.Addrs

This interface is not described in the spec, and is incidental to the implementation.

func NewSwarm

func NewSwarm[T p2p.Addr](x p2p.SecureSwarm[T], peers peers.Store[T]) Swarm

type TransportAddr

type TransportAddr = multiswarm.Addr

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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