From 3bfc4fbf99b333efff0d4a9f76e3175620c8951d Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Sun, 5 Aug 2018 09:46:35 -0700 Subject: [PATCH] Fix for #109 - Do basic connectivity checks for starting a server --- app/cli/main.go | 2 +- peer/cwtch_peer.go | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/cli/main.go b/app/cli/main.go index ce070c1..108679f 100644 --- a/app/cli/main.go +++ b/app/cli/main.go @@ -354,7 +354,7 @@ func main() { app.Peer.JoinServer(group.GroupServer) } } else { - fmt.Printf("Error creating new group: %v", err) + fmt.Printf("Error creating new group: %v\n", err) } } else { fmt.Printf("Error creating a new group, usage: %s\n", usages["new-group"]) diff --git a/peer/cwtch_peer.go b/peer/cwtch_peer.go index 5aaab02..c02c5ff 100644 --- a/peer/cwtch_peer.go +++ b/peer/cwtch_peer.go @@ -25,6 +25,7 @@ import ( "log" "strings" "sync" + "time" ) // cwtchPeer manages incoming and outgoing connections and all processing for a Cwtch Peer @@ -235,7 +236,21 @@ func (cp *cwtchPeer) ExportGroup(groupID string) (string, error) { // StartGroup create a new group linked to the given server and returns the group ID, an invite or an error. func (cp *cwtchPeer) StartGroup(server string) (string, []byte, error) { - return cp.Profile.StartGroup(server) + if len(server) == 16 { + servers := cp.GetServers() + _, ok := servers[server] + if !ok { + cp.JoinServer(server) + time.Sleep(5 * time.Second) + servers = cp.GetServers() + } + status, ok := servers[server] + if status != connections.AUTHENTICATED { + return "", nil, errors.New("server could not be connected, please check to see if this server is a cwtch server") + } + return cp.Profile.StartGroup(server) + } + return "", nil, errors.New("server is not an onion address") } // GetGroups returns an unordered list of all group IDs.