Expose setting auth level on outgoing connection

This is necessary to allow a remote to issue authenticated commands back
to us.
This commit is contained in:
Jason Rhinelander 2023-03-08 16:58:37 -04:00
parent 30a9a26ea7
commit 6e50822bc9
No known key found for this signature in database
GPG Key ID: C4992CE7A88D4262
2 changed files with 28 additions and 11 deletions

View File

@ -3,7 +3,7 @@ from setuptools import setup
# Available at setup time due to pyproject.toml # Available at setup time due to pyproject.toml
from pybind11.setup_helpers import Pybind11Extension, build_ext from pybind11.setup_helpers import Pybind11Extension, build_ext
__version__ = "1.0.3" __version__ = "1.0.4"
# Note: # Note:
# Sort input source files if you glob sources to ensure bit-for-bit # Sort input source files if you glob sources to ensure bit-for-bit

View File

@ -622,28 +622,34 @@ permissions: in this example, the required permissions the access the endpoint w
OxenMQ::ConnectSuccess on_success, OxenMQ::ConnectSuccess on_success,
OxenMQ::ConnectFailure on_failure, OxenMQ::ConnectFailure on_failure,
std::chrono::milliseconds timeout, std::chrono::milliseconds timeout,
std::optional<bool> ephemeral_routing_id) { std::optional<bool> ephemeral_routing_id,
AuthLevel auth_level) {
return self.connect_remote(remote, std::move(on_success), std::move(on_failure), return self.connect_remote(remote, std::move(on_success), std::move(on_failure),
connect_option::timeout{timeout}, connect_option::timeout{timeout},
connect_option::ephemeral_routing_id{ephemeral_routing_id.value_or(self.EPHEMERAL_ROUTING_ID)} connect_option::ephemeral_routing_id{ephemeral_routing_id.value_or(self.EPHEMERAL_ROUTING_ID)},
auth_level
); );
}, },
"remote"_a, "on_success"_a, "on_failure"_a, "remote"_a, "on_success"_a, "on_failure"_a,
kwonly, kwonly,
"timeout"_a = oxenmq::REMOTE_CONNECT_TIMEOUT, "ephemeral_routing_id"_a = std::nullopt, "timeout"_a = oxenmq::REMOTE_CONNECT_TIMEOUT,
"ephemeral_routing_id"_a = std::nullopt,
"auth_level"_a = AuthLevel::none,
R"( R"(
Starts connecting to a remote address and return immediately. The connection can be used Starts connecting to a remote address and return immediately. The connection can be used
immediately, however messages will only be queued until the connection is established (or dropped if immediately, however messages will only be queued until the connection is established (or dropped if
the connection fails). The given callbacks are invoked for success or failure. the connection fails). The given callbacks are invoked for success or failure.
`ephemeral_routing_id` and `timeout` allowing overriding the defaults (oxenmq.EPHEMERAL_ROUTING_ID `ephemeral_routing_id` and `timeout` allowing overriding the defaults (oxenmq.EPHEMERAL_ROUTING_ID
and 10s, respectively). and 10s, respectively). `auth_level` can be specified to set the auth level of *incoming* requests
that arrive through this connection.
)") )")
.def("connect_remote", [](OxenMQ& self, .def("connect_remote", [](OxenMQ& self,
const address& remote, const address& remote,
std::chrono::milliseconds timeout, std::chrono::milliseconds timeout,
std::optional<bool> ephemeral_routing_id) { std::optional<bool> ephemeral_routing_id,
AuthLevel auth_level) {
std::promise<ConnectionID> promise; std::promise<ConnectionID> promise;
self.connect_remote( self.connect_remote(
remote, remote,
@ -653,10 +659,16 @@ and 10s, respectively).
std::runtime_error{"Connection failed: " + std::string{reason}})); std::runtime_error{"Connection failed: " + std::string{reason}}));
}, },
oxenmq::connect_option::timeout{timeout}, oxenmq::connect_option::timeout{timeout},
connect_option::ephemeral_routing_id{ephemeral_routing_id.value_or(self.EPHEMERAL_ROUTING_ID)} connect_option::ephemeral_routing_id{ephemeral_routing_id.value_or(self.EPHEMERAL_ROUTING_ID)},
auth_level
); );
return promise.get_future().get(); return promise.get_future().get();
}, "remote"_a, "timeout"_a = oxenmq::REMOTE_CONNECT_TIMEOUT, "ephemeral_routing_id"_a = std::nullopt, },
"remote"_a,
"timeout"_a = oxenmq::REMOTE_CONNECT_TIMEOUT,
kwonly,
"ephemeral_routing_id"_a = std::nullopt,
"auth_level"_a = AuthLevel::none,
R"(Simpler version of connect_remote that connects to a remote address synchronously. R"(Simpler version of connect_remote that connects to a remote address synchronously.
This will block until the connection is established or times out; throws on connection failure, This will block until the connection is established or times out; throws on connection failure,
@ -667,12 +679,14 @@ Takes the address and an optional `timeout` to override the timeout (default 10s
py::bytes pubkey, py::bytes pubkey,
std::optional<std::chrono::milliseconds> keep_alive, std::optional<std::chrono::milliseconds> keep_alive,
std::optional<std::string> remote_hint, std::optional<std::string> remote_hint,
std::optional<bool> ephemeral_routing_id) { std::optional<bool> ephemeral_routing_id,
AuthLevel auth_level) {
return self.connect_sn(std::string{pubkey}, return self.connect_sn(std::string{pubkey},
connect_option::keep_alive{keep_alive.value_or(-1ms)}, connect_option::keep_alive{keep_alive.value_or(-1ms)},
connect_option::hint{remote_hint.value_or("")}, connect_option::hint{remote_hint.value_or("")},
connect_option::ephemeral_routing_id{ephemeral_routing_id.value_or(self.EPHEMERAL_ROUTING_ID)}); connect_option::ephemeral_routing_id{ephemeral_routing_id.value_or(self.EPHEMERAL_ROUTING_ID)},
}, "pubkey"_a, kwonly, "keep_alive"_a, "remote_hint"_a, "ephemeral_routing_id"_a, auth_level);
}, "pubkey"_a, kwonly, "keep_alive"_a, "remote_hint"_a, "ephemeral_routing_id"_a, "auth_level"_a = AuthLevel::none,
R"(Connect to a remote service node by pubkey. R"(Connect to a remote service node by pubkey.
Try to initiate a connection to the given SN in anticipation of needing a connection in the future. Try to initiate a connection to the given SN in anticipation of needing a connection in the future.
@ -699,6 +713,9 @@ Parameters:
- ephemeral_routing_id - if set, override the default OxenMQ.EPHEMERAL_ROUTING_ID for this - ephemeral_routing_id - if set, override the default OxenMQ.EPHEMERAL_ROUTING_ID for this
connection. connection.
- auth_level - specified the authentication level for incoming commands (i.e. issued *to us*) over
this connection.
Returns a ConnectionID that identifies an connection with the given SN. Typically you *don't* need Returns a ConnectionID that identifies an connection with the given SN. Typically you *don't* need
to worry about saving this (and can just discard it): you can always simply pass the pubkey into to worry about saving this (and can just discard it): you can always simply pass the pubkey into
send/request methods to send to the SN by pubkey. send/request methods to send to the SN by pubkey.