-
-
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
fix(swarm): add dnsaddr support in swarm connect #5535
Conversation
a282768
to
b794220
Compare
core/commands/swarm.go
Outdated
if err != nil { | ||
return nil, err | ||
} | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
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've looked through this whole PR and everything makes sense to me 👍. I do have a question about how these timeouts are specified in go-ipfs (both here and more generally). I notice lines like the following (and there are a handful):
https://github.com/ipfs/go-ipfs/blob/master/core/bootstrap.go#L60
And also lines like yours (e.g.):
https://github.com/ipfs/go-ipfs/blob/master/core/commands/pubsub.go#L178
Is there a rule of thumb for deciding when to specify these timeouts with a name vs inline?
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.
Well, we should probably name this. We just get lazy sometimes.
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, this subtly changes some important semantics. Now, if I run ipfs swarm connect /dnsaddr/a.b.c/ipfs/QmPeer
, we'll insert the resolved addrs into the peerstore instead of the dnsaddr. That means future connects won't try resolving the dnsaddr again. They'll instead use the resolved addresses, never learning about any changes to this DNS record.
I wonder if we should instead:
- For each address that doesn't end in
/ipfs/Qm...
, resolve it. - After resolving it, parse it but ignore everything but the peer ID.
- Create a IPFSAddr structs out of the original (unresolved) dnsaddrs and these peer IDs.
core/commands/swarm.go
Outdated
if err != nil { | ||
return nil, err | ||
} | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
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.
Well, we should probably name this. We just get lazy sometimes.
core/commands/swarm.go
Outdated
return nil, err | ||
} | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
raddrs, err := madns.Resolve(ctx, maddr) |
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.
Can we parallelize this?
core/commands/swarm.go
Outdated
if len(raddrs) == 0 { | ||
return nil, fmt.Errorf("non-resolvable multiaddr about %v", maddr) | ||
} | ||
maddrs = append(maddrs, raddrs...) |
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 believe we may need to filter out addresses that still don't end in /ipfs/Qm...
.
Maybe this has changed, but do unresolved addresses in the peerstore get resolved when building a connection? My impression when I was testing this a while ago is they didn't. I remember a discussion or PR in which @lanzafame was involved (??) suggesting to do this at a lower level in libp2p. A few months back, addresses were only resolved in So might be better off storing resolved addresses for the moment? |
Ah... No, they don't. That's broken. Yeah, you're right. But we should really fix this. We don't even do routing on that path. |
@Stebalien Did you mean that if address ends in However, I don't think it will solve the issue as mentioned:
|
3b0b8f8
to
a448431
Compare
@Stebalien I had made some changes according to your suggestion. |
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.
Sorry for the delay, I've been trying to push through a change that will make it easier to do this correctly (although, in retrospect, it was always possible).
core/commands/swarm.go
Outdated
return nil, err | ||
} | ||
// check whether address ends in `ipfs/Qm...` | ||
if _, err := maddr.ValueForProtocol(ma.P_IPFS); err != ma.ErrProtocolNotFound { |
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.
Sorry for the delay, I've been trying to push through a change to make this check more robust. You can now use:
if _, last := ma.SplitLast(maddr); last.Protocol().Code == ma.P_IPFS {
maddrs = append(maddrs, maddr)
continue
}
The current check will trip over relay addrs. That is, /p2p/QmRelayId/p2p-circuit/dnsaddr/foo.com
will pass the check but doesn't end in /p2p/QmTargetId
.
core/commands/swarm.go
Outdated
// filter out addresses that still doesn't end in `ipfs/Qm...` | ||
for _, raddr := range raddrs { | ||
if _, err := raddr.ValueForProtocol(ma.P_IPFS); err != ma.ErrProtocolNotFound { | ||
maddrs = append(maddrs, raddr) |
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 is going to be racy. We should probably be using a channel and collecting these in a central location.
core/commands/swarm.go
Outdated
} | ||
// filter out addresses that still doesn't end in `ipfs/Qm...` | ||
for _, raddr := range raddrs { | ||
if _, err := raddr.ValueForProtocol(ma.P_IPFS); err != ma.ErrProtocolNotFound { |
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 need the same "is an IPFS address as the one I suggested above")
a448431
to
c25ad4f
Compare
04a410b
to
66be4f4
Compare
@Stebalien Thx your advice, i had fixed it. |
66be4f4
to
f6d8c07
Compare
f6d8c07
to
38aeedf
Compare
License: MIT Signed-off-by: Overbool <overbool.xu@gmail.com>
License: MIT Signed-off-by: Overbool <overbool.xu@gmail.com>
38aeedf
to
4826173
Compare
4826173
to
393a67b
Compare
License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
393a67b
to
5fc7b02
Compare
Fixes: #5522
License: MIT
Signed-off-by: Overbool overbool.xu@gmail.com