Add winning_probability param to replace num_hops in CoverTrafficSettings
This commit is contained in:
parent
360a9aa558
commit
e188b6109c
|
@ -12,13 +12,12 @@ use std::task::{Context, Poll};
|
||||||
#[derive(Copy, Clone, Deserialize)]
|
#[derive(Copy, Clone, Deserialize)]
|
||||||
pub struct CoverTrafficSettings {
|
pub struct CoverTrafficSettings {
|
||||||
pub node_id: [u8; 32],
|
pub node_id: [u8; 32],
|
||||||
pub number_of_hops: usize,
|
pub winning_probability: f64,
|
||||||
pub slots_per_epoch: usize,
|
pub slots_per_epoch: usize,
|
||||||
pub network_size: usize,
|
pub network_size: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CoverTraffic<EpochStream, SlotStream, Message> {
|
pub struct CoverTraffic<EpochStream, SlotStream, Message> {
|
||||||
winning_probability: f64,
|
|
||||||
settings: CoverTrafficSettings,
|
settings: CoverTrafficSettings,
|
||||||
epoch_stream: EpochStream,
|
epoch_stream: EpochStream,
|
||||||
slot_stream: SlotStream,
|
slot_stream: SlotStream,
|
||||||
|
@ -36,9 +35,7 @@ where
|
||||||
epoch_stream: EpochStream,
|
epoch_stream: EpochStream,
|
||||||
slot_stream: SlotStream,
|
slot_stream: SlotStream,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let winning_probability = winning_probability(settings.number_of_hops);
|
|
||||||
CoverTraffic {
|
CoverTraffic {
|
||||||
winning_probability,
|
|
||||||
settings,
|
settings,
|
||||||
epoch_stream,
|
epoch_stream,
|
||||||
slot_stream,
|
slot_stream,
|
||||||
|
@ -58,7 +55,6 @@ where
|
||||||
|
|
||||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
|
||||||
let Self {
|
let Self {
|
||||||
winning_probability,
|
|
||||||
settings,
|
settings,
|
||||||
epoch_stream,
|
epoch_stream,
|
||||||
slot_stream,
|
slot_stream,
|
||||||
|
@ -71,7 +67,7 @@ where
|
||||||
epoch,
|
epoch,
|
||||||
settings.network_size,
|
settings.network_size,
|
||||||
settings.slots_per_epoch,
|
settings.slots_per_epoch,
|
||||||
*winning_probability,
|
settings.winning_probability,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if let Poll::Ready(Some(slot)) = slot_stream.poll_next_unpin(cx) {
|
if let Poll::Ready(Some(slot)) = slot_stream.poll_next_unpin(cx) {
|
||||||
|
@ -107,7 +103,3 @@ fn select_slot<Id: Hash + Eq + AsRef<[u8]> + Copy>(
|
||||||
}
|
}
|
||||||
w
|
w
|
||||||
}
|
}
|
||||||
|
|
||||||
fn winning_probability(number_of_hops: usize) -> f64 {
|
|
||||||
1.0 / number_of_hops as f64
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue