Skip to content

Commit

Permalink
replace deprecated Fmt.kstrf with Fmt.kstr
Browse files Browse the repository at this point in the history
Signed-off-by: David Scott <[email protected]>
  • Loading branch information
djs55 committed Jan 17, 2022
1 parent 129afb0 commit 47cebca
Show file tree
Hide file tree
Showing 27 changed files with 84 additions and 84 deletions.
2 changes: 1 addition & 1 deletion src/bin/bind.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ open Vmnet

let is_windows = Sys.os_type = "Win32"

let failf fmt = Fmt.kstrf (fun e -> Lwt_result.fail (`Msg e)) fmt
let failf fmt = Fmt.kstr (fun e -> Lwt_result.fail (`Msg e)) fmt

module Make(Socket: Sig.SOCKETS) = struct

Expand Down
2 changes: 1 addition & 1 deletion src/bin/connect.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module Unix = struct
| Error e ->
Log.err (fun f -> f "vsock connect write got %a" pp_write_error e);
close flow >>= fun () ->
Fmt.kstrf Lwt.fail_with "%a" pp_write_error e
Fmt.kstr Lwt.fail_with "%a" pp_write_error e
end

module Hvsock = struct
Expand Down
2 changes: 1 addition & 1 deletion src/dns_forward/dns_forward_error.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ open Lwt.Infix

type 'a t = ('a, [ `Msg of string ]) Lwt_result.t

let errorf fmt = Fmt.kstrf (fun s -> Lwt.return (Error (`Msg s))) fmt
let errorf fmt = Fmt.kstr (fun s -> Lwt.return (Error (`Msg s))) fmt

module FromFlowError(Flow: Mirage_flow.S) = struct
let (>>=) m f = m >>= function
Expand Down
2 changes: 1 addition & 1 deletion src/dns_mirage/dns_resolver_mirage.ml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ module Make(Time:Mirage_time.S)(S:Mirage_stack.V4) = struct
let txfn buf =
S.UDPV4.write ~src_port ~dst ~dst_port udp buf >>= function
| Error e ->
Fmt.kstrf fail_with
Fmt.kstr fail_with
"Attempting to communicate with remote resolver: %a"
S.UDPV4.pp_error e
| Ok () -> Lwt.return_unit
Expand Down
2 changes: 1 addition & 1 deletion src/fs9p/fs9p.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let ok x = Lwt.return (Ok x)

let map_error x = Fs9p_error.map_error x

let error fmt = Fmt.kstrf (fun s -> Lwt.return (Fs9p_error.error "%s" s)) fmt
let error fmt = Fmt.kstr (fun s -> Lwt.return (Fs9p_error.error "%s" s)) fmt

let err_not_a_dir name = error "%S is not a directory" name

Expand Down
2 changes: 1 addition & 1 deletion src/hostnet/capture.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Make(Input: Sig.VMNET) = struct
let lift_error = function
| Ok x -> Ok x
| Error (#Mirage_net.Net.error as e) -> Error e
| Error e -> Fmt.kstrf (fun s -> Error (`Unknown s)) "%a" Input.pp_error e
| Error e -> Fmt.kstr (fun s -> Error (`Unknown s)) "%a" Input.pp_error e

type packet = {
id: int; (* unique id *)
Expand Down
2 changes: 1 addition & 1 deletion src/hostnet/cohttp_mirage_io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module Make (Channel: Mirage_channel.S) = struct
type oc = Channel.t
type conn = Channel.flow

let failf fmt = Fmt.kstrf Lwt.fail_with fmt
let failf fmt = Fmt.kstr Lwt.fail_with fmt

let read_line ic =
Channel.read_line ic >>= function
Expand Down
2 changes: 1 addition & 1 deletion src/hostnet/filter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Make(Input: Sig.VMNET) = struct
let lift_error = function
| Ok x -> Ok x
| Error (#Mirage_net.Net.error as e) -> Error e
| Error e -> Fmt.kstrf (fun s -> Error (`Unknown s)) "%a" Input.pp_error e
| Error e -> Fmt.kstr (fun s -> Error (`Unknown s)) "%a" Input.pp_error e

type t = {
input: Input.t;
Expand Down
22 changes: 11 additions & 11 deletions src/hostnet/forward.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@ let set_allowed_addresses ips =
));
allowed_addresses := ips

let errorf fmt = Fmt.kstrf (fun e -> Error (`Msg e)) fmt
let errorf' fmt = Fmt.kstrf (fun e -> Lwt.return (Error (`Msg e))) fmt
let errorf fmt = Fmt.kstr (fun e -> Error (`Msg e)) fmt
let errorf' fmt = Fmt.kstr (fun e -> Lwt.return (Error (`Msg e))) fmt

