Skip to content

Commit

Permalink
Code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
NI committed Apr 15, 2022
1 parent 0c3c495 commit f884d7c
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 66 deletions.
2 changes: 1 addition & 1 deletion application/command/commands.go
Expand Up @@ -33,7 +33,7 @@ const (
// Errors
var (
ErrCommandRunUndefinedCommand = errors.New(
"Undefined Command")
"undefined Command")
)

// Command represents a command handler machine builder
Expand Down
11 changes: 3 additions & 8 deletions application/command/handler.go
Expand Up @@ -31,13 +31,13 @@ import (
// Errors
var (
ErrHandlerUnknownHeaderType = errors.New(
"Unknown command header type")
"unknown command header type")

ErrHandlerControlMessageTooLong = errors.New(
"Control message was too long")
"control message was too long")

ErrHandlerInvalidControlMessage = errors.New(
"Invalid control message")
"invalid control message")
)

// HandlerCancelSignal signals the cancel of the entire handling proccess
Expand Down Expand Up @@ -113,11 +113,6 @@ type streamHandlerSender struct {
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
func (h streamHandlerSender) Write(b []byte) (int, error) {
defer time.Sleep(h.sendDelay)
Expand Down
8 changes: 4 additions & 4 deletions application/command/streams.go
Expand Up @@ -28,16 +28,16 @@ import (
// Errors
var (
ErrStreamsInvalidStreamID = errors.New(
"Stream ID is invalid")
"stream ID is invalid")

ErrStreamsStreamOperateInactiveStream = errors.New(
"Specified stream was inactive for operation")
"specified stream was inactive for operation")

ErrStreamsStreamClosingInactiveStream = errors.New(
"Closing an inactive stream is not allowed")
"closing an inactive stream is not allowed")

ErrStreamsStreamReleasingInactiveStream = errors.New(
"Releasing an inactive stream is not allowed")
"releasing an inactive stream is not allowed")
)

// StreamError Stream Error signal
Expand Down
12 changes: 6 additions & 6 deletions application/commands/address.go
Expand Up @@ -28,22 +28,22 @@ import (
//Errors
var (
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(
"Buffer space was too small to parse the IPv4 address")
"buffer space was too small to parse the IPv4 address")

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(
"Buffer space was too small to parse the hostname address")
"buffer space was too small to parse the hostname address")

ErrAddressMarshalBufferTooSmall = errors.New(
"Buffer space was too small to marshal the address")
"buffer space was too small to marshal the address")

ErrAddressInvalidAddressType = errors.New(
"Invalid address type")
"invalid address type")
)

// AddressType Type of the address
Expand Down
4 changes: 2 additions & 2 deletions application/commands/integer.go
Expand Up @@ -26,10 +26,10 @@ import (
// Errors
var (
ErrIntegerMarshalNotEnoughBuffer = errors.New(
"Not enough buffer to marshal the integer")
"not enough buffer to marshal the integer")

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
Expand Down
20 changes: 10 additions & 10 deletions application/commands/ssh.go
Expand Up @@ -74,34 +74,34 @@ type sshAuthMethodBuilder func(b []byte) []ssh.AuthMethod
// Errors
var (
ErrSSHAuthCancelled = errors.New(
"Authentication has been cancelled")
"authentication has been cancelled")

ErrSSHInvalidAuthMethod = errors.New(
"Invalid auth method")
"invalid auth method")

ErrSSHInvalidAddress = errors.New(
"Invalid address")
"invalid address")

ErrSSHRemoteFingerprintVerificationCancelled = errors.New(
"Server Fingerprint verification process has been cancelled")
"server Fingerprint verification process has been cancelled")

ErrSSHRemoteFingerprintRefused = errors.New(
"Server Fingerprint has been refused")
"server Fingerprint has been refused")

ErrSSHRemoteConnUnavailable = errors.New(
"Remote SSH connection is unavailable")
"remote SSH connection is unavailable")

ErrSSHUnexpectedFingerprintVerificationRespond = errors.New(
"Unexpected fingerprint verification respond")
"unexpected fingerprint verification respond")

ErrSSHUnexpectedCredentialDataRespond = errors.New(
"Unexpected credential data respond")
"unexpected credential data respond")

ErrSSHCredentialDataTooLarge = errors.New(
"Credential was too large")
"credential was too large")

ErrSSHUnknownClientSignal = errors.New(
"Unknown client signal")
"unknown client signal")
)

var (
Expand Down
4 changes: 2 additions & 2 deletions application/commands/string.go
Expand Up @@ -26,10 +26,10 @@ import (
// Errors
var (
ErrStringParseBufferTooSmall = errors.New(
"Not enough buffer space to parse given string")
"not enough buffer space to parse given string")

ErrStringMarshalBufferTooSmall = errors.New(
"Not enough buffer space to marshal given string")
"not enough buffer space to marshal given string")
)

// String data
Expand Down
2 changes: 1 addition & 1 deletion application/commands/telnet.go
Expand Up @@ -33,7 +33,7 @@ import (
// Errors
var (
ErrTelnetUnableToReceiveRemoteConn = errors.New(
"Unable to acquire remote connection handle")
"unable to acquire remote connection handle")
)

