MCPcopy Create free account
hub / github.com/XTXMarkets/ternfs / fetchLocalShards

Function fetchLocalShards

cpp/core/RegistryClient.cpp:404–430  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

402}
403
404std::pair<int, std::string> fetchLocalShards(const std::string& host, uint16_t port, Duration timeout, std::array<ShardInfo, 256>& shards) {
405 const auto [sock, errStr] = registrySock(host, port, timeout);
406 if (sock.error()) {
407 return {sock.getErrno(), errStr};
408 }
409
410 RegistryReqContainer reqContainer;
411 reqContainer.setLocalShards();
412 {
413 const auto [err, errStr] = writeRegistryRequest(sock.get(), reqContainer, timeout);
414 if (err) { return {err, errStr}; }
415 }
416
417 RegistryRespContainer respContainer;
418 {
419 const auto [err, errStr] = readRegistryResponse(sock.get(), respContainer, timeout);
420 if (err) { return {err, errStr}; }
421 }
422 if (respContainer.getLocalShards().shards.els.size() != shards.size()) {
423 throw TERN_EXCEPTION("expecting %s shards, got %s", shards.size(), respContainer.getLocalShards().shards.els.size());
424 }
425 for (int i = 0; i < shards.size(); i++) {
426 shards[i] = respContainer.getLocalShards().shards.els[i];
427 }
428
429 return {};
430}
431
432bool parseRegistryAddress(const std::string& fullRegistryAddress, std::string& registryHost, uint16_t& registryPort) {
433 // split host:port

Callers 1

periodicStepMethod · 0.85

Calls 7

registrySockFunction · 0.85
getErrnoMethod · 0.80
getMethod · 0.80
writeRegistryRequestFunction · 0.70
readRegistryResponseFunction · 0.70
errorMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected