application

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2025 License: MIT Imports: 35 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	DefaultAppStatusPublishDuration = 15 * 60 * time.Second
)
View Source
const (
	DefaultAppStatusSyncDuration = 30 * time.Second
)
View Source
const (
	ProtoTagEcApp = "/em-app"
)
View Source
const (
	SyncAppPeerClientLoggerName = "sync-app-peer-client"
)

Variables

This section is empty.

Functions

func Call

func Call(clientHost host.Host, protoTag string, call *EdgeCall) ([]byte, error)

func CallWithFrom

func CallWithFrom(clientHost host.Host, protoTag string, call *EdgeCall, from types.Address) ([]byte, error)

func WriteSignedResponse

func WriteSignedResponse(w http.ResponseWriter, info []byte, endpoint *Endpoint)

Types

type AppPeer

type AppPeer struct {
	// identifier
	ID string
	// name
	Name string
	// relay string
	Relay string
	// addr string
	Addr string
	// app origin name string
	AppOrigin string

	// ai model hash string
	ModelHash string
	// mac addr
	Mac string
	// memory info
	MemInfo string
	// cpu info
	CpuInfo string

	// peer's distance
	Distance *big.Int
	// app startup time
	Starup_time uint64
	// app uptime
	Uptime uint64
	// amount of slots currently occupying the app
	Guage_height uint64
	// max limit
	Guage_max uint64
	// average e power value
	AveragePower float32
	//gpu info
	GpuInfo string
	// version
	Version string
}

func (*AppPeer) IsBetter

func (p *AppPeer) IsBetter(t *AppPeer) bool

type Application

type Application struct {
	Name    string
	Tag     string
	Version string
	PeerID  peer.ID

	// ip4 addr string
	IpAddr string
	// ai app origin name
	AppOrigin string
	// ai model hash string
	ModelHash string
	// mac addr
	Mac string
	// memory info
	MemInfo string
	// cpu info
	CpuInfo string
	// gpu info
	GpuInfo string

	// app startup time
	StartupTime uint64
	// app uptime
	Uptime uint64
	// amount of slots currently occupying the app
	GuageHeight uint64
	// max limit
	GuageMax uint64
	// average e power value
	AveragePower float32
	// relay host
	RelayHost string
	// proxy port of relay
	RelayProxyPort uint64
}

func (*Application) Copy

func (a *Application) Copy() *Application

type ApplicationStore

type ApplicationStore interface {
	// ApplicationStore returns the application of endpoint
	GetEndpointApplication() *Application
}

type EdgeCall

type EdgeCall struct {
	PeerId   string          `json:"peerId"`
	Endpoint string          `json:"endpoint"`
	Input    json.RawMessage `json:"input"`
}

func DecodeEdgeCallFromInterface

func DecodeEdgeCallFromInterface(i interface{}) (*EdgeCall, error)

func (*EdgeCall) Copy

func (e *EdgeCall) Copy() *EdgeCall

type Endpoint

type Endpoint struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewApplicationEndpoint

func NewApplicationEndpoint(
	logger hclog.Logger,
	privateKey *ecdsa.PrivateKey,
	srvHost host.Host,
	name string,
	appUrl string,
	appPort uint64,
	version string) (*Endpoint, error)

func (*Endpoint) AddHandler

func (e *Endpoint) AddHandler(url string, handler func(w http.ResponseWriter, r *http.Request))

func (*Endpoint) Close

func (e *Endpoint) Close()

func (*Endpoint) GetEndpointApplication

func (e *Endpoint) GetEndpointApplication() *Application

func (*Endpoint) GetHandlerList

func (e *Endpoint) GetHandlerList() []string

func (*Endpoint) SetAppOrigin

func (e *Endpoint) SetAppOrigin(appOrigin string)

func (*Endpoint) SetSigner

func (e *Endpoint) SetSigner(s proof.Signer)

SetSigner sets the signer the endpoint will use to validate an edge call response's signature.

func (*Endpoint) SubscribeEvents

func (e *Endpoint) SubscribeEvents() Subscription

SubscribeEvents returns a application event subscription

type EndpointHandler

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

func (*EndpointHandler) AddHandler

func (h *EndpointHandler) AddHandler(url string, handler func(w http.ResponseWriter, r *http.Request))

func (*EndpointHandler) ServeHTTP

