Skip to content

Commit

Permalink
fixes for code review
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrsantos committed Apr 12, 2023
1 parent 39ac49f commit 5f4745e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions libp2p/protocols/connectivity/dcutr/client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import ../../protocol,
../../../switch,
../../../utils/future

export DcutrError

type
DcutrClient* = ref object
connectTimeout: Duration
Expand Down
3 changes: 2 additions & 1 deletion libp2p/protocols/connectivity/dcutr/server.nim
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import ../../protocol,
../../../switch,
../../../utils/future

export chronicles
export DcutrError
export chronicles #FIXME undertand why this is needed

type Dcutr* = ref object of LPProtocol

Expand Down
10 changes: 6 additions & 4 deletions libp2p/services/hpservice.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ else:
{.push raises: [].}

import std/[tables, sequtils]

import chronos, chronicles

import ../switch, ../wire
import ../protocols/rendezvous
import ../services/autorelayservice
import ../discovery/[rendezvousinterface, discoverymngr]
import ../protocols/connectivity/relay/relay
import ../protocols/connectivity/autonat/service
from ../protocols/connectivity/dcutr/core import DcutrError
import ../protocols/connectivity/dcutr/[client, server]
import chronos


logScope:
topics = "libp2p hpservice"
Expand All @@ -41,7 +43,7 @@ proc new*(T: typedesc[HPService], autonatService: AutonatService, autoRelayServi
return T(autonatService: autonatService, autoRelayService: autoRelayService, isPublicIPAddrProc: isPublicIPAddrProc)

proc tryStartingDirectConn(self: HPService, switch: Switch, peerId: PeerId): Future[bool] {.async.} =
await sleepAsync(100.milliseconds) # wait for AddressBook to be populated
await sleepAsync(500.milliseconds) # wait for AddressBook to be populated
for address in switch.peerStore[AddressBook][peerId]:
try:
if self.isPublicIPAddrProc(initTAddress(address).get()):
Expand Down Expand Up @@ -76,7 +78,7 @@ method setup*(self: HPService, switch: Switch): Future[bool] {.async.} =
await sleepAsync(2000.milliseconds) # grace period before closing relayed connection
await conn.close()
except CatchableError as err:
error "Hole punching failed during dcutr", err = err.msg
debug "Hole punching failed during dcutr", err = err.msg

switch.connManager.addPeerEventHandler(self.newConnectedPeerHandler, PeerEventKind.Joined)

Expand Down

0 comments on commit 5f4745e

Please sign in to comment.