Browse Source

Fixing warnings and golint stuff

tags/v0.2.0
Daniel Oaks 7 years ago
parent
commit
e807f3ca04
8 changed files with 25 additions and 13 deletions
  1. 1
    1
      irc/config.go
  2. 4
    2
      irc/constants.go
  3. 1
    0
      irc/isupport.go
  4. 1
    0
      irc/logging.go
  5. 4
    0
      irc/net.go
  6. 8
    4
      irc/password.go
  7. 3
    3
      irc/server.go
  8. 3
    3
      oragono.go

+ 1
- 1
irc/config.go View File

@@ -37,7 +37,7 @@ func (conf *TLSListenConfig) Config() (*tls.Config, error) {
37 37
 }
38 38
 
39 39
 func (conf *PassConfig) PasswordBytes() []byte {
40
-	bytes, err := DecodePassword(conf.Password)
40
+	bytes, err := DecodePasswordHash(conf.Password)
41 41
 	if err != nil {
42 42
 		log.Fatal("decode password error: ", err)
43 43
 	}

+ 4
- 2
irc/constants.go View File

@@ -8,9 +8,11 @@ package irc
8 8
 import "fmt"
9 9
 
10 10
 const (
11
-	SEM_VER = "0.2.0-unreleased"
11
+	// SemVer is the semantic version of Oragono.
12
+	SemVer = "0.2.0-unreleased"
12 13
 )
13 14
 
14 15
 var (
15
-	VER = fmt.Sprintf("oragono-%s", SEM_VER)
16
+	// Ver is the full version of Oragono, used in responses to clients.
17
+	Ver = fmt.Sprintf("oragono-%s", SemVer)
16 18
 )

+ 1
- 0
irc/isupport.go View File

@@ -67,6 +67,7 @@ func (il *ISupportList) RegenerateCachedReply() {
67 67
 	}
68 68
 }
69 69
 
