encrypt arbitrary net frames
This commit is contained in:
parent
1733cd499a
commit
56e5fc3213
@ -181,7 +181,7 @@ and peer = {
|
|||||||
last_seen : unit -> float ;
|
last_seen : unit -> float ;
|
||||||
disconnect : unit -> unit Lwt.t;
|
disconnect : unit -> unit Lwt.t;
|
||||||
send : packet -> unit Lwt.t ;
|
send : packet -> unit Lwt.t ;
|
||||||
send_encr : MBytes.t -> unit Lwt.t ;
|
send_encr : frame -> unit Lwt.t ;
|
||||||
}
|
}
|
||||||
|
|
||||||
(* The (internal) type of network events, those dispatched from peer
|
(* The (internal) type of network events, those dispatched from peer
|
||||||
@ -357,7 +357,7 @@ let connect_to_peer config limits my_gid my_public_key my_nonce my_secret_key so
|
|||||||
let disconnect () = cancel () in
|
let disconnect () = cancel () in
|
||||||
let send p = send_packet socket p >>= fun _ -> return () in
|
let send p = send_packet socket p >>= fun _ -> return () in
|
||||||
let send_encr msg =
|
let send_encr msg =
|
||||||
let msg_encr = Crypto_box.box my_secret_key public_key msg (current_nonce ()) in
|
let msg_encr = Crypto_box.box my_secret_key public_key (to_raw msg) (current_nonce ()) in
|
||||||
let packet = Box msg_encr in
|
let packet = Box msg_encr in
|
||||||
next_nonce (); send_packet socket packet >>= fun _ -> return () in
|
next_nonce (); send_packet socket packet >>= fun _ -> return () in
|
||||||
(* net object construction *)
|
(* net object construction *)
|
||||||
@ -388,7 +388,10 @@ let connect_to_peer config limits my_gid my_public_key my_nonce my_secret_key so
|
|||||||
|> function
|
|> function
|
||||||
| None -> debug "(%a) cannot decrypt message (from peer) %a @ %a:%d"
|
| None -> debug "(%a) cannot decrypt message (from peer) %a @ %a:%d"
|
||||||
pp_gid my_gid pp_gid gid Ipaddr.pp_hum addr port ; receiver ()
|
pp_gid my_gid pp_gid gid Ipaddr.pp_hum addr port ; receiver ()
|
||||||
| Some msg -> push (Recv (peer, [B msg])) ; receiver ()
|
| Some bytes -> of_raw bytes |> function
|
||||||
|
| None -> debug "(%a) cannot decode message (from peer) %a @ %a:%d"
|
||||||
|
pp_gid my_gid pp_gid gid Ipaddr.pp_hum addr port ; receiver ()
|
||||||
|
| Some msg -> push (Recv (peer, msg)) ; receiver ()
|
||||||
in
|
in
|
||||||
(* The polling loop *)
|
(* The polling loop *)
|
||||||
let rec pulse_monitor ping =
|
let rec pulse_monitor ping =
|
||||||
|
Loading…
Reference in New Issue
Block a user