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

Feature request: add system network monitoring module #2735

Open
wlynxg opened this issue Mar 15, 2024 · 7 comments
Open

Feature request: add system network monitoring module #2735

wlynxg opened this issue Mar 15, 2024 · 7 comments

Comments

@wlynxg
Copy link
Contributor

wlynxg commented Mar 15, 2024

There are a large number of frequent scheduled tasks in libp2p to combat network changes. Maybe we can add a special module to obtain system network change events, and then publish these events through EventBus.

These are some of the possible impacts of network incidents that I am thinking about. Could you please add them:

network event affect can capture? process
Non-default routing network card IP change The LAN connection related to changing the network card is disconnected Yes Restart mDNS broadcast
Default routing network card IP change 1. PMP mapping is invalid
2. P2P mapping is invalid and related connections are disconnected
3. LAN connection is disconnected
4. DHT records are invalid
Yes 1. Re-establish PMP mapping.
2. Re-obtain the network card interface address and external network egress address
3. Re-broadcast mDNS
4. Re-broadcast to the DHT network
The router LAN port IP changes and the WAN port IP remains unchanged. PMP gateway address invalid Yes Retrieve gateway address
Router WAN port IP changed 1. PMP mapping is invalid
2. P2P mapping is invalid and related connections are disconnected
3. DHT record is invalid
No 1. Re-establish PMP mapping
2. Re-obtain the external network egress address
3. Re-broadcast to the DHT network
@MarcoPolo
Copy link
Collaborator

I don't fully understand these network events. Could you clarify what you mean by them?

What do you mean by default vs non-default routing network card? For the router changes do you mean the router itself changed IP address or that you have a different gateway?

@wlynxg
Copy link
Contributor Author

wlynxg commented Mar 21, 2024

I don't fully understand these network events. Could you clarify what you mean by them?

What do you mean by default vs non-default routing network card? For the router changes do you mean the router itself changed IP address or that you have a different gateway?

For machines with multiple network cards, default and non-default routing network cards are a way to distinguish. For example, if your laptop is connected to a wired network and a wireless network at the same time, the two network cards may be in different LAN environments, but only one network card will be used as the default route.

For example, the wired network card may be the default route, while the wireless network card belongs to another LAN. On my computer, the libp2p node establishes connections with a public network node and a node located under the Wi-Fi LAN at the same time. Assuming that the IP address of the wireless network card changes at this time, the connection with the node under the Wi-Fi LAN will need to be re-established, but the connection with the public network node will not be affected.

@wlynxg
Copy link
Contributor Author

wlynxg commented Mar 21, 2024

I don't fully understand these network events. Could you clarify what you mean by them?

What do you mean by default vs non-default routing network card? For the router changes do you mean the router itself changed IP address or that you have a different gateway?

For router changes, the router has WAN IP and LAN IP.

  1. WAN IP change: When the router's WAN IP changes, this will cause the external network address mapped through UPnP to change. This means that the external access address previously obtained via UPnP mapping will no longer be valid and will need to be updated to the new WAN IP.

  2. LAN IP change: If the router's LAN IP changes, this will affect sending UPnP packets to the correct IP address. UPnP uses the IP address of the internal network for communication, and if the LAN IP changes, the router will not be able to correctly forward UPnP packets to the target device.

@MarcoPolo
Copy link
Collaborator

For all but the router LAN ip changing, does EvtLocalAddressesUpdated ](https://pkg.go.dev/github.com/libp2p/[email protected]/core/event#EvtLocalAddressesUpdated) satisfy your needs?

For the router LAN ip changing, when does this happen? Wouldn't it break existing devices on the network if their gateway changes suddenly?

@wlynxg
Copy link
Contributor Author

wlynxg commented Mar 22, 2024

For all but the router LAN ip changing, does EvtLocalAddressesUpdated ](https://pkg.go.dev/github.com/libp2p/[email protected]/core/event#EvtLocalAddressesUpdated) satisfy your needs?

For the router LAN ip changing, when does this happen? Wouldn't it break existing devices on the network if their gateway changes suddenly?

I know that network address change events have been defined in libp2p, but these events in libp2p are driven by scheduled tasks, which requires many scheduled tasks to continuously obtain addresses and then compare them.

However, the operating system itself has interfaces for obtaining these network change events, such as rtnetlink on Linux, and NotifyUnicastIpAddressChange on Windows.

libp2p can rely on event changes in the operating system to perform address changes more accurately, which can reduce the pressure on scheduled tasks. Essentially, this module is just an optimization of libp2p behavior and can be regarded as an expansion module.❤

@MarcoPolo
Copy link
Collaborator

Gotcha. So the issue here is that we are polling for address changes rather than being notified on address changes?

@wlynxg
Copy link
Contributor Author

wlynxg commented Mar 23, 2024

It can be said like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants