<commit_before>// fcp project fcp.go
package fcp

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"net"
	"os"
	"strconv"
	"strings"
	"time"
)

type FCPClient struct {
	host       *net.TCPAddr
	isSSL      bool
	identifier string
	socket     *net.TCPConn
	msgSender  chan message
	msgHandler chan message
	caller     chan nodeMessager
}

type message struct {
	name   string
	params []string
	data   []byte
}

type nodeMessager interface {
	parseMessage([]string)
}

func NewClient(ipPort string, ssl bool, id string) (FCPClient, error) {
	addr, err := net.ResolveTCPAddr("tcp", ipPort)
	msgSender := make(chan message, 20)
	msgHandler := make(chan message, 20)
	caller := make(chan nodeMessager, 20)
	return FCPClient{addr, ssl, id, nil, msgSender, msgHandler, caller}, err
}

func (r *FCPClient) sender() {
	for {
		msg := <-r.msgSender
		fmt.Println(len(msg.data), "bytes of data after message sender receipt.")
		if r.socket == nil {
			err := errors.New("Trying to send a message while socket is closed.")
			fmt.Println(err.Error())
			return
		}
		r.socket.Write([]byte(msg.name))
		r.socket.Write([]byte("\n"))
		fmt.Println(msg.name) //crappy debug output is crappy
		for i := range msg.params {
			r.socket.Write([]byte(msg.params[i]))
			r.socket.Write([]byte("\n"))
			fmt.Println(msg.params[i]) //crappy debug output is crappy
		}

		if msg.data == nil {
			r.socket.Write([]byte("EndMessage\n"))
			fmt.Println("EndMessage") //crappy debug output is crappy
		} else {
			fmt.Println("Data -", len(msg.data), "bytes")
			r.socket.Write([]byte("Data\n"))
			t1 := time.Now()
			written, err := r.socket.Write(msg.data)
			if err == nil {
				fmt.Println(written, "bytes written in", time.Since(t1).Seconds(), "seconds")
			} else {
				fmt.Println(err.Error())
			}
		}
	}
}

