瀏覽代碼

upgrade go-ident to fix parsing issue

tags/v2.1.0-rc1
Shivaram Lingamneni 4 年之前
父節點
當前提交
d94a0aea9a
共有 5 個檔案被更改,包括 28 行新增27 行删除
  1. 1
    1
      go.mod
  2. 2
    0
      go.sum
  3. 3
    3
      irc/client.go
  4. 21
    22
      vendor/github.com/oragono/go-ident/client.go
  5. 1
    1
      vendor/modules.txt

+ 1
- 1
go.mod 查看文件

@@ -13,7 +13,7 @@ require (
13 13
 	github.com/onsi/ginkgo v1.12.0 // indirect
14 14
 	github.com/onsi/gomega v1.9.0 // indirect
15 15
 	github.com/oragono/confusables v0.0.0-20190624102032-fe1cf31a24b0
16
-	github.com/oragono/go-ident v0.0.0-20170110123031-337fed0fd21a
16
+	github.com/oragono/go-ident v0.0.0-20200511222032-830550b1d775
17 17
 	github.com/stretchr/testify v1.4.0 // indirect
18 18
 	github.com/tidwall/buntdb v1.1.2
19 19
 	github.com/toorop/go-dkim v0.0.0-20191019073156-897ad64a2eeb

+ 2
- 0
go.sum 查看文件

@@ -46,6 +46,8 @@ github.com/oragono/confusables v0.0.0-20190624102032-fe1cf31a24b0 h1:4qw57EiWD2M
46 46
 github.com/oragono/confusables v0.0.0-20190624102032-fe1cf31a24b0/go.mod h1:+uesPRay9e5tW6zhw4CJkRV3QOEbbZIJcsuo9ZnC+hE=
47 47
 github.com/oragono/go-ident v0.0.0-20170110123031-337fed0fd21a h1:tZApUffT5QuX4XhJLz2KfBJT8JgdwjLUBWtvmRwgFu4=
48 48
 github.com/oragono/go-ident v0.0.0-20170110123031-337fed0fd21a/go.mod h1:r5Fk840a4eu3ii1kxGDNSJupQu9Z1UC1nfJOZZXC24c=
49
+github.com/oragono/go-ident v0.0.0-20200511222032-830550b1d775 h1:AMAsAn/i4AgsmWQYdMoze9omwtHpbxrKuT+AT1LmhtI=
50
+github.com/oragono/go-ident v0.0.0-20200511222032-830550b1d775/go.mod h1:r5Fk840a4eu3ii1kxGDNSJupQu9Z1UC1nfJOZZXC24c=
49 51
 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
50 52
 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
51 53
 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

+ 3
- 3
irc/client.go 查看文件

@@ -27,8 +27,8 @@ import (
27 27
 )
28 28
 
29 29
 const (
30
-	// IdentTimeoutSeconds is how many seconds before our ident (username) check times out.
31
-	IdentTimeoutSeconds  = 1.5
30
+	// IdentTimeout is how long before our ident (username) check times out.
31
+	IdentTimeout         = time.Second + 500*time.Millisecond
32 32
 	IRCv3TimestampFormat = utils.IRCv3TimestampFormat
33 33
 )
34 34
 
@@ -483,7 +483,7 @@ func (client *Client) doIdentLookup(conn net.Conn) {
483 483
 	clientPort := remoteTCPAddr.Port
484 484
 
485 485
 	client.Notice(client.t("*** Looking up your username"))
486
-	resp, err := ident.Query(remoteTCPAddr.IP.String(), serverPort, clientPort, IdentTimeoutSeconds)
486
+	resp, err := ident.Query(remoteTCPAddr.IP.String(), serverPort, clientPort, IdentTimeout)
487 487
 	if err == nil {
488 488
 		err := client.SetNames(resp.Identifier, "", true)
489 489
 		if err == nil {

+ 21
- 22
vendor/github.com/oragono/go-ident/client.go 查看文件

@@ -37,49 +37,46 @@ func (e ProtocolError) Error() string {
37 37
 }
38 38
 
39 39
 // Query makes an Ident query, if timeout is >0 the query is timed out after that many seconds.
40
-func Query(ip string, portOnServer, portOnClient int, timeout float64) (Response, error) {
41
-	var (
42
-		conn   net.Conn
43
-		err    error
44
-		fields []string
45
-		r      *bufio.Reader
46
-		resp   string
47
-	)
48
-
40
+func Query(ip string, portOnServer, portOnClient int, timeout time.Duration) (response Response, err error) {
41
+	var conn net.Conn
49 42
 	if timeout > 0 {
50
-		conn, err = net.DialTimeout("tcp", net.JoinHostPort(ip, "113"), time.Duration(timeout)*time.Second)
43
+		conn, err = net.DialTimeout("tcp", net.JoinHostPort(ip, "113"), timeout)
51 44
 	} else {
52 45
 		conn, err = net.Dial("tcp", net.JoinHostPort(ip, "113"))
53 46
 	}
54 47
 	if err != nil {
55
-		return Response{}, err
48
+		return
56 49
 	}
57 50
 
58 51
 	// stop the ident read after <timeout> seconds
59 52
 	if timeout > 0 {
60
-		conn.SetDeadline(time.Now().Add(time.Second * time.Duration(timeout)))
53
+		conn.SetDeadline(time.Now().Add(timeout))
61 54
 	}
62 55
 
63 56
 	_, err = conn.Write([]byte(fmt.Sprintf("%d, %d", portOnClient, portOnServer) + "\r\n"))
64 57
 	if err != nil {
65
-		return Response{}, err
58
+		return
66 59
 	}
67 60
 
68
-	r = bufio.NewReader(conn)
69
-	resp, err = r.ReadString('\n')
61
+	r := bufio.NewReaderSize(conn, 1024)
62
+	respBytes, err := r.ReadSlice('\n')
70 63
 	if err != nil {
71
-		return Response{}, err
64
+		return
72 65
 	}
66
+	resp := string(respBytes)
73 67
 
74
-	fields = strings.SplitN(strings.TrimSpace(resp), " : ", 4)
68
+	fields := strings.SplitN(resp, ":", 4)
75 69
 	if len(fields) < 3 {
76
-		return Response{}, ProtocolError{resp}
70
+		return response, ProtocolError{resp}
71
+	}
72
+	for i, field := range fields {
73
+		fields[i] = strings.TrimSpace(field)
77 74
 	}
78 75
 
79 76
 	switch fields[1] {
80 77
 	case "USERID":
81 78
 		if len(fields) != 4 {
82
-			return Response{}, ProtocolError{resp}
79
+			return response, ProtocolError{resp}
83 80
 		}
84 81
 
85 82
 		var os, charset string
@@ -99,10 +96,12 @@ func Query(ip string, portOnServer, portOnClient int, timeout float64) (Response
99 96
 		}, nil
100 97
 	case "ERROR":
101 98
 		if len(fields) != 3 {
102
-			return Response{}, ProtocolError{resp}
99
+			return response, ProtocolError{resp}
103 100
 		}
104 101
 
105
-		return Response{}, ResponseError{fields[2]}
102
+		return response, ResponseError{fields[2]}
103
+	default:
104
+		err = ProtocolError{resp}
106 105
 	}
107
-	return Response{}, err
106
+	return
108 107
 }

+ 1
- 1
vendor/modules.txt 查看文件

@@ -30,7 +30,7 @@ github.com/goshuirc/irc-go/ircmsg
30 30
 # github.com/oragono/confusables v0.0.0-20190624102032-fe1cf31a24b0
31 31
 ## explicit
32 32
 github.com/oragono/confusables
33
-# github.com/oragono/go-ident v0.0.0-20170110123031-337fed0fd21a
33
+# github.com/oragono/go-ident v0.0.0-20200511222032-830550b1d775
34 34
 ## explicit
35 35
 github.com/oragono/go-ident
36 36
 # github.com/stretchr/testify v1.4.0

Loading…
取消
儲存