Skip to content

Commit b39820f

Browse files
author
steve
committed
"make test" and PubSub.sh both work
1 parent 71bec3e commit b39820f

File tree

142 files changed

+3075
-2627
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+3075
-2627
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,5 @@ rcvrRepo/
3939
sndrRepo/
4040
.libs/
4141
vgcore.*
42-
/hycast-1.0/
4342
/_build/
4443
/build/

CMakeLists.txt

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.19)
22

33
# Set the project name and version
4-
PROJECT(hycast VERSION 0.0 DESCRIPTION "Hybrid multicast/P2P protocol & data-distribution system")
4+
PROJECT(Bicast VERSION 0.0 DESCRIPTION "Combined multicast/P2P protocol & data-distribution system")
55

66
## Include gRPC in the build
77
#option(USE_SYSTEM_GRPC "Use system installed gRPC" OFF)
@@ -23,7 +23,7 @@ set(CMAKE_C_STANDARD 11)
2323
set(CMAKE_C_STANDARD_REQUIRED True)
2424

2525
# Specify the C++ standard
26-
set(CMAKE_CXX_STANDARD 11)
26+
set(CMAKE_CXX_STANDARD 14)
2727
set(CMAKE_CXX_STANDARD_REQUIRED True)
2828

2929
if(CMAKE_CXX_COMPILER_ID STREQUAL GNU AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
@@ -39,7 +39,7 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
3939
endif()
4040

4141
# Configure a configuration header file
42-
configure_file(config-cmake.h config.h)
42+
configure_file(config.h.in config.h)
4343
include_directories(${CMAKE_BINARY_DIR}) # necessary
4444

4545
include_directories(main main/misc main/inet main/mcast main/p2p main/repository main/node main/disposer)
@@ -71,10 +71,11 @@ endif()
7171
find_package(Doxygen)
7272
set(DOXYGEN_JAVADOC_AUTOBRIEF YES)
7373
set(DOXYGEN_ALIASES
74-
"exceptionsafety=@par Exception Safety:"
75-
"threadsafety=@par Thread Safety:"
76-
"asyncsignalsafe=@par Async-signal Safe:"
77-
"cancellationpoint=@par Cancellation Point:")
74+
[[exceptionsafety="@par Exception Safety:"]]
75+
[[threadsafety="@par Thread Safety:"]]
76+
[[asyncsignalsafe="@par Async-signal Safe:"]]
77+
[[cancellationpoint="@par Cancellation Point:"]])
78+
set(DOXYGEN_VERBATIM_VARS DOXYGEN_ALIASES)
7879
doxygen_add_docs(doxydocs mainpage.md main ALL)
7980

8081
# Install documentation

config-cmake.h config.h.in

File renamed without changes.

main/HycastProto.cpp main/BicastProto.cpp

+68-90
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
2-
* This file implements the types used in the Hycast protocol.
2+
* This file implements the types used in the Bicast protocol.
33
*
4-
* @file: HycastProto.cpp
4+
* @file: BicastProto.cpp
55
* @author: Steven R. Emmerson <[email protected]>
66
*
7-
* Copyright 2021 University Corporation for Atmospheric Research
7+
* Copyright 2023 University Corporation for Atmospheric Research
88
*
99
* Licensed under the Apache License, Version 2.0 (the "License");
1010
* you may not use this file except in compliance with the License.
@@ -20,31 +20,39 @@
2020
*/
2121
#include "config.h"
2222

23+
#include "BicastProto.h"
24+
2325
#include "error.h"
24-
#include "FileUtil.h"
25-
#include "HycastProto.h"
2626
#include "Xprt.h"
2727

2828
#include <chrono>
29+
#include <cinttypes>
2930
#include <climits>
3031
#include <cstdio>
3132
#include <cstring>
32-
#include <time.h>
33-
#include <inttypes.h>
33+
#include <ctime>
34+
#include <unordered_set>
3435
#include <openssl/sha.h>
3536

36-
namespace hycast {
37+
namespace bicast {
38+
39+
PduId::PduId(Xprt& xprt) {
40+
if (!xprt.read(value))
41+
throw EOF_ERROR("Couldn't read value");
42+
if (value > MAX_PDU_ID)
43+
throw INVALID_ARGUMENT("value=" + to_string());
44+
}
3745

38-
bool FeedInfo::write(Xprt xprt) const {
39-
return mcastGroup.write(xprt) &&
40-
mcastSource.write(xprt) &&
41-
xprt.write(segSize);
46+
bool PduId::write(Xprt& xprt) const {
47+
return xprt.write(value);
4248
}
4349

44-
bool FeedInfo::read(Xprt xprt) {
45-
return mcastGroup.read(xprt) &&
46-
mcastSource.read(xprt) &&
47-
xprt.read(segSize);
50+
bool PduId::read(Xprt& xprt) {
51+
if (!xprt.read(value))
52+
return false;
53+
if (value > MAX_PDU_ID)
54+
throw INVALID_ARGUMENT("value=" + to_string());
55+
return true;
4856
}
4957

5058
/**
@@ -78,47 +86,33 @@ String ProdId::to_string() const noexcept {
7886
return String(buf);
7987
}
8088

81-
std::string DataSegId::to_string(const bool withName) const
82-
{
89+
bool ProdId::write(Xprt& xprt) const {
90+
return xprt.write(id);
91+
}
92+
93+
bool ProdId::read(Xprt& xprt) {
94+
return xprt.read(id);
95+
}
96+
97+
std::string DataSegId::to_string(const bool withName) const {
8398
String string;
8499
if (withName)
85100
string += "DataSegId";
86101
return string + "{prodId=" + prodId.to_string() + ", offset=" + std::to_string(offset) + "}";
87102
}
88103

89-
String Notice::to_string() const {
90-
switch (id) {
91-
case Id::DATA_SEG_ID:
92-
return dataSegId.to_string();
93-
case Id::PROD_INDEX:
94-
return prodId.to_string();
95-
case Id::GOOD_PEER_SRVR:
96-
return srvrAddr.to_string();
97-
case Id::BAD_PEER_SRVR:
98-
return srvrAddr.to_string();
99-
case Id::GOOD_PEER_SRVRS:
100-
return tracker.to_string();
101-
case Id::BAD_PEER_SRVRS:
102-
return tracker.to_string();
103-
default:
104-
return "<unset>";
105-
}
106-
}
107-
108-
size_t Notice::hash() const noexcept {
109-
return (id == Id::PROD_INDEX)
110-
? prodId.hash()
111-
: (id == Id::DATA_SEG_ID)
112-
? dataSegId.hash()
113-
: 0;
104+
bool DataSegId::write(Xprt& xprt) const {
105+
auto success = prodId.write(xprt);
106+
if (success)
107+
success = xprt.write(offset);
108+
return success;
114109
}
115110

116-
bool Notice::operator==(const Notice& rhs) const noexcept {
117-
if (id != rhs.id) return false;
118-
if (id == Id::UNSET) return true;
119-
return (id == Id::PROD_INDEX)
120-
? prodId == rhs.prodId
121-
: dataSegId == rhs.dataSegId;
111+
bool DataSegId::read(Xprt& xprt) {
112+
auto success = prodId.read(xprt);
113+
if (success)
114+
success = xprt.read(offset);
115+
return success;
122116
}
123117

124118
/******************************************************************************/
@@ -127,17 +121,16 @@ bool Notice::operator==(const Notice& rhs) const noexcept {
127121

128122
class ProdIdSet::Impl
129123
{
130-
using Set = std::unordered_set<ProdId>;
131-
132-
Set prodIds;
124+
private:
125+
std::unordered_set<ProdId> prodIds;
133126

134127
public:
135128
/**
136129
* Constructs.
137130
* @param[in] n Initial capacity
138131
*/
139132
Impl(const size_t n)
140-
: prodIds{n}
133+
: prodIds(n)
141134
{}
142135

143136
/**
@@ -163,7 +156,7 @@ class ProdIdSet::Impl
163156
* @retval true Success
164157
* @retval false Connection lost
165158
*/
166-
bool write(Xprt xprt) const {
159+
bool write(Xprt& xprt) const {
167160
if (!xprt.write(static_cast<uint32_t>(prodIds.size())))
168161
return false;
169162
for (auto iter = prodIds.begin(), end = prodIds.end(); iter != end; ++iter)
@@ -178,7 +171,7 @@ class ProdIdSet::Impl
178171
* @retval true Success
179172
* @retval false Connection lost
180173
*/
181-
bool read(Xprt xprt) {
174+
bool read(Xprt& xprt) {
182175
uint32_t size;
183176
if (!xprt.read(size))
184177
return false;
@@ -223,15 +216,15 @@ class ProdIdSet::Impl
223216
* Returns an iterator over the product identifiers.
224217
* @return An iterator over the product identifiers
225218
*/
226-
Set::iterator begin() {
219+
decltype(prodIds)::iterator begin() {
227220
return prodIds.begin();
228221
}
229222

230223
/**
231224
* Returns an iterator just outside the product identifiers.
232225
* @return An iterator just outside the product identifiers
233226
*/
234-
Set::iterator end() {
227+
decltype(prodIds)::iterator end() {
235228
return prodIds.end();
236229
}
237230

@@ -255,11 +248,11 @@ void ProdIdSet::subtract(const ProdIdSet rhs) {
255248
pImpl->subtract(*rhs.pImpl);
256249
}
257250

258-
bool ProdIdSet::write(Xprt xprt) const {
251+
bool ProdIdSet::write(Xprt& xprt) const {
259252
return pImpl->write(xprt);
260253
}
261254

262-
bool ProdIdSet::read(Xprt xprt) {
255+
bool ProdIdSet::read(Xprt& xprt) {
263256
return pImpl->read(xprt);
264257
}
265258

@@ -302,7 +295,12 @@ class ProdInfo::Impl
302295
SysTimePoint creationTime; ///< When product was initially created
303296

304297
public:
305-
Impl() =default;
298+
Impl()
299+
: prodId()
300+
, name()
301+
, size(0)
302+
, creationTime()
303+
{}
306304

307305
/**
308306
* Constructs.
@@ -370,7 +368,7 @@ class ProdInfo::Impl
370368
* @retval true Success
371369
* @retval false Lost connection
372370
*/
373-
bool write(Xprt xprt) const {
371+
bool write(Xprt& xprt) const {
374372
//LOG_DEBUG("Writing product information to %s", xprt.to_string().data());
375373
auto success = prodId.write(xprt);
376374
if (success) {
@@ -396,7 +394,7 @@ class ProdInfo::Impl
396394
* @retval true Success
397395
* @retval false Lost connection
398396
*/
399-
bool read(Xprt xprt) {
397+
bool read(Xprt& xprt) {
400398
//LOG_DEBUG("Reading product information from %s", xprt.to_string().data());
401399
auto success = prodId.read(xprt);
402400
if (success) {
@@ -429,13 +427,13 @@ class ProdInfo::Impl
429427
ProdInfo::ProdInfo(const ProdId index,
430428
const std::string& name,
431429
const ProdSize size,
432-
const SysTimePoint& createTime)
430+
const SysTimePoint createTime)
433431
: pImpl{new Impl(index, name, size, createTime)}
434432
{}
435433

436434
ProdInfo::ProdInfo(const std::string& name,
437435
const ProdSize size,
438-
const SysTimePoint& createTime)
436+
const SysTimePoint createTime)
439437
: ProdInfo(ProdId{name}, name, size, createTime)
440438
{}
441439

@@ -472,47 +470,27 @@ String ProdInfo::to_string(const bool withName) const {
472470
return pImpl ? pImpl->to_string(withName) : "<unset>";
473471
}
474472

475-
bool ProdInfo::write(Xprt xprt) const {
473+
bool ProdInfo::write(Xprt& xprt) const {
476474
return pImpl->write(xprt);
477475
}
478476

479-
bool ProdInfo::read(Xprt xprt) {
477+
bool ProdInfo::read(Xprt& xprt) {
480478
if (!pImpl)
481479
pImpl = std::make_shared<Impl>();
482480
return pImpl->read(xprt);
483481
}
484482

485-
/**************************************************************************************************/
486-
// P2P server information
487-
488-
String P2pSrvrInfo::to_string() const {
489-
return "{addr=" + srvrAddr.to_string() + ", tier=" + std::to_string(tier) +
490-
", numAvail=" + std::to_string(numAvail) + ", valid=" + std::to_string(valid) + "}";
491-
}
492-
493-
bool P2pSrvrInfo::write(Xprt xprt) const {
494-
return srvrAddr.write(xprt) &&
495-
xprt.write(tier) &&
496-
xprt.write(numAvail) &&
497-
xprt.write(valid);
498-
}
499-
500-
bool P2pSrvrInfo::read(Xprt xprt) {
501-
return srvrAddr.read(xprt) &&
502-
xprt.read(tier) &&
503-
xprt.read(numAvail) &&
504-
xprt.read(valid);
505-
}
506-
507483
} // namespace
508484

509485
namespace std {
486+
using namespace bicast;
487+
510488
/// Returns the string representation of a data product's identifier
511-
string to_string(const hycast::ProdId prodId) {
489+
string to_string(const ProdId prodId) {
512490
return prodId.to_string();
513491
}
514492
/// Returns the string representation of information on a data product
515-
string to_string(const hycast::ProdInfo prodInfo) {
493+
string to_string(const ProdInfo prodInfo) {
516494
return prodInfo.to_string();
517495
}
518496
}

0 commit comments

Comments
 (0)