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

Tag peers with live hop streams #75

Merged
merged 3 commits into from
May 7, 2019
Merged

Tag peers with live hop streams #75

merged 3 commits into from
May 7, 2019

Conversation

vyzo
Copy link
Contributor

@vyzo vyzo commented May 7, 2019

This adds connection manager tagging for peers with live hops.
Note the extra supervisory goroutine in the hop, as we need to ensure both sides are closed before removing the tag and reduce the live hop count.

Closes #65

@vyzo vyzo requested review from Stebalien and raulk May 7, 2019 18:17
@ghost ghost assigned vyzo May 7, 2019
@ghost ghost added the status/in-progress In progress label May 7, 2019
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works, but we may want to consider reusing the existing goroutines. That is, either:

  1. Have one goroutine wait for the other to finish and make it responsible for cleaning up.
  2. Have both goroutines check/set an atomic counter. When the counter reaches 0, that goroutine does the cleanup.

usually, I'd say to just stick with an extra goroutine. However, we have a lot of goroutines here.

@vyzo
Copy link
Contributor Author

vyzo commented May 7, 2019

Reusing the existing goroutine will linger too, and will make decrementing the stream count awkward.
Plus the new goroutine has a very short stack, which is not necessarily the case when reusing the goroutine.

But I do like the idea of the atomic counter, it's more code but totally obviates the need for the extra goroutine.

@vyzo
Copy link
Contributor Author

vyzo commented May 7, 2019

Alright, implemented with an atomic counter.

@vyzo vyzo requested a review from Stebalien May 7, 2019 19:19
@@ -364,10 +369,18 @@ func (r *Relay) handleHopStream(s inet.Stream, msg *pb.CircuitRelay) {

r.addLiveHop(src.ID, dst.ID)

goroutines := new(int32)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that this is allocated on the heap to avoid lingering the original goroutine stack.

@Stebalien Stebalien merged commit ac02326 into master May 7, 2019
@ghost ghost removed the status/in-progress In progress label May 7, 2019
@Stebalien Stebalien deleted the feat/conn-tags branch May 7, 2019 19:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Work with the connection manager
2 participants