Documentation ¶
Index ¶
- Constants
- Variables
- func CreateMailMessage(body []byte, att []*MailAttachment) (msg []byte, err error)
- func EncryptMailMessage(key, body []byte) (cipher []byte, err error)
- func RecvData(conn net.Conn, data []byte, srv string) (int, bool)
- func RunService(network, addr string, hdlr []Service) error
- func SendData(conn net.Conn, data []byte, srv string) bool
- func SendMailMessage(host, proxy, fromAddr, toAddr string, body []byte) (err error)
- func Socks5Connect(proto string, addr string, port int, proxy string) (net.Conn, error)
- func Socks5ConnectTimeout(proto string, addr string, port int, proxy string, timeout time.Duration) (conn net.Conn, err error)
- func SplitNetworkEndpoint(networkendp string) (network string, endp string, err error)
- type MailAttachment
- type MailContent
- func ParseEncrypted(ct, addr string, getInfo MailUserInfo, body io.Reader) (mc *MailContent, err error)
- func ParseMailMessage(msg io.Reader, getInfo MailUserInfo) (mc *MailContent, err error)
- func ParsePlain(ct string, body io.Reader) (mc *MailContent, err error)
- func ParseSigned(ct, addr string, getInfo MailUserInfo, body io.Reader) (mc *MailContent, err error)
- type MailUserInfo
- type Mapping
- type POP3Session
- type PortMapper
- type RateLimiter
- type RateStats
- type Service
Constants ¶
const ( PmNONE = iota PmDIRECT PmUPNP PmSTUN )
Port mapping modes
Variables ¶
var ( ErrNetInvalidEndpoint = errors.New("invalid endpoint") ErrNetInvalidNetwork = errors.New("invalid network") )
Error codes
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
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 ¶
EncryptMailMessage encrypts a mail with given public key.
func RunService ¶
RunService runs a TCP/UDP network service with user-defined session handler.
func SendMailMessage ¶
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 ¶
Socks5Connect connects to a SOCKS5 proxy.
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 ¶
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.
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
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) 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
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.