host

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//state mapings
	STATE_MAPPINGS = map[HostStatus][]HostStatus{
		Status_IDLE:       {Status_STANDBY, Status_CLOSED},
		Status_STANDBY:    {Status_READY, Status_CLOSED},
		Status_CONNECTING: {Status_READY, Status_FAIL, Status_CLOSED},
		Status_READY:      {Status_STANDBY, Status_CLOSED},
		Status_CLOSED:     {Status_IDLE, Status_STANDBY},
		Status_FAIL:       {Status_CONNECTING, Status_STANDBY},
	}

	// Errors
	ErrTRANSITION = errors.New("cannot transition to state")
	ErrOPERATION  = errors.New("cannot perform operation, already active")
)

Functions

This section is empty.

Types

type HostStat added in v0.1.0

type HostStat struct {
	ID        string `json:"id"`
	Status    string `json:"status"`
	MultiAddr string `json:"multi_addr"`
}

type HostStatus

type HostStatus string

HostStatus is the status of the host

const (
	// States
	Status_IDLE       HostStatus = "IDLE"
	Status_STANDBY    HostStatus = "STANDBY"    // Host is standby, waiting for connection
	Status_CONNECTING HostStatus = "CONNECTING" // Host is connecting
	Status_READY      HostStatus = "READY"      // Host is ready
	Status_FAIL       HostStatus = "FAILURE"    // Host failed to connect
	Status_CLOSED     HostStatus = "CLOSED"     // Host is closed
)

SNRHostStatus Definitions

func (HostStatus) Equals

func (s HostStatus) Equals(other HostStatus) bool

Equals returns true if given SNRHostStatus matches this one

func (HostStatus) IsClosed

func (s HostStatus) IsClosed() bool

IsClosed returns true if the SNRHostStatus == Status_CLOSED

func (HostStatus) IsConnecting

func (s HostStatus) IsConnecting() bool

IsConnecting returns true if the SNRHostStatus == Status_CONNECTING

func (HostStatus) IsFail

func (s HostStatus) IsFail() bool

IsFail returns true if the SNRHostStatus == Status_FAIL

func (HostStatus) IsIdle added in v0.1.2

func (s HostStatus) IsIdle() bool

IsIdle returns true if the SNRHostStatus != Status_IDLE

func (HostStatus) IsReady

func (s HostStatus) IsReady() bool

IsReady returns true if the SNRHostStatus == Status_READY

func (HostStatus) IsStandby

func (s HostStatus) IsStandby() bool

IsStandby returns true if the SNRHostStatus == Status_STANDBY

type SFSM added in v0.1.2

type SFSM struct {
	CurrentStatus HostStatus
	Chn           chan bool

	States       *[]HostStatus
	StateMapping *map[HostStatus][]HostStatus
	// contains filtered or unexported fields
}

func NewFSM added in v0.1.2

func NewFSM(ctx context.Context) *SFSM

func (SFSM) GetCurrent added in v0.1.2

func (sm SFSM) GetCurrent() string

func (*SFSM) NeedsWait added in v0.1.2

func (sfm *SFSM) NeedsWait()

NeedsWait checks if state is Resumed or Paused 0 -> Running 1 -> Paused

func (*SFSM) PauseOperation added in v0.1.2

func (fsm *SFSM) PauseOperation() error

Pause tells all of goroutines to pause execution

func (*SFSM) ResumeOperation added in v0.1.2

func (fsm *SFSM) ResumeOperation() error

Resume tells all of goroutines to resume execution

func (*SFSM) SetState added in v0.1.2

func (fsm *SFSM) SetState(s HostStatus) error

SetState sets the host status and emits the event

type SonrHost

type SonrHost interface {
	// AuthenticateMessage authenticates a message
	// AuthenticateMessage(msg proto.Message, metadata *types.Metadata) error
	// Address returns the account address of the underlying wallet for the host
	Address() string

	// Config returns the configuration of the node
	Config() *config.Config

	// Connect to a peer
	Connect(pi peer.AddrInfo) error

	// HasRouting returns true if the node has routing
	HasRouting() bool

	// Host returns the Host
	Host() host.Host

	// HostID returns the ID of the Host
	HostID() peer.ID

	// Join subsrcibes to a topic
	Join(topic string, opts ...ps.TopicOpt) (*ps.Topic, error)

	// NewStream opens a new stream to a peer
	NewStream(ctx context.Context, pid peer.ID, pids ...protocol.ID) (network.Stream, error)

	// NewTopic creates a new pubsub topic with event handler and subscription
	NewTopic(topic string, opts ...ps.TopicOpt) (*ps.Topic, *ps.TopicEventHandler, *ps.Subscription, error)

	// NeedsWait checks if state is Resumed or Paused and blocks channel if needed
	NeedsWait()

	// Ping sends a ping to a peer to check if it is alive
	Ping(id string) error

	// TODO: implement
	// Peer returns the peer of the node
	Peer() (*ct.Peer, error)

	// SignData signs the data with the private key
	SignData(data []byte) ([]byte, error)

	// Pubsub returns the pubsub of the node
	Pubsub() *ps.PubSub

	// Role returns the role of the node
	Role() config.Role

	// Router returns the routing.Router
	Router(h host.Host) (routing.PeerRouting, error)

	// Routing returns the routing.Routing
	Routing() routing.Routing

	// PrivateKey returns the ed25519 private key instance of the libp2p host
	PrivateKey() (ed25519.PrivateKey, error)

	// SendMessage sends a message to a peer
	Send(id peer.ID, p protocol.ID, data []byte) error

	// SetStreamHandler sets the handler for a protocol
	SetStreamHandler(protocol protocol.ID, handler network.StreamHandler)

	// VerifyData verifies the data signature
	VerifyData(data []byte, signature []byte, peerId peer.ID, pubKeyData []byte) error

	// Close closes the node
	Close() error

	Start() error

	Stop() error

	// Pauses tells all of goroutines to pause execution
	Pause() error

	// Resume tells all of goroutines to resume execution
	Resume() error

	Status() HostStatus
}

SonrHost returns the SonrHost for the Main Node

func NewDefaultHost

func NewDefaultHost(ctx context.Context, c *config.Config, cb common.MotorCallback) (SonrHost, error)

NewDefaultHost Creates a Sonr libp2p Host with the given config

func NewWasmHost

func NewWasmHost(ctx context.Context, c *config.Config) (SonrHost, error)

NewWasmHost Creates a Sonr libp2p Host with the given config and wasm module

Jump to

Keyboard shortcuts

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