Skip to content

How to Use

P2PNetwork currently has three entrypoints in Network/cmd:

  • bootstrap - interactive bootstrap node
  • peer - interactive peer node
  • gui - Fyne desktop UI

From Network/:

Terminal window
go build -o bootstrap ./cmd/bootstrap
go build -o peer ./cmd/peer
go build -o gui ./cmd/gui

The repository also includes a Makefile:

Terminal window
make bootstrap
make peer

Start the bootstrap node:

Terminal window
./bootstrap

The program prompts for a node name, appends -bootstrap to it, starts on port 52837, prints the peer ID and multiaddrs, and writes the first multiaddr to a file called bs-nodes in the working directory.

Keep this terminal open. Every peer needs a bootstrap address to start discovering the network.

Start a second terminal in the same directory:

Terminal window
./peer

The peer node:

  • reads bs-nodes if it exists
  • prompts for a display name
  • connects to the bootstrap peers
  • starts discovery on fgov-network
  • keeps reconnecting to discovered peers when they are not already connected

The peer terminal accepts these commands:

connect <multiaddr>
peers
discovered
exit

Notes:

  • connect expects a full /ip4/.../tcp/.../p2p/... multiaddr
  • peers prints the currently connected peers and their names
  • discovered prints peers found by discovery
  • exit shuts the node down cleanly

The current CLI does not expose a disconnect command, even though the node package has a Disconnect method for programmatic use.

Run the desktop app:

Terminal window
./gui

The window title is FGov P2P Network. It lets you:

  • enter a node name
  • turn the node on and off
  • refresh the peer list
  • inspect the current running state
  1. The host is created with libp2p.
  2. The DHT starts in server mode.
  3. Bootstrap peers from bs-nodes are connected.
  4. The node prints Peer ID and Full addresses.
  5. Discovery starts after a short delay.
  6. Connected peers exchange names over the /fgov protocol.

The bootstrap node writes the first multiaddr it sees to bs-nodes.

That means:

  • running the peer from the same directory is enough for local testing
  • copying bs-nodes to another machine lets another peer join the same bootstrap node
  • if you move the binary elsewhere, copy the file too
Terminal window
./bootstrap
./peer
./peer

Because peer nodes listen on port 0, they pick an available port automatically. You can run several on one machine without adding a custom port flag.

  1. Start the bootstrap node on a reachable host.
  2. Use the printed multiaddr with the host’s real IP address.
  3. Give that multiaddr to peers on the same network or across the internet.
  • Check that bs-nodes exists
  • Check that the bootstrap node is still running
  • Make sure the printed multiaddr uses an address the peer can actually reach
  • Make sure a bootstrap node is already running
  • Refresh after the peer has had time to discover others
  • The bootstrap node gets -bootstrap appended automatically
  • Names are exchanged directly between peers after a connection is established