mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-01-18 21:35:11 +01:00
lightnind: removeDEFAULT_PORT
global definition
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
This commit is contained in:
parent
c07d44b4d4
commit
7ff62b4a00
@ -1,4 +1,5 @@
|
||||
#include "config.h"
|
||||
#include <assert.h>
|
||||
#include <bitcoin/chainparams.h>
|
||||
#include <ccan/array_size/array_size.h>
|
||||
#include <ccan/tal/str/str.h>
|
||||
@ -269,3 +270,9 @@ const char *chainparams_get_network_names(const tal_t *ctx)
|
||||
tal_append_fmt(&networks_string, ", %s", networks[i].network_name);
|
||||
return networks_string;
|
||||
}
|
||||
|
||||
int chainparams_get_ln_port(const struct chainparams *params)
|
||||
{
|
||||
assert(params);
|
||||
return params->ln_port;
|
||||
}
|
||||
|
@ -74,4 +74,9 @@ const struct chainparams *chainparams_by_chainhash(const struct bitcoin_blkid *c
|
||||
*/
|
||||
const char *chainparams_get_network_names(const tal_t *ctx);
|
||||
|
||||
/**
|
||||
* chainparams_get_ln_port - Return the lightning network default port by
|
||||
* network if the chainparams is initialized, otherwise 9735 as mock port
|
||||
*/
|
||||
int chainparams_get_ln_port(const struct chainparams *params);
|
||||
#endif /* LIGHTNING_BITCOIN_CHAINPARAMS_H */
|
||||
|
@ -1,9 +1,22 @@
|
||||
#include "config.h"
|
||||
#include "../wireaddr.c"
|
||||
#include <bitcoin/chainparams.h>
|
||||
#include <common/amount.h>
|
||||
#include <common/setup.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int simple_get_ln_port(const struct chainparams *params);
|
||||
|
||||
#define chainparams_get_ln_port simple_get_ln_port
|
||||
|
||||
#include "../wireaddr.c"
|
||||
|
||||
#define DEFAULT_PORT simple_get_ln_port(NULL)
|
||||
|
||||
int simple_get_ln_port(const struct chainparams *params UNNEEDED)
|
||||
{
|
||||
return 9735;
|
||||
}
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for amount_asset_is_main */
|
||||
bool amount_asset_is_main(struct amount_asset *asset UNNEEDED)
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "config.h"
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <bitcoin/chainparams.h>
|
||||
#include <ccan/mem/mem.h>
|
||||
#include <ccan/tal/str/str.h>
|
||||
#include <common/base32.h>
|
||||
@ -612,7 +613,7 @@ bool parse_wireaddr_internal(const char *arg, struct wireaddr_internal *addr,
|
||||
* an onion address. */
|
||||
if (strstarts(arg, "autotor:")) {
|
||||
addr->itype = ADDR_INTERNAL_AUTOTOR;
|
||||
addr->u.torservice.port = DEFAULT_PORT;
|
||||
addr->u.torservice.port = chainparams_get_ln_port(chainparams);
|
||||
/* Format is separated by slash. */
|
||||
char **parts = tal_strsplit(tmpctx, arg, "/", STR_EMPTY_OK);
|
||||
|
||||
@ -644,7 +645,7 @@ bool parse_wireaddr_internal(const char *arg, struct wireaddr_internal *addr,
|
||||
if (strstarts(arg, "statictor:")) {
|
||||
bool use_magic_blob = true;
|
||||
addr->itype = ADDR_INTERNAL_STATICTOR;
|
||||
addr->u.torservice.port = DEFAULT_PORT;
|
||||
addr->u.torservice.port = chainparams_get_ln_port(chainparams);
|
||||
memset(addr->u.torservice.blob, 0, sizeof(addr->u.torservice.blob));
|
||||
|
||||
/* Format is separated by slash. */
|
||||
|
@ -12,14 +12,6 @@ struct sockaddr_in6;
|
||||
struct sockaddr_in;
|
||||
struct sockaddr_un;
|
||||
|
||||
/* BOLT #1:
|
||||
*
|
||||
* The default TCP port is 9735. This corresponds to hexadecimal
|
||||
* `0x2607`: the Unicode code point for LIGHTNING.
|
||||
*/
|
||||
#define DEFAULT_PORT 9735
|
||||
|
||||
|
||||
/* BOLT #7:
|
||||
*
|
||||
* The following `address descriptor` types are defined:
|
||||
|
@ -8,6 +8,7 @@
|
||||
* it.
|
||||
*/
|
||||
#include "config.h"
|
||||
#include <bitcoin/chainparams.h>
|
||||
#include <ccan/array_size/array_size.h>
|
||||
#include <ccan/asort/asort.h>
|
||||
#include <ccan/closefrom/closefrom.h>
|
||||
@ -1707,7 +1708,7 @@ static void add_seed_addrs(struct wireaddr_internal **addrs,
|
||||
|
||||
for (size_t i = 0; i < tal_count(hostnames); i++) {
|
||||
status_peer_debug(id, "Resolving %s", hostnames[i]);
|
||||
new_addrs = wireaddr_from_hostname(tmpctx, hostnames[i], DEFAULT_PORT,
|
||||
new_addrs = wireaddr_from_hostname(tmpctx, hostnames[i], chainparams_get_ln_port(chainparams),
|
||||
NULL, broken_reply, NULL);
|
||||
if (new_addrs) {
|
||||
for (size_t j = 0; j < tal_count(new_addrs); j++) {
|
||||
@ -1859,7 +1860,7 @@ static void try_connect_peer(struct daemon *daemon,
|
||||
for (size_t i = 0; i < tal_count(hostnames); i++) {
|
||||
wireaddr_from_unresolved(&unresolved,
|
||||
hostnames[i],
|
||||
DEFAULT_PORT);
|
||||
chainparams_get_ln_port(chainparams));
|
||||
tal_arr_expand(&addrs, unresolved);
|
||||
}
|
||||
} else if (daemon->use_dns) {
|
||||
|
@ -10,6 +10,8 @@
|
||||
#include <stdio.h>
|
||||
#include <wire/wire.h>
|
||||
|
||||
#define DEFAULT_PORT 9735
|
||||
|
||||
/* AUTOGENERATED MOCKS START */
|
||||
/* Generated stub for amount_asset_is_main */
|
||||
bool amount_asset_is_main(struct amount_asset *asset UNNEEDED)
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <stdio.h>
|
||||
#include <wire/peer_wire.h>
|
||||
|
||||
#define chainparams_get_ln_port simple_get_ln_port
|
||||
#define io_write_ simple_write
|
||||
#define io_read_ simple_read
|
||||
#define io_close simple_close
|
||||
@ -45,7 +46,12 @@ static struct io_plan *simple_close(struct io_conn *conn)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#include "../connectd/handshake.c"
|
||||
static int simple_get_ln_port(const struct chainparams *params UNNEEDED)
|
||||
{
|
||||
return 9735;
|
||||
}
|
||||
|
||||
#include "../connectd/handshake.c"
|
||||
|
||||
/* This makes the handshake prototypes work. */
|
||||
struct io_conn {
|
||||
@ -322,7 +328,7 @@ int main(int argc, char *argv[])
|
||||
opt_usage_exit_fail("Invalid id %.*s",
|
||||
(int)(at - argv[1]), argv[1]);
|
||||
|
||||
if (!parse_wireaddr_internal(at+1, &addr, DEFAULT_PORT, NULL,
|
||||
if (!parse_wireaddr_internal(at+1, &addr, simple_get_ln_port(NULL), NULL,
|
||||
true, false, true, &err_msg))
|
||||
opt_usage_exit_fail("%s '%s'", err_msg, argv[1]);
|
||||
|
||||
@ -376,4 +382,3 @@ int main(int argc, char *argv[])
|
||||
handshake_success, argv+2);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
@ -350,8 +350,8 @@ static void handle_remote_addr(struct daemon *daemon, const u8 *msg)
|
||||
if (!fromwire_gossipd_remote_addr(msg, &remote_addr))
|
||||
master_badmsg(WIRE_GOSSIPD_REMOTE_ADDR, msg);
|
||||
|
||||
/* current best guess is that we use DEFAULT_PORT on public internet */
|
||||
remote_addr.port = DEFAULT_PORT;
|
||||
/* current best guess is that we use default port on public internet */
|
||||
remote_addr.port = chainparams_get_ln_port(chainparams);
|
||||
|
||||
switch (remote_addr.type) {
|
||||
case ADDR_TYPE_IPV4:
|
||||
|
@ -53,4 +53,3 @@ $(GOSSIPD_TEST_PROGRAMS): $(GOSSIPD_TEST_COMMON_OBJS) $(BITCOIN_OBJS)
|
||||
$(GOSSIPD_TEST_OBJS): $(GOSSIPD_HEADERS) $(GOSSIPD_SRC)
|
||||
|
||||
gossipd-tests: $(GOSSIPD_TEST_PROGRAMS:%=unittest/%)
|
||||
|
||||
|
@ -141,7 +141,7 @@ static struct command_result *json_connect(struct command *cmd,
|
||||
/* Is there a port? */
|
||||
if (!port) {
|
||||
port = tal(cmd, u32);
|
||||
*port = chainparams->ln_port;
|
||||
*port = chainparams_get_ln_port(chainparams);
|
||||
}
|
||||
addr = tal(cmd, struct wireaddr_internal);
|
||||
if (!parse_wireaddr_internal(name, addr, *port, false,
|
||||
|
@ -970,7 +970,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
/*~ Set the default portnum according to the used network
|
||||
* similarly to what Bitcoin Core does to ports by default. */
|
||||
ld->portnum = chainparams->ln_port;
|
||||
ld->portnum = chainparams_get_ln_port(chainparams);
|
||||
|
||||
/*~ Initialize all the plugins we just registered, so they can
|
||||
* do their thing and tell us about themselves (including
|
||||
|
@ -100,14 +100,14 @@ def test_remote_addr(node_factory, bitcoind):
|
||||
# must not yet be send as we need the same `remote_addr` confirmed from a
|
||||
# another peer we have a channel with.
|
||||
# Note: In this state l2 stores remote_addr as reported by l1
|
||||
assert not l2.daemon.is_in_log("Update our node_announcement for discovered address: 127.0.0.1:9735")
|
||||
assert not l2.daemon.is_in_log("Update our node_announcement for discovered address: 127.0.0.1:19846")
|
||||
l1.restart()
|
||||
l2.rpc.connect(l1.info['id'], 'localhost', l1.port)
|
||||
l2.daemon.wait_for_log("Peer says it sees our address as: 127.0.0.1:[0-9]{5}")
|
||||
|
||||
# Now l1 sees l2 but without announced addresses.
|
||||
assert(len(l1.rpc.listnodes(l2.info['id'])['nodes'][0]['addresses']) == 0)
|
||||
assert not l2.daemon.is_in_log("Update our node_announcement for discovered address: 127.0.0.1:9735")
|
||||
assert not l2.daemon.is_in_log("Update our node_announcement for discovered address: 127.0.0.1:19846")
|
||||
|
||||
# connect second node. This will not yet trigger `node_annoucement` update,
|
||||
# as we again do not have a channel at the time we connected.
|
||||
@ -117,20 +117,20 @@ def test_remote_addr(node_factory, bitcoind):
|
||||
# fund channel and check we didn't send Update earlier already
|
||||
l2.fundchannel(l3, wait_for_active=True)
|
||||
bitcoind.generate_block(5)
|
||||
assert not l2.daemon.is_in_log("Update our node_announcement for discovered address: 127.0.0.1:9735")
|
||||
assert not l2.daemon.is_in_log("Update our node_announcement for discovered address: 127.0.0.1:19846")
|
||||
|
||||
# restart, reconnect and re-check for updated node_annoucement. This time
|
||||
# l2 sees that two different peers with channel reported the same `remote_addr`.
|
||||
l3.restart()
|
||||
l2.rpc.connect(l3.info['id'], 'localhost', l3.port)
|
||||
l2.daemon.wait_for_log("Peer says it sees our address as: 127.0.0.1:[0-9]{5}")
|
||||
l2.daemon.wait_for_log("Update our node_announcement for discovered address: 127.0.0.1:9735")
|
||||
l2.daemon.wait_for_log("Update our node_announcement for discovered address: 127.0.0.1:19846")
|
||||
l1.daemon.wait_for_log(f"Received node_announcement for node {l2.info['id']}")
|
||||
|
||||
address = l1.rpc.listnodes(l2.info['id'])['nodes'][0]['addresses'][0]
|
||||
assert address['type'] == "ipv4"
|
||||
assert address['address'] == "127.0.0.1"
|
||||
assert address['port'] == 9735
|
||||
assert address['port'] == 19846
|
||||
|
||||
|
||||
@pytest.mark.developer("needs DEVELOPER=1 for fast gossip and --dev-allow-localhost for local remote_addr")
|
||||
|
@ -838,11 +838,11 @@ static struct peer *wallet_peer_load(struct wallet *w, const u64 dbid)
|
||||
|
||||
/* This can happen for peers last seen on Torv2! */
|
||||
addrstr = db_col_strdup(tmpctx, stmt, "address");
|
||||
if (!parse_wireaddr_internal(addrstr, &addr, DEFAULT_PORT,
|
||||
if (!parse_wireaddr_internal(addrstr, &addr, chainparams_get_ln_port(chainparams),
|
||||
false, false, true, true, NULL)) {
|
||||
log_unusual(w->log, "Unparsable peer address %s: replacing",
|
||||
addrstr);
|
||||
parse_wireaddr_internal("127.0.0.1:1", &addr, DEFAULT_PORT,
|
||||
parse_wireaddr_internal("127.0.0.1:1", &addr, chainparams_get_ln_port(chainparams),
|
||||
false, false, true, true, NULL);
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,9 @@ static const char *reason;
|
||||
/* Generated stub for chainparams_by_chainhash */
|
||||
const struct chainparams *chainparams_by_chainhash(const struct bitcoin_blkid *chain_hash UNNEEDED)
|
||||
{ fprintf(stderr, "chainparams_by_chainhash called!\n"); abort(); }
|
||||
/* Generate std for chainparams_get_ln_port */
|
||||
int chainparams_get_ln_port(const struct chainparams *params UNNEEDED)
|
||||
{ fprintf(stderr, "chainparams_get_ln_port called!\n"); abort(); }
|
||||
/* Generated stub for fromwire_channel_id */
|
||||
bool fromwire_channel_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
|
||||
struct channel_id *channel_id UNNEEDED)
|
||||
|
Loading…
Reference in New Issue
Block a user