From 03668a3e90feeb4aa9aed12eda895b8809612583 Mon Sep 17 00:00:00 2001 From: Diego Date: Thu, 23 May 2024 17:07:18 +0200 Subject: [PATCH] formatting --- libp2p/services/wildcardresolverservice.nim | 18 ++---- tests/testwildcardresolverservice.nim | 66 +++++++++++---------- 2 files changed, 41 insertions(+), 43 deletions(-) diff --git a/libp2p/services/wildcardresolverservice.nim b/libp2p/services/wildcardresolverservice.nim index d01463518..6f407fe6f 100644 --- a/libp2p/services/wildcardresolverservice.nim +++ b/libp2p/services/wildcardresolverservice.nim @@ -32,7 +32,8 @@ type ## and the machine has 2 interfaces with IPs 172.217.11.174 and 64.233.177.113, the address mapper will ## expand the wildcard address to 172.217.11.174:4001 and 64.233.177.113:4001. - NetworkInterfaceProvider* = proc (addrFamily: AddressFamily): seq[InterfaceAddress] {.gcsafe, raises: [].} + NetworkInterfaceProvider* = + proc(addrFamily: AddressFamily): seq[InterfaceAddress] {.gcsafe, raises: [].} proc isLoopbackOrUp(networkInterface: NetworkInterface): bool = if (networkInterface.ifType == IfSoftwareLoopback) or @@ -70,9 +71,7 @@ proc new*( ## ## Returns: ## - A new instance of `WildcardAddressResolverService`. - return T( - networkInterfaceProvider: networkInterfaceProvider, - ) + return T(networkInterfaceProvider: networkInterfaceProvider) proc getProtocolArgument*(ma: MultiAddress, codec: MultiCodec): MaResult[seq[byte]] = var buffer: seq[byte] @@ -87,9 +86,7 @@ proc getProtocolArgument*(ma: MultiAddress, codec: MultiCodec): MaResult[seq[byt err("Multiaddress codec has not been found") proc getWildcardMultiAddresses( - interfaceAddresses: seq[InterfaceAddress], - protocol: Protocol, - port: Port, + interfaceAddresses: seq[InterfaceAddress], protocol: Protocol, port: Port ): seq[MultiAddress] = var addresses: seq[MultiAddress] for ifaddr in interfaceAddresses: @@ -119,8 +116,7 @@ proc getWildcardAddress( return addresses proc expandWildcardAddresses( - networkInterfaceProvider: NetworkInterfaceProvider, - listenAddrs: seq[MultiAddress], + networkInterfaceProvider: NetworkInterfaceProvider, listenAddrs: seq[MultiAddress] ): seq[MultiAddress] = var addresses: seq[MultiAddress] # In this loop we expand bounded addresses like `0.0.0.0` and `::` to list of interface addresses. @@ -171,9 +167,7 @@ method setup*( listenAddrs: seq[MultiAddress] ): Future[seq[MultiAddress]] {.async.} = echo listenAddrs - return expandWildcardAddresses( - self.networkInterfaceProvider, listenAddrs - ) + return expandWildcardAddresses(self.networkInterfaceProvider, listenAddrs) debug "Setting up WildcardAddressResolverService" let hasBeenSetup = await procCall Service(self).setup(switch) diff --git a/tests/testwildcardresolverservice.nim b/tests/testwildcardresolverservice.nim index bc4e4f513..e9bd270f9 100644 --- a/tests/testwildcardresolverservice.nim +++ b/tests/testwildcardresolverservice.nim @@ -40,28 +40,29 @@ proc getAddressesMock( proc createSwitch(svc: Service): Switch = SwitchBuilder - .new() - .withRng(newRng()) - .withAddresses( - @[ - MultiAddress.init("/ip4/0.0.0.0/tcp/0/").tryGet(), - MultiAddress.init("/ip6/::/tcp/0/").tryGet(), - ] - ) - .withTcpTransport() - .withMplex() - .withNoise() - .withServices(@[svc]) - .build() + .new() + .withRng(newRng()) + .withAddresses( + @[ + MultiAddress.init("/ip4/0.0.0.0/tcp/0/").tryGet(), + MultiAddress.init("/ip6/::/tcp/0/").tryGet(), + ] + ) + .withTcpTransport() + .withMplex() + .withNoise() + .withServices(@[svc]) + .build() suite "WildcardAddressResolverService": teardown: checkTrackers() - proc setupWildcardService(): Future[tuple[svc: Service, switch: Switch, tcpIp4: MultiAddress, tcpIp6: MultiAddress]] {.async.} = - let svc: Service = WildcardAddressResolverService.new( - networkInterfaceProvider = getAddressesMock - ) + proc setupWildcardService(): Future[ + tuple[svc: Service, switch: Switch, tcpIp4: MultiAddress, tcpIp6: MultiAddress] + ] {.async.} = + let svc: Service = + WildcardAddressResolverService.new(networkInterfaceProvider = getAddressesMock) let switch = createSwitch(svc) await switch.start() let tcpIp4 = switch.peerInfo.addrs[0][multiCodec("tcp")].get # tcp port for ip4 @@ -70,19 +71,22 @@ suite "WildcardAddressResolverService": asyncTest "WildcardAddressResolverService must resolve wildcard addresses and stop doing so when stopped": let (svc, switch, tcpIp4, tcpIp6) = await setupWildcardService() - check switch.peerInfo.addrs == @[ - MultiAddress.init("/ip4/0.0.0.0" & $tcpIp4).get, - MultiAddress.init("/ip6/::" & $tcpIp6).get, - ] + check switch.peerInfo.addrs == + @[ + MultiAddress.init("/ip4/0.0.0.0" & $tcpIp4).get, + MultiAddress.init("/ip6/::" & $tcpIp6).get, + ] await svc.run(switch) - check switch.peerInfo.addrs == @[ - MultiAddress.init("/ip4/127.0.0.1" & $tcpIp4).get, - MultiAddress.init("/ip4/192.168.1.22" & $tcpIp4).get, - MultiAddress.init("/ip6/::1" & $tcpIp6).get, - MultiAddress.init("/ip6/fe80::1" & $tcpIp6).get, - ] + check switch.peerInfo.addrs == + @[ + MultiAddress.init("/ip4/127.0.0.1" & $tcpIp4).get, + MultiAddress.init("/ip4/192.168.1.22" & $tcpIp4).get, + MultiAddress.init("/ip6/::1" & $tcpIp6).get, + MultiAddress.init("/ip6/fe80::1" & $tcpIp6).get, + ] await switch.stop() - check switch.peerInfo.addrs == @[ - MultiAddress.init("/ip4/0.0.0.0" & $tcpIp4).get, - MultiAddress.init("/ip6/::" & $tcpIp6).get, - ] + check switch.peerInfo.addrs == + @[ + MultiAddress.init("/ip4/0.0.0.0" & $tcpIp4).get, + MultiAddress.init("/ip6/::" & $tcpIp6).get, + ]