Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

p2p/net/swarm: dial once at a time #549

Merged
merged 4 commits into from
Jan 13, 2015
Merged

p2p/net/swarm: dial once at a time #549

merged 4 commits into from
Jan 13, 2015

Conversation

jbenet
Copy link
Member

@jbenet jbenet commented Jan 13, 2015

This PR makes swarm dials wait for each other.

@jbenet jbenet added the status/in-progress In progress label Jan 13, 2015
@jbenet
Copy link
Member Author

jbenet commented Jan 13, 2015

@briantigerchow RFCR?

// may have received an incoming connection! if so, we no longer must dial.
//
// dial attempts. we may be doing the dialing. if not, we wait.
attempts := 3
Copy link
Contributor

Choose a reason for hiding this comment

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

const?

Copy link
Member Author

Choose a reason for hiding this comment

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

sgtm - 25c6ab8

@btc
Copy link
Contributor

btc commented Jan 13, 2015

@jbenet LGTM


// ok, we have been charged to dial! let's do it.
conn, err = s.dial(ctx, p)
s.dsync.Unlock(p)
Copy link
Contributor

Choose a reason for hiding this comment

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

It wasn't immediately clear that the conn is added to the swarm's list of conns in the dial method, so I thought this lock might've been released too early.

However, I read through and saw that swarm add conn occurs in dialConnSetup.

(nested state changes are somewhat hard to follow. It's nice to have lots of pure code (and to isolate code containing the side-effects, and to keep the side-effects as close to the surface as possible))

but the code looks correct. LGTM

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, i was annoyed by this, and other warts. it isn't easy to lift up, without carrying a lot of logic into this part, which I wanted to keep very light-- only focused on the sync attempts (turns out dialing is hard!). I added a note 8e888b1 which may clear it up for the reader.

@jbenet
Copy link
Member Author

jbenet commented Jan 13, 2015

ok, thanks! I'll merge when the build greens

jbenet added a commit that referenced this pull request Jan 13, 2015
p2p/net/swarm: dial once at a time
@jbenet jbenet merged commit 9b2ccf1 into master Jan 13, 2015
@jbenet jbenet removed the status/in-progress In progress label Jan 13, 2015
@jbenet jbenet deleted the fix-simultaneous-dials branch January 13, 2015 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants