コード例 #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
ファイル: client.go プロジェクト: sandwich-share/sandwich-go
func updateAddressList(newList addresslist.PeerList) {
	oldList := addressList.Contents()
	var resultList addresslist.PeerList
	reduceMap := make(map[string]*addresslist.PeerItem)
	sort.Sort(oldList)
	sort.Sort(newList)
	newList = removeDeadEntries(newList)
	if newList == nil {
		return
	}
	for _, elem := range oldList {
		if elem.IP.Equal(localIP) {
			continue
		}
		toReplace, ok := reduceMap[string(elem.IP)]
		if ok {
			if toReplace.LastSeen.Before(elem.LastSeen) {
				reduceMap[string(elem.IP)] = elem
			}
		} else {
			reduceMap[string(elem.IP)] = elem
		}
	}
	for _, elem := range newList {
		if elem.IP.Equal(localIP) {
			continue
		}
		toReplace, ok := reduceMap[string(elem.IP)]
		if ok {
			if toReplace.LastSeen.Before(elem.LastSeen) {
				reduceMap[string(elem.IP)] = elem
			}
		} else {
			reduceMap[string(elem.IP)] = elem
		}
	}
	for _, value := range reduceMap {
		resultList = append(resultList, value)
	}
	if len(resultList) > 0 {
		util.Save(resultList)
	}
	addressList.Copy(resultList)
}