mirror of
https://github.com/status-im/nim-dagger.git
synced 2025-01-10 06:36:06 +00:00
fix styling issues
This commit is contained in:
parent
feb13129f4
commit
b387b6aff4
@ -159,7 +159,7 @@ proc start*(s: CodexServer) {.async.} =
|
|||||||
|
|
||||||
await s.codexNode.switch.start()
|
await s.codexNode.switch.start()
|
||||||
|
|
||||||
let (announceAddrs,discoveryAddrs)= natedAddress(
|
let (announceAddrs,discoveryAddrs)= nattedAddress(
|
||||||
s.config.nat,
|
s.config.nat,
|
||||||
s.codexNode.switch.peerInfo.addrs,
|
s.codexNode.switch.peerInfo.addrs,
|
||||||
s.config.discoveryPort)
|
s.config.discoveryPort)
|
||||||
|
@ -386,7 +386,7 @@ proc setupAddress*(natConfig: NatConfig, bindIp: ValidIpAddress,
|
|||||||
of NatStrategy.NatUpnp, NatStrategy.NatPmp:
|
of NatStrategy.NatUpnp, NatStrategy.NatPmp:
|
||||||
return setupNat(natConfig.nat, tcpPort, udpPort, clientId)
|
return setupNat(natConfig.nat, tcpPort, udpPort, clientId)
|
||||||
|
|
||||||
proc natedAddress*(natConfig: NatConfig, addrs: seq[MultiAddress], udpPort: Port): tuple[libp2p, discovery: seq[MultiAddress]] =
|
proc nattedAddress*(natConfig: NatConfig, addrs: seq[MultiAddress], udpPort: Port): tuple[libp2p, discovery: seq[MultiAddress]] =
|
||||||
## Takes a NAT configuration, sequence of multiaddresses and UDP port and returns:
|
## Takes a NAT configuration, sequence of multiaddresses and UDP port and returns:
|
||||||
## - Modified multiaddresses with NAT-mapped addresses for libp2p
|
## - Modified multiaddresses with NAT-mapped addresses for libp2p
|
||||||
## - Discovery addresses with NAT-mapped UDP ports
|
## - Discovery addresses with NAT-mapped UDP ports
|
||||||
|
@ -51,13 +51,8 @@ proc getMultiAddrWithIPAndUDPPort*(ip: ValidIpAddress, port: Port): MultiAddress
|
|||||||
## Returns:
|
## Returns:
|
||||||
## A MultiAddress in the format "/ip4/<address>/udp/<port>" or "/ip6/<address>/udp/<port>"
|
## A MultiAddress in the format "/ip4/<address>/udp/<port>" or "/ip6/<address>/udp/<port>"
|
||||||
|
|
||||||
let ipFamily = ip.family
|
let ipFamily = if ip.family == IpAddressFamily.IPv4: "/ip4/" else: "/ip6/"
|
||||||
if ipFamily == IpAddressFamily.IPv4:
|
return MultiAddress.init(ipFamily & $ip & "/udp/" & $port).expect("valid multiaddr")
|
||||||
# Construct IPv4 multiaddress
|
|
||||||
return MultiAddress.init("/ip4/" & $ip & "/udp/" & $port).expect("valid multiaddr")
|
|
||||||
else:
|
|
||||||
# Construct IPv6 multiaddress
|
|
||||||
return MultiAddress.init("/ip6/" & $ip & "/udp/" & $port).expect("valid multiaddr")
|
|
||||||
|
|
||||||
proc getAddressAndPort*(ma: MultiAddress): tuple[ip: Option[ValidIpAddress], port: Option[Port]] =
|
proc getAddressAndPort*(ma: MultiAddress): tuple[ip: Option[ValidIpAddress], port: Option[Port]] =
|
||||||
try:
|
try:
|
||||||
|
@ -9,7 +9,7 @@ import ../../codex/utils
|
|||||||
|
|
||||||
|
|
||||||
suite "NAT Address Tests":
|
suite "NAT Address Tests":
|
||||||
test "natedAddress with local addresses":
|
test "nattedAddress with local addresses":
|
||||||
# Setup test data
|
# Setup test data
|
||||||
let
|
let
|
||||||
udpPort = Port(1234)
|
udpPort = Port(1234)
|
||||||
@ -39,7 +39,7 @@ suite "NAT Address Tests":
|
|||||||
addrs = @[localAddr, anyAddr, publicAddr]
|
addrs = @[localAddr, anyAddr, publicAddr]
|
||||||
|
|
||||||
# Test address remapping
|
# Test address remapping
|
||||||
let (libp2pAddrs,discoveryAddrs) = natedAddress(natConfig, addrs, udpPort)
|
let (libp2pAddrs,discoveryAddrs) = nattedAddress(natConfig, addrs, udpPort)
|
||||||
|
|
||||||
# Verify results
|
# Verify results
|
||||||
check(discoveryAddrs == expectedDiscoveryAddrs)
|
check(discoveryAddrs == expectedDiscoveryAddrs)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user