Esempio n. 1
0
func initializeAddressList() error {
	err := getLocalIP()
	if err != nil {
		log.Fatal(err)
		return err
	}

	path := util.ConfPath("peerlist")
	file, err := os.Open(path)

	if err != nil && os.IsNotExist(err) {
		if !Settings.DoNotBootStrap {
			bootStrap() //This bootstraps us into the network
		} else {
			var ipList addresslist.PeerList
			AddressList = addresslist.New(ipList)
			log.Println("Created empty AddressList")
		}

		return nil
	} else if err != nil {
		log.Fatal(err)
	} else {
		data, err := ioutil.ReadAll(file)
		if err != nil {
			log.Fatal(err)
			return err
		}
		ipList := addresslist.Unmarshal(data)
		AddressList = addresslist.New(ipList)
		log.Println("Loaded AddressList from file")
	}

	return err
}
Esempio n. 2
0
func bootStrap() error {
	iplist := make(addresslist.PeerList, 1)
	var host string
	fmt.Print("Please enter a host name for bootstrap\n=>")
	_, err := fmt.Scanln(&host)
	if err != nil {
		log.Println(err)
		return bootStrap()
	}
	addrs, err := net.LookupIP(host)
	if err != nil {
		log.Println(err)
		return bootStrap()
	}
	iplist[0] = &addresslist.PeerItem{addrs[0].To16(), FileIndex.IndexHash(), FileIndex.TimeStamp()}
	AddressList = addresslist.New(iplist)
	log.Println("Created new peerlist")
	return nil
}
Esempio n. 3
0
func InitializeAddressList() {
	path := ConfPath("peerlist")
	file, err := os.Open(path)

	pathErr, ok := err.(*os.PathError)
	if err != nil && ok && pathErr.Err.Error() == "no such file or directory" { //Yeah, this is pretty bad but the library
		// did not expose a constant to represent this

		log.Println(err)
		BootStrap() //This bootstraps us into the network
		return
	} else if err != nil {
		log.Fatal(err)
	}

	data, err := ioutil.ReadAll(file)
	if err != nil {
		log.Fatal(err)
	}
	iplist := addresslist.FromString(string(data))
	AddressList = addresslist.New(iplist)
	log.Println("Loaded AddressList from file")
}
Esempio n. 4
0
//TODO: Make a BootStrap that does something reasonable
func BootStrap() {
	iplist := make(addresslist.IPSlice, 1)
	iplist[0] = net.IPv4(127, 0, 0, 1)
	AddressList = addresslist.New(iplist)
}