本文整理汇总了C++中NodeID类的典型用法代码示例。如果您正苦于以下问题:C++ NodeID类的具体用法?C++ NodeID怎么用?C++ NodeID使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NodeID类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setVotedFor
/**
* Invokes storage IO.
*/
int setVotedFor(NodeID node_id)
{
if (!node_id.isValid())
{
UAVCAN_ASSERT(0);
return -ErrInvalidParam;
}
tracer_.onEvent(TraceRaftVotedForUpdate, node_id.get());
StorageMarshaller io(storage_);
uint32_t tmp = node_id.get();
int res = io.setAndGetBack(getVotedForKey(), tmp);
if (res < 0)
{
return res;
}
if (node_id.get() != tmp)
{
return -ErrFailure;
}
voted_for_ = node_id;
return 0;
}
示例2: handleTimerEvent
void handleTimerEvent(const TimerEvent&)
{
if (get_node_info_client_.hasPendingCalls())
{
return;
}
const NodeID node_id = pickNextNodeToQueryAndCleanupMap();
if (!node_id.isUnicast())
{
trace(TraceDiscoveryTimerStop, 0);
stop();
return;
}
if (!handler_.canDiscoverNewNodes())
{
return; // Timer must continue to run in order to not stuck when it unlocks
}
trace(TraceDiscoveryGetNodeInfoRequest, node_id.get());
UAVCAN_TRACE("dynamic_node_id_server::NodeDiscoverer", "Requesting GetNodeInfo from node %d",
int(node_id.get()));
const int res = get_node_info_client_.call(node_id, protocol::GetNodeInfo::Request());
if (res < 0)
{
getNode().registerInternalFailure("NodeDiscoverer GetNodeInfo call");
}
}
示例3: operator
bool operator()(const NodeID node_id, const FirmwareFilePath&)
{
if (node_id.get() > owner.last_queried_node_id_ &&
!owner.begin_fw_update_client_.hasPendingCallToServer(node_id))
{
output = min(output, node_id.get());
}
return false;
}
示例4: TEST
TEST(NodeID, SettingNamespaceUri_And_Index)
{
uint32_t id = 1;
uint32_t ns = 2;
NodeID node = NumericNodeID(id, ns);
node.SetNamespaceURI("uri");
node.SetServerIndex(3);
ASSERT_TRUE(node.HasNamespaceURI());
ASSERT_TRUE(node.HasServerIndex());
}
示例5: initialize
void initialize(int port)
{
myport = port;
current.__set_ip(get_eth_ip());
current.__set_port(myport);
current.__set_id(sha256_ip_port_hex(current.ip, current.port));
NodeID noSet; // the finger table nodes are noSet at the start
ftable.assign(256,noSet);
predecessor = current;
successor = current;
ftable[0] = current;
}
示例6: findSucc
void findSucc(NodeID& _return, const std::string& key) {
NodeID pred;
findPred(pred, key);
if (pred.id == current.id)
{
_return = successor;
_return.__set_count(pred.count);
return;
}
shared_ptr<DHTNodeClient> client(connectClientAgency(pred.ip, pred.port));
client->getNodeSucc(_return);
_return.__set_count(pred.count);
}
示例7: calcNodeID
NodeID
calcNodeID (PublicKey const& pk)
{
ripesha_hasher h;
h(pk.data(), pk.size());
auto const digest = static_cast<
ripesha_hasher::result_type>(h);
static_assert(NodeID::bytes ==
sizeof(ripesha_hasher::result_type), "");
NodeID result;
std::memcpy(result.data(),
digest.data(), digest.size());
return result;
}
示例8: Frame
Frame(DataTypeID data_type_id, TransferType transfer_type, NodeID src_node_id, NodeID dst_node_id,
uint_fast8_t frame_index, TransferID transfer_id, bool last_frame = false)
: transfer_priority_(getDefaultPriorityForTransferType(transfer_type))
, transfer_type_(transfer_type)
, data_type_id_(data_type_id)
, payload_len_(0)
, src_node_id_(src_node_id)
, dst_node_id_(dst_node_id)
, frame_index_(frame_index)
, transfer_id_(transfer_id)
, last_frame_(last_frame)
{
UAVCAN_ASSERT((transfer_type == TransferTypeMessageBroadcast) == dst_node_id.isBroadcast());
UAVCAN_ASSERT(data_type_id.isValidForDataTypeKind(getDataTypeKindForTransferType(transfer_type)));
UAVCAN_ASSERT(src_node_id.isUnicast() ? (src_node_id != dst_node_id) : true);
UAVCAN_ASSERT(frame_index <= getMaxIndex());
}
示例9: unicast
/**
* Unicast the message to the specified destination Node ID.
* Returns negative error code.
*/
int unicast(const DataType& message, NodeID dst_node_id)
{
if (!dst_node_id.isUnicast())
{
UAVCAN_ASSERT(0);
return -ErrInvalidParam;
}
return BaseType::publish(message, TransferTypeMessageUnicast, dst_node_id);
}
示例10: clog
void NodeTable::doDiscovery()
{
m_timers.schedule(c_bucketRefresh.count(), [this](boost::system::error_code const& _ec)
{
if (_ec)
// we can't use m_logger here, because captured this might be already destroyed
clog(VerbosityDebug, "discov")
<< "Discovery timer was probably cancelled: " << _ec.value() << " "
<< _ec.message();
if (_ec.value() == boost::asio::error::operation_aborted || m_timers.isStopped())
return;
LOG(m_logger) << "performing random discovery";
NodeID randNodeId;
crypto::Nonce::get().ref().copyTo(randNodeId.ref().cropped(0, h256::size));
crypto::Nonce::get().ref().copyTo(randNodeId.ref().cropped(h256::size, h256::size));
doDiscover(randNodeId, 0, make_shared<set<shared_ptr<NodeEntry>>>());
});
}
示例11: switch
NodeID RippleAddress::getNodeID () const
{
switch (nVersion)
{
case TOKEN_NONE:
Throw<std::runtime_error> ("unset source - getNodeID");
case TOKEN_NODE_PUBLIC:
{
// Note, we are encoding the left.
NodeID node;
node.copyFrom(Hash160 (vchData));
return node;
}
default:
Throw<std::runtime_error> ("bad source: " + std::to_string(nVersion));
}
return {}; // Silence compiler warning.
}
示例12: handleTimerEvent
virtual void handleTimerEvent(const TimerEvent&)
{
if (pending_nodes_.isEmpty())
{
TimerBase::stop();
UAVCAN_TRACE("FirmwareUpdateTrigger", "Timer stopped");
return;
}
const NodeID node_id = pickNextNodeID();
if (!node_id.isUnicast())
{
return;
}
FirmwareFilePath* const path = pending_nodes_.access(node_id);
if (path == UAVCAN_NULLPTR)
{
UAVCAN_ASSERT(0); // pickNextNodeID() returned a node ID that is not present in the map
return;
}
protocol::file::BeginFirmwareUpdate::Request req;
req.source_node_id = getNode().getNodeID().get();
if (!common_path_prefix_.empty())
{
req.image_file_remote_path.path += common_path_prefix_.c_str();
req.image_file_remote_path.path.push_back(protocol::file::Path::SEPARATOR);
}
req.image_file_remote_path.path += path->c_str();
UAVCAN_TRACE("FirmwareUpdateTrigger", "Request to %d with path: %s",
int(node_id.get()), req.image_file_remote_path.path.c_str());
const int call_res = begin_fw_update_client_.call(node_id, req);
if (call_res < 0)
{
getNode().registerInternalFailure("FirmwareUpdateTrigger call");
}
}
示例13: OutgoingTransferRegistryKey
OutgoingTransferRegistryKey(DataTypeID data_type_id, TransferType transfer_type, NodeID destination_node_id)
: data_type_id_(data_type_id)
, transfer_type_(transfer_type)
, destination_node_id_(destination_node_id)
{
UAVCAN_ASSERT((transfer_type == TransferTypeMessageBroadcast) == destination_node_id.isBroadcast());
/*
* Service response transfers must use the same Transfer ID as matching service request transfer,
* so this registry is not applicable for service response transfers at all.
*/
UAVCAN_ASSERT(transfer_type != TransferTypeServiceResponse);
}
示例14: findPred
void findPred(NodeID& _return, const std::string& key) {
string left = current.id;
string middle = key;
string right = successor.id;
/*
bool flag;
flag = right > left ? (middle > left && middle <= right)
: ((middle > left && middle > right) ||
(middle < left && middle <= right));
**/
if (keyCompare(current.id, key, successor.id)) {
_return = current;
_return.__set_count(0);
return ;
}
for(int i = 255; i >= 0; i--) {
if (ftable[i].id.empty()) continue;
if (keyCompare(current.id, ftable[i].id, key)) {
boost::shared_ptr<TSocket> socket(new TSocket(ftable[i].ip.c_str(),
ftable[i].port));
boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
boost::shared_ptr<DHTNodeClient> client(new DHTNodeClient(protocol));
transport->open();
try {
client->findPred(_return, key);
} catch (...) {
client = boost::shared_ptr<DHTNodeClient>();
transport->close();
}
transport->close();
_return.__set_count(_return.count + 1);
return ;
}
}
assert(false);
}
示例15: broadcastAllocationResponse
int broadcastAllocationResponse(const UniqueID& unique_id, NodeID allocated_node_id)
{
Allocation msg;
msg.unique_id.resize(msg.unique_id.capacity());
copy(unique_id.begin(), unique_id.end(), msg.unique_id.begin());
msg.node_id = allocated_node_id.get();
trace(TraceAllocationResponse, msg.node_id);
return allocation_pub_.broadcast(msg);
}