Browse Source

clean up: locks, set key in order to support delete

deleteClean
Dan Ballard 4 weeks ago
parent
commit
fc47b0463d
  1. 5
      server.go
  2. 7
      serverConfig.go
  3. 9
      servers.go

5
server.go

@ -189,10 +189,13 @@ func (s *server) GetStatistics() Statistics {
func (s *server) Delete(password string) error {
s.lock.Lock()
defer s.lock.Unlock()
if s.config.Encrypted && !s.config.CheckPassword(password) {
s.lock.Unlock()
log.Errorf("encryped and checkpassword failed")
return errors.New("Cannot delete server, passwords do not match")
}
s.lock.Unlock()
s.Destroy()
os.RemoveAll(s.config.ConfigDir)
return nil
}

7
serverConfig.go

@ -149,11 +149,12 @@ func LoadConfig(configDir, filename string, encrypted bool, password string) (*C
if err != nil {
return nil, err
}
key := v1.CreateKey(password, salt)
config.encFileStore = v1.NewFileStore(configDir, ServerConfigFile, key)
config.key = v1.CreateKey(password, salt)
config.encFileStore = v1.NewFileStore(configDir, ServerConfigFile, config.key)
raw, err = config.encFileStore.Read()
if err != nil {
log.Errorf("read enc bytes failed: %s\n", err)
// Not an error to log as load config is called blindly across all dirs with a password to see what it applies to
log.Debugf("read enc bytes failed: %s\n", err)
return nil, err
}
} else {

9
servers.go

@ -106,9 +106,10 @@ func (s *servers) DeleteServer(onion string, password string) error {
defer s.lock.Unlock()
server := s.servers[onion]
if server != nil {
server.Destroy()
err := server.Delete(password)
delete(s.servers, onion)
if err == nil {
delete(s.servers, onion)
}
return err
}
return errors.New("server not found")
@ -127,7 +128,9 @@ func (s *servers) LaunchServer(onion string) {
func (s *servers) StopServer(onion string) {
s.lock.Lock()
defer s.lock.Unlock()
s.servers[onion].Stop()
if server, exists := s.servers[onion]; exists {
server.Stop()
}
}
// Stop stops all the servers

Loading…
Cancel
Save