2017-08-13 15:30:08 +00:00
|
|
|
package goRicochetMobile
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/s-rah/go-ricochet/application"
|
|
|
|
"github.com/s-rah/go-ricochet/utils"
|
|
|
|
"log"
|
2017-08-20 20:42:55 +00:00
|
|
|
"net/http"
|
2017-08-13 15:30:08 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func GeneratePrivateKey() (string, error) {
|
|
|
|
privateKey, err := utils.GeneratePrivateKey()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return utils.PrivateKeyToString(privateKey), nil
|
|
|
|
}
|
|
|
|
|
2017-08-20 20:42:55 +00:00
|
|
|
func TestNet() (ok bool, ex error) {
|
|
|
|
_, err := http.Get("http://golang.org/")
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func EchoBot(privateKeyData string) {
|
2017-08-13 15:30:08 +00:00
|
|
|
privateKey, err := utils.ParsePrivateKey([]byte(privateKeyData))
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("error parsing private key: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
echobot := new(application.RicochetApplication)
|
|
|
|
|
2017-08-20 20:42:55 +00:00
|
|
|
log.Println("SetupOnion()...")
|
2017-08-16 14:44:38 +00:00
|
|
|
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)
|
2017-08-13 15:30:08 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("error setting up onion service: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
echobot.Init(privateKey, new(application.AcceptAllContactManager))
|
|
|
|
echobot.OnChatMessage(func(rai *application.RicochetApplicationInstance, id uint32, timestamp time.Time, message string) {
|
|
|
|
log.Printf("message from %v - %v", rai.RemoteHostname, message)
|
|
|
|
rai.SendChatMessage(message)
|
|
|
|
})
|
|
|
|
log.Printf("echobot listening on %s", l.Addr().String())
|
|
|
|
echobot.Run(l)
|
|
|
|
}
|