~samwhited/xmpp

dce8d13b0614b54c4fe8526cc03c617526685a35 — Sam Whited 5 years ago 19a23c2
Make lookupWebsocketDNS cancelable
1 files changed, 9 insertions(+), 3 deletions(-)

M lookup.go
M lookup.go => lookup.go +9 -3
@@ 40,7 40,9 @@ var (
// func LookupWebsocket(addr *jid.JID) {
// }

func lookupWebsocketDNS(name string) (urls []string, err error) {
// TODO(ssw): Rely on the OS DNS cache, or cache lookups ourselves?

func lookupWebsocketDNS(ctx context.Context, name string) (urls []string, err error) {
	txts, err := net.LookupTXT(name)
	if err != nil {
		return urls, err


@@ 48,6 50,9 @@ func lookupWebsocketDNS(name string) (urls []string, err error) {

	var s string
	for _, txt := range txts {
		if _, ok := <-ctx.Done(); ok {
			return urls, ctx.Err()
		}
		if s = strings.TrimPrefix(txt, wsPrefix); s != txt {
			urls = append(urls, s)
		}


@@ 56,8 61,9 @@ func lookupWebsocketDNS(name string) (urls []string, err error) {
	return urls, err
}

func lookupWebsocketHostMeta(ctx context.Context, name string) (urls []string, err error) {
	client := &http.Client{}
// TODO(ssw): Memoize the following functions?

func lookupWebsocketHostMeta(ctx context.Context, client *http.Client, name string) (urls []string, err error) {
	url, err := url.Parse(name)
	if err != nil {
		return urls, err