コード例 #1
0
ファイル: main.go プロジェクト: sandwich-share/sandwich-go
func Shutdown(fileManifest fileindex.FileManifest) {
	util.Save(AddressList.Contents())
	ioutil.WriteFile(util.ConfPath("blackwhitelist.xml"), BlackWhiteList.Marshal(), os.ModePerm)
	err := ioutil.WriteFile(util.ConfPath("manifest-cache.json"), fileManifest.Marshal(), os.ModePerm)
	if err != nil {
		log.Println(err)
	}
	os.Exit(0)
}
コード例 #2
0
func Initialize(newAddressList *addresslist.SafeIPList,
	newSandwichSettings *settings.Settings,
	newShutdown func(fileindex.FileManifest)) {
	addressList = newAddressList
	sandwichSettings = newSandwichSettings
	shutdown = newShutdown
	go downloadThread()
	go downloadThread()
	go downloadThread()
	go downloadThread()
	DownloadQueue = make(chan *IPFilePair, 1000)
	file, err := os.Open(util.ConfPath("manifest-cache.json"))
	if err != nil && os.IsNotExist(err) {
		fileManifest = client.BuildFileManifest()
	} else if err != nil {
		log.Println(err)
		fileManifest = client.BuildFileManifest()
	} else if xml, err := ioutil.ReadAll(file); err != nil {
		log.Println(err)
		fileManifest = client.BuildFileManifest()
		file.Close()
	} else if fileManifest, err = fileindex.UnmarshalManifest(xml); err != nil {
		fileManifest = client.BuildFileManifest()
	} else {
		fileManifest = client.CleanManifest(fileManifest)
		file.Close()
	}
	go InitializeFancyStuff()
	if !sandwichSettings.DontOpenBrowserOnStart {
		webbrowser.Open("http://localhost:" + sandwichSettings.LocalServerPort)
	}
}
コード例 #3
0
ファイル: main.go プロジェクト: sandwich-share/sandwich-go
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
}
コード例 #4
0
ファイル: main.go プロジェクト: sandwich-share/sandwich-go
func main() {

	log.Println(util.VERSION)

	runtime.GOMAXPROCS(runtime.NumCPU())

	util.ConfigPath = util.ConfigDirName //We need our conf directory to do anything else
	_, err := os.Stat(util.ConfigPath)
	if err != nil && os.IsNotExist(err) {
		err = os.MkdirAll(util.ConfigPath, os.ModePerm)
		if err != nil {
			log.Fatal(err)
		}
		log.Println("Created: " + util.ConfigPath)
	} else if err != nil {
		log.Fatal(err)
	}
	AddressSet = addresslist.NewAddressSet()
	file, err := os.Open(util.ConfPath("blackwhitelist.xml"))
	if err != nil {
		BlackWhiteList = addresslist.NewBWList(Whitelist)
	} else if data, err := ioutil.ReadAll(file); err != nil {
		file.Close()
		BlackWhiteList = addresslist.NewBWList(Whitelist)
	} else if BlackWhiteList, err = addresslist.UnmarshalBWList(data, Whitelist); err != nil {
		file.Close()
		BlackWhiteList = addresslist.NewBWList(Whitelist)
	}

	err = initializeSettings()
	if err != nil {
		return
	}
	err = initializePaths()
	if err != nil {
		return
	}
	err = initializeFileIndex()
	if err != nil {
		return
	}
	err = initializeAddressList()
	if err != nil {
		return
	}
	client.Initialize(AddressList, AddressSet, BlackWhiteList, LocalIP, Settings)
	frontend.Initialize(AddressList, Settings, Shutdown)
	if !Settings.WriteLogToScreen {
		logWriter, err := os.Create("log")
		if err != nil {
			log.Fatal(err)
			return
		}
		log.SetOutput(logWriter)
	}
	server.Initialize(AddressList, AddressSet, BlackWhiteList, FileIndex, LocalIP)
	if err != nil {
		return
	}
}
コード例 #5
0
ファイル: main.go プロジェクト: sandwich-share/sandwich-go
func initializeSettings() error {
	var err error
	settings.SettingsPath = util.ConfPath("settings.xml")
	Settings, err = settings.Load()
	if err != nil {
		Settings = &settings.Settings{}
	}
	if Settings.LocalServerPort == "" {
		Settings.LocalServerPort = "9001"
	}
	Settings.Save()
	return nil
}