<commit_before>package samtun

import (
  "bitbucket.org/majestrate/sam3"
  "fmt"
  "io/ioutil"
  "log"
  "os"
  "strings"
  "time"
)


// determine if this file exists and we can write to it
func checkfile(fname string) bool {
  _, err := os.Stat(fname)
  return err == nil
}

func Run() {
  // defaults
  fname := "samtun.json"

  if len(os.Args) > 1 {
    if os.Args[1] == "-h" || os.Args[1] == "--help" {
      // print usage and return
      fmt.Fprintf(os.Stdout, "usage: %s [config.json]\n")
      return
    } else {
      fname = os.Args[1]
    }
  }
  if ! checkfile(fname) {
    // generate a config we don't have it there
    genConfig(fname)
  }
  conf, err := loadConfig(fname)
  if err == nil {
    // we are configured correctly

    log.Println("connecting to", conf.Sam)
    sam, err := sam3.NewSAM(conf.Sam)
    if err == nil {
      // we have a sam connection
      var keys sam3.I2PKeys
      if ! checkfile(conf.Keyfile) {
        // we have not generated private keys yet
        log.Println("generating keys")
        keys, err = sam.NewKeys()
        log.Println("we are", keys.Addr().Base32())
        ioutil.WriteFile(conf.Keyfile, []byte(keys.String()+" "+keys.Addr().String()), 0600)
        b32 := keys.Addr().Base32()
        conf.Map[b32] = conf.Addr
        err = conf.Save(fname)
        if err != nil {
          log.Println("failed to save address map", err)
          return
        }<commit_msg>generate config and save it<commit_after>package samtun

import (
  "bitbucket.org/majestrate/sam3"
  "fmt"
  "io/ioutil"
  "log"
  "os"
  "strings"
  "time"
)


// determine if this file exists and we can write to it
func checkfile(fname string) bool {
  _, err := os.Stat(fname)
  return err == nil
}

func Run() {
  // defaults
  fname := "samtun.json"

  if len(os.Args) > 1 {
    if os.Args[1] == "-h" || os.Args[1] == "--help" {
      // print usage and return
      fmt.Fprintf(os.Stdout, "usage: %s [config.json]\n")
      return
    } else {
      fname = os.Args[1]
    }
  }
  if ! checkfile(fname) {
    // generate a config we don't have it there
    conf := genConfig(fname)
    conf.Save(fname)
  }
  conf, err := loadConfig(fname)
  if err == nil {
    // we are configured correctly

    log.Println("connecting to", conf.Sam)
    sam, err := sam3.NewSAM(conf.Sam)
    if err == nil {
      // we have a sam connection
      var keys sam3.I2PKeys
      if ! checkfile(conf.Keyfile) {
        // we have not generated private keys yet
        log.Println("generating keys")
        keys, err = sam.NewKeys()
        log.Println("we are", keys.Addr().Base32())
        ioutil.WriteFile(conf.Keyfile, []byte(keys.String()+" "+keys.Addr().String()), 0600)
        b32 := keys.Addr().Base32()
        conf.Map[b32] = conf.Addr
        err = conf.Save(fname)
        if err != nil {
          log.Println("failed to save address map", err)
          return
        }
{'fraction_non_alphanumeric': 0.14874613534867742, 'fraction_numerical': 0.013740982480247337, 'mean_word_length': 2.2248062015503876, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1967804', 'n_tokens_mistral': 1048, 'n_tokens_neox': 1018, 'n_words': 266}