summaryrefslogtreecommitdiff
path: root/lib/northbound_grpc.cpp
diff options
context:
space:
mode:
authorChristian Hopps <chopps@labn.net>2022-03-06 06:59:50 -0500
committerChristian Hopps <chopps@labn.net>2022-03-14 11:14:12 -0400
commitd3074a5207e2e4a5c7e669eb69f22dfd91b92c47 (patch)
treebc1418d5a5a5c63e94d21e1f2c92db5948b21497 /lib/northbound_grpc.cpp
parent79c681952ea3b963a29beab9775e9a7f7e4f72bb (diff)
lib: grpc: use candiate ID to delete rather than pointer to candiate
- also be consistent in candidate IDs being uint64_t Signed-off-by: Christian Hopps <chopps@labn.net>
Diffstat (limited to 'lib/northbound_grpc.cpp')
-rw-r--r--lib/northbound_grpc.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/northbound_grpc.cpp b/lib/northbound_grpc.cpp
index 31101f5c24..0a458b6262 100644
--- a/lib/northbound_grpc.cpp
+++ b/lib/northbound_grpc.cpp
@@ -78,7 +78,7 @@ class Candidates
{
// Delete candidates.
for (auto it = _cdb.begin(); it != _cdb.end(); it++)
- delete_candidate(&it->second);
+ delete_candidate(it->first);
}
struct candidate *create_candidate(void)
@@ -94,8 +94,14 @@ class Candidates
return c;
}
- void delete_candidate(struct candidate *c)
+ bool contains(uint64_t candidate_id)
{
+ return _cdb.count(candidate_id) > 0;
+ }
+
+ void delete_candidate(uint64_t candidate_id)
+ {
+ struct candidate *c = &_cdb[candidate_id];
char errmsg[BUFSIZ] = {0};
nb_config_free(c->config);
@@ -105,14 +111,14 @@ class Candidates
_cdb.erase(c->id);
}
- struct candidate *get_candidate(uint32_t id)
+ struct candidate *get_candidate(uint64_t id)
{
return _cdb.count(id) == 0 ? NULL : &_cdb[id];
}
private:
uint64_t _next_id = 0;
- std::map<uint32_t, struct candidate> _cdb;
+ std::map<uint64_t, struct candidate> _cdb;
};
class RpcStateBase
@@ -183,6 +189,9 @@ template <typename Q, typename S> class NewRpcState : RpcStateBase
pthread_cond_wait(&this->cond, &this->cmux);
pthread_mutex_unlock(&this->cmux);
+ if (enter_state == FINISH)
+ assert(this->state == DELETED);
+
if (this->state == DELETED) {
grpc_debug("%s RPC: -> [DELETED]", name);
delete this;
@@ -617,15 +626,14 @@ void HandleUnaryDeleteCandidate(NewRpcState<frr::DeleteCandidateRequest,
grpc_debug("%s(candidate_id: %u)", __func__, candidate_id);
- struct candidate *candidate = tag->cdb->get_candidate(candidate_id);
- if (!candidate) {
+ if (!tag->cdb->contains(candidate_id)) {
tag->responder.Finish(
tag->response,
grpc::Status(grpc::StatusCode::NOT_FOUND,
"candidate configuration not found"),
tag);
} else {
- tag->cdb->delete_candidate(candidate);
+ tag->cdb->delete_candidate(candidate_id);
tag->responder.Finish(tag->response, grpc::Status::OK, tag);
}
tag->state = FINISH;