github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/core/connection/interface.go (about)

     1  /*
     2   * Copyright (C) 2017 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 connection
    19  
    20  import (
    21  	"context"
    22  
    23  	"github.com/ethereum/go-ethereum/common"
    24  
    25  	"github.com/mysteriumnetwork/node/core/connection/connectionstate"
    26  	"github.com/mysteriumnetwork/node/identity"
    27  )
    28  
    29  // ConsumerConfig are the parameters used for the initiation of connection
    30  type ConsumerConfig interface{}
    31  
    32  // Connection represents a connection
    33  type Connection interface {
    34  	Start(context.Context, ConnectOptions) error
    35  	Reconnect(context.Context, ConnectOptions) error
    36  	Stop()
    37  	GetConfig() (ConsumerConfig, error)
    38  	State() <-chan connectionstate.State
    39  	Statistics() (connectionstate.Statistics, error)
    40  }
    41  
    42  // StateChannel is the channel we receive state change events on
    43  type StateChannel chan connectionstate.State
    44  
    45  // Manager interface provides methods to manage connection
    46  type Manager interface {
    47  	// Connect creates new connection from given consumer to provider, reports error if connection already exists
    48  	Connect(consumerID identity.Identity, hermesID common.Address, proposal ProposalLookup, params ConnectParams) error
    49  	// Status queries current status of connection
    50  	Status() connectionstate.Status
    51  	// Stats provides connection statistics information.
    52  	Stats() connectionstate.Statistics
    53  	// Disconnect closes established connection, reports error if no connection
    54  	Disconnect() error
    55  	// CheckChannel checks if current session channel is alive, returns error on failed keep-alive ping
    56  	CheckChannel(context.Context) error
    57  	// Reconnect reconnects current session
    58  	Reconnect()
    59  }
    60  
    61  // MultiManager interface provides methods to manage connection
    62  type MultiManager interface {
    63  	// Connect creates new connection from given consumer to provider, reports error if connection already exists
    64  	Connect(consumerID identity.Identity, hermesID common.Address, proposal ProposalLookup, params ConnectParams) error
    65  	// Status queries current status of connection
    66  	Status(n int) connectionstate.Status
    67  	// Stats provides connection statistics information.
    68  	Stats(n int) connectionstate.Statistics
    69  	// Disconnect closes established connection, reports error if no connection
    70  	Disconnect(n int) error
    71  	// CheckChannel checks if current session channel is alive, returns error on failed keep-alive ping
    72  	CheckChannel(context.Context) error
    73  	// Reconnect reconnects current session
    74  	Reconnect(n int)
    75  }