aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-12-24 23:39:10 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-12-24 23:39:10 +0100
commit66ee37696f8a77152dfe2fd75f1eab173c71f213 (patch)
tree937333325b3d5c41805a6adbe4f1cd3dddd5e8e7 /client.go
parent88533d6843eee95763c8e4782b60c4da17fc7609 (diff)
Add timeout on Solve
Diffstat (limited to 'client.go')
-rw-r--r--client.go17
1 files changed, 14 insertions, 3 deletions
diff --git a/client.go b/client.go
index bbae554..0dacdd8 100644
--- a/client.go
+++ b/client.go
@@ -216,6 +216,8 @@ func pickChallenge(c []Challenge) (int, Challenge) {
return -1, Challenge{}
}
+var errTimedOut = errors.New("timed out")
+
func (c *Client) Authorize(a *Account, altnames []string) error {
ident := Identifier{
Type: IdentDNS,
@@ -251,13 +253,21 @@ func (c *Client) Authorize(a *Account, altnames []string) error {
s = &httpChallenge{Addr: "localhost:8080", Challenge: *ans}
}
- if err := Solve(s); err != nil {
+ errc := make(chan error)
+ go func() {
+ if err := Solve(s); err != nil {
+ errc <- err
+ }
+ }()
+ select {
+ case err = <-errc:
return err
+ case <-time.After(5 * time.Second):
+ return errTimedOut
}
ns := parseHeader(resp)
done := make(chan bool)
- errc := make(chan error)
log.Println(ansi.Color("NextStep", "green"), ns)
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
@@ -274,7 +284,7 @@ func (c *Client) Authorize(a *Account, altnames []string) error {
case <-done:
case err = <-errc:
case <-time.After(5 * time.Second):
- return errors.New("timed out")
+ return errTimedOut
}
}
@@ -282,6 +292,7 @@ func (c *Client) Authorize(a *Account, altnames []string) error {
}
func (c *Client) Status(url string, n int, done chan bool) error {
+ log.Println(ansi.Color("STATUS", "red:yellow"))
r := &Authorization{}
resp, err := http.Get(url)
if err != nil {