<commit_before>package libytcd

import (
	"libGFC"
)

type Server struct {
	ports       []Port
	transaction chan TransactionError
	blocks      chan BlockError
	state       *libGFC.GFCChain
}

func NewServer(ports []Port) (s *Server) {
	s = new(Server)
	s.ports = ports
	s.state = libGFC.NewGFCChain()

	s.blocks = make(chan BlockError)
	s.transaction = make(chan TransactionError)

	go s.handleChannels()

	for _, p := range ports {
		p.AddTransactionChannel(s.transaction)
		p.AddBlockChannel(s.blocks)
	}

	return
}

func (s *Server) handleChannels() {
	for {
		select {
		case c := <-s.transaction:
			update := c.BlockMessage
			err := update.Verify(s.state)
			if err != nil {
				c.error <- err
			} else {
				for _, p := range s.ports {
					if p != c.Source {
						p.AddTransaction(update)
					}
				}
			}
		case block := <-s.blocks:
			for _, v := range block.BlockMessage {
				err := v.Verify(s.state)
				if err != nil {
					block.error <- err
					break
				}
				v.Apply(s.state)
			}

			for _, p := range s.ports {
				if p != block.Source {
					p.AddBlock(block.BlockMessage)
				}
			}
		}
	}
}
<commit_msg>Fix blocking bug in ytcd<commit_after>package libytcd

import (
	"libGFC"
)

type Server struct {
	ports       []Port
	transaction chan TransactionError
	blocks      chan BlockError
	state       *libGFC.GFCChain
}

func NewServer(ports []Port) (s *Server) {
	s = new(Server)
	s.ports = ports
	s.state = libGFC.NewGFCChain()

	s.blocks = make(chan BlockError)
	s.transaction = make(chan TransactionError)

	go s.handleChannels()

	for _, p := range ports {
		p.AddTransactionChannel(s.transaction)
		p.AddBlockChannel(s.blocks)
	}

	return
}

func (s *Server) handleChannels() {
	for {
		select {
		case c := <-s.transaction:
			update := c.BlockMessage
			err := update.Verify(s.state)
			if err != nil {
				c.error <- err
			} else {
				c.error <- nil
				for _, p := range s.ports {
					if p != c.Source {
						p.AddTransaction(update)
					}
				}
			}
		case block := <-s.blocks:
			var err error = nil
			for _, v := range block.BlockMessage {
				err = v.Verify(s.state)
				if err != nil {
					break
				}
				v.Apply(s.state)
			}
			block.error <- err

			for _, p := range s.ports {
				if p != block.Source {
					p.AddBlock(block.BlockMessage)
				}
			}
		}
	}
}

{'fraction_non_alphanumeric': 0.13019031141868512, 'fraction_numerical': 0.0, 'mean_word_length': 2.401470588235294, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 3, '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': '2447612', 'n_tokens_mistral': 1011, 'n_tokens_neox': 836, 'n_words': 198}