Commit Graph

203 Commits

Author SHA1 Message Date
galargh 50f065b4df chore: fix revive issues 2025-06-11 10:00:47 +01:00
sukun 5e6f217d84 addrsmanager: extract out addressing logic from basichost (#3075)
Benchmark for AllAddrs:

```
goos: linux
goarch: amd64
pkg: github.com/libp2p/go-libp2p
cpu: AMD Ryzen 7 7840U w/ Radeon  780M Graphics
BenchmarkAllAddrs-16               16737            122245 ns/op           21240 B/op        218 allocs/op
```
after:
```
goos: linux
goarch: amd64
pkg: github.com/libp2p/go-libp2p
cpu: AMD Ryzen 7 7840U w/ Radeon  780M Graphics
BenchmarkAllAddrs-16            11103236               105.7 ns/op           192 B/op          1 allocs/op
```
2025-02-27 22:24:57 +05:30
Marco Munizaga 785181fbb8 chore: Update go-multiaddr to v0.15 (#3145) 2025-02-24 14:21:47 -08:00
sukun f88beca8d5 basichost: add certhashes to addrs in place (#3200) 2025-02-18 13:19:00 -08:00
sukun 914331ba90 autorelay: send addresses on eventbus; dont wrap address factory (#3071) 2025-02-18 18:36:17 +05:30
sukun 02ab795c92 Implement error codes spec (#2927) 2025-02-09 21:39:18 +05:30
Ivan Shvedunov 8423de3a64 basichost: avoid modifying slice returned by AddrsFactory (#3068) 2024-11-28 22:02:47 +05:30
Marco Munizaga c31f093851 fix: basichost: Use NegotiationTimeout as fallback timeout for NewStream (#3020) 2024-11-04 09:42:44 -08:00
sukun b9cb861a98 autonat: fix interaction with autorelay (#2967)
* autonat: fix interaction with autorelay

* Fix race in test

* Use deadline from context if available for DialBack

* Return hasNewAddrs correctly

* nit: cleanup contains check

* Shuffle peers

* nits

* Change comment to indicate the bug

* holepuncher: pass address function in constructor (#2979)

* holepunch: pass address function in constructor

* nit

* Remove getPublicAddrs

---------

Co-authored-by: Marco Munizaga <git@marcopolo.io>

* Make a copy of the multiaddr slice in Addrs()

---------

Co-authored-by: Marco Munizaga <git@marcopolo.io>
2024-10-16 20:08:43 -07:00
Marco Munizaga e8b6685edb fix: swarm: refactor address resolution (#2990)
* Remove unused resolver in basic host

* Refactor Swarm.resolveAddrs

Refactors how DNS Address resolution works.

* lint

* Move MultiaddrDNSResolver interface to core

* Reserve output space for addresses left to resolve

* feat: core/transport: Add SkipResolver interface (#2989)

* Rebase on top of resolveAddrs refactor

* Add comments

* Sanitize address inputs when returning a reservation message (#3006)
2024-10-16 12:20:21 -07:00
Marco Munizaga c79cf3653d Add backoff for updating local IP addresses on error (#2999) 2024-10-16 12:12:51 -07:00
sukun c2556325d5 basichost: ensure no duplicates in Addrs output (#2980) 2024-10-03 10:43:59 +05:30
Marco Munizaga 9038a72c48 peerstore: better GC in membacked peerstore (#2960)
---------

Co-authored-by: sukun <sukunrt@gmail.com>
2024-09-17 23:49:53 +05:30
sukun 8a11b7c8e4 basic_host: close swarm on Close (#2916)
Using the `BasicHost` constructor transfers the ownership of the swarm.
This is similar to how using `libp2p.New` transfers the ownership of
user provided config options like `ResourceManager`, all of which are
closed on `host.Close`
2024-08-15 18:18:35 +05:30
Marco Munizaga 0cc0b2fba7 ObsAddrManager: Infer external addresses for transports that share the same listening address. (#2892)
* Remove this hack, the new observed address manager just works

* Infer addresses that share the same local thin waist

* Use Interface listen address as well
2024-08-01 16:05:04 -07:00
sukun f80d18f24c config: fix AddrFactory for AutoNAT (#2868)
---------

Co-authored-by: Marco Munizaga <git@marcopolo.io>
2024-07-31 16:56:32 +05:30
sukun 76b266558b basichost: reset stream if SetProtocol fails (#2875) 2024-07-18 17:38:25 +05:30
sukun c88d0a0d89 basichost: reset new stream if rcmgr blocks (#2869) 2024-07-11 22:52:41 +05:30
sukun ee0ac60d3f autonatv2: add server metrics for dial requests (#2848) 2024-07-02 16:00:52 +05:30
sukun 87c435512c autonatv2: implement autonatv2 spec (#2469) 2024-06-21 14:55:22 +05:30
sukun 6861cecb3c identify: refactor observed address manager to do address mapping at thin waist(IP+TCP/UDP) layer (#2793)
* refactor observed address manager to do mapping at thin waist layer

---------

Co-authored-by: Marco Munizaga <git@marcopolo.io>

* restrict output message size, add top level option to disable address
discovery

* Comment nit

* Increase maxPeerRecordSize

---------

Co-authored-by: Marco Munizaga <git@marcopolo.io>
2024-05-15 20:17:25 -07:00
sukun 01ce97c730 webrtc: add webrtc addresses to host normalizer (#2784) 2024-05-08 15:52:01 +05:30
Steven Allen af0161e83e Add a "Limited" network connectivity state (#2696)
Rename the Transient state on connection to Limited. This is more appropriate and also 
doesn't conflict with the transient resource manager scope.

Adds a Limited connectedness state for peers connected to us over Limited connections. 
This allows  users to ignore such peers if they are interested in only peers connected to 
us over Unlimited connections. 

For some peers who disconnect before we sent a Connectedness event, we will now 
only send a Disconnected event. 
---------

Co-authored-by: guillaumemichel <guillaume@michel.id>
Co-authored-by: sukun <sukunrt@gmail.com>
Co-authored-by: Marco Munizaga <git@marcopolo.io>
2024-05-08 15:51:22 +05:30
sukun 0385ec924b basichost: append certhash for webrtc addresses provided via address factory (#2774) 2024-04-23 17:12:01 +05:30
Marten Seemann 9d149fa3cb use Fx to start and stop the host, swarm, autorelay and quicreuse (#2118)
* config: refactor AutoNAT construction into separate method

* config: use a lifecycle hook to start listening on swarm addresses

* use Fx to construct the host

* add a test for constructing a routed host

* use Fx hooks to start the host

* config: use Fx lifecycle hooks to start AutoRelay and for PeerRouting

* basichost: don't close the swarm

The swarm is not constructed by the basic host, thus is shouldn't be
closed by it.

* config: use Fx hook to close the quicreuse connection manager

* test for goroutine leaks when starting/stopping fx

To do this, I've had to move a few leaky tests into a separate package.
I've filed a bug for the AutoNAT issue (#2743) but the "error on
startup" issue is going to require some pretty invasive changes (we need
to construct _then_ start).

* go fmt

* Ignore one more top function

* Typo

* Ignore any not top

---------

Co-authored-by: Sukun <sukunrt@gmail.com>
Co-authored-by: Steven Allen <steven@stebalien.com>
Co-authored-by: Marco Munizaga <git@marcopolo.io>
2024-03-21 10:18:34 -07:00
zhiqiangxu e416c52172 basichost: log more info when protocol selection fails (#2734) 2024-03-21 09:08:25 +05:30
shuoer86 3089ac3061 chore: fix typos (#2608)
Co-authored-by: Sukun <sukunrt@gmail.com>
2023-11-18 15:03:52 +03:00
Marten Seemann 284469128b pstoremanager: fix race condition when removing peers from peer store (#2644) 2023-11-17 15:22:06 +07:00
Sukun f5493140ff swarm: cleanup stream handler goroutine (#2610) 2023-10-19 21:09:40 -07:00
Marten Seemann dce942454b basichost: handle the SetProtocol error in NewStream (#2555) 2023-09-04 17:03:24 +05:30
Jorropo 2398ba4fac cleanup: add continue in case of failure in the (*BasicHost).Addrs certhash loop (#2492)
This does not do change anything because the transport always returns the same multiaddr you passed in in case of failure, it just looks wrong and relies on a obscure detail of the webtransport's AddCertHashes function, while this does not.
2023-08-16 09:24:41 -07:00
Jorropo d46e631f8b basichost: use byte representation of WebTransport multiaddr as map key (#2494) 2023-08-16 06:20:06 -07:00
Sukun 260b9695ca basichost: remove invalid comment (#2435) 2023-07-20 00:19:03 +05:30
Marten Seemann 63fdb48cfb update go-multiaddr to v0.10.1, use Unique function from there (#2407) 2023-07-11 01:50:50 +05:30
VM 8e341f7936 docs: fix some comments (#2391)
Co-authored-by: DylanYong <dylan.y@nodereal.io>
2023-06-28 10:12:31 -07:00
Hlib Kanunnikov e5334ed296 basichost / blankhost: wrap errors (#2331) 2023-06-27 11:21:32 -07:00
Sukun f87f6dbca8 nat: add HasDiscoveredNAT method for checking NAT environments (#2358)
* nat: add HasNAT method for checking NAT environments

* rename to better variable
2023-06-12 11:01:17 -07:00
Sukun 73c34f98da holepunch: add metrics (#2246)
* holepunch: add metrics

* don't track addresses

* add cancelled and no_suitable_address state

* separate holepunch dashbords by transport

* fix dashboard fields

* add instance filter to dashboard

* initialise metrics labels with 0

* fix panel names in dashboard

Co-authored-by: Marten Seemann <martenseemann@gmail.com>

---------

Co-authored-by: Marten Seemann <martenseemann@gmail.com>
2023-06-05 05:41:26 -07:00
Marten Seemann 0f9ad8c242 revert "feat:add contexts to all peerstore methods (#2312)" (#2328) 2023-06-03 16:55:08 +03:00
Prem Chaitanya Prathi 8864d1c33e feat:add contexts to all peerstore methods (#2312) 2023-06-03 02:24:50 -07:00
Marco Munizaga e89814c520 swarm: Dedup addresses to dial (#2322)
* Dedup addresses to dial

Co-authored-by: Aayush Rajasekaran <arajasek94@gmail.com>

* Move DedupAddrs test

* Typo

---------

Co-authored-by: Aayush Rajasekaran <arajasek94@gmail.com>
2023-06-02 13:26:28 -07:00
Marco Munizaga 1f7b0d2add transport integration tests: add tests for resource manager (#2285)
* Remove duplicate `SetProtocol` call

* Don't log if transport ErrListenerClosed

* Close the conn scope in webtransport dial

* Mock resource scope span

* Add transport rcmgr integration test

* PR nits

* Fix flakiness

* Threadsafe way of waiting for all streams

* Expand comment
2023-06-01 01:19:31 -07:00
Marten Seemann b456165430 webtransport: only add cert hashes if we already started listening (#2271) 2023-05-05 11:09:12 -07:00
Marten Seemann 4ee60e39d0 move more of the NAT mapping logging to the NAT manager 2023-04-14 14:31:24 +02:00
Marten Seemann 1ad214650c nat: replace alloc-heavy nat.Mapping with explicit GetMapping method 2023-04-14 14:31:21 +02:00
Marco Munizaga fbf11bc5c0 Infer public webtransport addrs from quic-v1 addrs. (#2251)
* Infer external webtransport addrs from external quic addrs

* Infer external webtransport addrs from external quic addrs is now pure

* Remove ConnManager method

* Nits

* Dedupe addrs

* Revert "Dedupe addrs"

This reverts commit b63155f4a3997d7adfebc337d0262defca329c15.

* Assume input is deduped
2023-04-12 14:44:48 -07:00
Marten Seemann 7dc3b81a0a basichost: don't allocate when deduplicating multiaddrs (#2206)
* basichost: don't allocate when deduplicating multiaddrs

* fix sort.Slice less comparison

Co-authored-by: Marco Munizaga <git@marcopolo.io>

* interop: don't send loopback addrs

---------

Co-authored-by: Marco Munizaga <git@marcopolo.io>
2023-04-12 11:51:01 -07:00
Marco Munizaga 3b3f8baf93 correctly handle WebTransport addresses without certhashes (#2239)
* Add helpers to transform webtransport multiaddrs in AddrsFactory

* Remove unused line

* PR nits

* Add wrapper around AddrsFactory to fill in missing certhash

* PR nits

* Handle WebTransport multiaddrs in observed addr manager

* Remove unneccessary change

* Remove unused func

* Use SplitLast

* Add comment

* Clone multiaddr before splitting last

* Revert "Clone multiaddr before splitting last"

This reverts commit f168a8e8b6.

* Wait for certmanager to be instantiated

* Copy addrs slice before modifying

* Fix stalled test
2023-04-05 23:45:54 -07:00
Marten Seemann 0d7e852b0a basichost: prevent duplicate dials (#2196) 2023-03-16 19:27:07 -07:00
Sukun bfc6fc30de relay service: add metrics (#2154)
* relay service: add metrics

Metrics Added:

ReservationRequest: Opened, Closed, Renewed
ReservationRequestResponseStatus
ReservationRejectionReason

ConnectionRequest: Opened, Closed
ConnectionRequestResponseStatus
ConnectionRejectionReason
ConnectionDuration

BytesTransferred

RelayStatus

* add dashboard and changelog

* bugfix

* add metrics tests

* address review comments

* rename dashboard

* address review comments

* change label to rolling avg
2023-03-07 01:26:37 -08:00