| 8278 | if (errlen) snprintf(err, errlen, "%s must be 32, 16, or 8", arg); |
| 8279 | return DS4_DIST_CLI_ERROR; |
| 8280 | } |
| 8281 | opt->activation_bits = bits; |
| 8282 | return DS4_DIST_CLI_MATCHED; |
| 8283 | } |
| 8284 | if (!strcmp(arg, "--dist-replay-check")) { |
| 8285 | if (!opt) { |
| 8286 | if (errlen) snprintf(err, errlen, "missing distributed options"); |
| 8287 | return DS4_DIST_CLI_ERROR; |
| 8288 | } |
| 8289 | opt->replay_check = true; |
| 8290 | return DS4_DIST_CLI_MATCHED; |
| 8291 | } |
| 8292 | if (!strcmp(arg, "--debug")) { |
| 8293 | if (!opt) { |
| 8294 | if (errlen) snprintf(err, errlen, "missing distributed options"); |
| 8295 | return DS4_DIST_CLI_ERROR; |
| 8296 | } |
| 8297 | opt->debug = true; |
| 8298 | return DS4_DIST_CLI_MATCHED; |
| 8299 | } |
| 8300 | return DS4_DIST_CLI_NOT_MATCHED; |
| 8301 | } |
| 8302 | |
| 8303 | static int dist_validate_options(const ds4_dist_options *opt, char *err, size_t errlen) { |
| 8304 | if (!opt) { |
| 8305 | if (errlen) snprintf(err, errlen, "missing distributed options"); |
| 8306 | return 1; |
| 8307 | } |
| 8308 | |
| 8309 | if (opt->role == DS4_DISTRIBUTED_NONE) { |
| 8310 | if (opt->layers.set || opt->listen_host || opt->listen_port || |
| 8311 | opt->coordinator_host || opt->coordinator_port || |
| 8312 | opt->prefill_chunk != 0 || opt->prefill_window != 0 || |
| 8313 | opt->activation_bits != 0) { |
| 8314 | if (errlen) snprintf(err, errlen, "distributed options require --role coordinator or --role worker"); |
| 8315 | return 1; |
| 8316 | } |
| 8317 | return 0; |
| 8318 | } |
| 8319 | |
| 8320 | if (!opt->layers.set) { |
| 8321 | if (errlen) snprintf(err, errlen, "--role %s requires --layers", dist_role_name(opt->role)); |
| 8322 | return 1; |
| 8323 | } |
| 8324 | if (opt->prefill_window > 64u) { |
| 8325 | if (errlen) snprintf(err, errlen, "--dist-prefill-window must be <= 64"); |
| 8326 | return 1; |
| 8327 | } |
| 8328 | if (opt->activation_bits != 0 && !dist_activation_bits_valid(opt->activation_bits)) { |
| 8329 | if (errlen) snprintf(err, errlen, "--dist-activation-bits must be 32, 16, or 8"); |
| 8330 | return 1; |
| 8331 | } |
| 8332 | |
| 8333 | if (opt->role == DS4_DISTRIBUTED_COORDINATOR) { |
| 8334 | if (!opt->listen_host || opt->listen_port <= 0) { |
| 8335 | if (errlen) snprintf(err, errlen, "--role coordinator requires --listen HOST PORT"); |
| 8336 | return 1; |
| 8337 | } |
no test coverage detected