mirror of
https://source.quilibrium.com/quilibrium/ceremonyclient.git
synced 2024-12-24 23:55:18 +00:00
Liberty (#167)
* And what country can preserve its liberties if their rulers are not warned from time to time that their people preserve the spirit of resistance? * adjust check to handle peer id change
This commit is contained in:
parent
a9fac688d0
commit
de115fbfad
@ -18,7 +18,7 @@ var acceptCmd = &cobra.Command{
|
||||
PendingTransaction - the address of the pending transfer
|
||||
`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) == 1 {
|
||||
if len(args) != 1 {
|
||||
fmt.Println("invalid command")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ var balanceCmd = &cobra.Command{
|
||||
Use: "balance",
|
||||
Short: "Lists the total balance of tokens in the managing account",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("1545.381923 QUIL")
|
||||
fmt.Println("1545.381923 QUIL (Account 0x026a5cf3d486b8e8733060d6ce0060074616f0f925671a0886faef744412dc8a)")
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ var rejectCmd = &cobra.Command{
|
||||
PendingTransaction - the address of the pending transfer
|
||||
`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) == 1 {
|
||||
if len(args) != 1 {
|
||||
fmt.Println("invalid command")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ var transferCmd = &cobra.Command{
|
||||
Either Amount or OfCoin must be specified
|
||||
`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) < 2 {
|
||||
if len(args) < 2 || len(args) > 4 {
|
||||
fmt.Println("invalid command")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -25,6 +25,20 @@ type Node struct {
|
||||
engine consensus.ConsensusEngine
|
||||
}
|
||||
|
||||
type DHTNode struct {
|
||||
pubSub p2p.PubSub
|
||||
quit chan struct{}
|
||||
}
|
||||
|
||||
func newDHTNode(
|
||||
pubSub p2p.PubSub,
|
||||
) (*DHTNode, error) {
|
||||
return &DHTNode{
|
||||
pubSub: pubSub,
|
||||
quit: make(chan struct{}),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func newNode(
|
||||
logger *zap.Logger,
|
||||
clockStore store.ClockStore,
|
||||
@ -126,6 +140,16 @@ func (n *Node) RunRepair() {
|
||||
n.logger.Info("check complete")
|
||||
}
|
||||
|
||||
func (d *DHTNode) Start() {
|
||||
<-d.quit
|
||||
}
|
||||
|
||||
func (d *DHTNode) Stop() {
|
||||
go func() {
|
||||
d.quit <- struct{}{}
|
||||
}()
|
||||
}
|
||||
|
||||
func (n *Node) Start() {
|
||||
err := <-n.engine.Start()
|
||||
if err != nil {
|
||||
|
@ -88,6 +88,14 @@ var consensusSet = wire.NewSet(
|
||||
),
|
||||
)
|
||||
|
||||
func NewDHTNode(*config.Config) (*DHTNode, error) {
|
||||
panic(wire.Build(
|
||||
debugLoggerSet,
|
||||
pubSubSet,
|
||||
newDHTNode,
|
||||
))
|
||||
}
|
||||
|
||||
func NewDebugNode(*config.Config, *protobufs.SelfTestReport) (*Node, error) {
|
||||
panic(wire.Build(
|
||||
debugLoggerSet,
|
||||
|
@ -23,6 +23,17 @@ import (
|
||||
|
||||
// Injectors from wire.go:
|
||||
|
||||
func NewDHTNode(configConfig *config.Config) (*DHTNode, error) {
|
||||
p2PConfig := configConfig.P2P
|
||||
zapLogger := debugLogger()
|
||||
blossomSub := p2p.NewBlossomSub(p2PConfig, zapLogger)
|
||||
dhtNode, err := newDHTNode(blossomSub)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dhtNode, nil
|
||||
}
|
||||
|
||||
func NewDebugNode(configConfig *config.Config, selfTestReport *protobufs.SelfTestReport) (*Node, error) {
|
||||
zapLogger := debugLogger()
|
||||
dbConfig := configConfig.DB
|
||||
|
File diff suppressed because one or more lines are too long
26
node/main.go
26
node/main.go
@ -84,6 +84,11 @@ var (
|
||||
false,
|
||||
"sets log output to debug (verbose)",
|
||||
)
|
||||
dhtOnly = flag.Bool(
|
||||
"dht-only",
|
||||
false,
|
||||
"sets a node to run strictly as a dht bootstrap peer (not full node)",
|
||||
)
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -180,11 +185,28 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println("Loading ceremony state and starting node...")
|
||||
kzg.Init()
|
||||
if !*dhtOnly {
|
||||
fmt.Println("Loading ceremony state and starting node...")
|
||||
kzg.Init()
|
||||
}
|
||||
|
||||
report := RunSelfTestIfNeeded(*configDirectory, nodeConfig)
|
||||
|
||||
if *dhtOnly {
|
||||
dht, err := app.NewDHTNode(nodeConfig)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
go func() {
|
||||
dht.Start()
|
||||
}()
|
||||
|
||||
<-done
|
||||
dht.Stop()
|
||||
return
|
||||
}
|
||||
|
||||
var node *app.Node
|
||||
if *debug {
|
||||
node, err = app.NewDebugNode(nodeConfig, report)
|
||||
|
@ -95,7 +95,7 @@ func NewBlossomSub(
|
||||
isBootstrapPeer := false
|
||||
peerId := getPeerID(p2pConfig)
|
||||
|
||||
for _, peerAddr := range p2pConfig.BootstrapPeers {
|
||||
for _, peerAddr := range config.BootstrapPeers {
|
||||
peerinfo, err := peer.AddrInfoFromString(peerAddr)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -350,7 +350,19 @@ func initDHT(
|
||||
zap.String("peer_id", h.ID().String()),
|
||||
)
|
||||
|
||||
defaultBootstrapPeers := p2pConfig.BootstrapPeers
|
||||
defaultBootstrapPeers := append([]string{}, p2pConfig.BootstrapPeers...)
|
||||
for _, peer := range config.BootstrapPeers {
|
||||
found := false
|
||||
for _, existing := range defaultBootstrapPeers {
|
||||
if existing == peer {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
defaultBootstrapPeers = append(defaultBootstrapPeers, peer)
|
||||
}
|
||||
}
|
||||
|
||||
for _, peerAddr := range defaultBootstrapPeers {
|
||||
peerinfo, err := peer.AddrInfoFromString(peerAddr)
|
||||
@ -365,7 +377,7 @@ func initDHT(
|
||||
}
|
||||
|
||||
if err := h.Connect(ctx, *peerinfo); err != nil {
|
||||
logger.Info("error while connecting to dht peer", zap.Error(err))
|
||||
logger.Debug("error while connecting to dht peer", zap.Error(err))
|
||||
} else {
|
||||
logger.Info(
|
||||
"connected to peer",
|
||||
|
Loading…
Reference in New Issue
Block a user