node

package
v0.8.8 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: MIT Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EnableRandomIdentity = func(o *NodeOption) {
	o.RandomIdentity = true
}
View Source
var EnableStaked = func(o *NodeOption) {
	o.IsStaked = true
}
View Source
var EnableTCP = func(o *NodeOption) {
	o.TCP = true
}
View Source
var EnableUDP = func(o *NodeOption) {
	o.UDP = true
}
View Source
var IsDiscordScraper = func(o *NodeOption) {
	o.IsDiscordScraper = true
}
View Source
var IsLlmServer = func(o *NodeOption) {
	o.IsLlmServer = true
}
View Source
var IsTelegramScraper = func(o *NodeOption) {
	o.IsTelegramScraper = true
}
View Source
var IsTwitterScraper = func(o *NodeOption) {
	o.IsTwitterScraper = true
}
View Source
var IsValidator = func(o *NodeOption) {
	o.IsValidator = true
}
View Source
var IsWebScraper = func(o *NodeOption) {
	o.IsWebScraper = true
}

Functions

This section is empty.

Types

type BlockData

type BlockData struct {
	Block            uint64      `json:"block"`
	InputData        interface{} `json:"input_data"`
	TransactionHash  string      `json:"transaction_hash"`
	PreviousHash     string      `json:"previous_hash"`
	TransactionNonce int         `json:"nonce"`
}

type BlockEventTracker

type BlockEventTracker struct {
	BlockEvents []BlockEvents
	// contains filtered or unexported fields
}

func NewBlockChain

func NewBlockChain() *BlockEventTracker

func (*BlockEventTracker) HandleMessage

func (b *BlockEventTracker) HandleMessage(m *pubsub.Message)

HandleMessage processes incoming pubsub messages containing block events. It unmarshals the message data into a slice of BlockEvents and appends them to the tracker's BlockEvents slice.

func (*BlockEventTracker) Start

func (b *BlockEventTracker) Start(path string) func(ctx context.Context, node *OracleNode)

type BlockEvents

type BlockEvents map[string]interface{}

type Blocks

type Blocks struct {
	BlockData []BlockData `json:"blocks"`
}

type NodeDataPage

type NodeDataPage struct {
	Data         []pubsub2.NodeData `json:"data"`
	PageNumber   int                `json:"pageNumber"`
	TotalPages   int                `json:"totalPages"`
	TotalRecords int                `json:"totalRecords"`
}

type NodeOption

type NodeOption struct {
	IsStaked    bool
	UDP         bool
	TCP         bool
	IsValidator bool
	PortNbr     int

	IsTwitterScraper  bool
	IsDiscordScraper  bool
	IsTelegramScraper bool
	IsWebScraper      bool
	IsLlmServer       bool

	Bootnodes            []string
	RandomIdentity       bool
	Services             []func(ctx context.Context, node *OracleNode)
	PubSubHandles        []PubSubHandlers
	ProtocolHandlers     map[protocol.ID]network.StreamHandler
	MasaProtocolHandlers map[string]network.StreamHandler
	Environment          string
	Version              string
}

func (*NodeOption) Apply

func (a *NodeOption) Apply(opts ...Option)

func (*NodeOption) HasBootnodes

func (a *NodeOption) HasBootnodes() bool

HasBootnodes checks if the AppConfig has any bootnodes configured. It returns true if there is at least one bootnode in the Bootnodes slice and it is not an empty string. Otherwise, it returns false, indicating that no bootnodes are configured.

type Option

type Option func(*NodeOption)

func WithBootNodes

func WithBootNodes(bootnodes ...string) Option

func WithEnvironment

func WithEnvironment(env string) Option

func WithMasaProtocolHandler

func WithMasaProtocolHandler(pid string, n network.StreamHandler) Option

func WithPort

func WithPort(port int) Option

func WithProtocolHandler

func WithProtocolHandler(pid protocol.ID, n network.StreamHandler) Option

func WithPubSubHandler

func WithPubSubHandler(protocolName string, handler types.SubscriptionHandler, includeSelf bool) Option

func WithService

func WithService(plugins ...func(ctx context.Context, node *OracleNode)) Option

func WithVersion

func WithVersion(version string) Option

type OracleNode

type OracleNode struct {
	Host     host.Host
	Protocol protocol.ID

	DHT           *dht.IpfsDHT
	PeerChan      chan myNetwork.PeerEvent
	NodeTracker   *pubsub.NodeEventTracker
	PubSubManager *pubsub.Manager
	Signature     string
	StartTime     time.Time
	WorkerTracker *pubsub.WorkerEventTracker
	Blockchain    *chain.Chain
	Options       NodeOption
	Context       context.Context
	// contains filtered or unexported fields
}

func NewOracleNode

func NewOracleNode(ctx context.Context, opts ...Option) (*OracleNode, error)

NewOracleNode creates a new OracleNode instance with the provided context and staking status. It initializes the libp2p host, DHT, pubsub manager, and other components needed for an Oracle node to join the network and participate.

func (*OracleNode) FromUnixTime

