Fix some annoying bugs for the demo
This commit is contained in:
parent
94f2b70dc7
commit
13c3fbab94
|
@ -2,7 +2,6 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/ed25519"
|
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
@ -114,12 +113,11 @@ func peerHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the timestamp of this val
|
// Get the timestamp of this val
|
||||||
func timestamp(val []byte) int64 {
|
func timestamp(val []byte) uint64 {
|
||||||
if len(val) < 8+ed25519.SignatureSize {
|
if len(val) < 8 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
ret, _ := binary.Varint(val[:8])
|
return binary.LittleEndian.Uint64(val)
|
||||||
return ret
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the value for a key from the DHT
|
// Get the value for a key from the DHT
|
||||||
|
|
|
@ -43,7 +43,7 @@ func replicate(id, s string) {
|
||||||
|
|
||||||
op := user.log[idx]
|
op := user.log[idx]
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
file, _ := os.Open(op)
|
file, _ := os.Open(dataDir + "/" + id + "/" + op)
|
||||||
resp, err := http.Post(s+"/storage/"+id+"/"+op+"?idx="+fmt.Sprint(idx), "application/octet-stream", file)
|
resp, err := http.Post(s+"/storage/"+id+"/"+op+"?idx="+fmt.Sprint(idx), "application/octet-stream", file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
time.Sleep(50 * time.Millisecond)
|
time.Sleep(50 * time.Millisecond)
|
||||||
|
@ -124,7 +124,6 @@ func storageHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
b, err := io.ReadAll(r.Body)
|
b, err := io.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -184,5 +183,6 @@ func storageHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
user.log = append(user.log, filename)
|
user.log = append(user.log, filename)
|
||||||
|
w.Write([]byte(fmt.Sprint(len(user.log))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ func reconfigure(id string, dhtVal []byte) {
|
||||||
persist(id)
|
persist(id)
|
||||||
if !inServers {
|
if !inServers {
|
||||||
delete(users, id)
|
delete(users, id)
|
||||||
_ = os.RemoveAll(id)
|
_ = os.RemoveAll(dataDir + "/" + id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ func userHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
if _, ok := users[id]; !ok {
|
if _, ok := users[id]; !ok {
|
||||||
// Add user
|
// Add user
|
||||||
users[id] = &user{dhtVal: val}
|
users[id] = &user{dhtVal: val, phase: 0}
|
||||||
os.Mkdir(dataDir+"/"+id, 0755)
|
os.Mkdir(dataDir+"/"+id, 0755)
|
||||||
persist(id)
|
persist(id)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue