diff --git a/Cargo.lock b/Cargo.lock index 3a02944..396921c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "anyhow" -version = "1.0.58" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" +checksum = "b9a8f622bcf6ff3df478e9deba3e03e4e04b300f8e6a139e192c05fa3490afc7" [[package]] name = "archiver" @@ -56,15 +56,15 @@ checksum = "5f40afb3abbf90895dda3ddbc6d8734d24215130a22d646067690f5e318f81bc" [[package]] name = "bech32" -version = "0.8.1" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9ff0bbfd639f15c74af777d81383cf53efb7c93613f6cab67c6c11e05bbf8b" +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" [[package]] name = "bitcoin" -version = "0.28.1" +version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05bba324e6baf655b882df672453dbbc527bc938cadd27750ae510aaccc3a66a" +checksum = "9cb36de3b18ad25f396f9168302e36fb7e1e8923298ab3127da252d288d5af9d" dependencies = [ "bech32", "bitcoin_hashes", @@ -73,9 +73,9 @@ dependencies = [ [[package]] name = "bitcoin_hashes" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "006cc91e1a1d99819bc5b8214be3555c1f0611b169f527a1fdc54ed1f2b745b0" +checksum = "90064b8dee6815a6470d60bad07bbbaee885c0e12d04177138fa3291a01b7bc4" [[package]] name = "bitflags" @@ -91,9 +91,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "bytes" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b3de4a0c5e67e16066a0715723abd91edc2f9001d09c46e1dca929351e130e" +checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" [[package]] name = "cc" @@ -129,9 +129,9 @@ dependencies = [ [[package]] name = "either" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" [[package]] name = "extractor" @@ -215,9 +215,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" +checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" [[package]] name = "lazy_static" @@ -227,15 +227,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" [[package]] name = "lock_api" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +checksum = "9f80bf5aacaf25cbfc8210d1cfb718f2bf3b11c4c54e5afe36c236853a8ec390" dependencies = [ "autocfg", "scopeguard", @@ -313,6 +313,12 @@ dependencies = [ "libc", ] +[[package]] +name = "once_cell" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0" + [[package]] name = "parking_lot" version = "0.12.1" @@ -348,18 +354,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.40" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" +checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" dependencies = [ "unicode-ident", ] [[package]] name = "prometheus" -version = "0.13.1" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cface98dfa6d645ea4c789839f176e4b072265d085bfcc48eaa8d137f58d3c39" +checksum = "45c8babc29389186697fe5a2a4859d697825496b83db5d0b65271cdc0488e88c" dependencies = [ "cfg-if", "fnv", @@ -433,18 +439,18 @@ checksum = "cf7e6d18738ecd0902d30d1ad232c9125985a3422929b16c65517b38adc14f96" [[package]] name = "quote" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] [[package]] name = "redox_syscall" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534cfe58d6a18cc17120fbf4635d53d14691c1fe4d951064df9bd326178d7d5a" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ "bitflags", ] @@ -481,18 +487,19 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "secp256k1" -version = "0.22.1" +version = "0.24.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26947345339603ae8395f68e2f3d85a6b0a8ddfe6315818e80b8504415099db0" +checksum = "b7649a0b3ffb32636e60c7ce0d70511eda9c52c658cd0634e194d5a19943aeff" dependencies = [ + "bitcoin_hashes", "secp256k1-sys", ] [[package]] name = "secp256k1-sys" -version = "0.5.2" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "152e20a0fd0519390fc43ab404663af8a0b794273d2a91d60ad4a39f13ffe110" +checksum = "7058dc8eaf3f2810d7828680320acda0b25a288f6d288e19278e249bbf74226b" dependencies = [ "cc", ] @@ -528,9 +535,9 @@ checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" [[package]] name = "syn" -version = "1.0.98" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" +checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" dependencies = [ "proc-macro2", "quote", @@ -553,18 +560,18 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.31" +version = "1.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" +checksum = "8c1b05ca9d106ba7d2e31a9dab4a64e7be2cce415321966ea3132c49a656e252" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.31" +version = "1.0.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" +checksum = "e8f2591983642de85c921015f3f070c665a197ed69e417af436115e3a1407487" dependencies = [ "proc-macro2", "quote", @@ -573,9 +580,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.11" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72c91f41dcb2f096c05f0873d667dceec1087ce5bcf984ec8ffb19acddbb3217" +checksum = "3c3f9a28b618c3a6b9251b6908e9c99e04b9e5c02e6581ccbb67d59c34ef7f9b" dependencies = [ "itoa", "libc", @@ -591,9 +598,9 @@ checksum = "42657b1a6f4d817cda8e7a0ace261fe0cc946cf3a80314390b22cc61ae080792" [[package]] name = "unicode-ident" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" +checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" [[package]] name = "version_check" @@ -603,13 +610,13 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "which" -version = "4.2.5" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae" +checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" dependencies = [ "either", - "lazy_static", "libc", + "once_cell", ] [[package]] diff --git a/extractor/bcc-programs/net_connections.c b/extractor/bcc-programs/net_connections.c index 6fbba7b..9dca8ab 100644 --- a/extractor/bcc-programs/net_connections.c +++ b/extractor/bcc-programs/net_connections.c @@ -21,18 +21,12 @@ struct Connection struct ClosedConnection { struct Connection conn; - u64 last_block_time; - u64 last_tx_time; - u64 last_ping_time; - u64 min_ping_time; - bool relays_txs; + u64 time_established; }; struct InboundConnection { struct Connection conn; - u64 services; - bool inbound_onion; u64 existing_connections; }; @@ -59,11 +53,7 @@ int trace_evicted_connection(struct pt_regs *ctx) { bpf_usdt_readarg_p(3, ctx, &evicted.conn.type, MAX_PEER_CONN_TYPE_LENGTH); bpf_usdt_readarg(4, ctx, &evicted.conn.network); bpf_usdt_readarg(5, ctx, &evicted.conn.net_group); - bpf_usdt_readarg(6, ctx, &evicted.last_block_time); - bpf_usdt_readarg(7, ctx, &evicted.last_tx_time); - bpf_usdt_readarg(8, ctx, &evicted.last_ping_time); - bpf_usdt_readarg(9, ctx, &evicted.min_ping_time); - bpf_usdt_readarg(10, ctx, &evicted.relays_txs); + bpf_usdt_readarg(6, ctx, &evicted.time_established); evicted_connections.ringbuf_output(&evicted, sizeof(evicted), 0); return 0; @@ -77,11 +67,7 @@ int trace_closed_connection(struct pt_regs *ctx) { bpf_usdt_readarg_p(3, ctx, &closed.conn.type, MAX_PEER_CONN_TYPE_LENGTH); bpf_usdt_readarg(4, ctx, &closed.conn.network); bpf_usdt_readarg(5, ctx, &closed.conn.net_group); - bpf_usdt_readarg(6, ctx, &closed.last_block_time); - bpf_usdt_readarg(7, ctx, &closed.last_tx_time); - bpf_usdt_readarg(8, ctx, &closed.last_ping_time); - bpf_usdt_readarg(9, ctx, &closed.min_ping_time); - bpf_usdt_readarg(10, ctx, &closed.relays_txs); + bpf_usdt_readarg(6, ctx, &evicted.time_established); closed_connections.ringbuf_output(&closed, sizeof(closed), 0); return 0; @@ -95,9 +81,7 @@ int trace_inbound_connection(struct pt_regs *ctx) { bpf_usdt_readarg_p(3, ctx, &inbound.conn.type, MAX_PEER_CONN_TYPE_LENGTH); bpf_usdt_readarg(4, ctx, &inbound.conn.network); bpf_usdt_readarg(5, ctx, &inbound.conn.net_group); - bpf_usdt_readarg(6, ctx, &inbound.services); - bpf_usdt_readarg(7, ctx, &inbound.inbound_onion); - bpf_usdt_readarg(8, ctx, &inbound.existing_connections); + bpf_usdt_readarg(6, ctx, &inbound.existing_connections); inbound_connections.ringbuf_output(&inbound, sizeof(inbound), 0); return 0; diff --git a/extractor/src/main.rs b/extractor/src/main.rs index d7668b3..7d9bcfd 100644 --- a/extractor/src/main.rs +++ b/extractor/src/main.rs @@ -27,10 +27,10 @@ fn main() { .enable_probe("net:outbound_message", "trace_outbound_message") .unwrap(); usdt_ctx - .enable_probe("net:evict_connection", "trace_evicted_connection") + .enable_probe("net:evicted_connection", "trace_evicted_connection") .unwrap(); usdt_ctx - .enable_probe("net:closesocket_connection", "trace_closed_connection") + .enable_probe("net:closed_connection", "trace_closed_connection") .unwrap(); usdt_ctx .enable_probe("net:inbound_connection", "trace_inbound_connection") diff --git a/metrics/src/main.rs b/metrics/src/main.rs index 9916942..f82eded 100644 --- a/metrics/src/main.rs +++ b/metrics/src/main.rs @@ -72,9 +72,6 @@ fn main() { metrics::CONN_INBOUND_NETGROUP .with_label_values(&[&i.conn.net_group.to_string()]) .inc(); - metrics::CONN_INBOUND_SERVICE - .with_label_values(&[&i.services.to_string()]) - .inc(); metrics::CONN_INBOUND_CURRENT.set(i.existing_connections as i64 + 1); } Event::Outbound(o) => { diff --git a/metrics/src/metrics.rs b/metrics/src/metrics.rs index c1706ac..6d2969e 100644 --- a/metrics/src/metrics.rs +++ b/metrics/src/metrics.rs @@ -228,15 +228,6 @@ lazy_static! { &[LABEL_CONN_ADDR] ).unwrap(); - /// Number of inbound connections with their services. - pub static ref CONN_INBOUND_SERVICE: IntCounterVec = - register_int_counter_vec!( - Opts::new("inbound_service", "Number of inbound connections with their services.") - .namespace(NAMESPACE) - .subsystem(SUBSYSTEM_CONN), - &[LABEL_P2P_SERVICES] - ).unwrap(); - /// Number of inbound connections by network. pub static ref CONN_INBOUND_NETWORK: IntCounterVec = register_int_counter_vec!( diff --git a/protobuf/protos/connection.proto b/protobuf/protos/connection.proto index 65af32e..0346a66 100644 --- a/protobuf/protos/connection.proto +++ b/protobuf/protos/connection.proto @@ -18,7 +18,7 @@ message ConnectionEvent { message Connection { required uint64 peer_id = 1; // Peer id assigned by Bitcoin Core required string addr = 2; // Address of the peer - required primitive.ConnType conn_type = 3; + required primitive.ConnType conn_type = 3; // Connection type required uint32 network = 4; // The network this connection is on required uint64 net_group = 5; // The net_group assigend by Bitcoin Core } @@ -26,29 +26,19 @@ message Connection { // A connection where the underlying socket has been closed. message ClosedConnection { required Connection conn = 1; - required uint64 last_block_time = 2; - required uint64 last_tx_time = 3; - required uint64 last_ping_time = 4; - required uint64 min_ping_time = 5; - required bool relays_txs = 6; + required uint64 time_established = 2; // Connection established UNIX epoch timestamp } // A connection that Bitcoin Core choose to evict. message EvictedConnection { required Connection conn = 1; - required uint64 last_block_time = 2; - required uint64 last_tx_time = 3; - required uint64 last_ping_time = 4; - required uint64 min_ping_time = 5; - required bool relays_txs = 6; + required uint64 time_established = 2; // Connection established UNIX epoch timestamp } // An inbound connection. message InboundConnection { required Connection conn = 1; - required uint64 services = 2; - required bool inbound_onion = 3; - required uint64 existing_connections = 4; + required uint64 existing_connections = 2; } // An outbound connection. diff --git a/shared/Cargo.toml b/shared/Cargo.toml index a16f0fd..87c6518 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dependencies] prost = "0.10" # Use master until 0.29 is released -bitcoin = {git = "https://github.com/rust-bitcoin/rust-bitcoin", branch = "master"} +bitcoin = "0.29" base32 = "0.4.0" # for encoding Tor/Onion addresses diff --git a/shared/src/bcc_types.rs b/shared/src/bcc_types.rs index 37219c3..329b1ae 100644 --- a/shared/src/bcc_types.rs +++ b/shared/src/bcc_types.rs @@ -278,25 +278,19 @@ impl fmt::Display for Connection { #[repr(C)] pub struct ClosedConnection { + /// The connection being closed pub connection: Connection, - pub last_block_time: u64, - pub last_tx_time: u64, - pub last_ping_time: u64, - pub min_ping_time: u64, - pub relays_txs: bool, + /// Connection established UNIX epoch timestamp + pub time_established: u64, } impl fmt::Display for ClosedConnection { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, - "ClosedConnection(conn={}, last_block_time={}, last_tx_time={}, last_ping_time={}, min_ping_time={}, relays_txs={})", + "ClosedConnection(conn={}, time_established={})", self.connection, - self.last_block_time, - self.last_tx_time, - self.last_ping_time, - self.min_ping_time, - self.relays_txs, + self.time_established, ) } } @@ -309,9 +303,9 @@ impl ClosedConnection { #[repr(C)] pub struct InboundConnection { + /// The inbound connection being opened pub connection: Connection, - pub services: u64, - pub inbound_onion: bool, + /// Number of inbound connections existing (not including this newly opened one) pub existing_connections: u64, } @@ -325,15 +319,17 @@ impl fmt::Display for InboundConnection { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, - "InboundConnection(conn={}, services={}, inbound_onion={}, existing_connections={})", - self.connection, self.services, self.inbound_onion, self.existing_connections, + "InboundConnection(conn={}, existing_connections={})", + self.connection, self.existing_connections, ) } } #[repr(C)] pub struct OutboundConnection { + /// The outbound connection being opened pub connection: Connection, + /// Number of outbound connections existing (not including this newly opened one) pub existing_connections: u64, } diff --git a/shared/src/connection.rs b/shared/src/connection.rs index c6ad966..6de4106 100644 --- a/shared/src/connection.rs +++ b/shared/src/connection.rs @@ -32,8 +32,8 @@ impl fmt::Display for ClosedConnection { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, - "ClosedConnection(conn={}, last_block_time={}, last_tx_time={}, last_ping_time={}, min_ping_time={}, relays_tx={})", - self.conn, self.last_block_time, self.last_tx_time, self.last_ping_time, self.min_ping_time, self.relays_txs + "ClosedConnection(conn={}, time_established={})", + self.conn, self.time_established ) } } @@ -42,11 +42,7 @@ impl From for ClosedConnection { fn from(cconn: bcc_types::ClosedConnection) -> Self { ClosedConnection { conn: cconn.connection.into(), - last_block_time: cconn.last_block_time, - last_tx_time: cconn.last_tx_time, - last_ping_time: cconn.last_ping_time, - min_ping_time: cconn.min_ping_time, - relays_txs: cconn.relays_txs, + time_established: cconn.time_established, } } } @@ -55,8 +51,8 @@ impl fmt::Display for EvictedConnection { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, - "EvictedConnection(conn={}, last_block_time={}, last_tx_time={}, last_ping_time={}, min_ping_time={}, relays_tx={})", - self.conn, self.last_block_time, self.last_tx_time, self.last_ping_time, self.min_ping_time, self.relays_txs + "EvictedConnection(conn={}, time_established={})", + self.conn, self.time_established ) } } @@ -65,11 +61,7 @@ impl From for EvictedConnection { fn from(econn: bcc_types::ClosedConnection) -> Self { EvictedConnection { conn: econn.connection.into(), - last_block_time: econn.last_block_time, - last_tx_time: econn.last_tx_time, - last_ping_time: econn.last_ping_time, - min_ping_time: econn.min_ping_time, - relays_txs: econn.relays_txs, + time_established: econn.time_established, } } } @@ -78,8 +70,8 @@ impl fmt::Display for InboundConnection { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, - "InboundConnection(conn={}, services={}, inbound_onion={}, existing_connections={})", - self.conn, self.services, self.inbound_onion, self.existing_connections, + "InboundConnection(conn={}, existing_connections={})", + self.conn, self.existing_connections ) } } @@ -88,8 +80,6 @@ impl From for InboundConnection { fn from(iconn: bcc_types::InboundConnection) -> Self { InboundConnection { conn: iconn.connection.into(), - services: iconn.services, - inbound_onion: iconn.inbound_onion, existing_connections: iconn.existing_connections, } }