3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-22 10:42:52 +01:00

upgrade go-ident to fix parsing issue

This commit is contained in:
Shivaram Lingamneni 2020-05-11 18:25:25 -04:00
parent b951546b77
commit d94a0aea9a
5 changed files with 28 additions and 27 deletions

2
go.mod
View File

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

2
go.sum
View File

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

View File

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

View File

@ -37,49 +37,46 @@ func (e ProtocolError) Error() string {
}
// Query makes an Ident query, if timeout is >0 the query is timed out after that many seconds.
func Query(ip string, portOnServer, portOnClient int, timeout float64) (Response, error) {
var (
conn net.Conn
err error
fields []string
r *bufio.Reader
resp string
)
func Query(ip string, portOnServer, portOnClient int, timeout time.Duration) (response Response, err error) {
var conn net.Conn
if timeout > 0 {
conn, err = net.DialTimeout("tcp", net.JoinHostPort(ip, "113"), time.Duration(timeout)*time.Second)
conn, err = net.DialTimeout("tcp", net.JoinHostPort(ip, "113"), timeout)
} else {
conn, err = net.Dial("tcp", net.JoinHostPort(ip, "113"))
}
if err != nil {
return Response{}, err
return
}
// stop the ident read after <timeout> seconds
if timeout > 0 {
conn.SetDeadline(time.Now().Add(time.Second * time.Duration(timeout)))
conn.SetDeadline(time.Now().Add(timeout))
}
_, err = conn.Write([]byte(fmt.Sprintf("%d, %d", portOnClient, portOnServer) + "\r\n"))
if err != nil {
return Response{}, err
return
}
r = bufio.NewReader(conn)
resp, err = r.ReadString('\n')
r := bufio.NewReaderSize(conn, 1024)
respBytes, err := r.ReadSlice('\n')
if err != nil {
return Response{}, err
return
}
resp := string(respBytes)
fields = strings.SplitN(strings.TrimSpace(resp), " : ", 4)
fields := strings.SplitN(resp, ":", 4)
if len(fields) < 3 {
return Response{}, ProtocolError{resp}
return response, ProtocolError{resp}
}
for i, field := range fields {
fields[i] = strings.TrimSpace(field)
}
switch fields[1] {
case "USERID":
if len(fields) != 4 {
return Response{}, ProtocolError{resp}
return response, ProtocolError{resp}
}
var os, charset string
@ -99,10 +96,12 @@ func Query(ip string, portOnServer, portOnClient int, timeout float64) (Response
}, nil
case "ERROR":
if len(fields) != 3 {
return Response{}, ProtocolError{resp}
return response, ProtocolError{resp}
}
return Response{}, ResponseError{fields[2]}
return response, ResponseError{fields[2]}
default:
err = ProtocolError{resp}
}
return Response{}, err
return
}

2
vendor/modules.txt vendored
View File

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