take 1 filesharing support

This commit is contained in:
erinn 2021-09-23 13:50:14 -07:00
parent f6fec4082a
commit fdabf3d649
4 changed files with 72 additions and 15 deletions

3
go.mod
View File

@ -5,9 +5,10 @@ go 1.15
require (
cwtch.im/cwtch v0.10.0
git.openprivacy.ca/openprivacy/connectivity v1.4.5
git.openprivacy.ca/openprivacy/log v1.0.2
git.openprivacy.ca/openprivacy/log v1.0.3
golang.org/x/mobile v0.0.0-20210716004757-34ab1303b554 // indirect
golang.org/x/mod v0.5.0 // indirect
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
golang.org/x/tools v0.1.5 // indirect
)

8
go.sum
View File

@ -6,6 +6,12 @@ cwtch.im/cwtch v0.10.0/go.mod h1:EwUUVWIU4OAcz0HmHUxaY4orzKH6ZiNXaVI8y/5UP5k=
git.openprivacy.ca/cwtch.im/tapir v0.3.4/go.mod h1:+Niy2AHhQC351ZTtfhC0uLjViCICyOxCJZsIlGKKNAU=
git.openprivacy.ca/cwtch.im/tapir v0.4.4 h1:KyuTVmr9GYptTCeR7JDODjmhBBbnIBf9V3NSC4+6bHc=
git.openprivacy.ca/cwtch.im/tapir v0.4.4/go.mod h1:qMFTdmDZITc1BLP1jSW0gVpLmvpg+Zjsh5ek8StwbFE=
git.openprivacy.ca/cwtch.im/tapir v0.4.5 h1:CTMFdH2qBt4dkiyzNbxuQpK52iKerZmFnG2SfLLSmS8=
git.openprivacy.ca/cwtch.im/tapir v0.4.5/go.mod h1:qMFTdmDZITc1BLP1jSW0gVpLmvpg+Zjsh5ek8StwbFE=
git.openprivacy.ca/cwtch.im/tapir v0.4.6 h1:hoKIXNfsWjTiLry9NYTBc9VJYSST3WydHv+Wrt+bn8s=
git.openprivacy.ca/cwtch.im/tapir v0.4.6/go.mod h1:qMFTdmDZITc1BLP1jSW0gVpLmvpg+Zjsh5ek8StwbFE=
git.openprivacy.ca/cwtch.im/tapir v0.4.7 h1:TFBpaoKDCZ1NhsPmdOBLPxaU3vOY2cbDhgL2CwmIRf0=
git.openprivacy.ca/cwtch.im/tapir v0.4.7/go.mod h1:qMFTdmDZITc1BLP1jSW0gVpLmvpg+Zjsh5ek8StwbFE=
git.openprivacy.ca/flutter/libcwtch-go v0.0.2 h1:Njc417xxzh9rxSsJWFWrIPezJeY31CuQSuSAA9II5eE=
git.openprivacy.ca/flutter/libcwtch-go v0.0.2/go.mod h1:Qc7knXLjifyYssPXEkxNknXaNsWrBkJrReu/0WjIJwI=
git.openprivacy.ca/openprivacy/bine v0.0.4 h1:CO7EkGyz+jegZ4ap8g5NWRuDHA/56KKvGySR6OBPW+c=
@ -16,6 +22,8 @@ git.openprivacy.ca/openprivacy/connectivity v1.4.5/go.mod h1:JVRCIdL+lAG6ohBFWiK
git.openprivacy.ca/openprivacy/log v1.0.1/go.mod h1:gGYK8xHtndRLDymFtmjkG26GaMQNgyhioNS82m812Iw=
git.openprivacy.ca/openprivacy/log v1.0.2 h1:HLP4wsw4ljczFAelYnbObIs821z+jgMPCe8uODPnGQM=
git.openprivacy.ca/openprivacy/log v1.0.2/go.mod h1:gGYK8xHtndRLDymFtmjkG26GaMQNgyhioNS82m812Iw=
git.openprivacy.ca/openprivacy/log v1.0.3 h1:E/PMm4LY+Q9s3aDpfySfEDq/vYQontlvNj/scrPaga0=
git.openprivacy.ca/openprivacy/log v1.0.3/go.mod h1:gGYK8xHtndRLDymFtmjkG26GaMQNgyhioNS82m812Iw=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802 h1:1BDTz0u9nC3//pOCMdNH+CiXJVYJh5UQNCOBG7jbELc=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

69
lib.go
View File

