mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-03 20:16:02 +02:00
Merge pull request #6149 from bhandras/graph_import_rpc
lnd: add `devrpc` sub server and `devrpc.ImportGraph` to import graph dumps
This commit is contained in:
28
server.go
28
server.go
@ -6,11 +6,9 @@ import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"image/color"
|
||||
"math/big"
|
||||
prand "math/rand"
|
||||
"net"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
@ -116,10 +114,6 @@ var (
|
||||
// gracefully exiting.
|
||||
ErrServerShuttingDown = errors.New("server is shutting down")
|
||||
|
||||
// validColorRegexp is a regexp that lets you check if a particular
|
||||
// color string matches the standard hex color format #RRGGBB.
|
||||
validColorRegexp = regexp.MustCompile("^#[A-Fa-f0-9]{6}$")
|
||||
|
||||
// MaxFundingAmount is a soft-limit of the maximum channel size
|
||||
// currently accepted within the Lightning Protocol. This is
|
||||
// defined in BOLT-0002, and serves as an initial precautionary limit
|
||||
@ -772,7 +766,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
||||
// the network.
|
||||
//
|
||||
// We'll start by parsing the node color from configuration.
|
||||
color, err := parseHexColor(cfg.Color)
|
||||
color, err := lncfg.ParseHexColor(cfg.Color)
|
||||
if err != nil {
|
||||
srvrLog.Errorf("unable to parse color: %v\n", err)
|
||||
return nil, err
|
||||
@ -4204,26 +4198,6 @@ func (s *server) Peers() []*peer.Brontide {
|
||||
return peers
|
||||
}
|
||||
|
||||
// parseHexColor takes a hex string representation of a color in the
|
||||
// form "#RRGGBB", parses the hex color values, and returns a color.RGBA
|
||||
// struct of the same color.
|
||||
func parseHexColor(colorStr string) (color.RGBA, error) {
|
||||
// Check if the hex color string is a valid color representation.
|
||||
if !validColorRegexp.MatchString(colorStr) {
|
||||
return color.RGBA{}, errors.New("Color must be specified " +
|
||||
"using a hexadecimal value in the form #RRGGBB")
|
||||
}
|
||||
|
||||
// Decode the hex color string to bytes.
|
||||
// The resulting byte array is in the form [R, G, B].
|
||||
colorBytes, err := hex.DecodeString(colorStr[1:])
|
||||
if err != nil {
|
||||
return color.RGBA{}, err
|
||||
}
|
||||
|
||||
return color.RGBA{R: colorBytes[0], G: colorBytes[1], B: colorBytes[2]}, nil
|
||||
}
|
||||
|
||||
// computeNextBackoff uses a truncated exponential backoff to compute the next
|
||||
// backoff using the value of the exiting backoff. The returned duration is
|
||||
// randomized in either direction by 1/20 to prevent tight loops from
|
||||
|
Reference in New Issue
Block a user