github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/consumer/session/session.go (about) 1 /* 2 * Copyright (C) 2018 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 session 19 20 import ( 21 "math/big" 22 "time" 23 24 "github.com/mysteriumnetwork/node/identity" 25 node_session "github.com/mysteriumnetwork/node/session" 26 ) 27 28 const ( 29 // StatusNew means that newly created session object is written to storage 30 StatusNew = "New" 31 // StatusCompleted means that session object is updated on connection disconnect event 32 StatusCompleted = "Completed" 33 ) 34 35 const ( 36 // DirectionConsumed marks traffic transaction where node participated as consumer. 37 DirectionConsumed = "Consumed" 38 // DirectionProvided marks traffic transaction where node participated as provider. 39 DirectionProvided = "Provided" 40 ) 41 42 // History holds structure for saving session history 43 type History struct { 44 SessionID node_session.ID `storm:"id"` 45 Direction string 46 ConsumerID identity.Identity 47 HermesID string 48 ProviderID identity.Identity 49 ServiceType string 50 ConsumerCountry string 51 ProviderCountry string 52 DataSent uint64 53 DataReceived uint64 54 Tokens *big.Int 55 56 IPType string 57 58 Status string 59 Started time.Time 60 Updated time.Time 61 } 62 63 // GetDuration returns delta in seconds (TimeUpdated - TimeStarted) 64 func (se *History) GetDuration() time.Duration { 65 ended := se.Updated 66 if ended.IsZero() { 67 ended = time.Now() 68 } 69 return ended.Sub(se.Started) 70 }