Browse Source

Alert the user when there is no internet

pull/233/head
Sarah Jamie Lewis 1 month ago
parent
commit
6dd346fe96
4 changed files with 64 additions and 4 deletions
  1. 4
    3
      go.mod
  2. 22
    0
      go.sum
  3. 24
    1
      go/handlers/appHandler.go
  4. 14
    0
      go/handlers/peerHandler.go

+ 4
- 3
go.mod View File

@@ -3,12 +3,13 @@ module cwtch.im/ui
go 1.12

require (
cwtch.im/cwtch v0.3.3
git.openprivacy.ca/openprivacy/libricochet-go v1.0.6
cwtch.im/cwtch v0.3.6
git.openprivacy.ca/openprivacy/libricochet-go v1.0.8
github.com/gopherjs/gopherjs v0.0.0-20190812055157-5d271430af9f // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/stretchr/testify v1.4.0 // indirect
github.com/therecipe/qt v0.0.0-20191002095216-73192f6811d0
github.com/therecipe/qt v0.0.0-20191101232336-18864661ae4f
github.com/therecipe/qt/internal/binding/files/docs/5.12.0 v0.0.0-20191101232336-18864661ae4f // indirect
github.com/therecipe/qt/internal/binding/files/docs/5.13.0 v0.0.0-20191002095216-73192f6811d0 // indirect
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586 // indirect
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 // indirect

+ 22
- 0
go.sum View File

@@ -6,6 +6,12 @@ cwtch.im/cwtch v0.3.2 h1:JxoauToMckHjmQz3QCmI7XG9pun1tF3pV/o5ziuqV1A=
cwtch.im/cwtch v0.3.2/go.mod h1:4b2qGW5bZKm4CwYxqc0+4pgpDU0LjjyoihC8a/ezOoQ=
cwtch.im/cwtch v0.3.3 h1:mAypnkTCehej5ebSEzl43nPufsyyXLNz/dw2RWOO+Wk=
cwtch.im/cwtch v0.3.3/go.mod h1:I95rbE3aK8uic7LsMOB1lfJDSzlNsRUP0/5cFCLkD0Y=
cwtch.im/cwtch v0.3.4 h1:EZzDE5kBvkWsNrlPg4+uQ0LKp5AMLfXr7cqXFUgnCc4=
cwtch.im/cwtch v0.3.4/go.mod h1:I95rbE3aK8uic7LsMOB1lfJDSzlNsRUP0/5cFCLkD0Y=
cwtch.im/cwtch v0.3.5 h1:L4hBYMRUSADodBz3gwIrYGXZf2V7HzTlzLUku9N3O9A=
cwtch.im/cwtch v0.3.5/go.mod h1:I95rbE3aK8uic7LsMOB1lfJDSzlNsRUP0/5cFCLkD0Y=
cwtch.im/cwtch v0.3.6 h1:a+BhoTpdlH5yI335HQDB7EEWZJqvNdoZnnjYLYne52Y=
cwtch.im/cwtch v0.3.6/go.mod h1:NU6Pm4RgHm97b03U83W7/NabmRvBxHQMxM8/kZnH12Y=
cwtch.im/tapir v0.1.10 h1:V+TkmwXNd6gySZqlVw468wMYEkmDwMSyvhkkpOfUw7w=
cwtch.im/tapir v0.1.10/go.mod h1:EuRYdVrwijeaGBQ4OijDDRHf7R2MDSypqHkSl5DxI34=
cwtch.im/tapir v0.1.11 h1:JLm1MIYq4VXKzhj68+P8OuVPllAU9U6G0DtUor2fbc4=
@@ -13,6 +19,11 @@ cwtch.im/tapir v0.1.11/go.mod h1:EuRYdVrwijeaGBQ4OijDDRHf7R2MDSypqHkSl5DxI34=
git.openprivacy.ca/openprivacy/libricochet-go v1.0.4/go.mod h1:yMSG1gBaP4f1U+RMZXN85d29D39OK5s8aTpyVRoH5FY=
git.openprivacy.ca/openprivacy/libricochet-go v1.0.6 h1:5o4K2qn3otEE1InC5v5CzU0yL7Wl7DhVp4s8H3K6mXY=
git.openprivacy.ca/openprivacy/libricochet-go v1.0.6/go.mod h1:yMSG1gBaP4f1U+RMZXN85d29D39OK5s8aTpyVRoH5FY=
git.openprivacy.ca/openprivacy/libricochet-go v1.0.7 h1:yOD87eeuIFVY/2dsYzduSotE2eYOVd2pks4i7dKw+Ng=
git.openprivacy.ca/openprivacy/libricochet-go v1.0.7/go.mod h1:6I+vO9Aagv3/yUWv+e7A57H8tgXgR67FCjfSj9Pp970=
git.openprivacy.ca/openprivacy/libricochet-go v1.0.8 h1:HVoyxfivFaEtkfO5K3piD6oq6MQB1qGF5IB2EYXeCW8=
git.openprivacy.ca/openprivacy/libricochet-go v1.0.8/go.mod h1:6I+vO9Aagv3/yUWv+e7A57H8tgXgR67FCjfSj9Pp970=
github.com/Julusian/godocdown v0.0.0-20170816220326-6d19f8ff2df8/go.mod h1:INZr5t32rG59/5xeltqoCJoNY7e5x/3xoY9WSWVWg74=
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI=
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=
github.com/c-bata/go-prompt v0.2.3/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOCSiVIqS34=
@@ -22,6 +33,8 @@ github.com/cretz/bine v0.1.0/go.mod h1:6PF6fWAvYtwjRGkAuDEJeWNOv3a2hUouSP/yRYXmv
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dvyukov/go-fuzz v0.0.0-20191022152526-8cb203812681/go.mod h1:11Gm+ccJnvAhCNLlf5+cS9KjtbaD5I5zaZpFMsTHWTw=
github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
@@ -43,7 +56,10 @@ github.com/mattn/go-tty v0.0.0-20190424173100-523744f04859/go.mod h1:XPvLUNfbS4f
github.com/pkg/term v0.0.0-20190109203006-aa71e9d9e942/go.mod h1:eCbImbZ95eXtAUIbLAuAVnBnwf83mjf6QIVH8SHYwqQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/robertkrimen/godocdown v0.0.0-20130622164427-0bfa04905481/go.mod h1:C9WhFzY47SzYBIvzFqSvHIR6ROgDo4TtdTuRaOMjF/s=
github.com/sirupsen/logrus v1.4.1 h1:GL2rEmy6nsikmW0r8opw9JIRScdMF5hA8cOYLH7In1k=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/stephens2424/writerset v1.0.2/go.mod h1:aS2JhsMn6eA7e82oNmW4rfsgAOp9COBTTl8mzkwADnc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
@@ -56,6 +72,10 @@ github.com/therecipe/qt v0.0.0-20190824160953-615e084bab56 h1:CAFR/rHptsl8gEP6ig
github.com/therecipe/qt v0.0.0-20190824160953-615e084bab56/go.mod h1:SUUR2j3aE1z6/g76SdD6NwACEpvCxb3fvG82eKbD6us=
github.com/therecipe/qt v0.0.0-20191002095216-73192f6811d0 h1:Y4I5RGVEZubcplYny6zwqg0G7WUC6gw+esy+2cPCruA=
github.com/therecipe/qt v0.0.0-20191002095216-73192f6811d0/go.mod h1:SUUR2j3aE1z6/g76SdD6NwACEpvCxb3fvG82eKbD6us=
github.com/therecipe/qt v0.0.0-20191101232336-18864661ae4f h1:06ICDSmDOBUC9jwgv44ngvyHzwudJNLa5H+rbCyDFRY=
github.com/therecipe/qt v0.0.0-20191101232336-18864661ae4f/go.mod h1:SUUR2j3aE1z6/g76SdD6NwACEpvCxb3fvG82eKbD6us=
github.com/therecipe/qt/internal/binding/files/docs/5.12.0 v0.0.0-20191101232336-18864661ae4f h1:035UB1g+zTNL+3BAKLLy8XwYzBL0dM+HwuDELYOoRoY=
github.com/therecipe/qt/internal/binding/files/docs/5.12.0 v0.0.0-20191101232336-18864661ae4f/go.mod h1:7m8PDYDEtEVqfjoUQc2UrFqhG0CDmoVJjRlQxexndFc=
github.com/therecipe/qt/internal/binding/files/docs/5.13.0 v0.0.0-20191002095216-73192f6811d0 h1:SC92QLlGwzwrT3Xi5YzKvtVXFIriPP0Ui1AOIZgDyh8=
github.com/therecipe/qt/internal/binding/files/docs/5.13.0 v0.0.0-20191002095216-73192f6811d0/go.mod h1:mH55Ek7AZcdns5KPp99O0bg+78el64YCYWHiQKrOdt4=
golang.org/x/crypto v0.0.0-20190128193316-c7b33c32a30b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
@@ -87,7 +107,9 @@ golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191031220737-6d8f1af9ccc0 h1:+o3suEKE/4hCUt6qjV8SDcVZhz2dO8UWlHliCa+4bvg=
golang.org/x/tools v0.0.0-20191031220737-6d8f1af9ccc0/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191108175616-46f5a7f28bf0/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=

+ 24
- 1
go/handlers/appHandler.go View File

@@ -9,6 +9,7 @@ import (
"git.openprivacy.ca/openprivacy/libricochet-go/log"
"os"
"strconv"
"time"
)

func App(gcd *ui.GrandCentralDispatcher, subscribed chan bool) {
@@ -17,13 +18,33 @@ func App(gcd *ui.GrandCentralDispatcher, subscribed chan bool) {
the.AppBus.Subscribe(event.PeerError, q)
the.AppBus.Subscribe(event.AppError, q)
the.AppBus.Subscribe(event.ACNStatus, q)
the.AppBus.Subscribe(event.NetworkStatus, q)
the.AppBus.Subscribe(event.ReloadDone, q)
subscribed <- true

networkOffline := false
timeSinceLastSuccess := time.Unix(0,0)

for {
e := q.Next()

switch e.EventType {
case event.NetworkStatus:
status := e.Data[event.Status]
if status == "Error" && !networkOffline {
networkOffline = true
// if it has been more that 5 minutes since we received any kind of success, then we should kill tor
// anything less that this i.e. transient networking failures, should allow us to reconnect without issue
if time.Now().Sub(timeSinceLastSuccess) > (time.Minute * 5) {
the.ACN.Restart()
}
}

if status == "Success" && networkOffline {
timeSinceLastSuccess = time.Now()
networkOffline = false
}

case event.ACNStatus:
progStr := e.Data[event.Progreess]
percent, _ := strconv.Atoi(progStr)
@@ -34,7 +55,7 @@ func App(gcd *ui.GrandCentralDispatcher, subscribed chan bool) {
message = "Connecting to network"
} else if percent < 100 {
statuscode = 2
message = "Establishng Tor circut"
message = "Establishing Tor circuit"
} else if percent == 100 {
statuscode = 3
message = "tor appears to be running just fine!"
@@ -44,6 +65,7 @@ func App(gcd *ui.GrandCentralDispatcher, subscribed chan bool) {
}

gcd.TorStatus(statuscode, message)

case event.PeerError:
// current only case
log.Errorf("couldn't load profiles: %v", e.Data[event.Error])
@@ -72,6 +94,7 @@ func App(gcd *ui.GrandCentralDispatcher, subscribed chan bool) {
onion := e.Data[event.Identity]

the.CwtchApp.AddPeerPlugin(onion, plugins.CONNECTIONRETRY)
the.CwtchApp.AddPeerPlugin(onion, plugins.NETWORKCHECK)

the.Peer = the.CwtchApp.GetPeer(onion)
the.EventBus = the.CwtchApp.GetEventBus(onion)

+ 14
- 0
go/handlers/peerHandler.go View File

@@ -20,12 +20,26 @@ func PeerHandler(uiManager *ui.Manager, subscribed chan bool) {
the.EventBus.Subscribe(event.ServerStateChange, q)
the.EventBus.Subscribe(event.PeerStateChange, q)
the.EventBus.Subscribe(event.PeerCreated, q)
the.EventBus.Subscribe(event.NetworkStatus, q)

subscribed <- true

networkOffline := false

for {
e := q.Next()

switch e.EventType {

case event.NetworkStatus:
the.AppBus.Publish(*e)
if e.Data["Status"] == "Success" && networkOffline {
networkOffline = false
// TODO we may have to reinitialize the peer
} else {
networkOffline = true
}

case event.NewMessageFromPeer: //event.TimestampReceived, event.RemotePeer, event.Data
ts, _ := time.Parse(time.RFC3339Nano, e.Data[event.TimestampReceived])
uiManager.AddMessage(e.Data[event.RemotePeer], e.Data[event.RemotePeer], e.Data[event.Data], false, e.EventID, ts, true)

Loading…
Cancel
Save