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 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281
crate::ix!();
//-------------------------------------------[.cpp/bitcoin/src/test/util/net.h]
pub struct ConnmanTestMsg {
base: Connman,
}
impl ConnmanTestMsg {
pub fn set_peer_connect_timeout(&mut self, timeout: i64) {
todo!();
/*
m_peer_connect_timeout = timeout;
*/
}
pub fn add_test_node(&mut self, node: &mut Node) {
todo!();
/*
LOCK(cs_vNodes);
vNodes.push_back(&node);
*/
}
pub fn clear_test_nodes(&mut self) {
todo!();
/*
LOCK(cs_vNodes);
for (Node* node : vNodes) {
delete node;
}
vNodes.clear();
*/
}
pub fn process_messages_once(&mut self, node: &mut AmoWriteGuard<Node>) {
todo!();
/*
m_msgproc->ProcessMessages(&node, flagInterruptMsgProc);
*/
}
pub fn node_receive_msg_bytes(&self,
node: &mut Node,
msg_bytes: &[u8],
complete: &mut bool) {
todo!();
/*
assert(node.ReceiveMsgBytes(msg_bytes, complete));
if (complete) {
size_t nSizeAdded = 0;
auto it(node.vRecvMsg.begin());
for (; it != node.vRecvMsg.end(); ++it) {
// vRecvMsg contains only completed CNetMessage
// the single possible partially deserialized message are held by TransportDeserializer
nSizeAdded += it->m_raw_message_size;
}
{
LOCK(node.cs_vProcessMsg);
node.vProcessMsg.splice(node.vProcessMsg.end(), node.vRecvMsg, node.vRecvMsg.begin(), it);
node.nProcessQueueSize += nSizeAdded;
node.fPauseRecv = node.nProcessQueueSize > nReceiveFloodSize;
}
}
*/
}
pub fn receive_msg_from(&self,
node: &mut Node,
ser_msg: &mut SerializedNetMsg) -> bool {
todo!();
/*
std::vector<uint8_t> ser_msg_header;
node.m_serializer->prepareForTransport(ser_msg, ser_msg_header);
bool complete;
NodeReceiveMsgBytes(node, ser_msg_header, complete);
NodeReceiveMsgBytes(node, ser_msg.data, complete);
return complete;
*/
}
}
pub const ALL_SERVICE_FLAGS: &[ServiceFlags] = &[
ServiceFlags::NODE_NONE,
ServiceFlags::NODE_NETWORK,
ServiceFlags::NODE_BLOOM,
ServiceFlags::NODE_WITNESS,
ServiceFlags::NODE_COMPACT_FILTERS,
ServiceFlags::NODE_NETWORK_LIMITED,
];
pub const ALL_NET_PERMISSION_FLAGS: &[NetPermissionFlags] = &[
NetPermissionFlags::None,
NetPermissionFlags::BloomFilter,
NetPermissionFlags::Relay,
NetPermissionFlags::ForceRelay,
NetPermissionFlags::NoBan,
NetPermissionFlags::Mempool,
NetPermissionFlags::Addr,
NetPermissionFlags::Download,
NetPermissionFlags::Implicit,
NetPermissionFlags::All,
];
pub const ALL_CONNECTION_TYPES: &[ConnectionType] = &[
ConnectionType::INBOUND,
ConnectionType::OUTBOUND_FULL_RELAY,
ConnectionType::MANUAL,
ConnectionType::FEELER,
ConnectionType::BLOCK_RELAY,
ConnectionType::ADDR_FETCH,
];
pub const ALL_NETWORKS: &[Network] = &[
Network::NET_UNROUTABLE,
Network::NET_IPV4,
Network::NET_IPV6,
Network::NET_ONION,
Network::NET_I2P,
Network::NET_CJDNS,
Network::NET_INTERNAL,
];
/**
| A mocked Sock alternative that returns
| a statically contained data upon read
| and succeeds and ignores all writes.
| The data to be returned is given to the
| constructor and when it is exhausted
| an EOF is returned by further reads.
|
*/
pub struct StaticContentsSock {
base: Sock,
contents: String,
consumed: RefCell<usize>,
}
impl Drop for StaticContentsSock {
fn drop(&mut self) {
todo!();
/*
Reset();
*/
}
}
impl StaticContentsSock {
pub fn new(contents: &String) -> Self {
todo!();
/*
: m_contents{contents}, m_consumed{0}
// Just a dummy number that is not INVALID_SOCKET.
m_socket = INVALID_SOCKET - 1;
*/
}
pub fn assign_from(&mut self, other: Sock) -> &mut StaticContentsSock {
todo!();
/*
assert(false && "Move of Sock into MockSock not allowed.");
return *this;
*/
}
pub fn reset(&mut self) {
todo!();
/*
m_socket = INVALID_SOCKET;
*/
}
pub fn send(&self,
_0: *const c_void,
len: usize,
_2: i32) -> isize {
todo!();
/*
return len;
*/
}
pub fn recv(&self,
buf: *mut c_void,
len: usize,
flags: i32) -> isize {
todo!();
/*
const size_t consume_bytes{std::min(len, m_contents.size() - m_consumed)};
std::memcpy(buf, m_contents.data() + m_consumed, consume_bytes);
if ((flags & MSG_PEEK) == 0) {
m_consumed += consume_bytes;
}
return consume_bytes;
*/
}
pub fn connect(&self,
_0: *const SocketAddr,
_1: libc::socklen_t) -> i32 {
todo!();
/*
return 0;
*/
}
pub fn get_sock_opt(&self,
level: i32,
opt_name: i32,
opt_val: *mut c_void,
opt_len: *mut libc::socklen_t) -> i32 {
todo!();
/*
std::memset(opt_val, 0x0, *opt_len);
return 0;
*/
}
pub fn wait(&self,
timeout: Duration /* milliseconds */,
requested: libevent_sys::event,
occurred: Option<*mut libevent_sys::event>) -> bool {
todo!();
/*
if (occurred != nullptr) {
*occurred = requested;
}
return true;
*/
}
}
//-------------------------------------------[.cpp/bitcoin/src/test/util/net.cpp]
pub fn get_random_node_eviction_candidates(
n_candidates: i32,
random_context: &mut FastRandomContext) -> Vec<NodeEvictionCandidate> {
todo!();
/*
std::vector<NodeEvictionCandidate> candidates;
for (int id = 0; id < n_candidates; ++id) {
candidates.push_back({
/* id */ id,
/* nTimeConnected */ static_cast<int64_t>(random_context.randrange(100)),
/* m_min_ping_time */ std::chrono::microseconds{random_context.randrange(100)},
/* nLastBlockTime */ static_cast<int64_t>(random_context.randrange(100)),
/* nLastTXTime */ static_cast<int64_t>(random_context.randrange(100)),
/* fRelevantServices */ random_context.randbool(),
/* fRelayTxes */ random_context.randbool(),
/* fBloomFilter */ random_context.randbool(),
/* nKeyedNetGroup */ random_context.randrange(100),
/* prefer_evict */ random_context.randbool(),
/* m_is_local */ random_context.randbool(),
/* m_network */ ALL_NETWORKS[random_context.randrange(ALL_NETWORKS.size())],
});
}
return candidates;
*/
}