A dial/LICENSE-GO => dial/LICENSE-GO +27 -0
@@ 0,0 1,27 @@
+Copyright (c) 2009 The Go Authors. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with the
+distribution.
+ * Neither the name of Google Inc. nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
R dial.go => dial/dial.go +8 -9
@@ 2,7 2,8 @@
// Use of this source code is governed by the BSD 2-clause
// license that can be found in the LICENSE file.
-package xmpp
+// Package dial contains methods and types for dialing XMPP connections.
+package dial
import (
"context"
@@ 15,20 16,20 @@ import (
"mellium.im/xmpp/jid"
)
-// DialClient discovers and connects to the address on the named network with a
+// Client discovers and connects to the address on the named network with a
// client-to-server (c2s) connection.
//
// For more information see the Dialer type.
-func DialClient(ctx context.Context, network string, addr jid.JID) (net.Conn, error) {
+func Client(ctx context.Context, network string, addr jid.JID) (net.Conn, error) {
var d Dialer
return d.Dial(ctx, network, addr)
}
-// DialServer discovers and connects to the address on the named network with a
+// Server discovers and connects to the address on the named network with a
// server-to-server connection (s2s).
//
// For more info see the Dialer type.
-func DialServer(ctx context.Context, network string, addr jid.JID) (net.Conn, error) {
+func Server(ctx context.Context, network string, addr jid.JID) (net.Conn, error) {
d := Dialer{
S2S: true,
}
@@ 40,7 41,7 @@ func DialServer(ctx context.Context, network string, addr jid.JID) (net.Conn, er
// an XMPP session on the connection.
//
// The zero value for each field is equivalent to dialing without that option.
-// Dialing with the zero value of Dialer is equivalent to calling the DialClient
+// Dialing with the zero value of Dialer is equivalent to calling the Client
// function.
type Dialer struct {
net.Dialer
@@ 77,8 78,6 @@ type Dialer struct {
// Network may be any of the network types supported by net.Dial, but you most
// likely want to use one of the tcp connection types ("tcp", "tcp4", or
// "tcp6").
-//
-// For more information see the Dialer type.
func (d *Dialer) Dial(ctx context.Context, network string, addr jid.JID) (net.Conn, error) {
return d.dial(ctx, network, addr)
}
@@ 164,7 163,7 @@ func (d *Dialer) dial(ctx context.Context, network string, addr jid.JID) (net.Co
}
// Copied from the net package in the standard library. Copyright The Go
-// Authors.
+// Authors. See LICENSE-GO.
func minNonzeroTime(a, b time.Time) time.Time {
if a.IsZero() {
return b
R dial_test.go => dial/dial_test.go +2 -2
@@ 2,7 2,7 @@
// Use of this source code is governed by the BSD 2-clause
// license that can be found in the LICENSE file.
-package xmpp
+package dial
import (
"strconv"
@@ 17,7 17,7 @@ func TestDialClientPanicsIfNilContext(t *testing.T) {
t.Error("Expected Dial to panic when passed a nil context.")
}
}()
- DialClient(nil, "tcp", jid.MustParse("feste@shakespeare.lit"))
+ Client(nil, "tcp", jid.MustParse("feste@shakespeare.lit"))
}
var connTypeTests = [...]struct {
M doc.go => doc.go +3 -3
@@ 20,7 20,6 @@
// These methods use sane defaults to dial a TCP connection and perform stream
// negotiation.
//
-//
// session, err := xmpp.DialClientSession(
// context.TODO(), addr,
// xmpp.BindResource(),
@@ 29,12 28,13 @@
// )
//
// If control over DNS or HTTP-based service discovery is desired, the user can
-// create a Dialer or use DialClient (c2s) or DialServer (s2s).
+// use the dial package to create a dial.Dialer or use dial.Client (c2s) or
+// dial.Server (s2s).
// To use the resulting connection, or to use something other than a TCP
// connection (eg. to communicate over a Unix domain socket, an in-memory pipe,
// etc.) the connection can be passed to NewClientSession or NewServerSession.
//
-// conn, err := xmpp.DialClient(context.TODO(), "tcp", addr)
+// conn, err := dial.Client(context.TODO(), "tcp", addr)
// …
// session, err := xmpp.NewClientSession(
// context.TODO(), addr, conn,
M session.go => session.go +3 -2
@@ 16,6 16,7 @@ import (
"time"
"mellium.im/xmlstream"
+ "mellium.im/xmpp/dial"
"mellium.im/xmpp/internal"
"mellium.im/xmpp/internal/ns"
"mellium.im/xmpp/jid"
@@ 176,7 177,7 @@ func NegotiateSession(ctx context.Context, location, origin jid.JID, rw io.ReadW
// If the provided context is canceled after stream negotiation is complete it
// has no effect on the session.
func DialClientSession(ctx context.Context, origin jid.JID, features ...StreamFeature) (*Session, error) {
- conn, err := DialClient(ctx, "tcp", origin)
+ conn, err := dial.Client(ctx, "tcp", origin)
if err != nil {
return nil, err
}
@@ 189,7 190,7 @@ func DialClientSession(ctx context.Context, origin jid.JID, features ...StreamFe
// If the provided context is canceled after stream negotiation is complete it
// has no effect on the session.
func DialServerSession(ctx context.Context, location, origin jid.JID, features ...StreamFeature) (*Session, error) {
- conn, err := DialServer(ctx, "tcp", location)
+ conn, err := dial.Server(ctx, "tcp", location)
if err != nil {
return nil, err
}