Browse Source

cleanup

tags/v0.1.0
Jeremy Latt 10 years ago
parent
commit
3b12dec207
2 changed files with 11 additions and 17 deletions
  1. 3
    17
      irc/client.go
  2. 8
    0
      irc/socket.go

+ 3
- 17
irc/client.go View File

@@ -60,19 +60,9 @@ func NewClient(server *Server, conn net.Conn) *Client {
60 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 63
 func (client *Client) run() {
69
-	client.send(&ProxyCommand{
70
-		hostname: AddrLookupHostname(client.socket.conn.RemoteAddr()),
71
-	})
72
-
73 64
 	for command := range client.commands {
74
-		checkPass, ok := command.(checkPasswordCommand)
75
-		if ok {
65
+		if checkPass, ok := command.(checkPasswordCommand); ok {
76 66
 			checkPass.LoadPassword(client.server)
77 67
 			// Block the client thread while handling a potentially expensive
78 68
 			// password bcrypt operation. Since the server is single-threaded
@@ -81,13 +71,9 @@ func (client *Client) run() {
81 71
 			// completes. This could be a form of DoS if handled naively.
82 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 79
 func (client *Client) connectionTimeout() {

+ 8
- 0
irc/socket.go View File

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

Loading…
Cancel
Save