<commit_before>package main

import (
	"encoding/hex"
	"fmt"
	"github.com/andrewtj/dnssd"
	"log"
	"net"
)

//starts the ROAP service
func startROAP(hardwareAddr net.HardwareAddr, hostName string) {

	name := fmt.Sprintf("%s@%s", hex.EncodeToString(hardwareAddr), hostName)
	op := dnssd.NewRegisterOp(name, "_raop._tcp", 5000, RegisterROAPCallbackFunc)

	op.SetTXTPair("txtvers", "1")
	op.SetTXTPair("ch", "2")
	op.SetTXTPair("cn", "0,1")
	op.SetTXTPair("et", "0,1")
	op.SetTXTPair("sv", "false")
	op.SetTXTPair("da", "true")
	op.SetTXTPair("sr", "44100")
	op.SetTXTPair("ss", "16")
	op.SetTXTPair("pw", "false")
	op.SetTXTPair("vn", "3")
	op.SetTXTPair("tp", "TCP,UDP")
	op.SetTXTPair("md", "0,1,2")
	op.SetTXTPair("vs", "130.14")
	op.SetTXTPair("sm", "false")
	op.SetTXTPair("ek", "1")
	err := op.Start()
	if err != nil {
		log.Printf("Failed to register ROAP service: %s", err)
		return
	}
	log.Println("started ROAP service")
	// later...
	//op.Stop()
}

//helper method for the ROAP service
func RegisterROAPCallbackFunc(op *dnssd.RegisterOp, err error, add bool, name, serviceType, domain string) {
	if err != nil {
		// op is now inactive
		log.Printf("ROAP Service registration failed: %s", err)
		return
	}
	if add {
		log.Printf("ROAP Service registered as “%s“ in %s", name, domain)
	} else {
		log.Printf("ROAP Service “%s” removed from %s", name, domain)
	}
}<commit_msg>working on ROAP service<commit_after>package main

import (
	"encoding/hex"
	"fmt"
	"github.com/andrewtj/dnssd"
	"log"
	"net"
	"time"
)

type ConnState int

const (
	StateNew ConnState = iota
	StateActive
	StateIdle
	StateHijacked
	StateClosed
)

//starts the ROAP service
func startROAP(hardwareAddr net.HardwareAddr, hostName string) {

	port := 5000
	name := fmt.Sprintf("%s@%s", hex.EncodeToString(hardwareAddr), hostName)
	op := dnssd.NewRegisterOp(name, "_raop._tcp", port, RegisterROAPCallbackFunc)

	op.SetTXTPair("txtvers", "1")
	op.SetTXTPair("ch", "2")
	op.SetTXTPair("cn", "0,1")
	op.SetTXTPair("et", "0,1")
	op.SetTXTPair("sv", "false")
	op.SetTXTPair("da", "true")
	op.SetTXTPair("sr", "44100")
	op.SetTXTPair("ss", "16")
	op.SetTXTPair("pw", "false")
	op.SetTXTPair("vn", "3")
	op.SetTXTPair("tp", "TCP,UDP")
	op.SetTXTPair("md", "0,1,2")
	op.SetTXTPair("vs", "130.14")
	op.SetTXTPair("sm", "false")
	op.SetTXTPair("ek", "1")
	err := op.Start()
	if err != nil {
		log.Printf("Failed to register ROAP service: %s", err)
		return
	}
	log.Println("started ROAP service")
	go startROAPWebServer(port)
	// later...
	//op.Stop()
}

//helper method for the ROAP service
func RegisterROAPCallbackFunc(op *dnssd.RegisterOp, err error, add bool, name, serviceType, domain string) {
	if err != nil {
		// op is now inactive
		log.Printf("ROAP Service registration failed: %s", err)
		return
	}
	if add {
		log.Printf("ROAP Service registered as “%s“ in %s", name, domain)
	} else {
		log.Printf("ROAP Service “%s” removed from %s", name, domain)
	}
}

func startROAPWebServer(port int) error {
	ln, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
	if err != nil {
		log.Println("error starting ROAP server:", err)
		return err
	}
	defer ln.Close()
	var tempDelay time.Duration // how long to sleep on accept failure
	for {
		rw, e := ln.Accept()
		if e != nil {
			if ne, ok := e.(net.Error); ok && ne.Temporary() {
				if tempDelay == 0 {
					tempDelay = 5 * time.Millisecond
				} else {
					tempDelay *= 2
				}
				if max := 1 * time.Second; tempDelay > max {
					tempDelay = max
				}
				log.Printf("ROAP: Accept error: %v; retrying in %v", e, tempDelay)
				time.Sleep(tempDelay)
				continue
			}
			return e
		}
		tempDelay = 0
		log.Println("got a connection from: ", rw.RemoteAddr())
		//need to setup a connection object that handles the connection
		//then figure out how to handle the RTSP protocol from the data returned.

		// c, err := newConn(rw)
		// if err != nil {
		// 	continue
		// }
		// c.setState(c.rwc, StateNew) // before Serve can return
		// go c.serve()
	}
}

// func newConn(rwc net.Conn) (c *conn) {
// 	c = new(conn)
// 	c.remoteAddr = rwc.RemoteAddr().String()
// 	c.server = srv
// 	c.rwc = rwc
// 	c.sr = liveSwitchReader{r: c.rwc}
// 	c.lr = io.LimitReader(&c.sr, noLimit).(*io.LimitedReader)
// 	br := newBufioReader(c.lr)
// 	bw := newBufioWriterSize(c.rwc, 4<<10)
// 	c.buf = bufio.NewReadWriter(br, bw)
// 	return c
// }
{'fraction_non_alphanumeric': 0.17653810835629016, 'fraction_numerical': 0.014233241505968778, 'mean_word_length': 3.725596529284165, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 4, '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': '6040378', 'n_tokens_mistral': 1848, 'n_tokens_neox': 1739, 'n_words': 417}