diff --git a/README.md b/README.md new file mode 100644 index 0000000..9f1bc8c --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Using Java camelcase packnameing because gomobile + Java have problems with '_'s and '-'s diff --git a/goRicochetMobile.go b/goRicochetMobile.go new file mode 100644 index 0000000..c2cbd3e --- /dev/null +++ b/goRicochetMobile.go @@ -0,0 +1,40 @@ +package goRicochetMobile + +import ( + "github.com/s-rah/go-ricochet/application" + "github.com/s-rah/go-ricochet/utils" + "log" + "time" +) + +func GeneratePrivateKey() (string, error) { + privateKey, err := utils.GeneratePrivateKey() + if err != nil { + return "", err + } + return utils.PrivateKeyToString(privateKey), nil +} + +func EchoBot(privateKeyData string) { + privateKey, err := utils.ParsePrivateKey([]byte(privateKeyData)) + + if err != nil { + log.Fatal("error parsing private key: %v", err) + } + + echobot := new(application.RicochetApplication) + + l, err := application.SetupOnion("127.0.0.1:9051", "", privateKey, 9878) + + 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) +} diff --git a/InitActivity.go b/ricochet-mobile.go similarity index 100% rename from InitActivity.go rename to ricochet-mobile.go