Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

98 lines (81 sloc) 2.945 kb
(*
This file is part of Arakoon, a distributed key-value store. Copyright
(C) 2010 Incubaid BVBA
Licensees holding a valid Incubaid license may use this file in
accordance with Incubaid's Arakoon commercial license agreement. For
more information on how to enter into this agreement, please contact
Incubaid (contact details can be found on www.arakoon.org/licensing).
Alternatively, this file may be redistributed and/or modified under
the terms of the GNU Affero General Public License version 3, as
published by the Free Software Foundation. Under this license, this
file is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License for more details.
You should have received a copy of the
GNU Affero General Public License along with this program (file "COPYING").
If not, see <http://www.gnu.org/licenses/>.
*)
open Lwt
open Baardskeerder
module ClientCfg = struct
type sa = string * int
type t = (string, sa) Hashtbl.t
let cfg_to buf (t:t) =
let entry2 buf k (ip,p) =
Pack.string_to buf k;
Pack.string_to buf ip;
Pack.vint_to buf p
in
Pack.hashtbl_to buf entry2 t
let cfg_from (buf: Pack.input) =
let entry_from buf =
let k = Pack.input_string buf in
let ip = Pack.input_string buf in
let p = Pack.input_vint buf in
let (sa:sa) = ip,p in
(k,sa)
in
Pack.hashtbl_from buf entry_from
let to_string t =
let buffer = Buffer.create 127 in
Hashtbl.iter (fun s (ip,p) ->
Buffer.add_string buffer (Printf.sprintf "(%s,(%s,%i))" s ip p)) t;
Buffer.contents buffer
let input_cfg ic =
let key_from ic =
Llio.input_string ic
in
let value_from ic =
Llio.input_string ic >>= fun ip ->
Llio.input_int ic >>= fun port ->
Lwt.return (ip,port)
in
Llio.input_hashtbl key_from value_from ic
let output_cfg oc cfg =
let helper oc key value =
Llio.output_string oc key >>= fun () ->
let (ip,port) = value in
Llio.output_string oc ip >>= fun () ->
Llio.output_int oc port
in
Llio.output_hashtbl helper oc cfg
let node_names (t:t) = Hashtbl.fold (fun k v acc -> k::acc) t []
let make () = Hashtbl.create 7
let add (t:t) name sa = Hashtbl.add t name sa
let get (t:t) name = Hashtbl.find t name
let from_file section fn = (* This is the format as defined in the extension *)
let inifile = new Inifiles.inifile fn in
let cfg = make () in
let _get s n p = Ini.get inifile s n p Ini.required in
let nodes = _get section "cluster" Ini.p_string_list in
let () = List.iter
(fun n ->
let ip = _get n "ip" Ini.p_string in
let port = _get n "client_port" Ini.p_int in
let sa = ip,port in
add cfg n sa
) nodes
in
cfg
end
Jump to Line
Something went wrong with that request. Please try again.