mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 18:52:41 +01:00
Fixing warnings and golint stuff
This commit is contained in:
parent
09802f7181
commit
e807f3ca04
@ -37,7 +37,7 @@ func (conf *TLSListenConfig) Config() (*tls.Config, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (conf *PassConfig) PasswordBytes() []byte {
|
func (conf *PassConfig) PasswordBytes() []byte {
|
||||||
bytes, err := DecodePassword(conf.Password)
|
bytes, err := DecodePasswordHash(conf.Password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("decode password error: ", err)
|
log.Fatal("decode password error: ", err)
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,11 @@ package irc
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SEM_VER = "0.2.0-unreleased"
|
// SemVer is the semantic version of Oragono.
|
||||||
|
SemVer = "0.2.0-unreleased"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
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)
|
||||||
)
|
)
|
||||||
|
@ -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() {
|
func (client *Client) RplISupport() {
|
||||||
for _, tokenline := range client.server.isupport.CachedReply {
|
for _, tokenline := range client.server.isupport.CachedReply {
|
||||||
// ugly trickery ahead
|
// ugly trickery ahead
|
||||||
|
@ -59,5 +59,6 @@ func NewLogging(level string) *Logging {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// Log is the default logger.
|
||||||
Log = NewLogging("warn")
|
Log = NewLogging("warn")
|
||||||
)
|
)
|
||||||
|
@ -12,16 +12,19 @@ import (
|
|||||||
func IPString(addr net.Addr) string {
|
func IPString(addr net.Addr) string {
|
||||||
addrStr := addr.String()
|
addrStr := addr.String()
|
||||||
ipaddr, _, err := net.SplitHostPort(addrStr)
|
ipaddr, _, err := net.SplitHostPort(addrStr)
|
||||||
|
//TODO(dan): Why is this needed, does this happen?
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return addrStr
|
return addrStr
|
||||||
}
|
}
|
||||||
return ipaddr
|
return ipaddr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddrLookupHostname returns the hostname (if possible) or address for the given `net.Addr`.
|
||||||
func AddrLookupHostname(addr net.Addr) string {
|
func AddrLookupHostname(addr net.Addr) string {
|
||||||
return LookupHostname(IPString(addr))
|
return LookupHostname(IPString(addr))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LookupHostname returns the hostname for `addr` if it has one. Otherwise, just returns `addr`.
|
||||||
func LookupHostname(addr string) string {
|
func LookupHostname(addr string) string {
|
||||||
names, err := net.LookupAddr(addr)
|
names, err := net.LookupAddr(addr)
|
||||||
if err != nil || len(names) < 1 || !IsHostname(names[0]) {
|
if err != nil || len(names) < 1 || !IsHostname(names[0]) {
|
||||||
@ -34,6 +37,7 @@ func LookupHostname(addr string) string {
|
|||||||
|
|
||||||
var allowedHostnameChars = "abcdefghijklmnopqrstuvwxyz1234567890-."
|
var allowedHostnameChars = "abcdefghijklmnopqrstuvwxyz1234567890-."
|
||||||
|
|
||||||
|
// IsHostname returns whether we consider `name` a valid hostname.
|
||||||
func IsHostname(name string) bool {
|
func IsHostname(name string) bool {
|
||||||
// IRC hostnames specifically require a period
|
// IRC hostnames specifically require a period
|
||||||
if !strings.Contains(name, ".") || len(name) < 1 || len(name) > 253 {
|
if !strings.Contains(name, ".") || len(name) < 1 || len(name) > 253 {
|
||||||
|
@ -11,12 +11,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
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) {
|
func GenerateEncodedPassword(passwd string) (encoded string, err error) {
|
||||||
if passwd == "" {
|
if passwd == "" {
|
||||||
err = EmptyPasswordError
|
err = ErrEmptyPassword
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
bcrypted, err := bcrypt.GenerateFromPassword([]byte(passwd), bcrypt.MinCost)
|
bcrypted, err := bcrypt.GenerateFromPassword([]byte(passwd), bcrypt.MinCost)
|
||||||
@ -27,15 +29,17 @@ func GenerateEncodedPassword(passwd string) (encoded string, err error) {
|
|||||||
return
|
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 == "" {
|
if encoded == "" {
|
||||||
err = EmptyPasswordError
|
err = ErrEmptyPassword
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
decoded, err = base64.StdEncoding.DecodeString(encoded)
|
decoded, err = base64.StdEncoding.DecodeString(encoded)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ComparePassword compares a given password with the given hash.
|
||||||
func ComparePassword(hash, password []byte) error {
|
func ComparePassword(hash, password []byte) error {
|
||||||
return bcrypt.CompareHashAndPassword(hash, password)
|
return bcrypt.CompareHashAndPassword(hash, password)
|
||||||
}
|
}
|
||||||
|
@ -394,10 +394,10 @@ func (s *Server) tryRegister(c *Client) {
|
|||||||
//NOTE(dan): we specifically use the NICK here instead of the nickmask
|
//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
|
// 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_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)))
|
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
|
//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()
|
c.RplISupport()
|
||||||
s.MOTD(c)
|
s.MOTD(c)
|
||||||
c.Send(nil, c.nickMaskString, RPL_UMODEIS, c.nick, c.ModeString())
|
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
|
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()
|
client.RplISupport()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
version := irc.SEM_VER
|
version := irc.SemVer
|
||||||
usage := `oragono.
|
usage := `oragono.
|
||||||
Usage:
|
Usage:
|
||||||
oragono initdb [--conf <filename>] [--quiet]
|
oragono initdb [--conf <filename>] [--quiet]
|
||||||
@ -85,8 +85,8 @@ Options:
|
|||||||
irc.Log.SetLevel(config.Server.Log)
|
irc.Log.SetLevel(config.Server.Log)
|
||||||
server := irc.NewServer(config)
|
server := irc.NewServer(config)
|
||||||
if !arguments["--quiet"].(bool) {
|
if !arguments["--quiet"].(bool) {
|
||||||
log.Println(irc.SEM_VER, "running")
|
log.Println(irc.SemVer, "running")
|
||||||
defer log.Println(irc.SEM_VER, "exiting")
|
defer log.Println(irc.SemVer, "exiting")
|
||||||
}
|
}
|
||||||
server.Run()
|
server.Run()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user