URI: 
       tdam-client: Move the init of the working directory to a separate function. - tordam - A library for peer discovery inside the Tor network
  HTML git clone https://git.parazyd.org/tordam
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 744a6b3b53755be364b37f7914b1961e9391bebf
   DIR parent a5268a9c66563b358d6b2d957051c3a10389ead9
  HTML Author: parazyd <parazyd@dyne.org>
       Date:   Sat, 27 Oct 2018 13:48:02 +0200
       
       dam-client: Move the init of the working directory to a separate function.
       
       Diffstat:
         M cmd/dam-client/main.go              |      41 ++++++++++++++++++++-----------
       
       1 file changed, 26 insertions(+), 15 deletions(-)
       ---
   DIR diff --git a/cmd/dam-client/main.go b/cmd/dam-client/main.go
       t@@ -45,6 +45,28 @@ type msgStruct struct {
                Secret string
        }
        
       +func clientInit(gen bool) {
       +        err := os.Chmod(lib.PrivKeyPath, 0600)
       +        lib.CheckError(err)
       +
       +        key, err := lib.GenRsa(lib.RsaBits)
       +        lib.CheckError(err)
       +
       +        err = lib.SavePrivRsa(lib.PrivKeyPath, key)
       +        lib.CheckError(err)
       +
       +        onionaddr, err := lib.OnionFromPubkeyRsa(key.PublicKey)
       +        lib.CheckError(err)
       +
       +        err = ioutil.WriteFile("hostname", onionaddr, 0644)
       +        lib.CheckError(err)
       +
       +        log.Printf("Our hostname is: %s\n", string(onionaddr))
       +        if gen {
       +                os.Exit(0)
       +        }
       +}
       +
        func announce(dir string, vals map[string]string, privkey *rsa.PrivateKey) (bool, error) {
                msg, err := json.Marshal(vals)
                if err != nil {
       t@@ -236,20 +258,8 @@ func main() {
                err := os.Chdir(lib.Cwd)
                lib.CheckError(err)
        
       -        if _, err := os.Stat(lib.PrivKeyPath); os.IsNotExist(err) || gen {
       -                os.Chmod(lib.PrivKeyPath, 0600)
       -                key, err := lib.GenRsa(lib.RsaBits)
       -                lib.CheckError(err)
       -                err = lib.SavePrivRsa(lib.PrivKeyPath, key)
       -                lib.CheckError(err)
       -                onionaddr, err := lib.OnionFromPubkeyRsa(key.PublicKey)
       -                lib.CheckError(err)
       -                err = ioutil.WriteFile("hostname", onionaddr, 0644)
       -                lib.CheckError(err)
       -                log.Println("Our hostname is:", string(onionaddr))
       -                if gen {
       -                        os.Exit(0)
       -                }
       +        if _, err = os.Stat(lib.PrivKeyPath); os.IsNotExist(err) || gen {
       +                clientInit(gen)
                }
        
                // Start up the hidden service
       t@@ -269,7 +279,8 @@ func main() {
                        for !(ok) {
                                t2 := time.Now().Unix()
                                if t2-t1 > 90 {
       -                                cmd.Process.Kill()
       +                                err := cmd.Process.Kill()
       +                                lib.CheckError(err)
                                        log.Fatalln("Too much time passed. Exiting.")
                                }
                                time.Sleep(1000 * time.Millisecond)