Skip to content

Commit fac1f20

Browse files
committed
Before moving notice-Q from PeerSet to Peer
1 parent a8bc2bb commit fac1f20

34 files changed

+1583
-1074
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ sndrRepo/
4040
.libs/
4141
vgcore.*
4242
/hycast-1.0/
43+
/build/

AUTHORS

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Steven R. Emmerson
1+
Steven R. Emmerson <[email protected]>

CMakeLists.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ PROJECT(Hycast VERSION 1.0
2222
# Specify the C standard
2323
set(CMAKE_C_STANDARD 11)
2424
set(CMAKE_C_STANDARD_REQUIRED True)
25-
set(CMAKE_BUILD_TYPE Debug)
2625

2726
# Specify the C++ standard
2827
set(CMAKE_CXX_STANDARD 11)
2928
set(CMAKE_CXX_STANDARD_REQUIRED True)
30-
set(CMAKE_BUILD_TYPE Debug)
3129

3230
# Specify the Eclipse IDE version
3331
set(CMAKE_ECLIPSE_VERSION 4.17)
@@ -40,6 +38,7 @@ endif()
4038
# Configure a configuration header file
4139
configure_file(config-cmake.h config.h)
4240
include_directories(${CMAKE_BINARY_DIR}) # necessary
41+
include_directories(AFTER SYSTEM /usr/include/c++/4.8.5) # necessary
4342

4443
# Add the main subdirectory
4544
add_subdirectory(main)

main/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ core.*
1212
/DerivedTemplateOfABC.cpp
1313
/p2p/
1414
/p2p-old/
15+
/protocol/

main/HycastProto.cpp

+15-16
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@ namespace hycast {
3232

3333
const PduId PduId::UNSET(0);
3434
const PduId PduId::PEER_SRVR_ADDRS(1);
35-
const PduId PduId::PUB_PATH_NOTICE(2);
36-
const PduId PduId::PROD_INFO_NOTICE(3);
37-
const PduId PduId::DATA_SEG_NOTICE(4);
38-
const PduId PduId::PROD_INFO_REQUEST(5);
39-
const PduId PduId::DATA_SEG_REQUEST(6);
40-
const PduId PduId::PROD_INFO(7);
41-
const PduId PduId::DATA_SEG(8);
35+
const PduId PduId::PROD_INFO_NOTICE(2);
36+
const PduId PduId::DATA_SEG_NOTICE(3);
37+
const PduId PduId::PROD_INFO_REQUEST(4);
38+
const PduId PduId::DATA_SEG_REQUEST(5);
39+
const PduId PduId::PROD_INFO(6);
40+
const PduId PduId::DATA_SEG(7);
4241

4342
PduId::PduId(Type value)
4443
: value(value)
@@ -68,23 +67,23 @@ std::string DataSegId::to_string(const bool withName) const
6867
", offset=" + std::to_string(offset) + "}";
6968
}
7069

71-
String NoteReq::to_string() const {
70+
String DatumId::to_string() const {
7271
return (id == Id::PROD_INDEX)
7372
? prodIndex.to_string()
7473
: (id == Id::DATA_SEG_ID)
7574
? dataSegId.to_string()
7675
: "<unset>";
7776
}
7877

79-
size_t NoteReq::hash() const noexcept {
78+
size_t DatumId::hash() const noexcept {
8079
return (id == Id::PROD_INDEX)
8180
? prodIndex.hash()
8281
: (id == Id::DATA_SEG_ID)
8382
? dataSegId.hash()
8483
: 0;
8584
}
8685

87-
bool NoteReq::operator==(const NoteReq& rhs) const noexcept {
86+
bool DatumId::operator==(const DatumId& rhs) const noexcept {
8887
if (id != rhs.id) return false;
8988
if (id == Id::UNSET) return true;
9089
return (id == Id::PROD_INDEX)
@@ -149,27 +148,27 @@ class ProdInfo::Impl
149148
}
150149

151150
bool write(Xprt& xprt) const {
152-
LOG_NOTE("Writing product information to %s", xprt.to_string().data());
151+
//LOG_DEBUG("Writing product information to %s", xprt.to_string().data());
153152
auto success = index.write(xprt);
154153
if (success) {
155-
LOG_NOTE("Writing product name to %s", xprt.to_string().data());
154+
//LOG_DEBUG("Writing product name to %s", xprt.to_string().data());
156155
success = xprt.write(name);
157156
if (success) {
158-
LOG_NOTE("Writing product size to %s", xprt.to_string().data());
157+
//LOG_DEBUG("Writing product size to %s", xprt.to_string().data());
159158
success = xprt.write(size);
160159
}
161160
}
162161
return success;
163162
}
164163

165164
bool read(Xprt& xprt) {
166-
LOG_NOTE("Reading product information from %s", xprt.to_string().data());
165+
//LOG_DEBUG("Reading product information from %s", xprt.to_string().data());
167166
auto success = index.read(xprt);
168167
if (success) {
169-
LOG_NOTE("Reading product name from %s", xprt.to_string().data());
168+
//LOG_DEBUG("Reading product name from %s", xprt.to_string().data());
170169
success = xprt.read(name);
171170
if (success) {
172-
LOG_NOTE("Reading product size from %s", xprt.to_string().data());
171+
//LOG_DEBUG("Reading product size from %s", xprt.to_string().data());
173172
success = xprt.read(size);
174173
}
175174
}

main/HycastProto.h

+64-34
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ using String = std::string;
4848

4949
constexpr uint8_t PROTOCOL_VERSION = 1;
5050

51+
class P2pMgr;
52+
class SubP2pMgr;
53+
5154
/******************************************************************************/
5255
// PDU payloads
5356

@@ -228,12 +231,10 @@ class ProdIndex : public XprtAble
228231
}
229232

230233
bool write(Xprt& xprt) const override {
231-
LOG_NOTE("Writing product-index to %s", xprt.to_string().data());
232234
return xprt.write(index);
233235
}
234236

235237
bool read(Xprt& xprt) override {
236-
LOG_NOTE("Reading product-index from %s", xprt.to_string().data());
237238
return xprt.read(index);
238239
}
239240
};
@@ -271,21 +272,16 @@ struct DataSegId : public XprtAble
271272
}
272273

273274
bool write(Xprt& xprt) const override {
274-
LOG_NOTE("Writing data-segment identifier to %s", xprt.to_string().data());
275275
auto success = prodIndex.write(xprt);
276276
if (success) {
277-
LOG_NOTE("Writing offset to %s", xprt.to_string().data());
278277
success = xprt.write(offset);
279278
}
280279
return success;
281280
}
282281

283282
bool read(Xprt& xprt) override {
284-
LOG_NOTE("Reading data-segment identifier from %s",
285-
xprt.to_string().data());
286283
auto success = prodIndex.read(xprt);
287284
if (success) {
288-
LOG_NOTE("Reading offset from %s", xprt.to_string().data());
289285
success = xprt.read(offset);
290286
}
291287
return success;
@@ -380,7 +376,7 @@ class DataSeg final : public XprtAble
380376

381377
operator bool() const;
382378

383-
const DataSegId getId() const noexcept;
379+
const DataSegId& getId() const noexcept;
384380

385381
ProdSize getProdSize() const noexcept;
386382

@@ -394,6 +390,8 @@ class DataSeg final : public XprtAble
394390
return getId().offset;
395391
}
396392

393+
bool operator==(const DataSeg& rhs) const;
394+
397395
String to_string(bool withName = false) const;
398396

399397
bool write(Xprt& xprt) const override;
@@ -435,7 +433,7 @@ class Product
435433
* such entities can be handled as a single object for the purpose of argument
436434
* passing and container element.
437435
*/
438-
struct NoteReq
436+
struct DatumId
439437
{
440438
public:
441439
enum class Id {
@@ -448,42 +446,43 @@ struct NoteReq
448446
DataSegId dataSegId;
449447
};
450448

451-
NoteReq() noexcept
449+
DatumId() noexcept
452450
: prodIndex()
453451
, id(Id::UNSET)
454452
{}
455453

456-
explicit NoteReq(const ProdIndex prodIndex) noexcept
454+
explicit DatumId(const ProdIndex prodIndex) noexcept
457455
: id(Id::PROD_INDEX)
458456
, prodIndex(prodIndex)
459457
{}
460458

461-
explicit NoteReq(const DataSegId dataSegId) noexcept
459+
explicit DatumId(const DataSegId dataSegId) noexcept
462460
: id(Id::DATA_SEG_ID)
463461
, dataSegId(dataSegId)
464462
{}
465463

466-
NoteReq(const NoteReq& noteReq) noexcept {
467-
::memcpy(this, &noteReq, sizeof(NoteReq));
464+
DatumId(const DatumId& datumId) noexcept {
465+
::memcpy(this, &datumId, sizeof(DatumId));
468466
}
469467

470-
~NoteReq() noexcept {
468+
~DatumId() noexcept {
471469
}
472470

473-
NoteReq& operator=(const NoteReq& noteReq) =default;
474-
475-
NoteReq& operator=(NoteReq&& noteReq) =default;
471+
DatumId& operator=(const DatumId& rhs) noexcept {
472+
::memcpy(this, &rhs, sizeof(DatumId));
473+
return *this;
474+
}
476475

477476
operator bool() const {
478477
return id != Id::UNSET;
479478
}
480479

481480
String to_string() const;
482481

483-
// `std::hash<NoteReq>()` is also defined
482+
// `std::hash<DatumId>()` is also defined
484483
size_t hash() const noexcept;
485484

486-
bool operator==(const NoteReq& rhs) const noexcept;
485+
bool operator==(const DatumId& rhs) const noexcept;
487486
};
488487

489488
/******************************************************************************/
@@ -505,8 +504,6 @@ class NoticeRcvr
505504
{
506505
public:
507506
virtual ~NoticeRcvr() {}
508-
virtual void recvNotice(const PubPath notice,
509-
Peer peer) =0;
510507
virtual bool recvNotice(const ProdIndex notice,
511508
Peer peer) =0;
512509
virtual bool recvNotice(const DataSegId notice,
@@ -520,8 +517,8 @@ class RequestRcvr
520517
virtual ~RequestRcvr() {}
521518
virtual ProdInfo recvRequest(const ProdIndex request,
522519
Peer peer) =0;
523-
virtual DataSeg recvRequest(const DataSegId request,
524-
Peer peer) =0;
520+
virtual DataSeg recvRequest(const DataSegId request,
521+
Peer peer) =0;
525522
};
526523

527524
/// Data receiver/server
@@ -537,8 +534,8 @@ class DataRcvr
537534

538535
/**
539536
* Interface for a Hycast node. Implementations manage incoming P2P requests for
540-
* data and outgoing P2P transmissions. This interface is implemented by a
541-
* publishing node.
537+
* data and outgoing P2P transmissions. This interface is implemented by both a
538+
* publishing node and a subscribing node.
542539
*/
543540
class Node
544541
{
@@ -552,7 +549,9 @@ class Node
552549
* @return Product information. Will test false if it
553550
* doesn't exist.
554551
*/
555-
ProdInfo recvRequest(const ProdIndex request);
552+
virtual ProdInfo recvRequest(
553+
const ProdIndex request,
554+
P2pMgr& p2pMgr) =0;
556555

557556
/**
558557
* Receives a request for a data-segment.
@@ -561,7 +560,9 @@ class Node
561560
* @return Product information. Will test false if it
562561
* doesn't exist.
563562
*/
564-
DataSeg recvRequest(const DataSegId request);
563+
virtual DataSeg recvRequest(
564+
const DataSegId request,
565+
P2pMgr& p2pMgr) =0;
565566
};
566567

567568
/**
@@ -572,24 +573,53 @@ class SubNode : public Node
572573
{
573574
public:
574575
virtual ~SubNode() noexcept =default;
576+
577+
/**
578+
* Receives notice about the availability of a product from the P2P network.
579+
*
580+
* @param[in] index Index of available product
581+
* @retval `true` Product information should be requested
582+
* @retval `false` Product information should not be requested
583+
*/
584+
virtual bool recvNotice(
585+
const ProdIndex index,
586+
SubP2pMgr& p2pMgr) =0;
587+
588+
/**
589+
* Receives notice about the availability of a data-segment from the P2P
590+
* network.
591+
*
592+
* @param[in] segId Identifier of available data-segment
593+
* @retval `true` Data-segment information should be requested
594+
* @retval `false` Data-segment information should not be requested
595+
*/
596+
virtual bool recvNotice(
597+
const DataSegId segId,
598+
SubP2pMgr& p2pMgr) =0;
599+
600+
virtual void recvData(
601+
const ProdInfo prodInfo,
602+
SubP2pMgr& p2pMgr) =0;
603+
604+
virtual void recvData(
605+
const DataSeg dataSeg,
606+
SubP2pMgr& p2pMgr) =0;
575607
};
576608

577609
} // namespace
578610

579611
namespace std {
580612
template<>
581-
class hash<hycast::ProdIndex> {
582-
public:
613+
struct hash<hycast::ProdIndex> {
583614
size_t operator()(const hycast::ProdIndex& prodIndex) const noexcept {
584615
return prodIndex.hash();
585616
}
586617
};
587618

588619
template<>
589-
class hash<hycast::NoteReq> {
590-
public:
591-
size_t operator()(const hycast::NoteReq& noteReq) const noexcept {
592-
return noteReq.hash();
620+
struct hash<hycast::DatumId> {
621+
size_t operator()(const hycast::DatumId& datumId) const noexcept {
622+
return datumId.hash();
593623
}
594624
};
595625
}

main/inet/InetAddr.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,8 @@ class Inet6Addr final : public InetAddr::Impl
479479
}
480480

481481
size_t hash() const noexcept {
482-
return myHash(((static_cast<uint64_t>(addr.s6_addr32[0]) ^
483-
addr.s6_addr32[1]) << 32) |
484-
(addr.s6_addr32[2] ^ addr.s6_addr32[3]));
482+
return myHash(*reinterpret_cast<const uint64_t*>(addr.s6_addr) ^
483+
*reinterpret_cast<const uint64_t*>(addr.s6_addr+8));
485484
}
486485

487486
int socket(

0 commit comments

Comments
 (0)