func (h *EndpointHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Event

type Event struct {
	// New Application
	NewApp []*Application

	// Type is the type of event
	Type EventType

	// Source is the source that generated the blocks for the event
	// right now it can be either the Sealer or the Syncer
	Source string
}

Event is the application event that gets passed to the listeners

func (*Event) AddNewApp

func (e *Event) AddNewApp(newApp *Application)

AddNewHeader appends a header to the event's NewChain array

func (*Event) LatestApp

func (e *Event) LatestApp() *Application

Header returns the latest block header for the event

type EventType

type EventType int
const (
	EventHead  EventType = iota // New head event
	EventReorg                  // Chain reorganization event
	EventFork                   // Chain fork event
)

type MockSubscription

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

func NewMockSubscription

func NewMockSubscription() *MockSubscription

func (*MockSubscription) Close

func (m *MockSubscription) Close()

func (*MockSubscription) GetEvent

func (m *MockSubscription) GetEvent() *Event

func (*MockSubscription) GetEventCh

func (m *MockSubscription) GetEventCh() chan *Event

func (*MockSubscription) Push

func (m *MockSubscription) Push(e *Event)

type Network

type Network interface {
	// AddrInfo returns Network Info
	AddrInfo() *peer.AddrInfo
	// RegisterProtocol registers gRPC service
	RegisterProtocol(string, network.Protocol)
	// Peers returns current connected peers
	Peers() []*network.PeerConnInfo
	// SubscribeCh returns a channel of peer event
	SubscribeCh(context.Context) (<-chan *event.PeerEvent, error)
	// GetPeerDistance returns the distance between the node and given peer
	GetPeerDistance(peer.ID) *big.Int
	// NewProtoConnection opens up a new stream on the set protocol to the peer,
	// and returns a reference to the connection
	NewProtoConnection(protocol string, peerID peer.ID) (*rawGrpc.ClientConn, error)
	// NewTopic Creates New Topic for gossip
	NewTopic(protoID string, obj proto.Message) (*network.Topic, error)
	// IsConnected returns the node is connecting to the peer associated with the given ID
	IsConnected(peerID peer.ID) bool
	// SaveProtocolStream saves stream
	SaveProtocolStream(protocol string, stream *rawGrpc.ClientConn, peerID peer.ID)
	// CloseProtocolStream closes stream
	CloseProtocolStream(protocol string, peerID peer.ID) error
}

type PeerMap

type PeerMap struct {
	sync.Map
}

func NewPeerMap

func NewPeerMap(peers []*AppPeer) *PeerMap

func (*PeerMap) BestPeer

func (m *PeerMap) BestPeer(skipMap map[string]bool) *AppPeer

BestPeer returns the top of heap

func (*PeerMap) Get

func (m *PeerMap) Get(id string) *AppPeer

func (*PeerMap) Put

func (m *PeerMap) Put(peers ...*AppPeer)

func (*PeerMap) Remove

func (m *PeerMap) Remove(peerID peer.ID)

Remove removes a peer from heap if it exists

type Subscription

type Subscription interface {
	GetEventCh() chan *Event
	GetEvent() *Event
	Close()
}

Subscription is the application subscription interface

type SyncAppPeerClient

type SyncAppPeerClient interface {
	// Start processes for SyncAppPeerClient
	Start(topicSubFlag bool) error
	// Close terminates running processes for SyncAppPeerClient
	Close()
	// GetPeerStatus fetches peer status
	GetPeerStatus(id peer.ID) (*AppPeer, error)
	// GetPeerData fetches peer data
	GetPeerData(peerID peer.ID, dataHash string, timeout time.Duration) (map[string][]byte, error)
	// GetConnectedPeerStatuses fetches the statuses of all connecting peers
	GetConnectedPeerStatuses() []*AppPeer
	// GetPeerStatusUpdateCh returns a channel of peer's status update
	GetPeerStatusUpdateCh() <-chan *AppPeer
	// GetPeerConnectionUpdateEventCh returns peer's connection change event
	GetPeerConnectionUpdateEventCh() <-chan *event.PeerEvent
	// CloseStream close a stream
	CloseStream(peerID peer.ID) error
	// DisablePublishingPeerStatus disables publishing status in syncer topic
	DisablePublishingPeerStatus()
	// EnablePublishingPeerStatus enables publishing status in syncer topic
	EnablePublishingPeerStatus()
	// PublishApplicationStatus publish application status
	PublishApplicationStatus(status *proto.AppStatus)
	// SubscribeAppEvents returns a application event subscription
	SubscribeAppEvents() Subscription
}

func NewSyncAppPeerClient

func NewSyncAppPeerClient(
	logger hclog.Logger,
	network Network,
	host host.Host,
	applicationStore ApplicationStore,
) SyncAppPeerClient

type SyncAppPeerService

type SyncAppPeerService interface {
	// Start starts server
	Start()
	// Close terminates running processes for SyncPeerService
	Close() error
}

func NewSyncAppPeerService

func NewSyncAppPeerService(
	logger hclog.Logger,
	network *network.Server,
	applicationStore ApplicationStore,
) SyncAppPeerService

type Syncer

type Syncer interface {
	// Start starts syncer processes
	Start(topicSubFlag bool) error
	// Close terminates syncer process
	Close() error
	// GetAppPeer get AppPeer by PeerID
	GetAppPeer(id string) *AppPeer
}

func NewSyncer

func NewSyncer(
	logger hclog.Logger,
	syncAppPeerClient SyncAppPeerClient,
	syncAppPeerService SyncAppPeerService,
	host host.Host,
	applicationStore ApplicationStore,
) Syncer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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