Skip to content

Commit

Permalink
Introduce option for reducing session length for testing purposes (#141)
Browse files Browse the repository at this point in the history
* Introduce option for reducing session length for testing purposes

* Remove buggy field
  • Loading branch information
RandoMan70 committed Jun 29, 2023
1 parent f74d330 commit bd012af
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/spf13/afero v1.8.0
github.com/stretchr/testify v1.8.1
github.com/vishvananda/netlink v1.1.0
github.com/vpnhouse/api v0.0.0-20230116104647-6e8abecfee64
github.com/vpnhouse/api v0.0.0-20230605051533-cf764d85e33c
github.com/vpnhouse/iprose-go v0.0.1-rc1
go.etcd.io/etcd/client/v3 v3.5.2
go.uber.org/multierr v1.6.0
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,12 @@ github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df h1:OviZH7qLw/7Zo
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
github.com/vpnhouse/api v0.0.0-20230116104647-6e8abecfee64 h1:dTTwLsC00oJLMqlT9LP4iK2bcmJbRnkANEpj1YyNplI=
github.com/vpnhouse/api v0.0.0-20230116104647-6e8abecfee64/go.mod h1:qeAZBOFAiz7FiTG49UremjHQExCUPui2tTdn1NMDn1s=
github.com/vpnhouse/api v0.0.0-20230602093917-1c4a6755eea1 h1:u6sHXNd4XDsWF3L+EpCEvySt7Vojrp3NEX7rw1DUAAM=
github.com/vpnhouse/api v0.0.0-20230602093917-1c4a6755eea1/go.mod h1:qeAZBOFAiz7FiTG49UremjHQExCUPui2tTdn1NMDn1s=
github.com/vpnhouse/api v0.0.0-20230602144934-6c3ffdc09ae8 h1:XrZRGa1/pLotthLKJBSGIQKn1DrnyY/QdTf0qxSSGzw=
github.com/vpnhouse/api v0.0.0-20230602144934-6c3ffdc09ae8/go.mod h1:qeAZBOFAiz7FiTG49UremjHQExCUPui2tTdn1NMDn1s=
github.com/vpnhouse/api v0.0.0-20230605051533-cf764d85e33c h1:InguOdXtcMuFcAv1YM4tqQOLt9eYorMK9a88+BFygNo=
github.com/vpnhouse/api v0.0.0-20230605051533-cf764d85e33c/go.mod h1:qeAZBOFAiz7FiTG49UremjHQExCUPui2tTdn1NMDn1s=
github.com/vpnhouse/iprose-go v0.0.0-20230427080607-e75f4c4f2077 h1:nNuldy4M/vmKF8JPV13Wc+2lXYvHqEPsaGPgSoM2zc8=
github.com/vpnhouse/iprose-go v0.0.0-20230427080607-e75f4c4f2077/go.mod h1:M+O35XTems9zYUHBpCw0scPBjQwUuXHcyOI7yn915MU=
github.com/vpnhouse/iprose-go v0.0.0-20230427103008-23a0a6b02ba7 h1:LidniN4vxSutnupGW3ystgumTqRGoqR0+t8p0Nj1huU=
Expand Down
11 changes: 8 additions & 3 deletions internal/httpapi/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (tun *TunnelAPI) ClientConnect(w http.ResponseWriter, r *http.Request) {
// Prepare openapi peer representation
oPeer := adminAPI.Peer{
InfoWireguard: oConnectRequest.InfoWireguard,
Expires: tun.getExpiration(),
Expires: tun.getExpiration(oConnectRequest.ExpireSeconds),
Claims: &claimsString,
Identifiers: oIdentifiers,
}
Expand Down Expand Up @@ -216,7 +216,7 @@ func (tun *TunnelAPI) ClientPing(w http.ResponseWriter, r *http.Request) {
return nil, err
}

if err := tun.manager.UpdatePeerExpiration(identifiers, tun.getExpiration()); err != nil {
if err := tun.manager.UpdatePeerExpiration(identifiers, tun.getExpiration(nil)); err != nil {
return nil, err
}

Expand Down Expand Up @@ -292,9 +292,14 @@ func (tun *TunnelAPI) extractPeerActionInfo(r *http.Request) (*types.PeerIdentif
return identifiers, claims, nil
}

func (tun *TunnelAPI) getExpiration() *time.Time {
func (tun *TunnelAPI) getExpiration(suggestedSeconds *int) *time.Time {
settings := tun.runtime.Settings.GetPublicAPIConfig()
expiresSeconds := settings.PingInterval + settings.PeerTTL

if suggestedSeconds != nil && *suggestedSeconds < expiresSeconds {
expiresSeconds = *suggestedSeconds
}

expires := time.Now().Add(time.Second * time.Duration(expiresSeconds))
return &expires
}

0 comments on commit bd012af

Please sign in to comment.