70
+// RplISupport outputs our ISUPPORT lines to the client. This is used on connection and in VERSION responses.
70 71
 func (client *Client) RplISupport() {
71 72
 	for _, tokenline := range client.server.isupport.CachedReply {
72 73
 		// ugly trickery ahead

+ 1
- 0
irc/logging.go View File

@@ -59,5 +59,6 @@ func NewLogging(level string) *Logging {
59 59
 }
60 60
 
61 61
 var (
62
+	// Log is the default logger.
62 63
 	Log = NewLogging("warn")
63 64
 )

+ 4
- 0
irc/net.go View File

@@ -12,16 +12,19 @@ import (
12 12
 func IPString(addr net.Addr) string {
13 13
 	addrStr := addr.String()
14 14
 	ipaddr, _, err := net.SplitHostPort(addrStr)
15
+	//TODO(dan): Why is this needed, does this happen?
15 16
 	if err != nil {
16 17
 		return addrStr
17 18
 	}
18 19
 	return ipaddr
19 20
 }
20 21
 
22
+// AddrLookupHostname returns the hostname (if possible) or address for the given `net.Addr`.
21 23
 func AddrLookupHostname(addr net.Addr) string {
22 24
 	return LookupHostname(IPString(addr))
23 25
 }
24 26
 
27
+// LookupHostname returns the hostname for `addr` if it has one. Otherwise, just returns `addr`.
25 28
 func LookupHostname(addr string) string {
26 29
 	names, err := net.LookupAddr(addr)
27 30
 	if err != nil || len(names) < 1 || !IsHostname(names[0]) {
@@ -34,6 +37,7 @@ func LookupHostname(addr string) string {
34 37
 
35 38
 var allowedHostnameChars = "abcdefghijklmnopqrstuvwxyz1234567890-."
36 39
 
40
+// IsHostname returns whether we consider `name` a valid hostname.
37 41
 func IsHostname(name string) bool {
38 42
 	// IRC hostnames specifically require a period
39 43
 	if !strings.Contains(name, ".") || len(name) < 1 || len(name) > 253 {

+ 8
- 4
irc/password.go View File

@@ -11,12 +11,14 @@ import (
11 11
 )
12 12
 
13 13
 var (
14
-	EmptyPasswordError = errors.New("empty password")
14
+	// ErrEmptyPassword means that an empty password was given.
15
+	ErrEmptyPassword = errors.New("empty password")
15 16
 )
16 17
 
18
+// GenerateEncodedPassword returns an encrypted password, encoded into a string with base64.
17 19
 func GenerateEncodedPassword(passwd string) (encoded string, err error) {
18 20
 	if passwd == "" {
19
-		err = EmptyPasswordError
21
+		err = ErrEmptyPassword
20 22
 		return
21 23
 	}
22 24
 	bcrypted, err := bcrypt.GenerateFromPassword([]byte(passwd), bcrypt.MinCost)
@@ -27,15 +29,17 @@ func GenerateEncodedPassword(passwd string) (encoded string, err error) {
27 29
 	return
28 30
 }
29 31
 
30
-func DecodePassword(encoded string) (decoded []byte, err error) {
32
+// DecodePasswordHash takes a base64-encoded password hash and returns the appropriate bytes.
33
+func DecodePasswordHash(encoded string) (decoded []byte, err error) {
31 34
 	if encoded == "" {
32
-		err = EmptyPasswordError
35
+		err = ErrEmptyPassword
33 36
 		return
34 37
 	}
35 38
 	decoded, err = base64.StdEncoding.DecodeString(encoded)
36 39
 	return
37 40
 }
38 41
 
42
+// ComparePassword compares a given password with the given hash.
39 43
 func ComparePassword(hash, password []byte) error {
40 44
 	return bcrypt.CompareHashAndPassword(hash, password)
41 45
 }

+ 3
- 3
irc/server.go View File

@@ -394,10 +394,10 @@ func (s *Server) tryRegister(c *Client) {
394 394
 	//NOTE(dan): we specifically use the NICK here instead of the nickmask
395 395
 	// see http://modern.ircdocs.horse/#rplwelcome-001 for details on why we avoid using the nickmask
396 396
 	c.Send(nil, s.name, RPL_WELCOME, c.nick, fmt.Sprintf("Welcome to the Internet Relay Network %s", c.nick))
397
-	c.Send(nil, s.name, RPL_YOURHOST, c.nick, fmt.Sprintf("Your host is %s, running version %s", s.name, VER))
397
+	c.Send(nil, s.name, RPL_YOURHOST, c.nick, fmt.Sprintf("Your host is %s, running version %s", s.name, Ver))
398 398
 	c.Send(nil, s.name, RPL_CREATED, c.nick, fmt.Sprintf("This server was created %s", s.ctime.Format(time.RFC1123)))
399 399
 	//TODO(dan): Look at adding last optional [<channel modes with a parameter>] parameter
400
-	c.Send(nil, s.name, RPL_MYINFO, c.nick, s.name, VER, supportedUserModesString, supportedChannelModesString)
400
+	c.Send(nil, s.name, RPL_MYINFO, c.nick, s.name, Ver, supportedUserModesString, supportedChannelModesString)
401 401
 	c.RplISupport()
402 402
 	s.MOTD(c)
403 403
 	c.Send(nil, c.nickMaskString, RPL_UMODEIS, c.nick, c.ModeString())
@@ -1103,7 +1103,7 @@ func versionHandler(server *Server, client *Client, msg ircmsg.IrcMessage) bool
1103 1103
 		return false
1104 1104
 	}
1105 1105
 
1106
-	client.Send(nil, server.name, RPL_VERSION, client.nick, VER, server.name)
1106
+	client.Send(nil, server.name, RPL_VERSION, client.nick, Ver, server.name)
1107 1107
 	client.RplISupport()
1108 1108
 	return false
1109 1109
 }

+ 3
- 3
oragono.go View File

@@ -17,7 +17,7 @@ import (
17 17
 )
18 18
 
19 19
 func main() {
20
-	version := irc.SEM_VER
20
+	version := irc.SemVer
21 21
 	usage := `oragono.
22 22
 Usage:
23 23
 	oragono initdb [--conf <filename>] [--quiet]
@@ -85,8 +85,8 @@ Options:
85 85
 		irc.Log.SetLevel(config.Server.Log)
86 86
 		server := irc.NewServer(config)
87 87
 		if !arguments["--quiet"].(bool) {
88
-			log.Println(irc.SEM_VER, "running")
89
-			defer log.Println(irc.SEM_VER, "exiting")
88
+			log.Println(irc.SemVer, "running")
89
+			defer log.Println(irc.SemVer, "exiting")
90 90
 		}
91 91
 		server.Run()
92 92
 	}

Loading…
Cancel
Save