module Port = struct
type t = Forwarder.Frame.Destination.t

let to_string = function
| `Tcp (ip, port) ->
Fmt.strf "tcp:%a:%d" Ipaddr.pp ip port
Fmt.str "tcp:%a:%d" Ipaddr.pp ip port
| `Udp (ip, port) ->
Fmt.strf "udp:%a:%d" Ipaddr.pp ip port
Fmt.str "udp:%a:%d" Ipaddr.pp ip port
| `Unix path ->
Fmt.strf "unix:%s" (Base64.encode_exn path)
Fmt.str "unix:%s" (Base64.encode_exn path)

let of_string x =
try
Expand Down Expand Up @@ -80,7 +80,7 @@ struct
let get_key t = t.local

let to_string t =
Fmt.strf "%s:%s" (Port.to_string t.local) (Port.to_string t.remote_port)
Fmt.str "%s:%s" (Port.to_string t.local) (Port.to_string t.remote_port)

let description_of_format =
"tcp:<local IP>:<local port>:tcp:<remote IP>:<remote port>
Expand Down Expand Up @@ -190,13 +190,13 @@ unix:<base64-encoded local path>:unix:<base64-encoded remote path>"
let conn_read flow buf =
Mux.Channel.read_into flow buf >>= function
| Ok `Eof -> Lwt.fail End_of_file
| Error e -> Fmt.kstrf Lwt.fail_with "%a" Mux.Channel.pp_error e
| Error e -> Fmt.kstr Lwt.fail_with "%a" Mux.Channel.pp_error e
| Ok (`Data ()) -> Lwt.return ()

let conn_write flow buf =
Mux.Channel.write flow buf >>= function
| Error `Closed -> Lwt.fail End_of_file
| Error e -> Fmt.kstrf Lwt.fail_with "%a" Mux.Channel.pp_write_error e
| Error e -> Fmt.kstr Lwt.fail_with "%a" Mux.Channel.pp_write_error e
| Ok () -> Lwt.return ()

let start_udp_proxy description remote_port server =
Expand Down Expand Up @@ -293,7 +293,7 @@ unix:<base64-encoded local path>:unix:<base64-encoded remote path>"
match t.local with
| `Tcp (local_ip, local_port) ->
let description =
Fmt.strf "forwarding from tcp:%a:%d" Ipaddr.pp local_ip local_port
Fmt.str "forwarding from tcp:%a:%d" Ipaddr.pp local_ip local_port
in
Lwt.catch (fun () ->
check_bind_allowed local_ip >>= fun () ->
Expand Down Expand Up @@ -326,7 +326,7 @@ unix:<base64-encoded local path>:unix:<base64-encoded remote path>"
)
| `Udp (local_ip, local_port) ->
let description =
Fmt.strf "forwarding from udp:%a:%d" Ipaddr.pp local_ip local_port
Fmt.str "forwarding from udp:%a:%d" Ipaddr.pp local_ip local_port
in
Lwt.catch (fun () ->
check_bind_allowed local_ip >>= fun () ->
Expand Down Expand Up @@ -359,7 +359,7 @@ unix:<base64-encoded local path>:unix:<base64-encoded remote path>"
)
| `Unix path ->
let description =
Fmt.strf "forwarding from unix:%s" path
Fmt.str "forwarding from unix:%s" path
in
Lwt.catch (fun () ->
Socket.Stream.Unix.bind ~description path
Expand Down
2 changes: 1 addition & 1 deletion src/hostnet/frame.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let ( >>= ) m f = match m with
| Ok x -> f x
| Error x -> Error x

let errorf fmt = Fmt.kstrf (fun e -> Error (`Msg e)) fmt
let errorf fmt = Fmt.kstr (fun e -> Error (`Msg e)) fmt

let need_space_for bufs n description =
if Cstructs.len bufs < n
Expand Down
32 changes: 16 additions & 16 deletions src/hostnet/host.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module Common = struct
| #Mirage_flow.write_error as e -> Mirage_flow.pp_write_error ppf e
| #error as e -> pp_error ppf e

let errorf fmt = Fmt.kstrf (fun s -> Lwt_result.fail (`Msg s)) fmt
let errorf fmt = Fmt.kstr (fun s -> Lwt_result.fail (`Msg s)) fmt

let ip_port_of_sockaddr sockaddr =
try match sockaddr with
Expand Down Expand Up @@ -126,7 +126,7 @@ module Sockets = struct

type address = Ipaddr.t * int

let string_of_flow t = Fmt.strf "udp -> %s" (string_of_address t.address)
let string_of_flow t = Fmt.str "udp -> %s" (string_of_address t.address)

let of_fd
?idx ?(read_buffer_size = Constants.max_udp_length)
Expand Down Expand Up @@ -280,7 +280,7 @@ module Sockets = struct

let bind ?(description="") (ip, port) =
let description =
Fmt.strf "udp:%a:%d %s" Ipaddr.pp ip port description
Fmt.str "udp:%a:%d %s" Ipaddr.pp ip port description
in
let sockaddr = make_sockaddr(ip, port) in
register_connection description >>= fun idx ->
Expand Down Expand Up @@ -311,7 +311,7 @@ module Sockets = struct
| Uwt.Ok sockaddr ->
begin match ip_port_of_sockaddr sockaddr with
| Some (ip, port) ->
Fmt.strf "udp:%a:%d" Ipaddr.pp ip port,
Fmt.str "udp:%a:%d" Ipaddr.pp ip port,
begin match ip with
| Ipaddr.V4 _ -> "UDPv4"
| Ipaddr.V6 _ -> "UDPv6"
Expand All @@ -326,7 +326,7 @@ module Sockets = struct
make ~idx ~label fd
| Uwt.Error error ->
let msg =
Fmt.strf "Socket.UDP?.of_bound_fd failed with %s" (Uwt.strerror error)
Fmt.str "Socket.UDP?.of_bound_fd failed with %s" (Uwt.strerror error)
in
Log.err (fun f -> f "Socket.UDP?.of_bound_fd: %s" msg);
failwith msg
Expand All @@ -336,7 +336,7 @@ module Sockets = struct
| Unix.ADDR_INET(iaddr, port) ->
Ipaddr.of_string_exn (Unix.string_of_inet_addr iaddr), port
| _ ->
Fmt.kstrf invalid_arg "Socket.%s.getsockname: passed a non-TCP socket"
Fmt.kstr invalid_arg "Socket.%s.getsockname: passed a non-TCP socket"
label

let shutdown server =
Expand Down Expand Up @@ -385,7 +385,7 @@ module Sockets = struct
let data = Cstruct.sub buffer 0 n in
(* construct a flow with this buffer available for reading *)
(* No new fd so no new idx *)
let description = Fmt.strf "udp:%s" (string_of_address address) in
let description = Fmt.str "udp:%s" (string_of_address address) in
let flow =
of_fd ~description ~read_buffer_size:0 ~already_read:(Some data)
(sockaddr_of_address address) address t.fd
Expand Down Expand Up @@ -454,7 +454,7 @@ module Sockets = struct
{ idx; label; description; fd; read_buffer; read_buffer_size; closed }

let connect ?(read_buffer_size = default_read_buffer_size) (ip, port) =
let description = Fmt.strf "tcp:%a:%d" Ipaddr.pp ip port in
let description = Fmt.str "tcp:%a:%d" Ipaddr.pp ip port in
let label = match ip with
| Ipaddr.V4 _ -> "TCPv4"
| Ipaddr.V6 _ -> "TCPv6" in
Expand Down Expand Up @@ -624,7 +624,7 @@ module Sockets = struct

let bind_one ?(description="") (ip, port) =
let description =
Fmt.strf "tcp:%a:%d %s" Ipaddr.pp ip port description
Fmt.str "tcp:%a:%d %s" Ipaddr.pp ip port description
in
register_connection description >>= fun idx ->
let fd =
Expand All @@ -639,7 +639,7 @@ module Sockets = struct
if not(Uwt.Int_result.is_ok result) then begin
let error = Uwt.Int_result.to_error result in
let msg =
Fmt.strf "Socket.%s.bind(%s, %d): %s" label (Ipaddr.to_string ip)
Fmt.str "Socket.%s.bind(%s, %d): %s" label (Ipaddr.to_string ip)
port (Uwt.strerror error)
in
Log.err (fun f -> f "Socket.%s.bind: %s" label msg);
Expand All @@ -658,7 +658,7 @@ module Sockets = struct
end
| Uwt.Error error ->
let msg =
Fmt.strf "Socket.%s.bind(%a, %d): %s" label Ipaddr.pp ip port
Fmt.str "Socket.%s.bind(%a, %d): %s" label Ipaddr.pp ip port
(Uwt.strerror error)
in
Log.debug (fun f -> f "Socket.%s.bind: %s" label msg);
Expand Down Expand Up @@ -700,7 +700,7 @@ module Sockets = struct
let of_bound_fd ?(read_buffer_size = default_read_buffer_size) fd =
let description = match Unix.getsockname fd with
| Unix.ADDR_INET(iaddr, port) ->
Fmt.strf "tcp:%s:%d" (Unix.string_of_inet_addr iaddr) port
Fmt.str "tcp:%s:%d" (Unix.string_of_inet_addr iaddr) port
| _ -> "of_bound_fd: unknown TCP socket" in
let fd = Uwt.Tcp.opentcp_exn fd in
let idx = register_connection_no_limit description in
Expand Down Expand Up @@ -739,7 +739,7 @@ module Sockets = struct
| Uwt.Ok sockaddr ->
begin match ip_port_of_sockaddr sockaddr with
| Some (ip, port) ->
Fmt.strf "tcp:%s:%d" (Ipaddr.to_string ip) port,
Fmt.str "tcp:%s:%d" (Ipaddr.to_string ip) port,
begin match ip with
| Ipaddr.V4 _ -> "TCPv4"
| Ipaddr.V6 _ -> "TCPv6"
Expand Down Expand Up @@ -931,7 +931,7 @@ module Sockets = struct
let bind ?(description="") path =
Lwt.catch (fun () -> Uwt.Fs.unlink path) (fun _ -> Lwt.return ())
>>= fun () ->
let description = Fmt.strf "unix:%s %s" path description in
let description = Fmt.str "unix:%s %s" path description in
register_connection description >>= fun idx ->
let fd = Uwt.Pipe.init () in
Lwt.catch (fun () ->
Expand Down Expand Up @@ -1009,7 +1009,7 @@ module Sockets = struct
{ idx; fd; closed = false; disable_connection_tracking = false }
| Uwt.Error error ->
let msg =
Fmt.strf "Socket.Pipe.of_bound_fd (read_buffer_size=%d) failed \
Fmt.str "Socket.Pipe.of_bound_fd (read_buffer_size=%d) failed \
with %s" read_buffer_size (Uwt.strerror error)
in
Log.err (fun f -> f "%s" msg);
Expand Down Expand Up @@ -1052,7 +1052,7 @@ module Files = struct
Uwt.Fs.close file
)
) (fun e ->
Lwt_result.fail (`Msg (Fmt.strf "reading %s: %a" path Fmt.exn e))
Lwt_result.fail (`Msg (Fmt.str "reading %s: %a" path Fmt.exn e))
)

(* NOTE(djs55): Fs_event didn't work for me on MacOS *)
Expand Down
6 changes: 3 additions & 3 deletions src/hostnet/hostnet_http.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let src =

module Log = (val Logs.src_log src : Logs.LOG)

let errorf fmt = Fmt.kstrf (fun e -> Lwt.return (Error (`Msg e))) fmt
let errorf fmt = Fmt.kstr (fun e -> Lwt.return (Error (`Msg e))) fmt

module Exclude = struct

Expand Down Expand Up @@ -144,7 +144,7 @@ module Make
None
end

let string_of_address (ip, port) = Fmt.strf "%s:%d" (Ipaddr.to_string ip) port
let string_of_address (ip, port) = Fmt.str "%s:%d" (Ipaddr.to_string ip) port

type t = {
http: proxy option;
Expand Down Expand Up @@ -459,7 +459,7 @@ module Make
| Ok ((ip, port) as address) ->
let host = Ipaddr.V4.to_string dst in
let description outgoing =
Fmt.strf "%s:443 %s %s:%d" host
Fmt.str "%s:443 %s %s:%d" host
(if outgoing then "-->" else "<--") (Ipaddr.to_string ip) port
in
Log.info (fun f -> f "%s: CONNECT" (description true));
Expand Down
2 changes: 1 addition & 1 deletion src/hostnet/hostnet_udp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ struct
{ max_idle_time; max_active_flows; new_flow_lock; background_gc_t; table; by_last_use; send_reply; preserve_remote_port }

let description { src = src, src_port; dst = dst, dst_port; _ } =
Fmt.strf "udp:%a:%d-%a:%d" Ipaddr.pp src src_port Ipaddr.pp
Fmt.str "udp:%a:%d-%a:%d" Ipaddr.pp src src_port Ipaddr.pp
dst dst_port

let outside_to_inside t flow server d =
Expand Down
4 changes: 2 additions & 2 deletions src/hostnet/mux.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ module Make (Netif: Mirage_net.S) = struct
let lift_error: ('a, Netif.error) result -> ('a, error) result = function
| Ok x -> Ok x
| Error (#Mirage_net.Net.error as e) -> Error e
| Error e -> Fmt.kstrf (fun s -> Error (`Unknown s)) "%a" Netif.pp_error e
| Error e -> Fmt.kstr (fun s -> Error (`Unknown s)) "%a" Netif.pp_error e

let filesystem t =
let xs =
RuleMap.fold
(fun ip t acc ->
Fmt.strf "%a last_active_time = %.1f" Ipaddr.V4.pp ip
Fmt.str "%a last_active_time = %.1f" Ipaddr.V4.pp ip
t.last_active_time
:: acc
) t.rules []
Expand Down
Loading

0 comments on commit 47cebca

Please sign in to comment.