mirror of
https://github.com/ergochat/ergo.git
synced 2025-01-24 19:24:16 +01:00
server: Remove useless comments, make idle/quit function layouts nicer
This commit is contained in:
parent
fb63691c8b
commit
9fe7c143c8
@ -165,7 +165,6 @@ func (client *Client) run() {
|
|||||||
// Set the hostname for this client
|
// Set the hostname for this client
|
||||||
client.rawHostname = AddrLookupHostname(client.socket.conn.RemoteAddr())
|
client.rawHostname = AddrLookupHostname(client.socket.conn.RemoteAddr())
|
||||||
|
|
||||||
//TODO(dan): Make this a socketreactor from ircbnc
|
|
||||||
for {
|
for {
|
||||||
line, err = client.socket.Read()
|
line, err = client.socket.Read()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -206,32 +205,17 @@ func (client *Client) run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// quit timer goroutine
|
// idle, quit, timers and timeouts
|
||||||
//
|
//
|
||||||
|
|
||||||
func (client *Client) connectionTimeout() {
|
// Active updates when the client was last 'active' (i.e. the user should be sitting in front of their client).
|
||||||
client.Quit(fmt.Sprintf("Ping timeout: %s seconds", TIMEOUT_STATED_SECONDS))
|
|
||||||
client.isQuitting = true
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// idle timer goroutine
|
|
||||||
//
|
|
||||||
|
|
||||||
func (client *Client) connectionIdle() {
|
|
||||||
client.server.idle <- client
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// server goroutine
|
|
||||||
//
|
|
||||||
|
|
||||||
// Active marks the client as 'active' (i.e. the user should be there).
|
|
||||||
func (client *Client) Active() {
|
func (client *Client) Active() {
|
||||||
client.atime = time.Now()
|
client.atime = time.Now()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Touch marks the client as alive.
|
// Touch marks the client as alive (as it it has a connection to us and we
|
||||||
|
// can receive messages from it), and resets when we'll send the client a
|
||||||
|
// keepalive PING.
|
||||||
func (client *Client) Touch() {
|
func (client *Client) Touch() {
|
||||||
client.timerMutex.Lock()
|
client.timerMutex.Lock()
|
||||||
defer client.timerMutex.Unlock()
|
defer client.timerMutex.Unlock()
|
||||||
@ -247,8 +231,9 @@ func (client *Client) Touch() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Idle resets the timeout handlers and sends the client a PING.
|
// connectionIdle is run when the client has not sent us any data for a while,
|
||||||
func (client *Client) Idle() {
|
// sends the client a PING and starts the quit timeout.
|
||||||
|
func (client *Client) connectionIdle() {
|
||||||
client.timerMutex.Lock()
|
client.timerMutex.Lock()
|
||||||
defer client.timerMutex.Unlock()
|
defer client.timerMutex.Unlock()
|
||||||
|
|
||||||
@ -261,6 +246,18 @@ func (client *Client) Idle() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// connectionTimeout runs after connectionIdle has been run, if we do not receive a
|
||||||
|
// 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.
|
||||||
|
func (client *Client) connectionTimeout() {
|
||||||
|
client.Quit(fmt.Sprintf("Ping timeout: %s seconds", TIMEOUT_STATED_SECONDS))
|
||||||
|
client.isQuitting = true
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// server goroutine
|
||||||
|
//
|
||||||
|
|
||||||
// Register sets the client details as appropriate when entering the network.
|
// Register sets the client details as appropriate when entering the network.
|
||||||
func (client *Client) Register() {
|
func (client *Client) Register() {
|
||||||
if client.registered {
|
if client.registered {
|
||||||
@ -587,13 +584,14 @@ func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, comm
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// force trailing
|
// force trailing, if message requires it
|
||||||
var usedSpaceHack bool
|
var usedTrailingHack bool
|
||||||
if commandsThatMustUseTrailing[strings.ToUpper(command)] && len(params) > 0 {
|
if commandsThatMustUseTrailing[strings.ToUpper(command)] && len(params) > 0 {
|
||||||
lastParam := params[len(params)-1]
|
lastParam := params[len(params)-1]
|
||||||
|
// to force trailing, we ensure the final param contains a space
|
||||||
if !strings.Contains(lastParam, " ") {
|
if !strings.Contains(lastParam, " ") {
|
||||||
params[len(params)-1] = lastParam + " "
|
params[len(params)-1] = lastParam + " "
|
||||||
usedSpaceHack = true
|
usedTrailingHack = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -613,8 +611,8 @@ func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, comm
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// strip space hack if we used it
|
// is we used the trailing hack, we need to strip the final space we appended earlier
|
||||||
if usedSpaceHack {
|
if usedTrailingHack {
|
||||||
line = line[:len(line)-3] + "\r\n"
|
line = line[:len(line)-3] + "\r\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -625,6 +623,7 @@ func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, comm
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Notice sends the client a notice from the server.
|
// Notice sends the client a notice from the server.
|
||||||
|
//TODO(dan): Make this handle message splitting.
|
||||||
func (client *Client) Notice(text string) {
|
func (client *Client) Notice(text string) {
|
||||||
client.Send(nil, client.server.name, "NOTICE", client.nick, text)
|
client.Send(nil, client.server.name, "NOTICE", client.nick, text)
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,6 @@ type Server struct {
|
|||||||
ctime time.Time
|
ctime time.Time
|
||||||
currentOpers map[*Client]bool
|
currentOpers map[*Client]bool
|
||||||
dlines *DLineManager
|
dlines *DLineManager
|
||||||
idle chan *Client
|
|
||||||
isupport *ISupportList
|
isupport *ISupportList
|
||||||
klines *KLineManager
|
klines *KLineManager
|
||||||
limits Limits
|
limits Limits
|
||||||
@ -208,7 +207,6 @@ func NewServer(configFilename string, config *Config, logger *logger.Manager) (*
|
|||||||
connectionThrottle: connectionThrottle,
|
connectionThrottle: connectionThrottle,
|
||||||
ctime: time.Now(),
|
ctime: time.Now(),
|
||||||
currentOpers: make(map[*Client]bool),
|
currentOpers: make(map[*Client]bool),
|
||||||
idle: make(chan *Client),
|
|
||||||
limits: Limits{
|
limits: Limits{
|
||||||
AwayLen: int(config.Limits.AwayLen),
|
AwayLen: int(config.Limits.AwayLen),
|
||||||
ChannelLen: int(config.Limits.ChannelLen),
|
ChannelLen: int(config.Limits.ChannelLen),
|
||||||
@ -483,9 +481,6 @@ func (server *Server) Run() {
|
|||||||
go NewClient(server, conn.Conn, conn.IsTLS)
|
go NewClient(server, conn.Conn, conn.IsTLS)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
case client := <-server.idle:
|
|
||||||
client.Idle()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user