Beispiel #1
0
//initialize logger.
func init() {
	logging = log.New(os.Stdout, "",
		log.Ldate|log.Ltime|log.Lshortfile)

	logging.Println("registering MetaDisk service...")

	s2 := commons.Service{}
	s2.Name = "MetaDisk"
	s2.Desc = `You can upload your data to the Storj network with a simple drag and drop.`
	s2.ImageURL = "http://storj.io/img/metadisk.png"
	commons.RegisterService(&s2)
	commons.RegisterHandler("/", &s2, Asset, nil)

	http.HandleFunc("/MetaDisk/api/upload", upload)
	http.HandleFunc("/MetaDisk/api/download/", download)
	http.HandleFunc("/MetaDisk/accounts/token/new/", tokenNew)
	http.HandleFunc("/MetaDisk/api/find/", find)
	http.HandleFunc("/MetaDisk/api/status/", status)
	http.HandleFunc("/MetaDisk/accounts/token/balance/", balance)

	//only for test
	telehashh, err := storjtelehash.NewStorjTelehashTest(0)
	if err == nil {
		telehash = telehashh
	}

}
Beispiel #2
0
func TestFarming(t *testing.T) {
	logging.Println("starting farming...")
	var err error
	loc, err := commons.Telehash.GetMyLocation()
	if err != nil {
		t.Errorf(err.Error())
	}
	h, err := newUploadHandler("rand.dat")
	if err != nil {
		t.Errorf(err.Error())
	}
	telehash, err = storjtelehash.NewStorjTelehashTest(0)
	if err != nil {
		t.Errorf(err.Error())
	}
	telehash.OpenChannel(loc, "farming", h)
	time.Sleep(60 * time.Second)

	if !deepCompare("rand.dat", driveshare.DownloadDir+"/9790d8321c9b8d91a81683b2987975176f726d116ce77c8a233f0d6fbb01b888") {
		t.Errorf("farmed file differs with original file")
	}
	b, err := hex.DecodeString("9790d8321c9b8d91a81683b2987975176f726d116ce77c8a233f0d6fbb01b888")
	if err != nil {
		t.Errorf(err.Error())
	}
	stat := StoredFiles.GetStatus(b)
	logging.Println(stat.Desc)
	if stat != nil && !(stat == &Verifying || stat == &SuccessHeartbeat || stat == &Challenging) {
		t.Errorf("failed while farming")
	}
	stat = driveshare.StoredFiles.GetStatus(b)
	logging.Println(stat.Desc)
	if stat != nil && !(stat == &driveshare.SuccessHeartbeat || stat == &driveshare.Confirming || stat == &driveshare.Proving) {
		t.Errorf("failed while farming")
	}

	logging.Println("starting retrieving...")
	f, err := os.Open("rand.dat")
	if err != nil {
		t.Errorf(err.Error())
	}
	fi, err := f.Stat()
	if err != nil {
		t.Errorf(err.Error())
	}
	rh := newRetrieveandler(b, fi.Size())
	telehash.OpenChannel(loc, "retrieving", rh)
	time.Sleep(30 * time.Second)
	if !deepCompare("rand.dat", DownloadDir+"/9790d8321c9b8d91a81683b2987975176f726d116ce77c8a233f0d6fbb01b888") {
		t.Errorf("downloaded file differs with original file")
	}
}