Skip to content

Commit

Permalink
Rename SessionStatsStore to SessionStatsKeeper
Browse files Browse the repository at this point in the history
  • Loading branch information
donce committed Jan 26, 2018
1 parent b3486a2 commit d5f3270
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 45 deletions.
4 changes: 2 additions & 2 deletions client_connection/manager.go
Expand Up @@ -124,7 +124,7 @@ func statusDisconnecting() ConnectionStatus {
}

func ConfigureVpnClientFactory(mysteriumAPIClient server.Client, vpnClientRuntimeDirectory string,
signerFactory identity.SignerFactory, statsStore *bytescount.SessionStatsStore) VpnClientFactory {
signerFactory identity.SignerFactory, statsKeeper *bytescount.SessionStatsKeeper) VpnClientFactory {
return func(vpnSession session.SessionDto, id identity.Identity) (openvpn.Client, error) {
vpnConfig, err := openvpn.NewClientConfigFromString(
vpnSession.Config,
Expand All @@ -134,7 +134,7 @@ func ConfigureVpnClientFactory(mysteriumAPIClient server.Client, vpnClientRuntim
return nil, err
}

statsSaver := bytescount.NewSessionStatsSaver(statsStore)
statsSaver := bytescount.NewSessionStatsSaver(statsKeeper)
statsSender := bytescount.NewSessionStatsSender(mysteriumAPIClient, vpnSession.ID, signerFactory(id))
statsHandler := bytescount.NewCompositeStatsHandler(statsSaver, statsSender)

Expand Down
6 changes: 3 additions & 3 deletions cmd/mysterium_client/run/command.go
Expand Up @@ -44,16 +44,16 @@ func NewCommandWith(
return identity.NewSigner(keystoreInstance, id)
}

statsStore := &bytescount.SessionStatsStore{}
statsKeeper := &bytescount.SessionStatsKeeper{}

vpnClientFactory := client_connection.ConfigureVpnClientFactory(mysteriumClient, options.DirectoryRuntime, signerFactory, statsStore)
vpnClientFactory := client_connection.ConfigureVpnClientFactory(mysteriumClient, options.DirectoryRuntime, signerFactory, statsKeeper)

connectionManager := client_connection.NewManager(mysteriumClient, dialogEstablisherFactory, vpnClientFactory)

router := tequilapi.NewAPIRouter()
tequilapi_endpoints.AddRoutesForIdentities(router, identityManager, mysteriumClient, signerFactory)
ipResolver := ip.NewResolver()
tequilapi_endpoints.AddRoutesForConnection(router, connectionManager, ipResolver, statsStore)
tequilapi_endpoints.AddRoutesForConnection(router, connectionManager, ipResolver, statsKeeper)
tequilapi_endpoints.AddRoutesForProposals(router, mysteriumClient)

httpAPIServer := tequilapi.NewServer(options.TequilapiAddress, options.TequilapiPort, router)
Expand Down
16 changes: 16 additions & 0 deletions openvpn/middlewares/client/bytescount/stats_keeper.go
@@ -0,0 +1,16 @@
package bytescount

// SessionStatsKeeper keeps session stats
type SessionStatsKeeper struct {
sessionStats SessionStats
}

// Save saves session stats to keeper
func (keeper *SessionStatsKeeper) Save(stats SessionStats) {
keeper.sessionStats = stats
}

// Retrieve retrieves session stats from keeper
func (keeper *SessionStatsKeeper) Retrieve() SessionStats {
return keeper.sessionStats
}
Expand Up @@ -6,9 +6,9 @@ import (
)

func TestSessionStatsStoreWorks(t *testing.T) {
statsStore := &SessionStatsStore{}
statsKeeper := &SessionStatsKeeper{}
stats := SessionStats{BytesSent: 1, BytesReceived: 2}

statsStore.Save(stats)
assert.Equal(t, stats, statsStore.Retrieve())
statsKeeper.Save(stats)
assert.Equal(t, stats, statsKeeper.Retrieve())
}
6 changes: 3 additions & 3 deletions openvpn/middlewares/client/bytescount/stats_saver.go
@@ -1,9 +1,9 @@
package bytescount

// NewSessionStatsSaver returns stats handler, which saves stats to global stats store
func NewSessionStatsSaver(statsStore *SessionStatsStore) SessionStatsHandler {
// NewSessionStatsSaver returns stats handler, which saves stats stats keeper
func NewSessionStatsSaver(statsKeeper *SessionStatsKeeper) SessionStatsHandler {
return func(sessionStats SessionStats) error {
statsStore.Save(sessionStats)
statsKeeper.Save(sessionStats)
return nil
}
}
6 changes: 3 additions & 3 deletions openvpn/middlewares/client/bytescount/stats_saver_test.go
Expand Up @@ -6,10 +6,10 @@ import (
)

func TestNewSessionStatsSaver(t *testing.T) {
statsStore := &SessionStatsStore{}
statsKeeper := &SessionStatsKeeper{}

saver := NewSessionStatsSaver(statsStore)
saver := NewSessionStatsSaver(statsKeeper)
stats := SessionStats{BytesSent: 1, BytesReceived: 2}
saver(stats)
assert.Equal(t, stats, statsStore.Retrieve())
assert.Equal(t, stats, statsKeeper.Retrieve())
}
16 changes: 0 additions & 16 deletions openvpn/middlewares/client/bytescount/stats_store.go

This file was deleted.

20 changes: 10 additions & 10 deletions tequilapi/endpoints/connection.go
Expand Up @@ -23,16 +23,16 @@ type statusResponse struct {
}

type connectionEndpoint struct {
manager client_connection.Manager
ipResolver ip.Resolver
statsStore *bytescount.SessionStatsStore
manager client_connection.Manager
ipResolver ip.Resolver
statsKeeper *bytescount.SessionStatsKeeper
}

func NewConnectionEndpoint(manager client_connection.Manager, ipResolver ip.Resolver, statsStore *bytescount.SessionStatsStore) *connectionEndpoint {
func NewConnectionEndpoint(manager client_connection.Manager, ipResolver ip.Resolver, statsKeeper *bytescount.SessionStatsKeeper) *connectionEndpoint {
return &connectionEndpoint{
manager: manager,
ipResolver: ipResolver,
statsStore: statsStore,
manager: manager,
ipResolver: ipResolver,
statsKeeper: statsKeeper,
}
}

Expand Down Expand Up @@ -86,7 +86,7 @@ func (ce *connectionEndpoint) GetIP(writer http.ResponseWriter, request *http.Re

// GetStatistics returns statistics about current connection
func (ce *connectionEndpoint) GetStatistics(writer http.ResponseWriter, request *http.Request, params httprouter.Params) {
stats := ce.statsStore.Retrieve()
stats := ce.statsKeeper.Retrieve()
response := struct {
BytesSent int `json:"bytesSent"`
BytesReceived int `json:"bytesReceived"`
Expand All @@ -99,8 +99,8 @@ func (ce *connectionEndpoint) GetStatistics(writer http.ResponseWriter, request

// AddRoutesForConnection adds connections routes to given router
func AddRoutesForConnection(router *httprouter.Router, manager client_connection.Manager, ipResolver ip.Resolver,
statsStore *bytescount.SessionStatsStore) {
connectionEndpoint := NewConnectionEndpoint(manager, ipResolver, statsStore)
statsKeeper *bytescount.SessionStatsKeeper) {
connectionEndpoint := NewConnectionEndpoint(manager, ipResolver, statsKeeper)
router.GET("/connection", connectionEndpoint.Status)
router.PUT("/connection", connectionEndpoint.Create)
router.DELETE("/connection", connectionEndpoint.Kill)
Expand Down
10 changes: 5 additions & 5 deletions tequilapi/endpoints/connection_test.go
Expand Up @@ -47,9 +47,9 @@ func TestAddRoutesForConnectionAddsRoutes(t *testing.T) {
router := httprouter.New()
fakeManager := fakeManager{}
ipResolver := ip.NewFakeResolver("123.123.123.123")
statsStore := &bytescount.SessionStatsStore{}
statsKeeper := &bytescount.SessionStatsKeeper{}

AddRoutesForConnection(router, &fakeManager, ipResolver, statsStore)
AddRoutesForConnection(router, &fakeManager, ipResolver, statsKeeper)

tests := []struct {
method string
Expand Down Expand Up @@ -299,12 +299,12 @@ func TestGetIPEndpointReturnsErrorWhenIPDetectionFails(t *testing.T) {
}

func TestGetStatisticsEndpointReturnsStatistics(t *testing.T) {
statsStore := &bytescount.SessionStatsStore{}
statsKeeper := &bytescount.SessionStatsKeeper{}
stats := bytescount.SessionStats{BytesSent: 1, BytesReceived: 2}
statsStore.Save(stats)
statsKeeper.Save(stats)

manager := fakeManager{}
connEndpoint := NewConnectionEndpoint(&manager, nil, statsStore)
connEndpoint := NewConnectionEndpoint(&manager, nil, statsKeeper)

resp := httptest.NewRecorder()
connEndpoint.GetStatistics(resp, nil, nil)
Expand Down

0 comments on commit d5f3270

Please sign in to comment.