Skip to content

Allow agent to join a network using network access tokens #923

@aryanjassal

Description

@aryanjassal

Specification

The Polykey agent needs a way to join a network. The target network can either be a public or a private one. To do this, the agent will perform the following steps:

  1. Perform DNS resolution to get details of the target seednode. An agent can connect to a seednode within a private network even while being unauthenticated.
  2. Attempt to switch the currently-active network to the target network's seednode
  3. If switching worked, then a network access claim already existed. If switching failed, attempt to create a new network access claim.

The network claiming and switching should automatically handle stuff like switching authentication and connection code to align with the new network.

The network join can be triggered at any time in the agent's lifecycle. The two main candidates for this are the polykey nodes join command, which can allow a running agent to connect to a said network, or polykey agent start --network to start the agent by attempting connection to the provided network.

Additional context

A dummy private network has not been created yet. Thus, tests need to be written for testing the validity of the new logic. The test called a node can join a public network without permissions under NodeManager.test.ts contains logic for attempting connection to a private seednode and issuing network access and authority tokens. It can be used as a template for writing tests for this issue. The tests will need to mock DNS resolution, as the seednode is running locally.

Tasks

  1. Update the NodeManager.claimNetwork function to check for an existing claim first instead of creating duplicate access tokens
  2. Update the syncNodeGraph and/or syncNodeGraphHandler to add this step
  3. Create a RPC handler for the network joining logic

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions