//Create will start a new DHT with a file system application and returns the FileSystem struct. //The input home indicates the directory that will store distributed documents. //The input addr specifies which address the application will listen on. func Create(home string, addr string) *FileSystem { me := new(FileSystem) me.node = chord.Create(addr) if me.node == nil { return nil } me.home = home me.mirror = fmt.Sprintf("%s/mirrored", home) me.addr = addr //make directories err := os.MkdirAll(me.home, 0755) err = os.MkdirAll(me.mirror, 0755) fmt.Printf("made directory %s.\n", me.home) if err != nil { checkError(err) return nil } me.node.Register(code, me) //experimental me.malicious = false me.cache = make(map[string]bool) return me }
func Create(home string, addr string) *LaviniaServer { me := new(LaviniaServer) me.node = chord.Create(addr) if me.node == nil { return nil } me.fs = fs.Extend(home, addr, me.node) if me.fs == nil { return nil } me.storage = fmt.Sprintf("%s/pmts", home) err := os.MkdirAll(me.storage, 0755) if err != nil { checkError(err) return nil } me.node.Register(code, me) return me }