marcelklehr / smokesignal

Build your own small (or larger) peer to peer network with node.js
156 stars 21 forks source link

Exclusive networks #18

Open jabr opened 7 years ago

jabr commented 7 years ago

There is a small probability of a network becoming exclusive (and rejecting any new nodes) if they all hit the max peer number within the current network.

I hit that with a test run with a single seed today.

The root issue is that the response to a peer request is 50/50 once past the minimum peer number.

I don't have a solution yet, and I'm curious if others have ideas.

marcelklehr commented 7 years ago

I think there's two issues:

1) If all nodes hit the max peer number every new node is rejected. This is rather unlikely, I'd say, because the nodes don't actively seek peers beyond the min peer number. How large was your network when it became exclusive?

2) When all nodes hit the min peer number there's a probability that a new node will be rejected, which is decreasing as the network size increases.

see https://github.com/marcelklehr/smokesignal/blob/6826808/lib/node.js#L320 for reference

I think 1) can maybe be avoided by having a proximity function and rejecting with higher probability the closer a node is. This is also useful for #7.

jabr commented 7 years ago

I created a seed node, then was creating 100 new nodes in a loop referencing the single seed.

The resulting network just had 9 or 10 connected nodes (all with 5 peers) and the rest disconnected.

Another approach might be an unlimited number of max nodes with a decreasing probability of adding a new peer past the min number. E.g. something like this to replace line 332:

if (this.isSufficientlyFilled() && Math.random() > 1.0 / this.peers.length) return
marcelklehr commented 7 years ago

That's a bummer, of course. I like both the empirical approach and the proposed solution. Let's try the same test with your suggested change.

On October 10, 2016 9:05:50 PM CEST, Justin Bradford notifications@github.com wrote:

I created a seed node, then was creating 100 new nodes in a loop referencing the single seed.

The resulting network just had 9 or 10 connected nodes (all with 5 peers) and the rest disconnected.

Another approach might be an unlimited number of max nodes, which a decreasing probability of adding a new peer past the min number. e.g. something like this to replace line 332:

if (this.isSufficientlyFilled() && Math.random() > 1.0 /
this.peers.length) return

You are receiving this because you commented. Reply to this email directly or view it on GitHub: https://github.com/marcelklehr/smokesignal/issues/18#issuecomment-252715482

Sent from my Android device with K-9 Mail. Please excuse my brevity.

sethleedy commented 7 years ago

How did the test go ?

marcelklehr commented 7 years ago

@sethleedy Sorry, I haven't done the test, yet, because the project shifted out of my focus. If you'd like to do the test, feel free. I haven't abandoned the project :)