Commit Graph

563 Commits

Author SHA1 Message Date
Steven Allen 024f1af9ae fix: obey new stream timeout 2020-12-08 14:35:58 -08:00
Steven Allen 7a98f28856 feat: update to go-libp2p-core 0.7.0 interface changes
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`.
2020-11-11 09:35:37 -08:00
vyzo 863439702d add note in godocs about non-closure of active connections to blocked entities. 2020-11-10 18:39:34 +02:00
vyzo e67928b576 word cosmetics 2020-11-10 16:08:28 +02:00
vyzo e6b6f9320b fix tests 2020-11-10 16:06:49 +02:00
vyzo 9ef1f9e49e propagate errors from datastore ops 2020-11-10 16:06:39 +02:00
vyzo 49cca12207 cosmetics 2020-11-10 15:54:42 +02:00
vyzo fd44d15e8d use a RWMutex 2020-11-10 15:53:30 +02:00
vyzo fd7f51887b add test 2020-09-14 15:56:50 +03:00
vyzo 9b78ee25e4 fix typos, add comment 2020-09-14 15:56:43 +03:00
vyzo d4be9c8028 add methods to list blocked entities 2020-09-14 15:25:46 +03:00
vyzo 9ca5c11a9e add support for persistence to datastore 2020-09-14 15:14:22 +03:00
vyzo aa8de6189d basic implementation of connection gater 2020-09-14 14:48:48 +03:00
Steven Allen b95d6ae6fd
Merge pull request #990 from fouge/feat/mdns-ipv6
Added parsing of IPv6 addresses for incoming mDNS requests
2020-08-20 09:55:50 -07:00
Cyril Fougeray 16d314cf30 Deduplicating code when parsing ipv4/ipv6 address; from the comment on the PR 2020-08-20 18:36:07 +02:00
Steven Allen de10591dd8 fix tests
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.
2020-08-19 11:03:55 -07:00
Cyril Fougeray 3fa37a3452 Added parsing of IPv6 addresses for incomming mDNS requests 2020-08-11 15:04:54 +02:00
Will 7cfc4e645e
Bump Autonat version & validate fixed call loop in `.Addrs` (#988)
* add test for host address with attached autonat
* bump autonat release
2020-08-03 14:33:21 -04:00
Steven Allen 717d9e7574 fix: use the correct external address when NAT port-mapping
Previously, we'd construct addresses like `/ip4/.../udp/...` instead of
`/ip4/.../udp/.../quic` because we'd use mapped addr (ip + transport + port)
instead of the full external address (ip + transport + port + other
transports...).
2020-08-03 10:29:26 -07:00
Raúl Kripalani a5786f0415
upgrade deps + interoperable uvarint delimited writer/reader. (#985) 2020-07-30 12:42:57 +01:00
sandman d9a4e38ac4 fix to call PublicAddr interface of AutoNat 2020-07-24 10:12:58 +08:00
sandman a55891f71b add AutoNat PublicAddr when host can be dialed but not get public addr by net.InterfaceAddrs() 2020-07-23 15:19:47 +08:00
Steven Allen 9cd6aaa9ea
Fix address advertisement bugs (#974)
* fix: use all interface addresses when we can't find the default route
* fix: don't add advertise unspecified addresses
* fix: resolve addresses before looking up observed addresses
* fix: only advertise global unicast
* fix: filter link-local addresses from advertisement
* test: fix basic host addr tests
2020-07-07 16:41:45 -07:00
Steven Allen 6a3b138a57
Merge pull request #971 from libp2p/fix/close-deadlock
fix: avoid a close deadlock in the natmanager
2020-06-23 10:21:59 -07:00
Steven Allen 72770db2f6 fix: avoid a close deadlock in the natmanager
Before, we would:

1. Receive a "listen close" event from an event handler, after the teardown started.
2. Try to add a child process to handle the event. This would block because we
were in the teardown.
3. In the teardown, try to unregister the event handler and deadlock

I've now:

* Removed the teardown.
* Switched to a single event loop.

Ideally, we'd remove goprocess entirely. But we'd need to refactor natmgr.

fixes #933
2020-06-22 16:33:19 -07:00
Raúl Kripalani 985120b6f9
upgrade swarm; add ID() on mock conns and streams. (#970) 2020-06-16 19:45:28 +01:00
Steven Allen 1180b6fa1e fix(nat): use the right addresses when nat port mapping
We switched `listenAddrs` from the _interface_ addresses to the raw addresses we
were listening on. Unfortunately, we needed the resolved addresses later in the
function when resolving port mappings.
2020-06-09 15:55:15 -07:00
Steven Allen 34e67e019e Fix peer handler race
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
2020-06-05 10:20:28 -07:00
Steven Allen 5ae0888629 fix(id): document observation struct 2020-06-04 14:57:07 -07:00
Steven Allen a03403fa64 fix: optimize numInbound count
We call this _very_ frequently when computing our local addresses.
2020-06-04 14:55:17 -07:00
Steven Allen 1e4ce46ca7 test(id): fix nits 2020-06-04 14:55:17 -07:00
Steven Allen 1dd7a8c4d4 fix: count observations with at least one inbound connection as inbound
We prefer addresses from inbound connections. We don't want outbound connections
to hide these perfectly good addresses.
2020-06-04 14:55:13 -07:00
Steven Allen 6ca83309d2 fix(mocknet): set inbound/outbound on the right link 2020-06-04 14:55:13 -07:00
Steven Allen a0813d7292 fix: make address observation types private
We don't use and/or expose these anyways. Making them private makes it easier to
reason about their state.
2020-06-04 14:55:10 -07:00
Steven Allen b22add866a fix: remove more field
We no longer need it now that we keep reading till the stream closes.
2020-06-03 15:41:08 -07:00
Aarsh Shah 513e13d0d2 changes as per review 2020-06-03 15:27:03 -07:00
Aarsh Shah c4a1e220ac test large push msgs 2020-06-03 15:27:02 -07:00
Aarsh Shah 60b52f10ae more protocol strings 2020-06-03 15:27:02 -07:00
Aarsh Shah 1b36fd8697 first draft 2020-06-03 15:27:01 -07:00
Aarsh Shah 6b34fff392
fixed compilation error (#956) 2020-05-29 19:55:04 +05:30
Aarsh Shah 3a1d20b748
Filter Interface Addresses (#936)
* Filter Host Addresses
2020-05-29 19:46:58 +05:30
Steven Allen 294ba3dfac
Merge pull request #953 from libp2p/fix/remove-addresses-immediately
fix: remove old addresses in identify immediately
2020-05-27 19:14:33 -07:00
Steven Allen be70fa2460 test: fix test for immediately forgetting addresses 2020-05-27 16:58:53 -07:00
Steven Allen 59062c6d6d fix: remove old addresses in identify immediately
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.
2020-05-27 16:22:39 -07:00
Aarsh Shah 0dd65a5998
fix flaky test (#952)
Fix flaky TestIdentifyPushOnAddrChange
2020-05-21 12:02:29 +05:30
Steven Allen 6ef5f5dacf fix: group observations by zeroing port
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).
2020-05-20 12:13:25 -07:00
Aarsh Shah ba118a4d14 create subscriber first 2020-05-20 15:10:04 +05:30
Aarsh Shah 79ead33e32
Filter observed addresses (#917)
* filter observed addrs
2020-05-20 11:39:45 +05:30
Steven Allen 01da330ef2 fix: don't try to marshal a nil record
fixes #939
2020-05-19 18:15:33 -07:00
Steven Allen aa60461752
Merge pull request #941 from libp2p/test/peer-records-no-listen-addrs
add test to demo missing peer records after listen
2020-05-19 18:10:57 -07:00
Steven Allen e3a983a355 fix: don't leak a goroutine if a peer connects and immediately disconnects 2020-05-19 13:37:52 -07:00
Yusef Napora 82c11bce2a sleep longer in test 2020-05-19 16:15:28 -04:00
Yusef Napora bd9e7b59ce detect listen addr changes in BasicHost 2020-05-19 16:12:56 -04:00
Yusef Napora 3364dccbbf make test fail to demonstrate issue 2020-05-19 14:38:25 -04:00
Yusef Napora 0d6e02e95b add test to demo missing peer records after listen 2020-05-19 14:20:24 -04:00
Aarsh Shah a7671efe6b
no signed peer records for mocknets (#934)
* Disable generation of Signed peer record for Mockenets.
2020-05-19 13:16:54 +05:30
Steven Allen b42ba0faf3
various identify fixes and nits (#922)
* various identify fixes and nits

Co-authored-by: Aarsh Shah <aarshkshah1992@gmail.com>
2020-05-14 17:24:10 +05:30
Aarsh Shah 973933ad7d
Remove race between ID, Push & Delta (#907)
* Solve races between Identify, Push and Delta.
2020-05-13 10:50:37 +05:30
Raúl Kripalani d9d18512ca
fix a compilation error introduced in 077a818. (#919) 2020-05-12 17:24:58 +01:00
Yusef Napora 077a81814f
exchange signed routing records in identify (#747)
*  Exchange signed routing records in identify


Co-authored-by: Aarsh Shah <aarshkshah1992@gmail.com>
2020-04-30 11:06:31 +05:30
Steven Allen 84b923c7bf fix: address code review 2020-04-24 23:54:07 -07:00
Steven Allen 06d9fc7987 fix: keep observed addrs alive as long as their associated connections are alive
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.
2020-04-24 22:55:16 -07:00
Steven Allen d3b7b3b907 test: fix a flaky test 2020-04-24 19:33:19 -07:00
Aarsh Shah 3d676b688c skip test local addr filtering 2020-04-24 19:05:23 -07:00
Steven Allen bd040ba050 fix: refactor logic for identifying connections
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.
2020-04-24 19:05:22 -07:00
Steven Allen 5fa6149ed2
Merge pull request #889 from libp2p/fix/noisy-log-line
fix: reduce log level of a noisy log line
2020-04-17 11:55:36 -07:00
Steven Allen e13a3fe3a3 fix: reduce log level of a noisy log line
This will trigger whenever we're, e.g., offline.
2020-04-17 11:31:17 -07:00
Edgar Aroutiounian 28f45ac904 [discovery] missing defer .Stop on ticker 2020-04-16 19:25:48 -07:00
Will Scott 81302e977a
remote mock addresses won't be unspecified. deprioritize those 2020-04-14 13:37:45 -07:00
Aarsh Shah 615f125342
Remove goprocess from Host (#865)
* remove goprocess from Host
2020-04-06 11:34:45 +05:30
Aarsh Shah e17a6f8bf2 remove lastaddrs as member variable 2020-03-25 00:52:25 +05:30
Aarsh Shah fa575b4d32 changes as per review 2020-03-25 00:35:26 +05:30
Aarsh Shah 82be3ee46f signal address change 2020-03-25 00:10:23 +05:30
Steven Allen c99a5bfa25 test(mock): close the mocknet when fuzzing 2020-03-23 14:27:41 -07:00
Steven Allen 29b355faaa fix(mock): close the mocknet's peerstore 2020-03-23 14:27:16 -07:00
Steven Allen 5403811df9 fix: make sure to close the mocknet's context when canceled 2020-03-23 14:27:04 -07:00
Steven Allen 223cd42251 fix(mock): wait till we add the connection to set it up
Otherwise, we can try to remove it before we add it and panic.
2020-03-23 14:26:16 -07:00
Steven Allen 22232e0d6d fix(mock): fire disconnect notifications async like we do in the swarm 2020-03-23 14:25:38 -07:00
Will Scott 3d4e8d8032
Merge branch 'master' of github.com:libp2p/go-libp2p into feat/autorelay 2020-03-20 16:45:56 -07:00
Aarsh Shah d49806efc9 emit address change evt 2020-03-20 10:04:13 +05:30
Will Scott 685ba00833
update to current autonat interface 2020-03-19 13:27:48 -07:00
Aarsh Shah ed4646f711 local addr updated event 2020-03-19 19:05:15 +05:30
Will Scott 8008b5d58f
update autorelay to remove dependence on autonat
instead, learns nat status through event bus
2020-03-16 16:11:23 -07:00
Will Scott 89c193e0ca
Merge branch 'master' into feat/autorelay 2020-03-10 11:53:55 -07:00
Steven Allen 5f75aa2068 feat(mock): reliable notifications
* Export StreamComplement/ConnComplement convenience functions.
* Make the TestNotifications test pass reliably, even when we have a bunch of
streams (identify, etc.).
* Make the mock net order disconnect events after connect events.
* Make closing one side of a connection actually close both sides.
* Make it possible to extract a mock stream's complement.
* Fire remote events at the same time as the local events.
2020-03-09 17:15:01 -07:00
Steven Allen 4ccf017104
Merge pull request #820 from libp2p/fix/remove-goroutine
fix: remove an unnecessary goroutine
2020-03-06 22:52:41 -08:00
Will Scott 0458b76abb
update to changed event structure 2020-03-05 09:12:57 -08:00
Steven Allen 6cdc404180 fix: remove an unnecessary goroutine
The stream handler runs in a goroutine anyways. We might as well block it.
2020-03-02 15:51:36 -08:00
Hlib 5e30cdeaac use of mux.ErrReset 2020-02-28 17:21:51 +02:00
Will Scott 85a83edf80
defer subscription closes 2020-02-27 10:10:42 -08:00
Will Scott f5386bdf79
autorelay triggers on NAT events
better use of the event bus between these two
2020-02-26 19:38:50 -08:00
Steven Allen 7ba322244e emit identify events and avoid advertising localhost
* 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>
2020-02-21 12:45:25 -05:00
Steven Allen 9ee9d94ea2
chore(ci): fix a flaky test (#787)
Timing tests never work well in CI.
2020-02-05 18:05:37 +00:00
Steven Allen 76944c4fc8
Merge pull request #705 from libp2p/feat/static-relays
options to configure static relays for autorelay
2020-01-17 05:22:16 -08:00
optman 3f43dfe646 enable non-public address port mapping announcement 2020-01-15 18:38:39 +08:00
Steven Allen 9073eaaf8f fix: demote stream deadline errors to debug logs
Otherwise, we spam an error every time we try to negotiate a protocol on a
closed stream (e.g., when the underlying connection closes on us).
2020-01-03 09:14:43 -08:00
Steven Allen e5d28696f5 feat(host): recursively resolve addresses
We currently only resolve /dnsaddr addresses once. This patch resolves up to 32
dnsaddr addresses per dial.

fixes https://github.com/libp2p/go-libp2p/issues/744
2019-12-16 15:53:51 +01:00
Hector Sanjuan 7e49c66219 Identify: Make activation threshold configurable
Also: fix the comments and try to explain how the activation/aliveness of
addresses happen (and write the correct defaults).
2019-11-05 12:18:55 +01:00
Steven Allen 94d7efc58e chore(dep): update libp2p-core and protobuf
* Enforces 2048 bit RSA keys when using OpenSSL
* Updates go-multiaddr-dns for /dns support.
* Update gogo/protobuf and regenerate all protobufs.
2019-10-28 16:41:54 -07:00
vyzo 9cd56c0bab use a global variable for default relays
and rename DefaultRelays option to DefaultStaticRelays.
2019-10-08 13:01:29 +03:00