full gomobile and ffi support + new GetMessages #3
|
@ -1 +1,5 @@
|
|||
.idea
|
||||
cwtch-sources.jar
|
||||
cwtch.aar
|
||||
libCwtch.h
|
||||
libCwtch.so
|
||||
|
|
12
README.md
12
README.md
|
@ -1,6 +1,14 @@
|
|||
# Build Instructions...
|
||||
go build -buildmode c-shared -o libCwtch.so
|
||||
make linux
|
||||
make android
|
||||
|
||||
# Using
|
||||
|
||||
LD_LIBRARY_PATH set to point to libCwtch.so
|
||||
## Linux Desktop:
|
||||
|
||||
- `LD_LIBRARY_PATH` set to point to `libCwtch.so`
|
||||
- or drop a symlink into `/usr/lib`
|
||||
|
||||
## Android
|
||||
|
||||
- copy `cwtch.aar` into `flutter_app/android/cwtch`
|
||||
|
|
87
lib.go
87
lib.go
|
@ -32,48 +32,47 @@ func c_StartCwtch(dir_c *C.char, len C.int, tor_c *C.char, torLen C.int) {
|
|||
}
|
||||
|
||||
func StartCwtch(appDir string, torPath string) {
|
||||
//go func (appDir string, torPath string) {
|
||||
log.SetLevel(log.LevelDebug)
|
||||
log.SetLevel(log.LevelDebug)
|
||||
|
||||
log.Infof("Loading Cwtch Directory %v and tor path: %v", appDir, torPath)
|
||||
log.Infof("Loading Cwtch Directory %v and tor path: %v", appDir, torPath)
|
||||
|
||||
mrand.Seed(int64(time.Now().Nanosecond()))
|
||||
port := mrand.Intn(1000) + 9600
|
||||
controlPort := port + 1
|
||||
mrand.Seed(int64(time.Now().Nanosecond()))
|
||||
port := mrand.Intn(1000) + 9600
|
||||
controlPort := port + 1
|
||||
|
||||
// generate a random password (actually random, stored in memory, for the control port)
|
||||
key := make([]byte, 64)
|
||||
_, err := rand.Read(key)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// generate a random password (actually random, stored in memory, for the control port)
|
||||
key := make([]byte, 64)
|
||||
_, err := rand.Read(key)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
log.Infof("making directory %v", appDir)
|
||||
os.MkdirAll(path.Join(appDir, "/.tor", "tor"), 0700)
|
||||
tor.NewTorrc().WithSocksPort(port).WithOnionTrafficOnly().WithControlPort(controlPort).WithHashedPassword(base64.StdEncoding.EncodeToString(key)).Build(filepath.Join(appDir, ".tor", "tor", "torrc"))
|
||||
acn, err := tor.NewTorACNWithAuth(path.Join(appDir, "/.tor"), torPath, controlPort, tor.HashedPasswordAuthenticator{base64.StdEncoding.EncodeToString(key)})
|
||||
if err != nil {
|
||||
log.Errorf("\nError connecting to Tor: %v\n", err)
|
||||
}
|
||||
//acn.WaitTillBootstrapped()
|
||||
log.Infof("making directory %v", appDir)
|
||||
os.MkdirAll(path.Join(appDir, "/.tor", "tor"), 0700)
|
||||
tor.NewTorrc().WithSocksPort(port).WithOnionTrafficOnly().WithControlPort(controlPort).WithHashedPassword(base64.StdEncoding.EncodeToString(key)).Build(filepath.Join(appDir, ".tor", "tor", "torrc"))
|
||||
acn, err := tor.NewTorACNWithAuth(path.Join(appDir, "/.tor"), torPath, controlPort, tor.HashedPasswordAuthenticator{base64.StdEncoding.EncodeToString(key)})
|
||||
if err != nil {
|
||||
log.Errorf("\nError connecting to Tor: %v\n", err)
|
||||
}
|
||||
//acn.WaitTillBootstrapped()
|
||||
|
||||
newApp := app.NewApp(acn, appDir)
|
||||
acnQueue = event.NewQueue()
|
||||
newApp.GetPrimaryBus().Subscribe(event.ACNStatus, acnQueue)
|
||||
peer.DefaultEventsToHandle = []event.Type{
|
||||
event.EncryptedGroupMessage,
|
||||
event.NewMessageFromPeer,
|
||||
event.PeerAcknowledgement,
|
||||
event.NewGroupInvite,
|
||||
event.PeerError,
|
||||
event.SendMessageToGroupError,
|
||||
event.NewGetValMessageFromPeer,
|
||||
event.PeerStateChange,
|
||||
}
|
||||
newApp.LoadProfiles("be gay do crime")
|
||||
newApp.LaunchPeers()
|
||||
application = newApp
|
||||
//}(appDir, torPath)
|
||||
newApp := app.NewApp(acn, appDir)
|
||||
acnQueue = event.NewQueue()
|
||||
newApp.GetPrimaryBus().Subscribe(event.ACNStatus, acnQueue)
|
||||
peer.DefaultEventsToHandle = []event.Type{
|
||||
event.EncryptedGroupMessage,
|
||||
event.NewMessageFromPeer,
|
||||
event.PeerAcknowledgement,
|
||||
event.NewGroupInvite,
|
||||
event.PeerError,
|
||||
event.SendMessageToGroupError,
|
||||
event.NewGetValMessageFromPeer,
|
||||
event.PeerStateChange,
|
||||
}
|
||||
newApp.LoadProfiles("be gay do crime")
|
||||
newApp.LaunchPeers()
|
||||
application = newApp
|
||||
log.Infof("libcwtch-go application SET\n")
|
||||
}
|
||||
|
||||
//export c_ACNEvents
|
||||
|
@ -179,6 +178,7 @@ func c_GetMessage(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, ha
|
|||
return C.CString(GetMessage(profile, handle, int(message_index)))
|
||||
}
|
||||
|
||||
// Deprecate - 2021.01.14 - not used
|
||||
func GetMessage(profile, handle string, message_index int) string {
|
||||
message := application.GetPeer(profile).GetContact(handle).Timeline.Messages[message_index]
|
||||
bytes,_ := json.Marshal(message)
|
||||
|
@ -186,5 +186,18 @@ func GetMessage(profile, handle string, message_index int) string {
|
|||
return string(bytes)
|
||||
}
|
||||
|
||||
//export c_GetMessages
|
||||
func c_GetMessages(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int, start C.int, end C.int) *C.char {
|
||||
profile := C.GoStringN(profile_ptr, profile_len)
|
||||
handle := C.GoStringN(handle_ptr, handle_len)
|
||||
return C.CString(GetMessages(profile, handle, int(start), int(end)))
|
||||
}
|
||||
|
||||
func GetMessages(profile, handle string, start, end int) string {
|
||||
messages := application.GetPeer(profile).GetContact(handle).Timeline.Messages[start:end]
|
||||
bytes,_ := json.Marshal(messages)
|
||||
return string(bytes)
|
||||
}
|
||||
|
||||
// Leave as is, needed by ffi
|
||||
//func main() {}
|
Loading…
Reference in New Issue