|
| 1 | +# Registrar package |
| 2 | + |
| 3 | +The `registrar` pkg is used to handle node registration on ThreeFold Grid. It is used by the `noded` module, which triggers the registration process by first collecting node capacity information, creating a Redis client, and then adding the `registrar` to the intercommunication process using `zbus` for remote procedure calls (RPC). |
| 4 | +re-registration occurs automatically every 24 hours or immediately after an IP address change, ensuring the node's information stays up-to-date. |
| 5 | +registration process can fail due to various reasons, such as RPC calls failure. |
| 6 | + |
| 7 | +The registration process includes: |
| 8 | + |
| 9 | +1. Collecting node information |
| 10 | +2. Creating/Ensuring a twinID exists for the node |
| 11 | +3. Registering the node on the blockchain |
| 12 | + |
| 13 | +## Error Handling |
| 14 | + |
| 15 | +`ErrInProgress`: Error raised if the node registration is still in progress. |
| 16 | + |
| 17 | +`ErrFailed`: Error raised if the node registration fails. |
| 18 | + |
| 19 | +## Constants |
| 20 | + |
| 21 | +### Node registration state constants |
| 22 | + |
| 23 | +`Failed`: Node registration failed |
| 24 | + |
| 25 | +`InProgress`: Node registration is in progress |
| 26 | + |
| 27 | +`Done`: Node registration is completed |
| 28 | + |
| 29 | +## Structs |
| 30 | + |
| 31 | +### State Struct |
| 32 | + |
| 33 | +used to store the state of the node registration. |
| 34 | + |
| 35 | +#### Fields |
| 36 | + |
| 37 | +`NodeID`: The ID of the node. |
| 38 | + |
| 39 | +`TwinID`: The twin ID of the node. |
| 40 | + |
| 41 | +`State`: The state of the node registration. |
| 42 | + |
| 43 | +`Msg`: The message associated with the node registration state. |
| 44 | + |
| 45 | +### RegistrationInfo Struct |
| 46 | + |
| 47 | +used to store the capacity, location, and other information of the node. |
| 48 | + |
| 49 | +#### Fields |
| 50 | + |
| 51 | +`Capacity`: The capacity of the node. |
| 52 | + |
| 53 | +`Location`: The location of the node. |
| 54 | + |
| 55 | +`SecureBoot`: State whether the node is booted via efi or not. |
| 56 | + |
| 57 | +`Virtualized`: State whether the node has hypervisor on it or not. |
| 58 | + |
| 59 | +`SerialNumber`: The serial number of the node. |
| 60 | + |
| 61 | +`GPUs`: The GPUs of the node. |
| 62 | + |
| 63 | +#### Methods |
| 64 | + |
| 65 | +`WithCapacity`: Set the capacity of the node, taking a `gridtypes.Capacity` as input. |
| 66 | + |
| 67 | +`WithLocation`: Set the location of the node, taking a `geoip.Location` as input. |
| 68 | + |
| 69 | +`WithSecureBoot`: Set the secure boot status of the node, taking a boolean as input. |
| 70 | + |
| 71 | +`WithVirtualized`: Set the virtualized status of the node, taking a boolean as input. |
| 72 | + |
| 73 | +`WithSerialNumber`: Set the serial number of the node, taking a string as input. |
| 74 | + |
| 75 | +`WithGPUs`: Set the GPUs of the node, taking a string as input. |
| 76 | + |
| 77 | +### Registrar Struct |
| 78 | + |
| 79 | +The registrar is used to register nodes on the ThreeFold Grid. |
| 80 | + |
| 81 | +#### Fields |
| 82 | + |
| 83 | +`state`: The state of the registrar. |
| 84 | + |
| 85 | +`mutex`: A mutex for synchronizing access to the registrar. |
| 86 | + |
| 87 | +#### Methods |
| 88 | + |
| 89 | +`NodeID`: Returns the node ID if the registrar is in the done state, otherwise returns an error. |
| 90 | + |
| 91 | +`TwinID`: Returns the twin ID if the registrar is in the done state, otherwise returns an error. |
| 92 | + |
| 93 | +## Functions |
| 94 | + |
| 95 | +### `NewRegistrar(ctx context.Context, cl Zbus.Client, env environment.Environment, info RegistrationInfo) *Registrar` |
| 96 | + |
| 97 | +Creates a new registrar with the given context, client, environment, and registration information, starts the registration process and returns the registrar. |
| 98 | + |
| 99 | +### `FailedState(err error) State` |
| 100 | + |
| 101 | +Returns a failed state with the given error. |
| 102 | + |
| 103 | +### `InProgressState() State` |
| 104 | + |
| 105 | +Returns an in progress state. |
| 106 | + |
| 107 | +### `DoneState(nodeID , twinID uint32) State` |
| 108 | + |
| 109 | +Returns a done state with the given node ID and twin ID. |
| 110 | + |
0 commit comments