point_c

package module
v0.0.13 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	CaddyfilePointCName = "point-c"
)
View Source
const NetworkStubName = "stub:"

Variables

This section is empty.

Functions

func DialRemoteLoop added in v0.0.3

func DialRemoteLoop(n Net, dstPort uint16, pairs <-chan *ConnPair, dialed chan<- *ConnPair)

func ListenLoop added in v0.0.3

func ListenLoop(ln net.Listener, conns chan<- net.Conn)

func PrepareConnPairLoop added in v0.0.3

func PrepareConnPairLoop(ctx context.Context, logger *slog.Logger, conns <-chan net.Conn, pairs chan<- *ConnPair)

func StartCopyLoop added in v0.0.3

func StartCopyLoop(pairs <-chan *ConnPair, copyFn func(done func(), dst io.Writer, src io.Reader, logger *slog.Logger))

func StubListener added in v0.0.3

func StubListener(_ context.Context, _, addr string, _ net.ListenConfig) (any, error)

StubListener creates a stub network listener. This listener does not accept actual network connections but instead blocks on Accept calls until Close is called. It can be used as a base listener when only tunnel listeners are required.

func TcpCopy added in v0.0.3

func TcpCopy(done func(), dst io.Writer, src io.Reader, logger *slog.Logger)

Types

type ConnPair added in v0.0.3

type ConnPair struct {
	Ctx    context.Context
	Cancel context.CancelFunc
	Remote net.Conn
	Tunnel net.Conn
	Logger *slog.Logger
}

func (*ConnPair) DialTunnel added in v0.0.3

func (cp *ConnPair) DialTunnel(n Net, dstPort uint16) bool

type Dialer

type Dialer interface {
	// Dial dials a remote address with the TCP protocol.
	Dial(context.Context, *net.TCPAddr) (net.Conn, error)
	// DialPacket dials a remote address with the UDP protocol.
	DialPacket(*net.UDPAddr) (net.PacketConn, error)
}

type DynamicDialer added in v0.0.10

type DynamicDialer struct {
	DialFn       func(ctx context.Context, addr *net.TCPAddr) (net.Conn, error)
	DialPacketFn func(addr *net.UDPAddr) (net.PacketConn, error)
}

func (*DynamicDialer) Dial added in v0.0.10

func (d *DynamicDialer) Dial(c context.Context, a *net.TCPAddr) (net.Conn, error)

func (*DynamicDialer) DialPacket added in v0.0.10

func (d *DynamicDialer) DialPacket(a *net.UDPAddr) (net.PacketConn, error)

type DynamicNet added in v0.0.10

type DynamicNet struct {
	ListenFn       func(*net.TCPAddr) (net.Listener, error)
	ListenPacketFn func(*net.UDPAddr) (net.PacketConn, error)
	DialerFn       func(laddr net.IP, port uint16) Dialer
	LocalAddrFn    func() net.IP
}

func (*DynamicNet) Dialer added in v0.0.10

func (d *DynamicNet) Dialer(a net.IP, p uint16) Dialer

func (*DynamicNet) Listen added in v0.0.10

func (d *DynamicNet) Listen(a *net.TCPAddr) (net.Listener, error)

func (*DynamicNet) ListenPacket added in v0.0.10

func (d *DynamicNet) ListenPacket(a *net.UDPAddr) (net.PacketConn, error)

func (*DynamicNet) LocalAddr added in v0.0.10

func (d *DynamicNet) LocalAddr() net.IP

type Forward added in v0.0.3

type Forward struct {
	ForwardsRaw []json.RawMessage     `json:"forwards,omitempty" caddy:"namespace=point-c.op.forward inline_key=forward"`
	Host        configvalues.Hostname `json:"host"`
	// contains filtered or unexported fields
}

func (*Forward) CaddyModule added in v0.0.3

func (f *Forward) CaddyModule() caddy.ModuleInfo

func (*Forward) Cleanup added in v0.0.3

func (f *Forward) Cleanup() error

func (*Forward) Provision added in v0.0.3

func (f *Forward) Provision(ctx caddy.Context) error

func (*Forward) Start added in v0.0.3

func (f *Forward) Start(lookup NetLookup) error

func (*Forward) UnmarshalCaddyfile added in v0.0.3

func (f *Forward) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

type ForwardProto added in v0.0.3

type ForwardProto = lifecycler.LifeCyclable[Net]

type ForwardTCP added in v0.0.3

type ForwardTCP struct {
	Ports configvalues.PortPair `json:"ports"`
	// contains filtered or unexported fields
}

func (*ForwardTCP) CaddyModule added in v0.0.3

func (f *ForwardTCP) CaddyModule() caddy.ModuleInfo

func (*ForwardTCP) Cleanup added in v0.0.3

func (f *ForwardTCP) Cleanup() error

func (*ForwardTCP) Provision added in v0.0.3

func (f *ForwardTCP) Provision(ctx caddy.Context) error

func (*ForwardTCP) Start added in v0.0.3

func (f *ForwardTCP) Start(n Net) error

func (*ForwardTCP) Stop added in v0.0.3

func (f *ForwardTCP) Stop() error

func (*ForwardTCP) UnmarshalCaddyfile added in v0.0.3

func (f *ForwardTCP) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

type Listener

type Listener struct {
	Name configvalues.Hostname `json:"name"`
	Port configvalues.Port     `json:"port"`
	// contains filtered or unexported fields
}

Listener allows a caddy server to listen on a point-c network.

func (*Listener) Accept

func (p *Listener) Accept() (net.Conn, error)

func (*Listener) Addr

func (p *Listener) Addr() net.Addr

