Now use ACN events instaed of tor poller #186
|
@ -8,6 +8,7 @@ import (
|
||||||
"cwtch.im/ui/go/the"
|
"cwtch.im/ui/go/the"
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AppEventListener(gcd *gothings.GrandCentralDispatcher) {
|
func AppEventListener(gcd *gothings.GrandCentralDispatcher) {
|
||||||
|
@ -15,11 +16,30 @@ func AppEventListener(gcd *gothings.GrandCentralDispatcher) {
|
||||||
the.AppBus.Subscribe(event.NewPeer, q.EventChannel)
|
the.AppBus.Subscribe(event.NewPeer, q.EventChannel)
|
||||||
the.AppBus.Subscribe(event.PeerError, q.EventChannel)
|
the.AppBus.Subscribe(event.PeerError, q.EventChannel)
|
||||||
the.AppBus.Subscribe(event.AppError, q.EventChannel)
|
the.AppBus.Subscribe(event.AppError, q.EventChannel)
|
||||||
|
the.AppBus.Subscribe(event.ACNStatus, q.EventChannel)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
e := q.Next()
|
e := q.Next()
|
||||||
|
|
||||||
switch e.EventType {
|
switch e.EventType {
|
||||||
|
case event.ACNStatus:
|
||||||
|
progStr := e.Data[event.Progreess]
|
||||||
|
percent, _ := strconv.Atoi(progStr)
|
||||||
|
message := e.Data[event.Status]
|
||||||
|
var statuscode int
|
||||||
|
if percent == 0 {
|
||||||
|
statuscode = 0
|
||||||
|
message = "can't find tor. is it running? is the controlport configured?"
|
||||||
|
} else if percent == 100 {
|
||||||
|
statuscode = 3
|
||||||
|
message = "tor appears to be running just fine!"
|
||||||
|
} else if percent < 80 {
|
||||||
|
statuscode = 1
|
||||||
|
} else {
|
||||||
|
statuscode = 2
|
||||||
|
}
|
||||||
|
|
||||||
|
gcd.TorStatus(statuscode, message)
|
||||||
case event.PeerError:
|
case event.PeerError:
|
||||||
// current only case
|
// current only case
|
||||||
log.Errorf("couldn't load profiles: %v", e.Data[event.Error])
|
log.Errorf("couldn't load profiles: %v", e.Data[event.Error])
|
||||||
|
@ -28,6 +48,7 @@ func AppEventListener(gcd *gothings.GrandCentralDispatcher) {
|
||||||
case event.AppError:
|
case event.AppError:
|
||||||
|
|
||||||
if e.Data[event.Error] == event.AppErrLoaded0 {
|
if e.Data[event.Error] == event.AppErrLoaded0 {
|
||||||
|
// TODO: only an error if other profiles are not loaded
|
||||||
log.Infoln("couldn't load your config file. attempting to create one now")
|
log.Infoln("couldn't load your config file. attempting to create one now")
|
||||||
|
|
||||||
the.CwtchApp.CreatePeer("alice", "be gay do crime")
|
the.CwtchApp.CreatePeer("alice", "be gay do crime")
|
||||||
|
@ -83,7 +104,6 @@ func AppEventListener(gcd *gothings.GrandCentralDispatcher) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
go IncomingListener(&gcd.UIState)
|
go IncomingListener(&gcd.UIState)
|
||||||
go TorStatusPoller(gcd.TorStatus, the.ACN)
|
|
||||||
go PresencePoller(&gcd.UIState)
|
go PresencePoller(&gcd.UIState)
|
||||||
|
|
||||||
// load ui preferences
|
// load ui preferences
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
package characters
|
|
||||||
|
|
||||||
import (
|
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TorStatusPoller(setTorStatus func(int, string), acn connectivity.ACN) {
|
|
||||||
if acn == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
for {
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
|
|
||||||
percent, message := acn.GetBootstrapStatus()
|
|
||||||
var statuscode int
|
|
||||||
if percent == 0 {
|
|
||||||
statuscode = 0
|
|
||||||
message = "can't find tor. is it running? is the controlport configured?"
|
|
||||||
} else if percent == 100 {
|
|
||||||
statuscode = 3
|
|
||||||
message = "tor appears to be running just fine!"
|
|
||||||
} else if percent < 80 {
|
|
||||||
statuscode = 1
|
|
||||||
} else {
|
|
||||||
statuscode = 2
|
|
||||||
}
|
|
||||||
|
|
||||||
setTorStatus(statuscode, message)
|
|
||||||
}
|
|
||||||
}
|
|
6
main.go
6
main.go
|
@ -222,11 +222,7 @@ func loadNetworkingAndFiles(gcd *gothings.GrandCentralDispatcher, service bool,
|
||||||
log.Infoln("Creating New App Service")
|
log.Infoln("Creating New App Service")
|
||||||
the.CwtchService = libapp.NewAppService(the.ACN, the.CwtchDir, serviceBridge)
|
the.CwtchService = libapp.NewAppService(the.ACN, the.CwtchDir, serviceBridge)
|
||||||
} else {
|
} else {
|
||||||
clientBridge, err := bridge.NewPipeBridgeClient(clientIn, serviceIn)
|
clientBridge := bridge.NewPipeBridgeClient(clientIn, serviceIn)
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Could not create client bridge: %v\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
log.Infoln("Creating New App Client")
|
log.Infoln("Creating New App Client")
|
||||||
the.CwtchApp = libapp.NewAppClient(the.CwtchDir, clientBridge)
|
the.CwtchApp = libapp.NewAppClient(the.CwtchDir, clientBridge)
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue