<commit_before>// Outgoing Relay Handler
//
// Handles an outgoing message.
// It serves as a relay that a worker can dial and have the
// relay handle delivering the message.

package handler

import (
	"fmt"
	"io/ioutil"
	"net"
)

// Read from the Session buffer and send to a handler function
func ReadOutgoing(conn net.Conn) {
	// close connection on exit
	defer conn.Close()

	result, err := ioutil.ReadAll(conn)
	checkError(err)

	err = sendMessage(result)
	checkError(err)
}

func sendMessage(result []byte) error {
	// Lookup Receiving Node
	node := "127.0.0.1:7834"

	tcpAddr, err := net.ResolveTCPAddr("tcp4", node)
	if err != nil {
		return err
	}

	conn, err := net.DialTCP("tcp", nil, tcpAddr)
	if err != nil {
		return err
	}
	defer conn.Close()

	_, err = conn.Write(result)
	if err != nil {
		return err
	}

	return nil
}

func checkError(err error) {
	if err != nil {
		fmt.Printf("Fatal error: %s", err.Error())
	}
}
<commit_msg>use ip addresses as domains to test sending<commit_after>// Outgoing Relay Handler
//
// Handles an outgoing message.
// It serves as a relay that a worker can dial and have the
// relay handle delivering the message.

package handler

import (
	"fmt"
	"github.com/msgbox/message"
	"io/ioutil"
	"net"
	"strings"
)

// Read from the Session buffer and send to a handler function
func ReadOutgoing(conn net.Conn) {
	// close connection on exit
	defer conn.Close()

	result, err := ioutil.ReadAll(conn)
	checkError(err)

	err = sendMessage(result)
	checkError(err)
}

func sendMessage(result []byte) error {
	// Lookup Receiving Node
	node := lookupAddress(result)

	conn, err := net.DialTCP("tcp", nil, node)
	if err != nil {
		return err
	}
	defer conn.Close()

	_, err = conn.Write(result)
	if err != nil {
		return err
	}

	return nil
}

// Get it working with with IP addresses for now
func lookupAddress(data []byte) *net.TCPAddr {
	port := ":7834" // Hardcoded for now
	msg := messages.Parse(data)
	receiver := msg.GetReceiver()
	addr := strings.Split(receiver, "@")
	tcpAddr, err := net.ResolveTCPAddr("tcp4", addr[1]+port)
	checkError(err)
	return tcpAddr
}

func checkError(err error) {
	if err != nil {
		fmt.Printf("Fatal error: %s", err.Error())
	}
}

{'fraction_non_alphanumeric': 0.12952898550724637, 'fraction_numerical': 0.007699275362318841, 'mean_word_length': 3.58298755186722, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '6154717', 'n_tokens_mistral': 795, 'n_tokens_neox': 765, 'n_words': 247}