Skip to content

Commit

Permalink
Boss/Mod/ChannelFinderBy*: Only re-trigger if not already running.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZmnSCPxj committed Nov 3, 2020
1 parent 7ded2c2 commit 3053223
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Boss/Mod/ChannelFinderByDistance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,15 @@ void ChannelFinderByDistance::start() {
>([this](Msg::SolicitChannelCandidates const& _) {
if (!rpc)
return Ev::lift();
if (running)
return Ev::lift();

running = true;
auto run = Run::create(bus, *rpc, waiter, self_id);
return Boss::concurrent(run->run());
return Boss::concurrent(run->run().then([this]() {
running = false;
return Ev::lift();
}));
});
}

Expand Down
2 changes: 2 additions & 0 deletions Boss/Mod/ChannelFinderByDistance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class ChannelFinderByDistance {
Boss::Mod::Rpc* rpc;
Boss::Mod::Waiter& waiter;
Ln::NodeId self_id;
bool running;

class Run;

Expand All @@ -37,6 +38,7 @@ class ChannelFinderByDistance {
) : bus(bus_)
, rpc(nullptr)
, waiter(waiter_)
, running(false)
{ start(); }
};

Expand Down
6 changes: 6 additions & 0 deletions Boss/Mod/ChannelFinderByListpays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ void ChannelFinderByListpays::start() {
>([this](Msg::SolicitChannelCandidates const& m) {
if (!rpc)
return Ev::lift();
if (running)
return Ev::lift();

running = true;
auto act = rpc->command( "listpays", Json::Out::empty_object()
).then([this](Jsmn::Object res) {
auto payees = std::map<Ln::NodeId, std::size_t>();
Expand Down Expand Up @@ -124,6 +127,9 @@ void ChannelFinderByListpays::start() {
act += Ev::foreach(std::move(f), std::move(proposals));

return act;
}).then([this]() {
running = false;
return Ev::lift();
});
return Boss::concurrent(act);
});
Expand Down
3 changes: 3 additions & 0 deletions Boss/Mod/ChannelFinderByListpays.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class ChannelFinderByListpays {
/* Peers we already have channels with. */
std::set<Ln::NodeId> channels;

bool running;

void start();

public:
Expand All @@ -33,6 +35,7 @@ class ChannelFinderByListpays {
ChannelFinderByListpays( S::Bus& bus_
) : bus(bus_)
, rpc(nullptr)
, running(false)
{ start(); }
};

Expand Down

0 comments on commit 3053223

Please sign in to comment.