Skip to content

Commit

Permalink
update: to connection tracepoint PR
Browse files Browse the repository at this point in the history
  • Loading branch information
0xB10C committed Sep 12, 2022
1 parent 97d8c7e commit b167ccf
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 125 deletions.
93 changes: 50 additions & 43 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 4 additions & 20 deletions extractor/bcc-programs/net_connections.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions extractor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 0 additions & 3 deletions metrics/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
9 changes: 0 additions & 9 deletions metrics/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
18 changes: 4 additions & 14 deletions protobuf/protos/connection.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,27 @@ 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
}

// 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.
Expand Down

0 comments on commit b167ccf

Please sign in to comment.