Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
501closed_connections = []503def handle_closed_connection(_, data, __):504event = ctypes.cast(data, ctypes.POINTER(ClosedConnection)).contents505self.log.info(f"handle_closed_connection(): {event}")506closed_connections.append(event)508bpf["closed_connections"].open_perf_buffer(handle_closed_connection)510self.log.info(511f"connect {EXPECTED_CLOSED_CONNECTIONS} P2P test nodes to our bitcoind node")512testnodes = list()513for p2p_idx in range(EXPECTED_CLOSED_CONNECTIONS):514testnode = P2PInterface()515self.nodes[0].add_p2p_connection(testnode)516testnodes.append(testnode)517for node in testnodes:518node.peer_disconnect()519self.wait_until(lambda: len(self.nodes[0].getpeerinfo()) == 0)520bpf.perf_buffer_poll(timeout=400)522assert_equal(EXPECTED_CLOSED_CONNECTIONS, len(closed_connections))523for closed_connection in closed_connections:524assert_greater_than(closed_connection.conn.id, 0)525assert_equal("inbound", closed_connection.conn.conn_type.decode('utf-8'))526assert_equal(0, closed_connection.conn.network)527assert_greater_than(closed_connection.time_established, 0)529bpf.cleanup()531if __name__ == '__main__':532NetTracepointTest(__file__).main()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.