lnsocket.h (3976B)
1 #ifndef LNSOCKET_H 2 #define LNSOCKET_H 3 4 #include <stdint.h> 5 #include <stdlib.h> 6 7 struct lnsocket; 8 9 #ifdef __EMSCRIPTEN__ 10 #include <emscripten.h> 11 #define EXPORT EMSCRIPTEN_KEEPALIVE 12 #else 13 #define EXPORT 14 #endif 15 16 enum peer_wire { 17 WIRE_INIT = 16, 18 WIRE_ERROR = 17, 19 WIRE_WARNING = 1, 20 WIRE_PING = 18, 21 WIRE_PONG = 19, 22 WIRE_TX_ADD_INPUT = 66, 23 WIRE_TX_ADD_OUTPUT = 67, 24 WIRE_TX_REMOVE_INPUT = 68, 25 WIRE_TX_REMOVE_OUTPUT = 69, 26 WIRE_TX_COMPLETE = 70, 27 WIRE_TX_SIGNATURES = 71, 28 WIRE_OPEN_CHANNEL = 32, 29 WIRE_ACCEPT_CHANNEL = 33, 30 WIRE_FUNDING_CREATED = 34, 31 WIRE_FUNDING_SIGNED = 35, 32 WIRE_FUNDING_LOCKED = 36, 33 WIRE_OPEN_CHANNEL2 = 64, 34 WIRE_ACCEPT_CHANNEL2 = 65, 35 WIRE_INIT_RBF = 72, 36 WIRE_ACK_RBF = 73, 37 WIRE_SHUTDOWN = 38, 38 WIRE_CLOSING_SIGNED = 39, 39 WIRE_UPDATE_ADD_HTLC = 128, 40 WIRE_UPDATE_FULFILL_HTLC = 130, 41 WIRE_UPDATE_FAIL_HTLC = 131, 42 WIRE_UPDATE_FAIL_MALFORMED_HTLC = 135, 43 WIRE_COMMITMENT_SIGNED = 132, 44 WIRE_REVOKE_AND_ACK = 133, 45 WIRE_UPDATE_FEE = 134, 46 WIRE_UPDATE_BLOCKHEIGHT = 137, 47 WIRE_CHANNEL_REESTABLISH = 136, 48 WIRE_ANNOUNCEMENT_SIGNATURES = 259, 49 WIRE_CHANNEL_ANNOUNCEMENT = 256, 50 WIRE_NODE_ANNOUNCEMENT = 257, 51 WIRE_CHANNEL_UPDATE = 258, 52 WIRE_QUERY_SHORT_CHANNEL_IDS = 261, 53 WIRE_REPLY_SHORT_CHANNEL_IDS_END = 262, 54 WIRE_QUERY_CHANNEL_RANGE = 263, 55 WIRE_REPLY_CHANNEL_RANGE = 264, 56 WIRE_GOSSIP_TIMESTAMP_FILTER = 265, 57 WIRE_OBS2_ONION_MESSAGE = 387, 58 WIRE_ONION_MESSAGE = 513, 59 }; 60 61 /* A single TLV field, consisting of the data and its associated metadata. */ 62 struct tlv { 63 uint64_t type; 64 size_t length; 65 unsigned char *value; 66 }; 67 68 struct lnsocket EXPORT *lnsocket_create(); 69 70 /* messages */ 71 72 int lnsocket_make_network_tlv(unsigned char *buf, int buflen, const unsigned char **blockids, int num_blockids, struct tlv *tlv_out); 73 int lnsocket_make_init_msg(unsigned char *buf, int buflen, const unsigned char *globalfeatures, unsigned short gflen, const unsigned char *features, unsigned short flen, const struct tlv **tlvs, unsigned short num_tlvs, unsigned short *outlen); 74 75 int lnsocket_perform_init(struct lnsocket *ln); 76 77 int lnsocket_connect(struct lnsocket *, const char *node_id, const char *host); 78 int lnsocket_connect_tor(struct lnsocket *, const char *node_id, const char *host, const char *tor_proxy); 79 80 int lnsocket_fd(struct lnsocket *, int *fd); 81 int lnsocket_write(struct lnsocket *, const unsigned char *msg, unsigned short msg_len); 82 int lnsocket_read(struct lnsocket *, unsigned char **buf, unsigned short *len); 83 84 int lnsocket_send(struct lnsocket *, unsigned short msg_type, const unsigned char *payload, unsigned short payload_len); 85 int lnsocket_recv(struct lnsocket *, unsigned short *msg_type, unsigned char **payload, unsigned short *payload_len); 86 int lnsocket_pong(struct lnsocket *, const unsigned char *ping, unsigned short ping_len); 87 88 89 int EXPORT lnsocket_make_pong_from_ping(unsigned char *buf, int buflen, const unsigned char *ping, unsigned short ping_len); 90 int EXPORT lnsocket_make_ping_msg(unsigned char *buf, int buflen, unsigned short num_pong_bytes, unsigned short ignored_bytes); 91 int EXPORT lnsocket_make_pong_msg(unsigned char *buf, int buflen, unsigned short num_pong_bytes); 92 void* EXPORT lnsocket_secp(struct lnsocket *); 93 void EXPORT lnsocket_genkey(struct lnsocket *); 94 int EXPORT lnsocket_setkey(struct lnsocket *, const unsigned char key[32]); 95 void EXPORT lnsocket_destroy(struct lnsocket *); 96 void EXPORT lnsocket_print_errors(struct lnsocket *); 97 int EXPORT lnsocket_make_default_initmsg(unsigned char *msgbuf, int buflen); 98 int EXPORT lnsocket_encrypt(struct lnsocket *ln, const unsigned char *msg, unsigned short msglen); 99 int EXPORT lnsocket_decrypt_header(struct lnsocket *ln, unsigned char *hdr); 100 101 #endif /* LNSOCKET_H */