Sfoglia il codice sorgente

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

tags/v0.8.0
Daniel Oaks 7 anni fa
parent
commit
9fe7c143c8
2 ha cambiato i file con 27 aggiunte e 33 eliminazioni
  1. 27
    28
      irc/client.go
  2. 0
    5
      irc/server.go

+ 27
- 28
irc/client.go Vedi File

@@ -165,7 +165,6 @@ func (client *Client) run() {
165 165
 	// Set the hostname for this client
166 166
 	client.rawHostname = AddrLookupHostname(client.socket.conn.RemoteAddr())
167 167
 
168
-	//TODO(dan): Make this a socketreactor from ircbnc
169 168
 	for {
170 169
 		line, err = client.socket.Read()
171 170
 		if err != nil {
@@ -206,32 +205,17 @@ func (client *Client) run() {
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 212
 func (client *Client) Active() {
231 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 219
 func (client *Client) Touch() {
236 220
 	client.timerMutex.Lock()
237 221
 	defer client.timerMutex.Unlock()
@@ -247,8 +231,9 @@ func (client *Client) Touch() {
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 237
 	client.timerMutex.Lock()
253 238
 	defer client.timerMutex.Unlock()
254 239
 
@@ -261,6 +246,18 @@ func (client *Client) Idle() {
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 261
 // Register sets the client details as appropriate when entering the network.
265 262
 func (client *Client) Register() {
266 263
 	if client.registered {
@@ -587,13 +584,14 @@ func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, comm
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 589
 	if commandsThatMustUseTrailing[strings.ToUpper(command)] && len(params) > 0 {
593 590
 		lastParam := params[len(params)-1]
591
+		// to force trailing, we ensure the final param contains a space
594 592
 		if !strings.Contains(lastParam, " ") {
595 593
 			params[len(params)-1] = lastParam + " "
596
-			usedSpaceHack = true
594
+			usedTrailingHack = true
597 595
 		}
598 596
 	}
599 597
 
@@ -613,8 +611,8 @@ func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, comm
613 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 616
 		line = line[:len(line)-3] + "\r\n"
619 617
 	}
620 618
 
@@ -625,6 +623,7 @@ func (client *Client) Send(tags *map[string]ircmsg.TagValue, prefix string, comm
625 623
 }
626 624
 
627 625
 // Notice sends the client a notice from the server.
626
+//TODO(dan): Make this handle message splitting.
628 627
 func (client *Client) Notice(text string) {
629 628
 	client.Send(nil, client.server.name, "NOTICE", client.nick, text)
630 629
 }

+ 0
- 5
irc/server.go Vedi File

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

Loading…
Annulla
Salva