func getFileIndexLoop(in chan net.IP, out chan fileindex.FileManifest) { resultSet := fileindex.NewFileManifest() for ip := range in { fileList, err := GetFileIndex(ip) if err != nil { continue } resultSet.Put(ip, fileList) } out <- resultSet }
func BuildFileManifest() (fileManifest fileindex.FileManifest) { fileManifest = fileindex.NewFileManifest() peerList := addressList.Contents() out1 := make(chan net.IP) out2 := make(chan net.IP) out3 := make(chan net.IP) out4 := make(chan net.IP) in1 := make(chan fileindex.FileManifest) in2 := make(chan fileindex.FileManifest) in3 := make(chan fileindex.FileManifest) in4 := make(chan fileindex.FileManifest) go getFileIndexLoop(out1, in1) go getFileIndexLoop(out2, in2) go getFileIndexLoop(out3, in3) go getFileIndexLoop(out4, in4) for _, item := range peerList { select { case out1 <- item.IP: case out2 <- item.IP: case out3 <- item.IP: case out4 <- item.IP: } } close(out1) close(out2) close(out3) close(out4) for i := 0; i < 4; i++ { select { case manifest := <-in1: fileManifest = aggregate(manifest, fileManifest) case manifest := <-in2: fileManifest = aggregate(manifest, fileManifest) case manifest := <-in3: fileManifest = aggregate(manifest, fileManifest) case manifest := <-in4: fileManifest = aggregate(manifest, fileManifest) } } log.Println("File index created") return }