changed the unit of lifetimestart to a millisecond
Updated to fire route updated upon lifetime extension
This commit is contained in:
parent
b41df682e1
commit
9c3a4d0c17
@ -38,7 +38,7 @@ type json_in_client_route struct {
|
||||
ServerPeerOption string `json:"server-peer-option"`
|
||||
|
||||
// the following two fields in the input structure is the requested values.
|
||||
// the actual values are returned in json_out_clinet_route and may be different from the requested ones
|
||||
// the actual values are returned in json_out_client_route and may be different from the requested ones
|
||||
ServerPeerSvcAddr string `json:"server-peer-svc-addr"` // requested listening address on the server side - not actual
|
||||
ServerPeerSvcNet string `json:"server-peer-svc-net"` // requested permitted network in prefix notation - not actual
|
||||
|
||||
@ -73,7 +73,7 @@ type json_out_client_route struct {
|
||||
ServerPeerSvcNet string `json:"server-peer-svc-net"`
|
||||
|
||||
Lifetime string `json:"lifetime"`
|
||||
LifetimeStart int64 `json:"lifetime-start"`
|
||||
LifetimeStartMilli int64 `json:"lifetime-start-milli"`
|
||||
CreatedMilli int64 `json:"created-milli"`
|
||||
}
|
||||
|
||||
@ -287,7 +287,7 @@ func (ctl *client_ctl_client_conns) ServeHTTP(w http.ResponseWriter, req *http.R
|
||||
ServerPeerSvcNet: r.ServerPeerSvcNet.Get(),
|
||||
ServerPeerOption: r.ServerPeerOption.String(),
|
||||
Lifetime: DurationToSecString(lftdur),
|
||||
LifetimeStart: lftsta.Unix(),
|
||||
LifetimeStartMilli : lftsta.UnixMilli(),
|
||||
CreatedMilli: r.Created.UnixMilli(),
|
||||
})
|
||||
}
|
||||
@ -405,7 +405,7 @@ func (ctl *client_ctl_client_conns_id) ServeHTTP(w http.ResponseWriter, req *htt
|
||||
ServerPeerSvcNet: r.ServerPeerSvcNet.Get(),
|
||||
ServerPeerOption: r.ServerPeerOption.String(),
|
||||
Lifetime: DurationToSecString(lftdur),
|
||||
LifetimeStart: lftsta.Unix(),
|
||||
LifetimeStartMilli : lftsta.UnixMilli(),
|
||||
CreatedMilli: r.Created.UnixMilli(),
|
||||
})
|
||||
}
|
||||
@ -486,7 +486,7 @@ func (ctl *client_ctl_client_conns_id_routes) ServeHTTP(w http.ResponseWriter, r
|
||||
ServerPeerSvcNet: r.ServerPeerSvcNet.Get(),
|
||||
ServerPeerOption: r.ServerPeerOption.String(),
|
||||
Lifetime: DurationToSecString(lftdur),
|
||||
LifetimeStart: lftsta.Unix(),
|
||||
LifetimeStartMilli : lftsta.UnixMilli(),
|
||||
CreatedMilli: r.Created.UnixMilli(),
|
||||
})
|
||||
}
|
||||
@ -605,7 +605,7 @@ func (ctl *client_ctl_client_conns_id_routes_id) ServeHTTP(w http.ResponseWriter
|
||||
ServerPeerSvcNet: r.ServerPeerSvcNet.Get(),
|
||||
ServerPeerOption: r.ServerPeerOption.String(),
|
||||
Lifetime: DurationToSecString(lftdur),
|
||||
LifetimeStart: lftsta.Unix(),
|
||||
LifetimeStartMilli : lftsta.UnixMilli(),
|
||||
CreatedMilli: r.Created.UnixMilli(),
|
||||
})
|
||||
if err != nil { goto oops }
|
||||
@ -694,7 +694,8 @@ func (ctl *client_ctl_client_conns_id_routes_spsp) ServeHTTP(w http.ResponseWrit
|
||||
ServerPeerSvcNet: r.ServerPeerSvcNet.Get(),
|
||||
ServerPeerOption: r.ServerPeerOption.String(),
|
||||
Lifetime: DurationToSecString(lftdur),
|
||||
LifetimeStart: lftsta.Unix(),
|
||||
LifetimeStartMilli : lftsta.UnixMilli(),
|
||||
CreatedMilli: r.Created.UnixMilli(),
|
||||
})
|
||||
if err != nil { goto oops }
|
||||
|
||||
@ -957,7 +958,7 @@ func (ctl *client_ctl_client_routes) ServeHTTP(w http.ResponseWriter, req *http.
|
||||
ServerPeerSvcNet: r.ServerPeerSvcNet.Get(),
|
||||
ServerPeerOption: r.ServerPeerOption.String(),
|
||||
Lifetime: DurationToSecString(lftdur),
|
||||
LifetimeStart: lftsta.Unix(),
|
||||
LifetimeStartMilli : lftsta.UnixMilli(),
|
||||
CreatedMilli: r.Created.UnixMilli(),
|
||||
})
|
||||
}
|
||||
|
12
client.go
12
client.go
@ -364,10 +364,10 @@ func (r *ClientRoute) FindClientPeerConnById(peer_id PeerId) *ClientPeerConn {
|
||||
|
||||
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
|
||||
r.lifetime_mtx.Unlock()
|
||||
return fmt.Errorf("prohibited operation")
|
||||
} else {
|
||||
var expiry time.Time
|
||||
@ -376,16 +376,19 @@ func (r *ClientRoute) ExtendLifetime(lifetime time.Duration) error {
|
||||
expiry = r.LifetimeStart.Add(r.Lifetime)
|
||||
r.lifetime_timer.Reset(expiry.Sub(time.Now()))
|
||||
if r.cts.C.route_persister != nil { r.cts.C.route_persister.Save(r.cts, r) }
|
||||
r.lifetime_mtx.Unlock()
|
||||
|
||||
r.cts.C.FireRouteEvent(CLIENT_EVENT_ROUTE_UPDATED, r)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ClientRoute) ResetLifetime(lifetime time.Duration) error {
|
||||
r.lifetime_mtx.Lock()
|
||||
defer r.lifetime_mtx.Unlock()
|
||||
if r.lifetime_timer == nil {
|
||||
// let's not support timer reset if route was not
|
||||
// first started with lifetime enabled
|
||||
r.lifetime_mtx.Unlock()
|
||||
return fmt.Errorf("prohibited operation")
|
||||
} else {
|
||||
r.lifetime_timer.Stop()
|
||||
@ -393,6 +396,9 @@ func (r *ClientRoute) ResetLifetime(lifetime time.Duration) error {
|
||||
r.LifetimeStart = time.Now()
|
||||
r.lifetime_timer.Reset(lifetime)
|
||||
if r.cts.C.route_persister != nil { r.cts.C.route_persister.Save(r.cts, r) }
|
||||
r.lifetime_mtx.Unlock()
|
||||
|
||||
r.cts.C.FireRouteEvent(CLIENT_EVENT_ROUTE_UPDATED, r)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -2139,7 +2145,7 @@ func (c *Client) FireRouteEvent(event_kind ClientEventKind, r *ClientRoute) {
|
||||
ServerPeerSvcNet: r.ServerPeerSvcNet.Get(),
|
||||
ServerPeerOption: r.ServerPeerOption.String(),
|
||||
Lifetime: DurationToSecString(lftdur),
|
||||
LifetimeStart: lftsta.Unix(),
|
||||
LifetimeStartMilli: lftsta.UnixMilli(),
|
||||
CreatedMilli: r.Created.UnixMilli(),
|
||||
},
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user