<commit_before>package main

import (
	"flag"
	"fmt"
	broker "github.com/abdulkadiryaman/hrotti/broker"
	command "github.com/hashicorp/consul/command"
	"github.com/hashicorp/consul/command/agent"
	consul "github.com/hashicorp/consul/consul"
	"github.com/mitchellh/cli"
	"log"
	"os"
	"os/signal"
	"syscall"
)

func bootstrapConsul(dc string, bootstrap bool) {
	private, err := consul.GetPrivateIP()
	if err != nil {
		fmt.Errorf("err: %v", err)
	}

	var agentArgs []string
	if bootstrap {
		agentArgs = []string{"-server", "-bootstrap", "-node", private.String(), "-dc", dc, "-data-dir", "/tmp/consul"}
	} else {
		agentArgs = []string{"-server", "-node", private.String(), "-dc", dc, "-data-dir", "/tmp/consul"}
	}
	ui := &cli.BasicUi{Writer: os.Stdout}
	agentCommand := &agent.Command{
		Ui:         ui,
		ShutdownCh: make(chan struct{}),
	}
	agentCommand.Run(agentArgs)
}

func bootstrapMqttServer() {
	listener := broker.NewListenerConfig("tcp://0.0.0.0:1883")

	h := broker.NewHrotti(100)

	h.AddListener("self", listener)

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, syscall.SIGTERM)
	<-c
	h.Stop()
}

func Join(args []string) int {
	var wan bool
	log.Println("Joining to cluster with addresses : ", args)
	cmdFlags := flag.NewFlagSet("join", flag.ContinueOnError)
	cmdFlags.BoolVar(&wan, "wan", false, "wan")
	rpcAddr := command.RPCAddrFlag(cmdFlags)
	if err := cmdFlags.Parse(args); err != nil {
		fmt.Errorf("Error occured : %v", err)
		return 1
	}

	addrs := cmdFlags.Args()
	if len(addrs) == 0 {
		log.Fatal("At least one address to join must be specified.")
		return 1
	}

	client, err := command.RPCClient(*rpcAddr)
	if err != nil {
		log.Fatal("Error connecting to Consul agent: %s", err)
		return 1
	}
	defer client.Close()

	n, err := client.Join(addrs, wan)
	if err != nil {
		log.Fatal("Error joining the cluster: %s", err)
		return 1
	}

	log.Println(
		"Successfully joined cluster by contacting %d nodes.", n)
	return 0
}

func main() {
	var bootstrap bool
	if len(os.Args) < 2 {
		bootstrap = true
	} else {
		bootstrap = os.Args[1] != "false"
	}

	go bootstrapConsul("dc1", bootstrap)

	if !bootstrap {
		joinArgs := []string{"172.17.0.2"}
		go Join(joinArgs)
	}

	bootstrapMqttServer()
}
<commit_msg>node name settings to default ip address<commit_after>package main

import (
	"flag"
	"fmt"
	broker "github.com/abdulkadiryaman/hrotti/broker"
	command "github.com/hashicorp/consul/command"
	"github.com/hashicorp/consul/command/agent"
	consul "github.com/hashicorp/consul/consul"
	"github.com/mitchellh/cli"
	"os"
	"os/signal"
	"syscall"
	"time"
	"log"
)

func bootstrapConsul(dc string, bootstrap bool) {
	private, err := consul.GetPrivateIP()
	if err != nil {
		fmt.Errorf("err: %v", err)
	}

	var agentArgs []string
	if bootstrap {
		agentArgs = []string{"-server", "-bootstrap", "-node", private.String(), "-dc", dc, "-data-dir", "/tmp/consul"}
	} else {
		agentArgs = []string{"-server", "-node", private.String(), "-dc", dc, "-data-dir", "/tmp/consul"}
	}
	ui := &cli.BasicUi{Writer: os.Stdout}
	agentCommand := &agent.Command{
		Ui:         ui,
		ShutdownCh: make(chan struct{}),
	}
	agentCommand.Run(agentArgs)
}

func bootstrapMqttServer() {
	listener := broker.NewListenerConfig("tcp://0.0.0.0:1883")

	h := broker.NewHrotti(100)

	h.AddListener("self", listener)

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, syscall.SIGTERM)
	<-c
	h.Stop()
}

func Join(args []string) int {
	log.Println("Sleeping for 3 seconds to consul come up....")
	time.Sleep(3000 * time.Millisecond)
	var wan bool
	log.Println("Joining to cluster with addresses : ", args)
	cmdFlags := flag.NewFlagSet("join", flag.ContinueOnError)
	cmdFlags.BoolVar(&wan, "wan", false, "wan")
	rpcAddr := command.RPCAddrFlag(cmdFlags)
	if err := cmdFlags.Parse(args); err != nil {
		fmt.Errorf("Error occured : %v", err)
		return 1
	}

	addrs := cmdFlags.Args()
	if len(addrs) == 0 {
		log.Fatal("At least one address to join must be specified.")
		return 1
	}

	client, err := command.RPCClient(*rpcAddr)
	if err != nil {
		log.Fatal("Error connecting to Consul agent: %s", err)
		return 1
	}
	defer client.Close()

	n, err := client.Join(addrs, wan)
	if err != nil {
		log.Fatal("Error joining the cluster: %s", err)
		return 1
	}

	log.Println(
		"Successfully joined cluster by contacting %d nodes.", n)
	return 0
}

func main() {
	var bootstrap bool
	if len(os.Args) < 2 {
		bootstrap = true
	} else {
		bootstrap = os.Args[1] != "false"
	}

	go bootstrapConsul("dc1", bootstrap)

	if !bootstrap {
		joinArgs := []string{"172.17.0.2"}
		go Join(joinArgs)
	}

	bootstrapMqttServer()
}

{'fraction_non_alphanumeric': 0.1685807150595883, 'fraction_numerical': 0.013217768147345613, 'mean_word_length': 3.947481243301179, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '990707', 'n_tokens_mistral': 1858, 'n_tokens_neox': 1729, 'n_words': 413}