<commit_before>package main

import (
	"html/template"

	"github.com/stretchr/graceful"

	"github.com/NebulousLabs/Sia/consensus"
	"github.com/NebulousLabs/Sia/modules"
	"github.com/NebulousLabs/Sia/modules/gateway"
	"github.com/NebulousLabs/Sia/modules/host"
	"github.com/NebulousLabs/Sia/modules/hostdb"
	"github.com/NebulousLabs/Sia/modules/miner"
	"github.com/NebulousLabs/Sia/modules/renter"
	"github.com/NebulousLabs/Sia/modules/transactionpool"
	"github.com/NebulousLabs/Sia/modules/wallet"
	"github.com/NebulousLabs/Sia/network"
)

type DaemonConfig struct {
	// Network Variables
	APIAddr string
	RPCAddr string

	// Host Variables
	HostDir string

	// Miner Variables
	Threads int

	// Renter Variables
	DownloadDir string

	// Wallet Variables
	WalletDir string
}

type daemon struct {
	state   *consensus.State
	tpool   modules.TransactionPool
	network *network.TCPServer
	wallet  modules.Wallet
	miner   *miner.Miner
	host    modules.Host
	hostDB  modules.HostDB
	renter  modules.Renter
	gateway modules.Gateway

	styleDir    string
	downloadDir string

	template *template.Template

	apiServer *graceful.Server
}

func newDaemon(config DaemonConfig) (d *daemon, err error) {
	d = new(daemon)
	d.state = consensus.CreateGenesisState()
	d.network, err = network.NewTCPServer(config.RPCAddr)
	if err != nil {
		return
	}
	d.gateway, err = gateway.New(d.network, d.state)
	if err != nil {
		return
	}
	d.tpool, err = transactionpool.New(d.state, d.gateway)
	if err != nil {
		return
	}
	d.wallet, err = wallet.New(d.state, d.tpool, config.WalletDir)
	if err != nil {
		return
	}
	d.miner, err = miner.New(d.state, d.gateway, d.tpool, d.wallet)
	if err != nil {
		return
	}
	d.host, err = host.New(d.state, d.tpool, d.wallet, config.HostDir)
	if err != nil {
		return
	}
	d.hostDB, err = hostdb.New(d.state)
	if err != nil {
		return
	}
	d.renter, err = renter.New(d.state, d.hostDB, d.wallet)
	if err != nil {
		return
	}

	d.initRPC()
	d.initAPI(config.APIAddr)

	return
}

// initRPC registers all of the daemon's RPC handlers
func (d *daemon) initRPC() (err error) {
	err = d.network.RegisterRPC("AcceptBlock", d.gateway.RelayBlock)
	if err != nil {
		return
	}
	err = d.network.RegisterRPC("AcceptTransaction", d.tpool.AcceptTransaction)
	if err != nil {
		return
	}
	err = d.network.RegisterRPC("AddMe", d.gateway.AddMe)
	if err != nil {
		return
	}
	err = d.network.RegisterRPC("SendBlocks", d.gateway.SendBlocks)
	if err != nil {<commit_msg>fix RPC misnomer<commit_after>package main

import (
	"html/template"

	"github.com/stretchr/graceful"

	"github.com/NebulousLabs/Sia/consensus"
	"github.com/NebulousLabs/Sia/modules"
	"github.com/NebulousLabs/Sia/modules/gateway"
	"github.com/NebulousLabs/Sia/modules/host"
	"github.com/NebulousLabs/Sia/modules/hostdb"
	"github.com/NebulousLabs/Sia/modules/miner"
	"github.com/NebulousLabs/Sia/modules/renter"
	"github.com/NebulousLabs/Sia/modules/transactionpool"
	"github.com/NebulousLabs/Sia/modules/wallet"
	"github.com/NebulousLabs/Sia/network"
)

type DaemonConfig struct {
	// Network Variables
	APIAddr string
	RPCAddr string

	// Host Variables
	HostDir string

	// Miner Variables
	Threads int

	// Renter Variables
	DownloadDir string

	// Wallet Variables
	WalletDir string
}

type daemon struct {
	state   *consensus.State
	tpool   modules.TransactionPool
	network *network.TCPServer
	wallet  modules.Wallet
	miner   *miner.Miner
	host    modules.Host
	hostDB  modules.HostDB
	renter  modules.Renter
	gateway modules.Gateway

	styleDir    string
	downloadDir string

	template *template.Template

	apiServer *graceful.Server
}

func newDaemon(config DaemonConfig) (d *daemon, err error) {
	d = new(daemon)
	d.state = consensus.CreateGenesisState()
	d.network, err = network.NewTCPServer(config.RPCAddr)
	if err != nil {
		return
	}
	d.gateway, err = gateway.New(d.network, d.state)
	if err != nil {
		return
	}
	d.tpool, err = transactionpool.New(d.state, d.gateway)
	if err != nil {
		return
	}
	d.wallet, err = wallet.New(d.state, d.tpool, config.WalletDir)
	if err != nil {
		return
	}
	d.miner, err = miner.New(d.state, d.gateway, d.tpool, d.wallet)
	if err != nil {
		return
	}
	d.host, err = host.New(d.state, d.tpool, d.wallet, config.HostDir)
	if err != nil {
		return
	}
	d.hostDB, err = hostdb.New(d.state)
	if err != nil {
		return
	}
	d.renter, err = renter.New(d.state, d.hostDB, d.wallet)
	if err != nil {
		return
	}

	d.initRPC()
	d.initAPI(config.APIAddr)

	return
}

// initRPC registers all of the daemon's RPC handlers
func (d *daemon) initRPC() (err error) {
	err = d.network.RegisterRPC("RelayBlock", d.gateway.RelayBlock)
	if err != nil {
		return
	}
	err = d.network.RegisterRPC("AcceptTransaction", d.tpool.AcceptTransaction)
	if err != nil {
		return
	}
	err = d.network.RegisterRPC("AddMe", d.gateway.AddMe)
	if err != nil {
		return
	}
	err = d.network.RegisterRPC("SendBlocks", d.gateway.SendBlocks)
	if err != nil {
{'fraction_non_alphanumeric': 0.12647417649450995, 'fraction_numerical': 0.0, 'mean_word_length': 3.7618586640851888, 'pattern_counts': {'":': 0, '<': 3, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5781529', 'n_tokens_mistral': 1969, 'n_tokens_neox': 1944, 'n_words': 386}