diff options
Diffstat (limited to 'src/peer.rs')
-rw-r--r-- | src/peer.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/peer.rs b/src/peer.rs new file mode 100644 index 0000000..29b90a2 --- /dev/null +++ b/src/peer.rs @@ -0,0 +1,31 @@ + +use errors::*; +use sleep_register::{HyperRegister, SleepDirRegister}; +use protocol::DatConnection; +use bitfield::Bitfield; + +pub struct DatPeer { + registers: Vec<SleepDirRegister>, + connection: DatConnection, + have_log: Vec<Vec<Bitfield>>, +} + +impl DatPeer { + + pub fn new(connection: DatConnection, registers: Vec<SleepDirRegister>) -> DatPeer { + DatPeer { + registers, + connection, + have_log: vec![], + } + } + + pub fn has(self, register: u64, index: u64) -> Result<bool> { + for bitfield in self.have_log[register as usize].iter() { + if bitfield.get(index)? { + return Ok(true) + } + } + Ok(false) + } +} |