network

package
v1.2.31 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2024 License: AGPL-3.0 Imports: 23 Imported by: 3

Documentation

Index

Constants

View Source
const (
	PmNONE = iota
	PmDIRECT
	PmUPNP
	PmSTUN
)

Port mapping modes

Variables

View Source
var (
	ErrNetInvalidEndpoint = errors.New("invalid endpoint")
	ErrNetInvalidNetwork  = errors.New("invalid network")
)

Error codes

View Source
var (
	ErrPortMapperInit    = fmt.Errorf("port mapper initialized")
	ErrPortMapperNoInit  = fmt.Errorf("port mapper not initialized")
	ErrPortMapperConfig  = fmt.Errorf("can't configure port mapper")
	ErrPortMapperUnknown = fmt.Errorf("unknown port mapping")
)

Error messages

View Source
var (
	ErrSocksUnsupportedProtocol = errors.New("unsupported protocol (TCP only)")
	ErrSocksInvalidProxyScheme  = errors.New("invalid proxy scheme")
	ErrSocksInvalidHost         = errors.New("invalid host definition (missing port)")
	ErrSocksInvalidPort         = errors.New("invalid host definition (port out of range)")
	ErrSocksProxyFailed         = errors.New("proxy server failed")
)

Error codes

Functions

func CreateMailMessage

func CreateMailMessage(body []byte, att []*MailAttachment) (msg []byte, err error)

CreateMailMessage creates a (plain) SMTP email with body and optional attachments.

func EncryptMailMessage

func EncryptMailMessage(key, body []byte) (cipher []byte, err error)

EncryptMailMessage encrypts a mail with given public key.

func RecvData

func RecvData(conn net.Conn, data []byte, srv string) (int, bool)

RecvData receives data over network connection (stream-oriented).

func RunService

func RunService(network, addr string, hdlr []Service) error

RunService runs a TCP/UDP network service with user-defined session handler.

func SendData

func SendData(conn net.Conn, data []byte, srv string) bool

SendData sends data over network connection (stream-oriented).

func SendMailMessage

func SendMailMessage(host, proxy, fromAddr, toAddr string, body []byte) (err error)

SendMailMessage handles outgoing message to SMTP server.

  • The connections to the service can be either plain (port 25) or SSL/TLS (port 465)

  • If the server supports STARTTLS and the channel is not already encrypted (via SSL), the application will use the "STLS" command to initiate a channel encryption.

- Connections can be tunneled through any SOCKS5 proxy (like Tor)

func Socks5Connect

func Socks5Connect(proto string, addr string, port int, proxy string) (net.Conn, error)

Socks5Connect connects to a SOCKS5 proxy.

func Socks5ConnectTimeout

func Socks5ConnectTimeout(proto string, addr string, port int, proxy string, timeout time.Duration) (conn net.Conn, err error)

Socks5ConnectTimeout connects to a SOCKS5 proxy with timeout.

func SplitNetworkEndpoint added in v1.2.2

func SplitNetworkEndpoint(networkendp string) (network string, endp string, err error)

SplitNetworkEndpoint splits a string like "tcp:127.0.0.1:80" or "unix:/run/app/app.sock" into components.

Types

type MailAttachment

type MailAttachment struct {
	Header textproto.MIMEHeader
	Data   []byte
}

MailAttachment is a data structure for data attached to a mail.

type MailContent

type MailContent struct {
	Mode    int    // message type (MDOE_XXX)
	From    string // sender email address
	To      string // recipient email address
	Subject string // subject line
	Body    string // message body
	Key     []byte // attached key or signing key (public)
}

MailContent is the result type for parsing mail messages

func ParseEncrypted

func ParseEncrypted(ct, addr string, getInfo MailUserInfo, body io.Reader) (mc *MailContent, err error)

ParseEncrypted parses a encrypted (and possibly signed) message.

func ParseMailMessage

func ParseMailMessage(msg io.Reader, getInfo MailUserInfo) (mc *MailContent, err error)

ParseMailMessage dissects an incoming mail message

func ParsePlain

