diff --git a/irc/config.go b/irc/config.go index 9b445cc8..e8e5fe8f 100644 --- a/irc/config.go +++ b/irc/config.go @@ -37,7 +37,7 @@ func (conf *TLSListenConfig) Config() (*tls.Config, error) { } func (conf *PassConfig) PasswordBytes() []byte { - bytes, err := DecodePassword(conf.Password) + bytes, err := DecodePasswordHash(conf.Password) if err != nil { log.Fatal("decode password error: ", err) } diff --git a/irc/constants.go b/irc/constants.go index 6b73fbcf..d5c788fd 100644 --- a/irc/constants.go +++ b/irc/constants.go @@ -8,9 +8,11 @@ package irc import "fmt" const ( - SEM_VER = "0.2.0-unreleased" + // SemVer is the semantic version of Oragono. + SemVer = "0.2.0-unreleased" ) var ( - VER = fmt.Sprintf("oragono-%s", SEM_VER) + // Ver is the full version of Oragono, used in responses to clients. + Ver = fmt.Sprintf("oragono-%s", SemVer) ) diff --git a/irc/isupport.go b/irc/isupport.go index 36ff5aaa..bd954410 100644 --- a/irc/isupport.go +++ b/irc/isupport.go @@ -67,6 +67,7 @@ func (il *ISupportList) RegenerateCachedReply() { } } +// RplISupport outputs our ISUPPORT lines to the client. This is used on connection and in VERSION responses. func (client *Client) RplISupport() { for _, tokenline := range client.server.isupport.CachedReply { // ugly trickery ahead diff --git a/irc/logging.go b/irc/logging.go index afc9f27b..b2ab34bd 100644 --- a/irc/logging.go +++ b/irc/logging.go @@ -59,5 +59,6 @@ func NewLogging(level string) *Logging { } var ( + // Log is the default logger. Log = NewLogging("warn") ) diff --git a/irc/net.go b/irc/net.go index b8a0040a..a6c96f15 100644 --- a/irc/net.go +++ b/irc/net.go @@ -12,16 +12,19 @@ import ( func IPString(addr net.Addr) string { addrStr := addr.String() ipaddr, _, err := net.SplitHostPort(addrStr) + //TODO(dan): Why is this needed, does this happen? if err != nil { return addrStr } return ipaddr } +// AddrLookupHostname returns the hostname (if possible) or address for the given `net.Addr`. func AddrLookupHostname(addr net.Addr) string { return LookupHostname(IPString(addr)) } +// LookupHostname returns the hostname for `addr` if it has one. Otherwise, just returns `addr`. func LookupHostname(addr string) string { names, err := net.LookupAddr(addr) if err != nil || len(names) < 1 || !IsHostname(names[0]) { @@ -34,6 +37,7 @@ func LookupHostname(addr string) string { var allowedHostnameChars = "abcdefghijklmnopqrstuvwxyz1234567890-." +// IsHostname returns whether we consider `name` a valid hostname. func IsHostname(name string) bool { // IRC hostnames specifically require a period if !strings.Contains(name, ".") || len(name) < 1 || len(name) > 253 { diff --git a/irc/password.go b/irc/password.go index 71ed849f..652f525a 100644 --- a/irc/password.go +++ b/irc/password.go @@ -11,12 +11,14 @@ import ( ) var ( - EmptyPasswordError = errors.New("empty password") + // ErrEmptyPassword means that an empty password was given. + ErrEmptyPassword = errors.New("empty password") ) +// GenerateEncodedPassword returns an encrypted password, encoded into a string with base64. func GenerateEncodedPassword(passwd string) (encoded string, err error) { if passwd == "" { - err = EmptyPasswordError + err = ErrEmptyPassword return } bcrypted, err := bcrypt.GenerateFromPassword([]byte(passwd), bcrypt.MinCost) @@ -27,15 +29,17 @@ func GenerateEncodedPassword(passwd string) (encoded string, err error) { return } -func DecodePassword(encoded string) (decoded []byte, err error) { +// DecodePasswordHash takes a base64-encoded password hash and returns the appropriate bytes. +func DecodePasswordHash(encoded string) (decoded []byte, err error) { if encoded == "" { - err = EmptyPasswordError + err = ErrEmptyPassword return } decoded, err = base64.StdEncoding.DecodeString(encoded) return } +// ComparePassword compares a given password with the given hash. func ComparePassword(hash, password []byte) error { return bcrypt.CompareHashAndPassword(hash, password) } diff --git a/irc/server.go b/irc/server.go index d65f1e73..ebbe068e 100644 --- a/irc/server.go +++ b/irc/server.go @@ -394,10 +394,10 @@ func (s *Server) tryRegister(c *Client) { //NOTE(dan): we specifically use the NICK here instead of the nickmask // see http://modern.ircdocs.horse/#rplwelcome-001 for details on why we avoid using the nickmask c.Send(nil, s.name, RPL_WELCOME, c.nick, fmt.Sprintf("Welcome to the Internet Relay Network %s", c.nick)) - c.Send(nil, s.name, RPL_YOURHOST, c.nick, fmt.Sprintf("Your host is %s, running version %s", s.name, VER)) + c.Send(nil, s.name, RPL_YOURHOST, c.nick, fmt.Sprintf("Your host is %s, running version %s", s.name, Ver)) c.Send(nil, s.name, RPL_CREATED, c.nick, fmt.Sprintf("This server was created %s", s.ctime.Format(time.RFC1123))) //TODO(dan): Look at adding last optional [] parameter - c.Send(nil, s.name, RPL_MYINFO, c.nick, s.name, VER, supportedUserModesString, supportedChannelModesString) + c.Send(nil, s.name, RPL_MYINFO, c.nick, s.name, Ver, supportedUserModesString, supportedChannelModesString) c.RplISupport() s.MOTD(c) 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 return false } - client.Send(nil, server.name, RPL_VERSION, client.nick, VER, server.name) + client.Send(nil, server.name, RPL_VERSION, client.nick, Ver, server.name) client.RplISupport() return false } diff --git a/oragono.go b/oragono.go index 4151c794..33870f23 100644 --- a/oragono.go +++ b/oragono.go @@ -17,7 +17,7 @@ import ( ) func main() { - version := irc.SEM_VER + version := irc.SemVer usage := `oragono. Usage: oragono initdb [--conf ] [--quiet] @@ -85,8 +85,8 @@ Options: irc.Log.SetLevel(config.Server.Log) server := irc.NewServer(config) if !arguments["--quiet"].(bool) { - log.Println(irc.SEM_VER, "running") - defer log.Println(irc.SEM_VER, "exiting") + log.Println(irc.SemVer, "running") + defer log.Println(irc.SemVer, "exiting") } server.Run() }