// Error codes
Expand Down
8 changes: 4 additions & 4 deletions application/configuration/config.go
Expand Up @@ -108,7 +108,7 @@ func (s Server) IsTLS() bool {
// Verify verifies current configuration
func (s Server) Verify() error {
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) ||
Expand All @@ -132,7 +132,7 @@ func (m Meta) Concretize() (map[string]string, error) {
result, err := v.Parse()

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
Expand Down Expand Up @@ -175,7 +175,7 @@ type Common struct {
// Verify verifies current setting
func (c Configuration) Verify() error {
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 {
Expand All @@ -185,7 +185,7 @@ func (c Configuration) Verify() error {
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
Expand Down
16 changes: 3 additions & 13 deletions application/configuration/loader_enviro.go
Expand Up @@ -42,16 +42,6 @@ func parseEnv(name string) string {
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
func Enviro() Loader {
return func(log log.Logger) (string, Configuration, error) {
Expand All @@ -75,7 +65,7 @@ func Enviro() Loader {

if cfgErr != nil {
return enviroTypeName, Configuration{}, fmt.Errorf(
"Failed to build the configuration: %s", cfgErr)
"failed to build the configuration: %s", cfgErr)
}

listenIface := parseEnv("SSHWIFTY_LISTENINTERFACE")
Expand Down Expand Up @@ -122,15 +112,15 @@ func Enviro() Loader {

if jErr != nil {
return enviroTypeName, Configuration{}, fmt.Errorf(
"Invalid \"SSHWIFTY_PRESETS\": %s", jErr)
"invalid \"SSHWIFTY_PRESETS\": %s", jErr)
}
}

concretizePresets, err := presets.concretize()

if err != nil {
return enviroTypeName, Configuration{}, fmt.Errorf(
"Unable to parse Preset data: %s", err)
"unable to parse Preset data: %s", err)
}

return enviroTypeName, Configuration{
Expand Down
2 changes: 1 addition & 1 deletion application/configuration/loader_file.go
Expand Up @@ -106,7 +106,7 @@ func (f fileCfgPresets) concretize() ([]Preset, error) {

if err != nil {
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)
}

Expand Down
2 changes: 1 addition & 1 deletion application/configuration/loader_redundant.go
Expand Up @@ -47,6 +47,6 @@ func Redundant(loaders ...Loader) Loader {
}

return redundantTypeName, Configuration{}, fmt.Errorf(
"All existing redundant loader has failed")
"all existing redundant loader has failed")
}
}
6 changes: 3 additions & 3 deletions application/configuration/string.go
Expand Up @@ -51,15 +51,15 @@ func (s String) Parse() (string, error) {
f, e := os.Open(fPath)

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()

fData, e := ioutil.ReadAll(f)

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
Expand All @@ -74,6 +74,6 @@ func (s String) Parse() (string, error) {

default:
return "", fmt.Errorf(
"Scheme \"%s\" was unsupported", ss[:sSchemeLeadIdx])
"scheme \"%s\" was unsupported", ss[:sSchemeLeadIdx])
}
}
2 changes: 1 addition & 1 deletion application/configuration/string_test.go
Expand Up @@ -84,7 +84,7 @@ func TestStringFile(t *testing.T) {

ss = String("file://" + filePath + ".notexist")

result, err = ss.Parse()
_, err = ss.Parse()

if err == nil {
t.Error("Parsing an non-existing file should result an error")
Expand Down
2 changes: 1 addition & 1 deletion application/network/dial_ac.go
Expand Up @@ -26,7 +26,7 @@ import (
// Errors
var (
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
Expand Down
2 changes: 1 addition & 1 deletion application/rw/fetch.go
Expand Up @@ -22,7 +22,7 @@ import "errors"
// Errors
var (
ErrFetchReaderNotEnoughBuffer = errors.New(
"Not enough buffer")
"not enough buffer")
)

// FetchReaderFetcher generates data for SourceReader
Expand Down
2 changes: 1 addition & 1 deletion application/rw/limited.go
Expand Up @@ -25,7 +25,7 @@ import (
// Errors
var (
ErrReadUntilCompletedBufferFull = errors.New(
"Cannot read more, not enough data buffer")
"cannot read more, not enough data buffer")
)

// LimitedReader reads only n bytes of data
Expand Down
4 changes: 0 additions & 4 deletions application/server/conn.go
Expand Up @@ -24,10 +24,6 @@ import (
"github.com/nirui/sshwifty/application/network"
)

var (
emptyTime = time.Time{}
)

type listener struct {
*net.TCPListener

Expand Down
3 changes: 1 addition & 2 deletions application/server/server.go
Expand Up @@ -42,7 +42,7 @@ func (d dumpWrite) Write(b []byte) (int, error) {
// Errors
var (
ErrInvalidIPAddress = errors.New(
"Invalid IP address")
"invalid IP address")
)

// HandlerBuilder builds a HTTP handler
Expand All @@ -60,7 +60,6 @@ type CloseCallback func(error)
// Server represents a server
type Server struct {
logger log.Logger
cfg configuration.Common
shutdownWait *sync.WaitGroup
}

Expand Down

0 comments on commit f884d7c

Please sign in to comment.