nethelper

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2020 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

This section is empty.

Variables

View Source
var (
	ErrDialerInvalid       = errors.New("invalid dialer")
	ErrTLSConfigInvalid    = errors.New("invalid tls config")
	ErrListenConfigInvalid = errors.New("invalid listen config")
)

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
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
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, supportTLS 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 register udp/udp4/udp6 with dtls support
Package piondtls register udp/udp4/udp6 with dtls support
Package pipenet register pipe with tls support
Package pipenet register pipe with tls support
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