Compare commits
No commits in common. "master" and "v0.1-send-message" have entirely different histories.
master
...
v0.1-send-
|
@ -1,4 +1,4 @@
|
||||||
package odClient
|
package ODClient
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/s-rah/go-ricochet/connection"
|
"github.com/s-rah/go-ricochet/connection"
|
||||||
|
@ -13,6 +13,7 @@ type ODClient struct {
|
||||||
connection.AutoConnectionHandler
|
connection.AutoConnectionHandler
|
||||||
connection *connection.Connection
|
connection *connection.Connection
|
||||||
recvMessages chan string
|
recvMessages chan string
|
||||||
|
sendMessages chan string
|
||||||
deviceName string
|
deviceName string
|
||||||
deviceLevel int
|
deviceLevel int
|
||||||
batteryLevel string
|
batteryLevel string
|
||||||
|
@ -42,6 +43,7 @@ func (odClient *ODClient) Connect(privateKeyData string, serverAddr string) erro
|
||||||
})
|
})
|
||||||
|
|
||||||
odClient.recvMessages = make(chan string)
|
odClient.recvMessages = make(chan string)
|
||||||
|
odClient.sendMessages = make(chan string)
|
||||||
|
|
||||||
log.Println("ODClient connecting...")
|
log.Println("ODClient connecting...")
|
||||||
odClient.connection, err = goricochet.Open(serverAddr)
|
odClient.connection, err = goricochet.Open(serverAddr)
|
||||||
|
@ -50,7 +52,7 @@ func (odClient *ODClient) Connect(privateKeyData string, serverAddr string) erro
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Println("ODCleint connected!")
|
log.Println("ODCleint connected!")
|
||||||
log.Println("Starting auth...")
|
log.Println("starting auth...")
|
||||||
known, err := connection.HandleOutboundConnection(odClient.connection).ProcessAuthAsClient(privateKey)
|
known, err := connection.HandleOutboundConnection(odClient.connection).ProcessAuthAsClient(privateKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error handling auth: %v", err)
|
log.Println("Error handling auth: %v", err)
|
||||||
|
@ -63,11 +65,14 @@ func (odClient *ODClient) Connect(privateKeyData string, serverAddr string) erro
|
||||||
if !known {
|
if !known {
|
||||||
err := odClient.connection.RequestOpenChannel("im.ricochet.contact.request", odClient)
|
err := odClient.connection.RequestOpenChannel("im.ricochet.contact.request", odClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Could not auth with server", err)
|
log.Printf("could not contact %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("ODClient: Authenticated")
|
log.Println("ODClient: Authenticated")
|
||||||
|
//odClient.connection.RequestOpenChannel("im.ricochet.contact.request", odClient)
|
||||||
|
|
||||||
|
log.Println("go")
|
||||||
|
|
||||||
log.Println("RequestOpenChanel chat")
|
log.Println("RequestOpenChanel chat")
|
||||||
err = odClient.connection.RequestOpenChannel("im.ricochet.chat", odClient)
|
err = odClient.connection.RequestOpenChannel("im.ricochet.chat", odClient)
|
||||||
|
@ -75,15 +80,12 @@ func (odClient *ODClient) Connect(privateKeyData string, serverAddr string) erro
|
||||||
log.Println("Error: " + err.Error())
|
log.Println("Error: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("Connection fully initiated, chat channel open!")
|
log.Println("sending greeting message")
|
||||||
return nil
|
odClient.SendMessage("hello from the client")
|
||||||
}
|
|
||||||
|
|
||||||
func (odClient *ODClient) Disconnect() {
|
|
||||||
log.Println("Break()...")
|
|
||||||
odClient.connection.Break()
|
return nil
|
||||||
log.Println("Conn.Close()...")
|
|
||||||
odClient.connection.Conn.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*func (odClient *ODClient) RequestContact() {
|
/*func (odClient *ODClient) RequestContact() {
|
||||||
|
@ -116,16 +118,11 @@ func (odClient *ODClient) SendMessage(message string) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (odClient *ODClient) GetMessage() string {
|
|
||||||
message := <-odClient.recvMessages
|
|
||||||
return message
|
|
||||||
}
|
|
||||||
|
|
||||||
/************* Chat Channel Handler ********/
|
/************* Chat Channel Handler ********/
|
||||||
|
|
||||||
// ChatMessage passes the response to recvMessages.
|
// ChatMessage passes the response to recvMessages.
|
||||||
func (odc *ODClient) ChatMessage(messageID uint32, when time.Time, message string) bool {
|
func (odc *ODClient) ChatMessage(messageID uint32, when time.Time, message string) bool {
|
||||||
//log.Printf("Received Message: %s", message)
|
log.Printf("Received Message: %s", message)
|
||||||
odc.recvMessages <- message
|
odc.recvMessages <- message
|
||||||
return true
|
return true
|
||||||
}
|
}
|
|
@ -8,10 +8,9 @@ import (
|
||||||
"time"
|
"time"
|
||||||
"github.com/yawning/bulb/utils/pkcs1"
|
"github.com/yawning/bulb/utils/pkcs1"
|
||||||
"crypto/rsa"
|
"crypto/rsa"
|
||||||
|
"github.com/dballard/goRicochetMobile/ODClient"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func GeneratePrivateKey() (string, error) {
|
func GeneratePrivateKey() (string, error) {
|
||||||
privateKey, err := utils.GeneratePrivateKey()
|
privateKey, err := utils.GeneratePrivateKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -30,10 +29,6 @@ func GetOnionAddress(privateKey string) string {
|
||||||
return addr
|
return addr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/******** Testing by standing up an echobot ******/
|
|
||||||
|
|
||||||
func TestNet() (ok bool, ex error) {
|
func TestNet() (ok bool, ex error) {
|
||||||
_, err := http.Get("http://golang.org/")
|
_, err := http.Get("http://golang.org/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -42,6 +37,15 @@ func TestNet() (ok bool, ex error) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ODClientConnect(privateKey string, serverAddr string) error {
|
||||||
|
log.Println("ODClientConnect(" + serverAddr + ")")
|
||||||
|
odClient := new(ODClient.ODClient)
|
||||||
|
err := odClient.Connect(privateKey, serverAddr)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
/******** Testing by standing up an echobot ******/
|
||||||
|
|
||||||
func EchoBot(privateKeyData string) {
|
func EchoBot(privateKeyData string) {
|
||||||
privateKey, err := utils.ParsePrivateKey([]byte(privateKeyData))
|
privateKey, err := utils.ParsePrivateKey([]byte(privateKeyData))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -55,7 +59,7 @@ func EchoBot(privateKeyData string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
echobot := new(application.RicochetApplication)
|
echobot := new(application.RicochetApplication)
|
||||||
echobot.Init(privateKey, new(application.AcceptAllContactManager))
|
echobot.Init(privateKey, new(application.RejectAllContactManager))
|
||||||
|
|
||||||
echobot.OnChatMessage(func(rai *application.RicochetApplicationInstance, id uint32, timestamp time.Time, message string) {
|
echobot.OnChatMessage(func(rai *application.RicochetApplicationInstance, id uint32, timestamp time.Time, message string) {
|
||||||
log.Printf("message from %v - %v", rai.RemoteHostname, message)
|
log.Printf("message from %v - %v", rai.RemoteHostname, message)
|
||||||
|
|
53
od/od.go
53
od/od.go
|
@ -1,53 +0,0 @@
|
||||||
package od
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/dballard/goRicochetMobile/od/odClient"
|
|
||||||
"log"
|
|
||||||
"strconv"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// Downsampling array from https://git.mascherari.press/oniondildonics/client/src/master/main.go
|
|
||||||
// moddified
|
|
||||||
levelArr = []int{1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6}
|
|
||||||
client *odClient.ODClient = nil
|
|
||||||
)
|
|
||||||
|
|
||||||
func ODClientConnect(privateKey string, serverAddr string) error {
|
|
||||||
log.Println("ODClientConnect()")
|
|
||||||
client = new(odClient.ODClient)
|
|
||||||
err := client.Connect(privateKey, serverAddr)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
func ODClientDisconnect() {
|
|
||||||
log.Println("ODClientDisconnect()")
|
|
||||||
client.Disconnect()
|
|
||||||
client = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetDeviceName() string {
|
|
||||||
client.SendMessage("/name")
|
|
||||||
name := client.GetMessage()
|
|
||||||
return name
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetBatteryLevel() string {
|
|
||||||
client.SendMessage("/battery")
|
|
||||||
batteryLevel := client.GetMessage()
|
|
||||||
return batteryLevel
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetVibeLevel() int {
|
|
||||||
client.SendMessage("/level")
|
|
||||||
level, err := strconv.Atoi(client.GetMessage())
|
|
||||||
if err != nil {
|
|
||||||
// TODO: don't swallow errors
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
return levelArr[level] // not bounds checking...
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetVibeLevel(newVibeLevel int) {
|
|
||||||
client.SendMessage("/level " + strconv.Itoa(newVibeLevel))
|
|
||||||
}
|
|
Loading…
Reference in New Issue