func (r *FCPClient) handler(caller chan nodeMessager) {
	for {
		msg := <-r.msgHandler

		switch msg.name {
		case "NodeHello":
			nh := &NodeHello{}
			nh.parseMessage(msg.params)
			caller <- nh
		case "CloseConnectionDuplicateClientName":
			fmt.Println("Unimplemented message:", msg.name)
		case "Peer":
			fmt.Println("Unimplemented message:", msg.name)
		case "PeerNote":
			fmt.Println("Unimplemented message:", msg.name)
		case "EndListPeers":
			fmt.Println("Unimplemented message:", msg.name)
		case "EndListPeerNotes":
			fmt.Println("Unimplemented message:", msg.name)
		case "PeerRemoved":
			fmt.Println("Unimplemented message:", msg.name)
		case "NodeData":
			fmt.Println("Unimplemented message:", msg.name)
		case "ConfigData": // (since 1027)
			fmt.Println("Unimplemented message:", msg.name)
		case "TestDDAReply": // (since 1027)
			fmt.Println("Unimplemented message:", msg.name)
		case "TestDDAComplete": // (since 1027)
			fmt.Println("Unimplemented message:", msg.name)
		case "SSKKeyPair":
			fmt.Println("Unimplemented message:", msg.name)
		case "PersistentGet":
			fmt.Println("Unimplemented message:", msg.name)
		case "PersistentPut":
			fmt.Println("Unimplemented message:", msg.name)
		case "PersistentPutDir":
			fmt.Println("Unimplemented message:", msg.name)
		case "URIGenerated":
			fmt.Println("Unimplemented message:", msg.name)
		case "PutSuccessful":
			fmt.Println("Unimplemented message:", msg.name)
		case "PutFetchable":
			fmt.Println("Unimplemented message:", msg.name)
		case "DataFound":
			fmt.Println("Unimplemented message:", msg.name)
		case "GetRequestStatus":
			fmt.Println("Unimplemented message:", msg.name)
		case "AllData":
			ad := &AllData{}
			ad.parseMessage(msg.params)
			ad.SetData(msg.data)
			caller <- ad
		case "StartedCompression":
			fmt.Println("Unimplemented message:", msg.name)
		case "FinishedCompression":
			fmt.Println("Unimplemented message:", msg.name)
		case "SimpleProgress":
			sp := &SimpleProgress{}
			sp.parseMessage(msg.params)
			caller <- sp
		case "ExpectedHashes": // (since 1254)
			fmt.Println("Unimplemented message:", msg.name)
		case "ExpectedMIME": // (since 1307)
			fmt.Println("Unimplemented message:", msg.name)
		case "ExpectedDataLength": // (since 1307)
			fmt.Println("Unimplemented message:", msg.name)
		case "CompatibilityMode": // (since 1254)
			fmt.Println("Unimplemented message:", msg.name)
		case "EndListPersistentRequests":
			fmt.Println("Unimplemented message:", msg.name)<commit_msg>Implemented ExpectedHashes, URIGenerated, and PutSuccessful.  the rest are placeholders.<commit_after>// fcp project fcp.go
package fcp

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"net"
	"os"
	"strconv"
	"strings"
	"time"
)

type FCPClient struct {
	host       *net.TCPAddr
	isSSL      bool
	identifier string
	socket     *net.TCPConn
	msgSender  chan message
	msgHandler chan message
	caller     chan nodeMessager
}

type message struct {
	name   string
	params []string
	data   []byte
}

type nodeMessager interface {
	parseMessage([]string)
}

func NewClient(ipPort string, ssl bool, id string) (FCPClient, error) {
	addr, err := net.ResolveTCPAddr("tcp", ipPort)
	msgSender := make(chan message, 20)
	msgHandler := make(chan message, 20)
	caller := make(chan nodeMessager, 20)
	return FCPClient{addr, ssl, id, nil, msgSender, msgHandler, caller}, err
}

func (r *FCPClient) sender() {
	for {
		msg := <-r.msgSender
		fmt.Println(len(msg.data), "bytes of data after message sender receipt.")
		if r.socket == nil {
			err := errors.New("Trying to send a message while socket is closed.")
			fmt.Println(err.Error())
			return
		}
		r.socket.Write([]byte(msg.name))
		r.socket.Write([]byte("\n"))
		fmt.Println(msg.name) //crappy debug output is crappy
		for i := range msg.params {
			r.socket.Write([]byte(msg.params[i]))
			r.socket.Write([]byte("\n"))
			fmt.Println(msg.params[i]) //crappy debug output is crappy
		}

		if msg.data == nil {
			r.socket.Write([]byte("EndMessage\n"))
			fmt.Println("EndMessage") //crappy debug output is crappy
		} else {
			fmt.Println("Data -", len(msg.data), "bytes")
			r.socket.Write([]byte("Data\n"))
			t1 := time.Now()
			written, err := r.socket.Write(msg.data)
			if err == nil {
				fmt.Println(written, "bytes written in", time.Since(t1).Seconds(), "seconds")
			} else {
				fmt.Println(err.Error())
			}
		}
	}
}

func (r *FCPClient) handler(caller chan nodeMessager) {
	for {
		msg := <-r.msgHandler

		switch msg.name {
		case "NodeHello":
			nh := &NodeHello{}
			nh.parseMessage(msg.params)
			caller <- nh
		case "CloseConnectionDuplicateClientName":
			fmt.Println("Unimplemented message:", msg.name)
		case "Peer":
			fmt.Println("Unimplemented message:", msg.name)
		case "PeerNote":
			fmt.Println("Unimplemented message:", msg.name)
		case "EndListPeers":
			fmt.Println("Unimplemented message:", msg.name)
		case "EndListPeerNotes":
			fmt.Println("Unimplemented message:", msg.name)
		case "PeerRemoved":
			fmt.Println("Unimplemented message:", msg.name)
		case "NodeData":
			fmt.Println("Unimplemented message:", msg.name)
		case "ConfigData": // (since 1027)
			fmt.Println("Unimplemented message:", msg.name)
		case "TestDDAReply": // (since 1027)
			fmt.Println("Unimplemented message:", msg.name)
		case "TestDDAComplete": // (since 1027)
			fmt.Println("Unimplemented message:", msg.name)
		case "SSKKeyPair":
			fmt.Println("Unimplemented message:", msg.name)
		case "PersistentGet":
			fmt.Println("Unimplemented message:", msg.name)
		case "PersistentPut":
			fmt.Println("Unimplemented message:", msg.name)
		case "PersistentPutDir":
			fmt.Println("Unimplemented message:", msg.name)
		case "URIGenerated":
			ug := &URIGenerated{}
			ug.parseMessage(msg.params)
			caller <- ug
		case "PutSuccessful":
			ps := &PutSuccessful{}
			ps.parseMessage(msg.params)
			caller <- ps
		case "PutFetchable":
			fmt.Println("Unimplemented message:", msg.name)
		case "DataFound":
			fmt.Println("Unimplemented message:", msg.name)
		case "GetRequestStatus":
			fmt.Println("Unimplemented message:", msg.name)
		case "AllData":
			ad := &AllData{}
			ad.parseMessage(msg.params)
			ad.SetData(msg.data)
			caller <- ad
		case "StartedCompression":
			fmt.Println("Unimplemented message:", msg.name)
		case "FinishedCompression":
			fmt.Println("Unimplemented message:", msg.name)
		case "SimpleProgress":
			sp := &SimpleProgress{}
			sp.parseMessage(msg.params)
			caller <- sp
		case "ExpectedHashes": // (since 1254)
			eh := &ExpectedHashes{}
			eh.parseMessage(msg.params)
			caller <- eh
		case "ExpectedMIME": // (since 1307)
			fmt.Println("Unimplemented message:", msg.name)
		case "ExpectedDataLength": // (since 1307)
			fmt.Println("Unimplemented message:", msg.name)
		case "CompatibilityMode": // (since 1254)
			fmt.Println("Unimplemented message:", msg.name)
		case "EndListPersistentRequests":
			fmt.Println("Unimplemented message:", msg.name)
{'fraction_non_alphanumeric': 0.15157773952954676, 'fraction_numerical': 0.008261617900172116, 'mean_word_length': 4.03523974581167, 'pattern_counts': {'":': 58, '<': 16, '<?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': '5332210', 'n_tokens_mistral': 3400, 'n_tokens_neox': 2994, 'n_words': 695}