Kaynağa Gözat

cleanup

tags/v0.1.0
Jeremy Latt 10 yıl önce
ebeveyn
işleme
3b12dec207
2 değiştirilmiş dosya ile 11 ekleme ve 17 silme
  1. 3
    17
      irc/client.go
  2. 8
    0
      irc/socket.go

+ 3
- 17
irc/client.go Dosyayı Görüntüle

60
 // command goroutine
60
 // command goroutine
61
 //
61
 //
62
 
62
 
63
-func (client *Client) send(command Command) {
64
-	command.SetClient(client)
65
-	client.server.commands <- command
66
-}
67
-
68
 func (client *Client) run() {
63
 func (client *Client) run() {
69
-	client.send(&ProxyCommand{
70
-		hostname: AddrLookupHostname(client.socket.conn.RemoteAddr()),
71
-	})
72
-
73
 	for command := range client.commands {
64
 	for command := range client.commands {
74
-		checkPass, ok := command.(checkPasswordCommand)
75
-		if ok {
65
+		if checkPass, ok := command.(checkPasswordCommand); ok {
76
 			checkPass.LoadPassword(client.server)
66
 			checkPass.LoadPassword(client.server)
77
 			// Block the client thread while handling a potentially expensive
67
 			// Block the client thread while handling a potentially expensive
78
 			// password bcrypt operation. Since the server is single-threaded
68
 			// password bcrypt operation. Since the server is single-threaded
81
 			// completes. This could be a form of DoS if handled naively.
71
 			// completes. This could be a form of DoS if handled naively.
82
 			checkPass.CheckPassword()
72
 			checkPass.CheckPassword()
83
 		}
73
 		}
84
-
85
-		client.send(command)
74
+		command.SetClient(client)
75
+		client.server.commands <- command
86
 	}
76
 	}
87
-
88
-	client.send(&QuitCommand{
89
-		message: "connection closed",
90
-	})
91
 }
77
 }
92
 
78
 
93
 func (client *Client) connectionTimeout() {
79
 func (client *Client) connectionTimeout() {

+ 8
- 0
irc/socket.go Dosyayı Görüntüle

38
 }
38
 }
39
 
39
 
40
 func (socket *Socket) readLines(commands chan<- Command) {
40
 func (socket *Socket) readLines(commands chan<- Command) {
41
+	commands <- &ProxyCommand{
42
+		hostname: AddrLookupHostname(socket.conn.RemoteAddr()),
43
+	}
44
+
41
 	scanner := bufio.NewScanner(socket.conn)
45
 	scanner := bufio.NewScanner(socket.conn)
42
 	for scanner.Scan() {
46
 	for scanner.Scan() {
43
 		line := scanner.Text()
47
 		line := scanner.Text()
58
 		Log.debug.Printf("%s error: %s", socket, err)
62
 		Log.debug.Printf("%s error: %s", socket, err)
59
 	}
63
 	}
60
 
64
 
65
+	commands <- &QuitCommand{
66
+		message: "connection closed",
67
+	}
68
+
61
 	close(commands)
69
 	close(commands)
62
 }
70
 }
63
 
71
 

Loading…
İptal
Kaydet