You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
2.5 KiB

  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2015 OpenWrt.org
  3. # Copyright (C) 2020 Nishant Sharma <nishant@hopbox.in>
  4. START=89
  5. STOP=11
  6. USE_PROCD=1
  7. PROG=/usr/bin/udpspeeder
  8. validate_udpspeeder_section() {
  9. uci_validate_section udpspeeder udpspeeder "${1}" \
  10. 'enabled:bool:0' \
  11. 'server:bool:0' \
  12. 'mode:integer:0' \
  13. 'mtu:integer:1250' \
  14. 'timeout:integer:8' \
  15. 'local:string' \
  16. 'remote:string' \
  17. 'report:integer:10' \
  18. 'disable_obscure:bool:0' \
  19. 'interval:integer:0' \
  20. 'fec:string:20:10' \
  21. 'disable_fec:bool:0' \
  22. 'sock_buf:integer:1024' \
  23. 'log_level:integer:4' \
  24. 'decode_buf:integer:2000' \
  25. 'fix_latency:bool:0' \
  26. 'queue_len:integer:200'
  27. }
  28. start_instance() {
  29. local section="$1"
  30. local server mode mtu timeout local remote report disable_obscure fifo interval fec disable_fec sock_buf queue_len \
  31. decode_buf sock_buf log_level enabled
  32. fifo="/tmp/udpspeeder-${section}.fifo"
  33. validate_udpspeeder_section $section || {
  34. echo "validation failed"
  35. return 1
  36. }
  37. if [ "${enabled}" -ne 1 ]
  38. then
  39. return 1
  40. fi
  41. procd_open_instance
  42. procd_set_param respawn
  43. procd_set_param stderr 1
  44. procd_set_param stdout 1
  45. procd_set_param command "${PROG}"
  46. if [ "${server}" -eq 1 ]
  47. then
  48. procd_append_param command -s
  49. else
  50. procd_append_param command -c
  51. fi
  52. if [ "${disable_fec}" -eq 1 ]
  53. then
  54. procd_append_param command --disable-fec
  55. else
  56. procd_append_param command --fec "${fec}"
  57. fi
  58. if [ "${fix_latency}" -eq 1 ] && [ "${mode}" -eq 0 ]
  59. then
  60. procd_append_param command --fix-latency
  61. fi
  62. if [ "${disable_obscure}" -eq 1 ]
  63. then
  64. procd_append_param command --disable-obscure
  65. fi
  66. procd_append_param command -l "${local}"
  67. procd_append_param command -r "${remote}"
  68. procd_append_param command --mode "${mode}"
  69. procd_append_param command --report "${report}"
  70. procd_append_param command --interval "${interval}"
  71. procd_append_param command --mtu "${mtu}"
  72. procd_append_param command --sock-buf "${sock_buf}"
  73. procd_append_param command --decode-buf "${decode_buf}"
  74. procd_append_param command --queue-len "${queue_len}"
  75. procd_append_param command --log-level "${log_level}"
  76. procd_append_param command --fifo "${fifo}"
  77. # procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
  78. procd_close_instance
  79. }
  80. start_service() {
  81. config_load 'udpspeeder'
  82. config_foreach start_instance 'udpspeeder'
  83. }
  84. stop_service()
  85. {
  86. service_stop ${PROG}
  87. }
  88. service_triggers()
  89. {
  90. procd_add_reload_trigger "udpspeeder"
  91. procd_add_validation validate_udpspeeder_section
  92. }