Skip to content
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

Autonat service #814

Merged
merged 35 commits into from
Dec 16, 2022
Merged

Autonat service #814

merged 35 commits into from
Dec 16, 2022

Conversation

diegomrsantos
Copy link
Contributor

@diegomrsantos diegomrsantos commented Dec 5, 2022

This a service which uses the Autonat protocol to estimate a node network reachability on the internet.

@codecov
Copy link

codecov bot commented Dec 5, 2022

Codecov Report

Merging #814 (3cf948c) into unstable (a17cad7) will decrease coverage by 0.02%.
The diff coverage is 89.03%.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##           unstable     #814      +/-   ##
============================================
- Coverage     83.62%   83.59%   -0.03%     
============================================
  Files            81       82       +1     
  Lines         14726    14910     +184     
============================================
+ Hits          12314    12464     +150     
- Misses         2412     2446      +34     
Impacted Files Coverage Δ
libp2p/protocols/connectivity/relay/client.nim 75.00% <ø> (-0.12%) ⬇️
libp2p/protocols/connectivity/autonat.nim 84.02% <74.07%> (-2.94%) ⬇️
libp2p/services/autonatservice.nim 90.42% <90.32%> (ø)
libp2p/switch.nim 90.90% <96.00%> (+0.96%) ⬆️
libp2p/builders.nim 95.74% <100.00%> (+0.09%) ⬆️
libp2p/connmanager.nim 91.13% <100.00%> (-0.10%) ⬇️
libp2p/protocols/pubsub/pubsub.nim 81.78% <0.00%> (-2.25%) ⬇️
libp2p/protocols/pubsub/gossipsub.nim 84.51% <0.00%> (-1.36%) ⬇️
libp2p/protocols/pubsub/gossipsub/behavior.nim 87.84% <0.00%> (-0.45%) ⬇️
... and 9 more

Copy link
Contributor

@alrevuelta alrevuelta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great, just some minor comments.

libp2p/services/autonatservice.nim Outdated Show resolved Hide resolved
libp2p/services/autonatservice.nim Outdated Show resolved Hide resolved
libp2p/services/autonatservice.nim Show resolved Hide resolved
libp2p/services/autonatservice.nim Outdated Show resolved Hide resolved
libp2p/services/autonatservice.nim Show resolved Hide resolved
libp2p/services/autonatservice.nim Outdated Show resolved Hide resolved
libp2p/services/autonatservice.nim Outdated Show resolved Hide resolved
tests/testautonatservice.nim Outdated Show resolved Hide resolved
tests/testautonatservice.nim Show resolved Hide resolved
libp2p/services/autonatservice.nim Outdated Show resolved Hide resolved
alrevuelta
alrevuelta previously approved these changes Dec 13, 2022
Copy link
Contributor

@alrevuelta alrevuelta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! thanks!

libp2p/services/autonatservice.nim Outdated Show resolved Hide resolved
libp2p/services/autonatservice.nim Outdated Show resolved Hide resolved
libp2p/services/autonatservice.nim Outdated Show resolved Hide resolved
libp2p/services/autonatservice.nim Outdated Show resolved Hide resolved
libp2p/services/autonatservice.nim Outdated Show resolved Hide resolved
Comment on lines 130 to 151
method setup*(self: AutonatService, switch: Switch): Future[bool] {.async.} =
let hasBeenSettedUp = await procCall Service(self).setup(switch)
if hasBeenSettedUp:
self.newConnectedPeerHandler = proc (peerId: PeerId, event: PeerEvent): Future[void] {.async.} =
discard askPeer(self, switch, peerId)
switch.connManager.addPeerEventHandler(self.newConnectedPeerHandler, PeerEventKind.Joined)
if self.scheduleInterval.isSome():
self.registerLoop = register(self, switch, self.scheduleInterval.get())
return hasBeenSettedUp

method run*(self: AutonatService, switch: Switch) {.async, public.} =
await askConnectedPeers(self, switch)

method stop*(self: AutonatService, switch: Switch): Future[bool] {.async, public.} =
let hasBeenStopped = await procCall Service(self).stop(switch)
if hasBeenStopped:
if not isNil(self.registerLoop):
self.registerLoop.cancel()
self.registerLoop = nil
if not isNil(self.newConnectedPeerHandler):
switch.connManager.removePeerEventHandler(self.newConnectedPeerHandler, PeerEventKind.Joined)
return hasBeenStopped
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very confusing, to refacto during the service rework

libp2p/switch.nim Outdated Show resolved Hide resolved
tests/helpers.nim Outdated Show resolved Hide resolved
tests/helpers.nim Outdated Show resolved Hide resolved
Menduist
Menduist previously approved these changes Dec 15, 2022
Copy link
Contributor

@Menduist Menduist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only minor tweaks left, overall LGTM!

libp2p/connmanager.nim Outdated Show resolved Hide resolved
@diegomrsantos diegomrsantos enabled auto-merge (squash) December 16, 2022 09:52
@diegomrsantos diegomrsantos merged commit 67ef25f into unstable Dec 16, 2022
@diegomrsantos diegomrsantos deleted the autonat-service branch December 16, 2022 11:32
@Menduist Menduist mentioned this pull request Dec 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants