tImplement handling of error replies from server in dam.go - tordam - A library for peer discovery inside the Tor network
 (HTM) git clone https://git.parazyd.org/tordam
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit bdc19f961efb7f6eeefc4d4dc04d761c0fea42b9
 (DIR) parent b6ba0392a41bb6f02bb4986312b3ca569d6de11b
 (HTM) Author: parazyd <parazyd@dyne.org>
       Date:   Thu,  7 Dec 2017 22:18:16 +0100
       
       Implement handling of error replies from server in dam.go
       
       Diffstat:
         M go/dam/dam.go                       |      20 +++++++++++++++-----
         M go/ddir/ddir.go                     |       1 -
       
       2 files changed, 15 insertions(+), 6 deletions(-)
       ---
 (DIR) diff --git a/go/dam/dam.go b/go/dam/dam.go
       t@@ -5,7 +5,6 @@ package main
        import (
                "encoding/base64"
                "encoding/json"
       -        "io/ioutil"
                "log"
                "os"
        
       t@@ -24,6 +23,10 @@ const Pubpath = "public.key"
        // Postmsg holds the message we are signing with our private key.
        const Postmsg = "I am a DECODE node!"
        
       +type msgStruct struct {
       +        Secret string
       +}
       +
        func main() {
                if _, err := os.Stat("private.key"); os.IsNotExist(err) {
                        key := lib.GenRsa(Bits)
       t@@ -53,10 +56,17 @@ func main() {
                log.Println("Sending request")
                resp := lib.HTTPPost("http://localhost:8080/announce", jsonVal)
        
       -        body, err := ioutil.ReadAll(resp.Body)
       -        lib.CheckError(err)
       -
                // TODO: Handle the secret decryption and returning it back decrypted to the
                // directory. Note to self: start saving state on ddir's side.
       -        log.Println(string(body))
       +
       +        // Parse server's reply
       +        var m msgStruct
       +        decoder := json.NewDecoder(resp.Body)
       +        err = decoder.Decode(&m)
       +        lib.CheckError(err)
       +
       +        if resp.StatusCode == 500 {
       +                log.Println("Unsuccessful reply from directory.")
       +                log.Fatalln("Server replied:", m.Secret)
       +        }
        }
 (DIR) diff --git a/go/ddir/ddir.go b/go/ddir/ddir.go
       t@@ -29,7 +29,6 @@ func handlePost(rw http.ResponseWriter, request *http.Request) {
                err := decoder.Decode(&n)
                lib.CheckError(err)
        
       -        log.Println(n.Signature)
                decSig, err := base64.StdEncoding.DecodeString(n.Signature)
                lib.CheckError(err)