1

I am currently learning core-development in go-ethereum. I am a little weak with networking, RPC and connections.

I am trying to write a function in my own consensus mechanism that gathers all currently connected node addresses into a struct and then uses it to display them. it currently has a structure like this.

type NodeAddresses struct {
    connectedNode []ConnectedNode
}

type ConnectedNode struct {
    address common.Address
}  

func GatherNodeAddresses() {
    nodes := &NodeAddresses{
        ......
    }

}

What I'm having trouble with is how to populate the struct of NodeAddresses with connecting nodes in a private network. Each node has their own personal account set up with an address. Could someone give me an insight of how to move forward from here? Cheers!

Yanzal
  • 128
  • 6

1 Answers1

3

You can use an approach similar to graph traversal https://en.wikipedia.org/wiki/Graph_traversal

  1. Connect to a node, add it to "knownNodes" map
  2. Find peers for this node Get a peer list for my geth node
  3. For each peer, if peer does not already exist in "knownNodes", perform steps #1 and #2
Shamit Verma
  • 534
  • 2
  • 5