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

feat(network): database-backed peer store #877

Closed
wants to merge 18 commits into from

Conversation

kehiy
Copy link
Contributor

@kehiy kehiy commented Dec 27, 2023

Description

Adding a new peers.json file in the working directory which when the node goes off will keep track of all connected peers. when we start the node again, we have all of the previous nodes to connect in the peer store.

The peer.json looks like this:

{
    "peers": {
        "12D3KooWACPieBCFwiF4BfaDAG9EQUk5QgCWvLc3ZYm4LGrW9np5": {
            "multi_address": "/ip4/207.211.157.238/udp/21777/quic-v1",
            "direction": 2
        },
        "12D3KooWAQzz1GtMa6CQRkcbzavaiQbuYPmyKjpmFEjTE9A5Cb8y": {
            "multi_address": "/ip4/146.56.144.37/udp/21777/quic-v1",
            "direction": 2
        },
        "12D3KooWAspuF1ZMc77e9d2efbZt28MPXDmiLj6QkhGbFe7AA1Cs": {
            "multi_address": "/ip4/168.138.184.213/udp/21777/quic-v1",
            "direction": 2
        },
        "12D3KooWBGNEH8NqdK1UddSnPV1yRHGLYpaQUcnujC24s7YNWPiq": {
            "multi_address": "/ip4/13.115.190.71/tcp/21777",
            "direction": 2
        }
    }
}

NOTE: most of the time it's around 30 peers, in this example, I showed 4 of them only.

The node owner can change the peer store path in config.

Related issue(s)

@kehiy kehiy added the network label Dec 27, 2023
@kehiy kehiy requested a review from b00f December 27, 2023 06:58
@kehiy kehiy self-assigned this Dec 27, 2023
@kehiy kehiy added the Sync label Dec 27, 2023
Copy link

codecov bot commented Dec 27, 2023

Codecov Report

Merging #877 (fbdb316) into main (b222d00) will increase coverage by 0.00%.
The diff coverage is 65.62%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #877   +/-   ##
=======================================
  Coverage   83.30%   83.30%           
=======================================
  Files         173      173           
  Lines        8815     8845   +30     
=======================================
+ Hits         7343     7368   +25     
- Misses       1117     1118    +1     
- Partials      355      359    +4     

@b00f
Copy link
Collaborator

b00f commented Dec 27, 2023

Two general comments:

  1. The nodes behind NAT also publish a public address. This should be considered.
  2. There is no need to add a new item to the configuration.

@@ -157,3 +181,39 @@ func (mgr *peerMgr) CheckConnectivity() {
}
}
}

type PeerStore struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we can't use peerMgr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This lp2ppeer.ID type makes a problem for us. Peer IDs going to be saved as the unicodes and then we can't retrive them at all. we can use map[string]PeerInfo without defineing it as a type ot struct. but the main problem is json tags.

@b00f
Copy link
Collaborator

b00f commented Dec 30, 2023

We need more R&D. The libp2p I think has persistent store for peers.

@kehiy
Copy link
Contributor Author

kehiy commented Dec 31, 2023

We need more R&D. The libp2p I think has persistent store for peers.

The persistent store for peers is now deprecated.
see:

So, we can implement it ourselves. just we have 2 issues, the peers with private reachability and having a new struct for peer store (as I said we can't use current map on peer manager).

About private peers, I thought if we can have reachability field on peerInfo struct too.

@kehiy kehiy changed the title feat: keep a peer store when node goes off feat(network): database-backed peer store Dec 31, 2023
@kehiy kehiy marked this pull request as draft January 4, 2024 13:30
@kehiy kehiy closed this Jan 6, 2024
@kehiy kehiy deleted the feature/peerManager branch January 6, 2024 17:28
@b00f
Copy link
Collaborator

b00f commented Jan 6, 2024

Why did you close it?

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

Successfully merging this pull request may close these issues.

Keeping peer list when node goes off
2 participants