github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/tequilapi/contract/node.go (about)

     1  /*
     2   * Copyright (C) 2021 The "MysteriumNetwork/node" Authors.
     3   *
     4   * This program is free software: you can redistribute it and/or modify
     5   * it under the terms of the GNU General Public License as published by
     6   * the Free Software Foundation, either version 3 of the License, or
     7   * (at your option) any later version.
     8   *
     9   * This program is distributed in the hope that it will be useful,
    10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12   * GNU General Public License for more details.
    13   *
    14   * You should have received a copy of the GNU General Public License
    15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16   */
    17  
    18  package contract
    19  
    20  import (
    21  	"time"
    22  
    23  	"github.com/mysteriumnetwork/node/core/monitoring"
    24  
    25  	"github.com/shopspring/decimal"
    26  
    27  	"github.com/mysteriumnetwork/node/core/node"
    28  )
    29  
    30  // NodeStatusResponse a node status reflects monitoring agent POV on node availability
    31  // swagger:model NodeStatusResponse
    32  type NodeStatusResponse struct {
    33  	Status monitoring.Status `json:"status"`
    34  }
    35  
    36  // MonitoringAgentResponse reflects amount of connectivity statuses for each service_type.
    37  // swagger:model MonitoringAgentResponse
    38  type MonitoringAgentResponse struct {
    39  	Statuses node.MonitoringAgentStatuses `json:"statuses"`
    40  	Error    string                       `json:"error,omitempty"`
    41  }
    42  
    43  // ProviderSessionsResponse reflects a list of sessions metrics during a period of time.
    44  // swagger:model ProviderSessionsResponse
    45  type ProviderSessionsResponse struct {
    46  	Sessions []ProviderSession `json:"sessions"`
    47  }
    48  
    49  // NewProviderSessionsResponse creates response from node.SessionItem slice
    50  func NewProviderSessionsResponse(sessionItems []node.SessionItem) *ProviderSessionsResponse {
    51  	r := ProviderSessionsResponse{Sessions: []ProviderSession{}}
    52  	for _, si := range sessionItems {
    53  		earningsDecimalEther, err := decimal.NewFromString(si.Earning)
    54  		if err != nil {
    55  			earningsDecimalEther = decimal.Zero
    56  		}
    57  
    58  		r.Sessions = append(r.Sessions, ProviderSession{
    59  			ID:               si.ID,
    60  			ConsumerCountry:  si.ConsumerCountry,
    61  			ServiceType:      si.ServiceType,
    62  			DurationSeconds:  si.Duration,
    63  			StartedAt:        time.Unix(si.StartedAt, 0).Format(time.RFC3339),
    64  			Earnings:         NewTokensFromDecimal(earningsDecimalEther),
    65  			TransferredBytes: si.Transferred,
    66  		})
    67  	}
    68  	return &r
    69  }
    70  
    71  // ProviderTransferredDataResponse reflects a number of bytes transferred by provider during a period of time.
    72  // swagger:model ProviderTransferredDataResponse
    73  type ProviderTransferredDataResponse struct {
    74  	Bytes int `json:"transferred_data_bytes"`
    75  }
    76  
    77  // ProviderSessionsCountResponse reflects a number of sessions during a period of time.
    78  // swagger:model ProviderSessionsCountResponse
    79  type ProviderSessionsCountResponse struct {
    80  	Count int `json:"count"`
    81  }
    82  
    83  // ProviderConsumersCountResponse reflects a number of unique consumers served during a period of time.
    84  // swagger:model ProviderConsumersCountResponse
    85  type ProviderConsumersCountResponse struct {
    86  	Count int `json:"count"`
    87  }
    88  
    89  // ProviderSeriesItem represents a general data series item
    90  type ProviderSeriesItem struct {
    91  	Value     string `json:"value"`
    92  	Timestamp int64  `json:"timestamp"`
    93  }
    94  
    95  // ProviderEarningsSeriesResponse reflects a earnings series metrics during a period of time.
    96  // swagger:model ProviderEarningsSeriesResponse
    97  type ProviderEarningsSeriesResponse struct {
    98  	Data []ProviderSeriesItem `json:"data"`
    99  }
   100  
   101  // ProviderSessionsSeriesResponse reflects a sessions data series metrics during a period of time.
   102  // swagger:model ProviderSessionsSeriesResponse
   103  type ProviderSessionsSeriesResponse struct {
   104  	Data []ProviderSeriesItem `json:"data"`
   105  }
   106  
   107  // ProviderTransferredDataSeriesResponse reflects a transferred bytes data series metrics during a period of time.
   108  // swagger:model ProviderTransferredDataSeriesResponse
   109  type ProviderTransferredDataSeriesResponse struct {
   110  	Data []ProviderSeriesItem `json:"data"`
   111  }
   112  
   113  // ActivityStatsResponse reflects a node activity stats.
   114  // swagger:model ActivityStatsResponse
   115  type ActivityStatsResponse struct {
   116  	Online float64 `json:"online_percent"`
   117  	Active float64 `json:"active_percent"`
   118  }
   119  
   120  // QualityInfoResponse reflects a node quality.
   121  // swagger:model QualityInfoResponse
   122  type QualityInfoResponse struct {
   123  	Quality float64 `json:"quality"`
   124  }
   125  
   126  // ProviderSession contains provided session information.
   127  // swagger:model ProviderSession
   128  type ProviderSession struct {
   129  	ID               string `json:"id"`
   130  	ConsumerCountry  string `json:"consumer_country"`
   131  	ServiceType      string `json:"service_type"`
   132  	DurationSeconds  int64  `json:"duration_seconds"`
   133  	StartedAt        string `json:"started_at"`
   134  	Earnings         Tokens `json:"earnings"`
   135  	TransferredBytes int64  `json:"transferred_bytes"`
   136  }
   137  
   138  // LatestReleaseResponse latest release info
   139  // swagger:model LatestReleaseResponse
   140  type LatestReleaseResponse struct {
   141  	Version string `json:"version"`
   142  }
   143  
   144  // EarningsPerServiceResponse contains information about earnings per service
   145  // swagger:model EarningsPerServiceResponse
   146  type EarningsPerServiceResponse struct {
   147  	EarningsPublic        Tokens `json:"public_tokens"`
   148  	EarningsVPN           Tokens `json:"data_transfer_tokens"`
   149  	EarningsScraping      Tokens `json:"scraping_tokens"`
   150  	EarningsDVPN          Tokens `json:"dvpn_tokens"`
   151  	EarningsTotal         Tokens `json:"total_tokens"`
   152  	TotalEarningsPublic   Tokens `json:"total_public_tokens"`
   153  	TotalEarningsVPN      Tokens `json:"total_data_transfer_tokens"`
   154  	TotalEarningsScraping Tokens `json:"total_scraping_tokens"`
   155  	TotalEarningsDVPN     Tokens `json:"total_dvpn_tokens"`
   156  }