Rename the network module to p2p

The `network` module deals with data types and logic related to
internetworking bitcoind nodes, this is commonly referred to as the p2p
layer.

Rename the `network` module to `p2p` and fix all the paths.
This commit is contained in:
Tobin C. Harding 2023-05-25 09:14:42 +10:00
parent dac97072a5
commit 1bac1fd518
No known key found for this signature in database
GPG Key ID: 40BF9E4C269D6607
22 changed files with 43 additions and 44 deletions

View File

@ -6,7 +6,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
use std::{env, process}; use std::{env, process};
use bitcoin::consensus::{encode, Decodable}; use bitcoin::consensus::{encode, Decodable};
use bitcoin::network::{address, constants, message, message_network}; use bitcoin::p2p::{address, constants, message, message_network};
use bitcoin::secp256k1; use bitcoin::secp256k1;
use bitcoin::secp256k1::rand::Rng; use bitcoin::secp256k1::rand::Rng;

View File

@ -46,7 +46,7 @@ use crate::blockdata::script::witness_version::{self, WitnessVersion};
use crate::blockdata::script::{self, Script, ScriptBuf}; use crate::blockdata::script::{self, Script, ScriptBuf};
use crate::crypto::key::{PublicKey, TapTweak, TweakedPublicKey, UntweakedPublicKey}; use crate::crypto::key::{PublicKey, TapTweak, TweakedPublicKey, UntweakedPublicKey};
use crate::hash_types::{PubkeyHash, ScriptHash}; use crate::hash_types::{PubkeyHash, ScriptHash};
use crate::network::constants::Network; use crate::p2p::constants::Network;
use crate::prelude::*; use crate::prelude::*;
use crate::taproot::TapNodeHash; use crate::taproot::TapNodeHash;
@ -996,7 +996,7 @@ mod tests {
use super::*; use super::*;
use crate::crypto::key::PublicKey; use crate::crypto::key::PublicKey;
use crate::network::constants::Network::{Bitcoin, Testnet}; use crate::p2p::constants::Network::{Bitcoin, Testnet};
fn roundtrips(addr: &Address) { fn roundtrips(addr: &Address) {
assert_eq!( assert_eq!(

View File

@ -23,7 +23,7 @@ use crate::crypto::key::{self, KeyPair, PrivateKey, PublicKey};
use crate::hash_types::XpubIdentifier; use crate::hash_types::XpubIdentifier;
use crate::internal_macros::impl_bytes_newtype; use crate::internal_macros::impl_bytes_newtype;
use crate::io::Write; use crate::io::Write;
use crate::network::constants::Network; use crate::p2p::constants::Network;
use crate::prelude::*; use crate::prelude::*;
/// A chain code /// A chain code
@ -866,7 +866,7 @@ mod tests {
use super::ChildNumber::{Hardened, Normal}; use super::ChildNumber::{Hardened, Normal};
use super::*; use super::*;
use crate::internal_macros::hex; use crate::internal_macros::hex;
use crate::network::constants::Network::{self, Bitcoin}; use crate::p2p::constants::Network::{self, Bitcoin};
#[test] #[test]
fn test_parse_derivation_path() { fn test_parse_derivation_path() {

View File

@ -20,7 +20,7 @@ use crate::blockdata::script;
use crate::blockdata::transaction::{OutPoint, Sequence, Transaction, TxIn, TxOut}; use crate::blockdata::transaction::{OutPoint, Sequence, Transaction, TxIn, TxOut};
use crate::blockdata::witness::Witness; use crate::blockdata::witness::Witness;
use crate::internal_macros::impl_bytes_newtype; use crate::internal_macros::impl_bytes_newtype;
use crate::network::constants::Network; use crate::p2p::constants::Network;
use crate::pow::CompactTarget; use crate::pow::CompactTarget;
use crate::Amount; use crate::Amount;
@ -198,7 +198,7 @@ mod test {
use crate::blockdata::locktime::absolute; use crate::blockdata::locktime::absolute;
use crate::consensus::encode::serialize; use crate::consensus::encode::serialize;
use crate::internal_macros::hex; use crate::internal_macros::hex;
use crate::network::constants::Network; use crate::p2p::constants::Network;
#[test] #[test]
fn bitcoin_genesis_first_transaction() { fn bitcoin_genesis_first_transaction() {

View File

@ -68,7 +68,7 @@ impl OutPoint {
/// ///
/// ```rust /// ```rust
/// use bitcoin::constants::genesis_block; /// use bitcoin::constants::genesis_block;
/// use bitcoin::network::constants::Network; /// use bitcoin::p2p::constants::Network;
/// ///
/// let block = genesis_block(Network::Bitcoin); /// let block = genesis_block(Network::Bitcoin);
/// let tx = &block.txdata[0]; /// let tx = &block.txdata[0];
@ -1508,7 +1508,7 @@ mod tests {
#[test] #[test]
fn test_is_coinbase() { fn test_is_coinbase() {
use crate::blockdata::constants; use crate::blockdata::constants;
use crate::network::constants::Network; use crate::p2p::constants::Network;
let genesis = constants::genesis_block(Network::Bitcoin); let genesis = constants::genesis_block(Network::Bitcoin);
assert!(genesis.txdata[0].is_coinbase()); assert!(genesis.txdata[0].is_coinbase());

View File

@ -26,7 +26,7 @@ use crate::blockdata::transaction::{Transaction, TxIn, TxOut};
use crate::hash_types::{BlockHash, FilterHash, FilterHeader, TxMerkleNode}; use crate::hash_types::{BlockHash, FilterHash, FilterHeader, TxMerkleNode};
use crate::io::{self, Cursor, Read}; use crate::io::{self, Cursor, Read};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use crate::network::{ use crate::p2p::{
address::{AddrV2Message, Address}, address::{AddrV2Message, Address},
message_blockdata::Inventory, message_blockdata::Inventory,
}; };
@ -836,7 +836,7 @@ mod tests {
use super::*; use super::*;
use crate::consensus::{deserialize_partial, Decodable, Encodable}; use crate::consensus::{deserialize_partial, Decodable, Encodable};
#[cfg(feature = "std")] #[cfg(feature = "std")]
use crate::network::{message_blockdata::Inventory, Address}; use crate::p2p::{message_blockdata::Inventory, Address};
#[test] #[test]
fn serialize_int_test() { fn serialize_int_test() {

View File

@ -6,7 +6,7 @@
//! chains (such as mainnet, testnet). //! chains (such as mainnet, testnet).
//! //!
use crate::network::constants::Network; use crate::p2p::constants::Network;
use crate::pow::Work; use crate::pow::Work;
/// Parameters that influence chain consensus. /// Parameters that influence chain consensus.

View File

@ -18,7 +18,7 @@ pub use secp256k1::{self, constants, KeyPair, Parity, Secp256k1, Verification, X
use crate::crypto::ecdsa; use crate::crypto::ecdsa;
use crate::hash_types::{PubkeyHash, WPubkeyHash}; use crate::hash_types::{PubkeyHash, WPubkeyHash};
use crate::network::constants::Network; use crate::p2p::constants::Network;
use crate::prelude::*; use crate::prelude::*;
use crate::taproot::{TapNodeHash, TapTweakHash}; use crate::taproot::{TapNodeHash, TapTweakHash};
use crate::{base58, io}; use crate::{base58, io};
@ -741,7 +741,7 @@ mod tests {
use super::*; use super::*;
use crate::address::Address; use crate::address::Address;
use crate::io; use crate::io;
use crate::network::constants::Network::{Bitcoin, Testnet}; use crate::p2p::constants::Network::{Bitcoin, Testnet};
#[test] #[test]
fn test_key_derivation() { fn test_key_derivation() {

View File

@ -1120,7 +1120,7 @@ mod tests {
use crate::crypto::key::PublicKey; use crate::crypto::key::PublicKey;
use crate::crypto::sighash::{LegacySighash, TapSighash}; use crate::crypto::sighash::{LegacySighash, TapSighash};
use crate::internal_macros::hex; use crate::internal_macros::hex;
use crate::network::constants::Network; use crate::p2p::constants::Network;
use crate::taproot::TapLeafHash; use crate::taproot::TapLeafHash;
extern crate serde_json; extern crate serde_json;

View File

@ -92,7 +92,7 @@ mod parse;
mod serde_utils; mod serde_utils;
#[macro_use] #[macro_use]
pub mod network; pub mod p2p;
pub mod address; pub mod address;
pub mod amount; pub mod amount;
pub mod base58; pub mod base58;
@ -146,7 +146,7 @@ pub use crate::hash_types::{
BlockHash, PubkeyHash, ScriptHash, Txid, WPubkeyHash, WScriptHash, Wtxid, BlockHash, PubkeyHash, ScriptHash, Txid, WPubkeyHash, WScriptHash, Wtxid,
}; };
pub use crate::merkle_tree::MerkleBlock; pub use crate::merkle_tree::MerkleBlock;
pub use crate::network::constants::Network; pub use crate::p2p::constants::Network;
pub use crate::pow::{CompactTarget, Target, Work}; pub use crate::pow::{CompactTarget, Target, Work};
pub use crate::psbt::Psbt; pub use crate::psbt::Psbt;

View File

@ -11,7 +11,7 @@ use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6, ToSoc
use crate::consensus::encode::{self, Decodable, Encodable, ReadExt, VarInt, WriteExt}; use crate::consensus::encode::{self, Decodable, Encodable, ReadExt, VarInt, WriteExt};
use crate::io; use crate::io;
use crate::network::constants::ServiceFlags; use crate::p2p::constants::ServiceFlags;
use crate::prelude::*; use crate::prelude::*;
/// A message which can be sent on the Bitcoin network /// A message which can be sent on the Bitcoin network
@ -311,7 +311,7 @@ mod test {
use super::{AddrV2, AddrV2Message, Address}; use super::{AddrV2, AddrV2Message, Address};
use crate::consensus::encode::{deserialize, serialize}; use crate::consensus::encode::{deserialize, serialize};
use crate::internal_macros::hex; use crate::internal_macros::hex;
use crate::network::constants::ServiceFlags; use crate::p2p::constants::ServiceFlags;
#[test] #[test]
fn serialize_address_test() { fn serialize_address_test() {

View File

@ -16,7 +16,7 @@
//! # Example: encoding a network's magic bytes //! # Example: encoding a network's magic bytes
//! //!
//! ```rust //! ```rust
//! use bitcoin::network::constants::Network; //! use bitcoin::p2p::constants::Network;
//! use bitcoin::consensus::encode::serialize; //! use bitcoin::consensus::encode::serialize;
//! //!
//! let network = Network::Bitcoin; //! let network = Network::Bitcoin;
@ -82,7 +82,7 @@ impl Network {
/// # Examples /// # Examples
/// ///
/// ```rust /// ```rust
/// use bitcoin::network::constants::{Network, Magic}; /// use bitcoin::p2p::constants::{Network, Magic};
/// use std::convert::TryFrom; /// use std::convert::TryFrom;
/// ///
/// assert_eq!(Ok(Network::Bitcoin), Network::try_from(Magic::from_bytes([0xF9, 0xBE, 0xB4, 0xD9]))); /// assert_eq!(Ok(Network::Bitcoin), Network::try_from(Magic::from_bytes([0xF9, 0xBE, 0xB4, 0xD9])));
@ -96,7 +96,7 @@ impl Network {
/// # Examples /// # Examples
/// ///
/// ```rust /// ```rust
/// use bitcoin::network::constants::{Network, Magic}; /// use bitcoin::p2p::constants::{Network, Magic};
/// ///
/// let network = Network::Bitcoin; /// let network = Network::Bitcoin;
/// assert_eq!(network.magic(), Magic::from_bytes([0xF9, 0xBE, 0xB4, 0xD9])); /// assert_eq!(network.magic(), Magic::from_bytes([0xF9, 0xBE, 0xB4, 0xD9]));
@ -148,7 +148,7 @@ impl Network {
/// # Examples /// # Examples
/// ///
/// ```rust /// ```rust
/// use bitcoin::network::constants::Network; /// use bitcoin::p2p::constants::Network;
/// use bitcoin::blockdata::constants::ChainHash; /// use bitcoin::blockdata::constants::ChainHash;
/// ///
/// let network = Network::Bitcoin; /// let network = Network::Bitcoin;
@ -161,7 +161,7 @@ impl Network {
/// # Examples /// # Examples
/// ///
/// ```rust /// ```rust
/// use bitcoin::network::constants::Network; /// use bitcoin::p2p::constants::Network;
/// use bitcoin::blockdata::constants::ChainHash; /// use bitcoin::blockdata::constants::ChainHash;
/// use std::convert::TryFrom; /// use std::convert::TryFrom;
/// ///
@ -723,7 +723,7 @@ mod tests {
#[derive(Serialize, Deserialize, PartialEq, Debug)] #[derive(Serialize, Deserialize, PartialEq, Debug)]
#[serde(crate = "actual_serde")] #[serde(crate = "actual_serde")]
struct T { struct T {
#[serde(with = "crate::network::constants::as_core_arg")] #[serde(with = "crate::p2p::constants::as_core_arg")]
pub network: Network, pub network: Network,
} }

View File

@ -16,9 +16,9 @@ use crate::blockdata::{block, transaction};
use crate::consensus::encode::{self, CheckedData, Decodable, Encodable, VarInt}; use crate::consensus::encode::{self, CheckedData, Decodable, Encodable, VarInt};
use crate::io; use crate::io;
use crate::merkle_tree::MerkleBlock; use crate::merkle_tree::MerkleBlock;
use crate::network::address::{AddrV2Message, Address}; use crate::p2p::address::{AddrV2Message, Address};
use crate::network::constants::Magic; use crate::p2p::constants::Magic;
use crate::network::{ use crate::p2p::{
message_blockdata, message_bloom, message_compact_blocks, message_filter, message_network, message_blockdata, message_bloom, message_compact_blocks, message_filter, message_network,
}; };
use crate::prelude::*; use crate::prelude::*;
@ -549,12 +549,12 @@ mod test {
use crate::blockdata::transaction::Transaction; use crate::blockdata::transaction::Transaction;
use crate::consensus::encode::{deserialize, deserialize_partial, serialize}; use crate::consensus::encode::{deserialize, deserialize_partial, serialize};
use crate::internal_macros::hex; use crate::internal_macros::hex;
use crate::network::address::{AddrV2, AddrV2Message, Address}; use crate::p2p::address::{AddrV2, AddrV2Message, Address};
use crate::network::constants::{Magic, Network, ServiceFlags}; use crate::p2p::constants::{Magic, Network, ServiceFlags};
use crate::network::message_blockdata::{GetBlocksMessage, GetHeadersMessage, Inventory}; use crate::p2p::message_blockdata::{GetBlocksMessage, GetHeadersMessage, Inventory};
use crate::network::message_bloom::{BloomFlags, FilterAdd, FilterLoad}; use crate::p2p::message_bloom::{BloomFlags, FilterAdd, FilterLoad};
use crate::network::message_compact_blocks::{GetBlockTxn, SendCmpct}; use crate::p2p::message_compact_blocks::{GetBlockTxn, SendCmpct};
use crate::network::message_filter::{ use crate::p2p::message_filter::{
CFCheckpt, CFHeaders, CFilter, GetCFCheckpt, GetCFHeaders, GetCFilters, CFCheckpt, CFHeaders, CFilter, GetCFCheckpt, GetCFHeaders, GetCFilters,
}; };

View File

@ -12,7 +12,7 @@ use crate::consensus::encode::{self, Decodable, Encodable};
use crate::hash_types::{BlockHash, Txid, Wtxid}; use crate::hash_types::{BlockHash, Txid, Wtxid};
use crate::internal_macros::impl_consensus_encoding; use crate::internal_macros::impl_consensus_encoding;
use crate::io; use crate::io;
use crate::network::constants; use crate::p2p::constants;
use crate::prelude::*; use crate::prelude::*;
/// An inventory item. /// An inventory item.

View File

@ -11,8 +11,8 @@ use hashes::sha256d;
use crate::consensus::{encode, Decodable, Encodable, ReadExt}; use crate::consensus::{encode, Decodable, Encodable, ReadExt};
use crate::internal_macros::impl_consensus_encoding; use crate::internal_macros::impl_consensus_encoding;
use crate::io; use crate::io;
use crate::network::address::Address; use crate::p2p::address::Address;
use crate::network::constants::{self, ServiceFlags}; use crate::p2p::constants::{self, ServiceFlags};
use crate::prelude::*; use crate::prelude::*;
/// Some simple messages /// Some simple messages
@ -146,7 +146,7 @@ mod tests {
use super::{Reject, RejectReason, VersionMessage}; use super::{Reject, RejectReason, VersionMessage};
use crate::consensus::encode::{deserialize, serialize}; use crate::consensus::encode::{deserialize, serialize};
use crate::internal_macros::hex; use crate::internal_macros::hex;
use crate::network::constants::ServiceFlags; use crate::p2p::constants::ServiceFlags;
#[test] #[test]
fn version_message_test() { fn version_message_test() {

View File

@ -1,10 +1,9 @@
// SPDX-License-Identifier: CC0-1.0 // SPDX-License-Identifier: CC0-1.0
//! Bitcoin network support. //! Bitcoin p2p network types.
//! //!
//! This module defines support for (de)serialization and network transport //! This module defines support for (de)serialization and network transport
//! of Bitcoin data and network messages. //! of Bitcoin data and Bitcoin p2p network messages.
//!
pub mod constants; pub mod constants;

View File

@ -823,7 +823,7 @@ mod tests {
use crate::blockdata::transaction::{OutPoint, Sequence, Transaction, TxIn, TxOut}; use crate::blockdata::transaction::{OutPoint, Sequence, Transaction, TxIn, TxOut};
use crate::blockdata::witness::Witness; use crate::blockdata::witness::Witness;
use crate::internal_macros::hex; use crate::internal_macros::hex;
use crate::network::constants::Network::Bitcoin; use crate::p2p::constants::Network::Bitcoin;
use crate::psbt::map::{Input, Output}; use crate::psbt::map::{Input, Output};
use crate::psbt::raw; use crate::psbt::raw;
use crate::psbt::serialize::{Deserialize, Serialize}; use crate::psbt::serialize::{Deserialize, Serialize};

View File

@ -1,7 +1,7 @@
use honggfuzz::fuzz; use honggfuzz::fuzz;
fn do_test(data: &[u8]) { fn do_test(data: &[u8]) {
let _: Result<bitcoin::network::message::RawNetworkMessage, _> = let _: Result<bitcoin::p2p::message::RawNetworkMessage, _> =
bitcoin::consensus::encode::deserialize(data); bitcoin::consensus::encode::deserialize(data);
} }

View File

@ -1,7 +1,7 @@
use bitcoin::address::Address; use bitcoin::address::Address;
use bitcoin::blockdata::script; use bitcoin::blockdata::script;
use bitcoin::consensus::encode; use bitcoin::consensus::encode;
use bitcoin::network::constants::Network; use bitcoin::p2p::constants::Network;
use honggfuzz::fuzz; use honggfuzz::fuzz;
fn do_test(data: &[u8]) { fn do_test(data: &[u8]) {