Ver código fonte

server: Remove useless comments, make idle/quit function layouts nicer

tags/v0.8.0
Daniel Oaks 7 anos atrás
pai
commit
9fe7c143c8
2 arquivos alterados com 27 adições e 33 exclusões
  1. 27
    28
      irc/client.go
  2. 0
    5
      irc/server.go

+ 27
- 28
irc/client.go Ver arquivo

165
 	// Set the hostname for this client
165
 	// Set the hostname for this client
166
 	client.rawHostname = AddrLookupHostname(client.socket.conn.RemoteAddr())
166
 	client.rawHostname = AddrLookupHostname(client.socket.conn.RemoteAddr())
167
 
167
 
168
-	//TODO(dan): Make this a socketreactor from ircbnc
169
 	for {
168
 	for {
170
 		line, err = client.socket.Read()
169
 		line, err = client.socket.Read()
171
 		if err != nil {
170
 		if err != nil {
206
 }
205
 }
207
 
206
 
208
 //
207
 //
209
-// quit timer goroutine
208
+// idle, quit, timers and timeouts
210
 //
209
 //
211
 
210
 
212
-func (client *Client) connectionTimeout() {
213
-	client.Quit(fmt.Sprintf("Ping timeout: %s seconds", TIMEOUT_STATED_SECONDS))
214
-	client.isQuitting = true
215
-}
216
-
217
-//
218
-// idle timer goroutine
219
-//
220
-
221
-func (client *Client) connectionIdle() {
222
-	client.server.idle <- client
223
-}
224
-
225
-//
226
-// server goroutine
227
-//
228
-
229
-// Active marks the client as 'active' (i.e. the user should be there).
211
+// Active updates when the client was last 'active' (i.e. the user should be sitting in front of their client).
230
 func (client *Client) Active() {
212
 func (client *Client) Active() {
231
 	client.atime = time.Now()
213
 	client.atime = time.Now()
232
 }
214
 }
233
 
215
 
234
-// Touch marks the client as alive.
216
+// Touch marks the client as alive (as it it has a connection to us and we
217
+// can receive messages from it), and resets when we'll send the client a
218
+// keepalive PING.
235
 func (client *Client) Touch() {
219
 func (client *Client) Touch() {
236
 	client.timerMutex.Lock()
220
 	client.timerMutex.Lock()
237
 	defer client.timerMutex.Unlock()
221
 	defer client.timerMutex.Unlock()
247
 	}
231
 	}
248
 }
232
 }
249
 
233
 
250
-// Idle resets the timeout handlers and sends the client a PING.
251
-func (client *Client) Idle() {
234
+// connectionIdle is run when the client has not sent us any data for a while,
235
+// sends the client a PING and starts the quit timeout.
236
+func (client *Client) connectionIdle() {
252
 	client.timerMutex.Lock()
237
 	client.timerMutex.Lock()
253
 	defer client.timerMutex.Unlock()
238
 	defer client.timerMutex.Unlock()
254
 
239
 
261
 	}
246
 	}
262
 }
247
 }
263
 
248
 
249
+// connectionTimeout runs after connectionIdle has been run, if we do not receive a
250
+// ping or any other activity back from the client. When this happens we assume the
251
+// connection has died and remove the client from the network.
252
+func (client *Client) connectionTimeout() {
253
+	client.Quit(fmt.Sprintf("Ping timeout: %s seconds", TIMEOUT_STATED_SECONDS))
254
+	client.isQuitting = true
255
+}
256
+
257
+//
258
+// server goroutine
259
+//
260
+
264
 // Register sets the client details as appropriate when entering the network.
261
 // Register sets the client details as appropriate when entering the network.
265
 func (client *Client) Register() {
262
 func (client *Client) Register() {
266
 	if client.registered {
263
 	if client.registered {
587
 		}
584
 		}
588
 	}
585
 	}
589
 
586
 
590
-	// force trailing
591
-	var usedSpaceHack bool
587
+	// force trailing, if message requires it
588
+	var usedTrailingHack bool
592
 	if commandsThatMustUseTrailing[strings.ToUpper(command)] && len(params) > 0 {
589
 	if commandsThatMustUseTrailing[strings.ToUpper(command)] && len(params) > 0 {
593
 		lastParam := params[len(params)-1]
590
 		lastParam := params[len(params)-1]
591
+		// to force trailing, we ensure the final param contains a space
594
 		if !strings.Contains(lastParam, " ") {
592
 		if !strings.Contains(lastParam, " ") {
595
 			params[len(params)-1] = lastParam + " "
593
 			params[len(params)-1] = lastParam + " "
596
-			usedSpaceHack = true
594
+			usedTrailingHack = true
597
 		}
595
 		}
598
 	}
596
 	}
599
 
597
 
613
 		return err
611
 		return err
614
 	}
612
 	}
615
 
613
 
616
-	// strip space hack if we used it
617
-	if usedSpaceHack {
614
+	// is we used the trailing hack, we need to strip the final space we appended earlier
615
+	if usedTrailingHack {
618
 		line = line[:len(line)-3] + "\r\n"
616
 		line = line[:len(line)-3] + "\r\n"
619
 	}
617
 	}
620
 
618
 
625
 }
623
 }
626
 
624
 
627
 // Notice sends the client a notice from the server.
625
 // Notice sends the client a notice from the server.
626
+//TODO(dan): Make this handle message splitting.
628
 func (client *Client) Notice(text string) {
627
 func (client *Client) Notice(text string) {
629
 	client.Send(nil, client.server.name, "NOTICE", client.nick, text)
628
 	client.Send(nil, client.server.name, "NOTICE", client.nick, text)
630
 }
629
 }

+ 0
- 5
irc/server.go Ver arquivo

100
 	ctime                        time.Time
100
 	ctime                        time.Time
101
 	currentOpers                 map[*Client]bool
101
 	currentOpers                 map[*Client]bool
102
 	dlines                       *DLineManager
102
 	dlines                       *DLineManager
103
-	idle                         chan *Client
104
 	isupport                     *ISupportList
103
 	isupport                     *ISupportList
105
 	klines                       *KLineManager
104
 	klines                       *KLineManager
106
 	limits                       Limits
105
 	limits                       Limits
208
 		connectionThrottle:           connectionThrottle,
207
 		connectionThrottle:           connectionThrottle,
209
 		ctime:                        time.Now(),
208
 		ctime:                        time.Now(),
210
 		currentOpers:                 make(map[*Client]bool),
209
 		currentOpers:                 make(map[*Client]bool),
211
-		idle:                         make(chan *Client),
212
 		limits: Limits{
210
 		limits: Limits{
213
 			AwayLen:        int(config.Limits.AwayLen),
211
 			AwayLen:        int(config.Limits.AwayLen),
214
 			ChannelLen:     int(config.Limits.ChannelLen),
212
 			ChannelLen:     int(config.Limits.ChannelLen),
483
 				go NewClient(server, conn.Conn, conn.IsTLS)
481
 				go NewClient(server, conn.Conn, conn.IsTLS)
484
 				continue
482
 				continue
485
 			}
483
 			}
486
-
487
-		case client := <-server.idle:
488
-			client.Idle()
489
 		}
484
 		}
490
 	}
485
 	}
491
 }
486
 }

Carregando…
Cancelar
Salvar