<commit_before>package apns

import (
	"bytes"
	"crypto/tls"
	"github.com/pranavraja/apns/notification"
	"net"
	"time"
)

type Queue []notification.Notification

func NewQueue() Queue {
	return Queue{}
}

func (queue Queue) Add(identifier int, token string, payload string) Queue {
	return append(queue, notification.MakeNotification(identifier, token, payload))
}

func (queue Queue) ResetAfter(identifier uint32) Queue {
	for index, n := range queue {
		if n.Header.Identifier > identifier {
			return queue[index:]
		}
	}
	return NewQueue()
}

func Connect(host string, certFile string, keyFile string) (conn *tls.Conn, err error) {
	conf := new(tls.Config)
	cert, err := tls.LoadX509KeyPair(certFile, keyFile)
	if err != nil {
		return
	}
	conf.Certificates = append(conf.Certificates, cert)
	return tls.Dial("tcp", host, conf)
}

func Channels(conn net.Conn) (writeChannel chan notification.Notification, readChannel chan notification.Failure, err error) {
	readChannel = make(chan notification.Failure, 0)
	writeChannel = make(chan notification.Notification, 100)
	go func() {
		for {
			conn.SetReadDeadline(time.Now().Add(2 * time.Second))
			failure := make([]byte, 6)
			_, err := conn.Read(failure)
			if err != nil {
				close(readChannel)
				break
			}
			readChannel <- notification.FailureFromBytes(bytes.NewBuffer(failure))
		}
	}()
	go func() {
		for {
			n := <-writeChannel
			notificationBytes, _ := n.Bytes()
			conn.Write(notificationBytes)
		}<commit_msg>Return net.Conn instead of *tls.Conn<commit_after>package apns

import (
	"bytes"
	"crypto/tls"
	"github.com/pranavraja/apns/notification"
	"net"
	"time"
)

type Queue []notification.Notification

func NewQueue() Queue {
	return Queue{}
}

func (queue Queue) Add(identifier int, token string, payload string) Queue {
	return append(queue, notification.MakeNotification(identifier, token, payload))
}

func (queue Queue) ResetAfter(identifier uint32) Queue {
	for index, n := range queue {
		if n.Header.Identifier > identifier {
			return queue[index:]
		}
	}
	return NewQueue()
}

func Connect(host string, certFile string, keyFile string) (conn net.Conn, err error) {
	conf := new(tls.Config)
	cert, err := tls.LoadX509KeyPair(certFile, keyFile)
	if err != nil {
		return
	}
	conf.Certificates = append(conf.Certificates, cert)
	return tls.Dial("tcp", host, conf)
}

func Channels(conn net.Conn) (writeChannel chan notification.Notification, readChannel chan notification.Failure, err error) {
	readChannel = make(chan notification.Failure, 0)
	writeChannel = make(chan notification.Notification, 100)
	go func() {
		for {
			conn.SetReadDeadline(time.Now().Add(2 * time.Second))
			failure := make([]byte, 6)
			_, err := conn.Read(failure)
			if err != nil {
				close(readChannel)
				break
			}
			readChannel <- notification.FailureFromBytes(bytes.NewBuffer(failure))
		}
	}()
	go func() {
		for {
			n := <-writeChannel
			notificationBytes, _ := n.Bytes()
			conn.Write(notificationBytes)
		}
{'fraction_non_alphanumeric': 0.12818791946308725, 'fraction_numerical': 0.00738255033557047, 'mean_word_length': 4.371171171171171, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3117185', 'n_tokens_mistral': 1069, 'n_tokens_neox': 975, 'n_words': 246}