Skip to content

Commit

Permalink
lightnind: remove the DEFAULT_PORT global definition.
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Jun 18, 2022
1 parent 7ec6353 commit 1380474
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 17 deletions.
3 changes: 3 additions & 0 deletions common/test/run-wireaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <common/setup.h>
#include <stdio.h>

/* DEFAULT_PORT of the current network */
#define DEFAULT_PORT chainparams->ln_port

/* AUTOGENERATED MOCKS START */
/* Generated stub for amount_asset_is_main */
bool amount_asset_is_main(struct amount_asset *asset UNNEEDED)
Expand Down
5 changes: 3 additions & 2 deletions common/wireaddr.c
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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->ln_port;
/* Format is separated by slash. */
char **parts = tal_strsplit(tmpctx, arg, "/", STR_EMPTY_OK);

Expand Down Expand Up @@ -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->ln_port;
memset(addr->u.torservice.blob, 0, sizeof(addr->u.torservice.blob));

/* Format is separated by slash. */
Expand Down
8 changes: 0 additions & 8 deletions common/wireaddr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions connectd/connectd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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->ln_port,
NULL, broken_reply, NULL);
if (new_addrs) {
for (size_t j = 0; j < tal_count(new_addrs); j++) {
Expand Down Expand Up @@ -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->ln_port);
tal_arr_expand(&addrs, unresolved);
}
} else if (daemon->use_dns) {
Expand Down
3 changes: 3 additions & 0 deletions connectd/test/run-netaddress.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include <stdio.h>
#include <wire/wire.h>

/* Default port of the current network */
#define DEFAULT_PORT chainparams->ln_port

/* AUTOGENERATED MOCKS START */
/* Generated stub for amount_asset_is_main */
bool amount_asset_is_main(struct amount_asset *asset UNNEEDED)
Expand Down
3 changes: 1 addition & 2 deletions devtools/gossipwith.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,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, chainparams->ln_port, NULL,
true, false, true, &err_msg))
opt_usage_exit_fail("%s '%s'", err_msg, argv[1]);

Expand Down Expand Up @@ -376,4 +376,3 @@ int main(int argc, char *argv[])
handshake_success, argv+2);
exit(0);
}

4 changes: 2 additions & 2 deletions gossipd/gossipd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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->ln_port;

switch (remote_addr.type) {
case ADDR_TYPE_IPV4:
Expand Down
2 changes: 1 addition & 1 deletion wallet/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ static struct peer *wallet_peer_load(struct wallet *w, const u64 dbid)
db_col_node_id(stmt, "node_id", &id);

addrstr = db_col_strdup(tmpctx, stmt, "address");
if (!parse_wireaddr_internal(addrstr, &addr, DEFAULT_PORT,
if (!parse_wireaddr_internal(addrstr, &addr, chainparams->ln_port,
false, false, true, true, NULL))
goto done;

Expand Down

0 comments on commit 1380474

Please sign in to comment.