<commit_before>package glutton

import (
	"encoding/hex"
	"net"

	"github.com/mushorg/glutton/rdp"
)

// HandleRDP takes a net.Conn and does basic RDP communication
func (g *Glutton) HandleRDP(conn net.Conn) {
	defer conn.Close()
	buffer := make([]byte, 1024)
	n, err := conn.Read(buffer)
	if err != nil {
		g.Logger.Errorf("[rdp     ] error: %v", err)
	}
	if n > 0 {
		g.Logger.Infof("[rdp     ]\n%s", hex.Dump(buffer[0:n]))
		pdu, err := rdp.ParseCRPDU(buffer[0:n])
		if err != nil {
			g.Logger.Errorf("[rdp     ] error: %v", err)
		}
		g.Logger.Infof("[rdp     ] req pdu: %+v", pdu)
		if len(pdu.Data) > 0 {
			g.Logger.Infof("[rdp     ] data: %s", string(pdu.Data))
		}
		resp := rdp.ConnectionConfirm()
		g.Logger.Infof("[rdp     ] resp pdu: %+v", pdu)
		conn.Write(resp)
	}
}<commit_msg>rdp fixes<commit_after>package glutton

import (
	"encoding/hex"
	"net"

	"github.com/mushorg/glutton/rdp"
)

// HandleRDP takes a net.Conn and does basic RDP communication
func (g *Glutton) HandleRDP(conn net.Conn) {
	defer conn.Close()
	buffer := make([]byte, 1024)
	for {
		n, err := conn.Read(buffer)
		if err != nil {
			g.Logger.Errorf("[rdp     ] error: %v", err)
		}
		if err != nil && n <= 0 {
			break
		}
		if n > 0 {
			g.Logger.Infof("[rdp     ]\n%s", hex.Dump(buffer[0:n]))
			pdu, err := rdp.ParseCRPDU(buffer[0:n])
			if err != nil {
				g.Logger.Errorf("[rdp     ] error: %v", err)
			}
			g.Logger.Infof("[rdp     ] req pdu: %+v", pdu)
			if len(pdu.Data) > 0 {
				g.Logger.Infof("[rdp     ] data: %s", string(pdu.Data))
			}
			resp := rdp.ConnectionConfirm()
			g.Logger.Infof("[rdp     ] resp pdu: %+v", resp)
			conn.Write(resp)
		}
	}
}
{'fraction_non_alphanumeric': 0.19226118500604594, 'fraction_numerical': 0.010278113663845224, 'mean_word_length': 2.8941176470588235, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 7, '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': '1471436', 'n_tokens_mistral': 768, 'n_tokens_neox': 708, 'n_words': 150}