Skip to content
This repository was archived by the owner on Sep 9, 2022. It is now read-only.

Detect dial cycles #96

Open
Stebalien opened this issue Mar 3, 2020 · 0 comments
Open

Detect dial cycles #96

Stebalien opened this issue Mar 3, 2020 · 0 comments

Comments

@Stebalien
Copy link
Member

It's possible to cause a dial cycle in the relay (libp2p/go-libp2p#816). While it would be nice to be able to solve this in the general case, we can at least solve this in this transport by keeping track of dial dependencies.

We need to keep a directed graph of active dials mapping target nodes (the ones we're dialing) to relays (the relays we're dialing those nodes through). Then, before we dial a target node, we can lookup the chosen relay in this graph, to see if it is also a target node. If it is, we need to recursively follow the graph to see if we end back up at the original target. If we do, we have a cycle and we need to abort.

More concretely, if we first try to dial b through c, then a through b, we'd have the following edges in our graph:

  • a (target) -> b (relay)
  • b (target) -> c (relay)

Then, if we try to dial c through a, we'd:

  • Lookup a in the graph, and get b,
  • Lookup b in the graph, and get c.
  • Compare c == c, determine that we have a cycle, and abort.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant