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

NAT traversal and automatic port forwarding #124

Open
layters opened this issue May 25, 2023 · 1 comment
Open

NAT traversal and automatic port forwarding #124

layters opened this issue May 25, 2023 · 1 comment
Labels
⬆️ high priority High priority issues 🆘 help wanted Extra attention is needed

Comments

@layters
Copy link
Owner

layters commented May 25, 2023

Details

In order to establish connections and maintain a decentralized network, nodes need to be able to communicate with each other, even if they are behind NAT (Network Address Translation) routers or a firewall.

By utilizing UPnP and other NAT traversal methods, Neroshop nodes can automate the process of port forwarding, making it easier for users to participate in the network without requiring manual configuration of their routers.

ELI5: Right now nodes can only send data but cannot receive data because receiving data from their public IP address requires NAT traversal.

Additional Information

The neroshop DHT node uses two separate UDP sockets for communication - one for listening to and responding to requests via the Node::run() function and the other is a temporary socket that is used for sending queries to other nodes in the network via the Node::send_query() function. I want to know how I can route both the inbound and outbound traffic of the Node using i2p.

Files

https://github.com/larteyoh/testshop/blob/main/src/core/protocol/p2p/node.cpp
https://github.com/larteyoh/testshop/blob/main/src/daemon/main.cpp

Libraries

There are a few lightweight NAT traversal libraries available for C/C++ that I've been able to compile so far:

libnatpmp: a lightweight and portable library for NAT-PMP (NAT Port Mapping Protocol) implementation which I've been able to compile but have no idea how to integrate since I'm just dumb.

miniupnpc: lightweight library that implements the UPnP (Universal Plug and Play) protocol which is not currently working for me.

opening a port through UPnP is not reliable for p2p apps. Consider using STUN/TURN/ICE to connect behind NAT

That brings me down to two C/C++ library options:

I am going with JUICE as it has zero dependencies and a very permissive license (🥳), but I will need help with integrating it into the neroshop daemon using these examples and this as a reference guide.

Related issues

I2P Integration

@layters layters added 🆘 help wanted Extra attention is needed ⬆️ high priority High priority issues labels May 25, 2023
@layters layters closed this as completed May 26, 2023
@layters layters reopened this May 29, 2023
@layters layters pinned this issue Jun 4, 2023
@layters
Copy link
Owner Author

layters commented Jun 8, 2023

The miniupnp code in daemon/main.cpp does not work for whatever reason. I've even had to contact the dev to review the code and he gave me the 👍🏿.

Edit: This issue may have to do with my node running on a home network that shares the same IPv4 address with all connected devices.

Edit 2: I've done some tests using libplum and miniupnp for automatic port forwarding/mapping and both often fail for me (even with UPnP enabled and firewall disabled) whereas STUN/TURN (libjuice) is usually successful.

Edit 3: libplum, miniupnp, and libnatpmp have been removed as of July 5 2023.

@layters layters unpinned this issue Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⬆️ high priority High priority issues 🆘 help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant