Skip to content

Commit de115fb

Browse files
authored
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
1 parent a9fac68 commit de115fb

File tree

10 files changed

+119
-38
lines changed

10 files changed

+119
-38
lines changed

client/cmd/accept.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var acceptCmd = &cobra.Command{
1818
PendingTransaction - the address of the pending transfer
1919
`,
2020
Run: func(cmd *cobra.Command, args []string) {
21-
if len(args) == 1 {
21+
if len(args) != 1 {
2222
fmt.Println("invalid command")
2323
os.Exit(1)
2424
}

client/cmd/balance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var balanceCmd = &cobra.Command{
1010
Use: "balance",
1111
Short: "Lists the total balance of tokens in the managing account",
1212
Run: func(cmd *cobra.Command, args []string) {
13-
fmt.Println("1545.381923 QUIL")
13+
fmt.Println("1545.381923 QUIL (Account 0x026a5cf3d486b8e8733060d6ce0060074616f0f925671a0886faef744412dc8a)")
1414
},
1515
}
1616

client/cmd/reject.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var rejectCmd = &cobra.Command{
1818
PendingTransaction - the address of the pending transfer
1919
`,
2020
Run: func(cmd *cobra.Command, args []string) {
21-
if len(args) == 1 {
21+
if len(args) != 1 {
2222
fmt.Println("invalid command")
2323
os.Exit(1)
2424
}

client/cmd/transfer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var transferCmd = &cobra.Command{
2626
Either Amount or OfCoin must be specified
2727
`,
2828
Run: func(cmd *cobra.Command, args []string) {
29-
if len(args) < 2 {
29+
if len(args) < 2 || len(args) > 4 {
3030
fmt.Println("invalid command")
3131
os.Exit(1)
3232
}

node/app/node.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ type Node struct {
2525
engine consensus.ConsensusEngine
2626
}
2727

28+
type DHTNode struct {
29+
pubSub p2p.PubSub
30+
quit chan struct{}
31+
}
32+
33+
func newDHTNode(
34+
pubSub p2p.PubSub,
35+
) (*DHTNode, error) {
36+
return &DHTNode{
37+
pubSub: pubSub,
38+
quit: make(chan struct{}),
39+
}, nil
40+
}
41+
2842
func newNode(
2943
logger *zap.Logger,
3044
clockStore store.ClockStore,
@@ -126,6 +140,16 @@ func (n *Node) RunRepair() {
126140
n.logger.Info("check complete")
127141
}
128142

143+
func (d *DHTNode) Start() {
144+
<-d.quit
145+
}
146+
147+
func (d *DHTNode) Stop() {
148+
go func() {
149+
d.quit <- struct{}{}
150+
}()
151+
}
152+
129153
func (n *Node) Start() {
130154
err := <-n.engine.Start()
131155
if err != nil {

node/app/wire.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ var consensusSet = wire.NewSet(
8888
),
8989
)
9090

91+
func NewDHTNode(*config.Config) (*DHTNode, error) {
92+
panic(wire.Build(
93+
debugLoggerSet,
94+
pubSubSet,
95+
newDHTNode,
96+
))
97+
}
98+
9199
func NewDebugNode(*config.Config, *protobufs.SelfTestReport) (*Node, error) {
92100
panic(wire.Build(
93101
debugLoggerSet,

node/app/wire_gen.go

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node/config/config.go

Lines changed: 33 additions & 29 deletions
Large diffs are not rendered by default.

node/main.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ var (
8484
false,
8585
"sets log output to debug (verbose)",
8686
)
87+
dhtOnly = flag.Bool(
88+
"dht-only",
89+
false,
90+
"sets a node to run strictly as a dht bootstrap peer (not full node)",
91+
)
8792
)
8893

8994
func main() {
@@ -180,11 +185,28 @@ func main() {
180185
return
181186
}
182187

183-
fmt.Println("Loading ceremony state and starting node...")
184-
kzg.Init()
188+
if !*dhtOnly {
189+
fmt.Println("Loading ceremony state and starting node...")
190+
kzg.Init()
191+
}
185192

186193
report := RunSelfTestIfNeeded(*configDirectory, nodeConfig)
187194

195+
if *dhtOnly {
196+
dht, err := app.NewDHTNode(nodeConfig)
197+
if err != nil {
198+
panic(err)
199+
}
200+
201+
go func() {
202+
dht.Start()
203+
}()
204+
205+
<-done
206+
dht.Stop()
207+
return
208+
}
209+
188210
var node *app.Node
189211
if *debug {
190212
node, err = app.NewDebugNode(nodeConfig, report)

node/p2p/blossomsub.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func NewBlossomSub(
9595
isBootstrapPeer := false
9696
peerId := getPeerID(p2pConfig)
9797

98-
for _, peerAddr := range p2pConfig.BootstrapPeers {
98+
for _, peerAddr := range config.BootstrapPeers {
9999
peerinfo, err := peer.AddrInfoFromString(peerAddr)
100100
if err != nil {
101101
panic(err)
@@ -350,7 +350,19 @@ func initDHT(
350350
zap.String("peer_id", h.ID().String()),
351351
)
352352

353-
defaultBootstrapPeers := p2pConfig.BootstrapPeers
353+
defaultBootstrapPeers := append([]string{}, p2pConfig.BootstrapPeers...)
354+
for _, peer := range config.BootstrapPeers {
355+
found := false
356+
for _, existing := range defaultBootstrapPeers {
357+
if existing == peer {
358+
found = true
359+
break
360+
}
361+
}
362+
if !found {
363+
defaultBootstrapPeers = append(defaultBootstrapPeers, peer)
364+
}
365+
}
354366

355367
for _, peerAddr := range defaultBootstrapPeers {
356368
peerinfo, err := peer.AddrInfoFromString(peerAddr)
@@ -365,7 +377,7 @@ func initDHT(
365377
}
366378

367379
if err := h.Connect(ctx, *peerinfo); err != nil {
368-
logger.Info("error while connecting to dht peer", zap.Error(err))
380+
logger.Debug("error while connecting to dht peer", zap.Error(err))
369381
} else {
370382
logger.Info(
371383
"connected to peer",

0 commit comments

Comments
 (0)