Make allow_connection properly optional
This commit is contained in:
parent
4020ab8a49
commit
f1160d0a25
|
@ -437,13 +437,13 @@ Things you want to do before calling this:
|
|||
.def("listen", [](OxenMQ& self,
|
||||
std::string bind,
|
||||
bool curve,
|
||||
py::function pyallow,
|
||||
std::optional<py::function> pyallow,
|
||||
std::function<void(bool success)> on_bind) {
|
||||
OxenMQ::AllowFunc allow;
|
||||
if (!pyallow.is_none())
|
||||
if (pyallow)
|
||||
// We need to wrap this to pass the pubkey as bytes (otherwise pybind tries to utf-8
|
||||
// encode it).
|
||||
allow = [pyallow=std::move(pyallow)](std::string_view addr, std::string_view pubkey, bool sn) {
|
||||
allow = [pyallow=std::move(*pyallow)](std::string_view addr, std::string_view pubkey, bool sn) {
|
||||
py::gil_scoped_acquire gil;
|
||||
return py::cast<AuthLevel>(
|
||||
pyallow(addr, py::bytes{pubkey.data(), pubkey.size()}, sn)
|
||||
|
@ -455,7 +455,7 @@ Things you want to do before calling this:
|
|||
else
|
||||
self.listen_plain(bind, std::move(allow), std::move(on_bind));
|
||||
},
|
||||
"bind"_a, "curve"_a, kwonly, "allow_connection"_a = nullptr, "on_bind"_a = nullptr,
|
||||
"bind"_a, "curve"_a, kwonly, "allow_connection"_a = std::nullopt, "on_bind"_a = nullptr,
|
||||
R"(Start listening on the given bind address.
|
||||
|
||||
Incoming connections can come from anywhere. `allow_connection` is invoked for any incoming
|
||||
|
|
Loading…
Reference in New Issue