{"action":"created","issue":{"url":"https://api.github.com/repos/mirage/ocaml-dns/issues/59","labels_url":"https://api.github.com/repos/mirage/ocaml-dns/issues/59/labels{/name}","comments_url":"https://api.github.com/repos/mirage/ocaml-dns/issues/59/comments","events_url":"https://api.github.com/repos/mirage/ocaml-dns/issues/59/events","html_url":"https://github.com/mirage/ocaml-dns/issues/59","id":62950876,"number":59,"title":"What's the purpose of PROCESSER module?","user":{"login":"heidi-ann","id":1835251,"avatar_url":"https://avatars.githubusercontent.com/u/1835251?v=3","gravatar_id":"","url":"https://api.github.com/users/heidi-ann","html_url":"https://github.com/heidi-ann","followers_url":"https://api.github.com/users/heidi-ann/followers","following_url":"https://api.github.com/users/heidi-ann/following{/other_user}","gists_url":"https://api.github.com/users/heidi-ann/gists{/gist_id}","starred_url":"https://api.github.com/users/heidi-ann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/heidi-ann/subscriptions","organizations_url":"https://api.github.com/users/heidi-ann/orgs","repos_url":"https://api.github.com/users/heidi-ann/repos","events_url":"https://api.github.com/users/heidi-ann/events{/privacy}","received_events_url":"https://api.github.com/users/heidi-ann/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-19T10:40:24Z","updated_at":"2015-03-19T11:56:02Z","closed_at":null,"body":"I'm currently writing a blog post on using the ocaml-dns library including processes. Can someone explain to me why we encapsulate processes into a processer and pass as a first class module, instead of passing processes directly?\r\n\r\nhere are the definitions from dns_server.ml:\r\n```ocaml\r\ntype 'a process = src:ip_endpoint -> \r\n  dst:ip_endpoint -> 'a -> Dns.Query.answer option Lwt.t\r\n\r\nmodule type PROCESSOR = sig\r\n  include Dns.Protocol.SERVER\r\n  val process : context process\r\nend\r\n\r\ntype 'a processor = (module PROCESSOR with type context = 'a)\r\n\r\nlet process_query buf len obuf src dst processor =\r\n  let module Processor = (val processor : PROCESSOR) in\r\n  match Processor.parse (Dns.Buf.sub buf 0 len) with\r\n  |None -> return None\r\n  |Some ctxt -> begin\r\n    lwt answer = Processor.process ~src ~dst ctxt in\r\n    match answer with\r\n    |None -> return None\r\n    |Some answer ->\r\n      let query = Processor.query_of_context ctxt in\r\n      let response = Dns.Query.response_of_answer query answer in\r\n      return (Processor.marshal obuf ctxt response)\r\n end\r\n\r\nlet processor_of_process process : Dns.Packet.t processor =\r\n  let module P = struct\r\n    include Dns.Protocol.Server\r\n\r\n    let process = process\r\n  end in\r\n  (module P)\r\n```\r\n\r\nIs the purpose to allow the library user the option to provide an alternative implementation of SERVER?\r\n```ocaml\r\nmodule type SERVER = sig\r\n  type context\r\n\r\n  (** Projects a context into its associated query *)\r\n  val query_of_context : context -> Packet.t\r\n\r\n  (** DNS wire format parser function.\r\n      @param buf message buffer\r\n      @return parsed packet and context\r\n  *)\r\n  val parse   : Buf.t -> context option\r\n\r\n  (** DNS wire format marshal function.\r\n      @param buf output resource\r\n      @param _q context\r\n      @param response answer packet\r\n      @return buffer to write\r\n  *)\r\n  val marshal : Buf.t -> context -> Packet.t -> Buf.t option\r\nend\r\n```"},"comment":{"url":"https://api.github.com/repos/mirage/ocaml-dns/issues/comments/83522834","html_url":"https://github.com/mirage/ocaml-dns/issues/59#issuecomment-83522834","issue_url":"https://api.github.com/repos/mirage/ocaml-dns/issues/59","id":83522834,"user":{"login":"avsm","id":53164,"avatar_url":"https://avatars.githubusercontent.com/u/53164?v=3","gravatar_id":"","url":"https://api.github.com/users/avsm","html_url":"https://github.com/avsm","followers_url":"https://api.github.com/users/avsm/followers","following_url":"https://api.github.com/users/avsm/following{/other_user}","gists_url":"https://api.github.com/users/avsm/gists{/gist_id}","starred_url":"https://api.github.com/users/avsm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/avsm/subscriptions","organizations_url":"https://api.github.com/users/avsm/orgs","repos_url":"https://api.github.com/users/avsm/repos","events_url":"https://api.github.com/users/avsm/events{/privacy}","received_events_url":"https://api.github.com/users/avsm/received_events","type":"User","site_admin":false},"created_at":"2015-03-19T11:56:02Z","updated_at":"2015-03-19T11:56:02Z","body":"Reopening :) If two people were confused by this (and indeed, it's a rather opaquely named module), it would be good to add comments in `PROCESSOR`'s interface file to explain its purpose."}}