Use default port for leafnode remote if not specified

Signed-off-by: Derek Collison <derek@nats.io>
This commit is contained in:
Derek Collison
2019-06-29 17:50:21 -07:00
parent 7d11d9288f
commit 100d0d2b02
3 changed files with 35 additions and 0 deletions

View File

@@ -143,6 +143,9 @@ const (
// DEFAULT_LEAFNODE_INFO_WAIT Route dial timeout.
DEFAULT_LEAFNODE_INFO_WAIT = 1 * time.Second
// DEFAULT_LEAFNODE_PORT is the default port for remote leafnode connections.
DEFAULT_LEAFNODE_PORT = 7422
// DEFAULT_CONNECT_ERROR_REPORTS is the number of attempts at which a
// repeated failed route, gateway or leaf node connection is reported.
// This is used for initial connection, that is, when the server has

View File

@@ -2432,10 +2432,18 @@ func setBaselineOptions(opts *Options) {
opts.LeafNode.AuthTimeout = float64(AUTH_TIMEOUT) / float64(time.Second)
}
}
// Set baseline connect port for remotes.
for _, r := range opts.LeafNode.Remotes {
if r != nil && r.URL.Port() == "" {
r.URL.Host = fmt.Sprintf("%s:%d", r.URL.Host, DEFAULT_LEAFNODE_PORT)
}
}
// Set this regardless of opts.LeafNode.Port
if opts.LeafNode.ReconnectInterval == 0 {
opts.LeafNode.ReconnectInterval = DEFAULT_LEAF_NODE_RECONNECT
}
if opts.MaxControlLine == 0 {
opts.MaxControlLine = MAX_CONTROL_LINE_SIZE
}

View File

@@ -2330,3 +2330,27 @@ func TestLeafNodeDistributedQueueEvenly(t *testing.T) {
}
}
}
func TestLeafNodeDefaultPort(t *testing.T) {
o := testDefaultOptionsForLeafNodes()
o.LeafNode.Port = server.DEFAULT_LEAFNODE_PORT
s := RunServer(o)
defer s.Shutdown()
conf := createConfFile(t, []byte(`
port: -1
leaf {
remotes = [
{
url: "leafnode://127.0.0.1"
}
]
}
`))
defer os.Remove(conf)
sl, _ := RunServerWithConfig(conf)
defer sl.Shutdown()
checkLeafNodeConnected(t, s)
}