What if the links form a graph?
Suppose machines are linked as neighbors, and links can form cycles. Machine 2 might be asked by 1 and then by 3. The tree protocol counts it twice, once under each asker. On a cycle it never stops: asks go round and round.
The fix is the seen-set of a graph search, spread over the machines. Each machine remembers whether it was asked before:
- First ask: visit. Store the asker as the parent and ask every neighbor except the parent.
- Any later ask: answer 0 at once. This machine is already counted under its first parent.
The 0 answer matters. The second asker is waiting for this machine like any other neighbor. Ignore the ask, and the asker waits forever.
The asks that were answered for real form a tree inside the graph, a spanning tree. The count runs over it, and the 0 answers are the extra links.
The editor holds a Machine whose neighbors replace children, with visit written and the ask branch of receive cut out. Write the ask branch: visit on the first ask, and answer 0 on every later one.