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())
321 , commit_index (s.getRaftCore().getCommitIndex())
323 , current_term (s.getRaftCore().getPersistentState().getCurrentTerm())
324 , voted_for (s.getRaftCore().getPersistentState().getVotedFor())
325 , last_activity_timestamp(s.getRaftCore().getLastActivityTimestamp())
326 , randomized_timeout (s.getRaftCore().getRandomizedTimeout())
327 , num_unknown_nodes (s.getNodeDiscoverer().getNumUnknownNodes())
333 last_log_term = e->term;
336 for (
uint8_t i = 0; i < (cluster_size - 1U); i++)
342 followers[i].node_id = node_id;
354 #endif // Include guard
void appendLog(const Entry::FieldTypes::unique_id &unique_id, NodeID node_id)
virtual void handleAllocationRequest(const UniqueID &unique_id, const NodeID preferred_node_id)
Log::Index last_log_index
virtual void handleLogCommitOnLeader(const protocol::dynamic_node_id::server::Entry &entry)
Server(INode &node, IStorageBackend &storage, IEventTracer &tracer)
bool operator()(const RaftCore::LogEntryInfo &info) const
void allocateNewNode(const UniqueID &unique_id, const NodeID preferred_node_id)
LazyConstructor< LogEntryInfo > traverseLogFromEndUntil(const Predicate &predicate) const
bool areAllLogEntriesCommitted() const
bool isConstructed() const
virtual bool canPublishFollowupAllocationResponse() const
void tryPublishAllocationResult(const protocol::dynamic_node_id::server::Entry &entry)
virtual NodeAwareness checkNodeAwareness(NodeID node_id) const
int init(const UniqueID &own_unique_id, const uint8_t cluster_size=ClusterManager::ClusterSizeUnknown, const TransferPriority priority=TransferPriority::OneHigherThanLowest)
MonotonicDuration randomized_timeout
int init(const UniqueID &own_unique_id, const TransferPriority priority)
#define UAVCAN_TRACE(...)
int init(const uint8_t cluster_size, const TransferPriority priority)
const Entry * getEntryAtIndex(Index index) const
Log::Index getServerNextIndex(NodeID server_node_id) const
StateReport(const Server &s)
bool isNodeIDTaken(const NodeID node_id) const
protocol::dynamic_node_id::server::Entry::FieldTypes::unique_id UniqueID
const ClusterManager & getClusterManager() const
MonotonicTime last_activity_timestamp
virtual void handleLocalLeadershipChange(bool local_node_is_leader)
virtual bool canDiscoverNewNodes() const
RaftCore::ServerState state
uint8_t num_unknown_nodes
NodeID getRemoteServerNodeIDAtIndex(uint8_t index) const
bool operator()(const RaftCore::LogEntryInfo &info) const
NodeIDLogPredicate(const NodeID &nid)
Log::Index getNumAllocations() const
virtual void handleNewNodeDiscovery(const UniqueID *unique_id_or_null, NodeID node_id)
UniqueIDLogPredicate(const UniqueID &uid)
Log::Index getNumAllocations() const
StorageType< Entry::FieldTypes::term >::Type Term
const RaftCore & getRaftCore() const
static const TransferPriority OneHigherThanLowest
const PersistentState & getPersistentState() const
Log::Index getServerMatchIndex(NodeID server_node_id) const