3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-10 22:19:31 +01:00
This commit is contained in:
Jeremy Latt 2014-03-27 18:58:12 -07:00
parent 2dc69c7e3d
commit 3b12dec207
2 changed files with 11 additions and 17 deletions

View File

@ -60,19 +60,9 @@ func NewClient(server *Server, conn net.Conn) *Client {
// command goroutine // command goroutine
// //
func (client *Client) send(command Command) {
command.SetClient(client)
client.server.commands <- command
}
func (client *Client) run() { func (client *Client) run() {
client.send(&ProxyCommand{
hostname: AddrLookupHostname(client.socket.conn.RemoteAddr()),
})
for command := range client.commands { for command := range client.commands {
checkPass, ok := command.(checkPasswordCommand) if checkPass, ok := command.(checkPasswordCommand); ok {
if ok {
checkPass.LoadPassword(client.server) checkPass.LoadPassword(client.server)
// Block the client thread while handling a potentially expensive // Block the client thread while handling a potentially expensive
// password bcrypt operation. Since the server is single-threaded // password bcrypt operation. Since the server is single-threaded
@ -81,13 +71,9 @@ func (client *Client) run() {
// completes. This could be a form of DoS if handled naively. // completes. This could be a form of DoS if handled naively.
checkPass.CheckPassword() checkPass.CheckPassword()
} }
command.SetClient(client)
client.send(command) client.server.commands <- command
} }
client.send(&QuitCommand{
message: "connection closed",
})
} }
func (client *Client) connectionTimeout() { func (client *Client) connectionTimeout() {

View File

@ -38,6 +38,10 @@ func (socket *Socket) Close() {
} }
func (socket *Socket) readLines(commands chan<- Command) { func (socket *Socket) readLines(commands chan<- Command) {
commands <- &ProxyCommand{
hostname: AddrLookupHostname(socket.conn.RemoteAddr()),
}
scanner := bufio.NewScanner(socket.conn) scanner := bufio.NewScanner(socket.conn)
for scanner.Scan() { for scanner.Scan() {
line := scanner.Text() line := scanner.Text()
@ -58,6 +62,10 @@ func (socket *Socket) readLines(commands chan<- Command) {
Log.debug.Printf("%s error: %s", socket, err) Log.debug.Printf("%s error: %s", socket, err)
} }
commands <- &QuitCommand{
message: "connection closed",
}
close(commands) close(commands)
} }