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

Add getPeers and addPeers to GraphQL and CLI #6715

Merged
merged 8 commits into from
Nov 14, 2020
Merged

Conversation

mrmr1993
Copy link
Member

This PR adds getPeers and addPeers commands to get the currently connected peers and connect to additional peers via GraphQL. This also implements CLI commands using the bindings.

Sample CLI run (with 2 running daemons, both started with -seed):

$ coda.exe advanced get-peers -help
List the peers currently connected to the daemon

  coda.exe advanced get-peers

=== flags ===

  [-rest-server URI/LOCALHOST-PORT]  graphql rest server for daemon interaction
                                     (examples: 3085 or
                                     http://localhost:3085/graphql,
                                     /dns4/peer1-rising-phoenix.o1test.net:3085/graphql)
                                     (default: 3085 or
                                     http://localhost:3085/graphql)
  [-help]                            print this help text and exit
                                     (alias: -?)

$ coda.exe advanced add-peers -help
Add peers to the daemon

Addresses take the format /ip4/IPADDR/tcp/PORT/p2p/PEERID

  coda.exe advanced add-peers PEER [PEER ...]

=== flags ===

  [-rest-server URI/LOCALHOST-PORT]  graphql rest server for daemon interaction
                                     (examples: 3085 or
                                     http://localhost:3085/graphql,
                                     /dns4/peer1-rising-phoenix.o1test.net:3085/graphql)
                                     (default: 3085 or
                                     http://localhost:3085/graphql)
  [-help]                            print this help text and exit
                                     (alias: -?)

$ coda.exe client status
Coda daemon status
-----------------------------------

Max observed block length:  1
Local uptime:               31s
Chain id:                   41eb505be7c6b777f43c403b89778d9cd06a5092af82ee130c64f2b887835b75
Git SHA-1:                  8ad2b9bea1d2a6dc291ab4c6a225b284dd6e31fa
Configuration directory:    /home/matthew/.coda-config
Peers:                      0
User_commands sent:         0
SNARK worker:               None
SNARK work fee:             1000000000
Sync status:                Bootstrap
Block producers running:    0
Consensus time now:         epoch=6, slot=116
Consensus mechanism:        proof_of_stake
Consensus configuration:
        Delta:                     0
        k:                         24
        Slots per epoch:           576
        Slot duration:             2s
        Epoch duration:            19m12s
        Genesis state timestamp:   2019-01-30 20:00:00.000000Z
        Acceptable network delay:  2s

Addresses and ports:
        External IP:    2.96.202.210
        Bind IP:        0.0.0.0
        Libp2p PeerID:  12D3KooWBiX6JEGgfift5y6364YcjPL5DQybz1BB1tn733dtDe9i
        Libp2p port:    8302
        Client port:    8301


$ coda.exe client status -daemon-port 8303
Coda daemon status
-----------------------------------

Max observed block length:  1
Local uptime:               40s
Chain id:                   41eb505be7c6b777f43c403b89778d9cd06a5092af82ee130c64f2b887835b75
Git SHA-1:                  8ad2b9bea1d2a6dc291ab4c6a225b284dd6e31fa
Configuration directory:    /tmp/coda-config2
Peers:                      0
User_commands sent:         0
SNARK worker:               None
SNARK work fee:             1000000000
Sync status:                Bootstrap
Block producers running:    0
Consensus time now:         epoch=6, slot=119
Consensus mechanism:        proof_of_stake
Consensus configuration:
        Delta:                     0
        k:                         24
        Slots per epoch:           576
        Slot duration:             2s
        Epoch duration:            19m12s
        Genesis state timestamp:   2019-01-30 20:00:00.000000Z
        Acceptable network delay:  2s

Addresses and ports:
        External IP:    2.96.202.210
        Bind IP:        0.0.0.0
        Libp2p PeerID:  12D3KooWRiqU2b6r4f2wVzE1ka8A3evRfcHxDDhJUZDZfTxbkAB7
        Libp2p port:    8304
        Client port:    8303


$ coda.exe advanced get-peers -rest-server 3085
Peers:
$ coda.exe advanced get-peers -rest-server 3086
Peers:
$ coda.exe advanced add-peers /ip4/127.0.0.1/tcp/8304/p2p/12D3KooWRiqU2b6r4f2wVzE1ka8A3evRfcHxDDhJUZDZfTxbkAB7
Requested to add peers:
/ip4/127.0.0.1/tcp/8304/p2p/12D3KooWRiqU2b6r4f2wVzE1ka8A3evRfcHxDDhJUZDZfTxbkAB7
$ coda.exe advanced get-peers -rest-server 3085
Peers:
/ip4/172.17.0.1/tcp/8304/p2p/12D3KooWRiqU2b6r4f2wVzE1ka8A3evRfcHxDDhJUZDZfTxbkAB7
$ coda.exe advanced get-peers -rest-server 3086
Peers:
/ip4/192.168.1.21/tcp/8302/p2p/12D3KooWBiX6JEGgfift5y6364YcjPL5DQybz1BB1tn733dtDe9i

Checklist:

  • Document code purpose, how to use it
    • Mention expected invariants, implicit constraints
  • Tests were added for the new behavior
    • Document test purpose, significance of failures
    • Test names should reflect their purpose
  • All tests pass (CI will check this if you didn't)
  • Serialized types are in stable-versioned modules
  • Does this close issues? List them:

@mrmr1993 mrmr1993 requested review from a team as code owners November 14, 2020 02:24
@mrmr1993 mrmr1993 added the ci-build-me Add this label to trigger a circle+buildkite build for this branch label Nov 14, 2020
@lk86
Copy link
Contributor

lk86 commented Nov 14, 2020

can you skip the "Peers:" output? it would be nice to coda client get-peers > peers.txt , and if there are no peers print something to stderr

This at the request of @lk86, so that we can
`coda client get-peers > peers.txt`
@mrmr1993 mrmr1993 merged commit 3f63025 into develop Nov 14, 2020
@mrmr1993 mrmr1993 deleted the feature/peers-graphql branch November 14, 2020 05:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-build-me Add this label to trigger a circle+buildkite build for this branch ready-to-merge-into-develop
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants