aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-02-02 18:11:51 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-02-02 18:11:51 +0100
commitfba8b2af286ace2aa857123e9c14aa794a42f830 (patch)
treefc49a8afa0493d6bd9455b93bea709bd55215e62
parent39fe0aa91b4f3d5b17abd391b40957c16421aa2d (diff)
Go concurrent
-rw-r--r--authorize.go25
-rw-r--r--cmd/acme/main.go54
2 files changed, 44 insertions, 35 deletions
diff --git a/authorize.go b/authorize.go
index 0dc82a2..6b3d22e 100644
--- a/authorize.go
+++ b/authorize.go
@@ -1,6 +1,9 @@
package acme
-import "time"
+import (
+ "sync"
+ "time"
+)
// Authorization request
type Authorization struct {
@@ -61,19 +64,27 @@ func (p *Provider) authz(s Signer, domain string, sol map[ChalType]Solver) error
return err
}
// second step: choose and start solver
+ wg := sync.WaitGroup{}
for _, ch := range req.Supported(sol) {
- if err = p.solve(s, ch, sol[ch.Type]); err != nil {
- return err
- }
+ wg.Add(1)
+ go func(ch Challenge) {
+ p.solve(s, ch, sol[ch.Type])
+ wg.Done()
+ }(ch)
}
+ wg.Wait()
return nil
}
func (p *Provider) Authorize(s Signer, d *Desire) error {
+ wg := sync.WaitGroup{}
for _, domain := range d.altnames {
- if err := p.authz(s, domain, d.solver); err != nil {
- return err
- }
+ wg.Add(1)
+ go func(domain string) {
+ p.authz(s, domain, d.solver)
+ wg.Done()
+ }(domain)
}
+ wg.Wait()
return nil
}
diff --git a/cmd/acme/main.go b/cmd/acme/main.go
index 7427ca3..d8b1cfd 100644
--- a/cmd/acme/main.go
+++ b/cmd/acme/main.go
@@ -6,6 +6,7 @@ import (
"log"
"os"
"runtime/trace"
+ "sync"
"dim13.org/acme"
)
@@ -57,30 +58,6 @@ func prepare(conf *Config) error {
return nil
}
-func satisfice(des *desire) error {
- if !des.account.registered {
- log.Println("register acc")
- if err := des.provider.Register(des.account, des.account.Contacts); err != nil {
- return err
- }
- des.account.registered = true
- }
-
- if err := des.provider.Authorize(des.account, des.Desire); err != nil {
- return err
- }
-
- if err := des.provider.Bundle(des.account, des.Desire); err != nil {
- return err
- }
-
- if err := des.Save(des.Cert, des.Key); err != nil {
- return err
- }
-
- return nil
-}
-
func main() {
flag.Parse()
if *tracing != "" {
@@ -114,6 +91,23 @@ func main() {
log.Fatal(err)
}
+ // register accs first
+ wg := sync.WaitGroup{}
+ for k, des := range conf.Desire {
+ if des.account.registered {
+ continue
+ }
+ wg.Add(1)
+ go func(name string, des *desire) {
+ log.Println("register", name)
+ des.provider.Register(des.account, des.account.Contacts)
+ des.account.registered = true
+ wg.Done()
+ }(k, des)
+ }
+ wg.Wait()
+
+ // satisfice
for k, des := range conf.Desire {
if des.Webroot != "" {
wrSol := acme.NewWebrootSolver(des.Webroot)
@@ -128,9 +122,13 @@ func main() {
log.Fatal("no Solver available")
}
- log.Println("satisfice", k)
- if err := satisfice(des); err != nil {
- log.Fatal(err)
- }
+ wg.Add(1)
+ go func(name string, des *desire) {
+ des.provider.Authorize(des.account, des.Desire)
+ des.provider.Bundle(des.account, des.Desire)
+ des.Save(des.Cert, des.Key)
+ wg.Done()
+ }(k, des)
}
+ wg.Wait()
}