diff --git a/src/connection/connect.jl b/src/connection/connect.jl index f905d0aa..62228203 100644 --- a/src/connection/connect.jl +++ b/src/connection/connect.jl @@ -26,6 +26,8 @@ function default_connect_options() end function validate_connect_options(server_info::Info, options) + # TODO: check if proto is 1 when `echo` flag is set + # TODO: maybe better to rely on server side validation. Grab Err messages and decide if conn should be terminated. server_info.proto > 0 || error("Server supports too old protocol version.") server_info.headers || error("Server does not support headers.") # TODO: maybe this can be relaxed. @@ -127,22 +129,20 @@ end """ connect([host, port; options...]) -Connect to NATS server. - -Connect is a blocking operation that initiazlies connection. +Connect to NATS server. The function is blocking until connection is initialized. Options are: -- `default`: sets connection as a default connection. Default connection is used when no connection is specified. -- `reconnect_delays`: vector of delays that reconnect is performed until connected again. Default is $RECONNECT_DELAYS. -- `outbox_size`: size of outbox buffer for cient messages. Default is $OUTBOX_SIZE. If to small operations may throw exceptions. -- `verbose: turns on `+OK` protocol acknowledgements +- `default`: boolean flag that indicated if a connection should be set as default which will be used when no connection specified +- `reconnect_delays`: vector of delays that reconnect is performed until connected again. Default is $RECONNECT_DELAYS +- `outbox_size`: size of outbox buffer for cient messages. Default is $OUTBOX_SIZE, if to small operations that send messages to server (e.g. `publish`) may throw an exception +- `verbose: turns on protocol acknowledgements - `pedantic: turns on additional strict format checking, e.g. for properly formed subjects - `tls_required: indicates whether the client requires an SSL connection - `auth_token`: client authorization token - `user`: connection username - `pass`: connection password - `name`: client name -- `echo`: if set to `false`, the server (version 1.2.0+) will not send originating messages from this connection to its own subscriptions. Clients should set this to `false` only for server supporting this feature, which is when `proto` in the `INFO` protocol is set to at least `1` +- `echo`: if set to `false`, the server will not send originating messages from this connection to its own subscriptions - `jwt`: the JWT that identifies a user permissions and account. - `no_responders`: enable quick replies for cases where a request is sent to a topic with no responders. - `headers`: whether the client supports headers diff --git a/src/connection/connection.jl b/src/connection/connection.jl index e4b047e2..184f1345 100644 --- a/src/connection/connection.jl +++ b/src/connection/connection.jl @@ -95,7 +95,6 @@ end include("utils.jl") include("tls.jl") -include("nkeys.jl") include("send.jl") include("handlers.jl") include("drain.jl") diff --git a/src/connection/drain.jl b/src/connection/drain.jl index 62fafbf2..41135b13 100644 --- a/src/connection/drain.jl +++ b/src/connection/drain.jl @@ -10,6 +10,7 @@ function drain(nc::Connection) for (_, sub) in nc.subs unsubscribe(sub; max_msgs = 0, connection = nc) end + # TODO: wait for handlers running == 0 sleep(3) length(nc.subs) > 0 && @warn "$(length(nc.subs)) not unsubscribed during drain." status(nc, DRAINED) diff --git a/src/connection/nkeys.jl b/src/protocol/nkeys.jl similarity index 100% rename from src/connection/nkeys.jl rename to src/protocol/nkeys.jl diff --git a/src/protocol/protocol.jl b/src/protocol/protocol.jl index 442ff02e..309ae16e 100644 --- a/src/protocol/protocol.jl +++ b/src/protocol/protocol.jl @@ -7,3 +7,4 @@ include("payload.jl") include("headers.jl") include("convert.jl") include("show.jl") +include("nkeys.jl") diff --git a/test/connection.jl b/test/connection.jl index 262169fc..dfd90df6 100644 --- a/test/connection.jl +++ b/test/connection.jl @@ -125,22 +125,6 @@ end @test_throws "Client requires TLS but it is not available for the server." NATS.connect(default = false, tls_required = true) end - -@testset "Nonce signatures" begin - seed = "SUAJ4LZRG3KF7C7U4E5737YMAOGUAWBODUM6DBWLY4UPUMXH6TH7JLQFDM" - nkey = "UAGPV4UFVS34M2XGY7HLSNEBDVJZZDZ6XMQ4NTXVEMKZQNSFH2AJFUA5" - nonce = "XTdilcu9paonaBQ" - sig = "3tsErI9fNKHWOHLAbc_XQ8Oo3XHv__7I_fA1aQ7xod3gYpxhDzt1vItbQLv3FhDtDFycxJJ0wA26rG3NEwWZBg" - @test NATS.sign(nonce, seed) == sig - - seed = "SUADPKZWX3XJQO4GJEX2IGZAKCYUSLSLNJXFG7KPAYAODEVABRK6ZKKALA" - nkey= "UDBKUC5JFUX5SDF6CGBT3WAZEZSJTGMWWSCRJMODEUPVOKBPCLVODH2J" - nonce = "HiA_hND1AV-DjmM" - sig = "g4HDazX_ZZig_FOFBzhorLSYCEDRlv20Y5vErFjDlTRZMqaaF27ImP16es_GI83Fn59xr9V98Ux5GlEvvaeADQ" - @test NATS.sign(nonce, seed) == sig -end - - @testset "Subscription warnings" begin nc = NATS.connect() diff --git a/test/protocol.jl b/test/protocol.jl index 5bf20dae..c90268b0 100644 --- a/test/protocol.jl +++ b/test/protocol.jl @@ -87,3 +87,17 @@ end @test String(repr(MIME_HEADERS(), ["A" => "B"])) == "NATS/1.0\r\nA: B\r\n\r\n" @test String(repr(MIME_HEADERS(), (nothing, nothing))) == "" end + +@testset "Nonce signatures" begin + seed = "SUAJ4LZRG3KF7C7U4E5737YMAOGUAWBODUM6DBWLY4UPUMXH6TH7JLQFDM" + nkey = "UAGPV4UFVS34M2XGY7HLSNEBDVJZZDZ6XMQ4NTXVEMKZQNSFH2AJFUA5" + nonce = "XTdilcu9paonaBQ" + sig = "3tsErI9fNKHWOHLAbc_XQ8Oo3XHv__7I_fA1aQ7xod3gYpxhDzt1vItbQLv3FhDtDFycxJJ0wA26rG3NEwWZBg" + @test NATS.sign(nonce, seed) == sig + + seed = "SUADPKZWX3XJQO4GJEX2IGZAKCYUSLSLNJXFG7KPAYAODEVABRK6ZKKALA" + nkey= "UDBKUC5JFUX5SDF6CGBT3WAZEZSJTGMWWSCRJMODEUPVOKBPCLVODH2J" + nonce = "HiA_hND1AV-DjmM" + sig = "g4HDazX_ZZig_FOFBzhorLSYCEDRlv20Y5vErFjDlTRZMqaaF27ImP16es_GI83Fn59xr9V98Ux5GlEvvaeADQ" + @test NATS.sign(nonce, seed) == sig +end \ No newline at end of file