commit bdc19f961efb7f6eeefc4d4dc04d761c0fea42b9
parent b6ba0392a41bb6f02bb4986312b3ca569d6de11b
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:
2 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/go/dam/dam.go b/go/dam/dam.go
@@ -5,7 +5,6 @@ package main
import (
"encoding/base64"
"encoding/json"
- "io/ioutil"
"log"
"os"
@@ -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)
@@ -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)
+ }
}
diff --git a/go/ddir/ddir.go b/go/ddir/ddir.go
@@ -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)