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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
crate::ix!();

/**
  | Data structure for an individual peer.
  | This struct is not protected by CS_MAIN
  | since it does not contain validation-critical
  | data.
  | 
  | Memory is owned by shared pointers and
  | this object is destructed when the refcount
  | drops to zero.
  | 
  | Mutexes inside this struct must not
  | be held when locking m_peer_mutex.
  | 
  | TODO: move most members from NodeState
  | to this structure.
  | 
  | TODO: move remaining application-layer
  | data members from Node to this structure.
  |
  */
pub struct Peer {

    /**
      | Same id as the Node object for this peer
      |
      */
    pub id:                NodeId, // default = { 0 }

    /**
      | Protects misbehavior data members
      |
      */
    pub misbehavior: Arc<Mutex<PeerMisbehavior>>,

    /**
      | Protects block inventory data members
      |
      */
    pub block_inv_mutex:   Arc<Mutex<PeerBlockInv>>,

    /**
      | This peer's reported block height when
      | we connected
      |
      */
    pub starting_height: Atomic<i32>, // default = { -1 }

    /**
      | The pong reply we're expecting, or 0
      | if no pong expected.
      |
      */
    pub ping_nonce_sent: Atomic<u64>, // default = { 0 }

    /**
      | When the last ping was sent, or 0 if no
      | ping was ever sent
      |
      */
    pub ping_start:      Atomic<OffsetDateTime /* micros */>, // default = { 0 }

    /**
      | Whether a ping has been requested by
      | the user
      |
      */
    pub ping_queued:     AtomicBool, // default = { false }

    /**
      | A vector of addresses to send to the peer,
      | limited to MAX_ADDR_TO_SEND.
      |
      */
    pub addrs_to_send:         Arc<Mutex<Vec<Address>>>,

    /**
      | Probabilistic filter to track recent
      | addr messages relayed with this peer.
      | Used to avoid relaying redundant addresses
      | to this peer.
      | 
      | We initialize this filter for outbound
      | peers (other than block-relay-only
      | connections) or when an inbound peer
      | sends us an address related message
      | (ADDR, ADDRV2, GETADDR).
      | 
      | Presence of this filter must correlate
      | with m_addr_relay_enabled.
      |
      */
    pub addr_known:            Option<RollingBloomFilter>,

    /**
      | Whether we are participating in address
      | relay with this connection.
      | 
      | We set this bool to true for outbound
      | peers (other than block-relay-only
      | connections), or when an inbound peer
      | sends us an address related message
      | (ADDR, ADDRV2, GETADDR).
      | 
      | We use this bool to decide whether a peer
      | is eligible for gossiping addr messages.
      | This avoids relaying to peers that are
      | unlikely to forward them, effectively
      | blackholing self announcements. Reasons
      | peers might support addr relay on the
      | link include that they connected to
      | us as a block-relay-only peer or they
      | are a light client.
      | 
      | This field must correlate with whether
      | m_addr_known has been initialized.
      |
      */
    pub addr_relay_enabled:    AtomicBool, // default = { false }

    /**
      | Whether a getaddr request to this peer
      | is outstanding.
      |
      */
    pub getaddr_sent:          bool, // default = { false }

    /**
      | Guards address sending timers.
      |
      */
    pub addr_send_times_mutex: Arc<Mutex<PeerAddrSendTimes>>,

    /**
      | Whether the peer has signaled support
      | for receiving ADDRv2 (BIP155) messages,
      | indicating a preference to receive
      | ADDRv2 instead of ADDR ones.
      |
      */
    pub wants_addrv2:           AtomicBool, // default = { false }

    /**
      | Whether this peer has already sent us
      | a getaddr message.
      |
      */
    pub getaddr_recvd:          bool, // default = { false }

    /**
      | Number of addresses that can be processed
      | from this peer. Start at 1 to permit self-announcement.
      |
      */
    pub addr_token_bucket:      f64, // default = { 1.0 }

    /**
      | When m_addr_token_bucket was last
      | updated
      |
      */
    pub addr_token_timestamp:   OffsetDateTime /* micros */,

    /**
      | Total number of addresses that were
      | dropped due to rate limiting.
      |
      */
    pub addr_rate_limited:      Atomic<u64>, // default = { 0 }

    /**
      | Total number of addresses that were
      | processed (excludes rate-limited
      | ones).
      |
      */
    pub addr_processed:         Atomic<u64>, // default = { 0 }

    //#[GUARDED_BY(g_cs_orphans)]
    pub orphan_work_set:        PeerOrphans,

    /**
      | Work queue of items requested by this
      | peer
      |
      */
    pub getdata_requests: Arc<Mutex<VecDeque<Inv>>>,
}

impl Peer {
    
    pub fn new(id: NodeId) -> Self {
    
        todo!();
        /*
        : id(id),

        
        */
    }
}