~samwhited/xmpp

2b0a46b19b15f9ba1ca0a1cf8f4dbcc1c041fdfc — Sam Whited 4 years ago 7719f94
Fix dial to use internal lookup functions
2 files changed, 7 insertions(+), 6 deletions(-)

M dial.go
M internal/lookup.go
M dial.go => dial.go +3 -2
@@ 10,6 10,7 @@ import (
	"strconv"
	"time"

	"mellium.im/xmpp/internal"
	"mellium.im/xmpp/jid"
)



@@ 72,7 73,7 @@ func (d *Dialer) Dial(ctx context.Context, network string, addr *jid.JID) (Conn,

func (d *Dialer) dial(ctx context.Context, network string, addr *jid.JID) (Conn, error) {
	if d.NoLookup {
		p, err := lookupPort(network, connType(d.S2S))
		p, err := internal.LookupPort(network, connType(d.S2S))
		if err != nil {
			return nil, err
		}


@@ 82,7 83,7 @@ func (d *Dialer) dial(ctx context.Context, network string, addr *jid.JID) (Conn,
		))
	}

	addrs, err := lookupService(connType(d.S2S), network, addr)
	addrs, err := internal.LookupService(connType(d.S2S), network, addr)
	if err != nil {
		return nil, err
	}

M internal/lookup.go => internal/lookup.go +4 -4
@@ 63,7 63,7 @@ var (
	}
)

func lookupPort(network, service string) (int, error) {
func LookupPort(network, service string) (int, error) {
	p, err := net.LookupPort(network, service)
	if err == nil {
		return p, err


@@ 79,11 79,11 @@ func lookupPort(network, service string) (int, error) {
	return 0, err
}

// lookupService looks for an XMPP service hosted by the given address. It
// LookupService looks for an XMPP service hosted by the given address. It
// returns addresses from SRV records or the default domain (as a fake SRV
// record) if no real records exist. Service should be one of "xmpp-client" or
// "xmpp-server".
func lookupService(service, network string, addr net.Addr) (addrs []*net.SRV, err error) {
func LookupService(service, network string, addr net.Addr) (addrs []*net.SRV, err error) {
	switch j := addr.(type) {
	case *jid.JID:
		addr = j.Domain()


@@ 104,7 104,7 @@ func lookupService(service, network string, addr net.Addr) (addrs []*net.SRV, er
	}

	// Use domain and default port.
	p, err := lookupPort(network, service)
	p, err := LookupPort(network, service)
	if err != nil {
		return nil, err
	}