Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

Commit

Permalink
fix features endian and update check items
Browse files Browse the repository at this point in the history
  • Loading branch information
nayuta-ueno committed Nov 27, 2019
1 parent e84d062 commit d894358
Show file tree
Hide file tree
Showing 13 changed files with 814 additions and 113 deletions.
4 changes: 0 additions & 4 deletions ln/ln.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,7 @@ bool ln_init(
pChannel->commit_info_remote.p_funding_info =
&pChannel->funding_info;

#ifdef USE_GOSSIP_QUERY
SLIST_INIT(&pChannel->gossip_query.request.send_encoded_ids);
#endif

LOGD("END\n");

Expand Down Expand Up @@ -1472,15 +1470,13 @@ static void channel_clear(ln_channel_t *pChannel)
pChannel->anno_flag = 0;
pChannel->shutdown_flag = 0;

#ifdef USE_GOSSIP_QUERY
ln_anno_encoded_ids_t *p = SLIST_FIRST(&pChannel->gossip_query.request.send_encoded_ids);
while (p) {
ln_anno_encoded_ids_t *p_bak = p;
p = SLIST_NEXT(p, list);
utl_buf_free(&p_bak->encoded_short_ids);
UTL_DBG_FREE(p_bak);
}
#endif

ln_establish_free(pChannel);
}
Expand Down
18 changes: 12 additions & 6 deletions ln/ln.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,23 @@ extern "C" {
#define LN_RCLOSE_IDX_TO_REMOTE (1) ///< to_remote
#define LN_RCLOSE_IDX_HTLC (2) ///< HTLC

//requires / supports feature
#define LN_INIT_LF_OPT_DATALOSS_REQ (1 << 0) ///< option_data_loss_protect
#define LN_INIT_LF_OPT_DATALOSS (1 << 1) ///< option_data_loss_protect
#define LN_INIT_LF_ROUTE_SYNC_REQ (1 << 2) ///< [NO]initial_routing_sync
#define LN_INIT_LF_ROUTE_SYNC (1 << 3) ///< initial_routing_sync
#define LN_INIT_LF_OPT_UPF_SHDN_REQ (1 << 4) ///< option_upfront_shutdown_script
#define LN_INIT_LF_OPT_UPF_SHDN (1 << 5) ///< option_upfront_shutdown_script
#define LN_INIT_LF_OPT_GSP_QUERY_REQ (1 << 6) ///< gossip_queries
#define LN_INIT_LF_OPT_GSP_QUERY (1 << 7) ///< gossip_queries
#define LN_INIT_LF_OPT_VAR_ONION_REQ (1 << 8) ///< var_onion_optin
#define LN_INIT_LF_OPT_VAR_ONION (1 << 9) ///< var_onion_optin
#define LN_INIT_LF_OPT_GQUERY_EX_REQ (1 << 10) ///< gossip_queries_ex
#define LN_INIT_LF_OPT_GQUERY_EX (1 << 11) ///< gossip_queries_ex
#define LN_INIT_LF_OPT_STATIC_RKEY_REQ (1 << 12) ///< option_static_remotekey
#define LN_INIT_LF_OPT_STATIC_RKEY (1 << 13) ///< option_static_remotekey
#define LN_INIT_LF_OPT_15_14_REQ (1 << 14) ///< RFU bit 15/14

#define LN_INIT_LF_OPT_GSP_QUERIES (LN_INIT_LF_OPT_GSP_QUERY_REQ | LN_INIT_LF_OPT_GSP_QUERY)

//XXX:
Expand Down Expand Up @@ -290,7 +300,6 @@ typedef struct {
} ln_anno_param_t;


#ifdef USE_GOSSIP_QUERY
/** @struct ln_anno_encoded_ids_t
* @brief encided_short_ids list
*/
Expand Down Expand Up @@ -355,7 +364,6 @@ typedef struct {
// uint64_t *p_reply_short_ids; ///< decoded short_channel_ids

} ln_gossip_query_t;
#endif

/// @}

Expand Down Expand Up @@ -395,8 +403,8 @@ struct ln_channel_t {

//msg:establish
uint8_t init_flag; ///< [INIT_01]initフラグ(M_INIT_FLAG_xxx)
uint8_t lfeature_local; ///< [INIT_02]initで送信したlocalfeature
uint8_t lfeature_remote; ///< [INIT_03]initで取得したlocalfeature
uint16_t lfeature_local; ///< [INIT_02]initで送信したfeature
uint16_t lfeature_remote; ///< [INIT_03]initで取得したfeature
uint64_t reest_next_local_commit_num; ///< [INIT_04]channel_reestablish.next_local_commitment_number
uint64_t reest_next_remote_revoke_num; ///< [INIT_05]channel_reestablish.next_remote_revocation_number

Expand Down Expand Up @@ -427,10 +435,8 @@ struct ln_channel_t {
uint8_t prev_remote_commit_txid[BTC_SZ_TXID];
///< [COMM_03]previous remote commit tx's txid (for second last remote unilateral close)

#ifdef USE_GOSSIP_QUERY
//gossip_queries
ln_gossip_query_t gossip_query; ///< [GQRY_01]gossip_queries
#endif

//last error
int err; ///< [ERRO_01]error code(ln_err.h)
Expand Down
52 changes: 2 additions & 50 deletions ln/ln_anno.c
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ bool ln_channel_update_disable(ln_channel_t *pChannel)

bool ln_query_short_channel_ids_send(ln_channel_t *pChannel, const uint8_t *pEncodedIds, uint16_t Len)
{
#ifdef USE_GOSSIP_QUERY
if ((pChannel->init_flag & M_INIT_GOSSIP_QUERY) == 0) {
LOGE("fail: not gossip_queries\n");
return false;
Expand All @@ -419,16 +418,11 @@ bool ln_query_short_channel_ids_send(ln_channel_t *pChannel, const uint8_t *pEnc
ln_callback(pChannel, LN_CB_TYPE_SEND_MESSAGE, &buf);
utl_buf_free(&buf);
return true;
#else
(void)pChannel; (void)pEncodedIds; (void)Len;
return false;
#endif
}


bool HIDDEN ln_query_short_channel_ids_recv(ln_channel_t *pChannel, const uint8_t *pData, uint16_t Len)
{
#ifdef USE_GOSSIP_QUERY
if ((pChannel->init_flag & M_INIT_GOSSIP_QUERY) == 0) {
LOGD("through: not gossip_queries\n");
return true;
Expand All @@ -442,24 +436,21 @@ bool HIDDEN ln_query_short_channel_ids_recv(ln_channel_t *pChannel, const uint8_
uint64_t *p_short_channel_ids;
size_t ids;
if (!ln_msg_gossip_ids_decode(&p_short_channel_ids, &ids, msg.p_encoded_short_ids, msg.len)) {
LOGE("fail: ids decode\n");
return false;
}
if (!ln_db_annoinfos_del_node_id(ln_remote_node_id(pChannel), p_short_channel_ids, ids)) {
LOGE("fail: annoinfo del\n");
return false;
}
UTL_DBG_FREE(p_short_channel_ids);

return true;
#else
(void)pChannel; (void)pData; (void)Len;
return false;
#endif
}


bool ln_reply_short_channel_ids_end_send(ln_channel_t *pChannel, const ln_msg_query_short_channel_ids_t *pMsg)
{
#ifdef USE_GOSSIP_QUERY
(void)pMsg;

if ((pChannel->init_flag & M_INIT_GOSSIP_QUERY) == 0) {
Expand All @@ -476,16 +467,11 @@ bool ln_reply_short_channel_ids_end_send(ln_channel_t *pChannel, const ln_msg_qu
ln_callback(pChannel, LN_CB_TYPE_SEND_MESSAGE, &buf);
utl_buf_free(&buf);
return true;
#else
(void)pChannel; (void)pMsg;
return false;
#endif
}


bool HIDDEN ln_reply_short_channel_ids_end_recv(ln_channel_t *pChannel, const uint8_t *pData, uint16_t Len)
{
#ifdef USE_GOSSIP_QUERY
if ((pChannel->init_flag & M_INIT_GOSSIP_QUERY) == 0) {
LOGE("fail: not gossip_queries\n");
return false;
Expand All @@ -500,16 +486,11 @@ bool HIDDEN ln_reply_short_channel_ids_end_recv(ln_channel_t *pChannel, const ui
}
pChannel->gossip_query.request.wait_query_short_channel_ids_end = false;
return true;
#else
(void)pChannel; (void)pData; (void)Len;
return false;
#endif
}


bool ln_query_channel_range_send(ln_channel_t *pChannel, uint32_t FirstBlock, uint32_t Num)
{
#ifdef USE_GOSSIP_QUERY
if ((pChannel->init_flag & M_INIT_GOSSIP_QUERY) == 0) {
LOGE("fail: not gossip_queries\n");
return false;
Expand All @@ -536,16 +517,11 @@ bool ln_query_channel_range_send(ln_channel_t *pChannel, uint32_t FirstBlock, ui
pChannel->gossip_query.request.first_blocknum = FirstBlock;
pChannel->gossip_query.request.rest_blocks = Num;
return true;
#else
(void)pChannel; (void)FirstBlock; (void)Num;
return false;
#endif
}


bool HIDDEN ln_query_channel_range_recv(ln_channel_t *pChannel, const uint8_t *pData, uint16_t Len)
{
#ifdef USE_GOSSIP_QUERY
if ((pChannel->init_flag & M_INIT_GOSSIP_QUERY) == 0) {
LOGD("through: not gossip_queries\n");
return true;
Expand All @@ -559,16 +535,11 @@ bool HIDDEN ln_query_channel_range_recv(ln_channel_t *pChannel, const uint8_t *p
return false;
}
return true;
#else
(void)pChannel; (void)pData; (void)Len;
return false;
#endif
}


bool ln_reply_channel_range_send(ln_channel_t *pChannel, const ln_msg_query_channel_range_t *pMsg)
{
#ifdef USE_GOSSIP_QUERY
bool ret;

if ((pChannel->init_flag & M_INIT_GOSSIP_QUERY) == 0) {
Expand Down Expand Up @@ -630,16 +601,11 @@ bool ln_reply_channel_range_send(ln_channel_t *pChannel, const ln_msg_query_chan
utl_buf_free(&buf);
utl_buf_free(&encoded_ids);
return true;
#else
(void)pChannel; (void)pMsg;
return false;
#endif
}


bool HIDDEN ln_reply_channel_range_recv(ln_channel_t *pChannel, const uint8_t *pData, uint16_t Len)
{
#ifdef USE_GOSSIP_QUERY
if ((pChannel->init_flag & M_INIT_GOSSIP_QUERY) == 0) {
LOGE("fail: not gossip_queries\n");
return false;
Expand Down Expand Up @@ -737,16 +703,11 @@ bool HIDDEN ln_reply_channel_range_recv(ln_channel_t *pChannel, const uint8_t *p
}
}
return true;
#else
(void)pChannel; (void)pData; (void)Len;
return false;
#endif
}


bool ln_gossip_timestamp_filter_send(ln_channel_t *pChannel)
{
#ifdef USE_GOSSIP_QUERY
if ((pChannel->init_flag & M_INIT_GOSSIP_QUERY) == 0) {
LOGE("fail: not gossip_queries\n");
return false;
Expand All @@ -761,16 +722,11 @@ bool ln_gossip_timestamp_filter_send(ln_channel_t *pChannel)
ln_callback(pChannel, LN_CB_TYPE_SEND_MESSAGE, &buf);
utl_buf_free(&buf);
return true;
#else
(void)pChannel;
return false;
#endif
}


bool HIDDEN ln_gossip_timestamp_filter_recv(ln_channel_t *pChannel, const uint8_t *pData, uint16_t Len)
{
#ifdef USE_GOSSIP_QUERY
if ((pChannel->init_flag & M_INIT_GOSSIP_QUERY) == 0) {
LOGD("through: not gossip_queries\n");
return true;
Expand All @@ -788,10 +744,6 @@ bool HIDDEN ln_gossip_timestamp_filter_recv(ln_channel_t *pChannel, const uint8_
return true;
}
return true;
#else
(void)pChannel; (void)pData; (void)Len;
return false;
#endif
}


Expand Down
21 changes: 16 additions & 5 deletions ln/ln_msg_setupctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,23 @@ static void init_print(const ln_msg_init_t *pMsg)
LOGD("-[init]-------------------------------\n");
LOGD("globalfeatures: ");
DUMPD(pMsg->p_globalfeatures, pMsg->gflen);
LOGD("localfeatures: ");
LOGD("features: ");
DUMPD(pMsg->p_localfeatures, pMsg->lflen);
LOGD(" option_data_loss_protect: %d\n", (pMsg->p_localfeatures[0] & 0x03));
LOGD(" initial_routing_sync: %d\n", (pMsg->p_localfeatures[0] & 0x0c) >> 2);
LOGD(" option_upfront_shutdown_script: %d\n", (pMsg->p_localfeatures[0] & 0x30) >> 4);
LOGD(" gossip_queries: %d\n", (pMsg->p_localfeatures[0] & 0xc0) >> 6);
//b7-0
if (pMsg->lflen > 0) {
const uint8_t feature = pMsg->p_localfeatures[pMsg->lflen - 1];
LOGD(" option_data_loss_protect: %d\n", (feature & 0x03));
LOGD(" initial_routing_sync: %d\n", (feature & 0x0c) >> 2);
LOGD(" option_upfront_shutdown_script: %d\n", (feature & 0x30) >> 4);
LOGD(" gossip_queries: %d\n", (feature & 0xc0) >> 6);
}
//b15-8
if (pMsg->lflen > 1) {
const uint8_t feature = pMsg->p_localfeatures[pMsg->lflen - 2];
LOGD(" var_onion_optin: %d\n", (feature & 0x03));
LOGD(" gossip_queries_ex: %d\n", (feature & 0x0c) >> 2);
LOGD(" option_static_remotekey: %d\n", (feature & 0x30) >> 4);
}
LOGD("--------------------------------\n");
#else
(void)pMsg;
Expand Down
Loading

0 comments on commit d894358

Please sign in to comment.