Fix for #109 - Do basic connectivity checks for starting a server

This commit is contained in:
Sarah Jamie Lewis 2018-08-05 09:46:35 -07:00
parent a459758070
commit 3bfc4fbf99
2 changed files with 17 additions and 2 deletions

View File

@ -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"])

View File

@ -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.