-
Notifications
You must be signed in to change notification settings - Fork 109
autopilot: feature configuration #626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ package main | |
| import ( | ||
| "context" | ||
| "encoding/hex" | ||
| "fmt" | ||
| "strconv" | ||
| "strings" | ||
| "time" | ||
|
|
@@ -65,6 +66,12 @@ var addAutopilotSessionCmd = cli.Command{ | |
| "perform actions on. In the " + | ||
| "form of: peerID1,peerID2,...", | ||
| }, | ||
| cli.StringSliceFlag{ | ||
| Name: "configuration", | ||
| Usage: `per feature JSON-serialized configuration, ` + | ||
| `expected format: {"version":0,"option1":` + | ||
| `"parameter1","option2":"parameter2",...}`, | ||
ellemouton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| } | ||
|
|
||
|
|
@@ -216,11 +223,27 @@ func initAutopilotSession(ctx *cli.Context) error { | |
| } | ||
| } | ||
|
|
||
| configs := ctx.StringSlice("configuration") | ||
| features := ctx.StringSlice("feature") | ||
|
|
||
| if len(configs) > 0 && len(features) != len(configs) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we just add a comment here explaining that as soon as one config flag is set, we need all of them set as else we dont know which config goes with which feature |
||
| return fmt.Errorf("number of features and configurations " + | ||
| "must match") | ||
| } | ||
|
|
||
| featureMap := make(map[string]*litrpc.FeatureConfig) | ||
| for _, feature := range ctx.StringSlice("feature") { | ||
| for i, feature := range ctx.StringSlice("feature") { | ||
| var config []byte | ||
|
|
||
| // We allow empty configs, to signal the usage of the default | ||
| // configuration when the session is registered. | ||
|
Comment on lines
+238
to
+239
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. awesome 😎 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add this to the flag description too? also should mention the importance of the order used when specifying the config flags There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw - I'd say this is a breaking change since users now have to set the new flag. Not a bad thing since I think most users dont register for autopilot sessions through the CLI but we should at least mention this in the release notes. perhaps worth adding a tracking issue for things like this so that we can just post a comment there if we want to remind ourselves about anything that should be added to the readme or release notes for the next release. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added all the suggestions, hope we have a better description now :). is it a breaking change? we can leave out all config flags and it will use the defaults There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah - you are right. Sorry about that 🙈 |
||
| if len(configs) > 0 && configs[i] != "{}" { | ||
| config = []byte(configs[i]) | ||
| } | ||
|
|
||
| featureMap[feature] = &litrpc.FeatureConfig{ | ||
| Rules: ruleMap, | ||
| Config: nil, | ||
| Config: config, | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ import ( | |
| "errors" | ||
| "fmt" | ||
| "math/big" | ||
| "regexp" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/lightninglabs/lightning-terminal/firewalldb" | ||
|
|
@@ -833,3 +835,41 @@ func CryptoRandIntn(n int) (int, error) { | |
|
|
||
| return int(nBig.Int64()), nil | ||
| } | ||
|
|
||
| // ObfuscateConfig alters the config string by replacing pubkeys with random | ||
| // values and updates the privacy pair map. | ||
| func ObfuscateConfig(privacyPairs map[string]string, configB []byte) ([]byte, | ||
|
Comment on lines
+839
to
+841
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. very cool! should we also match on channel IDs/outpoints? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, will add that 👍! |
||
| error) { | ||
|
|
||
| // The config is a JSON blob, so we interpret it as a string to detect | ||
| // any patterns we want to replace. | ||
| config := string(configB) | ||
|
|
||
| // Replace all pubkeys with a pseudo-random string. | ||
| pubKeyRegex := regexp.MustCompile(`[a-fA-F0-9]+`) | ||
| matches := pubKeyRegex.FindAllString(config, -1) | ||
|
|
||
| for _, match := range matches { | ||
| // A pubkey is 66 characters long. | ||
| if len(match) != 66 { | ||
| continue | ||
| } | ||
|
|
||
| if _, ok := privacyPairs[match]; ok { | ||
| continue | ||
| } | ||
|
|
||
| replacement, err := firewalldb.NewPseudoStr(len(match)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| privacyPairs[match] = replacement | ||
| } | ||
|
|
||
| // Replace all occurances. | ||
| for k, v := range privacyPairs { | ||
| config = strings.ReplaceAll(config, k, v) | ||
| } | ||
|
|
||
| return []byte(config), nil | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.