func (node *OracleNode) FromUnixTime(unixTime int64) string

FromUnixTime converts a Unix timestamp into a formatted string. The Unix timestamp is expected to be in seconds. The returned string is in the format "2006-01-02T15:04:05.000Z".

func (*OracleNode) GetMultiAddrs

func (node *OracleNode) GetMultiAddrs() multiaddr.Multiaddr

GetMultiAddrs returns the priority multiaddr for this node. It first checks if the priority address is already set, and returns it if so. If not, it determines the priority address from the available multiaddrs using the GetPriorityAddress utility function, sets it, and returns it.

func (*OracleNode) GetP2PMultiAddrs

func (node *OracleNode) GetP2PMultiAddrs() ([]multiaddr.Multiaddr, error)

GetP2PMultiAddrs returns the multiaddresses for the host in P2P format.

func (*OracleNode) GossipNodeData

func (node *OracleNode) GossipNodeData(stream network.Stream)

GossipNodeData handles receiving NodeData from a peer over a network stream. It reads the stream to get the remote peer ID and NodeData, updates the local NodeTracker with the data if it is about another node, and closes the stream when finished.

func (*OracleNode) HandleMessage

func (node *OracleNode) HandleMessage(msg *pubsub.Message)

HandleMessage unmarshals the node data from the pubsub message, and passes it to the NodeTracker to handle. This allows the OracleNode to receive node data published on the network, and process it.

func (*OracleNode) IsPublisher

func (node *OracleNode) IsPublisher() bool

IsPublisher returns true if this node is a publisher node. A publisher node is one that has a non-empty signature.

func (*OracleNode) IsWorker

func (node *OracleNode) IsWorker() bool

IsWorker determines if the OracleNode is configured to act as an actor. An actor node is one that has at least one of the following scrapers enabled: TwitterScraper, DiscordScraper, or WebScraper. It returns true if any of these scrapers are enabled, otherwise false.

func (*OracleNode) ListenToNodeTracker

func (node *OracleNode) ListenToNodeTracker()

ListenToNodeTracker listens to the NodeTracker's NodeDataChan and publishes any received node data to the node gossip topic. It also sends the node data directly to the peer if it's a join event and this node isn't a bootnode or has been running for more than 5 minutes.

func (*OracleNode) LogActiveTopics

func (node *OracleNode) LogActiveTopics()

LogActiveTopics logs the currently active topic names to the default logger. It gets the list of active topics from the PubSubManager and logs them if there are any, otherwise it logs that there are no active topics.

func (*OracleNode) ProtocolStream

func (node *OracleNode) ProtocolStream(ctx context.Context, peerID peer.ID, protocolName string) (network.Stream, error)

func (*OracleNode) PublishTopic

func (node *OracleNode) PublishTopic(protocolName string, data []byte) error

func (*OracleNode) PublishTopicMessage

func (node *OracleNode) PublishTopicMessage(protocolName string, data string) error

func (*OracleNode) ReceiveNodeData

func (node *OracleNode) ReceiveNodeData(stream network.Stream)

ReceiveNodeData handles receiving NodeData pages from a peer over a network stream. It scans the stream and unmarshals each page of NodeData, refreshing the local NodeTracker with the data.

func (*OracleNode) SendNodeData

func (node *OracleNode) SendNodeData(peerID peer.ID)

SendNodeData sends all node data to the peer with the given ID. It first checks if the node is staked, and if not, aborts. It gets the node data to send based on the last time the peer was seen. It paginates the node data into pages and sends each page over the stream.

func (*OracleNode) SendNodeDataPage

func (node *OracleNode) SendNodeDataPage(allNodeData []pubsub2.NodeData, stream network.Stream, pageNumber int)

SendNodeDataPage sends a page of node data over the given stream. It paginates the provided node data slice into pages of size config.PageSize. The pageNumber parameter specifies which page to send, starting from 0. The response includes the page of data, page number, total pages, and total records.

func (*OracleNode) Start

func (node *OracleNode) Start() (err error)

Start initializes the OracleNode by setting up libp2p stream handlers, connecting to the DHT and bootnodes, and subscribing to topics. It launches goroutines to handle discovered peers, listen to the node tracker, and discover peers. If this is a bootnode, it adds itself to the node tracker.

func (*OracleNode) Subscribe

func (node *OracleNode) Subscribe(protocolName string, handler types.SubscriptionHandler) error

func (*OracleNode) SubscribeTopic

func (node *OracleNode) SubscribeTopic(protocolName string, handler types.SubscriptionHandler, includeSelf bool) error

func (*OracleNode) ToUnixTime

func (node *OracleNode) ToUnixTime(stringTime string) int64

ToUnixTime converts a formatted string time into a Unix timestamp. The input string is expected to be in the format "2006-01-02T15:04:05.000Z". The returned Unix timestamp is in seconds.

func (*OracleNode) Version

func (node *OracleNode) Version() string

Version returns the current version string of the oracle node software.

type PubSubHandlers

type PubSubHandlers struct {
	ProtocolName string
	Handler      types.SubscriptionHandler
	IncludeSelf  bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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