diet256

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2022 License: MPL-2.0 Imports: 23 Imported by: 1

README

Diet256

Diet256 is a centrally coordinated, densely connected overlay network, implementing the INET256 spec. It's the same simple INET256 API, but without any of peering or routing configuration to manage.

Diet256 makes all its connections over The Internet using QUIC and uses a central server to discover the IP address of peers. The central server is outside an INET256 application's security perimeter, and the worst thing it can do is misinform a client about the location of a peer. It can't trick applications into sending or receiving messages to or from the wrong peers.

Getting Started

Either download a binary from the release page or build from source.

Installing From Source

In the repo, run make install and it will install to $GOPATH/bin.

Run the Daemon

You can run diet256 as a fully functional INET256 implementation (instead of the reference implementation).

$ diet256 daemon

All the INET256 tools will work with diet256 including the IPv6 Portal.

Using this Library

You can import this package as a go library and build an INET256 application without running any additional daemon processes.

package main

import (
	"context"
	"crypto/ed25519"
	"log"

	"github.com/inet256/diet256"
	"github.com/inet256/inet256/pkg/inet256"
)

func main() {
	srv, err := diet256.New() // That's it; now you're ready to create Nodes.
	if err != nil {
		log.Fatal(err)
	}

	// Provide a key, which will determine the Node's local address
	_, privateKey, _ = ed25519.GenerateKey(nil)
	node, err := srv.Open(ctx, privateKey)
	if err != nil {
		log.Fatal(err)
	}
	defer node.Close()
	log.Println("local node:", node.LocalAddr())

	// dst is the address of the peer you want to send to.
	dst := inet256.ID{}
	node.Send(context.Background(), dst, []byte("ping"))
}

Run the IPv6 Portal In-Process

Normally, the IPv6 Portal runs as its own process, separate from the INET256 daemon. You can do that with inet256 ip6-portal, if diet256 daemon or another INET256 implementation is running.

diet256 also supports an in process IPv6 portal. You can launch that with

$ diet256 ip6-portal --private-key ./path/to/private_key.pem

INFO[0000] opened node jAeAUgztUHiKUgNpIDtzBcVm19Y9Y829MvhqFvG3VSY
INFO[0000] Created TUN utun2
INFO[0000] Local INET256: jAeAUgztUHiKUgNpIDtzBcVm19Y9Y829MvhqFvG3VSY
INFO[0000] Local IPv6: 200:603c:290:676a:83c4:5290:1b49:1db

And then you will have a TUN device connected to the diet256 network using the standard IPv6-to-INET256 address mapping.

More

For more INET256 docs head over to INET256.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(opts ...ClientOption) inet256.Service

New creates a new inet256.Service

Types

type Client

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

func (*Client) Drop added in v0.0.2

func (c *Client) Drop(ctx context.Context, privateKey inet256.PrivateKey) error

func (*Client) Open

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

type ClientOption

type ClientOption = func(*Client)

func WithEndpoint

func WithEndpoint(id inet256.ID, addr string) ClientOption

func WithListenPacketConn

func WithListenPacketConn(fn ListenPacketConn) ClientOption

func WithLogger

func WithLogger(log *logrus.Logger) ClientOption

type Endpoint

type Endpoint struct {
	ID   inet256.ID
	Addr string
}

Endpoint is a INET256 address plus UDP address or domain name.

func ParseEndpoint

func ParseEndpoint(x []byte) (*Endpoint, error)

ParseEndpoint parses an endpoint in <INET256>@<host>:<port> format.

type ListenPacketConn

type ListenPacketConn = func(ctx context.Context, network, addr string) (net.PacketConn, error)

type Node

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

func (*Node) Close

func (n *Node) Close() error

func (*Node) FindAddr

func (n *Node) FindAddr(ctx context.Context, prefix []byte, nbits int) (inet256.Addr, error)

func (*Node) LocalAddr

func (n *Node) LocalAddr() inet256.Addr

func (*Node) LookupPublicKey

func (n *Node) LookupPublicKey(ctx context.Context, target inet256.Addr) (inet256.PublicKey, error)

func (*Node) MTU

func (n *Node) MTU(ctx context.Context, dst inet256.Addr) int

func (*Node) PublicKey

func (n *Node) PublicKey() inet256.PublicKey

func (*Node) Receive

func (n *Node) Receive(ctx context.Context, fn func(inet256.Message)) error

func (*Node) Send

func (n *Node) Send(ctx context.Context, dst inet256.Addr, data []byte) error

type Server

type Server struct {
	protocol.UnimplementedControlServer
	// contains filtered or unexported fields
}

func NewServer

func NewServer(pconn net.PacketConn, privateKey inet256.PrivateKey, opts ...ServerOption) (*Server, error)

func (*Server) Addr

func (s *Server) Addr() string

func (*Server) Close

func (s *Server) Close() error

func (*Server) Dial

func (s *Server) Dial(ctx context.Context, req *protocol.DialReq) (*protocol.DialRes, error)

Dial implements ControlServer.Dial

func (*Server) FindAddr

func (s *Server) FindAddr(ctx context.Context, req *protocol.FindAddrReq) (*protocol.FindAddrRes, error)

FindAddr implements ControlServer.FindAddr

func (*Server) Listen

func (s *Server) Listen(req *protocol.ListenReq, srv protocol.Control_ListenServer) (retErr error)

Dial implements ControlServer.Listen

func (*Server) LookupPublicKey

LookupPublicKey implements ControlServer.LookupPublicKey

func (*Server) PublicKey

func (s *Server) PublicKey() inet256.PublicKey

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

func (*Server) Wait

func (s *Server) Wait() error

type ServerOption added in v0.0.3

type ServerOption func(c *serverConfig)

func WithFindAddrMinBits added in v0.0.3

func WithFindAddrMinBits(n int) ServerOption

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

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