|
|
@ -9,10 +9,10 @@ import ( |
|
|
|
"json" |
|
|
|
"log" |
|
|
|
"mime" |
|
|
|
"os" |
|
|
|
"rand" |
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
) |
|
|
|
|
|
|
|
var ( |
|
|
@ -99,35 +99,41 @@ func dirWriteHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
func dirJoinHandler(w http.ResponseWriter, r *http.Request) { |
|
|
|
s := r.FormValue("server") |
|
|
|
publicServer := r.FormValue("publicServer") |
|
|
|
volumes := make([]store.VolumeStat,0) |
|
|
|
volumes := make([]store.VolumeStat, 0) |
|
|
|
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 |
|
|
|
|
|
|
|
func main() { |
|
|
|
flag.Parse() |
|
|
|
bothEnabled := false |
|
|
|
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) |
|
|
|
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) |
|
|
|
defer server.store.Close() |
|
|
|
http.HandleFunc("/", storeHandler) |
|
|
|
} |
|
|
|
if *metaEnabled { |
|
|
|
if *metaEnabled || bothEnabled { |
|
|
|
server.directory = directory.NewMapper(*metaFolder, "directory") |
|
|
|
defer server.directory.Save() |
|
|
|
http.HandleFunc("/dir/read", dirReadHandler) |
|
|
|
http.HandleFunc("/dir/write", dirWriteHandler) |
|
|
|
http.HandleFunc("/dir/join", dirJoinHandler) |
|
|
|
} |
|
|
|
|
|
|
|
go func() { |
|
|
|
time.Sleep(3000 * 1000) |
|
|
|
server.store.Join(*metaServer) |
|
|
|
log.Println("stored joined at", *metaServer) |
|
|
|
}() |
|
|
|
|
|
|
|
log.Println("Serving at http://127.0.0.1:" + strconv.Itoa(*port)) |
|
|
|
http.ListenAndServe(":"+strconv.Itoa(*port), nil) |
|
|
|
|
|
|
|
} |