<commit_before>;;;; Functions for querying EPMD (Erlang Port Mapped Daemon)

(in-package :cleric)

(defconstant +protocol-tcpip4+ 0)

;;;
;;; ALIVE2_REQ
;;
;; 2 bytes: Total length of following message in bytes
;; 1 byte:  'x'               [ALIVE2_REQ message]
;; 2 bytes: Listening port
;; 1 byte:  72                [hidden node (not Erlang node)]
;; 1 byte:  0                 [protocol: tcp/ip v4]
;; 2 bytes: 5                 [lowest version supported]
;; 2 bytes: 5                 [highest version supported]
;; 2 bytes: Length of node name
;; N bytes: Node name
;; 2 bytes: Length of the Extra field
;; M bytes: Extra             [???]
;;

(defun make-alive2-request (node-name port &optional (extra #()))
  (let* ((node-name-length (length node-name))
         (extra-field-length (length extra))
         (message-length (+ 13 node-name-length extra-field-length)))
    (concatenate 'vector
                 (uint16-to-bytes message-length)
                 (vector +alive2-req+)
                 (uint16-to-bytes port)
                 (vector +node-type-hidden+
                         +protocol-tcpip4+
                         +lowest-version-supported+
                         +highest-version-supported+)
                 (uint16-to-bytes node-name-length)
                 (string-to-bytes node-name)
                 (uint16-to-bytes extra-field-length)
                 extra)))


;;;
;;; ALIVE2_RESP
;;
;; 1 byte:  'y'               [ALIVE2_RESP message]
;; 1 byte:  Result            [0 means OK, >0 means ERROR]
;; 2 bytes: Creation          [?]
;;

(defun read-alive2-response (stream)<commit_msg>Highest and lowest supported version are encoded with two bytes. Fixed MAKE-ALIVE2-REQUEST.<commit_after>;;;; Functions for querying EPMD (Erlang Port Mapped Daemon)

(in-package :cleric)

(defconstant +protocol-tcpip4+ 0)

;;;
;;; ALIVE2_REQ
;;
;; 2 bytes: Total length of following message in bytes
;; 1 byte:  'x'               [ALIVE2_REQ message]
;; 2 bytes: Listening port
;; 1 byte:  72                [hidden node (not Erlang node)]
;; 1 byte:  0                 [protocol: tcp/ip v4]
;; 2 bytes: 5                 [lowest version supported]
;; 2 bytes: 5                 [highest version supported]
;; 2 bytes: Length of node name
;; N bytes: Node name
;; 2 bytes: Length of the Extra field
;; M bytes: Extra             [???]
;;

(defun make-alive2-request (node-name port &optional (extra #()))
  (let* ((node-name-length (length node-name))
         (extra-field-length (length extra))
         (message-length (+ 13 node-name-length extra-field-length)))
    (concatenate 'vector
                 (uint16-to-bytes message-length)
                 (vector +alive2-req+)
                 (uint16-to-bytes port)
                 (vector +node-type-hidden+
                         +protocol-tcpip4+)
                 (uint16-to-bytes +lowest-version-supported+)
                 (uint16-to-bytes +highest-version-supported+)
                 (uint16-to-bytes node-name-length)
                 (string-to-bytes node-name)
                 (uint16-to-bytes extra-field-length)
                 extra)))


;;;
;;; ALIVE2_RESP
;;
;; 1 byte:  'y'               [ALIVE2_RESP message]
;; 1 byte:  Result            [0 means OK, >0 means ERROR]
;; 2 bytes: Creation          [?]
;;

(defun read-alive2-response (stream)
{'fraction_non_alphanumeric': 0.12851165570830841, 'fraction_numerical': 0.02540346682606097, 'mean_word_length': 1.9003466204506065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '565477', 'n_tokens_mistral': 1071, 'n_tokens_neox': 984, 'n_words': 286}