Beispiel #1
0
func (c *pbuildCmd) Main() {
	if c.cache <= 0 {
		Usage(c, "Max cache size must be > 0")
	}
	c.configuredCmd.Main()
	InitLog()
	hashes := make(chan *symflux.Zp)
	done := make(chan interface{})
	var db *openpgp.DB
	var err error
	if db, err = openpgp.NewDB(); err != nil {
		die(err)
	}
	var ptree recon.PrefixTree
	reconSettings := recon.NewSettings(openpgp.Config().Settings.TomlTree)
	reconSettings.Set("symflux.recon.diskv.cacheSizeMax", 1024*1024*c.cache)
	if ptree, err = openpgp.NewSksPTree(reconSettings); err != nil {
		die(err)
	}
	if err = ptree.Create(); err != nil {
		panic(err)
	}
	insertPtree := func() {
		defer func() { done <- struct{}{} }()
		n := 0
		for {
			select {
			case z, ok := <-hashes:
				if z != nil {
					err = ptree.Insert(z)
					if err != nil {
						if c.ignoreDups && strings.Contains(err.Error(), "insert duplicate element") {
							continue
						}
						log.Printf("Error inserting %x into ptree: %v", z.Bytes(), err)
						panic(err)
					}
					n++
					if n%1000 == 0 {
						fmt.Printf(".")
					}
				}
				if !ok {
					return
				}
			}
		}
	}
	for i := 0; i < c.nworkers; i++ {
		go insertPtree()
	}
	readHashes(db, hashes)
	close(hashes)
	for i := 0; i < c.nworkers; i++ {
		<-done
	}
	if err = ptree.Close(); err != nil {
		log.Println("Close:", err)
	}
}
Beispiel #2
0
func (ec *loadCmd) Main() {
	if ec.path == "" {
		Usage(ec, "--path is required")
	}
	if ec.txnSize < 1 {
		Usage(ec, "Invalid --txn-size, must be >= 1")
	}

	if ec.totalKeyLimit < 0 {
		Usage(ec, "Please enter positive total Keys")
	} else {
		fmt.Println("Starting loading of ", ec.totalKeyLimit, " keys")
	}
	ec.configuredCmd.Main()
	InitLog()
	var err error
	if ec.db, err = openpgp.NewDB(); err != nil {
		die(err)
	}
	ec.l = openpgp.NewLoader(ec.db, true)
	// Ensure tables all exist
	if err = ec.db.CreateTables(); err != nil {
		die(err)
	}
	reconSettings := recon.NewSettings(openpgp.Config().Settings.TomlTree)
	if ec.ptree, err = openpgp.NewSksPTree(reconSettings); err != nil {
		die(err)
	}
	// Create the prefix tree (if not exists)
	if err = ec.ptree.Create(); err != nil {
		die(fmt.Errorf("Unable to create prefix tree: %v", err))
	}
	// Ensure tables all exist
	if err = ec.db.CreateTables(); err != nil {
		die(fmt.Errorf("Unable to create database tables: %v", err))
	}
	// Load all keys from input material
	ec.loadAllKeys(ec.path)
	// Close the prefix tree
	if err = ec.ptree.Close(); err != nil {
		log.Println("Close ptree:", err)
	}
	// Close the database connection
	if err = ec.db.Close(); err != nil {
		log.Println("Close database:", err)
	}
}
Beispiel #3
0
func (ec *deleteCmd) Main() {
	if ec.keyHash == "" {
		Usage(ec, "--keyHash is required")
	}
	keyHash, err := hex.DecodeString(ec.keyHash)
	if err != nil {
		die(err)
	}
	ec.configuredCmd.Main()
	InitLog()
	var db *openpgp.DB
	if db, err = openpgp.NewDB(); err != nil {
		die(err)
	}
	// Ensure tables all exist
	if err = db.CreateTables(); err != nil {
		die(err)
	}
	var ptree recon.PrefixTree
	reconSettings := recon.NewSettings(openpgp.Config().Settings.TomlTree)
	if ptree, err = openpgp.NewSksPTree(reconSettings); err != nil {
		die(err)
	}
	// Create the prefix tree (if not exists)
	if err = ptree.Create(); err != nil {
		die(err)
	}
	// Ensure tables all exist
	if err = db.CreateTables(); err != nil {
		die(err)
	}
	if err = ptree.Remove(symflux.Zb(symflux.P_SKS, keyHash)); err != nil {
		die(err)
	}
	log.Println(ec.keyHash, "deleted from prefix tree")
}