Esempio n. 1
0
// shall be called from the main thread
func InitPeers(dir string) {
	PeerDB, _ = qdb.NewDB(dir+"peers3", true)

	if common.CFG.ConnectOnly != "" {
		x := strings.Index(common.CFG.ConnectOnly, ":")
		if x == -1 {
			common.CFG.ConnectOnly = fmt.Sprint(common.CFG.ConnectOnly, ":", common.DefaultTcpPort)
		}
		oa, e := net.ResolveTCPAddr("tcp4", common.CFG.ConnectOnly)
		if e != nil {
			println(e.Error())
			os.Exit(1)
		}
		proxyPeer = new(onePeer)
		proxyPeer.Services = common.Services
		copy(proxyPeer.Ip4[:], oa.IP[0:4])
		proxyPeer.Port = uint16(oa.Port)
		fmt.Printf("Connect to bitcoin network via %d.%d.%d.%d:%d\n",
			oa.IP[0], oa.IP[1], oa.IP[2], oa.IP[3], oa.Port)
	} else {
		go func() {
			if !common.CFG.Testnet {
				initSeeds([]string{"seed.bitcoin.sipa.be", "dnsseed.bluematt.me",
					/*"dnsseed.bitcoin.dashjr.org",*/ "bitseed.xf2.org"}, 8333)
			} else {
				initSeeds([]string{"bitcoin.petertodd.org", "testnet-seed.bitcoin.petertodd.org",
					/*"bluematt.me",*/ "testnet-seed.bluematt.me"}, 18333)
			}
		}()
	}
}
Esempio n. 2
0
func (db *unspentDb) dbN(i int) *qdb.DB {
	if db.tdb[i] == nil {
		db.tdb[i], _ = qdb.NewDB(db.dir+fmt.Sprintf("%06d", i), true)
		if db.nosyncinprogress {
			db.tdb[i].NoSync()
		}
	}
	return db.tdb[i]
}
Esempio n. 3
0
func (db *unwindDb) dbH(i int) *qdb.DB {
	i &= 0xff
	if db.tdb[i] == nil {
		db.tdb[i], _ = qdb.NewDB(db.dir+fmt.Sprintf("unw%03d", i), true)
		if db.nosyncinprogress {
			db.tdb[i].NoSync()
		}
	}
	return db.tdb[i]
}
Esempio n. 4
0
func main() {
	var dir string

	if len(os.Args) > 1 {
		dir = os.Args[1]
	} else {
		dir = utils.BitcoinHome() + "gocoin" + string(os.PathSeparator) + "btcnet" + string(os.PathSeparator) + "peers3"
	}

	db, er := qdb.NewDB(dir, true)

	if er != nil {
		println(er.Error())
		os.Exit(1)
	}

	println(db.Count(), "peers in databse", dir)
	if db.Count() == 0 {
		return
	}

	tmp := make(manyPeers, db.Count())
	cnt := 0
	db.Browse(func(k qdb.KeyType, v []byte) uint32 {
		np := utils.NewPeer(v)
		if !utils.ValidIp4(np.Ip4[:]) {
			return 0
		}
		if cnt < len(tmp) {
			tmp[cnt] = np
			cnt++
		}
		return 0
	})

	sort.Sort(tmp[:cnt])
	for cnt = 0; cnt < len(tmp) && cnt < 25; cnt++ {
		ad := tmp[cnt]
		fmt.Printf("%3d) %16s   %5d  - seen %5d min ago\n", cnt+1,
			fmt.Sprintf("%d.%d.%d.%d", ad.Ip4[0], ad.Ip4[1], ad.Ip4[2], ad.Ip4[3]),
			ad.Port, (time.Now().Unix()-int64(ad.Time))/60)
	}
}