func ParsePlain(ct string, body io.Reader) (mc *MailContent, err error)

ParsePlain disassembles a plain email message.

func ParseSigned

func ParseSigned(ct, addr string, getInfo MailUserInfo, body io.Reader) (mc *MailContent, err error)

ParseSigned reads an unencrypted, but signed message.

type MailUserInfo

type MailUserInfo func(key int, data string) interface{}

MailUserInfo is a callback function to request user information:

type Mapping added in v1.2.2

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

Mapping of an "external" port to "internal" port for a network protocol. The IP addresses (external, internal) are the same for all mappings

type POP3Session

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

POP3Session data structure

func POP3Connect

func POP3Connect(service, proxy string) (sess *POP3Session, err error)

POP3Connect establishes a session with POP3 mailbox.

  • The connections to the service can be either plain (port 110) or SSL/TLS (port 995)

  • If the server supports STARTTLS and the channel is not already encrypted (via SSL), the application will use the "STLS" command to initiate a channel encryption.

- Connections can be tunneled through any SOCKS5 proxy (like Tor)

func (*POP3Session) Close

func (sess *POP3Session) Close() (err error)

Close a POP3 session with the server.

func (*POP3Session) Delete

func (sess *POP3Session) Delete(id int) error

Delete message# <id> from the server.

func (*POP3Session) Exec

func (sess *POP3Session) Exec(cmd string, expectData bool) ([]string, error)

Exec executes a command on the POP3 server: Expected data is assumed to be terminated by a line containing a single dot.

func (*POP3Session) ListUnread

func (sess *POP3Session) ListUnread() (list []int, err error)

ListUnread returns a list of unread messages.

func (*POP3Session) Retrieve

func (sess *POP3Session) Retrieve(id int) ([]string, error)

Retrieve message# <id> from the server.

type PortMapper added in v1.2.2

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

PortMapper implements a mapping between an external (globally visible) service address (ip:port) to an internal address.

func NewPortMapper added in v1.2.2

func NewPortMapper(name string) (*PortMapper, error)

NewPortMapper instaniates a new port mapping mechanism with given name.

func (*PortMapper) Assign added in v1.2.2

func (pm *PortMapper) Assign(network string, port int) (string, string, string, error)

Assign a port mapping for a given port and protocol. Returns the mapping identifier, external and internal service addresses and an optional error code.

func (*PortMapper) Close added in v1.2.2

func (pm *PortMapper) Close() error

Close port mapper

func (*PortMapper) Unassign added in v1.2.2

func (pm *PortMapper) Unassign(id string) error

Unassign removes a port mapping

type RateLimiter added in v1.2.8

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

RateLimiter computes rate limit-compliant delays for requests

func NewRateLimiter added in v1.2.8

func NewRateLimiter(rate ...int) *RateLimiter

NewRateLimiter creates a newly initialitzed rate limiter.

func (*RateLimiter) Pass added in v1.2.8

func (lim *RateLimiter) Pass()

Pass waits for a rate limit-compliant delay before passing a new request

func (*RateLimiter) Stats added in v1.2.8

func (lim *RateLimiter) Stats() (stats *RateStats)

Stats returns current statistics for the rate limiter

type RateStats added in v1.2.8

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

RateStats contains rate statistics

func (*RateStats) Wait added in v1.2.8

func (rs *RateStats) Wait() int

Wait returns the delay (wait time) to be rate-limit compliant

type Service

type Service interface {
	Process(conn net.Conn)          // main handler routine
	GetName() string                // get symbolic name of service
	CanHandle(protocol string) bool // check network protocol
	IsAllowed(remote string) bool   // check remote address
}

Service is a user-defined service handler that handles TCP/UDP client sessions. The interface defines four methods:

- Process (conn): Main handler routine for connection

- GetName(): Return service name (for logging output)

  • CanHandle (protocol): Check if handler can process given network protocol (TCP or UDP on IPv4 or IPv6)

  • IsAllowed (addr): Checkk if remote address is allowed to be served by the service handler.

Directories

Path Synopsis
tor

Jump to

Keyboard shortcuts

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