aboutsummaryrefslogtreecommitdiffstats
path: root/src/peer.rs
blob: 29b90a25ff1452ebb1f13ec2ab05470700278abc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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)
    }
}