Documentation ¶
Index ¶
- Constants
- Variables
- func NewClient(conn net.Conn, clientID uint64, logger log.Logger, envelope *mail.Pool) *client
- type AppConfig
- type ClientState
- type Daemon
- func (d *Daemon) AddProcessor(name string, pc backends.ProcessorConstructor)
- func (d *Daemon) LoadConfig(path string) (AppConfig, error)
- func (d *Daemon) Log() log.Logger
- func (d *Daemon) Publish(topic Event, args ...interface{})
- func (d *Daemon) ReloadConfig(c AppConfig) error
- func (d *Daemon) ReloadConfigFile(path string) error
- func (d *Daemon) ReopenLogs() error
- func (d *Daemon) SetConfig(c AppConfig) error
- func (d *Daemon) Shutdown()
- func (d *Daemon) Start() (err error)
- func (d *Daemon) Subscribe(topic Event, fn interface{}) error
- func (d *Daemon) Unsubscribe(topic Event, handler interface{}) error
- type Errors
- type Event
- type EventHandler
- type Guerrilla
- type Pool
- func (p *Pool) Borrow(conn net.Conn, clientID uint64, logger log.Logger, ep *mail.Pool) (Poolable, error)
- func (p *Pool) GetActiveClientsCount() int
- func (p *Pool) IsShuttingDown() bool
- func (p *Pool) Return(c Poolable)
- func (p *Pool) SetTimeout(duration time.Duration)
- func (p *Pool) ShutdownState()
- func (p *Pool) ShutdownWait()
- func (p *Pool) Start()
- type Poolable
- type ServerConfig
Constants ¶
const ( // The client has connected, and is awaiting our first response ClientGreeting = iota // We have responded to the client's connection and are awaiting a command ClientCmd // We have received the sender and recipient information ClientData // We have agreed with the client to secure the connection over TLS ClientStartTLS // Server will shutdown, client to shutdown on next command turn ClientShutdown )
const ( // server has just been created GuerrillaStateNew = iota // Server has been started and is running GuerrillaStateStarted // Server has just been stopped GuerrillaStateStopped )
const ( CommandVerbMaxLength = 16 CommandLineMaxLength = 1024 // Number of allowed unrecognized commands before we terminate the connection MaxUnrecognizedCommands = 5 // The maximum total length of a reverse-path or forward-path is 256 RFC2821LimitPath = 256 // The maximum total length of a user name or other local-part is 64 RFC2832LimitLocalPart = 64 //The maximum total length of a domain name or number is 255 RFC2821LimitDomain = 255 // The minimum total number of recipients that must be buffered is 100 RFC2821LimitRecipients = 100 )
const ( // server has just been created ServerStateNew = iota // Server has just been stopped ServerStateStopped // Server has been started and is running ServerStateRunning // Server could not start due to an error ServerStateStartError )
Variables ¶
var ( LineLimitExceeded = errors.New("Maximum line length exceeded") MessageSizeExceeded = errors.New("Maximum message size exceeded") )
var ( Version string Commit string BuildTime string StartTime time.Time ConfigLoadTime time.Time )
var (
ErrPoolShuttingDown = errors.New("server pool: shutting down")
)
Functions ¶
Types ¶
type AppConfig ¶
type AppConfig struct { // Servers can have one or more items. /// Defaults to 1 server listening on 127.0.0.1:2525 Servers []ServerConfig `json:"servers"` // AllowedHosts lists which hosts to accept email for. Defaults to os.Hostname AllowedHosts []string `json:"allowed_hosts"` // PidFile is the path for writing out the process id. No output if empty PidFile string `json:"pid_file"` // LogFile is where the logs go. Use path to file, or "stderr", "stdout" // or "off". Default "stderr" LogFile string `json:"log_file,omitempty"` // LogLevel controls the lowest level we log. // "info", "debug", "error", "panic". Default "info" LogLevel string `json:"log_level,omitempty"` // BackendConfig configures the email envelope processing backend BackendConfig backends.BackendConfig `json:"backend_config"` }
AppConfig is the holder of the configuration of the app
func (*AppConfig) EmitChangeEvents ¶
Emits any configuration change events onto the event bus.
func (*AppConfig) EmitLogReopenEvents ¶
EmitLogReopen emits log reopen events using existing config
type ClientState ¶
type ClientState int
ClientState indicates which part of the SMTP transaction a given client is in.
type Daemon ¶
type Daemon struct { Config *AppConfig Logger log.Logger Backend backends.Backend // contains filtered or unexported fields }
Daemon provides a convenient API when using go-guerrilla as a package in your Go project. Is's facade for Guerrilla, AppConfig, backends.Backend and log.Logger
func (*Daemon) AddProcessor ¶
func (d *Daemon) AddProcessor(name string, pc backends.ProcessorConstructor)
AddProcessor adds a processor constructor to the backend. name is the identifier to be used in the config. See backends docs for more info.
func (*Daemon) LoadConfig ¶
LoadConfig reads in the config from a JSON file. Note: if d.Config is nil, the sets d.Config with the unmarshalled AppConfig which will be returned
func (*Daemon) Log ¶
log returns a logger that implements our log.Logger interface. level is set to "info" by default
func (*Daemon) ReloadConfig ¶
Reload a config using the passed in AppConfig and emit config change events
func (*Daemon) ReloadConfigFile ¶
Reload a config from a file and emit config change events
func (*Daemon) ReopenLogs ¶
ReopenLogs send events to re-opens all log files. Typically, one would call this after rotating logs
func (*Daemon) SetConfig ¶
SetConfig is same as LoadConfig, except you can pass AppConfig directly does not emit any change events, instead use ReloadConfig after daemon has started
func (*Daemon) Shutdown ¶
func (d *Daemon) Shutdown()
Shuts down the daemon, including servers and backend. Do not call Start on it again, use a new server.
func (*Daemon) Start ¶
Starts the daemon, initializing d.Config, d.Logger and d.Backend with defaults can only be called once through the lifetime of the program
func (*Daemon) Unsubscribe ¶
for unsubscribing from config change events
type Event ¶
type Event int
const ( // when a new config was loaded EventConfigNewConfig Event = iota // when allowed_hosts changed EventConfigAllowedHosts // when pid_file changed EventConfigPidFile // when log_file changed EventConfigLogFile // when it's time to reload the main log file EventConfigLogReopen // when log level changed EventConfigLogLevel // when the backend's config changed EventConfigBackendConfig // when a new server was added EventConfigServerNew // when an existing server was removed EventConfigServerRemove // when a new server config was detected (general event) EventConfigServerConfig // when a server was enabled EventConfigServerStart // when a server was disabled EventConfigServerStop // when a server's log file changed EventConfigServerLogFile // when it's time to reload the server's log EventConfigServerLogReopen // when a server's timeout changed EventConfigServerTimeout // when a server's max clients changed EventConfigServerMaxClients // when a server's TLS config changed EventConfigServerTLSConfig )
type EventHandler ¶
func (*EventHandler) Publish ¶
func (h *EventHandler) Publish(topic Event, args ...interface{})
func (*EventHandler) Subscribe ¶
func (h *EventHandler) Subscribe(topic Event, fn interface{}) error
func (*EventHandler) Unsubscribe ¶
func (h *EventHandler) Unsubscribe(topic Event, handler interface{}) error
type Guerrilla ¶
type Pool ¶
type Pool struct { ShutdownChan chan int // contains filtered or unexported fields }
Pool holds Clients.
func (*Pool) Borrow ¶
func (p *Pool) Borrow(conn net.Conn, clientID uint64, logger log.Logger, ep *mail.Pool) (Poolable, error)
Borrow a Client from the pool. Will block if len(activeClients) > maxClients
func (*Pool) GetActiveClientsCount ¶
Gets the number of active clients that are currently out of the pool and busy serving
func (*Pool) IsShuttingDown ¶
returns true if the pool is shutting down
func (*Pool) SetTimeout ¶
set a timeout for all lent clients
func (*Pool) ShutdownState ¶
func (p *Pool) ShutdownState()
Lock the pool from borrowing then remove all active clients each active client's timeout is lowered to 1 sec and notified to stop accepting commands
func (*Pool) ShutdownWait ¶
func (p *Pool) ShutdownWait()
type Poolable ¶
type Poolable interface {
// contains filtered or unexported methods
}
a struct can be pooled if it has the following interface
type ServerConfig ¶
type ServerConfig struct { // IsEnabled set to true to start the server, false will ignore it IsEnabled bool `json:"is_enabled"` // Hostname will be used in the server's reply to HELO/EHLO. If TLS enabled // make sure that the Hostname matches the cert. Defaults to os.Hostname() Hostname string `json:"host_name"` // MaxSize is the maximum size of an email that will be accepted for delivery. // Defaults to 10 Mebibytes MaxSize int64 `json:"max_size"` // PrivateKeyFile path to cert private key in PEM format. Will be ignored if blank PrivateKeyFile string `json:"private_key_file"` // PublicKeyFile path to cert (public key) chain in PEM format. // Will be ignored if blank PublicKeyFile string `json:"public_key_file"` // Timeout specifies the connection timeout in seconds. Defaults to 30 Timeout int `json:"timeout"` // Listen interface specified in <ip>:<port> - defaults to 127.0.0.1:2525 ListenInterface string `json:"listen_interface"` // StartTLSOn should we offer STARTTLS command. Cert must be valid. // False by default StartTLSOn bool `json:"start_tls_on,omitempty"` // TLSAlwaysOn run this server as a pure TLS server, i.e. SMTPS TLSAlwaysOn bool `json:"tls_always_on,omitempty"` // MaxClients controls how many maxiumum clients we can handle at once. // Defaults to 100 MaxClients int `json:"max_clients"` // LogFile is where the logs go. Use path to file, or "stderr", "stdout" or "off". // defaults to AppConfig.Log file setting LogFile string `json:"log_file,omitempty"` // XClientOn when using a proxy such as Nginx, XCLIENT command is used to pass the // original client's IP address & client's HELO XClientOn bool `json:"xclient_on,omitempty"` // contains filtered or unexported fields }
ServerConfig specifies config options for a single server
func (*ServerConfig) Validate ¶
func (sc *ServerConfig) Validate() error
Validate validates the server's configuration.