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

     1  /*
     2   * Copyright (C) 2019 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 event
    19  
    20  import (
    21  	"math/big"
    22  	"time"
    23  
    24  	"github.com/ethereum/go-ethereum/common"
    25  
    26  	"github.com/mysteriumnetwork/node/identity"
    27  	"github.com/mysteriumnetwork/node/market"
    28  )
    29  
    30  const (
    31  	// AppTopicSession represents the session change topic.
    32  	AppTopicSession = "Session change"
    33  	// AppTopicDataTransferred represents the data transfer topic.
    34  	AppTopicDataTransferred = "Session data transferred"
    35  	// AppTopicTokensEarned is a topic for publish events about tokens earned as a provider.
    36  	AppTopicTokensEarned = "SessionTokensEarned"
    37  )
    38  
    39  // AppEventDataTransferred represents the data transfer event
    40  type AppEventDataTransferred struct {
    41  	ID       string
    42  	Up, Down uint64
    43  }
    44  
    45  // AppEventTokensEarned is an update on tokens earned during current session
    46  type AppEventTokensEarned struct {
    47  	ProviderID identity.Identity
    48  	SessionID  string
    49  	Total      *big.Int
    50  }
    51  
    52  // Status represents the different actions that might happen on a session
    53  type Status string
    54  
    55  const (
    56  	// CreatedStatus indicates a session has been created
    57  	CreatedStatus Status = "CreatedStatus"
    58  	// RemovedStatus indicates a session has been removed
    59  	RemovedStatus Status = "RemovedStatus"
    60  	// AcknowledgedStatus indicates a session has been reported as a success from consumer side
    61  	AcknowledgedStatus Status = "AcknowledgedStatus"
    62  )
    63  
    64  // AppEventSession represents the session change payload
    65  type AppEventSession struct {
    66  	Status  Status
    67  	Service ServiceContext
    68  	Session SessionContext
    69  }
    70  
    71  // ServiceContext holds service context metadata
    72  type ServiceContext struct {
    73  	ID string
    74  }
    75  
    76  // SessionContext holds session context metadata
    77  type SessionContext struct {
    78  	ID               string
    79  	StartedAt        time.Time
    80  	ConsumerID       identity.Identity
    81  	ConsumerLocation market.Location
    82  	HermesID         common.Address
    83  	Proposal         market.ServiceProposal
    84  }