add secret key to peer file
This commit is contained in:
parent
b8b93651af
commit
3a5368434c
@ -438,11 +438,19 @@ let public_key_encoding =
|
|||||||
(Crypto_box.to_public_key << MBytes.of_string)
|
(Crypto_box.to_public_key << MBytes.of_string)
|
||||||
string
|
string
|
||||||
|
|
||||||
|
let secret_key_encoding =
|
||||||
|
let open Data_encoding in
|
||||||
|
conv
|
||||||
|
(MBytes.to_string << Crypto_box.of_secret_key)
|
||||||
|
(Crypto_box.to_secret_key << MBytes.of_string)
|
||||||
|
string
|
||||||
|
|
||||||
let peers_file_encoding =
|
let peers_file_encoding =
|
||||||
let open Data_encoding in
|
let open Data_encoding in
|
||||||
obj3
|
obj4
|
||||||
(req "gid" string)
|
(req "gid" string)
|
||||||
(req "public_key" public_key_encoding)
|
(req "public_key" public_key_encoding)
|
||||||
|
(req "secret_key" secret_key_encoding)
|
||||||
(req "peers"
|
(req "peers"
|
||||||
(obj3
|
(obj3
|
||||||
(req "known"
|
(req "known"
|
||||||
@ -601,7 +609,7 @@ let bootstrap config limits =
|
|||||||
on_cancel (fun () -> close_msg_queue () ; return ()) ;
|
on_cancel (fun () -> close_msg_queue () ; return ()) ;
|
||||||
(* fill the known peers pools from last time *)
|
(* fill the known peers pools from last time *)
|
||||||
Data_encoding.Json.read_file config.peers_file >>= fun res ->
|
Data_encoding.Json.read_file config.peers_file >>= fun res ->
|
||||||
let known_peers, black_list, my_gid, my_public_key =
|
let known_peers, black_list, my_gid, my_public_key, my_secret_key =
|
||||||
let init_peers () =
|
let init_peers () =
|
||||||
let my_gid =
|
let my_gid =
|
||||||
fresh_gid () in
|
fresh_gid () in
|
||||||
@ -617,19 +625,19 @@ let bootstrap config limits =
|
|||||||
PeerMap.empty config.known_peers in
|
PeerMap.empty config.known_peers in
|
||||||
let black_list =
|
let black_list =
|
||||||
BlackList.empty in
|
BlackList.empty in
|
||||||
known_peers, black_list, my_gid, my_public_key in
|
known_peers, black_list, my_gid, my_public_key, my_secret_key in
|
||||||
match res with
|
match res with
|
||||||
| None ->
|
| None ->
|
||||||
let known_peers, black_list, my_gid, my_public_key = init_peers () in
|
let known_peers, black_list, my_gid, my_public_key, my_secret_key = init_peers () in
|
||||||
debug "(%a) peer cache initiated" pp_gid my_gid ;
|
debug "(%a) peer cache initiated" pp_gid my_gid ;
|
||||||
ref known_peers, ref black_list, my_gid, my_public_key
|
ref known_peers, ref black_list, my_gid, my_public_key, my_secret_key
|
||||||
| Some json ->
|
| Some json ->
|
||||||
match Data_encoding.Json.destruct peers_file_encoding json with
|
match Data_encoding.Json.destruct peers_file_encoding json with
|
||||||
| exception _ ->
|
| exception _ ->
|
||||||
let known_peers, black_list, my_gid, my_public_key = init_peers () in
|
let known_peers, black_list, my_gid, my_public_key, my_secret_key = init_peers () in
|
||||||
debug "(%a) peer cache reset" pp_gid my_gid ;
|
debug "(%a) peer cache reset" pp_gid my_gid ;
|
||||||
ref known_peers, ref black_list, my_gid, my_public_key
|
ref known_peers, ref black_list, my_gid, my_public_key, my_secret_key
|
||||||
| (my_gid, my_public_key, (k, b, w)) ->
|
| (my_gid, my_public_key, my_secret_key, (k, b, w)) ->
|
||||||
let white_list =
|
let white_list =
|
||||||
List.fold_right PointSet.add w PointSet.empty in
|
List.fold_right PointSet.add w PointSet.empty in
|
||||||
let known_peers =
|
let known_peers =
|
||||||
@ -654,7 +662,7 @@ let bootstrap config limits =
|
|||||||
(fun r (a, d) -> BlackList.add a d r)
|
(fun r (a, d) -> BlackList.add a d r)
|
||||||
BlackList.empty b in
|
BlackList.empty b in
|
||||||
debug "(%a) peer cache loaded" pp_gid my_gid ;
|
debug "(%a) peer cache loaded" pp_gid my_gid ;
|
||||||
ref known_peers, ref black_list, my_gid, my_public_key
|
ref known_peers, ref black_list, my_gid, my_public_key, my_secret_key
|
||||||
in
|
in
|
||||||
(* some peer reachability predicates *)
|
(* some peer reachability predicates *)
|
||||||
let black_listed (addr, _) =
|
let black_listed (addr, _) =
|
||||||
@ -673,6 +681,7 @@ let bootstrap config limits =
|
|||||||
Data_encoding.Json.construct peers_file_encoding @@
|
Data_encoding.Json.construct peers_file_encoding @@
|
||||||
(my_gid,
|
(my_gid,
|
||||||
my_public_key,
|
my_public_key,
|
||||||
|
my_secret_key,
|
||||||
PeerMap.fold
|
PeerMap.fold
|
||||||
(fun (addr, port) gid source (k, b, w) ->
|
(fun (addr, port) gid source (k, b, w) ->
|
||||||
let infos = match gid, source.connections with
|
let infos = match gid, source.connections with
|
||||||
|
@ -19,5 +19,7 @@ let random_nonce = Sodium.Box.random_nonce
|
|||||||
let increment_nonce = Sodium.Box.increment_nonce
|
let increment_nonce = Sodium.Box.increment_nonce
|
||||||
let box = Sodium.Box.Bigbytes.box
|
let box = Sodium.Box.Bigbytes.box
|
||||||
let box_open = Sodium.Box.Bigbytes.box_open
|
let box_open = Sodium.Box.Bigbytes.box_open
|
||||||
|
let to_secret_key = Sodium.Box.Bigbytes.to_secret_key
|
||||||
|
let of_secret_key = Sodium.Box.Bigbytes.of_secret_key
|
||||||
let to_public_key = Sodium.Box.Bigbytes.to_public_key
|
let to_public_key = Sodium.Box.Bigbytes.to_public_key
|
||||||
let of_public_key = Sodium.Box.Bigbytes.of_public_key
|
let of_public_key = Sodium.Box.Bigbytes.of_public_key
|
||||||
|
@ -18,5 +18,7 @@ val random_nonce : unit -> nonce
|
|||||||
val increment_nonce : ?step:int -> nonce -> nonce
|
val increment_nonce : ?step:int -> nonce -> nonce
|
||||||
val box : secret_key -> public_key -> MBytes.t -> nonce -> MBytes.t
|
val box : secret_key -> public_key -> MBytes.t -> nonce -> MBytes.t
|
||||||
val box_open : secret_key -> public_key -> MBytes.t -> nonce -> MBytes.t
|
val box_open : secret_key -> public_key -> MBytes.t -> nonce -> MBytes.t
|
||||||
|
val to_secret_key : MBytes.t -> secret_key
|
||||||
|
val of_secret_key : secret_key -> MBytes.t
|
||||||
val to_public_key : MBytes.t -> public_key
|
val to_public_key : MBytes.t -> public_key
|
||||||
val of_public_key : public_key -> MBytes.t
|
val of_public_key : public_key -> MBytes.t
|
||||||
|
Loading…
Reference in New Issue
Block a user