-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Circuit Relay integration #4091
Conversation
summning @whyrusleeping @Stebalien |
iptb testing scenario:
|
Rebased on #4094. |
Added a test/sharness script that implements the iptb scenario described above. |
More iptb interaction: verify the connection works:
I will extend the sharness test to verify the connection. |
I think it's ready for review. |
core/commands/swarm.go
Outdated
if strings.Contains(info.Addr, "/p2p-circuit/") { | ||
fmt.Fprintf(buf, "%s", info.Addr) | ||
} else { | ||
fmt.Fprintf(buf, "%s/ipfs/%s", info.Addr, info.Peer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats the purpose of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The address already contains the peer id in this case.
It's of the form .../p2p-circuit/ipfs/QmId
, so pasting the peer id again would result in the address formatted as .../p2p-circuit/ipfs/QmId/ipfs/QmId
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you want me to add a comment to that extent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hrm... that feels a bit weird. @Kubuxu @lgierth @Stebalien thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expect RemoteMultiaddr
to return just the /ipfs/QmProxy/p2p-circuit
part, not the final /ipfs/QmId
. As-is, this is inconsistent with TCP/IP addresses. Is there a technical reason not to do it this way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we actually need it: the address reported by Conn.RemoteMultiaddr should be dialable, and the partial address won't be.
I will add a comment here explaining why we need this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically /ipfs/QmId
serves two purposes:
- Routing information: An alias for an internet address (stored in the DHT):
/ip4/xxx.xxx.xxx.xxx/tcp/1234
- Identity information: The key of the target machine.
In the RemoteMultiaddr
case, the second ipfs
address is routing information.
We'd actually run into the same problem something returned /ipfs/QmId
as the entire RemoteMultiaddr
(which would actually make sense if you had a lower-level VPN that understood IPFS addresses).
Actually, that brings up a good point. Maybe we should just be checking to see if the last address is an /ipfs/
address (i.e., the multiaddr ends in /ipfs/QmId
) and, if it is, assert that the QmIds
match instead of appending something. Thoughts @vyzo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should just be checking to see if the last address is an /ipfs/ address (i.e., the multiaddr ends in /ipfs/QmId) and, if it is, assert that the QmIds match instead of appending something.
That's perhaps the generic case to handle routing addresses similar to how circuit reports address.
So instead of checking if it is a p2p-circuit address, check if it ends with the /ipfs/peerId
and if so only append if it doesn't match.
Sure, we can do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed the check to look for the /ipfs/QmPeer
suffix in the remote multiaddr.
If the suffix is present, then it doesn't duplicate it, otherwise it appends /ipfs/QmPeer
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure we need a comment any more, it's not p2p-circuit specific and the code is self-explaining.
Rebased on master. |
1d60f08
to
e9fa416
Compare
Reverted: libp2p/go-libp2p-circuit#7 |
Upon discussion with @Stebalien on irc we concluded that it is important to keep the invariant that multiaddrs returned by |
core/core.go
Outdated
} | ||
return raddrs | ||
} | ||
hostOpts = append(hostOpts, p2pbhost.AddrsFactory(filterRelayAddr)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if we have multiple address factories in the hostOpts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We would need to compose them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want me to add scaffolding for the composition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, Since we're going to be using the address factory pretty soon anyways for limiting which addresses we announce: #3948
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will need to add the AddrsFactory
option to ConstructPeerHostOpts
in order to scaffold the composition properly.
Then we have two options for the composition: filter first or announce factory first. It makes some sense to use the filter first, the announce factory might actually want to announce some relay addresses in the future. On the other hand it also makes sense for the announce factory to see the p2p-circuit relay address, so that it knows that relay is activated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nonetheless, the announce factory can also tell whether relay is in use from the swarm options already, so the latter argument is not all that compelling.
So the filter should be applied before the announce address factory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the scaffolding for address factory composition in 231f8e4:
- added an AddrsFactory option to ConstructPeerHostOpts
- composed the specified address factory with the relay filter when present
thirdparty/ipfsaddr/ipfsaddr.go
Outdated
@@ -106,6 +107,13 @@ func ParseMultiaddr(m ma.Multiaddr) (a IPFSAddr, err error) { | |||
|
|||
func Transport(iaddr IPFSAddr) (maddr ma.Multiaddr) { | |||
maddr = iaddr.Multiaddr() | |||
|
|||
// /ipfs/QmId is part of the transport address for p2p-circuit | |||
_, err := maddr.ValueForProtocol(circuit.P_CIRCUIT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would prefer if we at least put a TODO here to clean this up. We need to rethink (later, not now) how addresses get composed and consumed so that we don't have to have this special case here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, will add a TODO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added TODO comment in a11f632
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we could just stop distinguishing between the transport part and the application part. Multiaddrs don't really have a clear transport/application layer separation (they can have transport -> application -> transport -> transport -> application, etc...).
Instead, we could either:
a. Have dialers recursively dial (dial the parts they understand and then recursively call the "main" dialer to dial the rest).
b. Dial like we resolve through IPLD objects and return an intermediate transport + the rest of the undialed path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This LGTM for the most part, some questions around host construction, and the special casing of relay multiaddrs still weirds me out. But thats probably okay to figure out later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good to me. Just a question on configuration/documentation.
@@ -221,5 +221,12 @@ improvement, as well as a reduction in memory usage. | |||
- `DisableNatPortMap` | |||
Disable NAT discovery. | |||
|
|||
- `DisableRelay` | |||
Disables the p2p-circuit relay transport. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this disable relays entirely or just disable listening on relayed addresses? There are three cases:
- Listen using relays.
- Act as a relay.
- Connect to nodes through relays.
It would be nice to be able to enable/disable these independently. Can we currently do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting to true will disable the relay transport entirely.
The DislableRelay
controls option 1 and 3, so by default we listen for relay connections and we can connect to peers through relay.
In order to act as a hop relay (2), you need to EnableRelayHop
, in addition to having the relay transport enabled.
I don't think it makes sense to have more fine-grained independent configuration, as we can't really separate listening from dial (and do we really want to do that?) and we already have an option to control hop relaying.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed on IRC, I misunderstood what these toggles did. DisableRelay disables relaying entirely and we don't yet support advertising relayed addresses; when implemented, that will probably have an additional toggle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's the plan.
- enabled by default, so that we can dial/receive dials - /p2p-circuit/QmId address is not announced; filtered at host with AddrsFactory - use case is manual swarm connect with relay address License: MIT Signed-off-by: vyzo <[email protected]>
License: MIT Signed-off-by: vyzo <[email protected]>
License: MIT Signed-off-by: vyzo <[email protected]>
License: MIT Signed-off-by: vyzo <[email protected]>
Handles p2p-circuit addresses and any other address that uses a similar routing scheme. License: MIT Signed-off-by: vyzo <[email protected]>
License: MIT Signed-off-by: vyzo <[email protected]>
- Adds AddrsFactory to ConstructPeerHostOpts - Composes the AddrsFactory option with the relay filter License: MIT Signed-off-by: vyzo <[email protected]>
License: MIT Signed-off-by: vyzo <[email protected]>
integrate #3948 License: MIT Signed-off-by: vyzo <[email protected]>
Necessary for meaningful semantics in the presence of address filtering. License: MIT Signed-off-by: vyzo <[email protected]>
License: MIT Signed-off-by: vyzo <[email protected]>
License: MIT Signed-off-by: vyzo <[email protected]>
License: MIT Signed-off-by: vyzo <[email protected]>
License: MIT Signed-off-by: vyzo <[email protected]>
License: MIT Signed-off-by: vyzo <[email protected]>
Rebased on master and fixed the conflict. |
License: MIT Signed-off-by: vyzo <[email protected]>
9c22ded
to
b6150b2
Compare
@whyrusleeping this is ready to merge. |
Merged! ipfs has relay support!! Thank you @vyzo! |
@vyzo do you think you could write up a small doc on how to use the relay feature? That would be immensely helpful to have |
Sure! Where should it live though? |
|
#4148 adds documentation in docs/experimental-features.md |
#4090 Integrates circuit relay as a transport, enabled by default.
Notes:
Rebased on top of gx: update deps #4094. requires up-to-date go-libp2p. [BLOCKED]Adds the following options to swarm configuration options: