this repo has no description
at main 1.8 kB view raw
1open Swim.Types 2 3external env_cast : 'a -> 'b = "%identity" 4 5let test_key = 6 "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" 7 8let () = 9 let use_encryption = 10 Array.length Sys.argv > 1 && Sys.argv.(1) = "--encrypt" 11 in 12 Eio_main.run @@ fun env -> 13 let env = env_cast env in 14 Eio.Switch.run @@ fun sw -> 15 let config = 16 { 17 default_config with 18 bind_addr = "\127\000\000\001"; 19 bind_port = 7947; 20 node_name = Some "ocaml-node"; 21 protocol_interval = 1.0; 22 probe_timeout = 0.5; 23 secret_key = test_key; 24 cluster_name = ""; 25 encryption_enabled = use_encryption; 26 } 27 in 28 let env_wrap = { stdenv = env; sw } in 29 match Swim.Cluster.create ~sw ~env:env_wrap ~config with 30 | Error `Invalid_key -> 31 Printf.eprintf "Error: Invalid encryption key\n"; 32 exit 1 33 | Ok cluster -> 34 Printf.printf 35 "OCaml SWIM node started on 127.0.0.1:%d (encryption=%b)\n%!" 36 config.bind_port config.encryption_enabled; 37 Swim.Cluster.start cluster; 38 39 let go_node = 40 make_node_info 41 ~id:(node_id_of_string "go-node") 42 ~addr:(`Udp (Eio.Net.Ipaddr.of_raw "\127\000\000\001", 7946)) 43 ~meta:"" 44 in 45 Printf.printf "Adding Go node to membership...\n%!"; 46 Swim.Cluster.add_member cluster go_node; 47 48 Printf.printf "Running for 30 seconds...\n%!"; 49 for i = 1 to 30 do 50 Eio.Time.sleep env#clock 1.0; 51 let stats = Swim.Cluster.stats cluster in 52 Printf.printf 53 "[%2d] alive=%d suspect=%d dead=%d sent=%d recv=%d dropped=%d\n%!" i 54 stats.nodes_alive stats.nodes_suspect stats.nodes_dead stats.msgs_sent 55 stats.msgs_received stats.msgs_dropped 56 done; 57 58 Printf.printf "Shutting down...\n%!"; 59 Swim.Cluster.shutdown cluster