Andre's Blog

20160827 How To Decide Who is First When Everything Happens At The Same Time

[CISYSTEM] [ME] [DICE] [RANDOM]

I am working on my implementation of the network and communication layers of CISystem. From now on I need 2 weeks for getting something reasonable done, the connections are too big to split them and I only have 4 - 8 hours per week for it. This means from now on I post only every 2 weeks, my next post should be before 11th of September.

This week I had to think a lot about how my nodes will be connected with each other.

One of the requirements is, there is no central server node, every node shall be able to take over at any time.

My idea is to really have each node connected with every other node, but I want an efficient structure of connections.

My questions, answers and decisions are :

Which socket connections will be created automatically by the nodes?

At start a node is reading a configuration of other nodes.

There will be

  1. A thread opening connections to the configured nodes.
  2. A server socket accepting the connections of the other nodes.

Both will happen more or less at the same time and it would be hard to decide which connection to create or to allow and which not.

It means, each pair of nodes will be connected in both ways.

This ascii art shall visualize the direction in which the connections are set up, the to-node is always a server socket.

 A ---> B

 A <--- B

Which socket connections does the network really need?

Simple, only one connection between two nodes is needed. I have figured out, I can use the same implementation of communication and protocol for both client and server as both need to share the same information in both directions : they are both client and server at the same time.

This means, when a pair of nodes is connected in both directions, one connection is not needed.

Since setting up the connections happens at the same time it would be quite complicated to suppress one of them.

I have decided to drop one connection after both are set up.

The question is only : which one?

How does a pair of nodes decide which connection to drop?

Have you ever played Shadowrun? Or Cthulhu? Or any other role play or board game?

How do you decide who starts?

Sure, role a dice.

Both nodes will generate a random number and the node with the bigger number will be the lead node and drop one connection.

Every node will continuously check that it is connected with every other node, but one connection will be sufficient, so it is not necessary to inform the other node which connection will be dropped.

Select where to go ...


The Blog
My Technical Blogs
Projects
Blogs Of Friends
RSS
CV/About
Me