3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 02:32:39 +01:00

Fixing warnings and golint stuff

This commit is contained in:
Daniel Oaks 2016-10-13 17:36:44 +10:00
parent 09802f7181
commit e807f3ca04
8 changed files with 25 additions and 13 deletions

View File

@ -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)
}

View File

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

View File

@ -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

View File

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

View File

@ -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 {

View File

@ -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)
}

View File

@ -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 [<channel modes with a parameter>] 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
}

View File

@ -17,7 +17,7 @@ import (
)
func main() {
version := irc.SEM_VER
version := irc.SemVer
usage := `oragono.
Usage:
oragono initdb [--conf <filename>] [--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()
}