@@ -2,6 +2,7 @@ package node
2
2
3
3
import (
4
4
"context"
5
+ "github.com/unpackdev/fdb/pkg/types"
5
6
"sync"
6
7
"time"
7
8
@@ -25,24 +26,6 @@ const (
25
26
// P2PDistributorStateType is the type identifier for P2PDistributor state
26
27
const P2PDistributorStateType state.StateType = "p2p_distributor"
27
28
28
- // Priority represents the importance level of a record batch
29
- type Priority uint8
30
-
31
- const (
32
- PriorityHigh Priority = iota
33
- PriorityNormal
34
- PriorityLow
35
- )
36
-
37
- // Target specifies the distribution target type
38
- type Target uint8
39
-
40
- const (
41
- TargetAll Target = iota
42
- TargetValidators
43
- TargetDirectPeer
44
- )
45
-
46
29
// DistributionStats tracks performance metrics
47
30
type DistributionStats struct {
48
31
RecordsDistributed int64
@@ -56,8 +39,8 @@ type DistributionStats struct {
56
39
// RecordBatch represents a batch of records to be distributed
57
40
type RecordBatch struct {
58
41
Records []db.WriteRequest
59
- Priority Priority
60
- Target Target
42
+ Priority types. Priority
43
+ Target types. Target
61
44
TargetPeer * peer.ID // Only set if Target is TargetDirectPeer
62
45
}
63
46
@@ -439,13 +422,13 @@ func (d *P2PDistributor) distributeBatch(batch *RecordBatch) {
439
422
zap .Uint8 ("priority" , uint8 (batch .Priority )))
440
423
441
424
switch batch .Target {
442
- case TargetAll :
425
+ case types . TargetAll :
443
426
d .logger .Debug ("Distributing to all peers" , zap .Int ("record_count" , recordCount ))
444
427
d .distributeToAllPeers (batch )
445
- case TargetValidators :
428
+ case types . TargetValidators :
446
429
d .logger .Debug ("Distributing to validators" , zap .Int ("record_count" , recordCount ))
447
430
d .distributeToValidators (batch )
448
- case TargetDirectPeer :
431
+ case types . TargetDirectPeer :
449
432
if batch .TargetPeer != nil {
450
433
d .logger .Debug ("Distributing to direct peer" ,
451
434
zap .Int ("record_count" , recordCount ),
@@ -458,7 +441,7 @@ func (d *P2PDistributor) distributeBatch(batch *RecordBatch) {
458
441
}
459
442
460
443
// DistributeRecord adds a record to the appropriate distribution queue
461
- func (d * P2PDistributor ) DistributeRecord (key [32 ]byte , value []byte , priority Priority , target Target ) error {
444
+ func (d * P2PDistributor ) DistributeRecord (key [32 ]byte , value []byte , priority types. Priority , target types. Target ) error {
462
445
// Create a deep copy of the value when a record first enters the system
463
446
valueCopy := make ([]byte , len (value ))
464
447
copy (valueCopy , value )
@@ -477,11 +460,11 @@ func (d *P2PDistributor) DistributeRecord(key [32]byte, value []byte, priority P
477
460
// Queue based on priority
478
461
var queue chan * RecordBatch
479
462
switch priority {
480
- case PriorityHigh :
463
+ case types . PriorityHigh :
481
464
queue = d .highPriorityQueue
482
- case PriorityNormal :
465
+ case types . PriorityNormal :
483
466
queue = d .normalQueue
484
- case PriorityLow :
467
+ case types . PriorityLow :
485
468
queue = d .lowPriorityQueue
486
469
}
487
470
@@ -508,7 +491,7 @@ func (d *P2PDistributor) DistributeRecord(key [32]byte, value []byte, priority P
508
491
}
509
492
510
493
// DistributeRecordToPeer sends a record directly to a specific peer
511
- func (d * P2PDistributor ) DistributeRecordToPeer (key [32 ]byte , value []byte , peerID peer.ID , priority Priority ) error {
494
+ func (d * P2PDistributor ) DistributeRecordToPeer (key [32 ]byte , value []byte , peerID peer.ID , priority types. Priority ) error {
512
495
// Create a deep copy of the value when a record first enters the system
513
496
valueCopy := make ([]byte , len (value ))
514
497
copy (valueCopy , value )
@@ -521,18 +504,18 @@ func (d *P2PDistributor) DistributeRecordToPeer(key [32]byte, value []byte, peer
521
504
batch := & RecordBatch {
522
505
Records : []db.WriteRequest {record },
523
506
Priority : priority ,
524
- Target : TargetDirectPeer ,
507
+ Target : types . TargetDirectPeer ,
525
508
TargetPeer : & peerID ,
526
509
}
527
510
528
511
// Queue based on priority
529
512
var queue chan * RecordBatch
530
513
switch priority {
531
- case PriorityHigh :
514
+ case types . PriorityHigh :
532
515
queue = d .highPriorityQueue
533
- case PriorityNormal :
516
+ case types . PriorityNormal :
534
517
queue = d .normalQueue
535
- case PriorityLow :
518
+ case types . PriorityLow :
536
519
queue = d .lowPriorityQueue
537
520
}
538
521
0 commit comments