• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ergoplatform / sigma-rust / 16405540612

20 Jul 2025 11:50PM UTC coverage: 78.438% (-0.01%) from 78.451%
16405540612

Pull #790

github

web-flow
Merge 7bd76aff4 into 2725f402c
Pull Request #790: Use precomputed tables

62 of 69 new or added lines in 16 files covered. (89.86%)

10 existing lines in 5 files now uncovered.

11961 of 15249 relevant lines covered (78.44%)

2.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.42
/ergo-p2p/src/peer_info.rs
1
//! Peer info types
2

3
use ergo_chain_types::{ConnectionDirection, PeerAddr};
4

5
use crate::{peer_spec::PeerSpec, protocol_version::ProtocolVersion};
6

7
/// Information about peer to be stored in PeerDatabase
8
#[derive(PartialEq, Eq, Debug, Clone, Hash)]
9
pub struct PeerInfo {
10
    /// general information about the peer
11
    peer_spec: PeerSpec,
12
    /// timestamp when last handshake was done
13
    last_handshake: u64,
14
    /// type of connection (Incoming/Outgoing) established to this peer if any
15
    conn_type: Option<ConnectionDirection>,
16
}
17

18
impl PeerInfo {
19
    /// Create new PeerInfo instance
20
    pub fn new(
1✔
21
        peer_spec: PeerSpec,
22
        last_handshake: u64,
23
        conn_type: Option<ConnectionDirection>,
24
    ) -> Self {
25
        Self {
26
            peer_spec,
27
            last_handshake,
28
            conn_type,
29
        }
30
    }
31

32
    /// Return the PeerSpec associated with this PeerInfo
33
    pub fn spec(&self) -> PeerSpec {
3✔
34
        self.peer_spec.clone()
1✔
35
    }
36

37
    /// Create peer info from address only, when we don't know other fields
38
    /// (e.g. we got this information from config or from API)
39
    pub fn from_addr(addr: PeerAddr) -> PeerInfo {
×
40
        let peer_spec = PeerSpec::new(
41
            "unknown",
42
            ProtocolVersion::INITIAL,
43
            &format!("unknown-{}", addr),
×
44
            Some(addr),
×
45
            None,
×
46
        );
47

48
        PeerInfo::new(peer_spec, 0, None)
×
49
    }
50
}
51

52
/// Arbitrary
53
#[cfg(feature = "arbitrary")]
54
pub mod arbitrary {
55
    use super::*;
56
    use proptest::prelude::{Arbitrary, BoxedStrategy};
57
    use proptest::{option, prelude::*};
58

59
    impl Arbitrary for PeerInfo {
60
        type Parameters = ();
61
        type Strategy = BoxedStrategy<Self>;
62

63
        fn arbitrary_with(_: Self::Parameters) -> Self::Strategy {
3✔
64
            (
65
                any::<PeerSpec>(),
3✔
66
                any::<u64>(),
4✔
67
                option::of(prop_oneof![
8✔
68
                    Just(ConnectionDirection::Incoming),
4✔
69
                    Just(ConnectionDirection::Outgoing)
4✔
70
                ]),
71
            )
72
                .prop_map(|(spec, timestamp, direction)| PeerInfo::new(spec, timestamp, direction))
4✔
73
                .boxed()
74
        }
75
    }
76

77
    impl PeerInfo {
78
        /// Ensure the PeerSpec has a valid addr
79
        /// This can happen if declared_addr is none and there is no LocalAddressPeerFeature in features
80
        pub fn with_ensured_addr(mut self) -> Self {
3✔
81
            if self.peer_spec.addr().is_none() {
6✔
UNCOV
82
                self.peer_spec = self.peer_spec.with_ensured_addr();
×
83
            }
84
            self
3✔
85
        }
86
    }
87
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc