added ExtendLifetime
This commit is contained in:
parent
a147ed64ec
commit
24ca5f01b5
@ -6,6 +6,7 @@ import "net/http"
|
||||
import "net/url"
|
||||
import "runtime"
|
||||
import "strconv"
|
||||
import "strings"
|
||||
import "time"
|
||||
import "unsafe"
|
||||
|
||||
@ -549,8 +550,11 @@ func (ctl *client_ctl_client_conns_id_routes_id) ServeHTTP(w http.ResponseWriter
|
||||
goto oops
|
||||
}
|
||||
|
||||
|
||||
err = r.ResetLifetime(lifetime)
|
||||
if strings.HasPrefix(jcr.Lifetime, "+") {
|
||||
err = r.ExtendLifetime(lifetime)
|
||||
} else {
|
||||
err = r.ResetLifetime(lifetime)
|
||||
}
|
||||
if err != nil { goto oops }
|
||||
|
||||
case http.MethodDelete:
|
||||
@ -649,9 +653,17 @@ func (ctl *client_ctl_client_conns_id_routes_spsp) ServeHTTP(w http.ResponseWrit
|
||||
status_code = http.StatusBadRequest; w.WriteHeader(status_code)
|
||||
err = fmt.Errorf("wrong lifetime value %s - %s", jcr.Lifetime, err.Error())
|
||||
goto oops
|
||||
} else if lifetime < 0 {
|
||||
status_code = http.StatusBadRequest; w.WriteHeader(status_code)
|
||||
err = fmt.Errorf("negative lifetime value %s", jcr.Lifetime)
|
||||
goto oops
|
||||
}
|
||||
|
||||
err = r.ResetLifetime(lifetime)
|
||||
if strings.HasPrefix(jcr.Lifetime, "+") {
|
||||
err = r.ExtendLifetime(lifetime)
|
||||
} else {
|
||||
err = r.ResetLifetime(lifetime)
|
||||
}
|
||||
if err != nil { goto oops }
|
||||
|
||||
case http.MethodDelete:
|
||||
|
17
client.go
17
client.go
@ -266,6 +266,23 @@ func (r *ClientRoute) FindClientPeerConnById(conn_id PeerId) *ClientPeerConn {
|
||||
return c
|
||||
}
|
||||
|
||||
func (r *ClientRoute) ExtendLifetime(lifetime time.Duration) error {
|
||||
r.lifetime_mtx.Lock()
|
||||
defer r.lifetime_mtx.Unlock()
|
||||
if r.lifetime_timer == nil {
|
||||
// let's not support timer extend if route was not
|
||||
// first started with lifetime enabled
|
||||
return fmt.Errorf("prohibited operation")
|
||||
} else {
|
||||
var expiry time.Time
|
||||
r.lifetime_timer.Stop()
|
||||
r.lifetime = r.lifetime + lifetime
|
||||
expiry = r.lifetime_start.Add(r.lifetime)
|
||||
r.lifetime_timer.Reset(expiry.Sub(time.Now()))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ClientRoute) ResetLifetime(lifetime time.Duration) error {
|
||||
r.lifetime_mtx.Lock()
|
||||
defer r.lifetime_mtx.Unlock()
|
||||
|
Loading…
x
Reference in New Issue
Block a user