Documentation
¶
Index ¶
- Variables
- type BlockData
- type BlockEventTracker
- type BlockEvents
- type Blocks
- type NodeDataPage
- type NodeOption
- type Option
- func WithBootNodes(bootnodes ...string) Option
- func WithEnvironment(env string) Option
- func WithMasaProtocolHandler(pid string, n network.StreamHandler) Option
- func WithPort(port int) Option
- func WithProtocolHandler(pid protocol.ID, n network.StreamHandler) Option
- func WithPubSubHandler(protocolName string, handler types.SubscriptionHandler, includeSelf bool) Option
- func WithService(plugins ...func(ctx context.Context, node *OracleNode)) Option
- func WithVersion(version string) Option
- type OracleNode
- func (node *OracleNode) FromUnixTime(unixTime int64) string
- func (node *OracleNode) GetMultiAddrs() multiaddr.Multiaddr
- func (node *OracleNode) GetP2PMultiAddrs() ([]multiaddr.Multiaddr, error)
- func (node *OracleNode) GossipNodeData(stream network.Stream)
- func (node *OracleNode) HandleMessage(msg *pubsub.Message)
- func (node *OracleNode) IsPublisher() bool
- func (node *OracleNode) IsWorker() bool
- func (node *OracleNode) ListenToNodeTracker()
- func (node *OracleNode) LogActiveTopics()
- func (node *OracleNode) ProtocolStream(ctx context.Context, peerID peer.ID, protocolName string) (network.Stream, error)
- func (node *OracleNode) PublishTopic(protocolName string, data []byte) error
- func (node *OracleNode) PublishTopicMessage(protocolName string, data string) error
- func (node *OracleNode) ReceiveNodeData(stream network.Stream)
- func (node *OracleNode) SendNodeData(peerID peer.ID)
- func (node *OracleNode) SendNodeDataPage(allNodeData []pubsub2.NodeData, stream network.Stream, pageNumber int)
- func (node *OracleNode) Start() (err error)
- func (node *OracleNode) Subscribe(protocolName string, handler types.SubscriptionHandler) error
- func (node *OracleNode) SubscribeTopic(protocolName string, handler types.SubscriptionHandler, includeSelf bool) error
- func (node *OracleNode) ToUnixTime(stringTime string) int64
- func (node *OracleNode) Version() string
- type PubSubHandlers
Constants ¶
This section is empty.
Variables ¶
var EnableRandomIdentity = func(o *NodeOption) { o.RandomIdentity = true }
var EnableStaked = func(o *NodeOption) { o.IsStaked = true }
var EnableTCP = func(o *NodeOption) { o.TCP = true }
var EnableUDP = func(o *NodeOption) { o.UDP = true }
var IsDiscordScraper = func(o *NodeOption) { o.IsDiscordScraper = true }
var IsLlmServer = func(o *NodeOption) { o.IsLlmServer = true }
var IsTelegramScraper = func(o *NodeOption) { o.IsTelegramScraper = true }
var IsTwitterScraper = func(o *NodeOption) { o.IsTwitterScraper = true }
var IsValidator = func(o *NodeOption) { o.IsValidator = true }
var IsWebScraper = func(o *NodeOption) { o.IsWebScraper = true }
Functions ¶
This section is empty.
Types ¶
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 NodeDataPage ¶
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 WithEnvironment ¶
func WithMasaProtocolHandler ¶
func WithMasaProtocolHandler(pid string, n network.StreamHandler) 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 ¶
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 (*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
}