Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ortuman committed Mar 16, 2019
1 parent e345df1 commit 16b13b3
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ os:
- osx

go:
- 1.11.x
- 1.12.x

before_script:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-darwin-amd64 > ./cc-test-reporter; fi
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
# Please keep the list sorted.

Miguel Ángel Ortuño <ortuman@pm.me>
Robert Nasiadek <robert.nasiadek@cryptopunks.cc>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jackal supports the following features:

### Getting Started

To start using jackal, install Go 1.11+ and run the following commands:
To start using jackal, install Go 1.12+ and run the following commands:

```bash
$ go get -d github.com/ortuman/jackal
Expand Down
30 changes: 30 additions & 0 deletions router/error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2018 Miguel Ángel Ortuño.
* See the LICENSE file for more information.
*/

package router

import "github.com/pkg/errors"

var (
// ErrNotExistingAccount will be returned by Route method
// if destination user does not exist.
ErrNotExistingAccount = errors.New("router: account does not exist")

// ErrResourceNotFound will be returned by Route method
// if destination resource does not match any of user's available resources.
ErrResourceNotFound = errors.New("router: resource not found")

// ErrNotAuthenticated will be returned by Route method if
// destination user is not available at this moment.
ErrNotAuthenticated = errors.New("router: user not authenticated")

// ErrBlockedJID will be returned by Route method if
// destination jid matches any of the user's blocked jid.
ErrBlockedJID = errors.New("router: destination jid is blocked")

// ErrFailedRemoteConnect will be returned by Route method if
// couldn't establish a connection to the remote server.
ErrFailedRemoteConnect = errors.New("router: failed remote connection")
)
23 changes: 0 additions & 23 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package router

import (
"crypto/tls"
"errors"
"runtime"
"sync"

Expand All @@ -25,28 +24,6 @@ const defaultDomain = "localhost"

var bindMsgBatchSize = 1024

var (
// ErrNotExistingAccount will be returned by Route method
// if destination user does not exist.
ErrNotExistingAccount = errors.New("router: account does not exist")

// ErrResourceNotFound will be returned by Route method
// if destination resource does not match any of user's available resources.
ErrResourceNotFound = errors.New("router: resource not found")

// ErrNotAuthenticated will be returned by Route method if
// destination user is not available at this moment.
ErrNotAuthenticated = errors.New("router: user not authenticated")

// ErrBlockedJID will be returned by Route method if
// destination jid matches any of the user's blocked jid.
ErrBlockedJID = errors.New("router: destination jid is blocked")

// ErrFailedRemoteConnect will be returned by Route method if
// couldn't establish a connection to the remote server.
ErrFailedRemoteConnect = errors.New("router: failed remote connection")
)

// OutS2SProvider provides a specific s2s outgoing connection for every single
// pair of (localdomain, remotedomain) values.
type OutS2SProvider interface {
Expand Down
10 changes: 6 additions & 4 deletions s2s/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"
"time"

"github.com/ortuman/jackal/log"
"github.com/ortuman/jackal/router"
"github.com/ortuman/jackal/transport"
)
Expand All @@ -30,15 +31,16 @@ func newDialer(cfg *Config, router *router.Router) *dialer {
func (d *dialer) dial(localDomain, remoteDomain string) (*streamConfig, error) {
_, addrs, err := d.srvResolve("xmpp-server", "tcp", remoteDomain)
if err != nil {
return nil, err
log.Warnf("srv lookup error: %v", err)
}
var target string
if len(addrs) == 1 && addrs[0].Target == "." {

if err != nil || len(addrs) == 1 && addrs[0].Target == "." {
target = remoteDomain + ":5269"
} else {
target = strings.TrimSuffix(addrs[0].Target, ".")
target = strings.TrimSuffix(addrs[0].Target, ".") + ":" + strconv.Itoa(int(addrs[0].Port))
}
conn, err := d.dialTimeout("tcp", target+":"+strconv.Itoa(int(addrs[0].Port)), d.cfg.DialTimeout)
conn, err := d.dialTimeout("tcp", target, d.cfg.DialTimeout)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions s2s/dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func TestS2SDial(t *testing.T) {
return "", nil, mockedErr
}
out, err := d.dial("jackal.im", "jabber.org")
require.Nil(t, out)
require.Equal(t, mockedErr, err)
require.NotNil(t, out)
require.Nil(t, err)

// dialer error...
d.srvResolve = func(service, proto, name string) (cname string, addrs []*net.SRV, err error) {
Expand Down
21 changes: 0 additions & 21 deletions s2s/in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/ortuman/jackal/xmpp"
"github.com/ortuman/jackal/xmpp/jid"
"github.com/pborman/uuid"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -233,26 +232,6 @@ func TestStream_DialbackAuthorize(t *testing.T) {
require.NotNil(t, elem.Elements().Child("error").Elements().Child("item-not-found"))

cfg, conn := tUtilInStreamDefaultConfig(t, false)
cfg.dialer = &dialer{router: r}
cfg.dialer.srvResolve = func(_, _, _ string) (cname string, addrs []*net.SRV, err error) {
return "", nil, errors.New("mocked dialer error")
}
stm = newInStream(cfg, &module.Modules{}, r)

tUtilInStreamOpen(conn)
_ = conn.outboundRead() // read stream opening...
_ = conn.outboundRead() // read stream features...
atomic.StoreUint32(&stm.secured, 1)
atomic.StoreUint32(&stm.authenticated, 1)

conn.inboundWriteString(`<db:result to="jackal.im">abcd</db:result>`)
elem = conn.outboundRead()
require.Equal(t, "db:result", elem.Name())
require.Equal(t, xmpp.ErrorType, elem.Type())
require.NotNil(t, elem.Elements().Child("error"))
require.NotNil(t, elem.Elements().Child("error").Elements().Child("remote-server-not-found"))

cfg, conn = tUtilInStreamDefaultConfig(t, false)
cfg.dialer = &dialer{cfg: &Config{DialTimeout: time.Second}, router: r}
cfg.dialer.srvResolve = func(_, _, _ string) (cname string, addrs []*net.SRV, err error) {
return "", []*net.SRV{{Target: "jackal.im", Port: 5269}}, nil
Expand Down
11 changes: 10 additions & 1 deletion session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package session

import (
"bytes"
stdxml "encoding/xml"
"fmt"
"io"
Expand Down Expand Up @@ -75,6 +76,7 @@ type Config struct {
type Session struct {
id string
router *router.Router
wrBuff *bytes.Buffer
tr transport.Transport
pr *xmpp.Parser
remoteDomain string
Expand Down Expand Up @@ -102,6 +104,7 @@ func New(id string, config *Config, router *router.Router) *Session {
router: router,
tr: config.Transport,
pr: xmpp.NewParser(config.Transport, parsingMode, config.MaxStanzaSize),
wrBuff: bytes.NewBuffer(make([]byte, 0, 1024)),
remoteDomain: config.RemoteDomain,
isServer: config.IsServer,
isInitiating: config.IsInitiating,
Expand Down Expand Up @@ -207,7 +210,13 @@ func (s *Session) Send(elem xmpp.XElement) {
e.SetNamespace("")
}
log.Debugf("SEND(%s): %v", s.id, elem)
elem.ToXML(s.tr, true)

elem.ToXML(s.wrBuff, true)
_, err := io.Copy(s.tr, s.wrBuff)
if err != nil {
log.Warnf("%v", err)
}
s.wrBuff.Reset()
}

// Receive returns next incoming session element.
Expand Down

0 comments on commit 16b13b3

Please sign in to comment.