setMeshRole

fun setMeshRole(meshRole: UByte, ditto: DittoBase)

Upcoming SDK feature made available for prototyping.

Sets a mesh role for the local Ditto instance. Mesh roles are an optional feature used to group peers in a mesh based on their function and control which roles connect to others with which priority.

This function should be called before starting Ditto sync - or Ditto sync should be restarted if mesh roles are set at a later date.

Not all apps will require this functionality. In many apps, all peers are the same. These apps are better served by the automatic mesh which Ditto will form.

Mesh roles might be appropriate if your use case calls for connections between specific peers. For instance, a fast food ordering app might need to ensure that customer apps prioritize connections to restaurant kiosks rather than other customers so they can place their orders. In this example, all customer apps will receive one role (e.g. 1) and all kiosks will receive another (e.g. 2). Customer apps would be configured to treat kiosk peers as high-priority connection targets. Similar examples can be made for games in which one peer which is acting as the host server vs. other peers which are joining the game.

Mesh roles can also be used to prevent connections between peers of different roles. Peers of differing roles can be configured to regard each other with a "DONT_CONNECT" priority (see DittoConnectionPriority for more info).

The numeric value for the mesh role is entirely use-case specific and you can define the values however you like - provided all peers agree on the meaning of the values. All peers belong to role 0 initially and will connect to each other with normal priority until specified otherwise.

Note: mesh roles are not a security mechanism. A peer may change its role at any time. Mesh roles are used only to influence the shape of the mesh which Ditto creates or to serve as targets for multihop sync.

Parameters

meshRole

the mesh role for this peer. Must be between 0 and 63 (inclusive). Defaults to 0 if not set.

ditto

The DittoBase instance which should inherit the role.