1#ifndef __PEER_CONNECTION_H
2#define __PEER_CONNECTION_H
11#define BITCOIN_MAINNET_MAGIC 0xD9B4BEF9
14#define BITCOIN_MAINNET_PORT 8333
16#define htole16(x) ((uint16_t)((((x) & 0xFF) << 8) | (((x) >> 8) & 0xFF)))
17#define htole32(x) ((uint32_t)((((x) & 0xFF) << 24) | (((x) >> 8) & 0xFF00) | (((x) >> 16) & 0xFF) | (((x) >> 24) & 0xFF000000)))
18#define htole64(x) ((uint64_t)((((x) & 0xFF) << 56) | (((x) >> 8) & 0xFF00) | (((x) >> 16) & 0xFF0000) | (((x) >> 24) & 0xFF000000) | (((x) >> 32) & 0xFF00000000) | (((x) >> 40) & 0xFF0000000000) | (((x) >> 48) & 0xFF000000000000) | (((x) >> 56) & 0xFF00000000000000)))
20#define MAX_LOCATOR_COUNT 10
21#define GENESIS_BLOCK_HASH "0000000000000000000000000000000000000000000000000000000000000000"
22#define HEADERS_FILE "headers.dat"
23#define MAX_HEADERS_COUNT 2000
33 unsigned char checksum[4];
78int get_idx(
const char* ip_address);
134void send_headers(
int idx,
const unsigned char* start_hash,
const unsigned char* stop_hash);
185void send_tx(
int idx,
const unsigned char* tx_data,
size_t tx_size);
void list_connected_nodes()
Lists all connected nodes and their details.
void send_inv_and_wait(int idx, const unsigned char *inv_data, size_t inv_count)
Sends an 'inv' message to the peer and waits for a response.
void send_getheaders_and_wait(int idx)
Sends a 'getheaders' message to the peer and waits for a response.
void send_getblocks_and_wait(int idx)
Sends a 'getblocks' message to the peer and waits for a response.
unsigned char * load_blocks_from_file(const char *filename, size_t *payload_len)
int get_idx(const char *ip_address)
Get the index of the node with the given IP address.
void send_headers(int idx, const unsigned char *start_hash, const unsigned char *stop_hash)
Sends a 'headers' message to the peer.
void send_tx(int idx, const unsigned char *tx_data, size_t tx_size)
Sends a 'tx' message to the specified node.
void send_getaddr_and_wait(int idx)
Sends a 'getaddr' message to the peer and waits for a response.
int connect_to_peer(const char *ip_addr)
Connects to a peer using the specified IP address.
void disconnect(int node_id)
Disconnects from the node specified by the node ID.
void send_getdata_and_wait(int idx, const unsigned char *hashes, size_t hash_count)
Sends a 'getdata' message to the peer and waits for a response.
The structure to store information about a connected peer.
int operation_in_progress