Skip to content

Commit

Permalink
Add connection statistics to "status" CLI command
Browse files Browse the repository at this point in the history
  • Loading branch information
donce committed Jan 30, 2018
1 parent 1b74faa commit 79c3b5b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
14 changes: 11 additions & 3 deletions cmd/mysterium_client/cli/command.go
Expand Up @@ -202,11 +202,19 @@ func (c *Command) status() {
status, err := c.tequilapi.Status()
if err != nil {
warn(err)
return
} else {
info("Status:", status.Status)
info("SID:", status.SessionId)
}

info("Status:", status.Status)
info("SID:", status.SessionId)
statistics, err := c.tequilapi.ConnectionStatistics()
if err != nil {
warn(err)
} else {
info(fmt.Sprintf("Connection duration: %ds", statistics.DurationSeconds))
info("Bytes sent:", statistics.BytesSent)
info("Bytes received:", statistics.BytesReceived)
}
}

func (c *Command) ip() {
Expand Down
14 changes: 13 additions & 1 deletion tequilapi/client/client.go
Expand Up @@ -106,6 +106,18 @@ func (client *Client) Disconnect() (err error) {
return nil
}

// ConnectionStatistics returns statistics about current connection
func (client *Client) ConnectionStatistics() (statistics StatisticsDTO, err error) {
response, err := client.http.Get("connection/statistics", url.Values{})
if err != nil {
return
}
defer response.Body.Close()

err = parseResponseJson(response, &statistics)
return
}

// Status returns connection status
func (client *Client) Status() (status StatusDto, err error) {
response, err := client.http.Get("connection", url.Values{})
Expand All @@ -115,7 +127,7 @@ func (client *Client) Status() (status StatusDto, err error) {
defer response.Body.Close()

err = parseResponseJson(response, &status)
return status, err
return
}

// GetIP returns public ip
Expand Down
7 changes: 7 additions & 0 deletions tequilapi/client/dto.go
Expand Up @@ -6,6 +6,13 @@ type StatusDto struct {
SessionId string `json:"sessionId"`
}

// StatisticsDTO holds statistics about connection
type StatisticsDTO struct {
BytesSent int `json:"bytesSent"`
BytesReceived int `json:"bytesReceived"`
DurationSeconds int `json:"durationSeconds"`
}

// IdentityDto holds identity address
type IdentityDto struct {
Address string `json:"id"`
Expand Down

0 comments on commit 79c3b5b

Please sign in to comment.