Skip to content

Commit

Permalink
Add ipv6only, debug.
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Jan 15, 2025
1 parent 7afd0e0 commit ef5b1a6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 21 deletions.
4 changes: 4 additions & 0 deletions .github/scripts/build-posix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ git clone https://github.com/savonet/ocaml-xiph.git
cd ocaml-xiph
opam install -y .

git clone https://github.com/savonet/ocaml-srt.git
cd ocaml-srt
opam install -y .

cd /tmp/liquidsoap-full/liquidsoap

./.github/scripts/checkout-deps.sh
Expand Down
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
(shine (< 0.2.0))
(soundtouch (< 0.1.9))
(speex (< 1.0.0))
(srt (< 0.3.0))
(srt (< 0.3.2))
(ssl (< 0.7.0))
(tls (< 1.0.2))
(sdl-liquidsoap (< 2))
Expand Down
2 changes: 1 addition & 1 deletion liquidsoap-core.opam
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ conflicts: [
"shine" {< "0.2.0"}
"soundtouch" {< "0.1.9"}
"speex" {< "1.0.0"}
"srt" {< "0.3.0"}
"srt" {< "0.3.2"}
"ssl" {< "0.7.0"}
"tls" {< "1.0.2"}
"sdl-liquidsoap" {< "2"}
Expand Down
55 changes: 36 additions & 19 deletions src/core/io/srt_io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ let common_options ~mode =
Lang.string_t,
Some (Lang.string "0.0.0.0"),
Some "Address to bind on the local machine. Used only in listener mode" );
( "ipv6only",
Lang.nullable_t Lang.bool_t,
Some (Lang.bool true),
Some
"If `true`, binding to the ipv6 wildcard address `::` will bind to \
both IPv6 and IPv4 wildcard address. Defaults to system default when \
`null`." );
( "polling_delay",
Lang.float_t,
Some (Lang.float 2.),
Expand Down Expand Up @@ -165,6 +172,7 @@ type common_options = {
hostname : string;
port : int;
bind_address : Unix.sockaddr;
ipv6only : bool option;
listen_callback : Srt.listen_callback option;
streamid : string option;
pbkeylen : int option;
Expand All @@ -190,6 +198,7 @@ let parse_common_options p =
( List.assoc "bind_address" p,
Printf.sprintf "Invalid address: %s" (Printexc.to_string exn) ))
in
let ipv6only = Lang.to_valued_option Lang.to_bool (List.assoc "ipv6only" p) in
let passphrase_v = List.assoc "passphrase" p in
let passphrase = Lang.to_valued_option Lang.to_string passphrase_v in
(match passphrase with
Expand Down Expand Up @@ -251,6 +260,7 @@ let parse_common_options p =
hostname = Lang.to_string (List.assoc "host" p);
port = Lang.to_int (List.assoc "port" p);
bind_address;
ipv6only;
listen_callback;
pbkeylen;
enforced_encryption;
Expand Down Expand Up @@ -401,12 +411,15 @@ let string_of_address = function
| Unix.ADDR_INET (addr, port) ->
Printf.sprintf "%s:%d" (Unix.string_of_inet_addr addr) port

let mk_socket ~payload_size ~messageapi () =
let mk_socket ~payload_size ~ipv6only ~messageapi () =
let s = Srt.create_socket () in
Srt.setsockflag s Srt.payloadsize payload_size;
Srt.setsockflag s Srt.transtype `Live;
Srt.setsockflag s Srt.messageapi messageapi;
Srt.setsockflag s Srt.enforced_encryption conf_enforced_encryption#get;
(match ipv6only with
| None -> ()
| Some v -> Srt.setsockflag s Srt.ipv6only v);
s

let close_socket s = Srt.close s
Expand Down Expand Up @@ -492,7 +505,7 @@ class virtual caller ~enforced_encryption ~pbkeylen ~passphrase ~streamid
(match Atomic.exchange socket None with
| None -> ()
| Some (_, s) -> close_socket s);
let s = mk_socket ~payload_size ~messageapi () in
let s = mk_socket ~ipv6only:None ~payload_size ~messageapi () in
try
Srt.setsockflag s Srt.sndsyn true;
Srt.setsockflag s Srt.rcvsyn true;
Expand Down Expand Up @@ -557,8 +570,8 @@ class virtual caller ~enforced_encryption ~pbkeylen ~passphrase ~streamid
end

class virtual listener ~enforced_encryption ~pbkeylen ~passphrase ~max_clients
~listen_callback ~payload_size ~messageapi ~bind_address ~read_timeout
~write_timeout ~on_connect ~on_disconnect () =
~listen_callback ~payload_size ~messageapi ~bind_address ~ipv6only
~read_timeout ~write_timeout ~on_connect ~on_disconnect () =
object (self)
val mutable client_sockets = []
method virtual id : string
Expand All @@ -577,8 +590,10 @@ class virtual listener ~enforced_encryption ~pbkeylen ~passphrase ~max_clients
match Atomic.get listening_socket with
| Some s -> s
| None -> (
let s = mk_socket ~payload_size ~messageapi () in
let s = mk_socket ~payload_size ~ipv6only ~messageapi () in
try
Printf.printf "BIND SRT SOCKET: %s\n"
(string_of_address bind_address);
Srt.bind s bind_address;
let max_clients_callback =
Option.map
Expand Down Expand Up @@ -796,9 +811,9 @@ class virtual input_base ~max ~self_sync ~on_connect ~on_disconnect
end

class input_listener ~enforced_encryption ~pbkeylen ~passphrase ~listen_callback
~bind_address ~max ~payload_size ~self_sync ~on_connect ~on_disconnect
~read_timeout ~write_timeout ~messageapi ~dump ~on_start ~on_stop ~autostart
format =
~bind_address ~ipv6only ~max ~payload_size ~self_sync ~on_connect
~on_disconnect ~read_timeout ~write_timeout ~messageapi ~dump ~on_start
~on_stop ~autostart format =
object (self)
inherit
input_base
Expand All @@ -808,8 +823,8 @@ class input_listener ~enforced_encryption ~pbkeylen ~passphrase ~listen_callback
inherit
listener
~enforced_encryption ~pbkeylen ~passphrase ~listen_callback
~max_clients:(Some 1) ~bind_address ~payload_size ~read_timeout
~write_timeout ~messageapi ~on_connect ~on_disconnect ()
~max_clients:(Some 1) ~bind_address ~ipv6only ~payload_size
~read_timeout ~write_timeout ~messageapi ~on_connect ~on_disconnect ()

method private get_socket =
match self#get_sockets with
Expand Down Expand Up @@ -880,6 +895,7 @@ let _ =
pbkeylen;
passphrase;
bind_address;
ipv6only;
listen_callback;
polling_delay;
read_timeout;
Expand Down Expand Up @@ -913,9 +929,9 @@ let _ =
| `Listener ->
(new input_listener
~enforced_encryption ~pbkeylen ~passphrase ~listen_callback
~bind_address ~read_timeout ~write_timeout ~payload_size
~self_sync ~on_connect ~on_disconnect ~messageapi ~max ~dump
~on_start ~on_stop ~autostart format
~bind_address ~ipv6only ~read_timeout ~write_timeout
~payload_size ~self_sync ~on_connect ~on_disconnect ~messageapi
~max ~dump ~on_start ~on_stop ~autostart format
:> < Start_stop.active_source
; get_sockets : (Unix.sockaddr * Srt.socket) list >)
| `Caller ->
Expand Down Expand Up @@ -1050,7 +1066,7 @@ class output_caller ~enforced_encryption ~pbkeylen ~passphrase ~streamid
class output_listener ~enforced_encryption ~pbkeylen ~passphrase
~listen_callback ~max_clients ~payload_size ~messageapi ~on_start ~on_stop
~infallible ~register_telnet ~autostart ~on_connect ~on_disconnect
~bind_address ~read_timeout ~write_timeout ~encoder_factory source =
~bind_address ~ipv6only ~read_timeout ~write_timeout ~encoder_factory source =
object (self)
inherit
output_base
Expand All @@ -1059,9 +1075,9 @@ class output_listener ~enforced_encryption ~pbkeylen ~passphrase

inherit
listener
~bind_address ~payload_size ~read_timeout ~write_timeout ~messageapi
~on_connect ~on_disconnect ~enforced_encryption ~pbkeylen ~passphrase
~listen_callback ~max_clients ()
~bind_address ~ipv6only ~payload_size ~read_timeout ~write_timeout
~messageapi ~on_connect ~on_disconnect ~enforced_encryption ~pbkeylen
~passphrase ~listen_callback ~max_clients ()

method private client_error socket exn bt =
Utils.log_exception ~log:self#log
Expand Down Expand Up @@ -1106,6 +1122,7 @@ let _ =
pbkeylen;
passphrase;
bind_address;
ipv6only;
listen_callback;
polling_delay;
read_timeout;
Expand Down Expand Up @@ -1155,8 +1172,8 @@ let _ =
| `Listener ->
(new output_listener
~enforced_encryption ~pbkeylen ~passphrase ~bind_address
~read_timeout ~write_timeout ~payload_size ~autostart ~on_start
~on_stop ~infallible ~register_telnet ~messageapi
~ipv6only ~read_timeout ~write_timeout ~payload_size ~autostart
~on_start ~on_stop ~infallible ~register_telnet ~messageapi
~encoder_factory ~on_connect ~on_disconnect ~listen_callback
~max_clients source
:> < Output.output
Expand Down

0 comments on commit ef5b1a6

Please sign in to comment.