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

feat: Implement Custom TCP Dialers #3166

Merged
merged 2 commits into from
Feb 3, 2025
Merged

feat: Implement Custom TCP Dialers #3166

merged 2 commits into from
Feb 3, 2025

Conversation

MarcoPolo
Copy link
Collaborator

closes #3155. @parkan does this work for your use case? See the libp2p_test.go for an example on how to set this up.

@MarcoPolo MarcoPolo requested a review from sukunrt February 1, 2025 18:41
@MarcoPolo MarcoPolo mentioned this pull request Feb 1, 2025
20 tasks
Copy link
Member

@sukunrt sukunrt left a comment

Choose a reason for hiding this comment

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

The change looks good except for some naming preferences.

  1. The pattern is to use the provided Dialer for dialling. So, do we need to name it Custom?
  2. CustomTCPDialer reads like it should be the Dialer not something that returns a Dialer.

type ContextDialer interface {
DialContext(ctx context.Context, network, address string) (net.Conn, error)
}
type CustomTCPDialer func(raddr ma.Multiaddr) (ContextDialer, error)
Copy link
Member

Choose a reason for hiding this comment

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

NIT: DialerForAddr

Comment on lines 121 to 126
func WithCustomDialer(d CustomTCPDialer) Option {
return func(tr *TcpTransport) error {
tr.customDialer = d
return nil
}
}
Copy link
Member

Choose a reason for hiding this comment

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

NIT: WithDialerForAddr

@parkan
Copy link

parkan commented Feb 3, 2025

looking at this today, sorry for the delay

@MarcoPolo
Copy link
Collaborator Author

Thanks @parkan. If this works for you, it'll be included in the next release (hopefully today)

@parkan
Copy link

parkan commented Feb 3, 2025

in practice I think this should work for us 👍

what's mostly on my mind is how similar functionality is already implemented in net.proxy and whether anything in there should be leveraged or used as an example to follow 🤔

looking at it closely RegisterDialerType is actually a good place to inject a http proxy dialer for us, though that doesn't generalize to other dialer behaviors that don't map to Url schemes

(as a side note the onion transport uses net/proxy already: https://github.com/OpenBazaar/go-onion-transport/blob/master/onion_transport.go#L136)

@parkan
Copy link

parkan commented Feb 3, 2025

for example the PerHost functionality is very similar to overrideDialerForAddr

@MarcoPolo
Copy link
Collaborator Author

MarcoPolo commented Feb 3, 2025

I don't want to spend too much time bikeshedding an API that a handful of people will use. I see this as an escape hatch that enables your use case, but not something that most users should use.

With some finangling, I believe the PerHost should work here without any go-libp2p changes.

@MarcoPolo MarcoPolo merged commit 9584246 into master Feb 3, 2025
9 checks passed
@parkan
Copy link

parkan commented Feb 4, 2025

@MarcoPolo totally fair, thank you for getting this in 💪

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.

Custom Dialer for TCP transports
3 participants