p2p
p2p copied to clipboard
sharing neighbors
hi,
you did a great job with this little bookcase, congratulations!
how can I make the nodes share their neighbors with each other so that the network grows automatically
I had the following this steps in mind:
- one node start with some default nodes as a seeds, of which you know ip and port, hardcoded of by config file
- create a new type of message that sends the list of neighbors, for example it can be named 'discover'
- create a loop that interrogates your neighbors to ask them what their respective neighbors are and connect to them
I'm not sure how to start art code, can I ask you for a suggestion? are the above steps right?
Each node can respond to handshake
message with some kind of hello
message, but this will not be just nodes list. It must work like list list of
{
me: {
name: "Display name?",
alias: "this_node_unique_name",
signature: "base64url-bytes",
refifier: "base64Url-bytes"
},
peers: [ {
name: "some readable name",
alias: "other_unique_name",
seen: 1670794121448,
signature: "base64url-bytes",
verifier: "base64Url-bytes"
} ]
}
I placed here more data than necessary for your question, but I guess, that most important in that data is these parts:
- distinction between info about replying node (the
me
property) and its peers, in thepeers
property. - the
seen
property is like last time any message received bythis_node_unique_name
fromother_unique_name
. But joining node more likely to be bombarded with lots of replies,hello
messages like this.
Imagine nodes bob
, alice
, and mike
. Here mary
comes and broadcasts her handshake
message. This means that eventually mary
will get hello
messages from all them, identical or not, it depends from situation, because bob
and mike
for example can know henry
but not know julia
known to alice
who knows nothing about henry
. Joining node, mary
can include list of known nodes in her handshake
message like peers
field from example, but what if some node sorta popular and knows hundreds of other nodes? Should it broadcast all this large list?
May be spreading handshake
to other peers and replying with own information in hello
reply message is enough, and no need to spread whole lists across network.