#networking #bitcoin #address #bitcoin-system #addresses #serialization #structures

nightly bitcoin-network

an abstraction representing a Network -- an address may belong to more than one Network

7 releases

0.1.16-alpha.0 Mar 31, 2023
0.1.14-alpha.0 Mar 18, 2023
0.1.12-alpha.0 Jan 18, 2023

#12 in #bitcoin-system

Download history 138/week @ 2023-11-20 112/week @ 2023-11-27 86/week @ 2023-12-04 120/week @ 2023-12-11 200/week @ 2023-12-18 112/week @ 2023-12-25 65/week @ 2024-01-01 130/week @ 2024-01-08 158/week @ 2024-01-15 56/week @ 2024-01-22 49/week @ 2024-01-29 81/week @ 2024-02-05 128/week @ 2024-02-12 125/week @ 2024-02-19 158/week @ 2024-02-26 107/week @ 2024-03-04

518 downloads per month
Used in 63 crates (21 directly)

MIT license

575KB
1.5K SLoC

bitcoin-network


The bitcoin-network crate is a direct translation of the Bitcoin codebase from C++ to Rust, and is one of the subcomponents of the Bitcoin system. This crate provides a set of data structures and functions related to network communication and message propagation within the Bitcoin network.

The crate includes structures such as NetAddr, which represents a network address used to communicate with other Bitcoin nodes, and Network, which represents the Bitcoin network protocol. The ZeroSpan type is used for zero-length spans, and Reachability represents the reachability of a Bitcoin node.

The functions provided by the crate include methods to check the validity and properties of network addresses, serialize and unserialize network data, and get various network-related information. The crate also includes functions to calculate network-related mathematical properties, such as the netmask bits of an IP address.

Overall, the bitcoin-network crate is a critical component of the Bitcoin system, providing the necessary functionality to communicate and propagate messages across the Bitcoin network.

38> thanks -- could you tell me about NetAddr?

NetAddr is a Rust structure used in the Bitcoin network to represent network addresses. It includes an IP address and a port number, as well as other information such as the network version and the reachability of the address.

In Bitcoin, network addresses are used to maintain a peer-to-peer network of nodes that communicate with each other to transmit transactions and blocks across the network. Each node in the network maintains a list of known network addresses to other nodes, which it can use to establish new connections and maintain existing ones.

NetAddr provides a convenient way to represent these network addresses in Rust code, allowing for easy serialization and deserialization of network messages that contain network addresses.

The structure includes a number of methods to manipulate and query the properties of network addresses, such as is_reachable(), which checks if the address is currently reachable on the network, and to_string(), which returns a string representation of the address.

Overall, NetAddr is a useful tool for managing and manipulating network addresses in the context of the Bitcoin network.

Dependencies

~87MB
~785K SLoC