Compare commits
5 Commits
v0.1-send-
...
master
Author | SHA1 | Date |
---|---|---|
|
d8d5db80b1 | |
|
1dd4a113a6 | |
|
81906f08f6 | |
|
4d7017402d | |
|
7265e7b7de |
|
@ -8,9 +8,10 @@ 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 {
|
||||||
|
@ -29,6 +30,10 @@ 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 {
|
||||||
|
@ -37,15 +42,6 @@ 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 {
|
||||||
|
@ -59,7 +55,7 @@ func EchoBot(privateKeyData string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
echobot := new(application.RicochetApplication)
|
echobot := new(application.RicochetApplication)
|
||||||
echobot.Init(privateKey, new(application.RejectAllContactManager))
|
echobot.Init(privateKey, new(application.AcceptAllContactManager))
|
||||||
|
|
||||||
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)
|
||||||
|
@ -67,4 +63,4 @@ func EchoBot(privateKeyData string) {
|
||||||
})
|
})
|
||||||
log.Printf("echobot started on %s", l.Addr().String())
|
log.Printf("echobot started on %s", l.Addr().String())
|
||||||
echobot.Run(l)
|
echobot.Run(l)
|
||||||
}
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
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))
|
||||||
|
}
|
|
@ -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,7 +13,6 @@ 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
|
||||||
|
@ -43,7 +42,6 @@ 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)
|
||||||
|
@ -52,7 +50,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)
|
||||||
|
@ -65,14 +63,11 @@ 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 contact %s", err)
|
log.Printf("Could not auth with server", 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)
|
||||||
|
@ -80,14 +75,17 @@ func (odClient *ODClient) Connect(privateKeyData string, serverAddr string) erro
|
||||||
log.Println("Error: " + err.Error())
|
log.Println("Error: " + err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("sending greeting message")
|
log.Println("Connection fully initiated, chat channel open!")
|
||||||
odClient.SendMessage("hello from the client")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (odClient *ODClient) Disconnect() {
|
||||||
|
log.Println("Break()...")
|
||||||
|
odClient.connection.Break()
|
||||||
|
log.Println("Conn.Close()...")
|
||||||
|
odClient.connection.Conn.Close()
|
||||||
|
}
|
||||||
|
|
||||||
/*func (odClient *ODClient) RequestContact() {
|
/*func (odClient *ODClient) RequestContact() {
|
||||||
odClient.connection.Do(func() error {
|
odClient.connection.Do(func() error {
|
||||||
channel := odClient.connection.Channel("im.ricochet.contact.request", channels.Outbound)
|
channel := odClient.connection.Channel("im.ricochet.contact.request", channels.Outbound)
|
||||||
|
@ -118,11 +116,16 @@ 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
|
||||||
}
|
}
|
Loading…
Reference in New Issue