This patch updates go-libp2p for the stream interface changes in go-libp2p-core
0.7.0. This is a _significant_ breaking change to streams and all users should
read https://github.com/libp2p/go-libp2p-core/releases/tag/v0.7.0. In practice,
this change should remove a significant footgun.
TL;DR:
* `Stream.Close` now behaves like `net.TCPConn.Close`.
* There is a new `Stream.CloseWrite` (send an EOF) and `Stream.CloseRead` (close
for reading), behaving like their counterparts in `net.TCPConn`.
1. Fix tests on go 1.15 by avoiding `string(i)`.
2. Fix the autorelay test by making relays announce fake "public" addresses. I'm
not sure how this worked before.
Alternative to #963. Instead of using atomics, this patch ensures that all state
changes are performed on the main thread. It also:
* Threads the context through explicitly to make sure fields changed by the main
thread are never read by the handler goroutines. This isn't strictly necessary
but it makes it easier to reason about.
* Uses a callback to signal "on done". There may be cleaner ways to do this (I
hate callbacks), but this nicely decouples the peer handler from the main loop.
fixes#963
Previously, we'd keep addresses discovered through the DHT for up to 2
minutes (temporary TTL) and previously seen addresses (recently connected) for
up to 10 minutes (the TTL).
1. Make sure to downgrade both connected and recently connected addresses to the
"temporary" ttl before adding new addresses.
2. Finally, downgrade addresses with the temporary TTL to 0.
This could be more efficient with a better peerstore abstraction, but this is
better than nothing.
In #917, we started dropping additional address observations if we had multiple
for the same transport set. However, on further consideration, this isn't quite
correct. We _want_ to keep additional observations for multiple IP addresses.
The real issue is many observations for different ports.
So this patch simply changes the key with which we group observations from
"address protocols" to "address without the port" (well, with the port set to
0).
Otherwise, if we're not creating new connections, we'll eventually forget them.
Up until now, this wasn't _too_ much of an issue because our peers would still
remember our addresses. However, we now _tell_ our connected peers when our
addresses change. That means we'll tell our peers to forget where we are,
preventing anyone from finding us.
0. NEVER call `peerstore.SetProtocols(p)` (clear the protocol set). Given the
new identify events, if someone looked in the peerstore at the wrong time, they
could decide that the peer no longer speaks some protocol.
1. Reliably wait for identify before trying to open a stream. The old logic was
_really_ racy.
2. Avoids potentially calling identify on the same connection multiple times.
3. Calls identify as early as possible. Previously, we'd invoke identify on
inbound connections using an event that was only invoked _after_ all `Connected`
event handlers completed. Now we invoke identify from a `Connected` handler.
* fix(identify): announce localhost as long as one side of the connection is local (#742)
* identify: emit events on completion/failure. (#660)
* identify: Update addr advertise logic to exclude localhost addrs… (#657)
This is a rollup of the stabilize fixes.
Co-authored-by: bigs <cole@protocol.ai>
Co-authored-by: Raúl Kripalani <raul@protocol.ai>
Instead of using a global variable.
This also:
* Adds an option to the identify service to set the user agent.
* Removes the ability to pass an identify service to NewHost as any reasonable
Identify service already needs to be constructed with an instance of the host.
We still tell the remote host about the observed addr but we don't store it.
That way, we give them a chance to decide if they want to actually use and
advertise it.
Ideally, we'd distinguish between local information and signed routing
information but we don't do that yet.
This should reduce the address explosion issue where peers learn about
multiple (bad) observed addresses for the same peer. It should also give peers
more control over how they can be dialed.
Sending a protocol version is nice. However, this "disconnect if our versions
are different" logic makes the version entirely useless (because we can't change
it).
Really, each indevidual protocol is versioned so let's just leave it at that. If
we make a breaking change that requires a protocol bump, we can do that and
then switch on the other side's version. However, we'll have to wait for the
entire network to upgrade for that to work.
fixes#419
Also call FullClose in a goroutine; no need to block this.
(not happy with that but I'm starting to think we need to rethink stream
closing, again...)
This happens all the time in tests where we intentionally use fake keys for
performance.
Anyways, users probably don't want their logs spammed with errors they can't do
anything about.
This commit prevents us from repeatedly extending the lifetimes of all observed
addresses if a peer keeps on reconnecting.
It also fixes two race conditions:
1. We may end up processing a disconnect after a re-connect and may
accidentally give the addresses associated with that peer a
RecentlyConnectedAddrTTL instead of a ConnectedAddrTTL.
2. We may end up processing a connect after the associated disconnect storing
the associated peer addresses indefinitely.