lxchurbakov / p2p

Lightweight Node.js P2P library
https://www.npmjs.com/package/@swensson/p2p
37 stars 14 forks source link

sharing neighbors #1

Open stefanocudini opened 2 years ago

stefanocudini commented 2 years ago

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: 1) one node start with some default nodes as a seeds, of which you know ip and port, hardcoded of by config file 2) create a new type of message that sends the list of neighbors, for example it can be named 'discover' 3) 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?

koteisaev commented 1 year ago

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: 1) distinction between info about replying node (the me property) and its peers, in the peers property. 2) the seen property is like last time any message received by this_node_unique_name from other_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.