<commit_before>open Lwt
open Tsc
open Wire
open Int64
open Ntp_client

let red fmt    = Printf.sprintf ("\027[31m"^^fmt^^"\027[m")
let green fmt  = Printf.sprintf ("\027[32m"^^fmt^^"\027[m")
let yellow fmt = Printf.sprintf ("\027[33m"^^fmt^^"\027[m")
let blue fmt   = Printf.sprintf ("\027[36m"^^fmt^^"\027[m")

let server = Ipaddr.V4.of_string_exn  "172.16.58.3"

module Main (C: V1_LWT.CONSOLE) (S: V1_LWT.STACKV4) = struct
    module U = S.UDPV4


    let connect_to_server stack server =
        let udp = S.udpv4 stack in
        let st, push_st = Lwt_stream.create() in
        S.listen_udpv4 stack ~port:123 (fun ~src ~dst ~src_port data ->
            let ts = Int64.of_int @@ Tsc.rdtsc() in
            push_st @@ Some (data, ts);
            Lwt.return ()
            );
            st
    let rx stream =
        Lwt_stream.get stream
        >>= function
            | None -> Lwt.fail (Failure "heck")
            | Some buf -> Lwt.return buf

    let dump_packet c rxd nonce =
        let packet = validate_reply rxd nonce in
        match packet with
            | None -> C.log_s c (yellow "fail")
            | Some pkt -> C.log_s c (Printf.sprintf "recv %Lx\ntrans %Lx\ntime %Lx" (ts_to_int64 pkt.recv_ts) (ts_to_int64 pkt.trans_ts)(Int64.of_int @@ Tsc.rdtsc()))
        let start c s =
            let st = connect_to_server s server in
            let udp = S.udpv4 s in
            let state = blank_state in

            let q = new_query (Int64.of_int @@ Tsc.rdtsc()) in
            C.log_s c (Printf.sprintf "send ONE %Lx" ((fst q).tsc)) >>= fun () ->
            U.write ~source_port:123 ~dest_ip:server ~dest_port:123 udp (snd q) >>= fun () ->
            rx st >>= fun (rxd) ->
            C.log_s c (Printf.sprintf "recv ONE %Lx" (snd rxd)) >>= fun () ->
            let state = add_sample state (fst rxd) (fst q) (snd rxd) in
            let x = (History.nth state.samples 0)  in
            Lwt.return(update_estimators state) >>= fun(state) ->





            let q = new_query (Int64.of_int @@ Tsc.rdtsc()) in
            C.log_s c (Printf.sprintf "send TWO %Lx" ((fst q).tsc)) >>= fun () ->
            U.write ~source_port:123 ~dest_ip:server ~dest_port:123 udp (snd q) >>= fun () ->
            rx st >>= fun (rxd) ->
            C.log_s c (Printf.sprintf "recv TWO %Lx" (snd rxd)) >>= fun () ->
            let state = add_sample state (fst rxd) (fst q) (snd rxd) in
            Lwt.return(update_estimators state) >>= fun(state) ->


            let x = state.estimators.theta_hat_and_error in
            match x with
            | Some (x,y) -> C.log_s c (Printf.sprintf "THETA %.15E" (x)) >>= fun () ->


            OS.Time.sleep 2.0 >>= fun () ->
            let q = new_query (Int64.of_int @@ Tsc.rdtsc()) in
            C.log_s c (Printf.sprintf "send THREE %Lx" ((fst q).tsc)) >>= fun () ->
            U.write ~source_port:123 ~dest_ip:server ~dest_port:123 udp (snd q) >>= fun () ->
            rx st >>= fun (rxd) ->
            C.log_s c (Printf.sprintf "recv THREE %Lx" (snd rxd)) >>= fun () ->
            let state = add_sample state (fst rxd) (fst q) (snd rxd) in
            Lwt.return(update_estimators state) >>= fun(state) ->



            let x = state.estimators.p_hat_and_error in
            match x with
            | Some (x,y) -> C.log_s c (Printf.sprintf "THETA TWO %.15E" (x)) >>= fun () ->


<commit_msg>ppx_deriving works ~<commit_after>open Lwt
open Tsc
open Types
open Wire
open Int64
open Ntp_client

let red fmt    = Printf.sprintf ("\027[31m"^^fmt^^"\027[m")
let green fmt  = Printf.sprintf ("\027[32m"^^fmt^^"\027[m")
let yellow fmt = Printf.sprintf ("\027[33m"^^fmt^^"\027[m")
let blue fmt   = Printf.sprintf ("\027[36m"^^fmt^^"\027[m")

let server = Ipaddr.V4.of_string_exn  "172.16.58.3"

module Main (C: V1_LWT.CONSOLE) (S: V1_LWT.STACKV4) = struct
    module U = S.UDPV4


    let connect_to_server stack server =
        let udp = S.udpv4 stack in
        let st, push_st = Lwt_stream.create() in
        S.listen_udpv4 stack ~port:123 (fun ~src ~dst ~src_port data ->
            let ts = Int64.of_int @@ Tsc.rdtsc() in
            push_st @@ Some (data, ts);
            Lwt.return ()
            );
            st
    let rx stream =
        Lwt_stream.get stream
        >>= function
            | None -> Lwt.fail (Failure "heck")
            | Some buf -> Lwt.return buf

    let dump_packet c rxd nonce =
        let packet = validate_reply rxd nonce in
        match packet with
            | None -> C.log_s c (yellow "fail")
            | Some pkt -> C.log_s c (Printf.sprintf "recv %Lx\ntrans %Lx\ntime %Lx" (ts_to_int64 pkt.recv_ts) (ts_to_int64 pkt.trans_ts)(Int64.of_int @@ Tsc.rdtsc()))
        let start c s =
            let st = connect_to_server s server in
            let udp = S.udpv4 s in
            let state = blank_state in

            let q = new_query (Int64.of_int @@ Tsc.rdtsc()) in
            C.log_s c (Printf.sprintf "send ONE %Lx" ((fst q).tsc)) >>= fun () ->
            U.write ~source_port:123 ~dest_ip:server ~dest_port:123 udp (snd q) >>= fun () ->
            rx st >>= fun (rxd) ->
            C.log_s c (Printf.sprintf "recv ONE %Lx" (snd rxd)) >>= fun () ->
            let state = add_sample state (fst rxd) (fst q) (snd rxd) in
            Lwt.return(update_estimators state) >>= fun(state) ->





            let q = new_query (Int64.of_int @@ Tsc.rdtsc()) in
            C.log_s c (Printf.sprintf "send TWO %Lx" ((fst q).tsc)) >>= fun () ->
            U.write ~source_port:123 ~dest_ip:server ~dest_port:123 udp (snd q) >>= fun () ->
            rx st >>= fun (rxd) ->
            C.log_s c (Printf.sprintf "recv TWO %Lx" (snd rxd)) >>= fun () ->
            let state = add_sample state (fst rxd) (fst q) (snd rxd) in
            Lwt.return(update_estimators state) >>= fun(state) ->


            let x = state.estimators.theta_hat_and_error in
            match x with
            | Some (x,y) -> C.log_s c (Printf.sprintf "THETA %.15E" (x)) >>= fun () ->


            OS.Time.sleep 2.0 >>= fun () ->
            let q = new_query (Int64.of_int @@ Tsc.rdtsc()) in
            C.log_s c (Printf.sprintf "send THREE %Lx" ((fst q).tsc)) >>= fun () ->
            U.write ~source_port:123 ~dest_ip:server ~dest_port:123 udp (snd q) >>= fun () ->
            rx st >>= fun (rxd) ->
            C.log_s c (Printf.sprintf "recv THREE %Lx" (snd rxd)) >>= fun () ->
            let state = add_sample state (fst rxd) (fst q) (snd rxd) in
            Lwt.return(update_estimators state) >>= fun(state) ->



            C.log_s c (show_sync_state state) >>= fun ()->



{'fraction_non_alphanumeric': 0.14855237229043505, 'fraction_numerical': 0.027436713657723207, 'mean_word_length': 1.977436823104693, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 128, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5359225', 'n_tokens_mistral': 2521, 'n_tokens_neox': 2414, 'n_words': 656}