Exemple #1
0
func initPeers(dir string) {
	nextDefrag = time.Now().Add(defragEvery)

	peerDB, _ = qdb.NewDB(dir + "peers")
	if peerDB.Count() == 0 {
		if !*testnet {
			initSeeds([]string{"seed.bitcoin.sipa.be", "dnsseed.bluematt.me",
				"dnsseed.bitcoin.dashjr.org", "bitseed.xf2.org"}, 8333)
		} else {
			initSeeds([]string{"testnet-seed.bitcoin.petertodd.org", "testnet-seed.bluematt.me"}, 18333)
		}
		println("peerDB initiated with ", peerDB.Count(), "seeds")
	}

	if *proxy != "" {
		oa, e := net.ResolveTCPAddr("tcp4", *proxy)
		if e != nil {
			if strings.HasPrefix(e.Error(), "missing port in address") {
				oa, e = net.ResolveTCPAddr("tcp4", fmt.Sprint(*proxy, ":", DefaultTcpPort))
			}
			if e != nil {
				println(e.Error())
				os.Exit(1)
			}
		}
		proxyPeer = new(onePeer)
		proxyPeer.Services = 1
		copy(proxyPeer.Ip4[:], oa.IP[0:4])
		proxyPeer.Port = uint16(oa.Port)
	}

}
Exemple #2
0
func (db *unspentDb) dbN(i int) *qdb.DB {
	if db.tdb[i] == nil {
		db.tdb[i], _ = qdb.NewDB(db.dir + fmt.Sprintf("%02x/", i))
		db.tdb[i].Load()
		if db.nosyncinprogress {
			db.tdb[i].NoSync()
		}
	}
	return db.tdb[i]
}
Exemple #3
0
func newUnwindDB(dir string) (db *unwindDb) {
	db = new(unwindDb)
	db.tdb, _ = qdb.NewDB(dir)
	db.lastBlockHeight = 0
	db.tdb.Browse(func(k qdb.KeyType, v []byte) bool {
		h := uint32(k)
		if h > db.lastBlockHeight {
			db.lastBlockHeight = h
			copy(db.lastBlockHash[:], v[:32])
		}
		return true
	})
	return
}