-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Peer dialing to self #328
Comments
perhaps we should have a virtual network interface for this? |
If you point me to the right repos, I can put it on my to-do list |
@Stebalien thoughts and pointers? |
So, we'd have to be very careful here. All of our services (DHT, bitswap, identify, etc.) will break if we start dialing ourself. Somewhat off topic... We may need some form of "self dial" in the future for a libp2p daemon however, it won't look like a true self-dial. Basically, given a daemon and some service registered to handle protocol A, the some other local service may ask the daemon to dial itself and then speak protocol A. However, this is really just a special case that needs to be handled by the libp2p daemon dialer proxy. |
I need it, now.. Happy if it is a non-default option. |
@hsanjuan @Stebalien Would this have a special API (i.e. |
We want to be able to dial our own peer ID. |
In my experience, self-RPCs tend to cause more trouble than they're worth (mostly deadlocks). I assume you're trying to vote for yourself? The correct way to do this is to just vote for yourself internally before sending any RPCs. You should be doing this anyways so that you don't ask a bunch of peers to vote for you but then end up voting for a different peer. Basically, we can support this but I don't want to build you a footgun. |
I didn't implement Raft, we just plugged-in the libp2p transport. I haven't looked exactly why it tries to contact itself, but it does and produces a continues stream of errors (even if it seems to work as normal). The thing is you normally you do We handled this "doing things internally" in cluster for cluster RPC, but things would be nicer if the shortcut happened in libp2p. |
@hsanjuan so, I take it this is blocking you? |
@Stebalien not blocking me, but I'd like to address it rather sooner than later. I'm willing to take the stab if given a few pointers. |
Pointers:
Given the fact that the connection is immortal, we'll have to be careful with things that expect to be able to close it. |
This issue prevents filecoin miners from making deals with themselves, which is functionality that we'd really like to support. We'd love to be able to dial self to enable that functionality, see filecoin-project/venus#1917. |
Solution proposalFirst of all, let me point out that self-dialling sounds like a bit of a smell. There are usually more efficient ways of carrying out a transaction with yourself (by tackling this in business logic). However, I do recognise that requires special casing based on identity, so I lean towards providing a solution inside libp2p seeing that two projects already require this functionality, so there's likely more to come. In projects like Apache Camel, such abstraction was achieved by a special in-memory transport. We can find inspiration in that. Concretely I propose the following high-level design:
@Stebalien @hsanjuan – thoughts? |
How should |
@Stebalien IMO If self-dialling is enabled host-level:
EDIT: added more colour in point 2. |
SGTM. Maybe we should just throw away |
Seems redundant to have to declare the peer as self-dialing, and then the protocols, from a user point of view. Allowing or disallowing stream handling depending on its source sounds very much like adding an authorization mechanism (which could be generalized into whitelist/blacklists?). I don't know if there is a use-case for declaring a peer as self-dialable and then disallowing most protocols. Unless we are scared of current protocols causing some unintended breakage, we can just simply process those streams as normal (when self-dialing is enabled for the host). The user can always choose to abort such stream their handlers, as needed. This would also simplify implementation a little bit. In any case, the proposed solution also works for us. |
The rationale is that protocol handlers rely on the assumption that incoming streams are never local. Suddenly allowing any protocol to receive local streams is a breakage of implied contract, and will cause regressions. Some of those protocols we control within libp2p (DHT, Pubsub, Relay); most we don’t. That’s why — IMO — protocols should opt into this behaviour. |
Honestly, we should fix these services. Really, I think the main issue is that we need:
That should fix most of the issues around dialing self. |
Loopback AddressWhile we're talking about loopback functionality, if we decide to implement loopback functionality to those IPFS commands/RPCs that don't support it but could, it is worth considering whether we should also introduce a dedicated loopback address, similar to the way IP has the localhost name or 127.0.0.0/8 address space as loopback addresses. Here are some ideas, feel free to come up with other cooler suggestions: /p2p/self |
Is it do-able to enable peers to dial themselves?
We have Raft using a libp2p-transport and it wants to dial itself all the time. It does not seem to cause undesired side-effects, but it does not seem crazy that any cluster-application using RPCs ends up trying to contact itself for some things. (same issue in ipfs-cluster RPC, but we worked around it).
Perhaps we can provide some shortcut at a higher level so that a peer contacting itself does not even attempt touch the network?
Pointers appreciated...
The text was updated successfully, but these errors were encountered: