2018-05-26 14:03:12 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Copyright (c) 2014 - 2018. *)
|
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
2018-05-26 14:11:08 +04:00
|
|
|
open Signer_messages
|
2018-05-26 14:03:12 +04:00
|
|
|
|
|
|
|
let log = Logging.Client.Sign.lwt_log_notice
|
|
|
|
|
|
|
|
let run (cctxt : #Client_context.wallet) path =
|
|
|
|
Lwt_utils_unix.Socket.bind path >>=? fun fd ->
|
|
|
|
let rec loop () =
|
|
|
|
Lwt_unix.accept fd >>= fun (fd, _) ->
|
|
|
|
Lwt.async begin fun () ->
|
|
|
|
Lwt_utils_unix.Socket.recv fd Request.encoding >>=? function
|
|
|
|
| Sign req ->
|
|
|
|
let encoding = result_encoding Sign.Response.encoding in
|
2018-05-26 14:51:51 +04:00
|
|
|
Handler.sign cctxt req.pkh req.data >>= fun res ->
|
2018-05-26 14:03:12 +04:00
|
|
|
Lwt_utils_unix.Socket.send fd encoding res >>= fun _ ->
|
|
|
|
Lwt_unix.close fd >>= fun () ->
|
|
|
|
return ()
|
2018-05-26 14:51:51 +04:00
|
|
|
| Public_key pkh ->
|
2018-05-26 14:03:12 +04:00
|
|
|
let encoding = result_encoding Public_key.Response.encoding in
|
2018-05-26 14:51:51 +04:00
|
|
|
Handler.public_key cctxt pkh >>= fun res ->
|
2018-05-26 14:03:12 +04:00
|
|
|
Lwt_utils_unix.Socket.send fd encoding res >>= fun _ ->
|
|
|
|
Lwt_unix.close fd >>= fun () ->
|
|
|
|
return ()
|
|
|
|
end ;
|
|
|
|
loop ()
|
|
|
|
in
|
|
|
|
Lwt_unix.listen fd 10 ;
|
|
|
|
begin
|
|
|
|
match path with
|
|
|
|
| Tcp (host, port) ->
|
|
|
|
log "Accepting TCP requests on port %s:%d" host port
|
|
|
|
| Unix path ->
|
|
|
|
Sys.set_signal Sys.sigint (Signal_handle begin fun _ ->
|
|
|
|
Format.printf "Removing the local socket file and quitting.@." ;
|
|
|
|
Unix.unlink path ;
|
|
|
|
exit 0
|
|
|
|
end) ;
|
|
|
|
log "Accepting UNIX requests on %s" path
|
|
|
|
end >>= fun () ->
|
|
|
|
loop ()
|