start work on od client, classes and interface fulfilment

This commit is contained in:
Dan Ballard 2017-09-06 23:49:59 -07:00
parent 032f06dad1
commit 5085a1d08c
2 changed files with 76 additions and 7 deletions

View File

@ -6,9 +6,9 @@ import (
"log" "log"
"net/http" "net/http"
"time" "time"
"github.com/s-rah/go-ricochet/connection"
"github.com/yawning/bulb/utils/pkcs1" "github.com/yawning/bulb/utils/pkcs1"
"crypto/rsa" "crypto/rsa"
"github.com/s-rah/go-ricochet/channels"
) )
func GeneratePrivateKey() (string, error) { func GeneratePrivateKey() (string, error) {
@ -37,14 +37,31 @@ func TestNet() (ok bool, ex error) {
return true, nil return true, nil
} }
type ODClient struct { func ODClientConnect(privateKeyData string, serverAddr string) {
connection.AutoConnectionHandler privateKey, err := utils.ParsePrivateKey([]byte(privateKeyData))
messages chan string if err != nil {
deviceName string log.Fatal("error parsing private key: %v", err)
deviceLevel int }
batteryLevel string
odClient := new(ODClient)
odClient.Init(privateKey, serverAddr)
odClient.RegisterChannelHandler("im.ricochet.contact.request", func() channels.Handler {
contact := new(channels.ContactRequestChannel)
contact.Handler = odClient
return contact
})
odClient.RegisterChannelHandler("im.ricochet.chat", func() channels.Handler {
chat := new(channels.ChatChannel)
chat.Handler = odClient
return chat
})
} }
/******** Testing by standing up an echobot ******/ /******** Testing by standing up an echobot ******/
func EchoBot(privateKeyData string) { func EchoBot(privateKeyData string) {

52
odClient.go Normal file
View File

@ -0,0 +1,52 @@
package goRicochetMobile
import (
"github.com/s-rah/go-ricochet/connection"
"time"
"log"
)
type ODClient struct {
connection.AutoConnectionHandler
messages chan string
deviceName string
deviceLevel int
batteryLevel string
}
/************* Chat Channel Handler ********/
// ChatMessage passes the response to messages.
func (odc *ODClient) ChatMessage(messageID uint32, when time.Time, message string) bool {
log.Printf("Received Message: %s", message)
odc.messages <- message
return true
}
// ChatMessageAck does nothing.
func (odc *ODClient) ChatMessageAck(messageID uint32) {
}
/************* Contact Channel Handler ********/
// GetContactDetails is purposely empty
func (odc *ODClient) GetContactDetails() (string, string) {
return "", ""
}
// ContactRequest denies any contact request.
func (odc *ODClient) ContactRequest(name string, message string) string {
return "Rejected"
}
// ContactRequestRejected purposly does nothing.
func (odc *ODClient) ContactRequestRejected() {
}
// ContactRequestAccepted purposly does nothing.
func (odc *ODClient) ContactRequestAccepted() {
}
// ContactRequestError purposly does nothing.
func (odc *ODClient) ContactRequestError() {
}