5 #ifndef UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_SERVER_DISTRIBUTED_SERVER_HPP_INCLUDED
6 #define UAVCAN_PROTOCOL_DYNAMIC_NODE_ID_SERVER_DISTRIBUTED_SERVER_HPP_INCLUDED
18 namespace dynamic_node_id_server
38 return info.entry.unique_id == unique_id;
52 return info.entry.node_id == node_id.
get();
104 if (result->committed)
106 tryPublishAllocationResult(result->entry);
107 UAVCAN_TRACE(
"dynamic_node_id_server::distributed::Server",
108 "Allocation request served with existing allocation; node ID %d",
109 int(result->entry.node_id));
113 UAVCAN_TRACE(
"dynamic_node_id_server::distributed::Server",
114 "Allocation request ignored - allocation exists but not committed yet; node ID %d",
115 int(result->entry.node_id));
120 if (raft_core_.
isLeader() && !node_discoverer_.hasUnknownNodes())
122 allocateNewNode(unique_id, preferred_node_id);
141 return result->committed ? NodeAwarenessKnownAndCommitted : NodeAwarenessKnownButNotCommitted;
145 return NodeAwarenessUnknown;
173 tryPublishAllocationResult(entry);
178 if (!local_node_is_leader)
188 raft_core_.
appendLog(getOwnUniqueID(), node_.getNodeID());
197 UAVCAN_TRACE(
"dynamic_node_id_server::distributed::Server",
198 "Testing if node ID %d is taken",
int(node_id.
get()));
204 const NodeID allocated_node_id =
208 UAVCAN_TRACE(
"dynamic_node_id_server::distributed::Server",
"Request ignored - no free node ID left");
212 UAVCAN_TRACE(
"dynamic_node_id_server::distributed::Server",
"New node ID allocated: %d",
213 int(allocated_node_id.
get()));
214 raft_core_.
appendLog(unique_id, allocated_node_id);
219 const int res = allocation_request_manager_.broadcastAllocationResponse(entry.unique_id, entry.node_id);
223 node_.registerInternalFailure(
"Dynamic allocation response");
232 , raft_core_(
node, storage, tracer, *this)
242 int res = raft_core_.
init(cluster_size, priority);
265 if (own_log_entry->entry.unique_id != getOwnUniqueID())
267 return -ErrInvalidConfiguration;
318 :
cluster_size (
s.getRaftCore().getClusterManager().getClusterSize())
319 ,
state (
s.getRaftCore().getServerState())
320 ,
last_log_index (
s.getRaftCore().getPersistentState().getLog().getLastIndex())
323 ,
current_term (
s.getRaftCore().getPersistentState().getCurrentTerm())
324 ,
voted_for (
s.getRaftCore().getPersistentState().getVotedFor())
329 const Entry*
const e =
s.getRaftCore().getPersistentState().getLog().getEntryAtIndex(
last_log_index);
354 #endif // Include guard