2023-09-03 23:47:09 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
2023-10-09 04:52:19 +00:00
|
|
|
"go.uber.org/zap"
|
2024-08-08 05:41:46 +00:00
|
|
|
"source.quilibrium.com/quilibrium/monorepo/go-libp2p-blossomsub/pb"
|
2023-10-28 02:23:55 +00:00
|
|
|
"source.quilibrium.com/quilibrium/monorepo/node/keys"
|
2023-10-09 04:52:19 +00:00
|
|
|
"source.quilibrium.com/quilibrium/monorepo/node/p2p"
|
2023-09-03 23:47:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Node struct {
|
2024-08-08 05:41:46 +00:00
|
|
|
logger *zap.Logger
|
|
|
|
keyManager keys.KeyManager
|
|
|
|
pubSub p2p.PubSub
|
|
|
|
quit chan struct{}
|
2024-04-23 01:38:20 +00:00
|
|
|
}
|
|
|
|
|
2023-09-03 23:47:09 +00:00
|
|
|
func newNode(
|
2023-10-09 04:52:19 +00:00
|
|
|
logger *zap.Logger,
|
2023-10-28 02:23:55 +00:00
|
|
|
keyManager keys.KeyManager,
|
2023-10-09 04:52:19 +00:00
|
|
|
pubSub p2p.PubSub,
|
2023-09-03 23:47:09 +00:00
|
|
|
) (*Node, error) {
|
|
|
|
return &Node{
|
2024-08-08 05:41:46 +00:00
|
|
|
logger: logger,
|
|
|
|
keyManager: keyManager,
|
|
|
|
pubSub: pubSub,
|
|
|
|
quit: make(chan struct{}),
|
2023-09-03 23:47:09 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2024-08-08 05:41:46 +00:00
|
|
|
func (d *Node) Start() {
|
|
|
|
d.pubSub.Subscribe(
|
|
|
|
[]byte{
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
|
|
},
|
|
|
|
func(message *pb.Message) error { return nil },
|
|
|
|
)
|
2024-04-23 01:38:20 +00:00
|
|
|
<-d.quit
|
|
|
|
}
|
|
|
|
|
2024-08-08 05:41:46 +00:00
|
|
|
func (d *Node) Stop() {
|
2024-04-23 01:38:20 +00:00
|
|
|
go func() {
|
|
|
|
d.quit <- struct{}{}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2023-10-09 04:52:19 +00:00
|
|
|
func (n *Node) GetLogger() *zap.Logger {
|
|
|
|
return n.logger
|
|
|
|
}
|
|
|
|
|
2023-10-28 02:23:55 +00:00
|
|
|
func (n *Node) GetKeyManager() keys.KeyManager {
|
|
|
|
return n.keyManager
|
|
|
|
}
|
|
|
|
|
2023-10-09 04:52:19 +00:00
|
|
|
func (n *Node) GetPubSub() p2p.PubSub {
|
|
|
|
return n.pubSub
|
|
|
|
}
|