~samwhited/xmpp

0b7a9e490e1ee65f65d4d35a2b01e5d28adaf20b — Sam Whited 5 years ago 766717c
Remove Go 1.6 support

By the time this is anywhere near complete Go 1.7 will be out anyways,
and for the purpose of development it's way easier to just stick to
using one version of the language. I'm not against adding 1.6 support
back later, and it should be trivial to do.
9 files changed, 51 insertions(+), 146 deletions(-)

M bitbucket-pipelines.yml
M conn.go
M dial.go
D dial1_6.go
D dial1_7.go
M features.go
M lookup.go
M lookup_test.go
M starttls.go
M bitbucket-pipelines.yml => bitbucket-pipelines.yml +1 -1
@@ 1,4 1,4 @@
image: golang:latest
image: golang:1.7
pipelines:
  default:
    - step:

M conn.go => conn.go +1 -2
@@ 5,13 5,12 @@
package xmpp

import (
	"context"
	"encoding/xml"
	"errors"
	"io"
	"net"
	"time"

	"golang.org/x/net/context"
)

// SessionState represents the current state of an XMPP session. For a

M dial.go => dial.go +45 -1
@@ 5,10 5,11 @@
package xmpp

import (
	"context"
	"net"
	"strconv"
	"time"

	"golang.org/x/net/context"
	"mellium.im/xmpp/jid"
)



@@ 122,3 123,46 @@ func (d *Dialer) Dial(

	return c, err
}

func (d *Dialer) dial(
	ctx context.Context, network string, config *Config) (*Conn, error) {
	if ctx == nil {
		panic("xmpp.Dial: nil context")
	}

	if d.NoLookup {
		p, err := lookupPort(network, config.connType())
		if err != nil {
			return nil, err
		}
		conn, err := d.Dialer.DialContext(ctx, network, net.JoinHostPort(
			config.Location.Domainpart(),
			strconv.FormatUint(uint64(p), 10),
		))
		if err != nil {
			return nil, err
		}
		return NewConn(ctx, config, conn)
	}

	addrs, err := lookupService(config.connType(), network, config.Location)
	if err != nil {
		return nil, err
	}

	// Try dialing all of the SRV records we know about, breaking as soon as the
	// connection is established.
	for _, addr := range addrs {
		if conn, e := d.Dialer.DialContext(
			ctx, network, net.JoinHostPort(
				addr.Target, strconv.FormatUint(uint64(addr.Port), 10),
			),
		); e != nil {
			err = e
			continue
		} else {
			return NewConn(ctx, config, conn)
		}
	}
	return nil, err
}

D dial1_6.go => dial1_6.go +0 -79
@@ 1,79 0,0 @@
// Copyright 2016 Sam Whited.
// Use of this source code is governed by the BSD 2-clause license that can be
// found in the LICENSE file.

// +build !go1.7

package xmpp

import (
	"net"
	"strconv"
	"time"

	"golang.org/x/net/context"
)

func (d *Dialer) dial(
	ctx context.Context, network string, config *Config) (*Conn, error) {
	if ctx == nil {
		panic("xmpp.Dial: nil context")
	}

	// Backwards compatibility with old net.Dialer cancelation methods.
	deadline := d.deadline(ctx, time.Now())
	if !deadline.IsZero() {
		if d, ok := ctx.Deadline(); !ok || deadline.Before(d) {
			subCtx, cancel := context.WithDeadline(ctx, deadline)
			defer cancel()
			ctx = subCtx
		}
	}
	if oldCancel := d.Cancel; oldCancel != nil {
		subCtx, cancel := context.WithCancel(ctx)
		defer cancel()
		go func() {
			select {
			case <-oldCancel:
				cancel()
			case <-subCtx.Done():
			}
		}()
		ctx = subCtx
	}

	if d.NoLookup {
		p, err := lookupPort(network, config.connType())
		if err != nil {
			return nil, err
		}
		conn, err := d.Dialer.Dial(network, net.JoinHostPort(
			config.Location.Domainpart(),
			strconv.FormatUint(uint64(p), 10),
		))
		if err != nil {
			return nil, err
		}
		return NewConn(ctx, config, conn)
	}

	addrs, err := lookupService(config.connType(), network, config.Location)
	if err != nil {
		return nil, err
	}

	// Try dialing all of the SRV records we know about, breaking as soon as the
	// connection is established.
	for _, addr := range addrs {
		if conn, e := d.Dialer.Dial(network, net.JoinHostPort(
			addr.Target, strconv.FormatUint(uint64(addr.Port), 10),
		),
		); e != nil {
			err = e
			continue
		} else {
			return NewConn(ctx, config, conn)
		}
	}
	return nil, err
}

D dial1_7.go => dial1_7.go +0 -56
@@ 1,56 0,0 @@
// Copyright 2016 Sam Whited.
// Use of this source code is governed by the BSD 2-clause license that can be
// found in the LICENSE file.

// +build go1.7

package xmpp

import (
	"context"
	"net"
	"strconv"
)

func (d *Dialer) dial(
	ctx context.Context, network string, config *Config) (*Conn, error) {
	if ctx == nil {
		panic("xmpp.Dial: nil context")
	}

	if d.NoLookup {
		p, err := lookupPort(network, config.connType())
		if err != nil {
			return nil, err
		}
		conn, err := d.Dialer.DialContext(ctx, network, net.JoinHostPort(
			config.Location.Domainpart(),
			strconv.FormatUint(uint64(p), 10),
		))
		if err != nil {
			return nil, err
		}
		return NewConn(ctx, config, conn)
	}

	addrs, err := lookupService(config.connType(), network, config.Location)
	if err != nil {
		return nil, err
	}

	// Try dialing all of the SRV records we know about, breaking as soon as the
	// connection is established.
	for _, addr := range addrs {
		if conn, e := d.Dialer.DialContext(
			ctx, network, net.JoinHostPort(
				addr.Target, strconv.FormatUint(uint64(addr.Port), 10),
			),
		); e != nil {
			err = e
			continue
		} else {
			return NewConn(ctx, config, conn)
		}
	}
	return nil, err
}

M features.go => features.go +1 -2
@@ 5,9 5,8 @@
package xmpp

import (
	"context"
	"encoding/xml"

	"golang.org/x/net/context"
)

// A StreamFeature represents a feature that may be selected during stream

M lookup.go => lookup.go +1 -1
@@ 5,6 5,7 @@
package xmpp

import (
	"context"
	"encoding/xml"
	"errors"
	"net"


@@ 14,7 15,6 @@ import (
	"strings"
	"sync"

	"golang.org/x/net/context"
	"golang.org/x/net/context/ctxhttp"
	"mellium.im/xmpp/internal"
	"mellium.im/xmpp/jid"

M lookup_test.go => lookup_test.go +1 -2
@@ 5,9 5,8 @@
package xmpp

import (
	"context"
	"testing"

	"golang.org/x/net/context"
)

// If an invalid connection type is looked up, we should panic.

M starttls.go => starttls.go +1 -2
@@ 5,9 5,8 @@
package xmpp

import (
	"context"
	"encoding/xml"

	"golang.org/x/net/context"
)

// StartTLS returns a new stream feature that can be used for negotiating TLS.