-
Notifications
You must be signed in to change notification settings - Fork 961
introduce support for alternative addresses for peer connections #7422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
maxrantil
wants to merge
9
commits into
ElementsProject:master
Choose a base branch
from
maxrantil:max/alt-addr
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8cd3547
lightningd: add alt-addr config parameter
maxrantil 183ca77
channeld: provide alt-addr to peer upon channel establish
maxrantil 5a9c205
wallet: handle storing and reveiving alt_addrs from db
maxrantil e43ab91
connectd: handle alt addr for outbound connection
maxrantil 1be20b5
connectd: validate connections to alt-addr against a whitelist
maxrantil 14b873d
json-rpc: add rpc to provide bound alt-addr
maxrantil 9b5a55d
pytest: ... start testing
maxrantil 3f8bd91
lightningd: Update 'listpeers' command to print alt-addrs for a peer
maxrantil 6be03fc
generated files added to pass the 'make check-gen-updated' test
maxrantil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| #include "config.h" | ||
| #include <common/whitelisted_peer.h> | ||
| #include <connectd/connectd.h> | ||
| #include <wire/wire.h> | ||
|
|
||
| static void destroy_whitelisted_peer(struct whitelisted_peer *peer) | ||
| { | ||
| if (peer->my_alt_addrs) | ||
| tal_free(peer->my_alt_addrs); | ||
| tal_free(peer); | ||
| } | ||
|
|
||
| void populate_whitelist_table(struct daemon *daemon, | ||
| struct whitelisted_peer *wp) | ||
| { | ||
| if (wp) { | ||
| size_t num_whitelisted = tal_count(wp); | ||
| for (size_t i = 0; i < num_whitelisted; i++) { | ||
| if (whitelisted_peer_htable_get(daemon->whitelisted_peer_htable, | ||
| &wp[i].id)) { | ||
| tal_free(&wp[i]); | ||
| continue; | ||
| } | ||
|
|
||
| struct whitelisted_peer *new_peer = tal_steal(daemon, | ||
| &wp[i]); | ||
|
|
||
| whitelisted_peer_htable_add(daemon->whitelisted_peer_htable, | ||
| new_peer); | ||
|
|
||
| tal_add_destructor(new_peer, destroy_whitelisted_peer); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void towire_whitelisted_peer(uint8_t **p, const struct whitelisted_peer *wp) | ||
| { | ||
| /* Serialize the node_id */ | ||
| towire_node_id(p, &wp->id); | ||
|
|
||
| /* Serialize the num of addrs */ | ||
| uint16_t num_alt_addrs = tal_count(wp->my_alt_addrs); | ||
| towire_u16(p, num_alt_addrs); | ||
|
|
||
| /* Serialize each alternate address */ | ||
| for (size_t i = 0; i < num_alt_addrs; i++) | ||
| towire_wireaddr_internal(p, &wp->my_alt_addrs[i]); | ||
| } | ||
|
|
||
| bool fromwire_whitelisted_peer(const uint8_t **cursor, | ||
| size_t *plen, | ||
| struct whitelisted_peer *wp) | ||
| { | ||
| /* Deserialize the node_id */ | ||
| fromwire_node_id(cursor, plen, &wp->id); | ||
|
|
||
| /* Deserialize the number of alternate addresses */ | ||
| uint16_t num_alt_addrs = fromwire_u16(cursor, plen); | ||
|
|
||
| wp->my_alt_addrs = tal_arr(wp, struct wireaddr_internal, num_alt_addrs); | ||
|
|
||
| /* Deserialize each alternate address */ | ||
| for (size_t i = 0; i < num_alt_addrs; i++) | ||
| if (!fromwire_wireaddr_internal(cursor, plen, &wp->my_alt_addrs[i])) | ||
| return false; | ||
|
|
||
| return *cursor != NULL; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #ifndef LIGHTNING_COMMON_WHITELISTED_PEER_H | ||
| #define LIGHTNING_COMMON_WHITELISTED_PEER_H | ||
| #include "config.h" | ||
| #include <ccan/htable/htable_type.h> | ||
| #include <ccan/tal/tal.h> | ||
| #include <common/node_id.h> | ||
| #include <common/wireaddr.h> | ||
| #include <stdbool.h> | ||
| #include <stddef.h> | ||
| #include <stdint.h> | ||
|
|
||
| struct daemon; | ||
|
|
||
| struct whitelisted_peer { | ||
| struct node_id id; | ||
| struct wireaddr_internal *my_alt_addrs; | ||
| }; | ||
|
|
||
| /* Function for populating the hashtable */ | ||
| void populate_whitelist_table(struct daemon *daemon, | ||
| struct whitelisted_peer *peers); | ||
|
|
||
| void towire_whitelisted_peer(uint8_t **p, | ||
| const struct whitelisted_peer *whitelisted_peer); | ||
|
|
||
| bool fromwire_whitelisted_peer(const uint8_t **cursor, size_t *plen, | ||
| struct whitelisted_peer *whitelisted_peer); | ||
|
|
||
| #endif /* LIGHTNING_COMMON_WHITELISTED_PEER_H */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can simply be a set of node ids (i.e a htable of node_ids).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the previous answer does explain why we need more then only the node_id