3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-26 05:49:25 +01:00

General comments, fix misspellings and lints

This commit is contained in:
Daniel Oaks 2017-06-19 14:53:16 -06:00
parent 124139c097
commit 1c0c4841a1
9 changed files with 81 additions and 38 deletions

View File

@ -182,7 +182,7 @@ func accRegisterHandler(server *Server, client *Client, msg ircmsg.IrcMessage) b
} }
} }
if credentialType == "certfp" && client.certfp == "" { if credentialType == "certfp" && client.certfp == "" {
client.Send(nil, server.name, ERR_REG_INVALID_CRED_TYPE, client.nick, credentialType, callbackNamespace, "You are not using a certificiate") client.Send(nil, server.name, ERR_REG_INVALID_CRED_TYPE, client.nick, credentialType, callbackNamespace, "You are not using a TLS certificate")
removeFailedAccRegisterData(server.store, casefoldedAccount) removeFailedAccRegisterData(server.store, casefoldedAccount)
return false return false
} }

View File

@ -14,22 +14,39 @@ import (
type Capability string type Capability string
const ( const (
// AccountNotify is this IRCv3 capability: http://ircv3.net/specs/extensions/account-notify-3.1.html
AccountNotify Capability = "account-notify" AccountNotify Capability = "account-notify"
// AccountTag is this IRCv3 capability: http://ircv3.net/specs/extensions/account-tag-3.2.html
AccountTag Capability = "account-tag" AccountTag Capability = "account-tag"
// AwayNotify is this IRCv3 capability: http://ircv3.net/specs/extensions/away-notify-3.1.html
AwayNotify Capability = "away-notify" AwayNotify Capability = "away-notify"
// CapNotify is this IRCv3 capability: http://ircv3.net/specs/extensions/cap-notify-3.2.html
CapNotify Capability = "cap-notify" CapNotify Capability = "cap-notify"
// ChgHost is this IRCv3 capability: http://ircv3.net/specs/extensions/chghost-3.2.html
ChgHost Capability = "chghost" ChgHost Capability = "chghost"
// EchoMessage is this IRCv3 capability: http://ircv3.net/specs/extensions/echo-message-3.2.html
EchoMessage Capability = "echo-message" EchoMessage Capability = "echo-message"
// ExtendedJoin is this IRCv3 capability: http://ircv3.net/specs/extensions/extended-join-3.1.html
ExtendedJoin Capability = "extended-join" ExtendedJoin Capability = "extended-join"
// InviteNotify is this IRCv3 capability: http://ircv3.net/specs/extensions/invite-notify-3.2.html
InviteNotify Capability = "invite-notify" InviteNotify Capability = "invite-notify"
// MaxLine is this proposed capability: https://github.com/DanielOaks/ircv3-specifications/blob/master+line-lengths/extensions/line-lengths.md
MaxLine Capability = "draft/maxline" MaxLine Capability = "draft/maxline"
// MessageIDs is this draft IRCv3 capability: http://ircv3.net/specs/extensions/message-ids.html
MessageIDs Capability = "draft/message-ids" MessageIDs Capability = "draft/message-ids"
// MessageTags is this draft IRCv3 capability: http://ircv3.net/specs/core/message-tags-3.3.html
MessageTags Capability = "draft/message-tags-0.2" MessageTags Capability = "draft/message-tags-0.2"
// MultiPrefix is this IRCv3 capability: http://ircv3.net/specs/extensions/multi-prefix-3.1.html
MultiPrefix Capability = "multi-prefix" MultiPrefix Capability = "multi-prefix"
// Rename is this proposed capability: https://github.com/SaberUK/ircv3-specifications/blob/rename/extensions/rename.md
Rename Capability = "draft/rename" Rename Capability = "draft/rename"
// SASL is this IRCv3 capability: http://ircv3.net/specs/extensions/sasl-3.2.html
SASL Capability = "sasl" SASL Capability = "sasl"
// ServerTime is this IRCv3 capability: http://ircv3.net/specs/extensions/server-time-3.2.html
ServerTime Capability = "server-time" ServerTime Capability = "server-time"
// STS is this draft IRCv3 capability: http://ircv3.net/specs/core/sts-3.3.html
STS Capability = "draft/sts" STS Capability = "draft/sts"
// UserhostInNames is this IRCv3 capability: http://ircv3.net/specs/extensions/userhost-in-names-3.2.html
UserhostInNames Capability = "userhost-in-names" UserhostInNames Capability = "userhost-in-names"
) )

View File

@ -23,13 +23,18 @@ import (
) )
const ( const (
IDLE_TIMEOUT = time.Minute + time.Second*30 // how long before a client is considered idle // IdleTimeout is how long without traffic before a client's considered idle.
QUIT_TIMEOUT = time.Minute // how long after idle before a client is kicked IdleTimeout = time.Minute + time.Second*30
// QuitTimeout is how long without traffic (after they're considered idle) that clients are killed.
QuitTimeout = time.Minute
// IdentTimeoutSeconds is how many seconds before our ident (username) check times out.
IdentTimeoutSeconds = 5 IdentTimeoutSeconds = 5
) )
var ( var (
TIMEOUT_STATED_SECONDS = strconv.Itoa(int((IDLE_TIMEOUT + QUIT_TIMEOUT).Seconds())) // TimeoutStatedSeconds is how many seconds before clients are timed out (IdleTimeout plus QuitTimeout).
TimeoutStatedSeconds = strconv.Itoa(int((IdleTimeout + QuitTimeout).Seconds()))
// ErrNickAlreadySet is a weird error that's sent when the server's consistency has been compromised.
ErrNickAlreadySet = errors.New("Nickname is already set") ErrNickAlreadySet = errors.New("Nickname is already set")
) )
@ -233,9 +238,9 @@ func (client *Client) Touch() {
} }
if client.idleTimer == nil { if client.idleTimer == nil {
client.idleTimer = time.AfterFunc(IDLE_TIMEOUT, client.connectionIdle) client.idleTimer = time.AfterFunc(IdleTimeout, client.connectionIdle)
} else { } else {
client.idleTimer.Reset(IDLE_TIMEOUT) client.idleTimer.Reset(IdleTimeout)
} }
} }
@ -248,9 +253,9 @@ func (client *Client) connectionIdle() {
client.Send(nil, "", "PING", client.nick) client.Send(nil, "", "PING", client.nick)
if client.quitTimer == nil { if client.quitTimer == nil {
client.quitTimer = time.AfterFunc(QUIT_TIMEOUT, client.connectionTimeout) client.quitTimer = time.AfterFunc(QuitTimeout, client.connectionTimeout)
} else { } else {
client.quitTimer.Reset(QUIT_TIMEOUT) client.quitTimer.Reset(QuitTimeout)
} }
} }
@ -258,7 +263,7 @@ func (client *Client) connectionIdle() {
// ping or any other activity back from the client. When this happens we assume the // ping or any other activity back from the client. When this happens we assume the
// connection has died and remove the client from the network. // connection has died and remove the client from the network.
func (client *Client) connectionTimeout() { func (client *Client) connectionTimeout() {
client.Quit(fmt.Sprintf("Ping timeout: %s seconds", TIMEOUT_STATED_SECONDS)) client.Quit(fmt.Sprintf("Ping timeout: %s seconds", TimeoutStatedSeconds))
client.isQuitting = true client.isQuitting = true
} }

View File

@ -98,6 +98,7 @@ type OperConfig struct {
Modes string Modes string
} }
// PasswordBytes returns the bytes represented by the password hash.
func (conf *OperConfig) PasswordBytes() []byte { func (conf *OperConfig) PasswordBytes() []byte {
bytes, err := DecodePasswordHash(conf.Password) bytes, err := DecodePasswordHash(conf.Password)
if err != nil { if err != nil {

View File

@ -15,8 +15,11 @@ import (
type HelpEntryType int type HelpEntryType int
const ( const (
// CommandHelpEntry is a help entry explaining a client command.
CommandHelpEntry HelpEntryType = 0 CommandHelpEntry HelpEntryType = 0
// InformationHelpEntry is a help entry explaining general server info.
InformationHelpEntry HelpEntryType = 1 InformationHelpEntry HelpEntryType = 1
// ISupportHelpEntry is a help entry explaining a specific RPL_ISUPPORT token.
ISupportHelpEntry HelpEntryType = 2 ISupportHelpEntry HelpEntryType = 2
) )

View File

@ -32,6 +32,7 @@ const (
) )
var ( var (
// LogLevelNames takes a config name and gives the real log level.
LogLevelNames = map[string]Level{ LogLevelNames = map[string]Level{
"debug": LogDebug, "debug": LogDebug,
"info": LogInfo, "info": LogInfo,
@ -41,6 +42,7 @@ var (
"error": LogError, "error": LogError,
"errors": LogError, "errors": LogError,
} }
// LogLevelDisplayNames gives the display name to use for our log levels.
LogLevelDisplayNames = map[Level]string{ LogLevelDisplayNames = map[Level]string{
LogDebug: "debug", LogDebug: "debug",
LogInfo: "info", LogInfo: "info",

View File

@ -22,8 +22,11 @@ func (op ModeOp) String() string {
} }
const ( const (
// Add is used when adding the given key.
Add ModeOp = '+' Add ModeOp = '+'
// List is used when listing modes (for instance, listing the current bans on a channel).
List ModeOp = '=' List ModeOp = '='
// Remove is used when taking away the given key.
Remove ModeOp = '-' Remove ModeOp = '-'
) )
@ -105,6 +108,7 @@ const (
) )
var ( var (
// SupportedUserModes are the user modes that we actually support (modifying).
SupportedUserModes = Modes{ SupportedUserModes = Modes{
Away, Invisible, Operator, ServerNotice, UserRoleplaying, Away, Invisible, Operator, ServerNotice, UserRoleplaying,
} }
@ -135,6 +139,7 @@ var (
Halfop Mode = 'h' // arg Halfop Mode = 'h' // arg
Voice Mode = 'v' // arg Voice Mode = 'v' // arg
// SupportedChannelModes are the channel modes that we support.
SupportedChannelModes = Modes{ SupportedChannelModes = Modes{
BanMask, ExceptMask, InviteMask, InviteOnly, Key, NoOutside, BanMask, ExceptMask, InviteMask, InviteOnly, Key, NoOutside,
OpOnlyTopic, Secret, UserLimit, ChanRoleplaying, OpOnlyTopic, Secret, UserLimit, ChanRoleplaying,
@ -142,6 +147,7 @@ var (
// supportedChannelModesString acts as a cache for when we introduce users // supportedChannelModesString acts as a cache for when we introduce users
supportedChannelModesString = SupportedChannelModes.String() supportedChannelModesString = SupportedChannelModes.String()
// DefaultChannelModes are enabled on brand new channels when they're created.
DefaultChannelModes = Modes{ DefaultChannelModes = Modes{
NoOutside, OpOnlyTopic, NoOutside, OpOnlyTopic,
} }

View File

@ -25,12 +25,14 @@ var upgrader = websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool { return true }, CheckOrigin: func(r *http.Request) bool { return true },
} }
// WSContainer holds the websocket.
type WSContainer struct { type WSContainer struct {
*websocket.Conn *websocket.Conn
} }
func (this WSContainer) Read(msg []byte) (int, error) { // Read reads new incoming messages.
ty, bytes, err := this.ReadMessage() func (ws WSContainer) Read(msg []byte) (int, error) {
ty, bytes, err := ws.ReadMessage()
if ty == websocket.TextMessage { if ty == websocket.TextMessage {
n := copy(msg, []byte(string(bytes)+"\r\n\r\n")) n := copy(msg, []byte(string(bytes)+"\r\n\r\n"))
return n, err return n, err
@ -39,14 +41,16 @@ func (this WSContainer) Read(msg []byte) (int, error) {
return 0, nil return 0, nil
} }
func (this WSContainer) Write(msg []byte) (int, error) { // Write writes lines out to the websocket.
err := this.WriteMessage(websocket.TextMessage, msg) func (ws WSContainer) Write(msg []byte) (int, error) {
err := ws.WriteMessage(websocket.TextMessage, msg)
return len(msg), err return len(msg), err
} }
func (this WSContainer) SetDeadline(t time.Time) error { // SetDeadline sets the read and write deadline on this websocket.
if err := this.SetWriteDeadline(t); err != nil { func (ws WSContainer) SetDeadline(t time.Time) error {
if err := ws.SetWriteDeadline(t); err != nil {
return err return err
} }
return this.SetReadDeadline(t) return ws.SetReadDeadline(t)
} }

View File

@ -8,6 +8,7 @@ import (
"sync" "sync"
) )
// WhoWasList holds our list of prior clients (for use with the WHOWAS command).
type WhoWasList struct { type WhoWasList struct {
buffer []*WhoWas buffer []*WhoWas
start int start int
@ -16,6 +17,7 @@ type WhoWasList struct {
accessMutex sync.RWMutex accessMutex sync.RWMutex
} }
// WhoWas is an entry in the WhoWasList.
type WhoWas struct { type WhoWas struct {
nicknameCasefolded string nicknameCasefolded string
nickname string nickname string
@ -24,12 +26,14 @@ type WhoWas struct {
realname string realname string
} }
// NewWhoWasList returns a new WhoWasList
func NewWhoWasList(size uint) *WhoWasList { func NewWhoWasList(size uint) *WhoWasList {
return &WhoWasList{ return &WhoWasList{
buffer: make([]*WhoWas, size+1), buffer: make([]*WhoWas, size+1),
} }
} }
// Append adds an entry to the WhoWasList.
func (list *WhoWasList) Append(client *Client) { func (list *WhoWasList) Append(client *Client) {
list.accessMutex.Lock() list.accessMutex.Lock()
defer list.accessMutex.Unlock() defer list.accessMutex.Unlock()
@ -47,6 +51,7 @@ func (list *WhoWasList) Append(client *Client) {
} }
} }
// Find tries to find an entry in our WhoWasList with the given details.
func (list *WhoWasList) Find(nickname string, limit int64) []*WhoWas { func (list *WhoWasList) Find(nickname string, limit int64) []*WhoWas {
list.accessMutex.RLock() list.accessMutex.RLock()
defer list.accessMutex.RUnlock() defer list.accessMutex.RUnlock()
@ -81,7 +86,7 @@ func (list *WhoWasList) prev(index int) int {
return index return index
} }
// Iterate the buffer in reverse. // Each iterates the WhoWasList in reverse.
func (list *WhoWasList) Each() <-chan *WhoWas { func (list *WhoWasList) Each() <-chan *WhoWas {
ch := make(chan *WhoWas) ch := make(chan *WhoWas)
go func() { go func() {