func (*Listener) CaddyModule

func (*Listener) CaddyModule() caddy.ModuleInfo

func (*Listener) Close

func (p *Listener) Close() error

func (*Listener) Provision

func (p *Listener) Provision(ctx caddy.Context) error

func (*Listener) Start added in v0.0.13

func (p *Listener) Start(fn func(net.Listener)) error

func (*Listener) UnmarshalCaddyfile

func (p *Listener) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile unmarshals the caddyfile.

	{
	  servers :443 {
	    listener_wrappers {
	      merge {
         # this is the actual listener definition
	        point-c <network name> <port to expose>
	      }
       # make sure tls goes after otherwise encryption will be dropped
	      tls
	    }
	  }
	}

type ListenerProvider added in v0.0.13

type ListenerProvider lifecycler.LifeCyclable[func(net.Listener)]

MergeWrapper loads multiple [net.Listener]s and aggregates their [net.Conn]s into a single net.Listener. It allows caddy to accept connections from multiple sources.

type MergeWrapper added in v0.0.3

type MergeWrapper struct {
	// ListenerRaw is a slice of JSON-encoded data representing listener configurations.
	// These configurations are used to create the actual net.Listener instances.
	// Listeners should implement [net.Listener] and be in the 'caddy.listeners.merge.listeners' namespace.
	ListenerRaw []json.RawMessage `json:"listeners" caddy:"namespace=caddy.listeners.merge inline_key=listener"`
	// contains filtered or unexported fields
}

MergeWrapper loads multiple [net.Listener]s and aggregates their [net.Conn]s into a single net.Listener. It allows caddy to accept connections from multiple sources.

func (*MergeWrapper) CaddyModule added in v0.0.3

func (p *MergeWrapper) CaddyModule() caddy.ModuleInfo

CaddyModule implements caddy.Module.

func (*MergeWrapper) Cleanup added in v0.0.3

func (p *MergeWrapper) Cleanup() (err error)

Cleanup implements caddy.CleanerUpper. All wrapped listeners are closed and the struct is cleared.

func (*MergeWrapper) Provision added in v0.0.3

func (p *MergeWrapper) Provision(ctx caddy.Context) error

Provision implements caddy.Provisioner. It loads the listeners from their configs and asserts them to net.Listener. Any failed assertions will cause a panic.

func (*MergeWrapper) UnmarshalCaddyfile added in v0.0.3

func (p *MergeWrapper) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile implements caddyfile.Unmarshaler. Must have at least one listener to aggregate with the wrapped listener. `tls` should come specifically after any `merge` directives.

 http caddyfile:
	{
	  servers :443 {
	    listener_wrappers {
	      merge {
	        <submodule name> <submodule config>
	      }
	      tls
	    }
	  }
	}

func (*MergeWrapper) WrapListener added in v0.0.3

func (p *MergeWrapper) WrapListener(ls net.Listener) net.Listener

WrapListener implements caddy.ListenerWrapper. The listener passed in is closed by MergeWrapper during cleanup.

type Net

type Net interface {
	// Listen listens on the given address with the TCP protocol.
	Listen(addr *net.TCPAddr) (net.Listener, error)
	// ListenPacket listens on the given address with the UDP protocol.
	ListenPacket(addr *net.UDPAddr) (net.PacketConn, error)
	// Dialer returns a [Dialer] with a given local address. If the network does not support arbitrary remote addresses this value can be ignored.
	Dialer(laddr net.IP, port uint16) Dialer
	// LocalAddr is the local address of the net interface. If it does not have one, return nil.
	LocalAddr() net.IP
}

Net is a peer in the networking stack. If it has a local address [Net.LocalAddress] should return a non-nil value.

func NewSystemNet added in v0.0.10

func NewSystemNet() Net

type NetLookup

type NetLookup interface {
	Lookup(string) (Net, bool)
}

type NetOpApp added in v0.0.10

type NetOpApp Pointc

type Pointc

type Pointc struct {
	NetworksRaw []json.RawMessage `json:"networks,omitempty" caddy:"namespace=point-c.net inline_key=type"`
	NetOps      []json.RawMessage `json:"net-ops,omitempty" caddy:"namespace=point-c.op inline_key=op"`
	// contains filtered or unexported fields
}

Pointc allows usage of networks through a net-ish interface.

func (*Pointc) CaddyModule

func (*Pointc) CaddyModule() caddy.ModuleInfo

func (*Pointc) Cleanup

func (pc *Pointc) Cleanup() error

func (*Pointc) Lookup

func (pc *Pointc) Lookup(name string) (Net, bool)

Lookup gets a Net by its declared name.

func (*Pointc) Provision

func (pc *Pointc) Provision(ctx caddy.Context) error

func (*Pointc) Register added in v0.0.7

func (pc *Pointc) Register(key string, n Net) error

func (*Pointc) Start

func (pc *Pointc) Start() error

func (*Pointc) Stop

func (pc *Pointc) Stop() error

func (*Pointc) UnmarshalCaddyfile

func (pc *Pointc) UnmarshalCaddyfile(d *caddyfile.Dispenser) error

UnmarshalCaddyfile unmarshals a submodules from a caddyfile. The `netops` modifier causes the modules to be loaded as netops.

{
  point-c [netops] {
    <submodule name> <submodule config>
  }
}

type RegisterFunc

type RegisterFunc func(string, Net) error

RegisterFunc registers a unique name to a Net tunnel. Since ip addresses may be arbitrary depending on what the application is doing in the tunnel, names are used as lookup. This allows helps with configuration, so that users don't need to remember ip addresses.

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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