@ -8,32 +8,35 @@ import "C"
import (
"crypto/rand"
"cwtch.im/cwtch/app"
"cwtch.im/cwtch/event"
"cwtch.im/cwtch/model"
"cwtch.im/cwtch/model/attr"
"cwtch.im/cwtch/peer"
"encoding/json"
"fmt"
"git.openprivacy.ca/cwtch.im/libcwtch-go/constants"
contact "git.openprivacy.ca/cwtch.im/libcwtch-go/features/contacts"
"git.openprivacy.ca/cwtch.im/libcwtch-go/features/groups"
"git.openprivacy.ca/cwtch.im/libcwtch-go/utils"
"git.openprivacy.ca/openprivacy/connectivity"
"os/user"
"runtime"
"strconv"
"strings"
"unsafe"
"cwtch.im/cwtch/app"
"cwtch.im/cwtch/event"
"cwtch.im/cwtch/functionality/filesharing"
"cwtch.im/cwtch/model"
"cwtch.im/cwtch/model/attr"
"cwtch.im/cwtch/peer"
"git.openprivacy.ca/cwtch.im/libcwtch-go/constants"
contact "git.openprivacy.ca/cwtch.im/libcwtch-go/features/contacts"
"git.openprivacy.ca/cwtch.im/libcwtch-go/features/groups"
"git.openprivacy.ca/cwtch.im/libcwtch-go/utils"
"git.openprivacy.ca/openprivacy/connectivity"
"encoding/base64"
"git.openprivacy.ca/openprivacy/connectivity/tor"
"git.openprivacy.ca/openprivacy/log"
mrand "math/rand"
"os"
"path"
"path/filepath"
"time"
"git.openprivacy.ca/openprivacy/connectivity/tor"
"git.openprivacy.ca/openprivacy/log"
)
const (
@ -84,7 +87,7 @@ func StartCwtch(appDir string, torPath string) int {
if runtime.GOOS == "android" {
log.SetUseColor(false)
}
log.SetLevel(log.LevelInfo)
log.SetLevel(log.LevelDebug)
if logLevel := os.Getenv("LOG_LEVEL"); strings.ToLower(logLevel) == "debug" {
log.SetLevel(log.LevelDebug)
}
@ -180,6 +183,7 @@ func _startCwtch(appDir string, torPath string) {
event.ServerStateChange,
event.ProtocolEngineStopped,
event.RetryServerRequest,
event.ManifestReceived,
}
settings := utils.ReadGlobalSettings()
settingsJson, _ := json.Marshal(settings)
@ -254,7 +258,6 @@ func ReconnectCwtchForeground() {
application.GetPrimaryBus().Publish(event.NewEvent(utils.CwtchStarted, map[event.Field]string{}))
application.QueryACNStatus()
application.QueryACNVersion()
}
//export c_SendAppEvent
@ -663,6 +666,44 @@ func SendInvitation(profileOnion, handle, target string) {
}
}
//export c_ShareFile
func c_ShareFile(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int, filepath_ptr *C.char, filepath_len C.int) {
profile := C.GoStringN(profile_ptr, profile_len)
handle := C.GoStringN(handle_ptr, handle_len)
filepath := C.GoStringN(filepath_ptr, filepath_len)
ShareFile(profile, handle, filepath)
}
func ShareFile(profileOnion, handle, filepath string) {
profile := application.GetPeer(profileOnion)
fh, err := filesharing.FunctionalityGate(utils.ReadGlobalSettings().Experiments)
if err != nil {
log.Errorf("file sharing error: %v", err)
} else {
fh.ShareFile(filepath, profile, handle)
}
}
//export c_DownloadFile
func c_DownloadFile(profile_ptr *C.char, profile_len C.int, handle_ptr *C.char, handle_len C.int, filepath_ptr *C.char, filepath_len C.int, manifestpath_ptr *C.char, manifestpath_len C.int, filekey_ptr *C.char, filekey_len C.int) {
profile := C.GoStringN(profile_ptr, profile_len)
handle := C.GoStringN(handle_ptr, handle_len)
filepath := C.GoStringN(filepath_ptr, filepath_len)
manifestpath := C.GoStringN(manifestpath_ptr, manifestpath_len)
filekey := C.GoStringN(filekey_ptr, filekey_len)
DownloadFile(profile, handle, filepath, manifestpath, filekey)
}
func DownloadFile(profileOnion, handle, filepath, manifestpath, filekey string) {
profile := application.GetPeer(profileOnion)
fh, err := filesharing.FunctionalityGate(utils.ReadGlobalSettings().Experiments)
if err != nil {
log.Errorf("file sharing error: %v", err)
} else {
fh.DownloadFile(profile, handle, filepath, manifestpath, filekey)
}
}
//export c_ResetTor
func c_ResetTor() {
ResetTor()

View File

@ -372,6 +372,13 @@ func (eh *EventHandler) startHandlingPeer(onion string) {
eventBus.Subscribe(event.ChangePasswordError, q)
eventBus.Subscribe(event.NewRetValMessageFromPeer, q)
eventBus.Subscribe(event.SetAttribute, q)
eventBus.Subscribe(event.ShareManifest, q)
eventBus.Subscribe(event.ManifestSizeReceived, q)
eventBus.Subscribe(event.ManifestError, q)
eventBus.Subscribe(event.ManifestReceived, q)
eventBus.Subscribe(event.ManifestSaved, q)
eventBus.Subscribe(event.FileDownloadProgressUpdate, q)
eventBus.Subscribe(event.FileDownloaded, q)
go eh.forwardProfileMessages(onion, q)