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

Bootstrap immediately after calls to BootstrapWithConfig #170

Merged
merged 5 commits into from
Jul 24, 2018

Conversation

bigs
Copy link
Contributor

@bigs bigs commented Jun 29, 2018

closes #163. need to test locally just to be sure.

@bigs bigs added the status/in-progress In progress label Jun 29, 2018
@bigs bigs requested a review from Stebalien June 29, 2018 16:34
@ghost ghost assigned bigs Jun 29, 2018
dht_bootstrap.go Outdated
@@ -77,7 +77,24 @@ func (dht *IpfsDHT) BootstrapWithConfig(cfg BootstrapConfig) (goprocess.Process,
return nil, fmt.Errorf("invalid number of queries: %d", cfg.Queries)
}

proc := periodicproc.Tick(cfg.Period, dht.bootstrapWorker(cfg))
tickch := make(chan struct{}, 1)
proc := periodicproc.OnSignal(tickch, dht.bootstrapWorker(cfg))
Copy link
Member

Choose a reason for hiding this comment

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

So, OnSignal is useful when you already have a channel but, in this case, I'd just fire off your own goroutine:

dht.Process().Go(func(p goprocess.Process) {
    for {
       select {
       ...
       case <-p.Closing():
           return
       }
    }
})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah, totally!

@bigs
Copy link
Contributor Author

bigs commented Jul 2, 2018

@Stebalien that change is up!

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.

I need to stop forgetting about half-written reviews...

It should be possible to just write something like:

for {
  select {
  case <-time.After(cfg.Period):
    <-p.Go(dht.bootstrapWorker(cfg)).Closed()
  case <-p.Closing():
    return
  }
}

goprocess will tell the worker when to quit. Does that sound right?

@bigs
Copy link
Contributor Author

bigs commented Jul 23, 2018

@Stebalien so the details behind the slightly more complex logic are: the implementation of goprocess ticker functions is such that the process will not be executed again if the previous instantiation of it has not terminated, effectively skipping one of our intervals. i sought to keep that behavior consistent, though if it's not particularly necessary for us i'm happy to remove it! in c++ i'd probably just handle this with an std::atomic<bool> flag and be done with it, but the chan chan thing seemed to be most idiomatically go.

@Stebalien
Copy link
Member

Hm. That's kind of an odd way to do it... The code above will just avoid starting the timer until the previous operation has finished (i.e., it will cause the system to sleep interval between operations).

@Stebalien
Copy link
Member

I'd just go with the simple code. I'm not aware of any good reason we do what we do with ticker.

@bigs
Copy link
Contributor Author

bigs commented Jul 23, 2018

done!

dht_bootstrap.go Outdated
proc := periodicproc.Tick(cfg.Period, dht.bootstrapWorker(cfg))
proc := dht.Process().Go(func(p goprocess.Process) {
for {
select {
Copy link
Member

Choose a reason for hiding this comment

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

This'll need a <-p.Go(dht.bootstrapWorker(cfg)).Closed() at the top (to actually fix the bug 😄). Sorry about that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hahahaha wasn't even thinking about that. yup.

@bigs
Copy link
Contributor Author

bigs commented Jul 24, 2018

smh hahaha. done

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.

Bootstrap immediately
2 participants