network

package
v2.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2022 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PmNONE = iota
	PmDIRECT
	PmUPNP
	PmSTUN
)

Port mapping modes

Variables

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

Functions

func CreateMailMessage

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

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

func EncryptMailMessage

func EncryptMailMessage(key, body []byte) ([]byte, 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) 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) (net.Conn, error)

Socks5ConnectTimeout connects to a SOCKS5 proxy with timeout.

func SplitNetworkEndpoint

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) (*MailContent, error)

ParseEncrypted parses a encrypted (and possibly signed) message.

func ParseMailMessage

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

ParseMailMessage dissects an incoming mail message

func ParsePlain

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

ParsePlain disassembles a plain email message.

func ParseSigned

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

ParseSigned reads an unencrypted, but signed message.

type MailUserInfo

type MailUserInfo func(key int, data string) any

MailUserInfo is a callback function to request user information:

type Mapping

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) (*POP3Session, 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()

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() ([]int, 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

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

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

NewPortMapper instaniates a new port mapping mechanism with given name.

func (*PortMapper) Assign

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

func (pm *PortMapper) Close() error

Close port mapper

func (*PortMapper) Unassign

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

Unassign removes a port mapping

type RateLimiter

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

RateLimiter computes rate limit-compliant delays for requests

func NewRateLimiter

func NewRateLimiter(rate ...int) *RateLimiter

NewRateLimiter creates a newly initialitzed rate limiter.

func (*RateLimiter) Pass

func (lim *RateLimiter) Pass()

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

func (*RateLimiter) Stats

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

Stats returns current statistics for the rate limiter

type RateStats

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

RateStats contains rate statistics

func (*RateStats) Wait

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