Skip to content

Commit

Permalink
Add optional reason string to a peering's force_disconnect()
Browse files Browse the repository at this point in the history
  • Loading branch information
ckreibich committed Dec 3, 2024
1 parent 3cd74b2 commit f6d10e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 7 additions & 3 deletions libbroker/broker/internal/peering.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,12 @@ class suffix_generator : public affix_generator {

node_message first() override {
if (ptr_->removed()) {
std::string msg{"removed connection to remote peer"};
std::string reason = ptr_->removed_reason();
if (!reason.empty())
msg += " (" + reason + ")";
return make_status_msg(endpoint_info{ptr_->peer_id(), ptr_->addr()},
sc_constant<sc::peer_removed>(),
"removed connection to remote peer");
sc_constant<sc::peer_removed>(), msg.c_str());
} else {
return make_status_msg(endpoint_info{ptr_->peer_id(), ptr_->addr()},
sc_constant<sc::peer_lost>(),
Expand All @@ -119,9 +122,10 @@ void peering::on_bye_ack() {
bye_timeout_.dispose();
}

void peering::force_disconnect() {
void peering::force_disconnect(const std::string& reason) {
if (!removed_) {
removed_ = true;
removed_reason_ = reason;
}
on_bye_ack();
}
Expand Down
9 changes: 8 additions & 1 deletion libbroker/broker/internal/peering.hh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public:

/// Forces the peering to shut down its connection without performing the BYE
/// handshake.
void force_disconnect();
void force_disconnect(const std::string& reason = "");

void schedule_bye_timeout(caf::scheduled_actor* self);

Expand All @@ -63,6 +63,11 @@ public:
return removed_;
}

/// Returns the removal reason, which may be empty.
std::string removed_reason() const noexcept {
return removed_reason_;
}

/// Tag this peering as removed and send a BYE message on the `snk` for a
/// graceful shutdown.
void remove(caf::scheduled_actor* self,
Expand Down Expand Up @@ -117,6 +122,8 @@ private:
/// BYE message to the peer.
bool removed_ = false;

std::string removed_reason_;

/// Network address as reported from the transport (usually TCP).
network_info addr_;

Expand Down

0 comments on commit f6d10e1

Please sign in to comment.