This logic collects a list of known relays by testing every new connection.
It exists so we can dial /p2p-circuit/p2p/QmFoobar addresses (circuit addresses
that don't specify the relay). However, this kind of address is useless outside
of basic demos as a random relay is practically guaranteed to not be connected
to the target peer. Picking a random relay to connect to some peer is almost
_never_ the desired behavior.
Instead of feeding through the top-level context, feed through a cancel-free
context (that still carries the same context values). Then, when the top-level
context is canceled, call `stop` to shut everything down in-order. Finally,
cancel the inner context to make sure everything has been cleaned up.
Ideally, we just wouldn't use contexts for this. But this is strictly better
than what we have.
When request is sent to http://localhost:8080/ipfs/$cid response has
HTTP 301 status code and "Location" header with redirect destination at
$cid.ipfs.localhost:8080
Redirect is followed by browsersi, but not by commandline tools.
Status 301 is ignored by curl in default mode: it will print response
and won't follow redirect, user needs to add -L for that.
To fix curl, we return correct payload in body of HTTP 301 response,
but set Clear-Site-Data header to ensure Origin sandbox can't be abused.
This requires a surgical workaround:
If Location header is present in ResponseWriter's Header map,
we ensure http.ServeContent() returns HTTP 301
Context: https://github.com/ipfs/go-ipfs/pull/6982
License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
Instead of adding a new fake header (that could be spoofed by the client...),
just read the original request URI from the request object.
This also removes support for suborigins. They have never been implemented in
browsers and it looks like efforts have stalled. We can add support back if we
need it but, well, maintaining support was going to be more trouble than it was
worth.
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
* Adds the `--parents` optiont to the first command so that it is runnable
* Updates the description to specifies the option to use if you _do_ want nonexistant intermediate directories created
Instead of manually creating multiaddr strings, use the multiaddr logic to
format them. We were still using `/ipfs` multiaddrs instead of `/p2p` multiaddrs.
We've deprecated this system and have yet to move to a new system. We might as
well remove everything, switch to a new system, then deliberately trace the
entire system.
Unfortunately, we don't currently have any way to pick out good relays from bad.
That means we keep searching, trying bad relays, searching some more, trying
_the same relays_, etc. until we randomly find 3 good stable relays. In
practice, this means we just keep searching forever and keep thrashing the DHT.
see https://github.com/libp2p/go-libp2p/issues/694
This will be useful when testing `refs local, `repo gc`, and `repo verify`
commands once we store blocks by multihash instead of by CID. At that point,
these commands will return raw v1 CIDs as the blockstore won't actually remember
the codec used to store the block.
Flags choice:
* Ideally, we'd use the `-f, --format` flags like every other command but we're
already using `-f` (format) for the format string.
* Alternatively, I'd like to use `-c`. However, we're using _that_ for a global
`--config` flag (bit of a waste given that it doesn't work...).
`--codec` will have to do for now.
1. Require files to have known sizes. We can add support for unknown sizes
_later_ but we can't use ServeContent for those files.
2. Replace the `sizeReadSeeker` with a `lazySeeker`. This one makes no
assumptions about how it's used so we're less likely to run into weird bugs.