Skip to content

Commit

Permalink
multi: add socks proxy config option
Browse files Browse the repository at this point in the history
This commit adds a socks proxy option to the rpc config. This option is
set using the SocksProxy flag in the main faraday config.
  • Loading branch information
ellemouton committed May 19, 2021
1 parent 99c02d7 commit f3e9a5f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 5 deletions.
6 changes: 4 additions & 2 deletions accounting/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ type CommonConfig struct {
func NewOnChainConfig(ctx context.Context, lnd lndclient.LndServices, startTime,
endTime time.Time, disableFiat bool, txLookup fees.GetDetailsFunc,
fiatBackend fiat.PriceBackend, granularity *fiat.Granularity,
categories []CustomCategory) *OnChainConfig {
categories []CustomCategory, socksProxy string) *OnChainConfig {

var getFee func(chainhash.Hash) (btcutil.Amount, error)
if txLookup != nil {
Expand Down Expand Up @@ -140,6 +140,7 @@ func NewOnChainConfig(ctx context.Context, lnd lndclient.LndServices, startTime,
FiatBackend: fiatBackend,
Granularity: granularity,
Categories: categories,
SocksProxy: socksProxy,
},
GetFee: getFee,
}
Expand All @@ -152,7 +153,7 @@ func NewOffChainConfig(ctx context.Context, lnd lndclient.LndServices,
maxInvoices, maxPayments, maxForwards uint64, ownPubkey route.Vertex,
startTime, endTime time.Time, disableFiat bool,
fiatBackend fiat.PriceBackend, granularity *fiat.Granularity,
categories []CustomCategory) *OffChainConfig {
categories []CustomCategory, socksProxy string) *OffChainConfig {

return &OffChainConfig{
ListInvoices: func() ([]lndclient.Invoice, error) {
Expand Down Expand Up @@ -186,6 +187,7 @@ func NewOffChainConfig(ctx context.Context, lnd lndclient.LndServices,
FiatBackend: fiatBackend,
Granularity: granularity,
Categories: categories,
SocksProxy: socksProxy,
},
}
}
2 changes: 1 addition & 1 deletion cmd/frcli/fiat_estimate.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var fiatEstimateCommand = cli.Command{
cli.StringFlag{
Name: "fiat_backend",
Usage: "fiat backend to be used. Options include: " +
"'coincap' (default) and 'coindesk'",
"'coincap' (default if no proxy is set) and 'coindesk' (default if a proxy is set)",
},
},
Action: queryFiatEstimate,
Expand Down
3 changes: 3 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ type Config struct { //nolint:maligned

// Bitcoin is the configuration required to connect to a bitcoin node.
Bitcoin *chain.BitcoinConfig `group:"bitcoin" namespace:"bitcoin"`

// SocksProxy is the address to use as a socks proxy for http requests. No proxy is used if the value is empty.
SocksProxy string `long:"proxy" description:"Address to be used as the socks proxy for HTTP requests."`
}

// DefaultConfig returns all default values for the Config struct.
Expand Down
1 change: 1 addition & 0 deletions faraday.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func Main() error {
RestClientConfig: restClientCreds,
FaradayDir: config.FaradayDir,
MacaroonPath: config.MacaroonPath,
SocksProxy: config.SocksProxy,
}

// If the client chose to connect to a bitcoin client, get one now.
Expand Down
3 changes: 2 additions & 1 deletion frdrpc/node_audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func parseNodeAuditRequest(ctx context.Context, cfg *Config,
ctx, cfg.Lnd, uint64(maxInvoiceQueries),
uint64(maxPaymentQueries), uint64(maxForwardQueries),
pubkey, start, end, req.DisableFiat, fiatBackend, granularity,
offChainCategories,
offChainCategories, cfg.SocksProxy,
)

// If we have a chain connection, set our tx lookup function. Otherwise
Expand All @@ -88,6 +88,7 @@ func parseNodeAuditRequest(ctx context.Context, cfg *Config,
onChain := accounting.NewOnChainConfig(
ctx, cfg.Lnd, start, end, req.DisableFiat,
feeLookup, fiatBackend, granularity, onChainCategories,
cfg.SocksProxy,
)

return onChain, offChain, nil
Expand Down
5 changes: 4 additions & 1 deletion frdrpc/rpcserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ type Config struct {
// that is created automatically. This path normally is within
// FaradayDir unless otherwise specified by the user.
MacaroonPath string

// SocksProxy that if set is the url to use to proxy http requests.
SocksProxy string
}

// NewRPCServer returns a server which will listen for rpc requests on the
Expand Down Expand Up @@ -443,7 +446,7 @@ func (s *RPCServer) ExchangeRate(ctx context.Context,
}

prices, err := fiat.GetPrices(
ctx, timestamps, fiatBackend, *granularity, "",
ctx, timestamps, fiatBackend, *granularity, s.cfg.SocksProxy,
)
if err != nil {
return nil, err
Expand Down

0 comments on commit f3e9a5f

Please sign in to comment.