nethelper

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: Apache-2.0 Imports: 5 Imported by: 3

Documentation

Overview

Package nethelper wraps various kind of network support with universal api to dial and listen you need to import according packages to enabled certain network supprot

to support

		tcp/tcp4/tcp6/unix (with or without tls)
		udp/udp4/udp6 (without tls)
		unixpacket/unixgram (with or without tls)
 import _ "arhat.dev/pkg/nethelper/stdnet"

to support

		udp/udp4/udp6 (with tls)
 import _ "arhat.dev/pkg/nethelper/piondtls"

to support

		pipe (with or without tls)
 import _ "arhat.dev/pkg/nethelper/pipenet"

Index

Constants

View Source
const (
	ErrDialerInvalid       errhelper.ErrString = "invalid dialer"
	ErrTLSConfigInvalid    errhelper.ErrString = "invalid tls config"
	ErrListenConfigInvalid errhelper.ErrString = "invalid listen config"
)

Common network errors

Variables

This section is empty.

Functions

func Dial added in v0.4.0

func Dial(ctx context.Context, dialer interface{}, network, addr string, tlsConfig interface{}) (net.Conn, error)

func Forward added in v0.4.0

func Forward(
	ctx context.Context,
	dialer interface{},
	network string,
	addr string,
	upstream io.Reader,
	packetReadBuf []byte,
) (
	downstream io.ReadCloser,
	closeWrite func(),
	readErrCh <-chan error,
	err error,
)

Forward network traffic the parameters:

ctx is used to cancel dial operation and read error sending
dialer is optional for custom network dial options
network is the network name, e.g. tcp, udp, tcp4
addr is the endpoint address
upstream is the data channel to the endpoint
packetReadBuf is the buffer used for udp/ip/unix connection

the return values:

	downstream is used to read data sent from the forwarded port and close connection, it actually is a
   net.Conn and you can cast it to any real type it is, but kept as reader here for better understanding.
	closeWrite is intended to close write in stream oriented connection
	readErrCh is used to check read error and whether donwstream reading finished
	err if not nil the port forward failed

func Listen added in v0.4.0

func Listen(
	ctx context.Context,
	config interface{},
	network, addr string,
	tlsConfig interface{},
) (interface{}, error)

func Register added in v0.4.0

func Register(network string, forTLS bool, listen ListenFunc, dial DialFunc)

Types

type DialFunc added in v0.4.0

type DialFunc func(
	ctx context.Context,
	dialer interface{},
	network, addr string,
	tlsConfig interface{},
) (net.Conn, error)

type ListenFunc added in v0.4.0

type ListenFunc func(
	ctx context.Context,
	config interface{},
	network, addr string,
	tlsConfig interface{},
) (interface{}, error)

Directories

Path Synopsis
Package piondtls registers udp/udp4/udp6 with dtls support to nethelper package import this package as `_ "arhat.dev/pkg/nethelper/piondtls"` then you can listen and dial udp/udp4/udp6 dtls connections
Package piondtls registers udp/udp4/udp6 with dtls support to nethelper package import this package as `_ "arhat.dev/pkg/nethelper/piondtls"` then you can listen and dial udp/udp4/udp6 dtls connections
Package pipenet register pipe network (arhat.dev/pkg/pipenet) with and without tls support import this package as `_ "arhat.dev/pkg/nethelper/pipenet"` then you can listen and dial udp/udp4/udp6 dtls connections
Package pipenet register pipe network (arhat.dev/pkg/pipenet) with and without tls support import this package as `_ "arhat.dev/pkg/nethelper/pipenet"` then you can listen and dial udp/udp4/udp6 dtls connections
Package stdnet register tcp/tcp4/tcp6/udp/udp4/udp6/unix network implementation from standard `net` library
Package stdnet register tcp/tcp4/tcp6/udp/udp4/udp6/unix network implementation from standard `net` library

Jump to

Keyboard shortcuts

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