-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a8487ff
commit 16c96bd
Showing
7 changed files
with
69 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import std/[unittest, options, net],stew/shims/net as stewNet | ||
import pkg/chronos | ||
import pkg/libp2p/[multiaddress, multihash, multicodec] | ||
import pkg/stew/results | ||
|
||
import ../../codex/nat | ||
import ../../codex/utils/natutils | ||
import ../../codex/utils | ||
|
||
|
||
suite "NAT Address Tests": | ||
test "natedAddress with local addresses": | ||
# Setup test data | ||
let | ||
udpPort = Port(1234) | ||
natConfig = NatConfig( | ||
hasExtIp: true, | ||
extIp:ValidIpAddress.init("8.8.8.8")) | ||
|
||
# Create test addresses | ||
localAddr = MultiAddress.init("/ip4/127.0.0.1/tcp/5000").expect("valid multiaddr") | ||
anyAddr = MultiAddress.init("/ip4/0.0.0.0/tcp/5000").expect("valid multiaddr") | ||
publicAddr = MultiAddress.init("/ip4/192.168.1.1/tcp/5000").expect("valid multiaddr") | ||
|
||
# Expected results | ||
let | ||
expectedDiscoveryAddrs = @[ | ||
MultiAddress.init("/ip4/8.8.8.8/udp/1234").expect("valid multiaddr"), | ||
MultiAddress.init("/ip4/8.8.8.8/udp/1234").expect("valid multiaddr"), | ||
MultiAddress.init("/ip4/8.8.8.8/udp/1234").expect("valid multiaddr") | ||
] | ||
expectedlibp2pAddrs = @[ | ||
MultiAddress.init("/ip4/8.8.8.8/tcp/5000").expect("valid multiaddr"), | ||
MultiAddress.init("/ip4/8.8.8.8/tcp/5000").expect("valid multiaddr"), | ||
MultiAddress.init("/ip4/8.8.8.8/tcp/5000").expect("valid multiaddr") | ||
] | ||
|
||
#ipv6Addr = MultiAddress.init("/ip6/::1/tcp/5000").expect("valid multiaddr") | ||
addrs = @[localAddr, anyAddr, publicAddr] | ||
|
||
# Test address remapping | ||
let (libp2pAddrs,discoveryAddrs) = natedAddress(natConfig, addrs, udpPort) | ||
|
||
# Verify results | ||
check(discoveryAddrs == expectedDiscoveryAddrs) | ||
check(libp2pAddrs == expectedlibp2pAddrs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters