add GetMessages
This commit is contained in:
parent
b70da91e5c
commit
120dc5f468
|
@ -1 +1,5 @@
|
||||||
.idea
|
.idea
|
||||||
|
cwtch-sources.jar
|
||||||
|
cwtch.aar
|
||||||
|
libCwtch.h
|
||||||
|
libCwtch.so
|
||||||
|
|
12
README.md
12
README.md
|
@ -1,6 +1,14 @@
|
||||||
# Build Instructions...
|
# Build Instructions...
|
||||||
go build -buildmode c-shared -o libCwtch.so
|
make linux
|
||||||
|
make android
|
||||||
|
|
||||||
# Using
|
# 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) {
|
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()))
|
mrand.Seed(int64(time.Now().Nanosecond()))
|
||||||
port := mrand.Intn(1000) + 9600
|
port := mrand.Intn(1000) + 9600
|
||||||
controlPort := port + 1
|
controlPort := port + 1
|
||||||
|
|
||||||
// generate a random password (actually random, stored in memory, for the control port)
|
// generate a random password (actually random, stored in memory, for the control port)
|
||||||
key := make([]byte, 64)
|
key := make([]byte, 64)
|
||||||
_, err := rand.Read(key)
|
_, err := rand.Read(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("making directory %v", appDir)
|
log.Infof("making directory %v", appDir)
|
||||||
os.MkdirAll(path.Join(appDir, "/.tor", "tor"), 0700)
|
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"))
|
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)})
|
acn, err := tor.NewTorACNWithAuth(path.Join(appDir, "/.tor"), torPath, controlPort, tor.HashedPasswordAuthenticator{base64.StdEncoding.EncodeToString(key)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("\nError connecting to Tor: %v\n", err)
|
log.Errorf("\nError connecting to Tor: %v\n", err)
|
||||||
}
|
}
|
||||||
//acn.WaitTillBootstrapped()
|
//acn.WaitTillBootstrapped()
|
||||||
|
|
||||||
newApp := app.NewApp(acn, appDir)
|
newApp := app.NewApp(acn, appDir)
|
||||||
acnQueue = event.NewQueue()
|
acnQueue = event.NewQueue()
|
||||||
newApp.GetPrimaryBus().Subscribe(event.ACNStatus, acnQueue)
|
newApp.GetPrimaryBus().Subscribe(event.ACNStatus, acnQueue)
|
||||||
peer.DefaultEventsToHandle = []event.Type{
|
peer.DefaultEventsToHandle = []event.Type{
|
||||||
event.EncryptedGroupMessage,
|
event.EncryptedGroupMessage,
|
||||||
event.NewMessageFromPeer,
|
event.NewMessageFromPeer,
|
||||||
event.PeerAcknowledgement,
|
event.PeerAcknowledgement,
|
||||||
event.NewGroupInvite,
|
event.NewGroupInvite,
|
||||||
event.PeerError,
|
event.PeerError,
|
||||||
event.SendMessageToGroupError,
|
event.SendMessageToGroupError,
|
||||||
event.NewGetValMessageFromPeer,
|
event.NewGetValMessageFromPeer,
|
||||||
event.PeerStateChange,
|
event.PeerStateChange,
|
||||||
}
|
}
|
||||||
newApp.LoadProfiles("be gay do crime")
|
newApp.LoadProfiles("be gay do crime")
|
||||||
newApp.LaunchPeers()
|
newApp.LaunchPeers()
|
||||||
application = newApp
|
application = newApp
|
||||||
//}(appDir, torPath)
|
log.Infof("libcwtch-go application SET\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
//export c_ACNEvents
|
//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)))
|
return C.CString(GetMessage(profile, handle, int(message_index)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Deprecate - 2021.01.14 - not used
|
||||||
func GetMessage(profile, handle string, message_index int) string {
|
func GetMessage(profile, handle string, message_index int) string {
|
||||||
message := application.GetPeer(profile).GetContact(handle).Timeline.Messages[message_index]
|
message := application.GetPeer(profile).GetContact(handle).Timeline.Messages[message_index]
|
||||||
bytes,_ := json.Marshal(message)
|
bytes,_ := json.Marshal(message)
|
||||||
|
@ -186,5 +186,18 @@ func GetMessage(profile, handle string, message_index int) string {
|
||||||
return string(bytes)
|
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
|
// Leave as is, needed by ffi
|
||||||
//func main() {}
|
//func main() {}
|
Loading…
Reference in New Issue