reorg echobot code, port GetOnionAdd to correctly working bulb implementation

This commit is contained in:
Dan Ballard 2017-09-06 20:33:14 -07:00
parent 3ffb61065f
commit 032f06dad1
1 changed files with 25 additions and 8 deletions

View File

@ -6,6 +6,9 @@ import (
"log" "log"
"net/http" "net/http"
"time" "time"
"github.com/s-rah/go-ricochet/connection"
"github.com/yawning/bulb/utils/pkcs1"
"crypto/rsa"
) )
func GeneratePrivateKey() (string, error) { func GeneratePrivateKey() (string, error) {
@ -17,7 +20,13 @@ func GeneratePrivateKey() (string, error) {
} }
func GetOnionAddress(privateKey string) string { func GetOnionAddress(privateKey string) string {
return utils.GetOnionAddr(privateKey) pk, _ := utils.ParsePrivateKey([]byte(privateKey))
pubKey := rsa.PublicKey(pk.PublicKey)
addr, err := pkcs1.OnionAddr(&pubKey)
if err != nil || addr == "" {
return ""
}
return addr
} }
func TestNet() (ok bool, ex error) { func TestNet() (ok bool, ex error) {
@ -28,27 +37,35 @@ func TestNet() (ok bool, ex error) {
return true, nil return true, nil
} }
type ODClient struct {
connection.AutoConnectionHandler
messages chan string
deviceName string
deviceLevel int
batteryLevel string
}
/******** 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 {
log.Fatal("error parsing private key: %v", err) log.Fatal("error parsing private key: %v", err)
} }
echobot := new(application.RicochetApplication)
log.Println("SetupOnion()...") log.Println("Setup onion hidden service via tor control...")
l, err := application.SetupOnion("127.0.0.1:9051", "tcp4","", privateKey, 9878) l, err := application.SetupOnion("127.0.0.1:9051", "tcp4","", privateKey, 9878)
//l, err := application.SetupOnion("/data/data/org.torproject.android/app_bin/control.txt", "unix","", privateKey, 9878)
if err != nil { if err != nil {
log.Fatalf("error setting up onion service: %v", err) log.Fatalf("error setting up onion service: %v", err)
} }
echobot.Init(privateKey, new(application.AcceptAllContactManager)) echobot := new(application.RicochetApplication)
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)
rai.SendChatMessage(message) rai.SendChatMessage(message)
}) })
log.Printf("echobot listening on %s", l.Addr().String()) log.Printf("echobot started on %s", l.Addr().String())
echobot.Run(l) echobot.Run(l)
} }