<commit_before>package main

import (
	"fmt"
	"net"
	"net/http"
	_ "net/http/pprof"
	"os"
	"runtime"
	"strings"
	"time"

	"github.com/davecheney/profile"
	"github.com/docker/docker/pkg/mflag"
	"github.com/gorilla/mux"
	"github.com/weaveworks/mesh"

	"github.com/weaveworks/go-checkpoint"
	"github.com/weaveworks/weave/common"
	"github.com/weaveworks/weave/common/docker"
	"github.com/weaveworks/weave/db"
	"github.com/weaveworks/weave/ipam"
	"github.com/weaveworks/weave/nameserver"
	weavenet "github.com/weaveworks/weave/net"
	"github.com/weaveworks/weave/net/address"
	weave "github.com/weaveworks/weave/router"
)

var version = "(unreleased version)"

var Log = common.Log

type ipamConfig struct {
	IPRangeCIDR  string
	IPSubnetCIDR string
	PeerCount    int
	Observer     bool
	Seed         string
}

type dnsConfig struct {
	Domain                 string
	ListenAddress          string
	TTL                    int
	ClientTimeout          time.Duration
	EffectiveListenAddress string
}

const (
	versionCheckPeriod = 6 * time.Hour
)

func check() {
	handleResponse := func(r *checkpoint.CheckResponse, err error) {
		if err != nil {
			Log.Printf("Error checking version: %v", err)
		} else if r.Outdated {
			Log.Printf("Weave version %s is available; please update at %s",
				r.CurrentVersion, r.CurrentDownloadURL)
		}
	}

	// Start background version checking
	params := checkpoint.CheckParams{
		Product:       "weave-net",
		Version:       version,
		SignatureFile: "",
	}
	resp, err := checkpoint.Check(&params)
	handleResponse(resp, err)
	checkpoint.CheckInterval(&params, versionCheckPeriod, handleResponse)
}

func (c ipamConfig) Enabled() bool {
	var (
		hasPeerCount = c.PeerCount > 0
		hasSeed      = len(c.Seed) > 0
		hasRange     = c.IPRangeCIDR != ""
	)
	switch {
	case !(c.Observer || hasPeerCount || hasSeed || hasRange):
		return false
	case !hasRange:
		Log.Fatal("--observer, --ipam-seed or --init-peer-count specified without --ipalloc-range.")
	case c.Observer && hasPeerCount || hasPeerCount && hasSeed || hasSeed && c.Observer:
		Log.Fatal("At most one of --observer, --ipam-seed or --init-peer-count may be specified.")
	}
	return true
}

func main() {
	procs := runtime.NumCPU()
	// packet sniffing can block an OS thread, so we need one thread
	// for that plus at least one more.
	if procs < 2 {
		procs = 2
	}
	runtime.GOMAXPROCS(procs)

	var (
		justVersion        bool
		config             mesh.Config
		networkConfig      weave.NetworkConfig<commit_msg>add a check for "--ipalloc-default-subnet requires --ipalloc-range"<commit_after>package main

import (
	"fmt"
	"net"
	"net/http"
	_ "net/http/pprof"
	"os"
	"runtime"
	"strings"
	"time"

	"github.com/davecheney/profile"
	"github.com/docker/docker/pkg/mflag"
	"github.com/gorilla/mux"
	"github.com/weaveworks/mesh"

	"github.com/weaveworks/go-checkpoint"
	"github.com/weaveworks/weave/common"
	"github.com/weaveworks/weave/common/docker"
	"github.com/weaveworks/weave/db"
	"github.com/weaveworks/weave/ipam"
	"github.com/weaveworks/weave/nameserver"
	weavenet "github.com/weaveworks/weave/net"
	"github.com/weaveworks/weave/net/address"
	weave "github.com/weaveworks/weave/router"
)

var version = "(unreleased version)"

var Log = common.Log

type ipamConfig struct {
	IPRangeCIDR  string
	IPSubnetCIDR string
	PeerCount    int
	Observer     bool
	Seed         string
}

type dnsConfig struct {
	Domain                 string
	ListenAddress          string
	TTL                    int
	ClientTimeout          time.Duration
	EffectiveListenAddress string
}

const (
	versionCheckPeriod = 6 * time.Hour
)

func check() {
	handleResponse := func(r *checkpoint.CheckResponse, err error) {
		if err != nil {
			Log.Printf("Error checking version: %v", err)
		} else if r.Outdated {
			Log.Printf("Weave version %s is available; please update at %s",
				r.CurrentVersion, r.CurrentDownloadURL)
		}
	}

	// Start background version checking
	params := checkpoint.CheckParams{
		Product:       "weave-net",
		Version:       version,
		SignatureFile: "",
	}
	resp, err := checkpoint.Check(&params)
	handleResponse(resp, err)
	checkpoint.CheckInterval(&params, versionCheckPeriod, handleResponse)
}

func (c ipamConfig) Enabled() bool {
	var (
		hasPeerCount = c.PeerCount > 0
		hasSeed      = len(c.Seed) > 0
		hasRange     = c.IPRangeCIDR != ""
		hasSubnet    = c.IPSubnetCIDR != ""
	)
	switch {
	case !(c.Observer || hasPeerCount || hasSeed || hasRange || hasSubnet):
		return false
	case !hasRange && hasSubnet:
		Log.Fatal("--ipalloc-default-subnet specified without --ipalloc-range.")
	case !hasRange:
		Log.Fatal("--observer, --ipam-seed or --init-peer-count specified without --ipalloc-range.")
	case c.Observer && hasPeerCount || hasPeerCount && hasSeed || hasSeed && c.Observer:
		Log.Fatal("At most one of --observer, --ipam-seed or --init-peer-count may be specified.")
	}
	return true
}

func main() {
	procs := runtime.NumCPU()
	// packet sniffing can block an OS thread, so we need one thread
	// for that plus at least one more.
	if procs < 2 {
		procs = 2
	}
	runtime.GOMAXPROCS(procs)

	var (
		justVersion        bool
		config             mesh.Config
		networkConfig      weave.NetworkConfig
{'fraction_non_alphanumeric': 0.1228813559322034, 'fraction_numerical': 0.001926040061633282, 'mean_word_length': 3.239183673469388, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3784284', 'n_tokens_mistral': 1902, 'n_tokens_neox': 1818, 'n_words': 411}