11package main
22
33import (
4+ "bytes"
45 "encoding/json"
56 "fmt"
67 "io/ioutil"
@@ -47,10 +48,22 @@ type match struct {
4748 Channels []* channel `json:"channels"`
4849}
4950
51+ type donePair struct {
52+ Node1 * nodeInfo `json:"node1"`
53+ Node2 * nodeInfo `json:"node2"`
54+ Msg string `json:"msg"`
55+ }
56+
57+ func (p * donePair ) matches (node1 , node2 string ) bool {
58+ return (p .Node1 .PubKey == node1 && p .Node2 .PubKey == node2 ) ||
59+ (p .Node1 .PubKey == node2 && p .Node2 .PubKey == node1 )
60+ }
61+
5062type zombieRecoveryFindMatchesCommand struct {
5163 APIURL string
5264 Registrations string
5365 ChannelGraph string
66+ PairsDone string
5467
5568 cmd * cobra.Command
5669}
@@ -69,7 +82,8 @@ This command will be run by guggero and the result will be sent to the
6982registered nodes.` ,
7083 Example : `chantools zombierecovery findmatches \
7184 --registrations data.txt \
72- --channel_graph lncli_describegraph.json` ,
85+ --channel_graph lncli_describegraph.json \
86+ --pairs_done pairs-done.json` ,
7387 RunE : cc .Execute ,
7488 }
7589
@@ -86,6 +100,11 @@ registered nodes.`,
86100 "graph in the JSON format that the " +
87101 "'lncli describegraph' returns" ,
88102 )
103+ cc .cmd .Flags ().StringVar (
104+ & cc .PairsDone , "pairs_done" , "" , "an optional file containing " +
105+ "all pairs that have already been contacted and " +
106+ "shouldn't be matched again" ,
107+ )
89108
90109 return cc .cmd
91110}
@@ -126,6 +145,21 @@ func (c *zombieRecoveryFindMatchesCommand) Execute(_ *cobra.Command,
126145 return fmt .Errorf ("error parsing graph JSON: %v" , err )
127146 }
128147
148+ var donePairs []* donePair
149+ if c .PairsDone != "" {
150+ donePairsBytes , err := readInput (c .PairsDone )
151+ if err != nil {
152+ return fmt .Errorf ("error reading pairs JSON %s: %v" ,
153+ c .PairsDone , err )
154+ }
155+ decoder := json .NewDecoder (bytes .NewReader (donePairsBytes ))
156+ err = decoder .Decode (& donePairs )
157+ if err != nil {
158+ return fmt .Errorf ("error parsing pairs JSON %s: %v" ,
159+ c .PairsDone , err )
160+ }
161+ }
162+
129163 // Loop through all nodes now.
130164 matches := make (map [string ]map [string ]* match )
131165 for node1 , contact1 := range registrations {
@@ -176,7 +210,7 @@ func (c *zombieRecoveryFindMatchesCommand) Execute(_ *cobra.Command,
176210 // Write the matches to files.
177211 for node1 , node1map := range matches {
178212 for node2 , match := range node1map {
179- if match == nil {
213+ if match == nil || isPairDone ( donePairs , node1 , node2 ) {
180214 continue
181215 }
182216
@@ -198,3 +232,13 @@ func (c *zombieRecoveryFindMatchesCommand) Execute(_ *cobra.Command,
198232
199233 return nil
200234}
235+
236+ func isPairDone (donePairs []* donePair , node1 , node2 string ) bool {
237+ for _ , donePair := range donePairs {
238+ if donePair .matches (node1 , node2 ) {
239+ return true
240+ }
241+ }
242+
243+ return false
244+ }
0 commit comments