routertwo

package
v0.0.0-...-3faa176 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound errors are returned when searching for something that does not exist

View Source
var ErrOffline = errors.New("peer offline")

ErrOffline used to indicate an offline host

Functions

This section is empty.

Types

type Host

type Host struct {
	Routable `json:"-"`
	Name     string `json:"name"`

	// LastSeen is used when garbage collecting
	LastSeen time.Time `json:"lastseen"`
	Created  time.Time `json:"created"`
}

Host represents a host that can be offline

func (*Host) DialContext

func (h *Host) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext dials this host

func (*Host) FQDN

func (h *Host) FQDN() string

FQDN returns the fully qualified domain name for this host

func (*Host) Replaced

func (h *Host) Replaced()

Replaced indicates to this host, that it have been replaced

type Intermediate

type Intermediate struct {
	Host       *Host       `json:"host,omitempty"`
	NamedRoute *NamedRoute `json:"namedroute,omitempty"`
}

Intermediate is able to json parse either Hosts or NamedRoutes from json files

func (*Intermediate) Wake

func (i *Intermediate) Wake(r *Router) (Routable, error)

Wake wakes up a newly parsed Host or NamedRoute Named routes needs to know the current router

type NamedRoute

type NamedRoute struct {
	// Name, the FQDN
	Name string

	// Owner's pubkey fingerprint
	Owner string
	// contains filtered or unexported fields
}

NamedRoute implements Routable and is used when people want to create more human friendly hostnames for their tunnels

func NewName

func NewName(s string, r Routable) *NamedRoute

NewName sets up and returns a *NamedRoute which can be added the router

func (*NamedRoute) DialContext

func (n *NamedRoute) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext on a NamedRoute looks up the correct tunnel in the router and uses its DialContext

func (*NamedRoute) FQDN

func (n *NamedRoute) FQDN() string

FQDN returns the fully qualified domain name for this route

func (*NamedRoute) Replaced

func (n *NamedRoute) Replaced()

Replaced for NamedRoutes means deleting the NamedRoute for good and really should not happen - only in the case that a user tries to steal another users pubkey.hostname name - an when the guy with the actural key comes online - this Replaced is called which will remove it from the database

type Routable

type Routable interface {
	DialContext(ctx context.Context, network, address string) (net.Conn, error)

	// A routable should be able to identify it self
	FQDN() string

	// Replaced is used to indicate to a ssh session that it's routes
	// have been replaced with another ssh session
	Replaced()
}

Routable describes requirements to be routable

type Router

type Router struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Router - takes care of Routable and Namedroutes

func NewRouter

func NewRouter(dbPath string) (*Router, error)

NewRouter initializes a new Router with a given path

func (*Router) AddName

func (r *Router) AddName(n *NamedRoute) error

AddName adds a *NamedRoute to the router

func (*Router) DialContext

func (r *Router) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext is used by stuff that what to dial something up

func (*Router) Exists

func (r *Router) Exists(_ context.Context, s string) error

Exists returns an error if a given hostname does not exist

func (*Router) Find

func (r *Router) Find(n string) (Routable, bool)

Find fetches a route

func (*Router) Names

func (r *Router) Names(rtbl Routable) ([]NamedRoute, error)

Names returns a list of NamedRoutes

func (*Router) Offline

func (r *Router) Offline(d Routable)

Offline removes the routable from a host

func (*Router) Online

func (r *Router) Online(rtbl Routable) (bool, error)

Online should only be used by peers, e.g. ssh clients which proved by authentication that they do infact have the private key for their FQDN

func (*Router) RemoveName

func (r *Router) RemoveName(s string, from Routable) error

RemoveName removes a named router if * The route exists * The route is a *NamedRoute * The *NamedRoute's owner, is the one trying to remove it

func (*Router) RemoveNames

func (r *Router) RemoveNames(from Routable) ([]*NamedRoute, error)

RemoveNames removes all names from a Routable

Jump to

Keyboard shortcuts

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