config

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package config provides the forwarding configuration data models used in this application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsOnionHost

func IsOnionHost(s string) bool

IsOnionHost returns whether the host is a .onion address.

Types

type Endpoint

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

Endpoint represents a source or destination endpoint in a forwarding tunnel. The source may be regarded as the "backend" which provides a service being forwarded. The destination may be regarded as the "frontend" where the service is forwarded to, or published for consumption.

func ParseEndpoint

func ParseEndpoint(s string, dest bool) (*Endpoint, error)

ParseEndpoint returns an Endpoint from the given string representation and whether it is intended to be used as a destination or source in a forward.

func (*Endpoint) Alias

func (e *Endpoint) Alias() string

Alias returns the endpoint's alias, if it has one.

func (*Endpoint) Description

func (e *Endpoint) Description(remoteOnions map[string]string) string

Description returns a string description of the endpoint. If the endpoint destination is an onion, a mapping of alias to remote onion ID may be provided, to render the assigned onion address.

func (*Endpoint) IsDest

func (e *Endpoint) IsDest() bool

IsDest returns whether a resolved endpoint is a destination. If it's not a destination, it's a source in a forward.

func (*Endpoint) IsOnion

func (e *Endpoint) IsOnion() bool

IsOnion returns whether a resolved endpoint is an onion address.

func (*Endpoint) IsUnix

func (e *Endpoint) IsUnix() bool

IsUnix returns whether the endpoint is a unix socket.

func (*Endpoint) OnionID

func (e *Endpoint) OnionID() (string, bool)

OnionID returns the onion ID (host without the .onion suffix) and whether the host is an onion.

func (*Endpoint) Ports

func (e *Endpoint) Ports() []int

Ports returns the port numbers assigned to this endpoint.

func (*Endpoint) Resolve

func (e *Endpoint) Resolve(asOnion bool) error

Resolve validates the endpoint to ensure it is well-formed. For UNIX socket endpoints, the socket path is validated for existence. For local network TCP socket endpoints, the host is resolved to a network address according to the system's default name resolver.

asOnion is provided to disambiguate an endpoint that does not yet have its host resolved.

Such name resolution is provided here as a convenience -- if it doesn't resolve how you like, or there's a chance it will choose the wrong interface, configure the actual interface you want. The default resolver is generally Good Enough for container use cases, where the networking and routing is handled up the stack in something like compose or k8s. It might be a bit YOLO-networking on a bare metal server with several physical NICs and multiple DNS names. Caveat emp-tor.

func (*Endpoint) ServiceKey

func (e *Endpoint) ServiceKey() []byte

ServiceKey gets the remote endpoint's service key. May be nil.

func (*Endpoint) SetServiceKey

func (e *Endpoint) SetServiceKey(key []byte)

SetServiceKey sets the remote endpoint's service key.

func (*Endpoint) SingleAddr

func (e *Endpoint) SingleAddr() (string, error)

SingleAddr returns the string representation of the endpoint as a single address in a port or socket forward. Some endpoints do not have such a representation, in which case an error is returned.

type EndpointDoc

type EndpointDoc struct {
	Host  string `json:"host"`
	Ports []int  `json:"ports"`
	Path  string `json:"unix"`
	Alias string `json:"alias"`
}

EndpointDoc defines a JSON representation of an endpoint.

func (*EndpointDoc) Endpoint

func (d *EndpointDoc) Endpoint(dest, asOnion bool) (*Endpoint, error)

Endpoint returns a validated and resolved Endpoint from a JSON document object model.

type Forward

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

Forward defines a network forwarding relay from a source endpoint to a destination endpoint.

func ParseForward

func ParseForward(s string) (*Forward, error)

ParseForward returns a new Forward parsed from a string representation

func (*Forward) Description

func (f *Forward) Description(remoteOnions map[string]string) string

Description returns a string description of the forward. If the forward destination is an onion, a mapping of alias to remote onion ID may be provided, to render the assigned onion address.

func (*Forward) Destination

func (f *Forward) Destination() *Endpoint

Destination returns the destination endpoint in the forwarding relay.

func (*Forward) IsImport

func (f *Forward) IsImport() bool

IsImport returns whether the forward is importing an onion to a local network endpoint.

func (*Forward) Resolve

func (f *Forward) Resolve() error

Resolve validates the endpoints of the forward and whether together they constitute a valid, well-formed and supported forwarding arrangement.

func (*Forward) Source

func (f *Forward) Source() *Endpoint

Source returns the source endpoint in the forwarding relay.

type ForwardDoc

type ForwardDoc struct {
	Src  EndpointDoc `json:"src"`
	Dest EndpointDoc `json:"dest"`
}

ForwardDoc defines a JSON representation of a forward.

func (*ForwardDoc) Forward

func (d *ForwardDoc) Forward() (*Forward, error)

Forward returns a validated and resolved Forward from a JSON document object model.

Jump to

Keyboard shortcuts

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