session

package
v0.0.0-...-365054f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2024 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StatusNew means that newly created session object is written to storage
	StatusNew = "New"
	// StatusCompleted means that session object is updated on connection disconnect event
	StatusCompleted = "Completed"
)
View Source
const (
	// DirectionConsumed marks traffic transaction where node participated as consumer.
	DirectionConsumed = "Consumed"
	// DirectionProvided marks traffic transaction where node participated as provider.
	DirectionProvided = "Provided"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	StartedFrom *time.Time
	StartedTo   *time.Time
	Direction   *string
	ConsumerID  *identity.Identity
	HermesID    *string
	ProviderID  *identity.Identity
	ServiceType *string
	Status      *string
}

Filter defines all flags for session filtering in session storage.

func NewFilter

func NewFilter() *Filter

NewFilter creates instance of filter.

func (*Filter) SetConsumerID

func (f *Filter) SetConsumerID(id identity.Identity) *Filter

SetConsumerID filters fetched sessions by consumer.

func (*Filter) SetDirection

func (f *Filter) SetDirection(direction string) *Filter

SetDirection filters fetched sessions by direction.

func (*Filter) SetHermesID

func (f *Filter) SetHermesID(hermesID string) *Filter

SetHermesID filters fetched sessions by hermes.

func (*Filter) SetProviderID

func (f *Filter) SetProviderID(id identity.Identity) *Filter

SetProviderID filters fetched sessions by provider.

func (*Filter) SetServiceType

func (f *Filter) SetServiceType(serviceType string) *Filter

SetServiceType filters fetched sessions by service type.

func (*Filter) SetStartedFrom

func (f *Filter) SetStartedFrom(from time.Time) *Filter

SetStartedFrom filters fetched sessions from given time.

func (*Filter) SetStartedTo

func (f *Filter) SetStartedTo(to time.Time) *Filter

SetStartedTo filters fetched sessions to given time.

func (*Filter) SetStatus

func (f *Filter) SetStatus(status string) *Filter

SetStatus filters fetched sessions by status.

type History

type History struct {
	SessionID       node_session.ID `storm:"id"`
	Direction       string
	ConsumerID      identity.Identity
	HermesID        string
	ProviderID      identity.Identity
	ServiceType     string
	ConsumerCountry string
	ProviderCountry string
	DataSent        uint64
	DataReceived    uint64
	Tokens          *big.Int

	IPType string

	Status  string
	Started time.Time
	Updated time.Time
}

History holds structure for saving session history

func (*History) GetDuration

func (se *History) GetDuration() time.Duration

GetDuration returns delta in seconds (TimeUpdated - TimeStarted)

type Stats

type Stats struct {
	Count           int
	ConsumerCounts  map[identity.Identity]int
	SumDataSent     uint64
	SumDataReceived uint64
	SumDuration     time.Duration
	SumTokens       *big.Int
}

Stats holds structure of aggregate session statistics.

func NewStats

func NewStats() Stats

NewStats initiates zero Stats instance.

func (*Stats) Add

func (s *Stats) Add(session History)

Add accumulates given session to statistics.

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

Storage contains functions for storing, getting session objects.

func NewSessionStorage

func NewSessionStorage(storage *boltdb.Bolt) *Storage

NewSessionStorage creates session repository with given dependencies.

func (*Storage) GetAll

func (repo *Storage) GetAll() ([]History, error)

GetAll returns array of all sessions.

func (*Storage) List

func (repo *Storage) List(filter *Filter) (result []History, err error)

List retrieves stored entries.

func (*Storage) Stats

func (repo *Storage) Stats(filter *Filter) (result Stats, err error)

Stats fetches aggregated statistics to Filter.Stats.

func (*Storage) StatsByDay

func (repo *Storage) StatsByDay(filter *Filter) (result map[time.Time]Stats, err error)

StatsByDay retrieves aggregated statistics grouped by day to Filter.StatsByDay.

func (*Storage) Subscribe

func (repo *Storage) Subscribe(bus eventbus.Subscriber) error

Subscribe subscribes to relevant events of event bus.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL