<commit_before>#include "cmm_socket_control.h"
#include <stdexcept>
#include <iostream>
#include <sstream>
#include <netinet/in.h>
#include <arpa/inet.h>

void 
CMMSocketControlHdr::cleanup()
{
    if (type == CMM_CONTROL_MSG_BEGIN_IROB) {
        delete [] op.begin_irob.deps;
    } else if (type == CMM_CONTROL_MSG_IROB_CHUNK) {
        delete [] op.irob_chunk.data;
    }
}

const char *
CMMSocketControlHdr::type_str() const
{
    static const char *strs[] = {
	"Hello",
	"Begin IROB",
	"End IROB",
	"IROB chunk",
	"New Interface",
	"Down Interface",
	"Ack",
	"(unknown)"
    };
    short my_type = ntohs(type);
    if (my_type > CMM_CONTROL_MSG_ACK || my_type < CMM_CONTROL_MSG_HELLO) {
	my_type = CMM_CONTROL_MSG_ACK + 1;
    }
    return strs[my_type];
}

std::string
CMMSocketControlHdr::describe() const
{
    std::ostringstream stream;
    stream << std:: endl << "Type: " << type_str() << " ";
    switch (ntohs(type)) {
    case CMM_CONTROL_MSG_HELLO:
      stream << "listen port: " << ntohs(op.hello.listen_port) << " ";
      stream << "num_ifaces: " << ntohl(op.hello.num_ifaces);
      break;
    case CMM_CONTROL_MSG_BEGIN_IROB:
        stream << "IROB: " << ntohl(op.begin_irob.id)<< " ";
        stream << "send_labels: " << ntohl(op.begin_irob.send_labels)<< " ";
        stream << "recv_labels: " << ntohl(op.begin_irob.recv_labels)<< " ";
        stream << "numdeps: " << op.begin_irob.numdeps;
        if (op.begin_irob.deps) {
            stream << " [ ";
            for (int i = 0; i < op.begin_irob.numdeps; i++) {
		stream << ntohl(op.begin_irob.deps[i]) << " ";
            }
            stream << "]";
        }
        break;
    case CMM_CONTROL_MSG_END_IROB:
        stream << "IROB: " << op.end_irob.id;
        break;
    case CMM_CONTROL_MSG_IROB_CHUNK:
        stream << "IROB: " << ntohl(op.irob_chunk.id)<< " ";
        stream << "seqno: " << ntohl(op.irob_chunk.seqno)<< " ";
        stream << "datalen: " << op.irob_chunk.datalen;
        break;
    case CMM_CONTROL_MSG_NEW_INTERFACE:
        stream << "IP: " << inet_ntoa(op.new_interface.ip_addr) << " ";
        stream << "labels: " << op.new_interface.labels;
        break;
    case CMM_CONTROL_MSG_DOWN_INTERFACE:
        stream << "IP: " << inet_ntoa(op.down_interface.ip_addr);        
        break;
    case CMM_CONTROL_MSG_ACK:
        stream << "IROB: " << op.ack.id;
        if (ntohl(op.ack.seqno)== INVALID_IROB_SEQNO) {
            stream << " seqno: " << op.ack.seqno;
        }<commit_msg>fixed up some ntohls.<commit_after>#include "cmm_socket_control.h"
#include <stdexcept>
#include <iostream>
#include <sstream>
#include <netinet/in.h>
#include <arpa/inet.h>

void 
CMMSocketControlHdr::cleanup()
{
    if (type == CMM_CONTROL_MSG_BEGIN_IROB) {
        delete [] op.begin_irob.deps;
    } else if (type == CMM_CONTROL_MSG_IROB_CHUNK) {
        delete [] op.irob_chunk.data;
    }
}

const char *
CMMSocketControlHdr::type_str() const
{
    static const char *strs[] = {
	"Hello",
	"Begin IROB",
	"End IROB",
	"IROB chunk",
	"New Interface",
	"Down Interface",
	"Ack",
	"(unknown)"
    };
    short my_type = ntohs(type);
    if (my_type > CMM_CONTROL_MSG_ACK || my_type < CMM_CONTROL_MSG_HELLO) {
	my_type = CMM_CONTROL_MSG_ACK + 1;
    }
    return strs[my_type];
}

std::string
CMMSocketControlHdr::describe() const
{
    std::ostringstream stream;
    stream << std:: endl << "Type: " << type_str() << " ";
    switch (ntohs(type)) {
    case CMM_CONTROL_MSG_HELLO:
      stream << "listen port: " << ntohs(op.hello.listen_port) << " ";
      stream << "num_ifaces: " << ntohl(op.hello.num_ifaces);
      break;
    case CMM_CONTROL_MSG_BEGIN_IROB:
        stream << "IROB: " << ntohl(op.begin_irob.id) << " ";
        stream << "send_labels: " << ntohl(op.begin_irob.send_labels) << " ";
        stream << "recv_labels: " << ntohl(op.begin_irob.recv_labels) << " ";
        stream << "numdeps: " << op.begin_irob.numdeps;
        if (op.begin_irob.deps) {
            stream << " [ ";
            for (int i = 0; i < op.begin_irob.numdeps; i++) {
		stream << ntohl(op.begin_irob.deps[i]) << " ";
            }
            stream << "]";
        }
        break;
    case CMM_CONTROL_MSG_END_IROB:
        stream << "IROB: " << ntohl(op.end_irob.id);
        break;
    case CMM_CONTROL_MSG_IROB_CHUNK:
        stream << "IROB: " << ntohl(op.irob_chunk.id) << " ";
        stream << "seqno: " << ntohl(op.irob_chunk.seqno) << " ";
        stream << "datalen: " << ntohl(op.irob_chunk.datalen);
        break;
    case CMM_CONTROL_MSG_NEW_INTERFACE:
        stream << "IP: " << inet_ntoa(op.new_interface.ip_addr) << " ";
        stream << "labels: " << ntohl(op.new_interface.labels);
        break;
    case CMM_CONTROL_MSG_DOWN_INTERFACE:
        stream << "IP: " << inet_ntoa(op.down_interface.ip_addr);        
        break;
    case CMM_CONTROL_MSG_ACK:
        stream << "IROB: " << ntohl(op.ack.id);
        if (ntohl(op.ack.seqno)== INVALID_IROB_SEQNO) {
            stream << " seqno: " << ntohl(op.ack.seqno);
        }
{'fraction_non_alphanumeric': 0.16303486529318542, 'fraction_numerical': 0.000792393026941363, 'mean_word_length': 2.7234513274336285, 'pattern_counts': {'":': 0, '<': 197, '<?xml version=': 0, '>': 15, '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': '4701402', 'n_tokens_mistral': 1999, 'n_tokens_neox': 1961, 'n_words': 309}