Skip to content
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

multi: add socks proxy flag #117

Closed
wants to merge 2 commits into from

Conversation

ellemouton
Copy link
Member

@ellemouton ellemouton commented Apr 30, 2021

This PR addresses this comment suggestion to add a --proxy option to proxy http requests for price data over Tor.

It seems to me from testing that I have done than CoinCap does not allow requests over tor, but CoinDesk does. So in this PR the default backend is CoinCap if no proxy is set and is CoinDesk if a proxy is set. If both proxy and backend are specified then a validation check is done to check if the specified backend supports proxy requests.

@@ -91,17 +93,56 @@ var priceBackendNames = map[PriceBackend]string{
CoinDeskPriceBackend: "coindesk",
}

var priceBackendProxySupport = map[PriceBackend]bool{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thoughts on doing a config map instead of the 2 separate priceBackendNames and priceBackendProxySupport maps? So something like this:

type backendsConfig struct {
	name string
	proxySupport bool
}

var priceBackendsConfig = map[PriceBackend]backendsConfig {
	UnknownPriceBackend: {
		name: "unknown",
		proxySupport: false,
        },
	CoinCapPriceBackend: {
		name: "coincap",
		proxySupport: false,
	},
	CoinDeskPriceBackend: {
		name: "coindesk",
		proxySupport: true,
	},
}

@ellemouton ellemouton force-pushed the proxyFlag branch 3 times, most recently from f3e9a5f to 761b463 Compare May 20, 2021 07:05
@ellemouton ellemouton changed the title [WIP] multi: add socks proxy flag multi: add socks proxy flag May 20, 2021
This commit adds support for the coindesk backends to be initialized
with a socks proxy if one is provided.
This commit adds a socks proxy option to the rpc config. This option is
set using the SocksProxy flag in the main faraday config.
Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, goods are as advertised!

Just a unit test then this is gg.

fiat/prices.go Outdated
// Check that the proxy flag is not set for a price backend that does
// not support requests through a socks proxy.
if proxy != "" && !priceBackendProxySupport[backend] {
return nil, errors.New("can't use a socks proxy for the " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add the backend here for a friendlier user err

// String returns the string representation of a price backend.
func (p PriceBackend) String() string {
return priceBackendNames[p]
}

// NewPriceSource returns a PriceSource which can be used to query price
// data.
func NewPriceSource(backend PriceBackend, granularity *Granularity) (
*PriceSource, error) {
func NewPriceSource(backend PriceBackend, granularity *Granularity,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a unit test for this? Just to assert that we error out with the correct combinations etc.

@@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting to the point where it may be worth pulling all the fiat params out into a FiatConfig.
But I think we can kick that can down the road for now, if we hit > 3 params then it's time :')

@lightninglabs-deploy
Copy link

@ellemouton, remember to re-request review from reviewers for your latest update

@ellemouton
Copy link
Member Author

!lightninglabs-deploy mute

@ellemouton
Copy link
Member Author

closing for now - anyone else is welcome to take this over

@ellemouton ellemouton closed this Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants