| 317 | } |
| 318 | |
| 319 | static const struct bias *set_bias(struct layer *layer, |
| 320 | const struct short_channel_id_dir *scidd, |
| 321 | const char *description TAKES, |
| 322 | s8 bias_factor, |
| 323 | bool relative, |
| 324 | u64 timestamp) |
| 325 | { |
| 326 | struct bias *bias; |
| 327 | |
| 328 | bias = bias_hash_get(layer->biases, scidd); |
| 329 | if (!bias) { |
| 330 | bias = tal(layer, struct bias); |
| 331 | bias->scidd = *scidd; |
| 332 | bias_hash_add(layer->biases, bias); |
| 333 | bias->bias = 0; |
| 334 | } else { |
| 335 | tal_free(bias->description); |
| 336 | } |
| 337 | int bias_new = relative ? bias->bias + bias_factor : bias_factor; |
| 338 | bias_new = MIN(100, bias_new); |
| 339 | bias_new = MAX(-100, bias_new); |
| 340 | bias->bias = bias_new; |
| 341 | bias->description = tal_strdup_or_null(bias, description); |
| 342 | bias->timestamp = timestamp; |
| 343 | |
| 344 | /* Don't bother keeping around zero biases */ |
| 345 | if (bias->bias == 0) { |
| 346 | bias_hash_del(layer->biases, bias); |
| 347 | bias = tal_free(bias); |
| 348 | } |
| 349 | return bias; |
| 350 | } |
| 351 | |
| 352 | static const struct node_bias *set_node_bias(struct layer *layer, |
| 353 | const struct node_id *node, |
no test coverage detected