From 9248417773336e439fcda7f1129c4af4f79a647a Mon Sep 17 00:00:00 2001 From: Maarten Everts Date: Fri, 4 Sep 2020 16:09:43 +0200 Subject: [PATCH 1/3] Make UUID in JsonAddress optional --- signald/client-protocol/v1/types.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/signald/client-protocol/v1/types.go b/signald/client-protocol/v1/types.go index 18929c0..70596d8 100644 --- a/signald/client-protocol/v1/types.go +++ b/signald/client-protocol/v1/types.go @@ -2,7 +2,7 @@ package v1 // JsonAddress is a signal user's contact information. a phone number, UUID or both type JsonAddress struct { - UUID string `json:"uuid"` + UUID string `json:"uuid,omitempty"` Number string `json:"number"` } @@ -26,7 +26,7 @@ type JsonReadMessage struct { type JsonSendMessageResult struct { Address JsonAddress `json:"address"` - Success Success `json:"success"` + Success Success `json:"success"` NetworkFailure bool `json:"networkFailure"` UnregisteredFailure bool `json:"unregisteredFailure"` IdentityFailure string `json:"identityFailure"` From 599c65adb25f1f80d3ecd03a176913f760f6e549 Mon Sep 17 00:00:00 2001 From: Maarten Everts Date: Fri, 4 Sep 2020 16:10:28 +0200 Subject: [PATCH 2/3] Wait for response on socket when sending It appears that signald doesn't like not being able to send something back on the socket. --- cmd/signald-cli/cmd/send.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmd/signald-cli/cmd/send.go b/cmd/signald-cli/cmd/send.go index dbba3d7..a6132bd 100644 --- a/cmd/signald-cli/cmd/send.go +++ b/cmd/signald-cli/cmd/send.go @@ -19,6 +19,7 @@ import ( "log" "github.com/spf13/cobra" + "time" "git.callpipe.com/finn/signald-go/signald" "git.callpipe.com/finn/signald-go/signald/client-protocol/v1" @@ -59,6 +60,20 @@ var sendCmd = &cobra.Command{ request.AttachmentFilenames = []string{attachment} } s.SendRequest(request) + + timeout := 10 + + // Wait for the response + c := make(chan signald.Response) + + go s.Listen(c) + select { + case <-c: + log.Println("Ok.") + case <-time.After(1 * time.Second): + // But timeout after a while + log.Fatalf("Timeout after %d seconds\n", timeout) + } }, } From e9ba7bccbd37be1ccfc4851b9106d69b1a3fc341 Mon Sep 17 00:00:00 2001 From: Maarten Everts Date: Fri, 4 Sep 2020 16:11:32 +0200 Subject: [PATCH 3/3] Add error handling for when connection to socket fails --- cmd/signald-cli/cmd/root.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cmd/signald-cli/cmd/root.go b/cmd/signald-cli/cmd/root.go index de24eb8..a943e55 100644 --- a/cmd/signald-cli/cmd/root.go +++ b/cmd/signald-cli/cmd/root.go @@ -17,6 +17,7 @@ package cmd import ( "fmt" + "log" "os" "github.com/spf13/cobra" @@ -50,7 +51,11 @@ func init() { RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.signald-cli.yaml)") RootCmd.PersistentFlags().StringVarP(&socketPath, "socket", "s", "/var/run/signald/signald.sock", "the path to the signald socket file") s = &signald.Signald{SocketPath: socketPath} - s.Connect() + err := s.Connect() + if err != nil { + log.Fatal(err) + } + } // initConfig reads in config file and ENV variables if set.