diff options
Diffstat (limited to 'server/user.go')
-rw-r--r-- | server/user.go | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/server/user.go b/server/user.go index 6b55eb4..cd31ca1 100644 --- a/server/user.go +++ b/server/user.go @@ -5,6 +5,7 @@ import ( "encoding/base64" "encoding/gob" "errors" + "log" "net/http" "os" "strings" @@ -18,7 +19,7 @@ type user struct { nextIndex map[string]int } -var users map[string]user +var users map[string]*user // Verify that a body was signed by this ID func verify(id string, body []byte) error { @@ -59,17 +60,20 @@ func reconfigure(id string, dhtVal []byte) { user.dhtVal = dhtVal servers := strings.Split(string(dhtVal[8:len(dhtVal)-ed25519.SignatureSize]), "\n") + log.Printf("Reconfiguring %s %s", id, servers) + user.servers = servers if servers[0] == me { if user.nextIndex == nil { user.nextIndex = make(map[string]int) } - for _, server := range servers { - if _, ok := user.nextIndex[server]; !ok { + for i, server := range servers { + if _, ok := user.nextIndex[server]; !ok && i > 0 { user.nextIndex[server] = len(user.log) go replicate(id, server) } } } + inServers := false for _, server := range servers { if server == me { @@ -95,7 +99,7 @@ func userHandler(w http.ResponseWriter, r *http.Request) { mu.Lock() if _, ok := users[id]; !ok { // Add user - users[id] = user{dhtVal: val} + users[id] = &user{dhtVal: val} os.Mkdir(dataDir+"/"+id, 0755) persist(id) } |