@@ -48,6 +48,9 @@ using String = std::string;
48
48
49
49
constexpr uint8_t PROTOCOL_VERSION = 1 ;
50
50
51
+ class P2pMgr ;
52
+ class SubP2pMgr ;
53
+
51
54
/* *****************************************************************************/
52
55
// PDU payloads
53
56
@@ -228,12 +231,10 @@ class ProdIndex : public XprtAble
228
231
}
229
232
230
233
bool write (Xprt& xprt) const override {
231
- LOG_NOTE (" Writing product-index to %s" , xprt.to_string ().data ());
232
234
return xprt.write (index );
233
235
}
234
236
235
237
bool read (Xprt& xprt) override {
236
- LOG_NOTE (" Reading product-index from %s" , xprt.to_string ().data ());
237
238
return xprt.read (index );
238
239
}
239
240
};
@@ -271,21 +272,16 @@ struct DataSegId : public XprtAble
271
272
}
272
273
273
274
bool write (Xprt& xprt) const override {
274
- LOG_NOTE (" Writing data-segment identifier to %s" , xprt.to_string ().data ());
275
275
auto success = prodIndex.write (xprt);
276
276
if (success) {
277
- LOG_NOTE (" Writing offset to %s" , xprt.to_string ().data ());
278
277
success = xprt.write (offset);
279
278
}
280
279
return success;
281
280
}
282
281
283
282
bool read (Xprt& xprt) override {
284
- LOG_NOTE (" Reading data-segment identifier from %s" ,
285
- xprt.to_string ().data ());
286
283
auto success = prodIndex.read (xprt);
287
284
if (success) {
288
- LOG_NOTE (" Reading offset from %s" , xprt.to_string ().data ());
289
285
success = xprt.read (offset);
290
286
}
291
287
return success;
@@ -380,7 +376,7 @@ class DataSeg final : public XprtAble
380
376
381
377
operator bool () const ;
382
378
383
- const DataSegId getId () const noexcept ;
379
+ const DataSegId& getId () const noexcept ;
384
380
385
381
ProdSize getProdSize () const noexcept ;
386
382
@@ -394,6 +390,8 @@ class DataSeg final : public XprtAble
394
390
return getId ().offset ;
395
391
}
396
392
393
+ bool operator ==(const DataSeg& rhs) const ;
394
+
397
395
String to_string (bool withName = false ) const ;
398
396
399
397
bool write (Xprt& xprt) const override ;
@@ -435,7 +433,7 @@ class Product
435
433
* such entities can be handled as a single object for the purpose of argument
436
434
* passing and container element.
437
435
*/
438
- struct NoteReq
436
+ struct DatumId
439
437
{
440
438
public:
441
439
enum class Id {
@@ -448,42 +446,43 @@ struct NoteReq
448
446
DataSegId dataSegId;
449
447
};
450
448
451
- NoteReq () noexcept
449
+ DatumId () noexcept
452
450
: prodIndex()
453
451
, id(Id::UNSET)
454
452
{}
455
453
456
- explicit NoteReq (const ProdIndex prodIndex) noexcept
454
+ explicit DatumId (const ProdIndex prodIndex) noexcept
457
455
: id(Id::PROD_INDEX)
458
456
, prodIndex(prodIndex)
459
457
{}
460
458
461
- explicit NoteReq (const DataSegId dataSegId) noexcept
459
+ explicit DatumId (const DataSegId dataSegId) noexcept
462
460
: id(Id::DATA_SEG_ID)
463
461
, dataSegId(dataSegId)
464
462
{}
465
463
466
- NoteReq (const NoteReq& noteReq ) noexcept {
467
- ::memcpy (this , ¬eReq , sizeof (NoteReq ));
464
+ DatumId (const DatumId& datumId ) noexcept {
465
+ ::memcpy (this , &datumId , sizeof (DatumId ));
468
466
}
469
467
470
- ~NoteReq () noexcept {
468
+ ~DatumId () noexcept {
471
469
}
472
470
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
+ }
476
475
477
476
operator bool () const {
478
477
return id != Id::UNSET;
479
478
}
480
479
481
480
String to_string () const ;
482
481
483
- // `std::hash<NoteReq >()` is also defined
482
+ // `std::hash<DatumId >()` is also defined
484
483
size_t hash () const noexcept ;
485
484
486
- bool operator ==(const NoteReq & rhs) const noexcept ;
485
+ bool operator ==(const DatumId & rhs) const noexcept ;
487
486
};
488
487
489
488
/* *****************************************************************************/
@@ -505,8 +504,6 @@ class NoticeRcvr
505
504
{
506
505
public:
507
506
virtual ~NoticeRcvr () {}
508
- virtual void recvNotice (const PubPath notice,
509
- Peer peer) =0;
510
507
virtual bool recvNotice (const ProdIndex notice,
511
508
Peer peer) =0;
512
509
virtual bool recvNotice (const DataSegId notice,
@@ -520,8 +517,8 @@ class RequestRcvr
520
517
virtual ~RequestRcvr () {}
521
518
virtual ProdInfo recvRequest (const ProdIndex request,
522
519
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;
525
522
};
526
523
527
524
// / Data receiver/server
@@ -537,8 +534,8 @@ class DataRcvr
537
534
538
535
/* *
539
536
* 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 .
542
539
*/
543
540
class Node
544
541
{
@@ -552,7 +549,9 @@ class Node
552
549
* @return Product information. Will test false if it
553
550
* doesn't exist.
554
551
*/
555
- ProdInfo recvRequest (const ProdIndex request);
552
+ virtual ProdInfo recvRequest (
553
+ const ProdIndex request,
554
+ P2pMgr& p2pMgr) =0;
556
555
557
556
/* *
558
557
* Receives a request for a data-segment.
@@ -561,7 +560,9 @@ class Node
561
560
* @return Product information. Will test false if it
562
561
* doesn't exist.
563
562
*/
564
- DataSeg recvRequest (const DataSegId request);
563
+ virtual DataSeg recvRequest (
564
+ const DataSegId request,
565
+ P2pMgr& p2pMgr) =0;
565
566
};
566
567
567
568
/* *
@@ -572,24 +573,53 @@ class SubNode : public Node
572
573
{
573
574
public:
574
575
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;
575
607
};
576
608
577
609
} // namespace
578
610
579
611
namespace std {
580
612
template <>
581
- class hash <hycast::ProdIndex> {
582
- public:
613
+ struct hash <hycast::ProdIndex> {
583
614
size_t operator ()(const hycast::ProdIndex& prodIndex) const noexcept {
584
615
return prodIndex.hash ();
585
616
}
586
617
};
587
618
588
619
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 ();
593
623
}
594
624
};
595
625
}
0 commit comments