Code clean up
This commit is contained in:
@@ -33,7 +33,7 @@ const (
|
|||||||
// Errors
|
// Errors
|
||||||
var (
|
var (
|
||||||
ErrCommandRunUndefinedCommand = errors.New(
|
ErrCommandRunUndefinedCommand = errors.New(
|
||||||
"Undefined Command")
|
"undefined Command")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Command represents a command handler machine builder
|
// Command represents a command handler machine builder
|
||||||
|
|||||||
@@ -31,13 +31,13 @@ import (
|
|||||||
// Errors
|
// Errors
|
||||||
var (
|
var (
|
||||||
ErrHandlerUnknownHeaderType = errors.New(
|
ErrHandlerUnknownHeaderType = errors.New(
|
||||||
"Unknown command header type")
|
"unknown command header type")
|
||||||
|
|
||||||
ErrHandlerControlMessageTooLong = errors.New(
|
ErrHandlerControlMessageTooLong = errors.New(
|
||||||
"Control message was too long")
|
"control message was too long")
|
||||||
|
|
||||||
ErrHandlerInvalidControlMessage = errors.New(
|
ErrHandlerInvalidControlMessage = errors.New(
|
||||||
"Invalid control message")
|
"invalid control message")
|
||||||
)
|
)
|
||||||
|
|
||||||
// HandlerCancelSignal signals the cancel of the entire handling proccess
|
// HandlerCancelSignal signals the cancel of the entire handling proccess
|
||||||
@@ -113,11 +113,6 @@ type streamHandlerSender struct {
|
|||||||
sendDelay time.Duration
|
sendDelay time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
// signal sends handler signal
|
|
||||||
func (h streamHandlerSender) signal(hd Header, d []byte, buf []byte) error {
|
|
||||||
return h.handlerSender.signal(hd, d, buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Write sends data
|
// Write sends data
|
||||||
func (h streamHandlerSender) Write(b []byte) (int, error) {
|
func (h streamHandlerSender) Write(b []byte) (int, error) {
|
||||||
defer time.Sleep(h.sendDelay)
|
defer time.Sleep(h.sendDelay)
|
||||||
|
|||||||
@@ -28,16 +28,16 @@ import (
|
|||||||
// Errors
|
// Errors
|
||||||
var (
|
var (
|
||||||
ErrStreamsInvalidStreamID = errors.New(
|
ErrStreamsInvalidStreamID = errors.New(
|
||||||
"Stream ID is invalid")
|
"stream ID is invalid")
|
||||||
|
|
||||||
ErrStreamsStreamOperateInactiveStream = errors.New(
|
ErrStreamsStreamOperateInactiveStream = errors.New(
|
||||||
"Specified stream was inactive for operation")
|
"specified stream was inactive for operation")
|
||||||
|
|
||||||
ErrStreamsStreamClosingInactiveStream = errors.New(
|
ErrStreamsStreamClosingInactiveStream = errors.New(
|
||||||
"Closing an inactive stream is not allowed")
|
"closing an inactive stream is not allowed")
|
||||||
|
|
||||||
ErrStreamsStreamReleasingInactiveStream = errors.New(
|
ErrStreamsStreamReleasingInactiveStream = errors.New(
|
||||||
"Releasing an inactive stream is not allowed")
|
"releasing an inactive stream is not allowed")
|
||||||
)
|
)
|
||||||
|
|
||||||
// StreamError Stream Error signal
|
// StreamError Stream Error signal
|
||||||
|
|||||||
@@ -28,22 +28,22 @@ import (
|
|||||||
//Errors
|
//Errors
|
||||||
var (
|
var (
|
||||||
ErrAddressParseBufferTooSmallForHeader = errors.New(
|
ErrAddressParseBufferTooSmallForHeader = errors.New(
|
||||||
"Buffer space was too small to parse the address header")
|
"buffer space was too small to parse the address header")
|
||||||
|
|
||||||
ErrAddressParseBufferTooSmallForIPv4 = errors.New(
|
ErrAddressParseBufferTooSmallForIPv4 = errors.New(
|
||||||
"Buffer space was too small to parse the IPv4 address")
|
"buffer space was too small to parse the IPv4 address")
|
||||||
|
|
||||||
ErrAddressParseBufferTooSmallForIPv6 = errors.New(
|
ErrAddressParseBufferTooSmallForIPv6 = errors.New(
|
||||||
"Buffer space was too small to parse the IPv6 address")
|
"buffer space was too small to parse the IPv6 address")
|
||||||
|
|
||||||
ErrAddressParseBufferTooSmallForHostName = errors.New(
|
ErrAddressParseBufferTooSmallForHostName = errors.New(
|
||||||
"Buffer space was too small to parse the hostname address")
|
"buffer space was too small to parse the hostname address")
|
||||||
|
|
||||||
ErrAddressMarshalBufferTooSmall = errors.New(
|
ErrAddressMarshalBufferTooSmall = errors.New(
|
||||||
"Buffer space was too small to marshal the address")
|
"buffer space was too small to marshal the address")
|
||||||
|
|
||||||
ErrAddressInvalidAddressType = errors.New(
|
ErrAddressInvalidAddressType = errors.New(
|
||||||
"Invalid address type")
|
"invalid address type")
|
||||||
)
|
)
|
||||||
|
|
||||||
// AddressType Type of the address
|
// AddressType Type of the address
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ import (
|
|||||||
// Errors
|
// Errors
|
||||||
var (
|
var (
|
||||||
ErrIntegerMarshalNotEnoughBuffer = errors.New(
|
ErrIntegerMarshalNotEnoughBuffer = errors.New(
|
||||||
"Not enough buffer to marshal the integer")
|
"not enough buffer to marshal the integer")
|
||||||
|
|
||||||
ErrIntegerMarshalTooLarge = errors.New(
|
ErrIntegerMarshalTooLarge = errors.New(
|
||||||
"Integer cannot be marshalled, because the vaule was too large")
|
"integer cannot be marshalled, because the vaule was too large")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Integer is a 16bit unsigned integer data
|
// Integer is a 16bit unsigned integer data
|
||||||
|
|||||||
@@ -74,34 +74,34 @@ type sshAuthMethodBuilder func(b []byte) []ssh.AuthMethod
|
|||||||
// Errors
|
// Errors
|
||||||
var (
|
var (
|
||||||
ErrSSHAuthCancelled = errors.New(
|
ErrSSHAuthCancelled = errors.New(
|
||||||
"Authentication has been cancelled")
|
"authentication has been cancelled")
|
||||||
|
|
||||||
ErrSSHInvalidAuthMethod = errors.New(
|
ErrSSHInvalidAuthMethod = errors.New(
|
||||||
"Invalid auth method")
|
"invalid auth method")
|
||||||
|
|
||||||
ErrSSHInvalidAddress = errors.New(
|
ErrSSHInvalidAddress = errors.New(
|
||||||
"Invalid address")
|
"invalid address")
|
||||||
|
|
||||||
ErrSSHRemoteFingerprintVerificationCancelled = errors.New(
|
ErrSSHRemoteFingerprintVerificationCancelled = errors.New(
|
||||||
"Server Fingerprint verification process has been cancelled")
|
"server Fingerprint verification process has been cancelled")
|
||||||
|
|
||||||
ErrSSHRemoteFingerprintRefused = errors.New(
|
ErrSSHRemoteFingerprintRefused = errors.New(
|
||||||
"Server Fingerprint has been refused")
|
"server Fingerprint has been refused")
|
||||||
|
|
||||||
ErrSSHRemoteConnUnavailable = errors.New(
|
ErrSSHRemoteConnUnavailable = errors.New(
|
||||||
"Remote SSH connection is unavailable")
|
"remote SSH connection is unavailable")
|
||||||
|
|
||||||
ErrSSHUnexpectedFingerprintVerificationRespond = errors.New(
|
ErrSSHUnexpectedFingerprintVerificationRespond = errors.New(
|
||||||
"Unexpected fingerprint verification respond")
|
"unexpected fingerprint verification respond")
|
||||||
|
|
||||||
ErrSSHUnexpectedCredentialDataRespond = errors.New(
|
ErrSSHUnexpectedCredentialDataRespond = errors.New(
|
||||||
"Unexpected credential data respond")
|
"unexpected credential data respond")
|
||||||
|
|
||||||
ErrSSHCredentialDataTooLarge = errors.New(
|
ErrSSHCredentialDataTooLarge = errors.New(
|
||||||
"Credential was too large")
|
"credential was too large")
|
||||||
|
|
||||||
ErrSSHUnknownClientSignal = errors.New(
|
ErrSSHUnknownClientSignal = errors.New(
|
||||||
"Unknown client signal")
|
"unknown client signal")
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ import (
|
|||||||
// Errors
|
// Errors
|
||||||
var (
|
var (
|
||||||
ErrStringParseBufferTooSmall = errors.New(
|
ErrStringParseBufferTooSmall = errors.New(
|
||||||
"Not enough buffer space to parse given string")
|
"not enough buffer space to parse given string")
|
||||||
|
|
||||||
ErrStringMarshalBufferTooSmall = errors.New(
|
ErrStringMarshalBufferTooSmall = errors.New(
|
||||||
"Not enough buffer space to marshal given string")
|
"not enough buffer space to marshal given string")
|
||||||
)
|
)
|
||||||
|
|
||||||
// String data
|
// String data
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import (
|
|||||||
// Errors
|
// Errors
|
||||||
var (
|
var (
|
||||||
ErrTelnetUnableToReceiveRemoteConn = errors.New(
|
ErrTelnetUnableToReceiveRemoteConn = errors.New(
|
||||||
"Unable to acquire remote connection handle")
|
"unable to acquire remote connection handle")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Error codes
|
// Error codes
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ func (s Server) IsTLS() bool {
|
|||||||
// Verify verifies current configuration
|
// Verify verifies current configuration
|
||||||
func (s Server) Verify() error {
|
func (s Server) Verify() error {
|
||||||
if net.ParseIP(s.ListenInterface) == nil {
|
if net.ParseIP(s.ListenInterface) == nil {
|
||||||
return fmt.Errorf("Invalid IP address \"%s\"", s.ListenInterface)
|
return fmt.Errorf("invalid IP address \"%s\"", s.ListenInterface)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len(s.TLSCertificateFile) > 0 && len(s.TLSCertificateKeyFile) <= 0) ||
|
if (len(s.TLSCertificateFile) > 0 && len(s.TLSCertificateKeyFile) <= 0) ||
|
||||||
@@ -132,7 +132,7 @@ func (m Meta) Concretize() (map[string]string, error) {
|
|||||||
result, err := v.Parse()
|
result, err := v.Parse()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Unable to parse Meta \"%s\": %s", k, err)
|
return nil, fmt.Errorf("unable to parse Meta \"%s\": %s", k, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
mm[k] = result
|
mm[k] = result
|
||||||
@@ -175,7 +175,7 @@ type Common struct {
|
|||||||
// Verify verifies current setting
|
// Verify verifies current setting
|
||||||
func (c Configuration) Verify() error {
|
func (c Configuration) Verify() error {
|
||||||
if len(c.Servers) <= 0 {
|
if len(c.Servers) <= 0 {
|
||||||
return errors.New("Must specify at least one server")
|
return errors.New("must specify at least one server")
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, c := range c.Servers {
|
for i, c := range c.Servers {
|
||||||
@@ -185,7 +185,7 @@ func (c Configuration) Verify() error {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("Invalid setting for server %d: %s", i, vErr)
|
return fmt.Errorf("invalid setting for server %d: %s", i, vErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -42,16 +42,6 @@ func parseEnv(name string) string {
|
|||||||
return os.Getenv(v[21:])
|
return os.Getenv(v[21:])
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseEnvDef(name string, def string) string {
|
|
||||||
v := parseEnv(name)
|
|
||||||
|
|
||||||
if len(v) > 0 {
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
return def
|
|
||||||
}
|
|
||||||
|
|
||||||
// Enviro creates an environment variable based configuration loader
|
// Enviro creates an environment variable based configuration loader
|
||||||
func Enviro() Loader {
|
func Enviro() Loader {
|
||||||
return func(log log.Logger) (string, Configuration, error) {
|
return func(log log.Logger) (string, Configuration, error) {
|
||||||
@@ -75,7 +65,7 @@ func Enviro() Loader {
|
|||||||
|
|
||||||
if cfgErr != nil {
|
if cfgErr != nil {
|
||||||
return enviroTypeName, Configuration{}, fmt.Errorf(
|
return enviroTypeName, Configuration{}, fmt.Errorf(
|
||||||
"Failed to build the configuration: %s", cfgErr)
|
"failed to build the configuration: %s", cfgErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
listenIface := parseEnv("SSHWIFTY_LISTENINTERFACE")
|
listenIface := parseEnv("SSHWIFTY_LISTENINTERFACE")
|
||||||
@@ -122,7 +112,7 @@ func Enviro() Loader {
|
|||||||
|
|
||||||
if jErr != nil {
|
if jErr != nil {
|
||||||
return enviroTypeName, Configuration{}, fmt.Errorf(
|
return enviroTypeName, Configuration{}, fmt.Errorf(
|
||||||
"Invalid \"SSHWIFTY_PRESETS\": %s", jErr)
|
"invalid \"SSHWIFTY_PRESETS\": %s", jErr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,7 +120,7 @@ func Enviro() Loader {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return enviroTypeName, Configuration{}, fmt.Errorf(
|
return enviroTypeName, Configuration{}, fmt.Errorf(
|
||||||
"Unable to parse Preset data: %s", err)
|
"unable to parse Preset data: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return enviroTypeName, Configuration{
|
return enviroTypeName, Configuration{
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ func (f fileCfgPresets) concretize() ([]Preset, error) {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf(
|
return nil, fmt.Errorf(
|
||||||
"Unable to concretize Preset %d (titled \"%s\"): %s",
|
"unable to concretize Preset %d (titled \"%s\"): %s",
|
||||||
i+1, p.Title, err)
|
i+1, p.Title, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,6 @@ func Redundant(loaders ...Loader) Loader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return redundantTypeName, Configuration{}, fmt.Errorf(
|
return redundantTypeName, Configuration{}, fmt.Errorf(
|
||||||
"All existing redundant loader has failed")
|
"all existing redundant loader has failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func (s String) Parse() (string, error) {
|
|||||||
f, e := os.Open(fPath)
|
f, e := os.Open(fPath)
|
||||||
|
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return "", fmt.Errorf("Unable to open %s: %s", fPath, e)
|
return "", fmt.Errorf("unable to open %s: %s", fPath, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
@@ -59,7 +59,7 @@ func (s String) Parse() (string, error) {
|
|||||||
fData, e := ioutil.ReadAll(f)
|
fData, e := ioutil.ReadAll(f)
|
||||||
|
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return "", fmt.Errorf("Unable to read from %s: %s", fPath, e)
|
return "", fmt.Errorf("unable to read from %s: %s", fPath, e)
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(fData), nil
|
return string(fData), nil
|
||||||
@@ -74,6 +74,6 @@ func (s String) Parse() (string, error) {
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
return "", fmt.Errorf(
|
return "", fmt.Errorf(
|
||||||
"Scheme \"%s\" was unsupported", ss[:sSchemeLeadIdx])
|
"scheme \"%s\" was unsupported", ss[:sSchemeLeadIdx])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ func TestStringFile(t *testing.T) {
|
|||||||
|
|
||||||
ss = String("file://" + filePath + ".notexist")
|
ss = String("file://" + filePath + ".notexist")
|
||||||
|
|
||||||
result, err = ss.Parse()
|
_, err = ss.Parse()
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("Parsing an non-existing file should result an error")
|
t.Error("Parsing an non-existing file should result an error")
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ import (
|
|||||||
// Errors
|
// Errors
|
||||||
var (
|
var (
|
||||||
ErrAccessControlDialTargetHostNotAllowed = errors.New(
|
ErrAccessControlDialTargetHostNotAllowed = errors.New(
|
||||||
"Unable to dial to the specified remote host due to restriction")
|
"unable to dial to the specified remote host due to restriction")
|
||||||
)
|
)
|
||||||
|
|
||||||
// AllowedHosts contains a map of allowed remote hosts
|
// AllowedHosts contains a map of allowed remote hosts
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import "errors"
|
|||||||
// Errors
|
// Errors
|
||||||
var (
|
var (
|
||||||
ErrFetchReaderNotEnoughBuffer = errors.New(
|
ErrFetchReaderNotEnoughBuffer = errors.New(
|
||||||
"Not enough buffer")
|
"not enough buffer")
|
||||||
)
|
)
|
||||||
|
|
||||||
// FetchReaderFetcher generates data for SourceReader
|
// FetchReaderFetcher generates data for SourceReader
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
// Errors
|
// Errors
|
||||||
var (
|
var (
|
||||||
ErrReadUntilCompletedBufferFull = errors.New(
|
ErrReadUntilCompletedBufferFull = errors.New(
|
||||||
"Cannot read more, not enough data buffer")
|
"cannot read more, not enough data buffer")
|
||||||
)
|
)
|
||||||
|
|
||||||
// LimitedReader reads only n bytes of data
|
// LimitedReader reads only n bytes of data
|
||||||
|
|||||||
@@ -24,10 +24,6 @@ import (
|
|||||||
"github.com/nirui/sshwifty/application/network"
|
"github.com/nirui/sshwifty/application/network"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
emptyTime = time.Time{}
|
|
||||||
)
|
|
||||||
|
|
||||||
type listener struct {
|
type listener struct {
|
||||||
*net.TCPListener
|
*net.TCPListener
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ func (d dumpWrite) Write(b []byte) (int, error) {
|
|||||||
// Errors
|
// Errors
|
||||||
var (
|
var (
|
||||||
ErrInvalidIPAddress = errors.New(
|
ErrInvalidIPAddress = errors.New(
|
||||||
"Invalid IP address")
|
"invalid IP address")
|
||||||
)
|
)
|
||||||
|
|
||||||
// HandlerBuilder builds a HTTP handler
|
// HandlerBuilder builds a HTTP handler
|
||||||
@@ -60,7 +60,6 @@ type CloseCallback func(error)
|
|||||||
// Server represents a server
|
// Server represents a server
|
||||||
type Server struct {
|
type Server struct {
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
cfg configuration.Common
|
|
||||||
shutdownWait *sync.WaitGroup
|
shutdownWait *sync.WaitGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user