|
@ -9,10 +9,10 @@ import ( |
|
|
"json" |
|
|
"json" |
|
|
"log" |
|
|
"log" |
|
|
"mime" |
|
|
"mime" |
|
|
"os" |
|
|
|
|
|
"rand" |
|
|
"rand" |
|
|
"strconv" |
|
|
"strconv" |
|
|
"strings" |
|
|
"strings" |
|
|
|
|
|
"time" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
var ( |
|
|
var ( |
|
@ -99,35 +99,41 @@ func dirWriteHandler(w http.ResponseWriter, r *http.Request) { |
|
|
func dirJoinHandler(w http.ResponseWriter, r *http.Request) { |
|
|
func dirJoinHandler(w http.ResponseWriter, r *http.Request) { |
|
|
s := r.FormValue("server") |
|
|
s := r.FormValue("server") |
|
|
publicServer := r.FormValue("publicServer") |
|
|
publicServer := r.FormValue("publicServer") |
|
|
volumes := make([]store.VolumeStat,0) |
|
|
|
|
|
|
|
|
volumes := make([]store.VolumeStat, 0) |
|
|
json.Unmarshal([]byte(r.FormValue("volumes")), volumes) |
|
|
json.Unmarshal([]byte(r.FormValue("volumes")), volumes) |
|
|
server.directory.Add(directory.NewMachine(s,publicServer),volumes) |
|
|
|
|
|
|
|
|
server.directory.Add(directory.NewMachine(s, publicServer), volumes) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var server *Haystack |
|
|
var server *Haystack |
|
|
|
|
|
|
|
|
func main() { |
|
|
func main() { |
|
|
flag.Parse() |
|
|
flag.Parse() |
|
|
|
|
|
bothEnabled := false |
|
|
if !*chunkEnabled && !*metaEnabled { |
|
|
if !*chunkEnabled && !*metaEnabled { |
|
|
fmt.Fprintf(os.Stdout, "Act as both a store server and a directory server\n") |
|
|
|
|
|
|
|
|
bothEnabled = true |
|
|
|
|
|
log.Println("Act as both a store server and a directory server") |
|
|
} |
|
|
} |
|
|
server = new(Haystack) |
|
|
server = new(Haystack) |
|
|
if *chunkEnabled { |
|
|
|
|
|
fmt.Fprintf(os.Stdout, "Chunk data stored in %s\n", *chunkFolder) |
|
|
|
|
|
|
|
|
if *chunkEnabled || bothEnabled { |
|
|
|
|
|
log.Println("Chunk data stored in", *chunkFolder) |
|
|
server.store = store.NewStore(*chunkServer, *publicServer, *chunkFolder) |
|
|
server.store = store.NewStore(*chunkServer, *publicServer, *chunkFolder) |
|
|
defer server.store.Close() |
|
|
defer server.store.Close() |
|
|
http.HandleFunc("/", storeHandler) |
|
|
http.HandleFunc("/", storeHandler) |
|
|
} |
|
|
} |
|
|
if *metaEnabled { |
|
|
|
|
|
|
|
|
if *metaEnabled || bothEnabled { |
|
|
server.directory = directory.NewMapper(*metaFolder, "directory") |
|
|
server.directory = directory.NewMapper(*metaFolder, "directory") |
|
|
defer server.directory.Save() |
|
|
defer server.directory.Save() |
|
|
http.HandleFunc("/dir/read", dirReadHandler) |
|
|
http.HandleFunc("/dir/read", dirReadHandler) |
|
|
http.HandleFunc("/dir/write", dirWriteHandler) |
|
|
http.HandleFunc("/dir/write", dirWriteHandler) |
|
|
http.HandleFunc("/dir/join", dirJoinHandler) |
|
|
http.HandleFunc("/dir/join", dirJoinHandler) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
go func() { |
|
|
|
|
|
time.Sleep(3000 * 1000) |
|
|
server.store.Join(*metaServer) |
|
|
server.store.Join(*metaServer) |
|
|
|
|
|
log.Println("stored joined at", *metaServer) |
|
|
|
|
|
}() |
|
|
|
|
|
|
|
|
log.Println("Serving at http://127.0.0.1:" + strconv.Itoa(*port)) |
|
|
log.Println("Serving at http://127.0.0.1:" + strconv.Itoa(*port)) |
|
|
http.ListenAndServe(":"+strconv.Itoa(*port), nil) |
|
|
http.ListenAndServe(":"+strconv.Itoa(*port), nil) |
|
|
|
|
|
|
|
|
} |
|
|
} |